|
| 1 | +From 1fd9ac9dd1bdae6e1bd794119f8e5328fe4c7f6c Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jakub Karolczyk <jakub.karolczyk@signalwire.com> |
| 3 | +Date: Thu, 9 May 2024 11:45:38 +0100 |
| 4 | +Subject: [PATCH 3/4] [mod_av] Add support for FFmpeg 7.0 |
| 5 | + |
| 6 | +--- |
| 7 | + src/mod/applications/mod_av/avcodec.c | 36 +++++++++++++++++++++++--- |
| 8 | + src/mod/applications/mod_av/avformat.c | 17 +++++++++--- |
| 9 | + src/mod/applications/mod_av/mod_av.h | 2 ++ |
| 10 | + 3 files changed, 47 insertions(+), 8 deletions(-) |
| 11 | + |
| 12 | +--- a/src/mod/applications/mod_av/avcodec.c |
| 13 | ++++ b/src/mod/applications/mod_av/avcodec.c |
| 14 | +@@ -1227,8 +1227,14 @@ static switch_status_t open_encoder(h264 |
| 15 | + |
| 16 | + if (context->encoder_ctx) { |
| 17 | + if (avcodec_is_open(context->encoder_ctx)) { |
| 18 | ++#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V) |
| 19 | + avcodec_close(context->encoder_ctx); |
| 20 | ++#else |
| 21 | ++ /* avcodec_close() will be called in avcodec_free_context() */ |
| 22 | ++ avcodec_free_context(&context->encoder_ctx); |
| 23 | ++#endif |
| 24 | + } |
| 25 | ++ |
| 26 | + av_free(context->encoder_ctx); |
| 27 | + context->encoder_ctx = NULL; |
| 28 | + } |
| 29 | +@@ -1320,8 +1326,14 @@ FF_ENABLE_DEPRECATION_WARNINGS |
| 30 | + |
| 31 | + if (context->encoder_ctx) { |
| 32 | + if (avcodec_is_open(context->encoder_ctx)) { |
| 33 | ++#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V) |
| 34 | + avcodec_close(context->encoder_ctx); |
| 35 | ++#else |
| 36 | ++ /* avcodec_close() will be called in avcodec_free_context() */ |
| 37 | ++ avcodec_free_context(&context->encoder_ctx); |
| 38 | ++#endif |
| 39 | + } |
| 40 | ++ |
| 41 | + av_free(context->encoder_ctx); |
| 42 | + context->encoder_ctx = NULL; |
| 43 | + } |
| 44 | +@@ -1557,7 +1569,7 @@ static switch_status_t switch_h264_encod |
| 45 | + } |
| 46 | + |
| 47 | + avframe->pict_type = AV_PICTURE_TYPE_I; |
| 48 | +-#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V) |
| 49 | ++#if ((LIBAVCODEC_VERSION_MAJOR == LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V) || LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_7_V) |
| 50 | + avframe->flags |= AV_FRAME_FLAG_KEY; |
| 51 | + #else |
| 52 | + avframe->key_frame = 1; |
| 53 | +@@ -1604,7 +1616,7 @@ GCC_DIAG_ON(deprecated-declarations) |
| 54 | + } |
| 55 | + #endif |
| 56 | + |
| 57 | +-#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V) |
| 58 | ++#if ((LIBAVCODEC_VERSION_MAJOR == LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V) || LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_7_V) |
| 59 | + if (context->need_key_frame && (avframe->flags & AV_FRAME_FLAG_KEY)) { |
| 60 | + avframe->flags &= ~AV_FRAME_FLAG_KEY; |
| 61 | + #else |
| 62 | +@@ -1871,14 +1883,30 @@ static switch_status_t switch_h264_destr |
| 63 | + |
| 64 | + switch_buffer_destroy(&context->nalu_buffer); |
| 65 | + if (context->decoder_ctx) { |
| 66 | +- if (avcodec_is_open(context->decoder_ctx)) avcodec_close(context->decoder_ctx); |
| 67 | ++ if (avcodec_is_open(context->decoder_ctx)) { |
| 68 | ++#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V) |
| 69 | ++ avcodec_close(context->decoder_ctx); |
| 70 | ++#else |
| 71 | ++ /* avcodec_close() will be called in avcodec_free_context() */ |
| 72 | ++ avcodec_free_context(&context->decoder_ctx); |
| 73 | ++#endif |
| 74 | ++ } |
| 75 | ++ |
| 76 | + av_free(context->decoder_ctx); |
| 77 | + } |
| 78 | + |
| 79 | + switch_img_free(&context->img); |
| 80 | + |
| 81 | + if (context->encoder_ctx) { |
| 82 | +- if (avcodec_is_open(context->encoder_ctx)) avcodec_close(context->encoder_ctx); |
| 83 | ++ if (avcodec_is_open(context->encoder_ctx)) { |
| 84 | ++#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V) |
| 85 | ++ avcodec_close(context->encoder_ctx); |
| 86 | ++#else |
| 87 | ++ /* avcodec_close() will be called in avcodec_free_context() */ |
| 88 | ++ avcodec_free_context(&context->encoder_ctx); |
| 89 | ++#endif |
| 90 | ++ } |
| 91 | ++ |
| 92 | + av_free(context->encoder_ctx); |
| 93 | + } |
| 94 | + |
| 95 | +--- a/src/mod/applications/mod_av/avformat.c |
| 96 | ++++ b/src/mod/applications/mod_av/avformat.c |
| 97 | +@@ -623,11 +623,11 @@ static switch_status_t add_stream(av_fil |
| 98 | + c->rc_initial_buffer_occupancy = buffer_bytes * 8; |
| 99 | + |
| 100 | + if (codec_id == AV_CODEC_ID_H264) { |
| 101 | +-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) |
| 102 | ++#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) |
| 103 | + GCC_DIAG_OFF(deprecated-declarations) |
| 104 | + #endif |
| 105 | + c->ticks_per_frame = 2; |
| 106 | +-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) |
| 107 | ++#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) |
| 108 | + GCC_DIAG_ON(deprecated-declarations) |
| 109 | + #endif |
| 110 | + |
| 111 | +@@ -1417,7 +1417,11 @@ static switch_status_t open_input_file(a |
| 112 | + switch_goto_status(SWITCH_STATUS_FALSE, err); |
| 113 | + } |
| 114 | + |
| 115 | ++#if (LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) |
| 116 | ++ handle->seekable = !(context->fc->iformat->flags & AVFMT_NOTIMESTAMPS); |
| 117 | ++#else |
| 118 | + handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0); |
| 119 | ++#endif |
| 120 | + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "file %s is %sseekable\n", filename, handle->seekable ? "" : "not "); |
| 121 | + |
| 122 | + /** Get information on the input file (number of streams etc.). */ |
| 123 | +@@ -1509,7 +1513,12 @@ static switch_status_t open_input_file(a |
| 124 | + |
| 125 | + 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))); |
| 126 | + if ((cc = av_get_codec_context(&context->audio_st[0]))) { |
| 127 | ++#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_7_V) |
| 128 | + avcodec_close(cc); |
| 129 | ++#else |
| 130 | ++ /* avcodec_close() will be called in avcodec_free_context() */ |
| 131 | ++ avcodec_free_context(&cc); |
| 132 | ++#endif |
| 133 | + } |
| 134 | + |
| 135 | + context->has_audio = 0; |
| 136 | +@@ -3217,7 +3226,7 @@ static switch_status_t av_file_read_vide |
| 137 | + |
| 138 | + if ((c = av_get_codec_context(mst)) && c->time_base.num) { |
| 139 | + cp = av_stream_get_parser(st); |
| 140 | +-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) |
| 141 | ++#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) |
| 142 | + GCC_DIAG_OFF(deprecated-declarations) |
| 143 | + #endif |
| 144 | + ticks = cp ? cp->repeat_pict + 1 : c->ticks_per_frame; |
| 145 | +@@ -3229,7 +3238,7 @@ GCC_DIAG_OFF(deprecated-declarations) |
| 146 | + 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, |
| 147 | + 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)); |
| 148 | + } |
| 149 | +-#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) |
| 150 | ++#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) |
| 151 | + GCC_DIAG_ON(deprecated-declarations) |
| 152 | + #endif |
| 153 | + |
| 154 | +--- a/src/mod/applications/mod_av/mod_av.h |
| 155 | ++++ b/src/mod/applications/mod_av/mod_av.h |
| 156 | +@@ -42,9 +42,11 @@ |
| 157 | + |
| 158 | + #define LIBAVCODEC_V 59 /* FFmpeg version >= 5.1 */ |
| 159 | + #define LIBAVCODEC_6_V 60 /* FFmpeg version >= 6.0 */ |
| 160 | ++#define LIBAVCODEC_7_V 61 /* FFmpeg version >= 7.0 */ |
| 161 | + #define LIBAVCODEC_61_V 31 /* FFmpeg version >= 6.1 */ |
| 162 | + #define LIBAVFORMAT_V 59 /* FFmpeg version >= 5.1 */ |
| 163 | + #define LIBAVFORMAT_6_V 60 /* FFmpeg version >= 6.0 */ |
| 164 | ++#define LIBAVFORMAT_7_V 61 /* FFmpeg version >= 7.0 */ |
| 165 | + #define LIBAVFORMAT_61_V 16 /* FFmpeg version >= 6.1 */ |
| 166 | + #define LIBAVUTIL_V 57 /* FFmpeg version >= 5.1 */ |
| 167 | + |
0 commit comments