Dzjee, just found out ffmpeg has a function to calculate the buffer size for me, d'oh!

Original commit message from CVS:
Dzjee, just found out ffmpeg has a function to calculate the buffer size for me, d'oh!
This commit is contained in:
Ronald S. Bultje 2003-06-07 11:43:11 +00:00
parent 0139c8c671
commit 2cc34e4c8f

View file

@ -240,11 +240,10 @@ gst_ffmpegdec_get_buffer (AVCodecContext *context,
AVFrame *picture) AVFrame *picture)
{ {
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
gint hor_chr_dec = 0, ver_chr_dec = 0, bpp = 0; gint hor_chr_dec = -1, ver_chr_dec = -1;
gint width, height; gint width, height;
gint alignment; gint alignment;
gulong bufsize = 0; gulong bufsize = 0;
void *base;
/* set alignment */ /* set alignment */
if (context->codec_id == CODEC_ID_SVQ1) { if (context->codec_id == CODEC_ID_SVQ1) {
@ -259,46 +258,31 @@ gst_ffmpegdec_get_buffer (AVCodecContext *context,
switch (context->codec_type) { switch (context->codec_type) {
case CODEC_TYPE_VIDEO: case CODEC_TYPE_VIDEO:
bufsize = avpicture_get_size (context->pix_fmt,
width, height);
/* find out whether we are planar or packed */
switch (context->pix_fmt) { switch (context->pix_fmt) {
case PIX_FMT_YUV420P: case PIX_FMT_YUV420P:
bpp = 12; case PIX_FMT_YUV422P:
hor_chr_dec = ver_chr_dec = 2; case PIX_FMT_YUV444P:
case PIX_FMT_YUV410P:
case PIX_FMT_YUV411P:
avcodec_get_chroma_sub_sample (context->pix_fmt,
&hor_chr_dec, &ver_chr_dec);
break; break;
case PIX_FMT_YUV422: case PIX_FMT_YUV422:
bpp = 16;
break;
case PIX_FMT_YUV422P:
bpp = 16;
hor_chr_dec = 2; ver_chr_dec = 1;
break;
case PIX_FMT_RGB24: case PIX_FMT_RGB24:
case PIX_FMT_BGR24: case PIX_FMT_BGR24:
bpp = 24;
break;
case PIX_FMT_YUV444P:
bpp = 24;
hor_chr_dec = ver_chr_dec = 1;
break;
case PIX_FMT_RGBA32: case PIX_FMT_RGBA32:
bpp = 32;
break;
case PIX_FMT_YUV410P:
bpp = 9;
hor_chr_dec = ver_chr_dec = 4;
break;
case PIX_FMT_YUV411P:
bpp = 12;
hor_chr_dec = 4; ver_chr_dec = 1;
break;
case PIX_FMT_RGB565: case PIX_FMT_RGB565:
case PIX_FMT_RGB555: case PIX_FMT_RGB555:
bpp = 16; /* not planar */
break; break;
default: default:
g_assert (0); g_assert (0);
break; break;
} }
bufsize = width * height * bpp / 8;
break; break;
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
@ -314,23 +298,19 @@ gst_ffmpegdec_get_buffer (AVCodecContext *context,
buf = gst_buffer_new_and_alloc (bufsize); buf = gst_buffer_new_and_alloc (bufsize);
/* set up planes */ /* set up planes */
base = GST_BUFFER_DATA (buf); picture->data[0] = GST_BUFFER_DATA (buf);
if (hor_chr_dec > 0 && ver_chr_dec > 0) { if (hor_chr_dec >= 0 && ver_chr_dec >= 0) {
picture->linesize[0] = width; picture->linesize[0] = width;
picture->data[0] = base; picture->linesize[1] = width >> hor_chr_dec;
picture->linesize[2] = width >> hor_chr_dec;
base += width * height; picture->data[1] = picture->data[0] + (width * height);
picture->linesize[1] = picture->linesize[0] / hor_chr_dec; picture->data[2] = picture->data[1] +
picture->data[1] = base; ((width * height) >> (ver_chr_dec + hor_chr_dec));
base += (width * height) / (ver_chr_dec * hor_chr_dec);
picture->linesize[2] = picture->linesize[1];
picture->data[2] = base;
} else { } else {
picture->linesize[0] = GST_BUFFER_MAXSIZE (buf) / height; picture->linesize[0] = GST_BUFFER_MAXSIZE (buf) / height;
picture->data[0] = base;
picture->linesize[1] = picture->linesize[2] = 0; picture->linesize[1] = picture->linesize[2] = 0;
picture->data[1] = picture->data[2] = NULL; picture->data[1] = picture->data[2] = NULL;
} }
picture->linesize[3] = 0; picture->linesize[3] = 0;