Commit 916b6465 authored by Ghislain MARY's avatar Ghislain MARY

Fix compilation with different versions of ffmpeg.

parent 507eccbf
......@@ -151,6 +151,9 @@ AC_DEFUN([MS_CHECK_VIDEO],[
AC_CHECK_LIB(avcodec,avcodec_get_context_defaults3, [AC_DEFINE([HAVE_FUN_avcodec_get_context_defaults3], [], [Have ffmpeg function])] , , $FFMPEG_LIBS )
AC_CHECK_LIB(avcodec,avcodec_open2, [AC_DEFINE([HAVE_FUN_avcodec_open2], [], [Have ffmpeg function])] , , $FFMPEG_LIBS )
AC_CHECK_LIB(avcodec,avcodec_encode_video2, [AC_DEFINE([HAVE_FUN_avcodec_encode_video2], [], [Have ffmpeg function])] , , $FFMPEG_LIBS )
AC_CHECK_LIB(avutil,av_frame_alloc, [AC_DEFINE([HAVE_FUN_av_frame_alloc], [], [Have ffmpeg function])] , , $FFMPEG_LIBS )
AC_CHECK_LIB(avutil,av_frame_free, [AC_DEFINE([HAVE_FUN_av_frame_free], [], [Have ffmpeg function])] , , $FFMPEG_LIBS )
AC_CHECK_LIB(avutil,av_frame_unref, [AC_DEFINE([HAVE_FUN_av_frame_unref], [], [Have ffmpeg function])] , , $FFMPEG_LIBS )
LIBS=$LIBS_save
......
......@@ -56,4 +56,32 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
int avcodec_open2 (AVCodecContext *avctx, const AVCodec *codec, /*AVDictionary*/ void **options) {
return avcodec_open(avctx, (AVCodec*)codec);
}
#endif
\ No newline at end of file
#endif
#ifndef HAVE_FUN_av_frame_alloc
AVFrame* av_frame_alloc (void) {
return avcodec_alloc_frame();
}
#endif
#ifndef HAVE_FUN_av_frame_free
void av_frame_free (AVFrame** frame) {
/*
From http://git.videolan.org/?p=ffmpeg.git;a=blob;f=doc/APIchanges
2012-09-24 - 46a3595 / a42aada - lavc 54.59.100 / 54.28.0 - avcodec.h
Add avcodec_free_frame(). This function must now
be used for freeing an AVFrame.
*/
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,28,0)
avcodec_free_frame(frame);
#else
av_free(*frame);
#endif
}
#endif
#ifndef HAVE_FUN_av_frame_unref
void av_frame_unref (AVFrame *frame) {
avcodec_get_frame_defaults(frame);
}
#endif
......@@ -82,5 +82,18 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
int avcodec_open2 (AVCodecContext *avctx, const AVCodec *codec, /*AVDictionary*/ void **options);
#endif
#ifndef HAVE_FUN_av_frame_alloc
AVFrame* av_frame_alloc (void);
#endif
#ifndef HAVE_FUN_av_frame_free
void av_frame_free (AVFrame** frame);
#endif
#ifndef HAVE_FUN_av_frame_unref
void av_frame_unref (AVFrame *frame);
#endif
#endif /*iHAVE_LIBAVCODEC_AVCODEC_H*/
#endif /* FFMPEG_PRIV_H */
......@@ -79,7 +79,7 @@ static void dec_init(MSFilter *f){
d->outbuf.h=0;
d->bitstream_size=65536;
d->bitstream=ms_malloc0(d->bitstream_size);
d->orig = avcodec_alloc_frame();
d->orig = av_frame_alloc();
if (!d->orig) {
ms_error("Could not allocate frame");
}
......@@ -103,7 +103,7 @@ static void dec_uninit(MSFilter *f){
if (d->yuv_msg) freemsg(d->yuv_msg);
if (d->sps) freemsg(d->sps);
if (d->pps) freemsg(d->pps);
if (d->orig) avcodec_free_frame(&d->orig);
if (d->orig) av_frame_free(&d->orig);
ms_free(d->bitstream);
ms_free(d);
}
......@@ -276,7 +276,7 @@ static void dec_process(MSFilter *f){
int len;
int got_picture=0;
AVPacket pkt;
avcodec_get_frame_defaults(d->orig);
av_frame_unref(d->orig);
av_init_packet(&pkt);
pkt.data = p;
pkt.size = end-p;
......
......@@ -41,7 +41,7 @@ static void jpg_init(MSFilter *f){
if (s->codec==NULL){
ms_error("Could not find CODEC_ID_MJPEG !");
}
s->pict = avcodec_alloc_frame();
s->pict = av_frame_alloc();
f->data=s;
}
......@@ -50,7 +50,7 @@ static void jpg_uninit(MSFilter *f){
if (s->file!=NULL){
fclose(s->file);
}
if (s->pict) avcodec_free_frame(&s->pict);
if (s->pict) av_frame_free(&s->pict);
ms_free(s);
}
......@@ -130,7 +130,7 @@ static void jpg_process(MSFilter *f){
}
sws_freeContext(sws_ctx);
avcodec_get_frame_defaults(s->pict);
av_frame_unref(s->pict);
avpicture_fill((AVPicture*)s->pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
packet.data=comp_buf; packet.size=comp_buf_sz;
error=avcodec_encode_video2(avctx, &packet, s->pict, &got_pict);
......
......@@ -61,7 +61,7 @@ static mblk_t *jpeg2yuv(uint8_t *jpgbuf, int bufsize, MSVideoSize *reqsize){
AVPacket pkt;
MSPicture dest;
AVCodec *codec=avcodec_find_decoder(CODEC_ID_MJPEG);
AVFrame* orig = avcodec_alloc_frame();
AVFrame* orig = av_frame_alloc();
if (codec==NULL){
ms_error("Could not find MJPEG decoder in ffmpeg.");
......@@ -107,7 +107,7 @@ static mblk_t *jpeg2yuv(uint8_t *jpgbuf, int bufsize, MSVideoSize *reqsize){
return NULL;
}
sws_freeContext(sws_ctx);
avcodec_free_frame(&orig);
av_frame_free(&orig);
avcodec_close(&av_context);
return ret;
#elif TARGET_OS_IPHONE
......
......@@ -69,7 +69,7 @@ static void dec_init(MSFilter *f, enum CodecID cid){
if (s->av_codec==NULL){
ms_error("Could not find decoder %i!",s->codec);
}
s->orig = avcodec_alloc_frame();
s->orig = av_frame_alloc();
if (!s->orig) {
ms_error("Could not allocate frame");
}
......@@ -99,7 +99,7 @@ static void dec_snow_init(MSFilter *f){
static void dec_uninit(MSFilter *f){
DecState *s=(DecState*)f->data;
if (s->orig) {
avcodec_free_frame(&s->orig);
av_frame_free(&s->orig);
s->orig = NULL;
}
if (s->av_context.codec!=NULL){
......
......@@ -231,7 +231,7 @@ static void enc_init(MSFilter *f, enum CodecID codec)
s->av_context.codec=NULL;
s->vconf_list = get_vconf_list(s);
s->vconf = ms_video_find_best_configuration_for_bitrate(s->vconf_list, 500000);
s->pict = avcodec_alloc_frame();
s->pict = av_frame_alloc();
}
static void enc_h263_init(MSFilter *f){
......@@ -336,7 +336,7 @@ static void prepare_mpeg4(EncState *s){
static void enc_uninit(MSFilter *f){
EncState *s=(EncState*)f->data;
if (s->pict) avcodec_free_frame(&s->pict);
if (s->pict) av_frame_free(&s->pict);
ms_free(s);
}
......@@ -789,7 +789,7 @@ static void process_frame(MSFilter *f, mblk_t *inm){
ms_yuv_buf_init_from_mblk(&yuv, inm);
/* convert image if necessary */
avcodec_get_frame_defaults(s->pict);
av_frame_unref(s->pict);
avpicture_fill((AVPicture*)s->pict,yuv.planes[0],c->pix_fmt,c->width,c->height);
/* timestamp used by ffmpeg, unset here */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment