Browse Source

libobs: Remove legacy FFmpeg compatibility

derrod 2 years ago
parent
commit
c939525f77
3 changed files with 4 additions and 66 deletions
  1. 3 24
      libobs/graphics/graphics-ffmpeg.c
  2. 0 26
      libobs/media-io/media-remux.c
  3. 1 16
      libobs/obs-ffmpeg-compat.h

+ 3 - 24
libobs/graphics/graphics-ffmpeg.c

@@ -37,35 +37,23 @@ static bool ffmpeg_image_open_decoder_context(struct ffmpeg_image *info)
 	}
 
 	AVStream *const stream = fmt_ctx->streams[ret];
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
 	AVCodecParameters *const codecpar = stream->codecpar;
 	const AVCodec *const decoder = avcodec_find_decoder(
 		codecpar->codec_id); // fix discarded-qualifiers
-#else
-	AVCodecContext *const decoder_ctx = stream->codec;
-	AVCodec *const decoder = avcodec_find_decoder(decoder_ctx->codec_id);
-#endif
+
 	if (!decoder) {
 		blog(LOG_WARNING, "Failed to find decoder for file '%s'",
 		     info->file);
 		return false;
 	}
 
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
 	AVCodecContext *const decoder_ctx = avcodec_alloc_context3(decoder);
 	avcodec_parameters_to_context(decoder_ctx, codecpar);
-#endif
 
 	info->decoder_ctx = decoder_ctx;
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
 	info->cx = codecpar->width;
 	info->cy = codecpar->height;
 	info->format = codecpar->format;
-#else
-	info->cx = decoder_ctx->width;
-	info->cy = decoder_ctx->height;
-	info->format = decoder_ctx->pix_fmt;
-#endif
 
 	ret = avcodec_open2(decoder_ctx, decoder, NULL);
 	if (ret < 0) {
@@ -578,7 +566,6 @@ static void *ffmpeg_image_decode(struct ffmpeg_image *info,
 	}
 
 	while (!got_frame) {
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 40, 101)
 		ret = avcodec_send_packet(info->decoder_ctx, &packet);
 		if (ret == 0)
 			ret = avcodec_receive_frame(info->decoder_ctx, frame);
@@ -587,10 +574,7 @@ static void *ffmpeg_image_decode(struct ffmpeg_image *info,
 
 		if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
 			ret = 0;
-#else
-		ret = avcodec_decode_video2(info->decoder_ctx, frame,
-					    &got_frame, &packet);
-#endif
+
 		if (ret < 0) {
 			blog(LOG_WARNING, "Failed to decode frame for '%s': %s",
 			     info->file, av_err2str(ret));
@@ -606,12 +590,7 @@ fail:
 	return data;
 }
 
-void gs_init_image_deps(void)
-{
-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
-	av_register_all();
-#endif
-}
+void gs_init_image_deps(void) {}
 
 void gs_free_image_deps(void) {}
 

+ 0 - 26
libobs/media-io/media-remux.c

@@ -28,12 +28,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#if LIBAVCODEC_VERSION_MAJOR >= 58
-#define CODEC_FLAG_GLOBAL_H AV_CODEC_FLAG_GLOBAL_HEADER
-#else
-#define CODEC_FLAG_GLOBAL_H CODEC_FLAG_GLOBAL_HEADER
-#endif
-
 #ifndef FF_API_BUFFER_SIZE_T
 #define FF_API_BUFFER_SIZE_T (LIBAVUTIL_VERSION_MAJOR < 57)
 #endif
@@ -90,12 +84,7 @@ static inline bool init_output(media_remux_job_t job, const char *out_filename)
 
 	for (unsigned i = 0; i < job->ifmt_ctx->nb_streams; i++) {
 		AVStream *in_stream = job->ifmt_ctx->streams[i];
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
 		AVStream *out_stream = avformat_new_stream(job->ofmt_ctx, NULL);
-#else
-		AVStream *out_stream = avformat_new_stream(
-			job->ofmt_ctx, in_stream->codec->codec);
-#endif
 		if (!out_stream) {
 			blog(LOG_ERROR, "media_remux: Failed to allocate output"
 					" stream");
@@ -137,12 +126,8 @@ static inline bool init_output(media_remux_job_t job, const char *out_filename)
 			}
 		}
 
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
 		ret = avcodec_parameters_copy(out_stream->codecpar,
 					      in_stream->codecpar);
-#else
-		ret = avcodec_copy_context(out_stream->codec, in_stream->codec);
-#endif
 
 		if (ret < 0) {
 			blog(LOG_ERROR,
@@ -152,7 +137,6 @@ static inline bool init_output(media_remux_job_t job, const char *out_filename)
 
 		av_dict_copy(&out_stream->metadata, in_stream->metadata, 0);
 
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
 		if (in_stream->codecpar->codec_id == AV_CODEC_ID_HEVC &&
 		    job->ofmt_ctx->oformat->codec_tag &&
 		    av_codec_get_id(job->ofmt_ctx->oformat->codec_tag,
@@ -166,12 +150,6 @@ static inline bool init_output(media_remux_job_t job, const char *out_filename)
 			// Otherwise tag 0 to let FFmpeg automatically select the appropriate tag
 			out_stream->codecpar->codec_tag = 0;
 		}
-#else
-		out_stream->codec->codec_tag = 0;
-		out_stream->time_base = out_stream->codec->time_base;
-		if (job->ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
-			out_stream->codec->flags |= CODEC_FLAG_GLOBAL_H;
-#endif
 	}
 
 #ifndef NDEBUG
@@ -212,10 +190,6 @@ bool media_remux_job_create(media_remux_job_t *job, const char *in_filename,
 
 	init_size(*job, in_filename);
 
-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
-	av_register_all();
-#endif
-
 	if (!init_input(*job, in_filename))
 		goto fail;
 

+ 1 - 16
libobs/obs-ffmpeg-compat.h

@@ -12,24 +12,9 @@
 	 (LIBAVCODEC_VERSION_MICRO >= 100 &&                    \
 	  LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(a, d, e)))
 
-#if !LIBAVCODEC_VERSION_CHECK(54, 28, 0, 59, 100)
-#define avcodec_free_frame av_freep
-#endif
-
-#if LIBAVCODEC_VERSION_INT < 0x371c01
-#define av_frame_alloc avcodec_alloc_frame
-#define av_frame_unref avcodec_get_frame_defaults
-#define av_frame_free avcodec_free_frame
-#endif
-
-#if LIBAVCODEC_VERSION_MAJOR >= 58
 #if LIBAVCODEC_VERSION_MAJOR < 60
 #define CODEC_CAP_TRUNC AV_CODEC_CAP_TRUNCATED
 #define CODEC_FLAG_TRUNC AV_CODEC_FLAG_TRUNCATED
 #endif
+
 #define INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE
-#else
-#define CODEC_CAP_TRUNC CODEC_CAP_TRUNCATED
-#define CODEC_FLAG_TRUNC CODEC_FLAG_TRUNCATED
-#define INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
-#endif