msdk: map MFX_FOURCC_AYUV to VA_FOURCC_AYUV
[platform/upstream/gstreamer.git] / sys / msdk / msdk_libva.c
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   {0, 0}
70 };
71
72 static const struct rt_map gst_msdk_rt_mfx_to_va[] = {
73   RT_MFX_TO_VA (YUV420, YUV420),
74   RT_MFX_TO_VA (YUV422, YUV422),
75   RT_MFX_TO_VA (YUV444, YUV444),
76   {0, 0}
77 };
78
79 mfxStatus
80 gst_msdk_get_mfx_status_from_va_status (VAStatus va_res)
81 {
82   mfxStatus mfxRes = MFX_ERR_NONE;
83
84   switch (va_res) {
85     case VA_STATUS_SUCCESS:
86       mfxRes = MFX_ERR_NONE;
87       break;
88     case VA_STATUS_ERROR_ALLOCATION_FAILED:
89       mfxRes = MFX_ERR_MEMORY_ALLOC;
90       break;
91     case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
92     case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
93     case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
94     case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
95     case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
96     case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
97     case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
98       mfxRes = MFX_ERR_UNSUPPORTED;
99       break;
100     case VA_STATUS_ERROR_INVALID_DISPLAY:
101     case VA_STATUS_ERROR_INVALID_CONFIG:
102     case VA_STATUS_ERROR_INVALID_CONTEXT:
103     case VA_STATUS_ERROR_INVALID_SURFACE:
104     case VA_STATUS_ERROR_INVALID_BUFFER:
105     case VA_STATUS_ERROR_INVALID_IMAGE:
106     case VA_STATUS_ERROR_INVALID_SUBPICTURE:
107       mfxRes = MFX_ERR_NOT_INITIALIZED;
108       break;
109     case VA_STATUS_ERROR_INVALID_PARAMETER:
110       mfxRes = MFX_ERR_INVALID_VIDEO_PARAM;
111       break;
112     default:
113       mfxRes = MFX_ERR_UNKNOWN;
114       break;
115   }
116   return mfxRes;
117 }
118
119 guint
120 gst_msdk_get_va_fourcc_from_mfx_fourcc (mfxU32 fourcc)
121 {
122   const struct fourcc_map *m = gst_msdk_fourcc_mfx_to_va;
123
124   for (; m->mfx_fourcc != 0; m++) {
125     if (m->mfx_fourcc == fourcc)
126       return m->va_fourcc;
127   }
128
129   return 0;
130 }
131
132 guint
133 gst_msdk_get_mfx_fourcc_from_va_fourcc (guint32 fourcc)
134 {
135   const struct fourcc_map *m = gst_msdk_fourcc_mfx_to_va;
136
137   for (; m->va_fourcc != 0; m++) {
138     if (m->va_fourcc == fourcc)
139       return m->mfx_fourcc;
140   }
141
142   return 0;
143 }
144
145 guint
146 gst_msdk_get_va_rt_format_from_mfx_rt_format (mfxU32 format)
147 {
148   const struct rt_map *m = gst_msdk_rt_mfx_to_va;
149
150   for (; m->mfx_rt_format != 0; m++) {
151     if (m->mfx_rt_format == format)
152       return m->va_rt_format;
153   }
154
155   return 0;
156 }
157
158 guint
159 gst_msdk_get_mfx_rt_format_from_va_rt_format (guint32 format)
160 {
161   const struct rt_map *m = gst_msdk_rt_mfx_to_va;
162
163   for (; m->va_rt_format != 0; m++) {
164     if (m->va_rt_format == format)
165       return m->mfx_rt_format;
166   }
167
168   return 0;
169 }