From: <rb...@fr...> - 2004-10-29 09:47:55
|
CVS Root: /home/cvs/gstreamer Module: gst-ffmpeg Changes by: rbultje Date: Fri Oct 29 2004 02:47:53 PDT Log message: * ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_avpicture_fill): * ext/ffmpeg/gstffmpegcodecmap.h: * ext/ffmpeg/gstffmpegcolorspace.c: (gst_ffmpegcsp_chain): * ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_get_buffer), (gst_ffmpegdec_chain): * ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_chain_video): Sync with gst-plugins ffmpegcolorspace, align-by-4. Ready to re-sync gst-plugins ffmpegcolorspace with ours and deprecate this one. Modified files: . : ChangeLog ext/ffmpeg : gstffmpegcodecmap.c gstffmpegcodecmap.h gstffmpegcolorspace.c gstffmpegdec.c gstffmpegenc.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ChangeLog.diff?r1=1.87&r2=1.88 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.c.diff?r1=1.64&r2=1.65 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.h.diff?r1=1.10&r2=1.11 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcolorspace.c.diff?r1=1.24&r2=1.25 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegdec.c.diff?r1=1.66&r2=1.67 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegenc.c.diff?r1=1.51&r2=1.52 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /home/cvs/gstreamer/gst-ffmpeg/ChangeLog,v retrieving revision 1.87 retrieving revision 1.88 diff -u -d -r1.87 -r1.88 --- ChangeLog 25 Oct 2004 21:26:34 -0000 1.87 +++ ChangeLog 29 Oct 2004 09:47:40 -0000 1.88 @@ -1,3 +1,15 @@ +2004-10-29 Ronald S. Bultje <rb...@ro...> + + * ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_avpicture_fill): + * ext/ffmpeg/gstffmpegcodecmap.h: + * ext/ffmpeg/gstffmpegcolorspace.c: (gst_ffmpegcsp_chain): + * ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_get_buffer), + (gst_ffmpegdec_chain): + * ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_chain_video): + Sync with gst-plugins ffmpegcolorspace, align-by-4. Ready to + re-sync gst-plugins ffmpegcolorspace with ours and deprecate + this one. 2004-10-25 Ronald S. Bultje <rb...@ro...> * ext/ffmpeg/gstffmpegcolorspace.c: (gst_ffmpegcsp_pad_link): Index: gstffmpegcodecmap.c RCS file: /home/cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.c,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- gstffmpegcodecmap.c 25 Oct 2004 11:56:52 -0000 1.64 +++ gstffmpegcodecmap.c 29 Oct 2004 09:47:41 -0000 1.65 @@ -1953,3 +1953,283 @@ return name; } +/* + * Fill in pointers to memory in a AVPicture, where + * everything is aligned by 4 (as required by X). + * This is mostly a copy from imgconvert.c with some + * small changes. + */ +#define FF_COLOR_RGB 0 /* RGB color space */ +#define FF_COLOR_GRAY 1 /* gray color space */ +#define FF_COLOR_YUV 2 /* YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */ +#define FF_COLOR_YUV_JPEG 3 /* YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */ +#define FF_PIXEL_PLANAR 0 /* each channel has one component in AVPicture */ +#define FF_PIXEL_PACKED 1 /* only one components containing all the channels */ +#define FF_PIXEL_PALETTE 2 /* one components containing indexes for a palette */ +typedef struct PixFmtInfo { + const char *name; + uint8_t nb_channels; /* number of channels (including alpha) */ + uint8_t color_type; /* color type (see FF_COLOR_xxx constants) */ + uint8_t pixel_type; /* pixel storage type (see FF_PIXEL_xxx constants) */ + uint8_t is_alpha : 1; /* true if alpha can be specified */ + uint8_t x_chroma_shift; /* X chroma subsampling factor is 2 ^ shift */ + uint8_t y_chroma_shift; /* Y chroma subsampling factor is 2 ^ shift */ + uint8_t depth; /* bit depth of the color components */ +} PixFmtInfo; +/* this table gives more information about formats */ +static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { + /* YUV formats */ + [PIX_FMT_YUV420P] = { + .name = "yuv420p", + .nb_channels = 3, + .color_type = FF_COLOR_YUV, + .pixel_type = FF_PIXEL_PLANAR, + .depth = 8, + .x_chroma_shift = 1, .y_chroma_shift = 1, + }, + [PIX_FMT_YUV422P] = { + .name = "yuv422p", + .x_chroma_shift = 1, .y_chroma_shift = 0, + [PIX_FMT_YUV444P] = { + .name = "yuv444p", + .x_chroma_shift = 0, .y_chroma_shift = 0, + [PIX_FMT_YUV422] = { + .name = "yuv422", + .nb_channels = 1, + .pixel_type = FF_PIXEL_PACKED, + .x_chroma_shift = 1, .y_chroma_shift = 0, + [PIX_FMT_YUV410P] = { + .name = "yuv410p", + .x_chroma_shift = 2, .y_chroma_shift = 2, + [PIX_FMT_YUV411P] = { + .name = "yuv411p", + .x_chroma_shift = 2, .y_chroma_shift = 0, + /* JPEG YUV */ + [PIX_FMT_YUVJ420P] = { + .name = "yuvj420p", + .color_type = FF_COLOR_YUV_JPEG, + [PIX_FMT_YUVJ422P] = { + .name = "yuvj422p", + [PIX_FMT_YUVJ444P] = { + .name = "yuvj444p", + /* RGB formats */ + [PIX_FMT_RGB24] = { + .name = "rgb24", + .color_type = FF_COLOR_RGB, + .x_chroma_shift = 0, .y_chroma_shift = 0, + [PIX_FMT_BGR24] = { + .name = "bgr24", + [PIX_FMT_RGBA32] = { + .name = "rgba32", + .nb_channels = 4, .is_alpha = 1, + [PIX_FMT_RGB565] = { + .name = "rgb565", + .depth = 5, + [PIX_FMT_RGB555] = { + .name = "rgb555", + /* gray / mono formats */ + [PIX_FMT_GRAY8] = { + .name = "gray", + .color_type = FF_COLOR_GRAY, + [PIX_FMT_MONOWHITE] = { + .name = "monow", + .depth = 1, + [PIX_FMT_MONOBLACK] = { + .name = "monob", + /* paletted formats */ + [PIX_FMT_PAL8] = { + .name = "pal8", + .pixel_type = FF_PIXEL_PALETTE, +}; +#define ROUND_UP_4(x) (((x) + 3) & ~3) +int +gst_ffmpeg_avpicture_fill (AVPicture * picture, + uint8_t * ptr, enum PixelFormat pix_fmt, int width, int height) +{ + int size, w2, h2, size2; + int stride, stride2; + PixFmtInfo *pinfo; + pinfo = &pix_fmt_info[pix_fmt]; + stride = ROUND_UP_4 (width); + size = stride * height; + switch (pix_fmt) { + case PIX_FMT_YUV420P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV444P: + case PIX_FMT_YUV410P: + case PIX_FMT_YUV411P: + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUVJ444P: + stride = ROUND_UP_4 (width); + size = stride * height; + w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; + stride2 = ROUND_UP_4 (w2); + h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; + size2 = stride2 * h2; + picture->data[0] = ptr; + picture->data[1] = picture->data[0] + size; + picture->data[2] = picture->data[1] + size2; + picture->linesize[0] = stride; + picture->linesize[1] = stride2; + picture->linesize[2] = stride2; + return size + 2 * size2; + case PIX_FMT_RGB24: + case PIX_FMT_BGR24: + stride = ROUND_UP_4 (width * 3); + picture->data[1] = NULL; + picture->data[2] = NULL; + return size; + case PIX_FMT_RGBA32: + stride = width * 4; + case PIX_FMT_RGB555: + case PIX_FMT_RGB565: + case PIX_FMT_YUV422: + stride = ROUND_UP_4 (width * 2); + case PIX_FMT_GRAY8: + case PIX_FMT_MONOWHITE: + case PIX_FMT_MONOBLACK: + stride = ROUND_UP_4 ((width + 7) >> 3); + case PIX_FMT_PAL8: + /* already forced to be with stride, so same result as other function */ + picture->data[1] = ptr + size; /* palette is stored here as 256 32 bit words */ + picture->linesize[1] = 4; + return size + 256 * 4; + default: + picture->data[0] = NULL; + picture->data[3] = NULL; + return -1; + } + return 0; +} Index: gstffmpegcodecmap.h RCS file: /home/cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcodecmap.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- gstffmpegcodecmap.h 24 Oct 2004 22:24:43 -0000 1.10 +++ gstffmpegcodecmap.h 29 Oct 2004 09:47:41 -0000 1.11 @@ -96,6 +96,17 @@ gst_ffmpeg_get_codecid_longname (enum CodecID codec_id); /* + * Fill in pointers in an AVPicture, aligned by 4 (required by X). + uint8_t * ptr, + enum PixelFormat pix_fmt, + int width, + int height); * FFMPEG debugging function; maybe move to a different file. */ Index: gstffmpegcolorspace.c RCS file: /home/cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegcolorspace.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- gstffmpegcolorspace.c 25 Oct 2004 21:26:34 -0000 1.24 +++ gstffmpegcolorspace.c 29 Oct 2004 09:47:41 -0000 1.25 @@ -362,17 +362,20 @@ if (space->from_pixfmt == space->to_pixfmt) { outbuf = inbuf; } else { guint size = avpicture_get_size (space->to_pixfmt, - space->width, space->height); + ROUND_UP_4 (space->width), ROUND_UP_4 (space->height)); outbuf = gst_pad_alloc_buffer (space->srcpad, GST_BUFFER_OFFSET_NONE, size); /* convert */ - avpicture_fill ((AVPicture *) space->from_frame, GST_BUFFER_DATA (inbuf), + gst_ffmpeg_avpicture_fill ((AVPicture *) space->from_frame, + GST_BUFFER_DATA (inbuf), space->from_pixfmt, space->width, space->height); if (space->palette) space->from_frame->data[1] = (uint8_t *) space->palette; - avpicture_fill ((AVPicture *) space->to_frame, GST_BUFFER_DATA (outbuf), + gst_ffmpeg_avpicture_fill ((AVPicture *) space->to_frame, + GST_BUFFER_DATA (outbuf), space->to_pixfmt, space->width, space->height); img_convert ((AVPicture *) space->to_frame, space->to_pixfmt, (AVPicture *) space->from_frame, space->from_pixfmt, Index: gstffmpegdec.c RCS file: /home/cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegdec.c,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- gstffmpegdec.c 24 Oct 2004 22:24:43 -0000 1.66 +++ gstffmpegdec.c 29 Oct 2004 09:47:41 -0000 1.67 @@ -317,7 +317,8 @@ bufsize = avpicture_get_size (context->pix_fmt, context->width, context->height); buf = gst_buffer_new_and_alloc (bufsize); - avpicture_fill ((AVPicture *) picture, GST_BUFFER_DATA (buf), + gst_ffmpeg_avpicture_fill ((AVPicture *) picture, + GST_BUFFER_DATA (buf), context->pix_fmt, context->width, context->height); break; @@ -405,16 +406,17 @@ ffmpegdec->picture, &have_data, data, size); if (len >= 0 && have_data) { /* libavcodec constantly crashes on stupid buffer allocation * errors inside. This drives me crazy, so we let it allocate * it's own buffers and copy to our own buffer afterwards... */ AVPicture pic; gint size = avpicture_get_size (ffmpegdec->context->pix_fmt, - ffmpegdec->context->width, - ffmpegdec->context->height); + ROUND_UP_4 (ffmpegdec->context->width), + ROUND_UP_4 (ffmpegdec->context->height)); outbuf = gst_buffer_new_and_alloc (size); - avpicture_fill (&pic, GST_BUFFER_DATA (outbuf), + gst_ffmpeg_avpicture_fill (&pic, GST_BUFFER_DATA (outbuf), ffmpegdec->context->pix_fmt, ffmpegdec->context->width, ffmpegdec->context->height); img_convert (&pic, ffmpegdec->context->pix_fmt, Index: gstffmpegenc.c RCS file: /home/cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegenc.c,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- gstffmpegenc.c 25 Oct 2004 11:56:52 -0000 1.51 +++ gstffmpegenc.c 29 Oct 2004 09:47:41 -0000 1.52 @@ -421,7 +421,7 @@ /* FIXME: events (discont (flush!) and eos (close down) etc.) */ outbuf = gst_buffer_new_and_alloc (ffmpegenc->buffer_size); - avpicture_fill ((AVPicture *) ffmpegenc->picture, + gst_ffmpeg_avpicture_fill ((AVPicture *) ffmpegenc->picture, GST_BUFFER_DATA (inbuf), ffmpegenc->context->pix_fmt, ffmpegenc->context->width, ffmpegenc->context->height); |