1 /*--------------------------------------------------------------------------
2 Copyright (c) 2017, 2018 The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 --------------------------------------------------------------------------*/
29 #define LOG_TAG "OMX_COMMON"
30 
31 #include <utils/Log.h>
32 #include "vidc_debug.h"
33 #include "vidc_common.h"
34 #include "OMX_Core.h"
35 #include "OMX_QCOMExtns.h"
36 #include "OMX_VideoExt.h"
37 #include "OMX_IndexExt.h"
38 #include <linux/videodev2.h>
39 
40 int debug_level = PRIO_ERROR;
41 
42 
43 pl_map profile_level_converter::profile_avc_omx_to_v4l2 ({
44             {QOMX_VIDEO_AVCProfileConstrainedBaseline,
45                         V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE},
46             {QOMX_VIDEO_AVCProfileBaseline,
47                         V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE},
48             {QOMX_VIDEO_AVCProfileMain,
49                         V4L2_MPEG_VIDEO_H264_PROFILE_MAIN},
50             {QOMX_VIDEO_AVCProfileConstrainedHigh,
51                         V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH},
52             {QOMX_VIDEO_AVCProfileHigh,
53                         V4L2_MPEG_VIDEO_H264_PROFILE_HIGH}
54         });
55 
56 pl_map profile_level_converter::profile_avc_v4l2_to_omx ({});
57 
58 pl_map profile_level_converter::profile_hevc_omx_to_v4l2 ({
59             {OMX_VIDEO_HEVCProfileMain,
60                         V4L2_MPEG_VIDC_VIDEO_HEVC_PROFILE_MAIN},
61             {OMX_VIDEO_HEVCProfileMain10HDR10,
62                         V4L2_MPEG_VIDC_VIDEO_HEVC_PROFILE_MAIN10},
63             {OMX_VIDEO_HEVCProfileMainStill,
64                         V4L2_MPEG_VIDC_VIDEO_HEVC_PROFILE_MAIN_STILL_PIC},
65         });
66 
67 pl_map profile_level_converter::profile_hevc_v4l2_to_omx ({});
68 
69 pl_map profile_level_converter::profile_mpeg2_omx_to_v4l2 ({
70             {OMX_VIDEO_MPEG2ProfileSimple,
71                         V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_SIMPLE},
72             {OMX_VIDEO_MPEG2ProfileMain,
73                         V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_MAIN},
74         });
75 
76 pl_map profile_level_converter::profile_mpeg2_v4l2_to_omx ({});
77 
78 pl_map profile_level_converter::profile_vp9_omx_to_v4l2 ({
79             {OMX_VIDEO_VP9Profile0, V4L2_MPEG_VIDC_VIDEO_VP9_PROFILE_P0},
80             {OMX_VIDEO_VP9Profile2HDR, V4L2_MPEG_VIDC_VIDEO_VP9_PROFILE_P2_10},
81             {OMX_VIDEO_VP9Profile2HDR10Plus, V4L2_MPEG_VIDC_VIDEO_VP9_PROFILE_P2_10},
82         });
83 
84 pl_map profile_level_converter::profile_vp9_v4l2_to_omx ({});
85 
86 pl_map profile_level_converter::profile_tme_omx_to_v4l2 ({
87             {QOMX_VIDEO_TMEProfile0,
88                         V4L2_MPEG_VIDC_VIDEO_TME_PROFILE_0},
89             {QOMX_VIDEO_TMEProfile1,
90                         V4L2_MPEG_VIDC_VIDEO_TME_PROFILE_1},
91             {QOMX_VIDEO_TMEProfile2,
92                         V4L2_MPEG_VIDC_VIDEO_TME_PROFILE_2},
93             {QOMX_VIDEO_TMEProfile3,
94                         V4L2_MPEG_VIDC_VIDEO_TME_PROFILE_3},
95         });
96 
97 pl_map profile_level_converter::profile_tme_v4l2_to_omx ({});
98 
99 pl_map profile_level_converter::level_avc_omx_to_v4l2 ({
100             {OMX_VIDEO_AVCLevel1, V4L2_MPEG_VIDEO_H264_LEVEL_1_0},
101             {OMX_VIDEO_AVCLevel11, V4L2_MPEG_VIDEO_H264_LEVEL_1_1},
102             {OMX_VIDEO_AVCLevel12, V4L2_MPEG_VIDEO_H264_LEVEL_1_2},
103             {OMX_VIDEO_AVCLevel13, V4L2_MPEG_VIDEO_H264_LEVEL_1_3},
104             {OMX_VIDEO_AVCLevel1b, V4L2_MPEG_VIDEO_H264_LEVEL_1B},
105             {OMX_VIDEO_AVCLevel2, V4L2_MPEG_VIDEO_H264_LEVEL_2_0},
106             {OMX_VIDEO_AVCLevel21, V4L2_MPEG_VIDEO_H264_LEVEL_2_1},
107             {OMX_VIDEO_AVCLevel22, V4L2_MPEG_VIDEO_H264_LEVEL_2_2},
108             {OMX_VIDEO_AVCLevel3, V4L2_MPEG_VIDEO_H264_LEVEL_3_0},
109             {OMX_VIDEO_AVCLevel31, V4L2_MPEG_VIDEO_H264_LEVEL_3_1},
110             {OMX_VIDEO_AVCLevel32, V4L2_MPEG_VIDEO_H264_LEVEL_3_2},
111             {OMX_VIDEO_AVCLevel4, V4L2_MPEG_VIDEO_H264_LEVEL_4_0},
112             {OMX_VIDEO_AVCLevel41, V4L2_MPEG_VIDEO_H264_LEVEL_4_1},
113             {OMX_VIDEO_AVCLevel42, V4L2_MPEG_VIDEO_H264_LEVEL_4_2},
114             {OMX_VIDEO_AVCLevel5, V4L2_MPEG_VIDEO_H264_LEVEL_5_0},
115             {OMX_VIDEO_AVCLevel51, V4L2_MPEG_VIDEO_H264_LEVEL_5_1},
116             {OMX_VIDEO_AVCLevel52, V4L2_MPEG_VIDEO_H264_LEVEL_5_2},
117             {OMX_VIDEO_AVCLevel6, V4L2_MPEG_VIDEO_H264_LEVEL_6_0},
118             {OMX_VIDEO_AVCLevel61, V4L2_MPEG_VIDEO_H264_LEVEL_6_1},
119             {OMX_VIDEO_AVCLevel62, V4L2_MPEG_VIDEO_H264_LEVEL_6_2},
120         });
121 
122 pl_map profile_level_converter::level_avc_v4l2_to_omx ({});
123 
124 pl_map profile_level_converter::level_hevc_omx_to_v4l2 ({
125             {OMX_VIDEO_HEVCMainTierLevel1, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_1},
126             {OMX_VIDEO_HEVCMainTierLevel2, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_2},
127             {OMX_VIDEO_HEVCMainTierLevel21, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_2_1},
128             {OMX_VIDEO_HEVCMainTierLevel3, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_3},
129             {OMX_VIDEO_HEVCMainTierLevel31, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_3_1},
130             {OMX_VIDEO_HEVCMainTierLevel4, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_4},
131             {OMX_VIDEO_HEVCMainTierLevel41, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_4_1},
132             {OMX_VIDEO_HEVCMainTierLevel5, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_5},
133             {OMX_VIDEO_HEVCMainTierLevel51, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_5_1},
134             {OMX_VIDEO_HEVCMainTierLevel52, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_5_2},
135             {OMX_VIDEO_HEVCMainTierLevel6, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_6},
136             {OMX_VIDEO_HEVCMainTierLevel61, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_6_1},
137             {OMX_VIDEO_HEVCMainTierLevel62, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_MAIN_TIER_LEVEL_6_2},
138             {OMX_VIDEO_HEVCHighTierLevel1, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_1},
139             {OMX_VIDEO_HEVCHighTierLevel2, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_2},
140             {OMX_VIDEO_HEVCHighTierLevel21, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_2_1},
141             {OMX_VIDEO_HEVCHighTierLevel3, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_3},
142             {OMX_VIDEO_HEVCHighTierLevel31, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_3_1},
143             {OMX_VIDEO_HEVCHighTierLevel4, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_4},
144             {OMX_VIDEO_HEVCHighTierLevel41, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_4_1},
145             {OMX_VIDEO_HEVCHighTierLevel5, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_5},
146             {OMX_VIDEO_HEVCHighTierLevel51, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_5_1},
147             {OMX_VIDEO_HEVCHighTierLevel52, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_5_2},
148             {OMX_VIDEO_HEVCHighTierLevel6, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_6},
149             {OMX_VIDEO_HEVCHighTierLevel61, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_6_1},
150             {OMX_VIDEO_HEVCHighTierLevel62, V4L2_MPEG_VIDC_VIDEO_HEVC_LEVEL_HIGH_TIER_LEVEL_6_2},
151         });
152 
153 pl_map profile_level_converter::level_hevc_v4l2_to_omx ({});
154 
155 pl_map profile_level_converter::level_vp8_omx_to_v4l2 ({
156             {OMX_VIDEO_VP8Level_Version0, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_0},
157             {OMX_VIDEO_VP8Level_Version1, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_1},
158             {OMX_VIDEO_VP8Level_Version2, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_2},
159             {OMX_VIDEO_VP8Level_Version3, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_3},
160         });
161 
162 pl_map profile_level_converter::level_vp8_v4l2_to_omx ({});
163 
164 pl_map profile_level_converter::level_mpeg2_omx_to_v4l2 ({
165             {OMX_VIDEO_MPEG2LevelLL, V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_0},
166             {OMX_VIDEO_MPEG2LevelML, V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_1},
167             {OMX_VIDEO_MPEG2LevelHL, V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_2},
168         });
169 
170 pl_map profile_level_converter::level_mpeg2_v4l2_to_omx ({});
171 
172 pl_map profile_level_converter::level_vp9_omx_to_v4l2 ({
173             {OMX_VIDEO_VP9Level1, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_1},
174             {OMX_VIDEO_VP9Level11, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_11},
175             {OMX_VIDEO_VP9Level2, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_2},
176             {OMX_VIDEO_VP9Level21, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_21},
177             {OMX_VIDEO_VP9Level3, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_3},
178             {OMX_VIDEO_VP9Level31, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_31},
179             {OMX_VIDEO_VP9Level4, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_4},
180             {OMX_VIDEO_VP9Level41, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_41},
181             {OMX_VIDEO_VP9Level5, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_5},
182             {OMX_VIDEO_VP9Level51, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_51},
183             {OMX_VIDEO_VP9Level6, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_6},
184             {OMX_VIDEO_VP9Level61, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_61},
185         });
186 
187 pl_map profile_level_converter::level_vp9_v4l2_to_omx ({});
188 
189 pl_map profile_level_converter::level_tme_omx_to_v4l2 ({
190             {QOMX_VIDEO_TMELevelInteger, V4L2_MPEG_VIDC_VIDEO_TME_LEVEL_INTEGER},
191         });
192 
193 pl_map profile_level_converter::level_tme_v4l2_to_omx ({});
194 
195 codec_map profile_level_converter::profile_omx_to_v4l2_map ({
196             {V4L2_PIX_FMT_H264, &profile_avc_omx_to_v4l2},
197             {V4L2_PIX_FMT_HEVC, &profile_hevc_omx_to_v4l2},
198             {V4L2_PIX_FMT_MPEG2, &profile_mpeg2_omx_to_v4l2},
199             {V4L2_PIX_FMT_VP9, &profile_vp9_omx_to_v4l2},
200             {V4L2_PIX_FMT_TME, &profile_tme_omx_to_v4l2},
201         });
202 
203 codec_map profile_level_converter::profile_v4l2_to_omx_map ({
204             {V4L2_PIX_FMT_H264, &profile_avc_v4l2_to_omx},
205             {V4L2_PIX_FMT_HEVC, &profile_hevc_v4l2_to_omx},
206             {V4L2_PIX_FMT_MPEG2, &profile_mpeg2_v4l2_to_omx},
207             {V4L2_PIX_FMT_VP9, &profile_vp9_v4l2_to_omx},
208             {V4L2_PIX_FMT_TME, &profile_tme_v4l2_to_omx},
209         });
210 
211 codec_map profile_level_converter::level_omx_to_v4l2_map ({
212             {V4L2_PIX_FMT_H264, &level_avc_omx_to_v4l2},
213             {V4L2_PIX_FMT_HEVC, &level_hevc_omx_to_v4l2},
214             {V4L2_PIX_FMT_MPEG2, &level_mpeg2_omx_to_v4l2},
215             {V4L2_PIX_FMT_VP8, &level_vp8_omx_to_v4l2},
216             {V4L2_PIX_FMT_VP9, &level_vp9_omx_to_v4l2},
217             {V4L2_PIX_FMT_TME, &level_tme_omx_to_v4l2},
218         });
219 
220 codec_map profile_level_converter::level_v4l2_to_omx_map ({
221             {V4L2_PIX_FMT_H264, &level_avc_v4l2_to_omx},
222             {V4L2_PIX_FMT_HEVC, &level_hevc_v4l2_to_omx},
223             {V4L2_PIX_FMT_MPEG2, &level_mpeg2_v4l2_to_omx},
224             {V4L2_PIX_FMT_VP8, &level_vp8_v4l2_to_omx},
225             {V4L2_PIX_FMT_VP9, &level_vp9_v4l2_to_omx},
226             {V4L2_PIX_FMT_TME, &level_tme_v4l2_to_omx},
227         });
228 
reverse_map(pl_map source_map,pl_map & dest_map)229 void reverse_map(pl_map source_map, pl_map &dest_map)
230 {
231     pl_map::iterator it;
232 
233     for(it = source_map.begin(); it != source_map.end(); it++) {
234         dest_map[it->second] = it->first;
235     }
236     return;
237 }
238 
init()239 void profile_level_converter::init()
240 {
241     reverse_map(profile_avc_omx_to_v4l2, profile_avc_v4l2_to_omx);
242     reverse_map(profile_hevc_omx_to_v4l2, profile_hevc_v4l2_to_omx);
243     reverse_map(profile_mpeg2_omx_to_v4l2, profile_mpeg2_v4l2_to_omx);
244     reverse_map(profile_vp9_omx_to_v4l2, profile_vp9_v4l2_to_omx);
245     reverse_map(profile_tme_omx_to_v4l2, profile_tme_v4l2_to_omx);
246     reverse_map(level_avc_omx_to_v4l2, level_avc_v4l2_to_omx);
247     reverse_map(level_hevc_omx_to_v4l2, level_hevc_v4l2_to_omx);
248     reverse_map(level_vp8_omx_to_v4l2, level_vp8_v4l2_to_omx);
249     reverse_map(level_mpeg2_omx_to_v4l2, level_mpeg2_v4l2_to_omx);
250     reverse_map(level_vp9_omx_to_v4l2, level_vp9_v4l2_to_omx);
251     reverse_map(level_tme_omx_to_v4l2, level_tme_v4l2_to_omx);
252 }
253 
find_map(const codec_map & map,int key,pl_map ** value_map)254 bool profile_level_converter::find_map(const codec_map &map, int key, pl_map **value_map)
255 {
256     auto map_it = map.find (key);
257     if (map_it == map.end()) {
258         DEBUG_PRINT_ERROR(" Invalid codec : %d Cannot find map for this codec", key);
259         return false;
260     }
261     *value_map = map_it->second;
262     return true;
263 }
264 
find_item(const pl_map & map,int key,int * value)265 bool profile_level_converter::find_item(const pl_map &map, int key, int *value)
266 {
267     auto it = map.find (key);
268     if (it == map.end()) {
269         DEBUG_PRINT_ERROR(" Invalid key : %d Cannot find key in map ", key);
270         return false;
271     }
272     *value = it->second;
273     return true;
274 }
275 
convert_v4l2_profile_to_omx(int codec,int v4l2_profile,int * omx_profile)276 bool profile_level_converter::convert_v4l2_profile_to_omx(int codec, int v4l2_profile, int *omx_profile)
277 {
278     pl_map *profile_map;
279 
280     if (!find_map(profile_v4l2_to_omx_map, codec, &profile_map))
281         return false;
282 
283     return find_item(*profile_map, v4l2_profile, omx_profile);
284 }
285 
convert_omx_profile_to_v4l2(int codec,int omx_profile,int * v4l2_profile)286 bool profile_level_converter::convert_omx_profile_to_v4l2(int codec, int omx_profile, int *v4l2_profile)
287 {
288     pl_map *profile_map;
289 
290     if (!find_map(profile_omx_to_v4l2_map, codec, &profile_map))
291         return false;
292 
293     return find_item(*profile_map, omx_profile, v4l2_profile);
294 }
295 
convert_v4l2_level_to_omx(int codec,int v4l2_level,int * omx_level)296 bool profile_level_converter::convert_v4l2_level_to_omx(int codec, int v4l2_level, int *omx_level)
297 {
298     pl_map *level_map;
299 
300     if (!find_map(level_v4l2_to_omx_map, codec, &level_map))
301         return false;
302 
303     return find_item(*level_map, v4l2_level, omx_level);
304 }
305 
convert_omx_level_to_v4l2(int codec,int omx_level,int * v4l2_level)306 bool profile_level_converter::convert_omx_level_to_v4l2(int codec, int omx_level, int *v4l2_level)
307 {
308     pl_map *level_map;
309 
310     if (!find_map(level_omx_to_v4l2_map, codec, &level_map))
311         return false;
312 
313     return find_item(*level_map, omx_level, v4l2_level);
314 }
315 
get_gralloc_format_as_string(char * buf,int buf_len,int format)316 void get_gralloc_format_as_string(char * buf, int buf_len, int format) {
317     switch (format) {
318         case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
319             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_NV12_ENCODEABLE");
320             break;
321         case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
322             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC");
323             break;
324         case HAL_PIXEL_FORMAT_RGBA_8888:
325             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_RGBA_8888");
326             break;
327         case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m:
328             snprintf(buf, buf_len, "QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m");
329             break;
330         case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
331             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC");
332             break;
333         case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
334             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS");
335             break;
336         case QOMX_COLOR_FormatYVU420SemiPlanar:
337             snprintf(buf, buf_len, "QOMX_COLOR_FormatYVU420SemiPlanar");
338             break;
339         default:
340             snprintf(buf, buf_len, "no match found for gralloc format 0x%d",
341                     format);
342             return;
343     }
344 }
345 
get_v4l2_color_format_as_string(char * buf,int buf_len,unsigned long v4l2Pixformat)346 void get_v4l2_color_format_as_string(char * buf, int buf_len, unsigned long v4l2Pixformat) {
347     switch (v4l2Pixformat) {
348         case V4L2_PIX_FMT_RGB32:
349             snprintf(buf, buf_len, "V4L2_PIX_FMT_RGB32");
350             break;
351         case V4L2_PIX_FMT_RGBA8888_UBWC:
352             snprintf(buf, buf_len, "V4L2_PIX_FMT_RGBA8888_UBWC");
353             break;
354         case V4L2_PIX_FMT_NV12:
355             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12");
356             break;
357         case V4L2_PIX_FMT_NV12_UBWC:
358             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12_UBWC");
359             break;
360         case V4L2_PIX_FMT_NV12_TP10_UBWC:
361             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12_TP10_UBWC");
362             break;
363         case V4L2_PIX_FMT_SDE_Y_CBCR_H2V2_P010_VENUS:
364             snprintf(buf, buf_len, "V4L2_PIX_FMT_SDE_Y_CBCR_H2V2_P010_VENUS");
365             break;
366         case V4L2_PIX_FMT_NV21:
367             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV21");
368             break;
369         case V4L2_PIX_FMT_NV12_P010_UBWC:
370             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12_P010_UBWC");
371             break;
372         default:
373             snprintf(buf, buf_len, "no match found for v4l2 pix format 0x%lx",
374                     v4l2Pixformat);
375             return;
376     }
377 }
378 
IvfFileHeader()379 IvfFileHeader:: IvfFileHeader() :
380     signature{'D','K','I','F'},
381     version(),
382     size(32),
383     fourCC{'V','P','8','0'},
384     width(0),
385     height(0),
386     rate(0),
387     scale(0),
388     frameCount(0),
389     unused()
390 {
391 }
392 
IvfFileHeader(bool isVp9,int width,int height,int rate,int scale,int frameCount)393 IvfFileHeader:: IvfFileHeader(bool isVp9, int width, int height,
394                     int rate, int scale, int frameCount) :
395     IvfFileHeader() {
396     this->width = width;
397     this->height = height;
398     this->rate = rate;
399     this->scale = scale;
400     this->frameCount = frameCount;
401     fourCC[2] = isVp9 ? '9' : '8';
402 }
403 
IvfFrameHeader()404 IvfFrameHeader:: IvfFrameHeader(): filledLen(), timeStamp() {}
405 
IvfFrameHeader(uint32_t filledLen,uint64_t timeStamp)406 IvfFrameHeader:: IvfFrameHeader(uint32_t filledLen, uint64_t timeStamp) :
407     filledLen(filledLen),
408     timeStamp(timeStamp) {
409 }
410