[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48028] trunk/blender: Reduce amount of deprecated symbols used from FFmpeg

Sergey Sharybin sergey.vfx at gmail.com
Mon Jun 18 12:29:21 CEST 2012


Revision: 48028
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48028
Author:   nazgul
Date:     2012-06-18 10:29:11 +0000 (Mon, 18 Jun 2012)
Log Message:
-----------
Reduce amount of deprecated symbols used from FFmpeg

This switches some areas of Blender which are related on FFmpeg stuff
from deprecated symbols to currently supported one.

Pretty straightforward changes based on documentation of FFmpeg's
API which symbols should be now used.

This should make Blender compatible with recent FFmpeg 0.11.

Should be no functional changes.

Modified Paths:
--------------
    trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
    trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp
    trunk/blender/intern/ffmpeg/ffmpeg_compat.h
    trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
    trunk/blender/source/blender/imbuf/intern/anim_movie.c
    trunk/blender/source/blender/imbuf/intern/indexer.c
    trunk/blender/source/blender/imbuf/intern/util.c
    trunk/blender/source/gameengine/VideoTexture/VideoFFmpeg.cpp
    trunk/blender/source/gameengine/VideoTexture/VideoFFmpeg.h

Modified: trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
===================================================================
--- trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp	2012-06-18 09:52:41 UTC (rev 48027)
+++ trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp	2012-06-18 10:29:11 UTC (rev 48028)
@@ -143,23 +143,23 @@
 
 	switch(m_codecCtx->sample_fmt)
 	{
-	case SAMPLE_FMT_U8:
+	case AV_SAMPLE_FMT_U8:
 		m_convert = AUD_convert_u8_float;
 		m_specs.format = AUD_FORMAT_U8;
 		break;
-	case SAMPLE_FMT_S16:
+	case AV_SAMPLE_FMT_S16:
 		m_convert = AUD_convert_s16_float;
 		m_specs.format = AUD_FORMAT_S16;
 		break;
-	case SAMPLE_FMT_S32:
+	case AV_SAMPLE_FMT_S32:
 		m_convert = AUD_convert_s32_float;
 		m_specs.format = AUD_FORMAT_S32;
 		break;
-	case SAMPLE_FMT_FLT:
+	case AV_SAMPLE_FMT_FLT:
 		m_convert = AUD_convert_copy<float>;
 		m_specs.format = AUD_FORMAT_FLOAT32;
 		break;
-	case SAMPLE_FMT_DBL:
+	case AV_SAMPLE_FMT_DBL:
 		m_convert = AUD_convert_double_float;
 		m_specs.format = AUD_FORMAT_FLOAT64;
 		break;
@@ -189,7 +189,7 @@
 	}
 	catch(AUD_Exception&)
 	{
-		av_close_input_file(m_formatCtx);
+		avformat_close_input(&m_formatCtx);
 		throw;
 	}
 }
@@ -227,7 +227,7 @@
 	}
 	catch(AUD_Exception&)
 	{
-		av_close_input_stream(m_formatCtx);
+		avformat_close_input(&m_formatCtx);
 		av_free(m_aviocontext);
 		throw;
 	}
@@ -239,7 +239,7 @@
 
 	if(m_aviocontext)
 	{
-		av_close_input_stream(m_formatCtx);
+		avformat_close_input(&m_formatCtx);
 		av_free(m_aviocontext);
 	}
 	else

Modified: trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp
===================================================================
--- trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp	2012-06-18 09:52:41 UTC (rev 48027)
+++ trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp	2012-06-18 10:29:11 UTC (rev 48028)
@@ -133,23 +133,23 @@
 		{
 		case AUD_FORMAT_U8:
 			m_convert = AUD_convert_float_u8;
-			m_codecCtx->sample_fmt = SAMPLE_FMT_U8;
+			m_codecCtx->sample_fmt = AV_SAMPLE_FMT_U8;
 			break;
 		case AUD_FORMAT_S16:
 			m_convert = AUD_convert_float_s16;
-			m_codecCtx->sample_fmt = SAMPLE_FMT_S16;
+			m_codecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
 			break;
 		case AUD_FORMAT_S32:
 			m_convert = AUD_convert_float_s32;
-			m_codecCtx->sample_fmt = SAMPLE_FMT_S32;
+			m_codecCtx->sample_fmt = AV_SAMPLE_FMT_S32;
 			break;
 		case AUD_FORMAT_FLOAT32:
 			m_convert = AUD_convert_copy<float>;
-			m_codecCtx->sample_fmt = SAMPLE_FMT_FLT;
+			m_codecCtx->sample_fmt = AV_SAMPLE_FMT_FLT;
 			break;
 		case AUD_FORMAT_FLOAT64:
 			m_convert = AUD_convert_float_double;
-			m_codecCtx->sample_fmt = SAMPLE_FMT_DBL;
+			m_codecCtx->sample_fmt = AV_SAMPLE_FMT_DBL;
 			break;
 		default:
 			AUD_THROW(AUD_ERROR_FFMPEG, format_error);

Modified: trunk/blender/intern/ffmpeg/ffmpeg_compat.h
===================================================================
--- trunk/blender/intern/ffmpeg/ffmpeg_compat.h	2012-06-18 09:52:41 UTC (rev 48027)
+++ trunk/blender/intern/ffmpeg/ffmpeg_compat.h	2012-06-18 10:29:11 UTC (rev 48028)
@@ -40,7 +40,6 @@
 #endif
 
 #include <libswscale/swscale.h>
-#include <libavcodec/opt.h>
 
 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 105))
 #define FFMPEG_HAVE_AVIO 1
@@ -76,6 +75,20 @@
 #define FFMPEG_FFV1_ALPHA_SUPPORTED
 #endif
 
+#if ((LIBAVFORMAT_VERSION_MAJOR < 53) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR < 24)) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR < 24) && (LIBAVFORMAT_VERSION_MICRO < 2)))
+#define avformat_close_input(x) av_close_input_file(*(x))
+#endif
+
+#if ((LIBAVFORMAT_VERSION_MAJOR > 53) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR > 32)) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR == 24) && (LIBAVFORMAT_VERSION_MICRO >= 100)))
+void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
+
+static inline
+void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
+{
+    ff_update_cur_dts(s, ref_st, timestamp);
+}
+#endif
+
 #ifndef FFMPEG_HAVE_AVIO
 #define AVIO_FLAG_WRITE URL_WRONLY
 #define avio_open url_fopen

Modified: trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2012-06-18 09:52:41 UTC (rev 48027)
+++ trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2012-06-18 10:29:11 UTC (rev 48028)
@@ -42,8 +42,8 @@
 #include <libavformat/avformat.h>
 #include <libavcodec/avcodec.h>
 #include <libavutil/rational.h>
+#include <libavutil/samplefmt.h>
 #include <libswscale/swscale.h>
-#include <libavcodec/opt.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -615,7 +615,7 @@
 
 	c->sample_rate = rd->ffcodecdata.audio_mixrate;
 	c->bit_rate = ffmpeg_audio_bitrate * 1000;
-	c->sample_fmt = SAMPLE_FMT_S16;
+	c->sample_fmt = AV_SAMPLE_FMT_S16;
 	c->channels = rd->ffcodecdata.audio_channels;
 	codec = avcodec_find_encoder(c->codec_id);
 	if (!codec) {
@@ -657,11 +657,21 @@
 }
 /* essential functions -- start, append, end */
 
+static void ffmpeg_dict_set_int(AVDictionary **dict, const char *key, int value)
+{
+	char buffer[32];
+
+	BLI_snprintf(buffer, sizeof(buffer), "%d", value);
+
+	av_dict_set(dict, key, buffer, 0);
+}
+
 static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, ReportList *reports)
 {
 	/* Handle to the output file */
 	AVFormatContext *of;
 	AVOutputFormat *fmt;
+	AVDictionary *opts = NULL;
 	char name[256];
 	const char **exts;
 
@@ -707,13 +717,14 @@
 	of->oformat = fmt;
 	of->packet_size = rd->ffcodecdata.mux_packet_size;
 	if (ffmpeg_audio_codec != CODEC_ID_NONE) {
-		of->mux_rate = rd->ffcodecdata.mux_rate;
+		ffmpeg_dict_set_int(&opts, "muxrate", rd->ffcodecdata.mux_rate);
 	}
 	else {
-		of->mux_rate = 0;
+		av_dict_set(&opts, "muxrate", "0", 0);
 	}
 
-	of->preload = (int)(0.5 * AV_TIME_BASE);
+	ffmpeg_dict_set_int(&opts, "preload", (int)(0.5 * AV_TIME_BASE));
+
 	of->max_delay = (int)(0.7 * AV_TIME_BASE);
 
 	fmt->audio_codec = ffmpeg_audio_codec;
@@ -776,6 +787,7 @@
 		fmt->audio_codec = CODEC_ID_PCM_S16LE;
 		if (ffmpeg_audio_codec != CODEC_ID_NONE && rd->ffcodecdata.audio_mixrate != 48000 && rd->ffcodecdata.audio_channels != 2) {
 			BKE_report(reports, RPT_ERROR, "FFMPEG only supports 48khz / stereo audio for DV!");
+			av_dict_free(&opts);
 			return 0;
 		}
 	}
@@ -785,6 +797,7 @@
 		printf("alloc video stream %p\n", video_stream);
 		if (!video_stream) {
 			BKE_report(reports, RPT_ERROR, "Error initializing video stream.");
+			av_dict_free(&opts);
 			return 0;
 		}
 	}
@@ -793,27 +806,26 @@
 		audio_stream = alloc_audio_stream(rd, fmt->audio_codec, of);
 		if (!audio_stream) {
 			BKE_report(reports, RPT_ERROR, "Error initializing audio stream.");
+			av_dict_free(&opts);
 			return 0;
 		}
 	}
-	if (av_set_parameters(of, NULL) < 0) {
-		BKE_report(reports, RPT_ERROR, "Error setting output parameters.");
-		return 0;
-	}
 	if (!(fmt->flags & AVFMT_NOFILE)) {
 		if (avio_open(&of->pb, name, AVIO_FLAG_WRITE) < 0) {
 			BKE_report(reports, RPT_ERROR, "Could not open file for writing.");
+			av_dict_free(&opts);
 			return 0;
 		}
 	}
-
-	if (av_write_header(of) < 0) {
+	if (avformat_write_header(of, NULL) < 0) {
 		BKE_report(reports, RPT_ERROR, "Could not initialize streams. Probably unsupported codec combination.");
+			av_dict_free(&opts);
 		return 0;
 	}
 
 	outfile = of;
 	av_dump_format(of, 0, name, 1);
+	av_dict_free(&opts);
 
 	return 1;
 }

Modified: trunk/blender/source/blender/imbuf/intern/anim_movie.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/anim_movie.c	2012-06-18 09:52:41 UTC (rev 48027)
+++ trunk/blender/source/blender/imbuf/intern/anim_movie.c	2012-06-18 10:29:11 UTC (rev 48028)
@@ -445,7 +445,7 @@
 	int i, videoStream;
 
 	AVCodec *pCodec;
-	AVFormatContext *pFormatCtx;
+	AVFormatContext *pFormatCtx = NULL;
 	AVCodecContext *pCodecCtx;
 	int frs_num;
 	double frs_den;
@@ -464,7 +464,7 @@
 
 	do_init_ffmpeg();
 
-	if (av_open_input_file(&pFormatCtx, anim->name, NULL, 0, NULL) != 0) {
+	if (avformat_open_input(&pFormatCtx, anim->name, NULL, NULL) != 0) {
 		return -1;
 	}
 

Modified: trunk/blender/source/blender/imbuf/intern/indexer.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/indexer.c	2012-06-18 09:52:41 UTC (rev 48027)
+++ trunk/blender/source/blender/imbuf/intern/indexer.c	2012-06-18 10:29:11 UTC (rev 48028)
@@ -531,13 +531,6 @@
 		rv->c->flags |= CODEC_FLAG_GLOBAL_HEADER;
 	}
 
-	if (av_set_parameters(rv->of, NULL) < 0) {
-		fprintf(stderr, "Couldn't set output parameters? "
-		        "Proxy not built!\n");
-		av_free(rv->of);
-		return 0;
-	}
-
 	if (avio_open(&rv->of->pb, fname, AVIO_FLAG_WRITE) < 0) {
 		fprintf(stderr, "Couldn't open outputfile! "
 		        "Proxy not built!\n");
@@ -574,7 +567,12 @@
 		        NULL, NULL, NULL);
 	}
 
-	av_write_header(rv->of);
+	if (avformat_write_header(rv->of, NULL) < 0) {
+		fprintf(stderr, "Couldn't set output parameters? "
+		        "Proxy not built!\n");
+		av_free(rv->of);
+		return 0;
+	}
 
 	return rv;
 }
@@ -737,7 +735,7 @@
 	memset(context->proxy_ctx, 0, sizeof(context->proxy_ctx));
 	memset(context->indexer, 0, sizeof(context->indexer));
 
-	if (av_open_input_file(&context->iFormatCtx, anim->name, NULL, 0, NULL) != 0) {
+	if (avformat_open_input(&context->iFormatCtx, anim->name, NULL, NULL) != 0) {
 		MEM_freeN(context);
 		return NULL;
 	}

Modified: trunk/blender/source/blender/imbuf/intern/util.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/util.c	2012-06-18 09:52:41 UTC (rev 48027)
+++ trunk/blender/source/blender/imbuf/intern/util.c	2012-06-18 10:29:11 UTC (rev 48028)
@@ -247,7 +247,7 @@
 
 static int isffmpeg(const char *filename)
 {
-	AVFormatContext *pFormatCtx;
+	AVFormatContext *pFormatCtx = NULL;
 	unsigned int i;
 	int videoStream;
 	AVCodec *pCodec;
@@ -268,7 +268,7 @@
 		return 0;
 	}
 
-	if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL) != 0) {
+	if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) != 0) {
 		if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_open_input_file failed\n");
 		return 0;
 	}

Modified: trunk/blender/source/gameengine/VideoTexture/VideoFFmpeg.cpp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list