Commit 235af313 authored by Guillaume Beraudo's avatar Guillaume Beraudo

Use newest ffmpeg functions.

parent 46b7347d
......@@ -27,8 +27,12 @@ mediastreamer2.spec
missing
stamp-h1
*.gmo
java/bin/
java/libs/
java/gen/
libs
*.dirstamp
*.kdev4
tools/test_x11window
tools/tones
......@@ -146,6 +146,14 @@ AC_DEFUN([MS_CHECK_VIDEO],[
AC_CHECK_HEADERS(libswscale/swscale.h)
CPPFLAGS=$CPPFLAGS_save
LIBS_save=$LIBS
dnl check if we need to emulate newer functions
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 )
LIBS=$LIBS_save
AC_ARG_ENABLE(sdl,
[AS_HELP_STRING([--disable-sdl], [Disable SDL support (default: disabled except on macos)])],
[case "${enableval}" in
......@@ -276,7 +284,7 @@ AC_DEFUN([MS_CHECK_VIDEO],[
VIDEO_CFLAGS="$VIDEO_CFLAGS -DHAVE_XV"
fi
fi
AC_SUBST(VIDEO_CFLAGS)
AC_SUBST(VIDEO_LIBS)
])
......@@ -20,20 +20,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ffmpeg-priv.h"
#ifdef FF_API_ALLOC_CONTEXT
#if !FF_API_ALLOC_CONTEXT
AVCodecContext *avcodec_alloc_context(void) {
return avcodec_alloc_context3(NULL);
}
void avcodec_get_context_defaults(AVCodecContext *s) {
avcodec_get_context_defaults3(s, NULL);
#ifndef HAVE_FUN_avcodec_encode_video2
int avcodec_encode_video2 (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) {
return avcodec_encode_video(avctx, avpkt->data, avpkt->size);
}
#endif
#endif
#ifdef FF_API_AVCODEC_OPEN
#if !FF_API_AVCODEC_OPEN
int avcodec_open(AVCodecContext *avctx, AVCodec *codec) {
return avcodec_open2(avctx, codec, NULL);
#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
int avcodec_get_context_defaults3 (AVCodecContext *s, const AVCodec *codec) {
return avcodec_get_context_defaults(s);
}
#endif
#endif
#ifndef HAVE_FUN_avcodec_open2 /**/
int avcodec_open2 (AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options) {
return avcodec_open(avctx, codec);
}
#endif
\ No newline at end of file
......@@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* new layout */
# include <libavcodec/avcodec.h>
# include <libavutil/avutil.h>
# include <libavutil/mem.h>
#endif
#if defined(HAVE_LIBSWSCALE_SWSCALE_H)
......@@ -59,22 +60,26 @@ static inline int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
return avcodec_decode_video(avctx,picture, got_picture_ptr,avpkt->data,avpkt->size);
}
#endif
#if (LIBAVCODEC_VERSION_MAJOR >= 56)
#include <libavcodec/old_codec_ids.h>
#endif
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,25,0)
#define CodecID AVCodecID
#endif
#ifdef FF_API_ALLOC_CONTEXT
#if !FF_API_ALLOC_CONTEXT
AVCodecContext *avcodec_alloc_context(void);
void avcodec_get_context_defaults(AVCodecContext *s);
#endif
#ifndef HAVE_FUN_avcodec_encode_video2
int avcodec_encode_video2 (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr);
#endif
#ifdef FF_API_AVCODEC_OPEN
#if !FF_API_AVCODEC_OPEN
int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
#ifndef HAVE_FUN_avcodec_get_context_defaults3 /**/
int avcodec_get_context_defaults3 (AVCodecContext *s, const AVCodec *codec);
#endif
#ifndef HAVE_FUN_avcodec_open2 /**/
int avcodec_open2 (AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
#endif
#endif /*iHAVE_LIBAVCODEC_AVCODEC_H*/
#endif /* FFMPEG_PRIV_H */
......@@ -58,8 +58,8 @@ static void dec_open(DecData *d){
int error;
codec=avcodec_find_decoder(CODEC_ID_H264);
if (codec==NULL) ms_fatal("Could not find H264 decoder in ffmpeg.");
avcodec_get_context_defaults(&d->av_context);
error=avcodec_open(&d->av_context,codec);
avcodec_get_context_defaults3(&d->av_context, NULL);
error=avcodec_open2(&d->av_context,codec, NULL);
if (error!=0){
ms_fatal("avcodec_open() failed.");
}
......
......@@ -83,14 +83,16 @@ static void jpg_process(MSFilter *f){
MSPicture yuvbuf, yuvjpeg;
mblk_t *m=ms_queue_peek_last(f->inputs[0]);
if (ms_yuv_buf_init_from_mblk(&yuvbuf,m)==0){
int error;
int error,got_pict;
int comp_buf_sz=msgdsize(m);
uint8_t *comp_buf=(uint8_t*)alloca(comp_buf_sz);
AVFrame pict;
mblk_t *jpegm;
struct SwsContext *sws_ctx;
struct AVPacket packet;
memset(&packet, 0, sizeof(packet));
AVCodecContext *avctx=avcodec_alloc_context();
AVCodecContext *avctx=avcodec_alloc_context3(NULL);
avctx->width=yuvbuf.w;
avctx->height=yuvbuf.h;
......@@ -98,7 +100,7 @@ static void jpg_process(MSFilter *f){
avctx->time_base.den =1;
avctx->pix_fmt=PIX_FMT_YUVJ420P;
error=avcodec_open(avctx,s->codec);
error=avcodec_open2(avctx,s->codec,NULL);
if (error!=0) {
ms_error("avcodec_open() failed: %i",error);
cleanup(s,NULL);
......@@ -128,7 +130,8 @@ static void jpg_process(MSFilter *f){
avcodec_get_frame_defaults(&pict);
avpicture_fill((AVPicture*)&pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
error=avcodec_encode_video(avctx, (uint8_t*)comp_buf,comp_buf_sz, &pict);
packet.data=comp_buf; packet.size=comp_buf_sz;
error=avcodec_encode_video2(avctx, &packet, &pict, &got_pict);
if (error<0){
ms_error("Could not encode jpeg picture.");
}else{
......
......@@ -68,8 +68,8 @@ static mblk_t *jpeg2yuv(uint8_t *jpgbuf, int bufsize, MSVideoSize *reqsize){
return NULL;
}
avcodec_get_context_defaults(&av_context);
if (avcodec_open(&av_context,codec)<0){
avcodec_get_context_defaults3(&av_context,NULL);
if (avcodec_open2(&av_context,codec,NULL)<0){
ms_error("jpeg2yuv: avcodec_open failed");
return NULL;
}
......
......@@ -53,7 +53,7 @@ static void dec_init(MSFilter *f, enum CodecID cid){
DecState *s=(DecState *)ms_new0(DecState,1);
ms_ffmpeg_check_init();
avcodec_get_context_defaults(&s->av_context);
avcodec_get_context_defaults3(&s->av_context, NULL);
s->av_codec=NULL;
s->codec=cid;
s->input=NULL;
......@@ -135,7 +135,7 @@ static void dec_preprocess(MSFilter *f){
if (s->av_context.codec==NULL){
/* we must know picture size before initializing snow decoder*/
if (s->codec!=CODEC_ID_SNOW){
error=avcodec_open(&s->av_context, s->av_codec);
error=avcodec_open2(&s->av_context, s->av_codec, NULL);
if (error!=0) ms_error("avcodec_open() failed: %i",error);
if (s->codec==CODEC_ID_MPEG4 && s->dci_size>0){
s->av_context.extradata=s->dci;
......@@ -225,7 +225,7 @@ static mblk_t * parse_snow_header(DecState *s,mblk_t *inm){
int error;
s->av_context.width=h>>16;
s->av_context.height=h&0xffff;
error=avcodec_open(&s->av_context, s->av_codec);
error=avcodec_open2(&s->av_context, s->av_codec, NULL);
if (error!=0) ms_error("avcodec_open() failed for snow: %i",error);
else {
s->snow_initialized=TRUE;
......
......@@ -281,7 +281,7 @@ static void prepare(EncState *s){
AVCodecContext *c=&s->av_context;
const int max_br_vbv=128000;
avcodec_get_context_defaults(c);
avcodec_get_context_defaults3(c, NULL);
if (s->codec==CODEC_ID_MJPEG)
{
ms_message("Codec bitrate set to %i",c->bit_rate);
......@@ -387,7 +387,7 @@ static void enc_preprocess(MSFilter *f){
ms_error("could not find encoder for codec id %i",s->codec);
return;
}
error=avcodec_open(&s->av_context, s->av_codec);
error=avcodec_open2(&s->av_context, s->av_codec, NULL);
if (error!=0) {
ms_error("avcodec_open() failed: %i",error);
return;
......@@ -806,10 +806,12 @@ static void process_frame(MSFilter *f, mblk_t *inm){
EncState *s=(EncState*)f->data;
AVFrame pict;
AVCodecContext *c=&s->av_context;
int error;
int error,got_packet;
mblk_t *comp_buf=s->comp_buf;
int comp_buf_sz=comp_buf->b_datap->db_lim-comp_buf->b_datap->db_base;
YuvBuf yuv;
struct AVPacket packet;
memset(&packet, 0, sizeof(packet));
ms_yuv_buf_init_from_mblk(&yuv, inm);
/* convert image if necessary */
......@@ -836,7 +838,8 @@ static void process_frame(MSFilter *f, mblk_t *inm){
comp_buf_sz-=4;
}
error=avcodec_encode_video(c, (uint8_t*)comp_buf->b_wptr,comp_buf_sz, &pict);
packet.data=comp_buf->b_wptr; packet.size=comp_buf_sz;
error=avcodec_encode_video2(c, &packet, &pict, &got_packet);
if (error<=0) ms_warning("ms_AVencoder_process: error %i.",error);
else{
......
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