1 /*--------------------------------------------------------------------------
2 Copyright (c) 2017-2020 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_VIDEO_HEVC_PROFILE_MAIN},
61             {OMX_VIDEO_HEVCProfileMain10,
62                         V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10},
63             {OMX_VIDEO_HEVCProfileMainStill,
64                         V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE},
65             {OMX_VIDEO_HEVCProfileMain10HDR10,
66                         V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10},
67             {OMX_VIDEO_HEVCProfileMain10HDR10Plus,
68                         V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10},
69         });
70 
71 pl_map profile_level_converter::profile_hevc_v4l2_to_omx ({});
72 
73 pl_map profile_level_converter::profile_mpeg2_omx_to_v4l2 ({
74             {OMX_VIDEO_MPEG2ProfileSimple,
75                         V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_SIMPLE},
76             {OMX_VIDEO_MPEG2ProfileMain,
77                         V4L2_MPEG_VIDC_VIDEO_MPEG2_PROFILE_MAIN},
78         });
79 
80 pl_map profile_level_converter::profile_mpeg2_v4l2_to_omx ({});
81 
82 pl_map profile_level_converter::profile_vp8_omx_to_v4l2 ({
83             {OMX_VIDEO_VP8ProfileMain, V4L2_MPEG_VIDEO_VP8_PROFILE_0},
84         });
85 
86 pl_map profile_level_converter::profile_vp8_v4l2_to_omx ({});
87 
88 pl_map profile_level_converter::profile_vp9_omx_to_v4l2 ({
89             {OMX_VIDEO_VP9Profile0, V4L2_MPEG_VIDEO_VP9_PROFILE_0},
90             {OMX_VIDEO_VP9Profile2, V4L2_MPEG_VIDEO_VP9_PROFILE_2},
91             {OMX_VIDEO_VP9Profile2HDR, V4L2_MPEG_VIDEO_VP9_PROFILE_2},
92             {OMX_VIDEO_VP9Profile2HDR10Plus, V4L2_MPEG_VIDEO_VP9_PROFILE_2},
93         });
94 
95 pl_map profile_level_converter::profile_vp9_v4l2_to_omx ({});
96 
97 pl_map profile_level_converter::level_avc_omx_to_v4l2 ({
98             {OMX_VIDEO_AVCLevel1, V4L2_MPEG_VIDEO_H264_LEVEL_1_0},
99             {OMX_VIDEO_AVCLevel11, V4L2_MPEG_VIDEO_H264_LEVEL_1_1},
100             {OMX_VIDEO_AVCLevel12, V4L2_MPEG_VIDEO_H264_LEVEL_1_2},
101             {OMX_VIDEO_AVCLevel13, V4L2_MPEG_VIDEO_H264_LEVEL_1_3},
102             {OMX_VIDEO_AVCLevel1b, V4L2_MPEG_VIDEO_H264_LEVEL_1B},
103             {OMX_VIDEO_AVCLevel2, V4L2_MPEG_VIDEO_H264_LEVEL_2_0},
104             {OMX_VIDEO_AVCLevel21, V4L2_MPEG_VIDEO_H264_LEVEL_2_1},
105             {OMX_VIDEO_AVCLevel22, V4L2_MPEG_VIDEO_H264_LEVEL_2_2},
106             {OMX_VIDEO_AVCLevel3, V4L2_MPEG_VIDEO_H264_LEVEL_3_0},
107             {OMX_VIDEO_AVCLevel31, V4L2_MPEG_VIDEO_H264_LEVEL_3_1},
108             {OMX_VIDEO_AVCLevel32, V4L2_MPEG_VIDEO_H264_LEVEL_3_2},
109             {OMX_VIDEO_AVCLevel4, V4L2_MPEG_VIDEO_H264_LEVEL_4_0},
110             {OMX_VIDEO_AVCLevel41, V4L2_MPEG_VIDEO_H264_LEVEL_4_1},
111             {OMX_VIDEO_AVCLevel42, V4L2_MPEG_VIDEO_H264_LEVEL_4_2},
112             {OMX_VIDEO_AVCLevel5, V4L2_MPEG_VIDEO_H264_LEVEL_5_0},
113             {OMX_VIDEO_AVCLevel51, V4L2_MPEG_VIDEO_H264_LEVEL_5_1},
114             {OMX_VIDEO_AVCLevel52, V4L2_MPEG_VIDEO_H264_LEVEL_5_2},
115             {OMX_VIDEO_AVCLevel6, V4L2_MPEG_VIDEO_H264_LEVEL_6_0},
116             {OMX_VIDEO_AVCLevel61, V4L2_MPEG_VIDEO_H264_LEVEL_6_1},
117             {OMX_VIDEO_AVCLevel62, V4L2_MPEG_VIDEO_H264_LEVEL_6_2},
118         });
119 
120 pl_map profile_level_converter::level_avc_v4l2_to_omx ({});
121 
122 pl_map profile_level_converter::level_hevc_omx_to_v4l2 ({
123             {OMX_VIDEO_HEVCMainTierLevel1,  V4L2_MPEG_VIDEO_HEVC_LEVEL_1},
124             {OMX_VIDEO_HEVCMainTierLevel2,  V4L2_MPEG_VIDEO_HEVC_LEVEL_2},
125             {OMX_VIDEO_HEVCMainTierLevel21, V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1},
126             {OMX_VIDEO_HEVCMainTierLevel3,  V4L2_MPEG_VIDEO_HEVC_LEVEL_3},
127             {OMX_VIDEO_HEVCMainTierLevel31, V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1},
128             {OMX_VIDEO_HEVCMainTierLevel4,  V4L2_MPEG_VIDEO_HEVC_LEVEL_4},
129             {OMX_VIDEO_HEVCMainTierLevel41, V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1},
130             {OMX_VIDEO_HEVCMainTierLevel5,  V4L2_MPEG_VIDEO_HEVC_LEVEL_5},
131             {OMX_VIDEO_HEVCMainTierLevel51, V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1},
132             {OMX_VIDEO_HEVCMainTierLevel52, V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2},
133             {OMX_VIDEO_HEVCMainTierLevel6,  V4L2_MPEG_VIDEO_HEVC_LEVEL_6},
134             {OMX_VIDEO_HEVCMainTierLevel61, V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1},
135             {OMX_VIDEO_HEVCMainTierLevel62, V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2},
136         });
137 
138 pl_map profile_level_converter::level_hevc_v4l2_to_omx ({});
139 
140 pl_map profile_level_converter::level_vp8_omx_to_v4l2 ({
141             {OMX_VIDEO_VP8Level_Version0, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_0},
142             {OMX_VIDEO_VP8Level_Version1, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_1},
143             {OMX_VIDEO_VP8Level_Version2, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_2},
144             {OMX_VIDEO_VP8Level_Version3, V4L2_MPEG_VIDC_VIDEO_VP8_VERSION_3},
145         });
146 
147 pl_map profile_level_converter::level_vp8_v4l2_to_omx ({});
148 
149 pl_map profile_level_converter::level_mpeg2_omx_to_v4l2 ({
150             {OMX_VIDEO_MPEG2LevelLL, V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_0},
151             {OMX_VIDEO_MPEG2LevelML, V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_1},
152             {OMX_VIDEO_MPEG2LevelHL, V4L2_MPEG_VIDC_VIDEO_MPEG2_LEVEL_2},
153         });
154 
155 pl_map profile_level_converter::level_mpeg2_v4l2_to_omx ({});
156 
157 pl_map profile_level_converter::level_vp9_omx_to_v4l2 ({
158             {OMX_VIDEO_VP9Level1, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_1},
159             {OMX_VIDEO_VP9Level11, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_11},
160             {OMX_VIDEO_VP9Level2, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_2},
161             {OMX_VIDEO_VP9Level21, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_21},
162             {OMX_VIDEO_VP9Level3, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_3},
163             {OMX_VIDEO_VP9Level31, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_31},
164             {OMX_VIDEO_VP9Level4, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_4},
165             {OMX_VIDEO_VP9Level41, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_41},
166             {OMX_VIDEO_VP9Level5, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_5},
167             {OMX_VIDEO_VP9Level51, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_51},
168             {OMX_VIDEO_VP9Level6, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_6},
169             {OMX_VIDEO_VP9Level61, V4L2_MPEG_VIDC_VIDEO_VP9_LEVEL_61},
170         });
171 
172 pl_map profile_level_converter::level_vp9_v4l2_to_omx ({});
173 
174 codec_map profile_level_converter::profile_omx_to_v4l2_map ({
175             {V4L2_PIX_FMT_H264, &profile_avc_omx_to_v4l2},
176             {V4L2_PIX_FMT_HEVC, &profile_hevc_omx_to_v4l2},
177             {V4L2_PIX_FMT_MPEG2, &profile_mpeg2_omx_to_v4l2},
178             {V4L2_PIX_FMT_VP8, &profile_vp8_omx_to_v4l2},
179             {V4L2_PIX_FMT_VP9, &profile_vp9_omx_to_v4l2},
180         });
181 
182 codec_map profile_level_converter::profile_v4l2_to_omx_map ({
183             {V4L2_PIX_FMT_H264, &profile_avc_v4l2_to_omx},
184             {V4L2_PIX_FMT_HEVC, &profile_hevc_v4l2_to_omx},
185             {V4L2_PIX_FMT_MPEG2, &profile_mpeg2_v4l2_to_omx},
186             {V4L2_PIX_FMT_VP8, &profile_vp8_v4l2_to_omx},
187             {V4L2_PIX_FMT_VP9, &profile_vp9_v4l2_to_omx},
188         });
189 
190 codec_map profile_level_converter::level_omx_to_v4l2_map ({
191             {V4L2_PIX_FMT_H264, &level_avc_omx_to_v4l2},
192             {V4L2_PIX_FMT_HEVC, &level_hevc_omx_to_v4l2},
193             {V4L2_PIX_FMT_MPEG2, &level_mpeg2_omx_to_v4l2},
194             {V4L2_PIX_FMT_VP8, &level_vp8_omx_to_v4l2},
195             {V4L2_PIX_FMT_VP9, &level_vp9_omx_to_v4l2},
196         });
197 
198 codec_map profile_level_converter::level_v4l2_to_omx_map ({
199             {V4L2_PIX_FMT_H264, &level_avc_v4l2_to_omx},
200             {V4L2_PIX_FMT_HEVC, &level_hevc_v4l2_to_omx},
201             {V4L2_PIX_FMT_MPEG2, &level_mpeg2_v4l2_to_omx},
202             {V4L2_PIX_FMT_VP8, &level_vp8_v4l2_to_omx},
203             {V4L2_PIX_FMT_VP9, &level_vp9_v4l2_to_omx},
204         });
205 
reverse_map(pl_map source_map,pl_map & dest_map)206 void reverse_map(pl_map source_map, pl_map &dest_map)
207 {
208     pl_map::iterator it;
209 
210     for(it = source_map.begin(); it != source_map.end(); it++) {
211         dest_map[it->second] = it->first;
212     }
213     return;
214 }
215 
init()216 void profile_level_converter::init()
217 {
218     reverse_map(profile_avc_omx_to_v4l2, profile_avc_v4l2_to_omx);
219     reverse_map(profile_hevc_omx_to_v4l2, profile_hevc_v4l2_to_omx);
220     reverse_map(profile_mpeg2_omx_to_v4l2, profile_mpeg2_v4l2_to_omx);
221     reverse_map(profile_vp8_omx_to_v4l2, profile_vp8_v4l2_to_omx);
222     reverse_map(profile_vp9_omx_to_v4l2, profile_vp9_v4l2_to_omx);
223     reverse_map(level_avc_omx_to_v4l2, level_avc_v4l2_to_omx);
224     reverse_map(level_hevc_omx_to_v4l2, level_hevc_v4l2_to_omx);
225     reverse_map(level_vp8_omx_to_v4l2, level_vp8_v4l2_to_omx);
226     reverse_map(level_mpeg2_omx_to_v4l2, level_mpeg2_v4l2_to_omx);
227     reverse_map(level_vp9_omx_to_v4l2, level_vp9_v4l2_to_omx);
228 }
229 
find_map(const codec_map & map,int key,pl_map ** value_map)230 bool profile_level_converter::find_map(const codec_map &map, int key, pl_map **value_map)
231 {
232     auto map_it = map.find (key);
233     if (map_it == map.end()) {
234         DEBUG_PRINT_ERROR(" Invalid codec : %d Cannot find map for this codec", key);
235         return false;
236     }
237     *value_map = map_it->second;
238     return true;
239 }
240 
find_item(const pl_map & map,int key,int * value)241 bool profile_level_converter::find_item(const pl_map &map, int key, int *value)
242 {
243     auto it = map.find (key);
244     if (it == map.end()) {
245         DEBUG_PRINT_ERROR(" Invalid key : %d Cannot find key in map ", key);
246         return false;
247     }
248     *value = it->second;
249     return true;
250 }
251 
convert_v4l2_profile_to_omx(int codec,int v4l2_profile,int * omx_profile)252 bool profile_level_converter::convert_v4l2_profile_to_omx(int codec, int v4l2_profile, int *omx_profile)
253 {
254     pl_map *profile_map;
255 
256     if (!find_map(profile_v4l2_to_omx_map, codec, &profile_map))
257         return false;
258 
259     return find_item(*profile_map, v4l2_profile, omx_profile);
260 }
261 
convert_omx_profile_to_v4l2(int codec,int omx_profile,int * v4l2_profile)262 bool profile_level_converter::convert_omx_profile_to_v4l2(int codec, int omx_profile, int *v4l2_profile)
263 {
264     pl_map *profile_map;
265 
266     if (!find_map(profile_omx_to_v4l2_map, codec, &profile_map))
267         return false;
268 
269     return find_item(*profile_map, omx_profile, v4l2_profile);
270 }
271 
convert_v4l2_level_to_omx(int codec,int v4l2_level,int * omx_level)272 bool profile_level_converter::convert_v4l2_level_to_omx(int codec, int v4l2_level, int *omx_level)
273 {
274     pl_map *level_map;
275 
276     if (!find_map(level_v4l2_to_omx_map, codec, &level_map))
277         return false;
278 
279     return find_item(*level_map, v4l2_level, omx_level);
280 }
281 
find_tier(int codec,int omx_level,unsigned int * tier)282 bool profile_level_converter::find_tier(int codec, int omx_level, unsigned int *tier)
283 {
284     /* Default is HIGH tier */
285     *tier = V4L2_MPEG_VIDEO_HEVC_TIER_HIGH;
286 
287     if(codec == V4L2_PIX_FMT_HEVC) {
288         unsigned int level_main_mask = OMX_VIDEO_HEVCMainTierLevel1  |
289                                        OMX_VIDEO_HEVCMainTierLevel2  |
290                                        OMX_VIDEO_HEVCMainTierLevel21 |
291                                        OMX_VIDEO_HEVCMainTierLevel3  |
292                                        OMX_VIDEO_HEVCMainTierLevel31 |
293                                        OMX_VIDEO_HEVCMainTierLevel4  |
294                                        OMX_VIDEO_HEVCMainTierLevel41 |
295                                        OMX_VIDEO_HEVCMainTierLevel5  |
296                                        OMX_VIDEO_HEVCMainTierLevel51 |
297                                        OMX_VIDEO_HEVCMainTierLevel52 |
298                                        OMX_VIDEO_HEVCMainTierLevel6  |
299                                        OMX_VIDEO_HEVCMainTierLevel61 |
300                                        OMX_VIDEO_HEVCMainTierLevel62;
301         unsigned int bit_set = level_main_mask & (unsigned int)omx_level;
302         if (bit_set && (bit_set & (bit_set-1)) == 0) {
303           *tier = V4L2_MPEG_VIDEO_HEVC_TIER_MAIN;
304         }
305     }
306     return true;
307 }
308 
convert_omx_level_to_v4l2(int codec,int omx_level,int * v4l2_level)309 bool profile_level_converter::convert_omx_level_to_v4l2(int codec, int omx_level, int *v4l2_level)
310 {
311     pl_map *level_map;
312 
313     if (!find_map(level_omx_to_v4l2_map, codec, &level_map))
314         return false;
315 
316     return find_item(*level_map, omx_level, v4l2_level);
317 }
318 
get_gralloc_format_as_string(char * buf,int buf_len,int format)319 void get_gralloc_format_as_string(char * buf, int buf_len, int format) {
320     switch (format) {
321         case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
322             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_NV12_ENCODEABLE");
323             break;
324         case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
325             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC");
326             break;
327         case HAL_PIXEL_FORMAT_RGBA_8888:
328             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_RGBA_8888");
329             break;
330         case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m:
331             snprintf(buf, buf_len, "QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m");
332             break;
333         case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
334             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC");
335             break;
336         case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
337             snprintf(buf, buf_len, "HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS");
338             break;
339         case QOMX_COLOR_FormatYVU420SemiPlanar:
340             snprintf(buf, buf_len, "QOMX_COLOR_FormatYVU420SemiPlanar");
341             break;
342         default:
343             snprintf(buf, buf_len, "no match found for gralloc format 0x%d",
344                     format);
345             return;
346     }
347 }
348 
get_v4l2_color_format_as_string(char * buf,int buf_len,unsigned long v4l2Pixformat)349 void get_v4l2_color_format_as_string(char * buf, int buf_len, unsigned long v4l2Pixformat) {
350     switch (v4l2Pixformat) {
351         case V4L2_PIX_FMT_RGB32:
352             snprintf(buf, buf_len, "V4L2_PIX_FMT_RGB32");
353             break;
354         case V4L2_PIX_FMT_RGBA8888_UBWC:
355             snprintf(buf, buf_len, "V4L2_PIX_FMT_RGBA8888_UBWC");
356             break;
357         case V4L2_PIX_FMT_NV12:
358             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12");
359             break;
360         case V4L2_PIX_FMT_NV12_512:
361             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12_512");
362             break;
363         case V4L2_PIX_FMT_NV12_UBWC:
364             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12_UBWC");
365             break;
366         case V4L2_PIX_FMT_NV12_TP10_UBWC:
367             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12_TP10_UBWC");
368             break;
369         case V4L2_PIX_FMT_SDE_Y_CBCR_H2V2_P010_VENUS:
370             snprintf(buf, buf_len, "V4L2_PIX_FMT_SDE_Y_CBCR_H2V2_P010_VENUS");
371             break;
372         case V4L2_PIX_FMT_NV21:
373             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV21");
374             break;
375         case V4L2_PIX_FMT_NV12_P010_UBWC:
376             snprintf(buf, buf_len, "V4L2_PIX_FMT_NV12_P010_UBWC");
377             break;
378         default:
379             snprintf(buf, buf_len, "no match found for v4l2 pix format 0x%lx",
380                     v4l2Pixformat);
381             return;
382     }
383 }
384 
IvfFileHeader()385 IvfFileHeader:: IvfFileHeader() :
386     signature{'D','K','I','F'},
387     version(),
388     size(32),
389     fourCC{'V','P','8','0'},
390     width(0),
391     height(0),
392     rate(0),
393     scale(0),
394     frameCount(0),
395     unused()
396 {
397 }
398 
IvfFileHeader(bool isVp9,int width,int height,int rate,int scale,int frameCount)399 IvfFileHeader:: IvfFileHeader(bool isVp9, int width, int height,
400                     int rate, int scale, int frameCount) :
401     IvfFileHeader() {
402     this->width = width;
403     this->height = height;
404     this->rate = rate;
405     this->scale = scale;
406     this->frameCount = frameCount;
407     fourCC[2] = isVp9 ? '9' : '8';
408 }
409 
IvfFrameHeader()410 IvfFrameHeader:: IvfFrameHeader(): filledLen(), timeStamp() {}
411 
IvfFrameHeader(uint32_t filledLen,uint64_t timeStamp)412 IvfFrameHeader:: IvfFrameHeader(uint32_t filledLen, uint64_t timeStamp) :
413     filledLen(filledLen),
414     timeStamp(timeStamp) {
415 }
416 
do_sync_ioctl(int fd,struct dma_buf_sync * sync)417 void do_sync_ioctl(int fd, struct dma_buf_sync* sync) {
418 #ifdef USE_ION
419     int rc = ioctl(fd, DMA_BUF_IOCTL_SYNC, sync);
420     if (rc < 0) {
421         DEBUG_PRINT_ERROR("Failed DMA_BUF_IOCTL_SYNC");
422         return;
423     }
424 #else
425     (void)fd, (void)sync;
426 #endif
427 }
428