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 "util/vl_vlc.h"
53
54 #include "vl/vl_codec.h"
55
56 #include "entrypoint.h"
57 #include "vid_dec.h"
58 #include "vid_omx_common.h"
59 #include "vid_dec_h264_common.h"
60
61 static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name);
62 static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp);
63 static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param);
64 static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param);
65 static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE *comp, internalRequestMessageType *msg);
66 static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf);
67 static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf);
68 static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, OMX_BUFFERHEADERTYPE* output);
69
vid_dec_LoaderComponent(stLoaderComponentType * comp)70 OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp)
71 {
72 comp->componentVersion.s.nVersionMajor = 0;
73 comp->componentVersion.s.nVersionMinor = 0;
74 comp->componentVersion.s.nRevision = 0;
75 comp->componentVersion.s.nStep = 1;
76 comp->name_specific_length = 4;
77
78 comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
79 if (comp->name == NULL)
80 goto error;
81
82 comp->name_specific = CALLOC(comp->name_specific_length, sizeof(char *));
83 if (comp->name_specific == NULL)
84 goto error;
85
86 comp->role_specific = CALLOC(comp->name_specific_length, sizeof(char *));
87 if (comp->role_specific == NULL)
88 goto error;
89
90 comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
91 if (comp->name_specific[0] == NULL)
92 goto error_specific;
93
94 comp->name_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
95 if (comp->name_specific[1] == NULL)
96 goto error_specific;
97
98 comp->name_specific[2] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
99 if (comp->name_specific[2] == NULL)
100 goto error_specific;
101
102 comp->name_specific[3] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
103 if (comp->name_specific[3] == NULL)
104 goto error_specific;
105
106 comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
107 if (comp->role_specific[0] == NULL)
108 goto error_specific;
109
110 comp->role_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
111 if (comp->role_specific[1] == NULL)
112 goto error_specific;
113
114 comp->role_specific[2] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
115 if (comp->role_specific[2] == NULL)
116 goto error_specific;
117
118 comp->role_specific[3] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
119 if (comp->role_specific[3] == NULL)
120 goto error_specific;
121
122 strcpy(comp->name, OMX_VID_DEC_BASE_NAME);
123 strcpy(comp->name_specific[0], OMX_VID_DEC_MPEG2_NAME);
124 strcpy(comp->name_specific[1], OMX_VID_DEC_AVC_NAME);
125 strcpy(comp->name_specific[2], OMX_VID_DEC_HEVC_NAME);
126 strcpy(comp->name_specific[3], OMX_VID_DEC_AV1_NAME);
127
128 strcpy(comp->role_specific[0], OMX_VID_DEC_MPEG2_ROLE);
129 strcpy(comp->role_specific[1], OMX_VID_DEC_AVC_ROLE);
130 strcpy(comp->role_specific[2], OMX_VID_DEC_HEVC_ROLE);
131 strcpy(comp->role_specific[3], OMX_VID_DEC_AV1_ROLE);
132
133 comp->constructor = vid_dec_Constructor;
134
135 return OMX_ErrorNone;
136
137 error_specific:
138 FREE(comp->role_specific[3]);
139 FREE(comp->role_specific[2]);
140 FREE(comp->role_specific[1]);
141 FREE(comp->role_specific[0]);
142 FREE(comp->name_specific[3]);
143 FREE(comp->name_specific[2]);
144 FREE(comp->name_specific[1]);
145 FREE(comp->name_specific[0]);
146
147 error:
148 FREE(comp->role_specific);
149 FREE(comp->name_specific);
150
151 FREE(comp->name);
152
153 return OMX_ErrorInsufficientResources;
154 }
155
vid_dec_Constructor(OMX_COMPONENTTYPE * comp,OMX_STRING name)156 static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name)
157 {
158 vid_dec_PrivateType *priv;
159 omx_base_video_PortType *port;
160 struct pipe_screen *screen;
161 OMX_ERRORTYPE r;
162 int i;
163
164 assert(!comp->pComponentPrivate);
165
166 priv = comp->pComponentPrivate = CALLOC(1, sizeof(vid_dec_PrivateType));
167 if (!priv)
168 return OMX_ErrorInsufficientResources;
169
170 r = omx_base_filter_Constructor(comp, name);
171 if (r)
172 return r;
173
174 priv->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
175
176 if (!strcmp(name, OMX_VID_DEC_MPEG2_NAME))
177 priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN;
178
179 if (!strcmp(name, OMX_VID_DEC_AVC_NAME))
180 priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
181
182 if (!strcmp(name, OMX_VID_DEC_HEVC_NAME))
183 priv->profile = PIPE_VIDEO_PROFILE_HEVC_MAIN;
184
185 if (!strcmp(name, OMX_VID_DEC_AV1_NAME))
186 priv->profile = PIPE_VIDEO_PROFILE_AV1_MAIN;
187
188 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
189 priv->BufferMgmtCallback = vid_dec_av1_FrameDecoded;
190 else
191 priv->BufferMgmtCallback = vid_dec_FrameDecoded;
192 priv->messageHandler = vid_dec_MessageHandler;
193 priv->destructor = vid_dec_Destructor;
194
195 comp->SetParameter = vid_dec_SetParameter;
196 comp->GetParameter = vid_dec_GetParameter;
197
198 priv->screen = omx_get_screen();
199 if (!priv->screen)
200 return OMX_ErrorInsufficientResources;
201
202 screen = priv->screen->pscreen;
203
204 if (!vl_codec_supported(screen, priv->profile, false))
205 return OMX_ErrorInsufficientResources;
206
207 priv->pipe = pipe_create_multimedia_context(screen);
208 if (!priv->pipe)
209 return OMX_ErrorInsufficientResources;
210
211 if (!vl_compositor_init(&priv->compositor, priv->pipe)) {
212 priv->pipe->destroy(priv->pipe);
213 priv->pipe = NULL;
214 return OMX_ErrorInsufficientResources;
215 }
216
217 if (!vl_compositor_init_state(&priv->cstate, priv->pipe)) {
218 vl_compositor_cleanup(&priv->compositor);
219 priv->pipe->destroy(priv->pipe);
220 priv->pipe = NULL;
221 return OMX_ErrorInsufficientResources;
222 }
223
224 priv->sPortTypesParam[OMX_PortDomainVideo].nStartPortNumber = 0;
225 priv->sPortTypesParam[OMX_PortDomainVideo].nPorts = 2;
226 priv->ports = CALLOC(2, sizeof(omx_base_PortType *));
227 if (!priv->ports)
228 return OMX_ErrorInsufficientResources;
229
230 for (i = 0; i < 2; ++i) {
231 priv->ports[i] = CALLOC(1, sizeof(omx_base_video_PortType));
232 if (!priv->ports[i])
233 return OMX_ErrorInsufficientResources;
234
235 base_video_port_Constructor(comp, &priv->ports[i], i, i == 0);
236 }
237
238 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
239 strcpy(port->sPortParam.format.video.cMIMEType,"video/MPEG2");
240 port->sPortParam.nBufferCountMin = 8;
241 port->sPortParam.nBufferCountActual = 8;
242 port->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
243 port->sPortParam.format.video.nFrameWidth = 176;
244 port->sPortParam.format.video.nFrameHeight = 144;
245 port->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
246 port->sVideoParam.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
247 port->Port_SendBufferFunction = vid_dec_DecodeBuffer;
248 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) {
249 port->Port_AllocateBuffer = vid_dec_av1_AllocateInBuffer;
250 port->Port_UseBuffer = vid_dec_av1_UseInBuffer;
251 }
252
253 port->Port_FreeBuffer = vid_dec_FreeDecBuffer;
254 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
255 port->sPortParam.nBufferCountActual = 8;
256 port->sPortParam.nBufferCountMin = 4;
257 port->sPortParam.format.video.nFrameWidth = 176;
258 port->sPortParam.format.video.nFrameHeight = 144;
259 port->sPortParam.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
260 port->sVideoParam.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
261
262 return OMX_ErrorNone;
263 }
264
vid_dec_Destructor(OMX_COMPONENTTYPE * comp)265 static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp)
266 {
267 vid_dec_PrivateType* priv = comp->pComponentPrivate;
268 int i;
269
270 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
271 vid_dec_av1_ReleaseTasks(priv);
272
273 if (priv->ports) {
274 for (i = 0; i < priv->sPortTypesParam[OMX_PortDomainVideo].nPorts; ++i) {
275 if(priv->ports[i])
276 priv->ports[i]->PortDestructor(priv->ports[i]);
277 }
278 FREE(priv->ports);
279 priv->ports=NULL;
280 }
281
282 if (priv->pipe) {
283 vl_compositor_cleanup_state(&priv->cstate);
284 vl_compositor_cleanup(&priv->compositor);
285 priv->pipe->destroy(priv->pipe);
286 }
287
288 if (priv->screen)
289 omx_put_screen();
290
291 return omx_workaround_Destructor(comp);
292 }
293
vid_dec_SetParameter(OMX_HANDLETYPE handle,OMX_INDEXTYPE idx,OMX_PTR param)294 static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param)
295 {
296 OMX_COMPONENTTYPE *comp = handle;
297 vid_dec_PrivateType *priv = comp->pComponentPrivate;
298 OMX_ERRORTYPE r;
299
300 if (!param)
301 return OMX_ErrorBadParameter;
302
303 switch(idx) {
304 case OMX_IndexParamPortDefinition: {
305 OMX_PARAM_PORTDEFINITIONTYPE *def = param;
306
307 r = omx_base_component_SetParameter(handle, idx, param);
308 if (r)
309 return r;
310
311 if (def->nPortIndex == OMX_BASE_FILTER_INPUTPORT_INDEX) {
312 omx_base_video_PortType *port;
313 unsigned framesize = def->format.video.nFrameWidth * def->format.video.nFrameHeight;
314
315 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
316 port->sPortParam.nBufferSize = framesize * 512 / (16*16);
317
318 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
319 port->sPortParam.format.video.nFrameWidth = def->format.video.nFrameWidth;
320 port->sPortParam.format.video.nFrameHeight = def->format.video.nFrameHeight;
321 port->sPortParam.format.video.nStride = def->format.video.nFrameWidth;
322 port->sPortParam.format.video.nSliceHeight = def->format.video.nFrameHeight;
323 port->sPortParam.nBufferSize = framesize*3/2;
324
325 priv->callbacks->EventHandler(comp, priv->callbackData, OMX_EventPortSettingsChanged,
326 OMX_BASE_FILTER_OUTPUTPORT_INDEX, 0, NULL);
327 }
328 break;
329 }
330 case OMX_IndexParamStandardComponentRole: {
331 OMX_PARAM_COMPONENTROLETYPE *role = param;
332
333 r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE));
334 if (r)
335 return r;
336
337 if (!strcmp((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE)) {
338 priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN;
339 } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_AVC_ROLE)) {
340 priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
341 } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_HEVC_ROLE)) {
342 priv->profile = PIPE_VIDEO_PROFILE_HEVC_MAIN;
343 } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_AV1_ROLE)) {
344 priv->profile = PIPE_VIDEO_PROFILE_AV1_MAIN;
345 } else {
346 return OMX_ErrorBadParameter;
347 }
348
349 break;
350 }
351 case OMX_IndexParamVideoPortFormat: {
352 OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param;
353 omx_base_video_PortType *port;
354
355 r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
356 if (r)
357 return r;
358
359 if (format->nPortIndex > 1)
360 return OMX_ErrorBadPortIndex;
361
362 port = (omx_base_video_PortType *)priv->ports[format->nPortIndex];
363 memcpy(&port->sVideoParam, format, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
364 break;
365 }
366 default:
367 return omx_base_component_SetParameter(handle, idx, param);
368 }
369 return OMX_ErrorNone;
370 }
371
vid_dec_GetParameter(OMX_HANDLETYPE handle,OMX_INDEXTYPE idx,OMX_PTR param)372 static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param)
373 {
374 OMX_COMPONENTTYPE *comp = handle;
375 vid_dec_PrivateType *priv = comp->pComponentPrivate;
376 OMX_ERRORTYPE r;
377
378 if (!param)
379 return OMX_ErrorBadParameter;
380
381 switch(idx) {
382 case OMX_IndexParamStandardComponentRole: {
383 OMX_PARAM_COMPONENTROLETYPE *role = param;
384
385 r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE));
386 if (r)
387 return r;
388
389 if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN)
390 strcpy((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE);
391 else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH)
392 strcpy((char *)role->cRole, OMX_VID_DEC_AVC_ROLE);
393 else if (priv->profile == PIPE_VIDEO_PROFILE_HEVC_MAIN)
394 strcpy((char *)role->cRole, OMX_VID_DEC_HEVC_ROLE);
395 else if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
396 strcpy((char *)role->cRole, OMX_VID_DEC_AV1_ROLE);
397
398 break;
399 }
400
401 case OMX_IndexParamVideoInit:
402 r = checkHeader(param, sizeof(OMX_PORT_PARAM_TYPE));
403 if (r)
404 return r;
405
406 memcpy(param, &priv->sPortTypesParam[OMX_PortDomainVideo], sizeof(OMX_PORT_PARAM_TYPE));
407 break;
408
409 case OMX_IndexParamVideoPortFormat: {
410 OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param;
411 omx_base_video_PortType *port;
412
413 r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
414 if (r)
415 return r;
416
417 if (format->nPortIndex > 1)
418 return OMX_ErrorBadPortIndex;
419
420 port = (omx_base_video_PortType *)priv->ports[format->nPortIndex];
421 memcpy(format, &port->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
422 break;
423 }
424
425 default:
426 return omx_base_component_GetParameter(handle, idx, param);
427
428 }
429 return OMX_ErrorNone;
430 }
431
vid_dec_MessageHandler(OMX_COMPONENTTYPE * comp,internalRequestMessageType * msg)432 static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE* comp, internalRequestMessageType *msg)
433 {
434 vid_dec_PrivateType* priv = comp->pComponentPrivate;
435
436 if (msg->messageType == OMX_CommandStateSet) {
437 if ((msg->messageParam == OMX_StateIdle ) && (priv->state == OMX_StateLoaded)) {
438 if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN)
439 vid_dec_mpeg12_Init(priv);
440 else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH)
441 vid_dec_h264_Init(priv);
442 else if (priv->profile == PIPE_VIDEO_PROFILE_HEVC_MAIN)
443 vid_dec_h265_Init(priv);
444 else if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN) {
445 vid_dec_av1_Init(priv);
446 }
447
448 } else if ((msg->messageParam == OMX_StateLoaded) && (priv->state == OMX_StateIdle)) {
449 if (priv->shadow) {
450 priv->shadow->destroy(priv->shadow);
451 priv->shadow = NULL;
452 }
453 if (priv->codec) {
454 priv->codec->destroy(priv->codec);
455 priv->codec = NULL;
456 }
457 }
458 }
459
460 return omx_base_component_MessageHandler(comp, msg);
461 }
462
vid_dec_DecodeBuffer(omx_base_PortType * port,OMX_BUFFERHEADERTYPE * buf)463 static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf)
464 {
465 OMX_COMPONENTTYPE* comp = port->standCompContainer;
466 vid_dec_PrivateType *priv = comp->pComponentPrivate;
467 unsigned i = priv->num_in_buffers++;
468 OMX_ERRORTYPE r;
469
470 priv->in_buffers[i] = buf;
471 priv->sizes[i] = buf->nFilledLen;
472 priv->inputs[i] = buf->pBuffer;
473 priv->timestamps[i] = buf->nTimeStamp;
474
475 while (priv->num_in_buffers > (!!(buf->nFlags & OMX_BUFFERFLAG_EOS) ? 0 : 1)) {
476 bool eos = !!(priv->in_buffers[0]->nFlags & OMX_BUFFERFLAG_EOS);
477 unsigned min_bits_left = eos ? 32 : MAX2(buf->nFilledLen * 8, 32);
478 struct vl_vlc vlc;
479
480 vl_vlc_init(&vlc, priv->num_in_buffers, priv->inputs, priv->sizes);
481
482 if (priv->slice)
483 priv->bytes_left = vl_vlc_bits_left(&vlc) / 8;
484
485 while (vl_vlc_bits_left(&vlc) > min_bits_left) {
486 priv->Decode(priv, &vlc, min_bits_left);
487 vl_vlc_fillbits(&vlc);
488 }
489
490 if (priv->slice) {
491 unsigned bytes = priv->bytes_left - vl_vlc_bits_left(&vlc) / 8;
492
493 priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base,
494 1, &priv->slice, &bytes);
495
496 if (priv->num_in_buffers)
497 priv->slice = priv->inputs[1];
498 else
499 priv->slice = NULL;
500 }
501
502 if (eos && priv->frame_started)
503 priv->EndFrame(priv);
504
505 if (priv->frame_finished) {
506 priv->frame_finished = false;
507 priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen;
508 r = base_port_SendBufferFunction(port, priv->in_buffers[0]);
509 } else if (eos) {
510 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
511 vid_dec_av1_FreeInputPortPrivate(priv, priv->in_buffers[0]);
512 else
513 vid_dec_FreeInputPortPrivate(priv->in_buffers[0]);
514 priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen;
515 r = base_port_SendBufferFunction(port, priv->in_buffers[0]);
516 } else {
517 priv->in_buffers[0]->nFilledLen = 0;
518 r = port->ReturnBufferFunction(port, priv->in_buffers[0]);
519 }
520
521 if (--priv->num_in_buffers) {
522 unsigned delta = MIN2((min_bits_left - vl_vlc_bits_left(&vlc)) / 8, priv->sizes[1]);
523
524 priv->in_buffers[0] = priv->in_buffers[1];
525 priv->sizes[0] = priv->sizes[1] - delta;
526 priv->inputs[0] = priv->inputs[1] + delta;
527 priv->timestamps[0] = priv->timestamps[1];
528 }
529
530 if (r)
531 return r;
532 }
533
534 return OMX_ErrorNone;
535 }
536
vid_dec_FreeDecBuffer(omx_base_PortType * port,OMX_U32 idx,OMX_BUFFERHEADERTYPE * buf)537 static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf)
538 {
539 OMX_COMPONENTTYPE* comp = port->standCompContainer;
540 vid_dec_PrivateType *priv = comp->pComponentPrivate;
541
542 if (priv->profile == PIPE_VIDEO_PROFILE_AV1_MAIN)
543 vid_dec_av1_FreeInputPortPrivate(priv, buf);
544 else
545 vid_dec_FreeInputPortPrivate(buf);
546
547 return base_port_FreeBuffer(port, idx, buf);
548 }
549
vid_dec_FrameDecoded(OMX_COMPONENTTYPE * comp,OMX_BUFFERHEADERTYPE * input,OMX_BUFFERHEADERTYPE * output)550 static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input,
551 OMX_BUFFERHEADERTYPE* output)
552 {
553 vid_dec_PrivateType *priv = comp->pComponentPrivate;
554
555 vid_dec_FrameDecoded_common(priv, input, output);
556 }
557