omxvideodec: simplify color format conversion in fill_buffer function

This commit is contained in:
Aurélien Zanelli 2014-04-09 18:51:57 +02:00 committed by Julien Isorce
parent 6834d2e0b3
commit f5f876f681

View file

@ -436,105 +436,64 @@ gst_omx_video_dec_fill_buffer (GstOMXVideoDec * self,
} }
/* Different strides */ /* Different strides */
if (gst_video_frame_map (&frame, vinfo, outbuf, GST_MAP_WRITE)) {
const guint nstride = port_def->format.video.nStride;
const guint nslice = port_def->format.video.nSliceHeight;
guint src_stride[GST_VIDEO_MAX_PLANES] = { nstride, 0, };
guint src_size[GST_VIDEO_MAX_PLANES] = { nstride * nslice, 0, };
gint dst_width[GST_VIDEO_MAX_PLANES] = { 0, };
gint dst_height[GST_VIDEO_MAX_PLANES] =
{ GST_VIDEO_INFO_HEIGHT (vinfo), 0, };
const guint8 *src;
guint p;
switch (vinfo->finfo->format) { switch (GST_VIDEO_INFO_FORMAT (vinfo)) {
case GST_VIDEO_FORMAT_I420:{ case GST_VIDEO_FORMAT_I420:
gint i, j, height, width; dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo);
guint8 *src, *dest; src_stride[1] = nstride / 2;
gint src_stride, dest_stride; src_size[1] = (src_stride[1] * nslice) / 2;
dst_width[1] = GST_VIDEO_INFO_WIDTH (vinfo) / 2;
gst_video_frame_map (&frame, vinfo, outbuf, GST_MAP_WRITE); dst_height[1] = GST_VIDEO_INFO_HEIGHT (vinfo) / 2;
for (i = 0; i < 3; i++) { src_stride[2] = nstride / 2;
if (i == 0) { src_size[2] = (src_stride[1] * nslice) / 2;
src_stride = port_def->format.video.nStride; dst_width[2] = GST_VIDEO_INFO_WIDTH (vinfo) / 2;
dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, i); dst_height[2] = GST_VIDEO_INFO_HEIGHT (vinfo) / 2;
break;
/* XXX: Try this if no stride was set */ case GST_VIDEO_FORMAT_NV12:
if (src_stride == 0) dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo);
src_stride = dest_stride; src_stride[1] = nstride;
} else { src_size[1] = src_stride[1] * nslice / 2;
src_stride = port_def->format.video.nStride / 2; dst_width[1] = GST_VIDEO_INFO_WIDTH (vinfo);
dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, i); dst_height[1] = GST_VIDEO_INFO_HEIGHT (vinfo) / 2;
break;
/* XXX: Try this if no stride was set */ default:
if (src_stride == 0) g_assert_not_reached ();
src_stride = dest_stride; break;
}
src = inbuf->omx_buf->pBuffer + inbuf->omx_buf->nOffset;
if (i > 0)
src +=
port_def->format.video.nSliceHeight *
port_def->format.video.nStride;
if (i == 2)
src +=
(port_def->format.video.nSliceHeight / 2) *
(port_def->format.video.nStride / 2);
dest = GST_VIDEO_FRAME_COMP_DATA (&frame, i);
height = GST_VIDEO_FRAME_COMP_HEIGHT (&frame, i);
width = GST_VIDEO_FRAME_COMP_WIDTH (&frame, i);
for (j = 0; j < height; j++) {
memcpy (dest, src, width);
src += src_stride;
dest += dest_stride;
}
}
gst_video_frame_unmap (&frame);
ret = TRUE;
break;
} }
case GST_VIDEO_FORMAT_NV12:{
gint i, j, height, width;
guint8 *src, *dest;
gint src_stride, dest_stride;
gst_video_frame_map (&frame, vinfo, outbuf, GST_MAP_WRITE); src = inbuf->omx_buf->pBuffer + inbuf->omx_buf->nOffset;
for (i = 0; i < 2; i++) { for (p = 0; p < GST_VIDEO_INFO_N_PLANES (vinfo); p++) {
if (i == 0) { const guint8 *data;
src_stride = port_def->format.video.nStride; guint8 *dst;
dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, i); guint h;
/* XXX: Try this if no stride was set */ dst = GST_VIDEO_FRAME_PLANE_DATA (&frame, p);
if (src_stride == 0) data = src;
src_stride = dest_stride; for (h = 0; h < dst_height[p]; h++) {
} else { memcpy (dst, data, dst_width[p]);
src_stride = port_def->format.video.nStride; dst += GST_VIDEO_INFO_PLANE_STRIDE (vinfo, p);
dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (&frame, i); data += src_stride[p];
/* XXX: Try this if no stride was set */
if (src_stride == 0)
src_stride = dest_stride;
}
src = inbuf->omx_buf->pBuffer + inbuf->omx_buf->nOffset;
if (i == 1)
src +=
port_def->format.video.nSliceHeight *
port_def->format.video.nStride;
dest = GST_VIDEO_FRAME_COMP_DATA (&frame, i);
height = GST_VIDEO_FRAME_COMP_HEIGHT (&frame, i);
width = GST_VIDEO_FRAME_COMP_WIDTH (&frame, i) * (i == 0 ? 1 : 2);
for (j = 0; j < height; j++) {
memcpy (dest, src, width);
src += src_stride;
dest += dest_stride;
}
} }
gst_video_frame_unmap (&frame); src += src_size[p];
ret = TRUE;
break;
} }
default:
GST_ERROR_OBJECT (self, "Unsupported format"); gst_video_frame_unmap (&frame);
goto done; ret = TRUE;
break; } else {
GST_ERROR_OBJECT (self, "Can't map output buffer to frame");
goto done;
} }
done: done:
if (ret) { if (ret) {
GST_BUFFER_PTS (outbuf) = GST_BUFFER_PTS (outbuf) =