1 /**************************************************************************
2 *
3 * Copyright 2013 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Christian König <christian.koenig@amd.com>
31 *
32 */
33
34
35 #include <assert.h>
36
37 #include <OMX_Video.h>
38
39 /* bellagio defines a DEBUG macro that we don't want */
40 #ifndef DEBUG
41 #include <bellagio/omxcore.h>
42 #undef DEBUG
43 #else
44 #include <bellagio/omxcore.h>
45 #endif
46
47 #include "pipe/p_screen.h"
48 #include "pipe/p_video_codec.h"
49 #include "util/u_memory.h"
50 #include "util/u_surface.h"
51 #include "vl/vl_video_buffer.h"
52 #include "vl/vl_vlc.h"
53
54 #include "entrypoint.h"
55 #include "vid_dec.h"
56 #include "vid_omx_common.h"
57 #include "vid_dec_h264_common.h"
58
59 static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name);
60 static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp);
61 static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param);
62 static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param);
63 static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE *comp, internalRequestMessageType *msg);
64 static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf);
65 static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf);
66 static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, OMX_BUFFERHEADERTYPE* output);
67
vid_dec_LoaderComponent(stLoaderComponentType * comp)68 OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp)
69 {
70 comp->componentVersion.s.nVersionMajor = 0;
71 comp->componentVersion.s.nVersionMinor = 0;
72 comp->componentVersion.s.nRevision = 0;
73 comp->componentVersion.s.nStep = 1;
74 comp->name_specific_length = 4;
75
76 comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
77 if (comp->name == NULL)
78 goto error;
79
80 comp->name_specific = CALLOC(comp->name_specific_length, sizeof(char *));
81 if (comp->name_specific == NULL)
82 goto error;
83
84 comp->role_specific = CALLOC(comp->name_specific_length, sizeof(char *));
85 if (comp->role_specific == NULL)
86 goto error;
87
88 comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
89 if (comp->name_specific[0] == NULL)
90 goto error_specific;
91
92 comp->name_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
93 if (comp->name_specific[1] == NULL)
94 goto error_specific;
95
96 comp->name_specific[2] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
97 if (comp->name_specific[2] == NULL)
98 goto error_specific;
99
100 comp->name_specific[3] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
101 if (comp->name_specific[3] == NULL)
102 goto error_specific;
103
104 comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
105 if (comp->role_specific[0] == NULL)
106 goto error_specific;
107
108 comp->role_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
109 if (comp->role_specific[1] == NULL)
110 goto error_specific;
111
112 comp->role_specific[2] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
113 if (comp->role_specific[2] == NULL)
114 goto error_specific;
115
116 comp->role_specific[3] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
117 if (comp->role_specific[3] == NULL)
118 goto error_specific;
119
120 strcpy(comp->name, OMX_VID_DEC_BASE_NAME);
121 strcpy(comp->name_specific[0], OMX_VID_DEC_MPEG2_NAME);
122 strcpy(comp->name_specific[1], OMX_VID_DEC_AVC_NAME);
123 strcpy(comp->name_specific[2], OMX_VID_DEC_HEVC_NAME);
124 strcpy(comp->name_specific[3], OMX_VID_DEC_AV1_NAME);
125
126 strcpy(comp->role_specific[0], OMX_VID_DEC_MPEG2_ROLE);
127 strcpy(comp->role_specific[1], OMX_VID_DEC_AVC_ROLE);
128 strcpy(comp->role_specific[2], OMX_VID_DEC_HEVC_ROLE);
129 strcpy(comp->role_specific[3], OMX_VID_DEC_AV1_ROLE);
130
131 comp->constructor = vid_dec_Constructor;
132
133 return OMX_ErrorNone;
134
135 error_specific:
136 FREE(comp->role_specific[3]);
137 FREE(comp->role_specific[2]);
138 FREE(comp->role_specific[1]);
139 FREE(comp->role_specific[0]);
140 FREE(comp->name_specific[3]);
141 FREE(comp->name_specific[2]);
142 FREE(comp->name_specific[1]);
143 FREE(comp->name_specific[0]);
144
145 error:
146 FREE(comp->role_specific);
147 FREE(comp->name_specific);
148
149 FREE(comp->name);
150
151 return OMX_ErrorInsufficientResources;
152 }
153
vid_dec_Constructor(OMX_COMPONENTTYPE * comp,OMX_STRING name)154 static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name)
155 {
156 vid_dec_PrivateType *priv;
157 omx_base_video_PortType *port;
158 struct pipe_screen *screen;
159 OMX_ERRORTYPE r;
160 int i;
161
162 assert(!comp->pComponentPrivate);
163
164 priv = comp->pComponentPrivate = CALLOC(1, sizeof(vid_dec_PrivateType));
165 if (!priv)
166 return OMX_ErrorInsufficientResources;
167
168 r = omx_base_filter_Constructor(comp, name);
169 if (r)
170 return r;
171
172 priv->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
173
174 if (!strcmp(name, OMX_VID_DEC_MPEG2_NAME))
175 priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN;
176
177 if (!strcmp(name, OMX_VID_DEC_AVC_NAME))
178 priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
179
180 if (!strcmp(name, OMX_VID_DEC_HEVC_NAME))
181 priv->profile = PIPE_VIDEO_PROFILE_HEVC_MAIN;
182
183 if (!strcmp(name, OMX_VID_DEC_AV1_NAME))
184 priv->profile = PIPE_VIDEO_PROFILE_AV1_MAIN;
185
186 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
187 priv->BufferMgmtCallback = vid_dec_av1_FrameDecoded;
188 else
189 priv->BufferMgmtCallback = vid_dec_FrameDecoded;
190 priv->messageHandler = vid_dec_MessageHandler;
191 priv->destructor = vid_dec_Destructor;
192
193 comp->SetParameter = vid_dec_SetParameter;
194 comp->GetParameter = vid_dec_GetParameter;
195
196 priv->screen = omx_get_screen();
197 if (!priv->screen)
198 return OMX_ErrorInsufficientResources;
199
200 screen = priv->screen->pscreen;
201 priv->pipe = pipe_create_multimedia_context(screen);
202 if (!priv->pipe)
203 return OMX_ErrorInsufficientResources;
204
205 if (!vl_compositor_init(&priv->compositor, priv->pipe)) {
206 priv->pipe->destroy(priv->pipe);
207 priv->pipe = NULL;
208 return OMX_ErrorInsufficientResources;
209 }
210
211 if (!vl_compositor_init_state(&priv->cstate, priv->pipe)) {
212 vl_compositor_cleanup(&priv->compositor);
213 priv->pipe->destroy(priv->pipe);
214 priv->pipe = NULL;
215 return OMX_ErrorInsufficientResources;
216 }
217
218 priv->sPortTypesParam[OMX_PortDomainVideo].nStartPortNumber = 0;
219 priv->sPortTypesParam[OMX_PortDomainVideo].nPorts = 2;
220 priv->ports = CALLOC(2, sizeof(omx_base_PortType *));
221 if (!priv->ports)
222 return OMX_ErrorInsufficientResources;
223
224 for (i = 0; i < 2; ++i) {
225 priv->ports[i] = CALLOC(1, sizeof(omx_base_video_PortType));
226 if (!priv->ports[i])
227 return OMX_ErrorInsufficientResources;
228
229 base_video_port_Constructor(comp, &priv->ports[i], i, i == 0);
230 }
231
232 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
233 strcpy(port->sPortParam.format.video.cMIMEType,"video/MPEG2");
234 port->sPortParam.nBufferCountMin = 8;
235 port->sPortParam.nBufferCountActual = 8;
236 port->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
237 port->sPortParam.format.video.nFrameWidth = 176;
238 port->sPortParam.format.video.nFrameHeight = 144;
239 port->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
240 port->sVideoParam.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
241 port->Port_SendBufferFunction = vid_dec_DecodeBuffer;
242 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) {
243 port->Port_AllocateBuffer = vid_dec_av1_AllocateInBuffer;
244 port->Port_UseBuffer = vid_dec_av1_UseInBuffer;
245 }
246
247 port->Port_FreeBuffer = vid_dec_FreeDecBuffer;
248 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
249 port->sPortParam.nBufferCountActual = 8;
250 port->sPortParam.nBufferCountMin = 4;
251 port->sPortParam.format.video.nFrameWidth = 176;
252 port->sPortParam.format.video.nFrameHeight = 144;
253 port->sPortParam.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
254 port->sVideoParam.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
255
256 return OMX_ErrorNone;
257 }
258
vid_dec_Destructor(OMX_COMPONENTTYPE * comp)259 static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp)
260 {
261 vid_dec_PrivateType* priv = comp->pComponentPrivate;
262 int i;
263
264 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
265 vid_dec_av1_ReleaseTasks(priv);
266
267 if (priv->ports) {
268 for (i = 0; i < priv->sPortTypesParam[OMX_PortDomainVideo].nPorts; ++i) {
269 if(priv->ports[i])
270 priv->ports[i]->PortDestructor(priv->ports[i]);
271 }
272 FREE(priv->ports);
273 priv->ports=NULL;
274 }
275
276 if (priv->pipe) {
277 vl_compositor_cleanup_state(&priv->cstate);
278 vl_compositor_cleanup(&priv->compositor);
279 priv->pipe->destroy(priv->pipe);
280 }
281
282 if (priv->screen)
283 omx_put_screen();
284
285 return omx_workaround_Destructor(comp);
286 }
287
vid_dec_SetParameter(OMX_HANDLETYPE handle,OMX_INDEXTYPE idx,OMX_PTR param)288 static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param)
289 {
290 OMX_COMPONENTTYPE *comp = handle;
291 vid_dec_PrivateType *priv = comp->pComponentPrivate;
292 OMX_ERRORTYPE r;
293
294 if (!param)
295 return OMX_ErrorBadParameter;
296
297 switch(idx) {
298 case OMX_IndexParamPortDefinition: {
299 OMX_PARAM_PORTDEFINITIONTYPE *def = param;
300
301 r = omx_base_component_SetParameter(handle, idx, param);
302 if (r)
303 return r;
304
305 if (def->nPortIndex == OMX_BASE_FILTER_INPUTPORT_INDEX) {
306 omx_base_video_PortType *port;
307 unsigned framesize = def->format.video.nFrameWidth * def->format.video.nFrameHeight;
308
309 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
310 port->sPortParam.nBufferSize = framesize * 512 / (16*16);
311
312 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
313 port->sPortParam.format.video.nFrameWidth = def->format.video.nFrameWidth;
314 port->sPortParam.format.video.nFrameHeight = def->format.video.nFrameHeight;
315 port->sPortParam.format.video.nStride = def->format.video.nFrameWidth;
316 port->sPortParam.format.video.nSliceHeight = def->format.video.nFrameHeight;
317 port->sPortParam.nBufferSize = framesize*3/2;
318
319 priv->callbacks->EventHandler(comp, priv->callbackData, OMX_EventPortSettingsChanged,
320 OMX_BASE_FILTER_OUTPUTPORT_INDEX, 0, NULL);
321 }
322 break;
323 }
324 case OMX_IndexParamStandardComponentRole: {
325 OMX_PARAM_COMPONENTROLETYPE *role = param;
326
327 r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE));
328 if (r)
329 return r;
330
331 if (!strcmp((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE)) {
332 priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN;
333 } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_AVC_ROLE)) {
334 priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
335 } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_HEVC_ROLE)) {
336 priv->profile = PIPE_VIDEO_PROFILE_HEVC_MAIN;
337 } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_AV1_ROLE)) {
338 priv->profile = PIPE_VIDEO_PROFILE_AV1_MAIN;
339 } else {
340 return OMX_ErrorBadParameter;
341 }
342
343 break;
344 }
345 case OMX_IndexParamVideoPortFormat: {
346 OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param;
347 omx_base_video_PortType *port;
348
349 r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
350 if (r)
351 return r;
352
353 if (format->nPortIndex > 1)
354 return OMX_ErrorBadPortIndex;
355
356 port = (omx_base_video_PortType *)priv->ports[format->nPortIndex];
357 memcpy(&port->sVideoParam, format, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
358 break;
359 }
360 default:
361 return omx_base_component_SetParameter(handle, idx, param);
362 }
363 return OMX_ErrorNone;
364 }
365
vid_dec_GetParameter(OMX_HANDLETYPE handle,OMX_INDEXTYPE idx,OMX_PTR param)366 static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param)
367 {
368 OMX_COMPONENTTYPE *comp = handle;
369 vid_dec_PrivateType *priv = comp->pComponentPrivate;
370 OMX_ERRORTYPE r;
371
372 if (!param)
373 return OMX_ErrorBadParameter;
374
375 switch(idx) {
376 case OMX_IndexParamStandardComponentRole: {
377 OMX_PARAM_COMPONENTROLETYPE *role = param;
378
379 r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE));
380 if (r)
381 return r;
382
383 if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN)
384 strcpy((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE);
385 else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH)
386 strcpy((char *)role->cRole, OMX_VID_DEC_AVC_ROLE);
387 else if (priv->profile == PIPE_VIDEO_PROFILE_HEVC_MAIN)
388 strcpy((char *)role->cRole, OMX_VID_DEC_HEVC_ROLE);
389 else if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
390 strcpy((char *)role->cRole, OMX_VID_DEC_AV1_ROLE);
391
392 break;
393 }
394
395 case OMX_IndexParamVideoInit:
396 r = checkHeader(param, sizeof(OMX_PORT_PARAM_TYPE));
397 if (r)
398 return r;
399
400 memcpy(param, &priv->sPortTypesParam[OMX_PortDomainVideo], sizeof(OMX_PORT_PARAM_TYPE));
401 break;
402
403 case OMX_IndexParamVideoPortFormat: {
404 OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param;
405 omx_base_video_PortType *port;
406
407 r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
408 if (r)
409 return r;
410
411 if (format->nPortIndex > 1)
412 return OMX_ErrorBadPortIndex;
413
414 port = (omx_base_video_PortType *)priv->ports[format->nPortIndex];
415 memcpy(format, &port->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
416 break;
417 }
418
419 default:
420 return omx_base_component_GetParameter(handle, idx, param);
421
422 }
423 return OMX_ErrorNone;
424 }
425
vid_dec_MessageHandler(OMX_COMPONENTTYPE * comp,internalRequestMessageType * msg)426 static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE* comp, internalRequestMessageType *msg)
427 {
428 vid_dec_PrivateType* priv = comp->pComponentPrivate;
429
430 if (msg->messageType == OMX_CommandStateSet) {
431 if ((msg->messageParam == OMX_StateIdle ) && (priv->state == OMX_StateLoaded)) {
432 if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN)
433 vid_dec_mpeg12_Init(priv);
434 else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH)
435 vid_dec_h264_Init(priv);
436 else if (priv->profile == PIPE_VIDEO_PROFILE_HEVC_MAIN)
437 vid_dec_h265_Init(priv);
438 else if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) {
439 vid_dec_av1_Init(priv);
440 }
441
442 } else if ((msg->messageParam == OMX_StateLoaded) && (priv->state == OMX_StateIdle)) {
443 if (priv->shadow) {
444 priv->shadow->destroy(priv->shadow);
445 priv->shadow = NULL;
446 }
447 if (priv->codec) {
448 priv->codec->destroy(priv->codec);
449 priv->codec = NULL;
450 }
451 }
452 }
453
454 return omx_base_component_MessageHandler(comp, msg);
455 }
456
vid_dec_DecodeBuffer(omx_base_PortType * port,OMX_BUFFERHEADERTYPE * buf)457 static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf)
458 {
459 OMX_COMPONENTTYPE* comp = port->standCompContainer;
460 vid_dec_PrivateType *priv = comp->pComponentPrivate;
461 unsigned i = priv->num_in_buffers++;
462 OMX_ERRORTYPE r;
463
464 priv->in_buffers[i] = buf;
465 priv->sizes[i] = buf->nFilledLen;
466 priv->inputs[i] = buf->pBuffer;
467 priv->timestamps[i] = buf->nTimeStamp;
468
469 while (priv->num_in_buffers > (!!(buf->nFlags & OMX_BUFFERFLAG_EOS) ? 0 : 1)) {
470 bool eos = !!(priv->in_buffers[0]->nFlags & OMX_BUFFERFLAG_EOS);
471 unsigned min_bits_left = eos ? 32 : MAX2(buf->nFilledLen * 8, 32);
472 struct vl_vlc vlc;
473
474 vl_vlc_init(&vlc, priv->num_in_buffers, priv->inputs, priv->sizes);
475
476 if (priv->slice)
477 priv->bytes_left = vl_vlc_bits_left(&vlc) / 8;
478
479 while (vl_vlc_bits_left(&vlc) > min_bits_left) {
480 priv->Decode(priv, &vlc, min_bits_left);
481 vl_vlc_fillbits(&vlc);
482 }
483
484 if (priv->slice) {
485 unsigned bytes = priv->bytes_left - vl_vlc_bits_left(&vlc) / 8;
486
487 priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base,
488 1, &priv->slice, &bytes);
489
490 if (priv->num_in_buffers)
491 priv->slice = priv->inputs[1];
492 else
493 priv->slice = NULL;
494 }
495
496 if (eos && priv->frame_started)
497 priv->EndFrame(priv);
498
499 if (priv->frame_finished) {
500 priv->frame_finished = false;
501 priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen;
502 r = base_port_SendBufferFunction(port, priv->in_buffers[0]);
503 } else if (eos) {
504 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
505 vid_dec_av1_FreeInputPortPrivate(priv, priv->in_buffers[0]);
506 else
507 vid_dec_FreeInputPortPrivate(priv->in_buffers[0]);
508 priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen;
509 r = base_port_SendBufferFunction(port, priv->in_buffers[0]);
510 } else {
511 priv->in_buffers[0]->nFilledLen = 0;
512 r = port->ReturnBufferFunction(port, priv->in_buffers[0]);
513 }
514
515 if (--priv->num_in_buffers) {
516 unsigned delta = MIN2((min_bits_left - vl_vlc_bits_left(&vlc)) / 8, priv->sizes[1]);
517
518 priv->in_buffers[0] = priv->in_buffers[1];
519 priv->sizes[0] = priv->sizes[1] - delta;
520 priv->inputs[0] = priv->inputs[1] + delta;
521 priv->timestamps[0] = priv->timestamps[1];
522 }
523
524 if (r)
525 return r;
526 }
527
528 return OMX_ErrorNone;
529 }
530
vid_dec_FreeDecBuffer(omx_base_PortType * port,OMX_U32 idx,OMX_BUFFERHEADERTYPE * buf)531 static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf)
532 {
533 OMX_COMPONENTTYPE* comp = port->standCompContainer;
534 vid_dec_PrivateType *priv = comp->pComponentPrivate;
535
536 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
537 vid_dec_av1_FreeInputPortPrivate(priv, buf);
538 else
539 vid_dec_FreeInputPortPrivate(buf);
540
541 return base_port_FreeBuffer(port, idx, buf);
542 }
543
vid_dec_FrameDecoded(OMX_COMPONENTTYPE * comp,OMX_BUFFERHEADERTYPE * input,OMX_BUFFERHEADERTYPE * output)544 static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input,
545 OMX_BUFFERHEADERTYPE* output)
546 {
547 vid_dec_PrivateType *priv = comp->pComponentPrivate;
548
549 vid_dec_FrameDecoded_common(priv, input, output);
550 }
551