]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_av] Add support for FFmpeg 7.0 2842/head
authorJakub Karolczyk <jakub.karolczyk@signalwire.com>
Thu, 9 May 2024 10:45:38 +0000 (11:45 +0100)
committerJakub Karolczyk <jakub.karolczyk@signalwire.com>
Fri, 11 Jul 2025 09:37:09 +0000 (10:37 +0100)
src/mod/applications/mod_av/avcodec.c
src/mod/applications/mod_av/avformat.c
src/mod/applications/mod_av/mod_av.h

index 97bf55b9559b2ea9a9a464b7407f3aa0459ad838..a9d449b562c283ca35111712e27bf43f609006bd 100644 (file)
@@ -1227,8 +1227,14 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt
 
        if (context->encoder_ctx) {
                if (avcodec_is_open(context->encoder_ctx)) {
+#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V)
                        avcodec_close(context->encoder_ctx);
+#else
+                       /* avcodec_close() will be called in avcodec_free_context() */
+                       avcodec_free_context(&context->encoder_ctx);
+#endif
                }
+
                av_free(context->encoder_ctx);
                context->encoder_ctx = NULL;
        }
@@ -1320,8 +1326,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
                if (context->encoder_ctx) {
                        if (avcodec_is_open(context->encoder_ctx)) {
+#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V)
                                avcodec_close(context->encoder_ctx);
+#else
+                               /* avcodec_close() will be called in avcodec_free_context() */
+                               avcodec_free_context(&context->encoder_ctx);
+#endif
                        }
+
                        av_free(context->encoder_ctx);
                        context->encoder_ctx = NULL;
                }
@@ -1557,7 +1569,7 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t
                }
 
                 avframe->pict_type = AV_PICTURE_TYPE_I;
-#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V)
+#if ((LIBAVCODEC_VERSION_MAJOR == LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V) || LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_7_V)
                 avframe->flags |= AV_FRAME_FLAG_KEY;
 #else
                 avframe->key_frame = 1;
@@ -1604,7 +1616,7 @@ GCC_DIAG_ON(deprecated-declarations)
                }
 #endif
 
-#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V)
+#if ((LIBAVCODEC_VERSION_MAJOR == LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V) || LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_7_V)
        if (context->need_key_frame && (avframe->flags & AV_FRAME_FLAG_KEY)) {
                avframe->flags &= ~AV_FRAME_FLAG_KEY;
 #else
@@ -1871,14 +1883,30 @@ static switch_status_t switch_h264_destroy(switch_codec_t *codec)
 
        switch_buffer_destroy(&context->nalu_buffer);
        if (context->decoder_ctx) {
-               if (avcodec_is_open(context->decoder_ctx)) avcodec_close(context->decoder_ctx);
+               if (avcodec_is_open(context->decoder_ctx)) {
+#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V)
+                               avcodec_close(context->decoder_ctx);
+#else
+                               /* avcodec_close() will be called in avcodec_free_context() */
+                               avcodec_free_context(&context->decoder_ctx);
+#endif
+               }
+
                av_free(context->decoder_ctx);
        }
 
        switch_img_free(&context->img);
 
        if (context->encoder_ctx) {
-               if (avcodec_is_open(context->encoder_ctx)) avcodec_close(context->encoder_ctx);
+               if (avcodec_is_open(context->encoder_ctx)) {
+#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V)
+                       avcodec_close(context->encoder_ctx);
+#else
+                       /* avcodec_close() will be called in avcodec_free_context() */
+                       avcodec_free_context(&context->encoder_ctx);
+#endif
+               }
+
                av_free(context->encoder_ctx);
        }
 
index ac90e87fc5f8199bd8bfc345c81cff3c852d29f3..708291ad5218356195a248775e69a6556dd21198 100644 (file)
@@ -623,11 +623,11 @@ static switch_status_t add_stream(av_file_context_t *context, MediaStream *mst,
                c->rc_initial_buffer_occupancy = buffer_bytes * 8;
 
                if (codec_id == AV_CODEC_ID_H264) {
-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
+#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
 GCC_DIAG_OFF(deprecated-declarations)
 #endif
                        c->ticks_per_frame = 2;
-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
+#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
 GCC_DIAG_ON(deprecated-declarations)
 #endif
 
@@ -1417,7 +1417,11 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
                switch_goto_status(SWITCH_STATUS_FALSE, err);
        }
 
+#if (LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
+       handle->seekable = !(context->fc->iformat->flags & AVFMT_NOTIMESTAMPS);
+#else
        handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0);
+#endif
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "file %s is %sseekable\n", filename, handle->seekable ? "" : "not ");
 
        /** Get information on the input file (number of streams etc.). */
@@ -1509,7 +1513,12 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
 
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open input audio codec channel 2 (error '%s')\n", get_error_text(error, ebuf, sizeof(ebuf)));
                if ((cc = av_get_codec_context(&context->audio_st[0]))) {
+#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V)
                        avcodec_close(cc);
+#else
+                       /* avcodec_close() will be called in avcodec_free_context() */
+                       avcodec_free_context(&cc);
+#endif
                }
 
                context->has_audio = 0;
@@ -3217,7 +3226,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
 
        if ((c = av_get_codec_context(mst)) && c->time_base.num) {
                cp = av_stream_get_parser(st);
-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
+#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
 GCC_DIAG_OFF(deprecated-declarations)
 #endif
                ticks = cp ? cp->repeat_pict + 1 : c->ticks_per_frame;
@@ -3229,7 +3238,7 @@ GCC_DIAG_OFF(deprecated-declarations)
                        context->video_start_time, ticks, c ? c->ticks_per_frame : -1, st->time_base.num, st->time_base.den, c ? c->time_base.num : -1, c ? c->time_base.den : -1,
                        st->start_time, st->duration == AV_NOPTS_VALUE ? context->fc->duration / AV_TIME_BASE * 1000 : st->duration, st->nb_frames, av_q2d(st->time_base));
        }
-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
+#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
 GCC_DIAG_ON(deprecated-declarations)
 #endif
 
index f73e3eee09a9cc6756d2d21a57218ce858843e5d..8152a77a815e5fca4f7ef05940517e739b85e8d8 100644 (file)
 
 #define LIBAVCODEC_V 59 /* FFmpeg version >= 5.1 */
 #define LIBAVCODEC_6_V 60 /* FFmpeg version >= 6.0 */
+#define LIBAVCODEC_7_V 61 /* FFmpeg version >= 7.0 */
 #define LIBAVCODEC_61_V 31 /* FFmpeg version >= 6.1 */
 #define LIBAVFORMAT_V 59 /* FFmpeg version >= 5.1 */
 #define LIBAVFORMAT_6_V 60 /* FFmpeg version >= 6.0 */
+#define LIBAVFORMAT_7_V 61 /* FFmpeg version >= 7.0 */
 #define LIBAVFORMAT_61_V 16 /* FFmpeg version >= 6.1 */
 #define LIBAVUTIL_V 57 /* FFmpeg version >= 5.1 */