1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2016, Oblong Industries, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <fcntl.h>
33 #include <unistd.h>
34
35 #include <va/va_drm.h>
36 #include "msdk.h"
37 #include "msdk_libva.h"
38
39 struct fourcc_map
40 {
41 mfxU32 mfx_fourcc;
42 guint32 va_fourcc;
43 };
44
45 struct rt_map
46 {
47 mfxU32 mfx_rt_format;
48 guint32 va_rt_format;
49 };
50
51 #define FOURCC_MFX_TO_VA(MFX, VA) \
52 { MFX_FOURCC_##MFX, VA_FOURCC_##VA }
53
54 #define RT_MFX_TO_VA(MFX, VA) \
55 { MFX_CHROMAFORMAT_##MFX, VA_RT_FORMAT_##VA }
56
57 static const struct fourcc_map gst_msdk_fourcc_mfx_to_va[] = {
58 FOURCC_MFX_TO_VA (NV12, NV12),
59 FOURCC_MFX_TO_VA (YUY2, YUY2),
60 FOURCC_MFX_TO_VA (UYVY, UYVY),
61 FOURCC_MFX_TO_VA (YV12, YV12),
62 FOURCC_MFX_TO_VA (RGB4, ARGB),
63 FOURCC_MFX_TO_VA (P8, P208),
64 FOURCC_MFX_TO_VA (P010, P010),
65 #if (MFX_VERSION >= 1028)
66 FOURCC_MFX_TO_VA (RGB565, RGB565),
67 #endif
68 FOURCC_MFX_TO_VA (AYUV, AYUV),
69 #if VA_CHECK_VERSION(1, 4, 1)
70 FOURCC_MFX_TO_VA (A2RGB10, A2R10G10B10),
71 #endif
72 {0, 0}
73 };
74
75 static const struct rt_map gst_msdk_rt_mfx_to_va[] = {
76 RT_MFX_TO_VA (YUV420, YUV420),
77 RT_MFX_TO_VA (YUV422, YUV422),
78 RT_MFX_TO_VA (YUV444, YUV444),
79 {0, 0}
80 };
81
82 mfxStatus
gst_msdk_get_mfx_status_from_va_status(VAStatus va_res)83 gst_msdk_get_mfx_status_from_va_status (VAStatus va_res)
84 {
85 mfxStatus mfxRes = MFX_ERR_NONE;
86
87 switch (va_res) {
88 case VA_STATUS_SUCCESS:
89 mfxRes = MFX_ERR_NONE;
90 break;
91 case VA_STATUS_ERROR_ALLOCATION_FAILED:
92 mfxRes = MFX_ERR_MEMORY_ALLOC;
93 break;
94 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
95 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
96 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
97 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
98 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
99 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
100 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
101 mfxRes = MFX_ERR_UNSUPPORTED;
102 break;
103 case VA_STATUS_ERROR_INVALID_DISPLAY:
104 case VA_STATUS_ERROR_INVALID_CONFIG:
105 case VA_STATUS_ERROR_INVALID_CONTEXT:
106 case VA_STATUS_ERROR_INVALID_SURFACE:
107 case VA_STATUS_ERROR_INVALID_BUFFER:
108 case VA_STATUS_ERROR_INVALID_IMAGE:
109 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
110 mfxRes = MFX_ERR_NOT_INITIALIZED;
111 break;
112 case VA_STATUS_ERROR_INVALID_PARAMETER:
113 mfxRes = MFX_ERR_INVALID_VIDEO_PARAM;
114 break;
115 default:
116 mfxRes = MFX_ERR_UNKNOWN;
117 break;
118 }
119 return mfxRes;
120 }
121
122 guint
gst_msdk_get_va_fourcc_from_mfx_fourcc(mfxU32 fourcc)123 gst_msdk_get_va_fourcc_from_mfx_fourcc (mfxU32 fourcc)
124 {
125 const struct fourcc_map *m = gst_msdk_fourcc_mfx_to_va;
126
127 for (; m->mfx_fourcc != 0; m++) {
128 if (m->mfx_fourcc == fourcc)
129 return m->va_fourcc;
130 }
131
132 return 0;
133 }
134
135 guint
gst_msdk_get_mfx_fourcc_from_va_fourcc(guint32 fourcc)136 gst_msdk_get_mfx_fourcc_from_va_fourcc (guint32 fourcc)
137 {
138 const struct fourcc_map *m = gst_msdk_fourcc_mfx_to_va;
139
140 for (; m->va_fourcc != 0; m++) {
141 if (m->va_fourcc == fourcc)
142 return m->mfx_fourcc;
143 }
144
145 return 0;
146 }
147
148 guint
gst_msdk_get_va_rt_format_from_mfx_rt_format(mfxU32 format)149 gst_msdk_get_va_rt_format_from_mfx_rt_format (mfxU32 format)
150 {
151 const struct rt_map *m = gst_msdk_rt_mfx_to_va;
152
153 for (; m->mfx_rt_format != 0; m++) {
154 if (m->mfx_rt_format == format)
155 return m->va_rt_format;
156 }
157
158 return 0;
159 }
160
161 guint
gst_msdk_get_mfx_rt_format_from_va_rt_format(guint32 format)162 gst_msdk_get_mfx_rt_format_from_va_rt_format (guint32 format)
163 {
164 const struct rt_map *m = gst_msdk_rt_mfx_to_va;
165
166 for (; m->va_rt_format != 0; m++) {
167 if (m->va_rt_format == format)
168 return m->mfx_rt_format;
169 }
170
171 return 0;
172 }
173