avcommon: use a specific macro to check the FFmpeg libavcodec version
authorSteve Lhomme <robux4@ycbcr.xyz>
Wed, 19 Jun 2024 11:59:15 +0000 (13:59 +0200)
committerSebastian Ramacher <sramacher@debian.org>
Tue, 21 Jan 2025 18:02:47 +0000 (19:02 +0100)
This macro doesn't check for libav which is assumed to not have to relevant
code. This is the same macro name used in VLC 4.0.

Gbp-Pq: Name 0087-avcommon-use-a-specific-macro-to-check-the-FFmpeg-li.patch

modules/codec/avcodec/audio.c
modules/codec/avcodec/avcommon.h
modules/codec/avcodec/avcommon_compat.h
modules/codec/avcodec/directx_va.c
modules/codec/avcodec/encoder.c
modules/codec/avcodec/fourcc.c
modules/codec/avcodec/video.c
modules/demux/avformat/demux.c
modules/demux/avformat/mux.c

index 7a979e96e191442fbe8789438ee6e6df94498547..a3f67f7bd93471f0311b4813242e3211c61da322 100644 (file)
@@ -142,7 +142,7 @@ static int OpenAudioCodec( decoder_t *p_dec )
     }
 
     ctx->sample_rate = p_dec->fmt_in.audio.i_rate;
-#if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
     av_channel_layout_default( &ctx->ch_layout, p_dec->fmt_in.audio.i_channels );
 #else
     ctx->channels = p_dec->fmt_in.audio.i_channels;
@@ -402,7 +402,7 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         ret = avcodec_receive_frame( ctx, frame );
         if( ret == 0 )
         {
-#if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
             int channels = frame->ch_layout.nb_channels;
 #else
             int channels = ctx->channels;
@@ -592,7 +592,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
     p_dec->fmt_out.audio.i_rate = p_sys->p_context->sample_rate;
 
     /* */
-#if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
     if( p_sys->i_previous_channels == p_sys->p_context->ch_layout.nb_channels &&
         p_sys->i_previous_layout == p_sys->p_context->ch_layout.u.mask )
         return;
@@ -617,7 +617,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
 
     int i_channels_src = 0, channel_count;
     uint64_t channel_layout_mask;
-#if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
     channel_layout_mask = p_sys->p_context->ch_layout.u.mask;
     channel_count = p_sys->p_context->ch_layout.nb_channels;
 #elif API_CHANNEL_LAYOUT
index aa0c0b88b859acb3a446915621c3035fd0edddbd..10ad13dc5f8a2ced7910627a70e1a17ab68b09f8 100644 (file)
@@ -123,7 +123,7 @@ static inline void vlc_init_avcodec(vlc_object_t *obj)
 
     vlc_init_avutil(obj);
 
-#if (LIBAVFORMAT_VERSION_MICRO < 100) || (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100))
+#if (LIBAVFORMAT_VERSION_MICRO < 100) || !(LIBAVCODEC_VERSION_CHECK(58, 10, 100))
     avcodec_register_all();
 #endif
 
index b504fcd82186b4d3477721bc6b230512dfb1e431..ac02c06d2339e92a55c179a47f05ac9fc08e4db6 100644 (file)
 #ifdef HAVE_LIBAVCODEC_AVCODEC_H
 #include <libavcodec/avcodec.h>
 
+/* check the FFmpeg libavutil version */
+#define LIBAVCODEC_VERSION_CHECK( a, d, e ) \
+    (LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, d, e ) )
+
 /* LIBAV_CODEC_VERSION_CHECK checks for the right version of libav and FFmpeg
  * a is the major version
  * b and c the minor and micro versions of libav
index 607a1bcb990dae20c449f0ba4b061d2a0c9e2102..890473e938f3f3fa47c17be439329b493860c0a2 100644 (file)
@@ -274,7 +274,7 @@ static const directx_va_mode_t DXVA_MODES[] = {
 
     /* VPx */
     { "VP8",                                                                          &DXVA_ModeVP8_VLD,                      8, 0, NULL },
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 57, 17, 100 ) && LIBAVCODEC_VERSION_MICRO >= 100
+#if LIBAVCODEC_VERSION_CHECK( 57, 17, 100 )
     { "VP9 profile 0",                                                                &DXVA_ModeVP9_VLD_Profile0,             8, AV_CODEC_ID_VP9, PROF_VP9_MAIN },
     { "VP9 profile 2",                                                                &DXVA_ModeVP9_VLD_10bit_Profile2,       10, AV_CODEC_ID_VP9, PROF_VP9_10 },
 #else
@@ -284,7 +284,7 @@ static const directx_va_mode_t DXVA_MODES[] = {
     { "VP9 profile Intel",                                                            &DXVA_ModeVP9_VLD_Intel,                8, 0, NULL },
 
     /* AV1 */
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 58, 112, 103 ) && LIBAVCODEC_VERSION_MICRO >= 100
+#if LIBAVCODEC_VERSION_CHECK( 58, 112, 103 )
     { "AV1 Main profile 8",                                                           &DXVA_ModeAV1_VLD_Profile0,             8, AV_CODEC_ID_AV1, PROF_AV1_MAIN },
     { "AV1 Main profile 10",                                                          &DXVA_ModeAV1_VLD_Profile0,             10, AV_CODEC_ID_AV1, PROF_AV1_MAIN },
     { "AV1 High profile 8",                                                           &DXVA_ModeAV1_VLD_Profile1,             8, AV_CODEC_ID_AV1, PROF_AV1_HIGH },
index 9cf9a7d0607d6c444b2703debbaff28184b3712d..2014b8afaf52d4676086acce18bec86f232eb054 100644 (file)
@@ -61,8 +61,7 @@
 
 #define RAW_AUDIO_FRAME_SIZE (2048)
 
-#if LIBAVCODEC_VERSION_MICRO >= 100 && \
-    LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 0, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 0, 100)
 # define AVC_MAYBE_CONST const
 #else
 # define AVC_MAYBE_CONST
@@ -183,7 +182,7 @@ static const uint64_t pi_channels_map[][2] =
     { AV_CH_STEREO_RIGHT,      0 },
 };
 
-# if !LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+# if !LIBAVCODEC_VERSION_CHECK(59, 24, 100)
 static const uint32_t channel_mask[][2] = {
     {0,0},
     {AOUT_CHAN_CENTER, AV_CH_LAYOUT_MONO},
@@ -765,7 +764,7 @@ int InitVideoEnc( vlc_object_t *p_this )
         uint32_t order_mask = 0;
         int i_channels_src = 0;
         msg_Dbg( p_enc, "Creating channel order for reordering");
-# if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+# if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
         av_channel_layout_default( &p_context->ch_layout, p_enc->fmt_out.audio.i_channels );
         uint64_t channel_mask = p_context->ch_layout.u.mask;
 # else
@@ -918,7 +917,7 @@ errmsg:
 
         if( p_enc->fmt_out.audio.i_channels > 2 )
         {
-#if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
             av_channel_layout_default( &p_context->ch_layout, 2 );
 #else
             p_context->channels = 2;
@@ -1282,7 +1281,7 @@ static block_t *handle_delay_buffer( encoder_t *p_enc, encoder_sys_t *p_sys, uns
     av_frame_unref( p_sys->frame );
     p_sys->frame->format     = p_sys->p_context->sample_fmt;
     p_sys->frame->nb_samples = leftover_samples + p_sys->i_samples_delay;
-#if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
     av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
 #else
     p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
@@ -1417,7 +1416,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
         p_sys->frame->pts        = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den /
                                     CLOCK_FREQ / p_sys->p_context->time_base.num;
 
-#if LIBAV_CODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
         av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
 #else
         p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
index 3aea6b58ff0412cd3e25ae6362d8316eaaaea4b3..d75c21ffa495ae88d3e0b1414e4574f0cfae8054 100644 (file)
@@ -182,12 +182,10 @@ static const struct vlc_avcodec_fourcc video_codecs[] =
     /* AV_CODEC_ID_V210X */
     { VLC_CODEC_TMV, AV_CODEC_ID_TMV },
     { VLC_CODEC_V210, AV_CODEC_ID_V210 },
-#if LIBAVCODEC_VERSION_MICRO >= 100
-# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 42, 102 )
+#if LIBAVCODEC_VERSION_CHECK( 59, 42, 102 )
     { VLC_CODEC_VUYA, AV_CODEC_ID_RAWVIDEO },
-# elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 54, 50, 100 )
+#elif LIBAVCODEC_VERSION_CHECK( 54, 50, 100 )
     { VLC_CODEC_VUYA, AV_CODEC_ID_AYUV },
-# endif
 #endif
     /* AV_CODEC_ID_DPX */
     { VLC_CODEC_MAD, AV_CODEC_ID_MAD },
@@ -285,19 +283,19 @@ static const struct vlc_avcodec_fourcc video_codecs[] =
     /* ffmpeg only: AV_CODEC_ID_SNOW */
     /* ffmpeg only: AV_CODEC_ID_SMVJPEG */
 
-#if LIBAV_CODEC_VERSION_CHECK( 57, 999, 999, 24, 102 )
+#if LIBAVCODEC_VERSION_CHECK( 57, 24, 102 )
     { VLC_CODEC_CINEFORM, AV_CODEC_ID_CFHD },
 #endif
 
-#if LIBAV_CODEC_VERSION_CHECK( 57, 999, 999, 70, 100 )
+#if LIBAVCODEC_VERSION_CHECK( 57, 70, 100 )
     { VLC_CODEC_PIXLET, AV_CODEC_ID_PIXLET },
 #endif
 
-#if LIBAV_CODEC_VERSION_CHECK( 57, 999, 999, 71, 101 )
+#if LIBAVCODEC_VERSION_CHECK( 57, 71, 101 )
     { VLC_CODEC_SPEEDHQ, AV_CODEC_ID_SPEEDHQ },
 #endif
 
-#if LIBAV_CODEC_VERSION_CHECK( 57, 999, 999, 79, 100 )
+#if LIBAVCODEC_VERSION_CHECK( 57, 79, 100 )
     { VLC_CODEC_FMVC, AV_CODEC_ID_FMVC },
 #endif
 };
@@ -414,7 +412,7 @@ static const struct vlc_avcodec_fourcc audio_codecs[] =
     /* AV_CODEC_ID_WESTWOOD_SND1 */
     { VLC_CODEC_GSM, AV_CODEC_ID_GSM },
     { VLC_CODEC_QDM2, AV_CODEC_ID_QDM2 },
-#if LIBAV_CODEC_VERSION_CHECK( 57, 999, 999, 71, 100 )
+#if LIBAVCODEC_VERSION_CHECK( 57, 71, 100 )
     { VLC_CODEC_QDMC, AV_CODEC_ID_QDMC },
 #endif
     { VLC_CODEC_COOK, AV_CODEC_ID_COOK },
@@ -482,7 +480,7 @@ static const struct vlc_avcodec_fourcc spu_codecs[] =
     { VLC_CODEC_SSA, AV_CODEC_ID_SSA },
     /* AV_CODEC_ID_MOV_TEXT */
     { VLC_CODEC_BD_PG, AV_CODEC_ID_HDMV_PGS_SUBTITLE },
-#if LIBAV_CODEC_VERSION_CHECK( 57, 999, 999, 71, 100 )
+#if LIBAVCODEC_VERSION_CHECK( 57, 71, 100 )
     { VLC_CODEC_BD_TEXT, AV_CODEC_ID_HDMV_TEXT_SUBTITLE },
 #endif
     { VLC_CODEC_TELETEXT, AV_CODEC_ID_DVB_TELETEXT },
index 552c602edf6a20b625074673738d739d4d0e4220..c306e916c7d68451cfcd3c6084c2b327e03b0fdf 100644 (file)
@@ -1824,8 +1824,7 @@ no_reuse:
     if (!can_hwaccel)
         return swfmt;
 
-#if (LIBAVCODEC_VERSION_MICRO >= 100) \
-  && (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 83, 101))
+#if (LIBAVCODEC_VERSION_MICRO >= 100) && !(LIBAVCODEC_VERSION_CHECK(57, 83, 101))
     if (p_context->active_thread_type)
     {
         msg_Warn(p_dec, "thread type %d: disabling hardware acceleration",
index 39d2366cef2b1575d926c0add135870e32346751..9975b0f47b673c17694c9209664bd98d388572ab 100644 (file)
@@ -400,7 +400,7 @@ int avformat_OpenDemux( vlc_object_t *p_this )
             es_format_Init( &es_fmt, AUDIO_ES, fcc );
             es_fmt.i_original_fourcc = CodecTagToFourcc( cp->codec_tag );
             es_fmt.i_bitrate = cp->bit_rate;
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 ) && LIBAVCODEC_VERSION_MICRO >= 100
+#if LIBAVCODEC_VERSION_CHECK( 59, 24, 100 )
             es_fmt.audio.i_channels = cp->ch_layout.nb_channels;
 #else
             es_fmt.audio.i_channels = cp->channels;
index 664a646734c0d17eda901170878231cfc72e8553..a48190c93ca0eb543d23c8844b63301d4d989742 100644 (file)
@@ -273,7 +273,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     {
     case AUDIO_ES:
         codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 ) && LIBAVCODEC_VERSION_MICRO >= 100
+#if LIBAVCODEC_VERSION_CHECK( 59, 24, 100 )
         av_channel_layout_default( &codecpar->ch_layout, fmt->audio.i_channels );
 #else
         codecpar->channels = fmt->audio.i_channels;