From bd8b9ef6d1689f71ebcefd9a6ac7ff6aa74b676b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 18 Aug 2012 11:19:58 +0200 Subject: demux_gif: change format of packets to make it work again The only decoder which could handle demux_gif's output was vd_raw, which has been removed recently. Instead of re-adding vd_raw, make it work with vd_ffmpeg. By coincidence, the FourCC "raw " fits our needs and it understood by the ffmpeg raw decoder (apparently used in mov files going by libavcodec/rawdec.c). Since there doesn't seem to be any good way to transport the palette in mplayer dmuxer packets, create an AVPacket for this purpose. (struct sh_video provides a "global" palette. Rather than hacking vd_ffmpeg to use it, it seems cleaner to make demux_gif use AVPacket, which supports a per-frame palette.) --- libmpdemux/demux_gif.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'libmpdemux/demux_gif.c') diff --git a/libmpdemux/demux_gif.c b/libmpdemux/demux_gif.c index eee7a856dc..d46e35a564 100644 --- a/libmpdemux/demux_gif.c +++ b/libmpdemux/demux_gif.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "config.h" @@ -157,20 +158,25 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds) return 0; // oops } - len = gif->Image.Width * gif->Image.Height; - dp = new_demux_packet(priv->w * priv->h); buf = calloc(gif->Image.Width, gif->Image.Height); - if (priv->useref) - fast_memcpy(dp->buffer, priv->refimg, priv->w * priv->h); - else - memset(dp->buffer, gif->SBackGroundColor, priv->w * priv->h); - + len = gif->Image.Width * gif->Image.Height; if (DGifGetLine(gif, buf, len) == GIF_ERROR) { PrintGifError(); free(buf); return 0; // oops } + AVPacket *avpacket = talloc(NULL, AVPacket); + if (av_new_packet(avpacket, priv->w * priv->h) != 0) + abort(); + dp = new_demux_packet_fromdata(avpacket->data, avpacket->size); + dp->avpacket = avpacket; + + if (priv->useref) + fast_memcpy(dp->buffer, priv->refimg, priv->w * priv->h); + else + memset(dp->buffer, gif->SBackGroundColor, priv->w * priv->h); + effective_map = gif->Image.ColorMap; if (effective_map == NULL) effective_map = gif->SColorMap; @@ -227,6 +233,12 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds) free(buf); + int palsize = 256 * 4; + uint8_t *pal = av_packet_new_side_data(avpacket, AV_PKT_DATA_PALETTE, + palsize); + if (pal) + memcpy(pal, priv->palette, palsize); + demuxer->video->dpos++; dp->pts = ((float)priv->current_pts) / 100; dp->pos = stream_tell(demuxer->stream); @@ -276,12 +288,14 @@ static demuxer_t* demux_open_gif(demuxer_t* demuxer) // video_read_properties() will choke sh_video->ds = demuxer->video; - sh_video->format = mmioFOURCC(8, 'R', 'G', 'B'); + sh_video->format = mmioFOURCC('r', 'a', 'w', ' '); sh_video->fps = 5.0f; sh_video->frametime = 1.0f / sh_video->fps; - sh_video->bih = malloc(sizeof(*sh_video->bih) + (256 * 4)); + int size = sizeof(*sh_video->bih) + (256 * 4); + sh_video->bih = calloc(1, size); + sh_video->bih->biSize = size; sh_video->bih->biCompression = sh_video->format; sh_video->bih->biWidth = priv->w = (uint16_t)gif->SWidth; sh_video->bih->biHeight = priv->h = (uint16_t)gif->SHeight; -- cgit v1.2.3