st/omx/dec: set dst rect to match src size
[mesa.git] / src / gallium / state_trackers / omx / vid_dec.c
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
57 static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name);
58 static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp);
59 static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param);
60 static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param);
61 static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE *comp, internalRequestMessageType *msg);
62 static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf);
63 static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf);
64 static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input, OMX_BUFFERHEADERTYPE* output);
65
66 OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp)
67 {
68 comp->componentVersion.s.nVersionMajor = 0;
69 comp->componentVersion.s.nVersionMinor = 0;
70 comp->componentVersion.s.nRevision = 0;
71 comp->componentVersion.s.nStep = 1;
72 comp->name_specific_length = 2;
73
74 comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
75 if (comp->name == NULL)
76 goto error;
77
78 comp->name_specific = CALLOC(comp->name_specific_length, sizeof(char *));
79 if (comp->name_specific == NULL)
80 goto error;
81
82 comp->role_specific = CALLOC(comp->name_specific_length, sizeof(char *));
83 if (comp->role_specific == NULL)
84 goto error;
85
86 comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
87 if (comp->name_specific[0] == NULL)
88 goto error_specific;
89
90 comp->name_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
91 if (comp->name_specific[1] == NULL)
92 goto error_specific;
93
94 comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
95 if (comp->role_specific[0] == NULL)
96 goto error_specific;
97
98 comp->role_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
99 if (comp->role_specific[1] == NULL)
100 goto error_specific;
101
102 strcpy(comp->name, OMX_VID_DEC_BASE_NAME);
103 strcpy(comp->name_specific[0], OMX_VID_DEC_MPEG2_NAME);
104 strcpy(comp->name_specific[1], OMX_VID_DEC_AVC_NAME);
105
106 strcpy(comp->role_specific[0], OMX_VID_DEC_MPEG2_ROLE);
107 strcpy(comp->role_specific[1], OMX_VID_DEC_AVC_ROLE);
108
109 comp->constructor = vid_dec_Constructor;
110
111 return OMX_ErrorNone;
112
113 error_specific:
114 FREE(comp->role_specific[1]);
115 FREE(comp->role_specific[0]);
116 FREE(comp->name_specific[1]);
117 FREE(comp->name_specific[0]);
118
119 error:
120 FREE(comp->role_specific);
121 FREE(comp->name_specific);
122
123 FREE(comp->name);
124
125 return OMX_ErrorInsufficientResources;
126 }
127
128 static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING name)
129 {
130 vid_dec_PrivateType *priv;
131 omx_base_video_PortType *port;
132 struct pipe_screen *screen;
133 OMX_ERRORTYPE r;
134 int i;
135
136 assert(!comp->pComponentPrivate);
137
138 priv = comp->pComponentPrivate = CALLOC(1, sizeof(vid_dec_PrivateType));
139 if (!priv)
140 return OMX_ErrorInsufficientResources;
141
142 r = omx_base_filter_Constructor(comp, name);
143 if (r)
144 return r;
145
146 priv->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
147
148 if (!strcmp(name, OMX_VID_DEC_MPEG2_NAME))
149 priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN;
150
151 if (!strcmp(name, OMX_VID_DEC_AVC_NAME))
152 priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
153
154 priv->BufferMgmtCallback = vid_dec_FrameDecoded;
155 priv->messageHandler = vid_dec_MessageHandler;
156 priv->destructor = vid_dec_Destructor;
157
158 comp->SetParameter = vid_dec_SetParameter;
159 comp->GetParameter = vid_dec_GetParameter;
160
161 priv->screen = omx_get_screen();
162 if (!priv->screen)
163 return OMX_ErrorInsufficientResources;
164
165 screen = priv->screen->pscreen;
166 priv->pipe = screen->context_create(screen, priv->screen, 0);
167 if (!priv->pipe)
168 return OMX_ErrorInsufficientResources;
169
170 if (!vl_compositor_init(&priv->compositor, priv->pipe)) {
171 priv->pipe->destroy(priv->pipe);
172 priv->pipe = NULL;
173 return OMX_ErrorInsufficientResources;
174 }
175
176 if (!vl_compositor_init_state(&priv->cstate, priv->pipe)) {
177 vl_compositor_cleanup(&priv->compositor);
178 priv->pipe->destroy(priv->pipe);
179 priv->pipe = NULL;
180 return OMX_ErrorInsufficientResources;
181 }
182
183 priv->sPortTypesParam[OMX_PortDomainVideo].nStartPortNumber = 0;
184 priv->sPortTypesParam[OMX_PortDomainVideo].nPorts = 2;
185 priv->ports = CALLOC(2, sizeof(omx_base_PortType *));
186 if (!priv->ports)
187 return OMX_ErrorInsufficientResources;
188
189 for (i = 0; i < 2; ++i) {
190 priv->ports[i] = CALLOC(1, sizeof(omx_base_video_PortType));
191 if (!priv->ports[i])
192 return OMX_ErrorInsufficientResources;
193
194 base_video_port_Constructor(comp, &priv->ports[i], i, i == 0);
195 }
196
197 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
198 strcpy(port->sPortParam.format.video.cMIMEType,"video/MPEG2");
199 port->sPortParam.nBufferCountMin = 8;
200 port->sPortParam.nBufferCountActual = 8;
201 port->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
202 port->sPortParam.format.video.nFrameWidth = 176;
203 port->sPortParam.format.video.nFrameHeight = 144;
204 port->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
205 port->sVideoParam.eCompressionFormat = OMX_VIDEO_CodingMPEG2;
206 port->Port_SendBufferFunction = vid_dec_DecodeBuffer;
207 port->Port_FreeBuffer = vid_dec_FreeDecBuffer;
208
209 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
210 port->sPortParam.nBufferCountActual = 8;
211 port->sPortParam.nBufferCountMin = 4;
212 port->sPortParam.format.video.nFrameWidth = 176;
213 port->sPortParam.format.video.nFrameHeight = 144;
214 port->sPortParam.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
215 port->sVideoParam.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
216
217 return OMX_ErrorNone;
218 }
219
220 static OMX_ERRORTYPE vid_dec_Destructor(OMX_COMPONENTTYPE *comp)
221 {
222 vid_dec_PrivateType* priv = comp->pComponentPrivate;
223 int i;
224
225 if (priv->ports) {
226 for (i = 0; i < priv->sPortTypesParam[OMX_PortDomainVideo].nPorts; ++i) {
227 if(priv->ports[i])
228 priv->ports[i]->PortDestructor(priv->ports[i]);
229 }
230 FREE(priv->ports);
231 priv->ports=NULL;
232 }
233
234 if (priv->pipe) {
235 vl_compositor_cleanup_state(&priv->cstate);
236 vl_compositor_cleanup(&priv->compositor);
237 priv->pipe->destroy(priv->pipe);
238 }
239
240 if (priv->screen)
241 omx_put_screen();
242
243 return omx_workaround_Destructor(comp);
244 }
245
246 static OMX_ERRORTYPE vid_dec_SetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param)
247 {
248 OMX_COMPONENTTYPE *comp = handle;
249 vid_dec_PrivateType *priv = comp->pComponentPrivate;
250 OMX_ERRORTYPE r;
251
252 if (!param)
253 return OMX_ErrorBadParameter;
254
255 switch(idx) {
256 case OMX_IndexParamPortDefinition: {
257 OMX_PARAM_PORTDEFINITIONTYPE *def = param;
258
259 r = omx_base_component_SetParameter(handle, idx, param);
260 if (r)
261 return r;
262
263 if (def->nPortIndex == OMX_BASE_FILTER_INPUTPORT_INDEX) {
264 omx_base_video_PortType *port;
265 unsigned framesize = def->format.video.nFrameWidth * def->format.video.nFrameHeight;
266
267 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
268 port->sPortParam.nBufferSize = framesize * 512 / (16*16);
269
270 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
271 port->sPortParam.format.video.nFrameWidth = def->format.video.nFrameWidth;
272 port->sPortParam.format.video.nFrameHeight = def->format.video.nFrameHeight;
273 port->sPortParam.format.video.nStride = def->format.video.nFrameWidth;
274 port->sPortParam.format.video.nSliceHeight = def->format.video.nFrameHeight;
275 port->sPortParam.nBufferSize = framesize*3/2;
276
277 priv->callbacks->EventHandler(comp, priv->callbackData, OMX_EventPortSettingsChanged,
278 OMX_BASE_FILTER_OUTPUTPORT_INDEX, 0, NULL);
279 }
280 break;
281 }
282 case OMX_IndexParamStandardComponentRole: {
283 OMX_PARAM_COMPONENTROLETYPE *role = param;
284
285 r = checkHeader(param, sizeof(OMX_PARAM_COMPONENTROLETYPE));
286 if (r)
287 return r;
288
289 if (!strcmp((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE)) {
290 priv->profile = PIPE_VIDEO_PROFILE_MPEG2_MAIN;
291 } else if (!strcmp((char *)role->cRole, OMX_VID_DEC_AVC_ROLE)) {
292 priv->profile = PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
293 } else {
294 return OMX_ErrorBadParameter;
295 }
296
297 break;
298 }
299 case OMX_IndexParamVideoPortFormat: {
300 OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param;
301 omx_base_video_PortType *port;
302
303 r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
304 if (r)
305 return r;
306
307 if (format->nPortIndex > 1)
308 return OMX_ErrorBadPortIndex;
309
310 port = (omx_base_video_PortType *)priv->ports[format->nPortIndex];
311 memcpy(&port->sVideoParam, format, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
312 break;
313 }
314 default:
315 return omx_base_component_SetParameter(handle, idx, param);
316 }
317 return OMX_ErrorNone;
318 }
319
320 static OMX_ERRORTYPE vid_dec_GetParameter(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx, OMX_PTR param)
321 {
322 OMX_COMPONENTTYPE *comp = handle;
323 vid_dec_PrivateType *priv = comp->pComponentPrivate;
324 OMX_ERRORTYPE r;
325
326 if (!param)
327 return OMX_ErrorBadParameter;
328
329 switch(idx) {
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 (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN)
338 strcpy((char *)role->cRole, OMX_VID_DEC_MPEG2_ROLE);
339 else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH)
340 strcpy((char *)role->cRole, OMX_VID_DEC_AVC_ROLE);
341
342 break;
343 }
344
345 case OMX_IndexParamVideoInit:
346 r = checkHeader(param, sizeof(OMX_PORT_PARAM_TYPE));
347 if (r)
348 return r;
349
350 memcpy(param, &priv->sPortTypesParam[OMX_PortDomainVideo], sizeof(OMX_PORT_PARAM_TYPE));
351 break;
352
353 case OMX_IndexParamVideoPortFormat: {
354 OMX_VIDEO_PARAM_PORTFORMATTYPE *format = param;
355 omx_base_video_PortType *port;
356
357 r = checkHeader(param, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
358 if (r)
359 return r;
360
361 if (format->nPortIndex > 1)
362 return OMX_ErrorBadPortIndex;
363
364 port = (omx_base_video_PortType *)priv->ports[format->nPortIndex];
365 memcpy(format, &port->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
366 break;
367 }
368
369 default:
370 return omx_base_component_GetParameter(handle, idx, param);
371
372 }
373 return OMX_ErrorNone;
374 }
375
376 static OMX_ERRORTYPE vid_dec_MessageHandler(OMX_COMPONENTTYPE* comp, internalRequestMessageType *msg)
377 {
378 vid_dec_PrivateType* priv = comp->pComponentPrivate;
379
380 if (msg->messageType == OMX_CommandStateSet) {
381 if ((msg->messageParam == OMX_StateIdle ) && (priv->state == OMX_StateLoaded)) {
382 if (priv->profile == PIPE_VIDEO_PROFILE_MPEG2_MAIN)
383 vid_dec_mpeg12_Init(priv);
384 else if (priv->profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH)
385 vid_dec_h264_Init(priv);
386
387 } else if ((msg->messageParam == OMX_StateLoaded) && (priv->state == OMX_StateIdle)) {
388 if (priv->shadow) {
389 priv->shadow->destroy(priv->shadow);
390 priv->shadow = NULL;
391 }
392 if (priv->codec) {
393 priv->codec->destroy(priv->codec);
394 priv->codec = NULL;
395 }
396 }
397 }
398
399 return omx_base_component_MessageHandler(comp, msg);
400 }
401
402 void vid_dec_NeedTarget(vid_dec_PrivateType *priv)
403 {
404 struct pipe_video_buffer templat = {};
405 struct vl_screen *omx_screen;
406 struct pipe_screen *pscreen;
407 omx_base_video_PortType *port;
408
409 omx_screen = priv->screen;
410 port = (omx_base_video_PortType *)priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
411
412 assert(omx_screen);
413 assert(port);
414
415 pscreen = omx_screen->pscreen;
416
417 assert(pscreen);
418
419 if (!priv->target) {
420 memset(&templat, 0, sizeof(templat));
421
422 templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
423 templat.width = port->sPortParam.format.video.nFrameWidth;
424 templat.height = port->sPortParam.format.video.nFrameHeight;
425 templat.buffer_format = pscreen->get_video_param(
426 pscreen,
427 PIPE_VIDEO_PROFILE_UNKNOWN,
428 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
429 PIPE_VIDEO_CAP_PREFERED_FORMAT
430 );
431 templat.interlaced = pscreen->get_video_param(
432 pscreen,
433 PIPE_VIDEO_PROFILE_UNKNOWN,
434 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
435 PIPE_VIDEO_CAP_PREFERS_INTERLACED
436 );
437 priv->target = priv->pipe->create_video_buffer(priv->pipe, &templat);
438 }
439 }
440
441 static void vid_dec_FreeInputPortPrivate(OMX_BUFFERHEADERTYPE *buf)
442 {
443 struct pipe_video_buffer *vbuf = buf->pInputPortPrivate;
444 if (!vbuf)
445 return;
446
447 vbuf->destroy(vbuf);
448 buf->pInputPortPrivate = NULL;
449 }
450
451 static OMX_ERRORTYPE vid_dec_DecodeBuffer(omx_base_PortType *port, OMX_BUFFERHEADERTYPE *buf)
452 {
453 OMX_COMPONENTTYPE* comp = port->standCompContainer;
454 vid_dec_PrivateType *priv = comp->pComponentPrivate;
455 unsigned i = priv->num_in_buffers++;
456 OMX_ERRORTYPE r;
457
458 priv->in_buffers[i] = buf;
459 priv->sizes[i] = buf->nFilledLen;
460 priv->inputs[i] = buf->pBuffer;
461 priv->timestamps[i] = buf->nTimeStamp;
462
463 while (priv->num_in_buffers > (!!(buf->nFlags & OMX_BUFFERFLAG_EOS) ? 0 : 1)) {
464 bool eos = !!(priv->in_buffers[0]->nFlags & OMX_BUFFERFLAG_EOS);
465 unsigned min_bits_left = eos ? 32 : MAX2(buf->nFilledLen * 8, 32);
466 struct vl_vlc vlc;
467
468 vl_vlc_init(&vlc, priv->num_in_buffers, priv->inputs, priv->sizes);
469
470 if (priv->slice)
471 priv->bytes_left = vl_vlc_bits_left(&vlc) / 8;
472
473 while (vl_vlc_bits_left(&vlc) > min_bits_left) {
474 priv->Decode(priv, &vlc, min_bits_left);
475 vl_vlc_fillbits(&vlc);
476 }
477
478 if (priv->slice) {
479 unsigned bytes = priv->bytes_left - vl_vlc_bits_left(&vlc) / 8;
480
481 priv->codec->decode_bitstream(priv->codec, priv->target, &priv->picture.base,
482 1, &priv->slice, &bytes);
483
484 if (priv->num_in_buffers)
485 priv->slice = priv->inputs[1];
486 else
487 priv->slice = NULL;
488 }
489
490 if (eos && priv->frame_started)
491 priv->EndFrame(priv);
492
493 if (priv->frame_finished) {
494 priv->frame_finished = false;
495 priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen;
496 r = base_port_SendBufferFunction(port, priv->in_buffers[0]);
497 } else if (eos) {
498 vid_dec_FreeInputPortPrivate(priv->in_buffers[0]);
499 priv->in_buffers[0]->nFilledLen = priv->in_buffers[0]->nAllocLen;
500 r = base_port_SendBufferFunction(port, priv->in_buffers[0]);
501 } else {
502 priv->in_buffers[0]->nFilledLen = 0;
503 r = port->ReturnBufferFunction(port, priv->in_buffers[0]);
504 }
505
506 if (--priv->num_in_buffers) {
507 unsigned delta = MIN2((min_bits_left - vl_vlc_bits_left(&vlc)) / 8, priv->sizes[1]);
508
509 priv->in_buffers[0] = priv->in_buffers[1];
510 priv->sizes[0] = priv->sizes[1] - delta;
511 priv->inputs[0] = priv->inputs[1] + delta;
512 priv->timestamps[0] = priv->timestamps[1];
513 }
514
515 if (r)
516 return r;
517 }
518
519 return OMX_ErrorNone;
520 }
521
522 static OMX_ERRORTYPE vid_dec_FreeDecBuffer(omx_base_PortType *port, OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf)
523 {
524 vid_dec_FreeInputPortPrivate(buf);
525 return base_port_FreeBuffer(port, idx, buf);
526 }
527
528 static void vid_dec_FillOutput(vid_dec_PrivateType *priv, struct pipe_video_buffer *buf,
529 OMX_BUFFERHEADERTYPE* output)
530 {
531 omx_base_PortType *port = priv->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
532 OMX_VIDEO_PORTDEFINITIONTYPE *def = &port->sPortParam.format.video;
533
534 struct pipe_sampler_view **views;
535 unsigned i, j;
536 unsigned width, height;
537
538 views = buf->get_sampler_view_planes(buf);
539
540 for (i = 0; i < 2 /* NV12 */; i++) {
541 if (!views[i]) continue;
542 width = def->nFrameWidth;
543 height = def->nFrameHeight;
544 vl_video_buffer_adjust_size(&width, &height, i, buf->chroma_format, buf->interlaced);
545 for (j = 0; j < views[i]->texture->array_size; ++j) {
546 struct pipe_box box = {0, 0, j, width, height, 1};
547 struct pipe_transfer *transfer;
548 uint8_t *map, *dst;
549 map = priv->pipe->transfer_map(priv->pipe, views[i]->texture, 0,
550 PIPE_TRANSFER_READ, &box, &transfer);
551 if (!map)
552 return;
553
554 dst = ((uint8_t*)output->pBuffer + output->nOffset) + j * def->nStride +
555 i * def->nFrameWidth * def->nFrameHeight;
556 util_copy_rect(dst,
557 views[i]->texture->format,
558 def->nStride * views[i]->texture->array_size, 0, 0,
559 box.width, box.height, map, transfer->stride, 0, 0);
560
561 pipe_transfer_unmap(priv->pipe, transfer);
562 }
563 }
564 }
565
566 static void vid_dec_deint(vid_dec_PrivateType *priv, struct pipe_video_buffer *src_buf,
567 struct pipe_video_buffer *dst_buf)
568 {
569 struct vl_compositor *compositor = &priv->compositor;
570 struct vl_compositor_state *s = &priv->cstate;
571 struct pipe_surface **dst_surface;
572 struct u_rect dst_rect;
573
574 dst_surface = dst_buf->get_surfaces(dst_buf);
575 vl_compositor_clear_layers(s);
576
577 dst_rect.x0 = 0;
578 dst_rect.x1 = src_buf->width;
579 dst_rect.y0 = 0;
580 dst_rect.y1 = src_buf->height;
581
582 vl_compositor_set_yuv_layer(s, compositor, 0, src_buf, NULL, NULL, true);
583 vl_compositor_set_layer_dst_area(s, 0, &dst_rect);
584 vl_compositor_render(s, compositor, dst_surface[0], NULL, false);
585
586 dst_rect.x1 /= 2;
587 dst_rect.y1 /= 2;
588
589 vl_compositor_set_yuv_layer(s, compositor, 0, src_buf, NULL, NULL, false);
590 vl_compositor_set_layer_dst_area(s, 0, &dst_rect);
591 vl_compositor_render(s, compositor, dst_surface[1], NULL, false);
592 }
593
594 static void vid_dec_FrameDecoded(OMX_COMPONENTTYPE *comp, OMX_BUFFERHEADERTYPE* input,
595 OMX_BUFFERHEADERTYPE* output)
596 {
597 vid_dec_PrivateType *priv = comp->pComponentPrivate;
598 bool eos = !!(input->nFlags & OMX_BUFFERFLAG_EOS);
599 OMX_TICKS timestamp;
600
601 if (!input->pInputPortPrivate) {
602 input->pInputPortPrivate = priv->Flush(priv, &timestamp);
603 if (timestamp != OMX_VID_DEC_TIMESTAMP_INVALID)
604 input->nTimeStamp = timestamp;
605 }
606
607 if (input->pInputPortPrivate) {
608 if (output->pInputPortPrivate) {
609 struct pipe_video_buffer *tmp, *vbuf, *new_vbuf;
610
611 tmp = output->pOutputPortPrivate;
612 vbuf = input->pInputPortPrivate;
613 if (vbuf->interlaced) {
614 /* re-allocate the progressive buffer */
615 omx_base_video_PortType *port;
616 struct pipe_video_buffer templat = {};
617
618 port = (omx_base_video_PortType *)
619 priv->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
620 memset(&templat, 0, sizeof(templat));
621 templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
622 templat.width = port->sPortParam.format.video.nFrameWidth;
623 templat.height = port->sPortParam.format.video.nFrameHeight;
624 templat.buffer_format = PIPE_FORMAT_NV12;
625 templat.interlaced = false;
626 new_vbuf = priv->pipe->create_video_buffer(priv->pipe, &templat);
627
628 /* convert the interlaced to the progressive */
629 vid_dec_deint(priv, input->pInputPortPrivate, new_vbuf);
630 priv->pipe->flush(priv->pipe, NULL, 0);
631
632 /* set the progrssive buffer for next round */
633 vbuf->destroy(vbuf);
634 input->pInputPortPrivate = new_vbuf;
635 }
636 output->pOutputPortPrivate = input->pInputPortPrivate;
637 input->pInputPortPrivate = tmp;
638 } else {
639 vid_dec_FillOutput(priv, input->pInputPortPrivate, output);
640 }
641 output->nFilledLen = output->nAllocLen;
642 output->nTimeStamp = input->nTimeStamp;
643 }
644
645 if (eos && input->pInputPortPrivate)
646 vid_dec_FreeInputPortPrivate(input);
647 else
648 input->nFilledLen = 0;
649 }