[PATCH] gpac: port to FFmpeg-0.8 API
Dominik 'Rathann' Mierzejewski
dominik at greysector.net
Sun Sep 4 00:00:23 CEST 2011
This is a modified version of the patch already present in the package.
I can separate the actual API porting to a separate patch if you want.
--
Fedora http://fedoraproject.org/wiki/User:Rathann
RPMFusion http://rpmfusion.org | MPlayer http://mplayerhq.hu
"Faith manages."
-- Delenn to Lennier in Babylon 5:"Confessions and Lamentations"
-------------- next part --------------
diff -up gpac/configure.ffmpeg gpac/configure
--- gpac/configure.ffmpeg 2010-06-25 14:17:46.000000000 +0200
+++ gpac/configure 2011-09-02 10:56:49.000000000 +0200
@@ -851,12 +851,21 @@ fi
#look for FFMPEG support
+if pkg-config --exists libavcodec libavformat libswscale 2> /dev/null ; then
+ ffmpeg_cflags=`pkg-config --cflags libavcodec libavformat libswscale libavutil`
+ ffmpeg_lflags=`pkg-config --libs libavcodec libavformat libswscale libavutil`
+ has_ffmpeg="system"
+else
+ ffmpeg_cflags=``
+ ffmpeg_lflags=`-lz -lavcodec -lavformat`
+fi
+
cat > $TMPC << EOF
#include <libavcodec/avcodec.h>
int main( void ) { return 0; }
EOF
-if $cc $TMPO -c $TMPC 2> /dev/null ; then
+if $cc $TMPO $ffmpeg_cflags -c $TMPC 2> /dev/null ; then
old_ffmpeg_inc="no"
else
@@ -871,10 +880,10 @@ fi
if test "$cross_prefix" != "" ; then
- if $cc -o $TMPO $TMPC -I$prefix/include -L$prefix/lib -lz -lavcodec -lavformat -lavutil 2> /dev/null ; then
+ if $cc -o $TMPO $TMPC -I$prefix/include -L$prefix/lib $ffmpeg_cflags $ffmpeg_lflags 2> /dev/null ; then
has_ffmpeg="system"
else
- if $cc -o $TMPO $TMPC -I$local_inc -L$local_lib -lz -lavcodec -lavformat 2> /dev/null ; then
+ if $cc -o $TMPO $TMPC -I$local_inc -L$local_lib $ffmpeg_cflags $ffmpeg_lflags 2> /dev/null ; then
has_ffmpeg="local"
echo OK
fi
@@ -1999,6 +2013,10 @@ echo "CONFIG_VORBIS=$has_vorbis" >> conf
echo "CONFIG_THEORA=$has_theora" >> config.mak
echo "CONFIG_FFMPEG=$has_ffmpeg" >> config.mak
echo "CONFIG_FFMPEG_OLD=$old_ffmpeg_inc" >> config.mak
+if test x$has_ffmpeg != x ; then
+ echo "FFMPEG_CFLAGS=$ffmpeg_cflags" >> config.mak
+ echo "FFMPEG_LFLAGS=$ffmpeg_lflags" >> config.mak
+fi
echo "CONFIG_OSS_AUDIO=$has_oss_audio" >> config.mak
echo "CONFIG_ALSA=$has_alsa" >> config.mak
diff -up gpac/modules/ffmpeg_in/ffmpeg_decode.c.ffmpeg gpac/modules/ffmpeg_in/ffmpeg_decode.c
--- gpac/modules/ffmpeg_in/ffmpeg_decode.c.ffmpeg 2010-07-06 10:33:31.000000000 +0200
+++ gpac/modules/ffmpeg_in/ffmpeg_decode.c 2011-09-03 09:11:40.000000000 +0200
@@ -150,7 +150,11 @@ static GF_Err FFDEC_AttachStream(GF_Base
bs = gf_bs_new(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, GF_BITSTREAM_READ);
codec_id = gf_bs_read_u32(bs);
if (ffd->st==GF_STREAM_AUDIO) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
(*ctx)->codec_type = CODEC_TYPE_AUDIO;
+#else
+ (*ctx)->codec_type = AVMEDIA_TYPE_AUDIO;
+#endif
(*ctx)->sample_rate = gf_bs_read_u32(bs);
(*ctx)->channels = gf_bs_read_u16(bs);
(*ctx)->frame_size = gf_bs_read_u16(bs);
@@ -160,7 +164,11 @@ static GF_Err FFDEC_AttachStream(GF_Base
/*ffmpeg specific*/
(*ctx)->block_align = gf_bs_read_u16(bs);
} else if (ffd->st==GF_STREAM_VISUAL) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
(*ctx)->codec_type = CODEC_TYPE_VIDEO;
+#else
+ (*ctx)->codec_type = AVMEDIA_TYPE_VIDEO;
+#endif
(*ctx)->width = gf_bs_read_u16(bs);
(*ctx)->height = gf_bs_read_u16(bs);
}
@@ -177,7 +185,11 @@ static GF_Err FFDEC_AttachStream(GF_Base
bs = gf_bs_new(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, GF_BITSTREAM_READ);
codec_id = gf_bs_read_u32(bs);
if (ffd->st==GF_STREAM_AUDIO) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
(*ctx)->codec_type = CODEC_TYPE_AUDIO;
+#else
+ (*ctx)->codec_type = AVMEDIA_TYPE_AUDIO;
+#endif
(*ctx)->sample_rate = gf_bs_read_u32(bs);
(*ctx)->channels = gf_bs_read_u16(bs);
(*ctx)->frame_size = gf_bs_read_u16(bs);
@@ -190,7 +202,11 @@ static GF_Err FFDEC_AttachStream(GF_Base
(*ctx)->frame_size = 160;
}
} else if (ffd->st==GF_STREAM_VISUAL) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
(*ctx)->codec_type = CODEC_TYPE_VIDEO;
+#else
+ (*ctx)->codec_type = AVMEDIA_TYPE_VIDEO;
+#endif
(*ctx)->width = gf_bs_read_u16(bs);
(*ctx)->height = gf_bs_read_u16(bs);
}
@@ -202,7 +218,11 @@ static GF_Err FFDEC_AttachStream(GF_Base
else {
u32 codec_id = 0;
if (ffd->st==GF_STREAM_VISUAL) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
(*ctx)->codec_type = CODEC_TYPE_VIDEO;
+#else
+ (*ctx)->codec_type = AVMEDIA_TYPE_VIDEO;
+#endif
switch (ffd->oti) {
case GPAC_OTI_VIDEO_MPEG4_PART2:
codec_id = CODEC_ID_MPEG4;
@@ -229,7 +249,11 @@ static GF_Err FFDEC_AttachStream(GF_Base
break;
}
} else if (ffd->st==GF_STREAM_AUDIO) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
(*ctx)->codec_type = CODEC_TYPE_AUDIO;
+#else
+ (*ctx)->codec_type = AVMEDIA_TYPE_AUDIO;
+#endif
switch (ffd->oti) {
case GPAC_OTI_AUDIO_MPEG2_PART3:
case GPAC_OTI_AUDIO_MPEG1:
@@ -284,7 +308,7 @@ static GF_Err FFDEC_AttachStream(GF_Base
/*setup audio streams*/
if (ffd->st==GF_STREAM_AUDIO) {
- if ((*codec)->type == CODEC_ID_MP2) {
+ if ((*codec)->id == CODEC_ID_MP2) {
(*ctx)->frame_size = ((*ctx)->sample_rate > 24000) ? 1152 : 576;
}
/*may be 0 (cfg not known yet)*/
@@ -303,7 +327,15 @@ static GF_Err FFDEC_AttachStream(GF_Base
break;
case CODEC_ID_DVD_SUBTITLE:
*frame = avcodec_alloc_frame();
+#if FF_API_VIDEO_OLD
avcodec_decode_video((*ctx), *frame, &gotpic, esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength);
+#else
+ AVPacket avpkt;
+ av_init_packet(&avpkt);
+ avpkt.data = esd->decoderConfig->decoderSpecificInfo->data;
+ avpkt.size = esd->decoderConfig->decoderSpecificInfo->dataLength;
+ avcodec_decode_video2((*ctx), *frame, &gotpic, &avpkt);
+#endif
ffd->pix_fmt = GF_PIXEL_YV12;
break;
default:
@@ -553,12 +585,24 @@ static GF_Err FFDEC_ProcessData(GF_Media
redecode:
gotpic = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+#if FF_API_AUDIO_OLD
len = avcodec_decode_audio2(ctx, (short *)ffd->audio_buf, &gotpic, inBuffer + ffd->frame_start, inBufferLength - ffd->frame_start);
+#else
+ AVPacket avpkt;
+ av_init_packet(&avpkt);
+ avpkt.data = inBuffer + ffd->frame_start;
+ avpkt.size = inBufferLength - ffd->frame_start;
+ len = avcodec_decode_audio3(ctx, (short *)ffd->audio_buf, &gotpic, &avpkt);
+#endif
if (len<0) { ffd->frame_start = 0; return GF_NON_COMPLIANT_BITSTREAM; }
if (gotpic<0) { ffd->frame_start = 0; return GF_OK; }
+#if FF_API_HURRY_UP
ctx->hurry_up = 0;
+#else
+ ctx->skip_frame = 0;
+#endif
/*first config*/
if (!ffd->out_size) {
@@ -659,7 +703,15 @@ redecode:
avcodec_close(ctx);
*codec = avcodec_find_decoder(CODEC_ID_H263);
if (! (*codec) || (avcodec_open(ctx, *codec)<0)) return GF_NON_COMPLIANT_BITSTREAM;
+#if FF_API_VIDEO_OLD
if (avcodec_decode_video(ctx, frame, &gotpic, inBuffer, inBufferLength) < 0) {
+#else
+ AVPacket avpkt;
+ av_init_packet(&avpkt);
+ avpkt.data = inBuffer;
+ avpkt.size = inBufferLength;
+ if (avcodec_decode_video2(ctx, frame, &gotpic, &avpkt) < 0) {
+#endif
/*nope, stay in MPEG-4*/
avcodec_close(ctx);
*codec = avcodec_find_decoder(old_codec);
@@ -669,7 +721,11 @@ redecode:
}
}
}
+#if FF_API_HURRY_UP
ctx->hurry_up = 0;
+#else
+ ctx->skip_frame = 0;
+#endif
/*some streams use odd width/height frame values*/
if (ffd->out_pix_fmt == GF_PIXEL_YV12) {
diff -up gpac/modules/ffmpeg_in/ffmpeg_demux.c.ffmpeg gpac/modules/ffmpeg_in/ffmpeg_demux.c
--- gpac/modules/ffmpeg_in/ffmpeg_demux.c.ffmpeg 2010-05-27 10:42:25.000000000 +0200
+++ gpac/modules/ffmpeg_in/ffmpeg_demux.c 2011-09-03 09:21:08.000000000 +0200
@@ -242,10 +242,18 @@ static Bool FFD_CanHandleURL(GF_InputSer
for(i = 0; i < ctx->nb_streams; i++) {
AVCodecContext *enc = ctx->streams[i]->codec;
switch(enc->codec_type) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
case CODEC_TYPE_AUDIO:
+#else
+ case AVMEDIA_TYPE_AUDIO:
+#endif
if (!has_audio) has_audio = 1;
break;
+#if LIBAVCODEC_VERSION_MAJOR < 53
case CODEC_TYPE_VIDEO:
+#else
+ case AVMEDIA_TYPE_VIDEO:
+#endif
if (!has_video) has_video= 1;
break;
default:
@@ -255,7 +263,11 @@ static Bool FFD_CanHandleURL(GF_InputSer
if (!has_audio && !has_video) goto exit;
ret = 1;
+#if FF_API_GUESS_FORMAT
fmt_out = guess_stream_format(NULL, url, NULL);
+#else
+ fmt_out = av_guess_format(NULL, url, NULL);
+#endif
if (fmt_out) gf_term_register_mime_type(plug, fmt_out->mime_type, fmt_out->extensions, fmt_out->name);
else {
ext = strrchr(szName, '.');
@@ -554,10 +566,17 @@ static GF_Err FFD_ConnectService(GF_Inpu
switch (res) {
#ifndef _WIN32_WCE
case 0: e = GF_OK; break;
+#if LIBAVUTIL_VERSION_MAJOR < 51
case AVERROR_IO: e = GF_URL_ERROR; goto err_exit;
case AVERROR_INVALIDDATA: e = GF_NON_COMPLIANT_BITSTREAM; goto err_exit;
case AVERROR_NOMEM: e = GF_OUT_OF_MEM; goto err_exit;
case AVERROR_NOFMT: e = GF_NOT_SUPPORTED; goto err_exit;
+#else
+ case AVERROR(EIO): e = GF_URL_ERROR; goto err_exit;
+ case AVERROR(EINVAL): e = GF_NON_COMPLIANT_BITSTREAM; goto err_exit;
+ case AVERROR(ENOMEM): e = GF_OUT_OF_MEM; goto err_exit;
+ case AVERROR(EILSEQ): e = GF_NOT_SUPPORTED; goto err_exit;
+#endif
#endif
default: e = GF_SERVICE_ERROR; goto err_exit;
}
@@ -577,13 +596,21 @@ static GF_Err FFD_ConnectService(GF_Inpu
for (i = 0; i < ffd->ctx->nb_streams; i++) {
AVCodecContext *enc = ffd->ctx->streams[i]->codec;
switch(enc->codec_type) {
+#if LIBAVCODEC_VERSION_MAJOR < 53
case CODEC_TYPE_AUDIO:
+#else
+ case AVMEDIA_TYPE_AUDIO:
+#endif
if ((ffd->audio_st<0) && (ffd->service_type!=1)) {
ffd->audio_st = i;
ffd->audio_tscale = ffd->ctx->streams[i]->time_base;
}
break;
+#if LIBAVCODEC_VERSION_MAJOR < 53
case CODEC_TYPE_VIDEO:
+#else
+ case AVMEDIA_TYPE_VIDEO:
+#endif
if ((ffd->video_st<0) && (ffd->service_type!=2)) {
ffd->video_st = i;
ffd->video_tscale = ffd->ctx->streams[i]->time_base;
diff -up gpac/modules/ffmpeg_in/Makefile.ffmpeg gpac/modules/ffmpeg_in/Makefile
--- gpac/modules/ffmpeg_in/Makefile.ffmpeg 2010-05-21 09:49:31.000000000 +0200
+++ gpac/modules/ffmpeg_in/Makefile 2011-09-02 10:56:49.000000000 +0200
@@ -2,7 +2,7 @@ include ../../config.mak
vpath %.c $(SRC_PATH)/modules/ffmpeg_in
-CFLAGS= $(OPTFLAGS) -I$(SRC_PATH)/include
+CFLAGS= $(OPTFLAGS) -I$(SRC_PATH)/include $(FFMPEG_CFLAGS)
ifeq ($(DEBUGBUILD), yes)
CFLAGS+=-g
@@ -15,7 +15,7 @@ LDFLAGS+=-pg
endif
LOCAL_LIB=
-LINKLIBS=-lgpac -lavcodec -lavformat -lavutil -lz
+LINKLIBS=-lgpac -lz $(FFMPEG_LFLAGS)
#darwin needs bz2
ifeq ($(CONFIG_DARWIN),yes)
@@ -25,8 +25,6 @@ endif
#old ffmpeg lib
ifeq ($(CONFIG_FFMPEG_OLD), yes)
CFLAGS+=-DFFMPEG_OLD_HEADERS
-else
-LINKLIBS+=-lswscale
endif
#common obj
More information about the rpmfusion-developers
mailing list