Description: Replace deprecated FFmpeg API
Author: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Last-Update: 2015-11-02

--- linphone-3.6.1.orig/mediastreamer2/src/videofilters/h264dec.c
+++ linphone-3.6.1/mediastreamer2/src/videofilters/h264dec.c
@@ -119,7 +119,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f
 		s->outbuf.w=ctx->width;
 		s->outbuf.h=ctx->height;
 		s->sws_ctx=sws_getContext(ctx->width,ctx->height,ctx->pix_fmt,
-			ctx->width,ctx->height,PIX_FMT_YUV420P,SWS_FAST_BILINEAR,
+			ctx->width,ctx->height,AV_PIX_FMT_YUV420P,SWS_FAST_BILINEAR,
                 	NULL, NULL, NULL);
 	}
 #if LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(0,9,0)	
@@ -245,7 +245,7 @@ static void dec_process(MSFilter *f){
 	DecData *d=(DecData*)f->data;
 	mblk_t *im;
 	MSQueue nalus;
-	AVFrame orig;
+	AVFrame *orig = av_frame_alloc();
 	ms_queue_init(&nalus);
 	while((im=ms_queue_get(f->inputs[0]))!=NULL){
 		/*push the sps/pps given in sprop-parameter-sets if any*/
@@ -272,11 +272,11 @@ static void dec_process(MSFilter *f){
 				int len;
 				int got_picture=0;
 				AVPacket pkt;
-				avcodec_get_frame_defaults(&orig);
+				av_frame_unref(orig);
 				av_init_packet(&pkt);
 				pkt.data = p;
 				pkt.size = end-p;
-				len=avcodec_decode_video2(&d->av_context,&orig,&got_picture,&pkt);
+				len=avcodec_decode_video2(&d->av_context,orig,&got_picture,&pkt);
 				if (len<=0) {
 					ms_warning("ms_AVdecoder_process: error %i.",len);
 					if ((f->ticker->time - d->last_error_reported_time)>5000 || d->last_error_reported_time==0) {
@@ -286,7 +286,7 @@ static void dec_process(MSFilter *f){
 					break;
 				}
 				if (got_picture) {
-					ms_queue_put(f->outputs[0],get_as_yuvmsg(f,d,&orig));
+					ms_queue_put(f->outputs[0],get_as_yuvmsg(f,d,orig));
 					if (!d->first_image_decoded) {
 						ms_filter_notify_no_arg(f,MS_VIDEO_DECODER_FIRST_IMAGE_DECODED);
 						d->first_image_decoded = TRUE;
@@ -297,6 +297,7 @@ static void dec_process(MSFilter *f){
 		}
 		d->packet_num++;
 	}
+	av_frame_free(&orig);
 }
 
 static int dec_add_fmtp(MSFilter *f, void *arg){
--- linphone-3.6.1.orig/mediastreamer2/src/videofilters/jpegwriter.c
+++ linphone-3.6.1/mediastreamer2/src/videofilters/jpegwriter.c
@@ -84,7 +84,7 @@ static void jpg_process(MSFilter *f){
 		mblk_t *m=ms_queue_peek_last(f->inputs[0]);
 		if (ms_yuv_buf_init_from_mblk(&yuvbuf,m)==0){
 			int error, got_output;
-			AVFrame pict;
+			AVFrame *pict = av_frame_alloc();
 			AVPacket pkt = { 0 };
 			mblk_t *jpegm;
 			struct SwsContext *sws_ctx;
@@ -95,20 +95,22 @@ static void jpg_process(MSFilter *f){
 			avctx->height=yuvbuf.h;
 			avctx->time_base.num = 1;
 			avctx->time_base.den =1;
-			avctx->pix_fmt=PIX_FMT_YUVJ420P;
+			avctx->pix_fmt=AV_PIX_FMT_YUVJ420P;
 
 			error=avcodec_open(avctx,s->codec);
 			if (error!=0) {
 				ms_error("avcodec_open() failed: %i",error);
 				cleanup(s,NULL);
 				av_free(avctx);
+				av_frame_free(&pict);
 				return;
 			}
-			sws_ctx=sws_getContext(avctx->width,avctx->height,PIX_FMT_YUV420P,
+			sws_ctx=sws_getContext(avctx->width,avctx->height,AV_PIX_FMT_YUV420P,
 				avctx->width,avctx->height,avctx->pix_fmt,SWS_FAST_BILINEAR,NULL, NULL, NULL);
 			if (sws_ctx==NULL) {
 				ms_error(" sws_getContext() failed.");
 				cleanup(s,avctx);
+				av_frame_free(&pict);
 				goto end;
 			}
 			jpegm=ms_yuv_buf_alloc (&yuvjpeg,avctx->width, avctx->height);
@@ -121,13 +123,14 @@ static void jpg_process(MSFilter *f){
 				sws_freeContext(sws_ctx);
 				cleanup(s,avctx);
 				freemsg(jpegm);
+				av_frame_free(&pict);
 				goto end;
 			}
 			sws_freeContext(sws_ctx);
 			
-			avcodec_get_frame_defaults(&pict);
-			avpicture_fill((AVPicture*)&pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
-			error=avcodec_encode_video2(avctx, &pkt, &pict, &got_output);
+			av_frame_unref(pict);
+			avpicture_fill((AVPicture*)pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
+			error=avcodec_encode_video2(avctx, &pkt, pict, &got_output);
 			if (error<0){
 				ms_error("Could not encode jpeg picture.");
 			}else if (got_output) {
@@ -140,6 +143,7 @@ static void jpg_process(MSFilter *f){
 			av_packet_unref(&pkt);
 			cleanup(s,avctx);
 			freemsg(jpegm);
+			av_frame_free(&pict);
 		}
 		goto end;
 	}
--- linphone-3.6.1.orig/mediastreamer2/src/videofilters/nowebcam.c
+++ linphone-3.6.1/mediastreamer2/src/videofilters/nowebcam.c
@@ -82,7 +82,7 @@ static mblk_t *jpeg2yuv(uint8_t *jpgbuf,
 	pkt.data=jpgbuf;
 	pkt.size=bufsize;
 
-	if (avcodec_decode_video2(&av_context,&orig,&got_picture,&pkt) < 0) {
+	if (avcodec_decode_video2(&av_context,orig,&got_picture,&pkt) < 0) {
 		ms_error("jpeg2yuv: avcodec_decode_video failed");
 		av_frame_free(&orig);
 		avcodec_close(&av_context);
@@ -90,9 +90,9 @@ static mblk_t *jpeg2yuv(uint8_t *jpgbuf,
 	}
 	ret=ms_yuv_buf_alloc(&dest, reqsize->width,reqsize->height);
 	/* not using SWS_FAST_BILINEAR because it doesn't play well with
-	 * av_context.pix_fmt set to PIX_FMT_YUVJ420P by jpeg decoder */
+	 * av_context.pix_fmt set to AV_PIX_FMT_YUVJ420P by jpeg decoder */
 	sws_ctx=sws_getContext(av_context.width,av_context.height,av_context.pix_fmt,
-		reqsize->width,reqsize->height,PIX_FMT_YUV420P,SWS_BILINEAR,
+		reqsize->width,reqsize->height,AV_PIX_FMT_YUV420P,SWS_BILINEAR,
                 NULL, NULL, NULL);
 	if (sws_ctx==NULL) {
 		ms_error("jpeg2yuv: ms_sws_getContext() failed.");
--- linphone-3.6.1.orig/mediastreamer2/src/videofilters/videodec.c
+++ linphone-3.6.1/mediastreamer2/src/videofilters/videodec.c
@@ -40,7 +40,7 @@ typedef struct DecState{
 	YuvBuf outbuf;
 	mblk_t *yuv_msg;
 	struct SwsContext *sws_ctx;
-	enum PixelFormat output_pix_fmt;
+	enum AVPixelFormat output_pix_fmt;
 	uint8_t dci[512];
 	int dci_size;
 	uint64_t last_error_reported_time;
@@ -57,7 +57,7 @@ static void dec_init(MSFilter *f, enum C
 	s->codec=cid;
 	s->input=NULL;
 	s->yuv_msg=NULL;
-	s->output_pix_fmt=PIX_FMT_YUV420P;
+	s->output_pix_fmt=AV_PIX_FMT_YUV420P;
 	s->outbuf.w=0;
 	s->outbuf.h=0;
 	s->sws_ctx=NULL;
--- linphone-3.6.1.orig/mediastreamer2/src/videofilters/videoenc.c
+++ linphone-3.6.1/mediastreamer2/src/videofilters/videoenc.c
@@ -247,7 +247,7 @@ static void prepare(EncState *s){
 		c->time_base.num = 1;
 		c->time_base.den = (int)s->fps;
 		c->gop_size=(int)s->fps*5; /*emit I frame every 5 seconds*/
-		c->pix_fmt=PIX_FMT_YUVJ420P;
+		c->pix_fmt=AV_PIX_FMT_YUVJ420P;
 		s->comp_buf=allocb(c->bit_rate*2,0);
 		return;
 	}
@@ -280,7 +280,7 @@ static void prepare(EncState *s){
 	c->time_base.num = 1;
 	c->time_base.den = (int)s->fps;
 	c->gop_size=(int)s->fps*10; /*emit I frame every 10 seconds*/
-	c->pix_fmt=PIX_FMT_YUV420P;
+	c->pix_fmt=AV_PIX_FMT_YUV420P;
 	s->comp_buf=allocb(c->bit_rate*2,0);
 	
 	ms_message("Codec size set to w=%i/h=%i",c->width, c->height);
@@ -755,7 +755,7 @@ static void split_and_send(MSFilter *f,
 
 static void process_frame(MSFilter *f, mblk_t *inm){
 	EncState *s=(EncState*)f->data;
-	AVFrame pict;
+	AVFrame *pict = av_frame_alloc();
 	AVPacket pkt;
 	AVCodecContext *c=&s->av_context;
 	int error, got_output;
@@ -765,25 +765,25 @@ static void process_frame(MSFilter *f, m
 
 	ms_yuv_buf_init_from_mblk(&yuv, inm);
 	/* convert image if necessary */
-	avcodec_get_frame_defaults(&pict);
-	avpicture_fill((AVPicture*)&pict,yuv.planes[0],c->pix_fmt,c->width,c->height);
+	av_frame_unref(pict);
+	avpicture_fill((AVPicture*)pict,yuv.planes[0],c->pix_fmt,c->width,c->height);
 	
 	/* timestamp used by ffmpeg, unset here */
-	pict.pts=AV_NOPTS_VALUE;
+	pict->pts=AV_NOPTS_VALUE;
 		
 	if (video_starter_need_i_frame (&s->starter,f->ticker->time)){
 		/*sends an I frame at 2 seconds and 4 seconds after the beginning of the call*/
 		s->req_vfu=TRUE;
 	}
 	if (s->req_vfu){
-		pict.pict_type=FF_I_TYPE;
+		pict->pict_type=FF_I_TYPE;
 		s->req_vfu=FALSE;
 	}
 	comp_buf->b_rptr=comp_buf->b_wptr=comp_buf->b_datap->db_base;
 
 	pkt.data = (uint8_t *)comp_buf->b_wptr;
 	pkt.size = comp_buf_sz;
-	error=avcodec_encode_video2(c, &pkt, &pict, &got_output);
+	error=avcodec_encode_video2(c, &pkt, pict, &got_output);
 
 	if (error<0) ms_warning("ms_AVencoder_process: error %i.",error);
 	else if (got_output) {
@@ -798,6 +798,7 @@ static void process_frame(MSFilter *f, m
 		split_and_send(f,s,comp_buf);
 	}
 	freemsg(inm);
+	av_frame_free(&pict);
 }
 
 static void enc_process(MSFilter *f){
--- linphone-3.6.1.orig/mediastreamer2/src/voip/msvideo.c
+++ linphone-3.6.1/mediastreamer2/src/voip/msvideo.c
@@ -349,21 +349,21 @@ void ms_rgb_to_yuv(const uint8_t rgb[3],
 int ms_pix_fmt_to_ffmpeg(MSPixFmt fmt){
 	switch(fmt){
 		case MS_RGBA32:
-			return PIX_FMT_RGBA;
+			return AV_PIX_FMT_RGBA;
 		case MS_RGB24:
-			return PIX_FMT_RGB24;
+			return AV_PIX_FMT_RGB24;
 		case MS_RGB24_REV:
-			return PIX_FMT_BGR24;
+			return AV_PIX_FMT_BGR24;
 		case MS_YUV420P:
-			return PIX_FMT_YUV420P;
+			return AV_PIX_FMT_YUV420P;
 		case MS_YUYV:
-			return PIX_FMT_YUYV422;
+			return AV_PIX_FMT_YUYV422;
 		case MS_UYVY:
-			return PIX_FMT_UYVY422;
+			return AV_PIX_FMT_UYVY422;
 		case MS_YUY2:
-			return PIX_FMT_YUYV422;   /* <- same as MS_YUYV */
+			return AV_PIX_FMT_YUYV422;   /* <- same as MS_YUYV */
 		case MS_RGB565:
-			return PIX_FMT_RGB565;
+			return AV_PIX_FMT_RGB565;
 		default:
 			ms_fatal("format not supported.");
 			return -1;
@@ -373,19 +373,19 @@ int ms_pix_fmt_to_ffmpeg(MSPixFmt fmt){
 
 MSPixFmt ffmpeg_pix_fmt_to_ms(int fmt){
 	switch(fmt){
-		case PIX_FMT_RGB24:
+		case AV_PIX_FMT_RGB24:
 			return MS_RGB24;
-		case PIX_FMT_BGR24:
+		case AV_PIX_FMT_BGR24:
 			return MS_RGB24_REV;
-		case PIX_FMT_YUV420P:
+		case AV_PIX_FMT_YUV420P:
 			return MS_YUV420P;
-		case PIX_FMT_YUYV422:
+		case AV_PIX_FMT_YUYV422:
 			return MS_YUYV;     /* same as MS_YUY2 */
-		case PIX_FMT_UYVY422:
+		case AV_PIX_FMT_UYVY422:
 			return MS_UYVY;
-		case PIX_FMT_RGBA:
+		case AV_PIX_FMT_RGBA:
 			return MS_RGBA32;
-		case PIX_FMT_RGB565:
+		case AV_PIX_FMT_RGB565:
 			return MS_RGB565;
 		default:
 			ms_fatal("format not supported.");
