Skip to content

Commit 40dcae6

Browse files
committed
freeswitch: backport mod_av patch for FFmpeg 6.0+ support
Backport mod_av patch for FFmpeg 6.0+ support to fix compilation error on x86 target. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
1 parent b4f1c7a commit 40dcae6

5 files changed

Lines changed: 354 additions & 1 deletion

net/freeswitch/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
77

88
PKG_NAME:=freeswitch
99
PKG_VERSION:=1.10.12
10-
PKG_RELEASE:=2
10+
PKG_RELEASE:=3
1111
PKG_MAINTAINER:=
1212

1313
PKG_SOURCE:=freeswitch-$(PKG_VERSION).-release.tar.xz
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
From 9dccd0b6e6761434d54d75d6385cdc7a7b3fa39c Mon Sep 17 00:00:00 2001
2+
From: Jakub Karolczyk <jakub.karolczyk@signalwire.com>
3+
Date: Wed, 8 May 2024 10:53:58 +0100
4+
Subject: [PATCH 1/4] [mod_av] Add support for FFmpeg 6.0
5+
6+
---
7+
src/mod/applications/mod_av/avformat.c | 11 +++++++++++
8+
src/mod/applications/mod_av/mod_av.h | 1 +
9+
2 files changed, 12 insertions(+)
10+
11+
--- a/src/mod/applications/mod_av/avformat.c
12+
+++ b/src/mod/applications/mod_av/avformat.c
13+
@@ -416,6 +416,7 @@ static int interrupt_cb(void *cp)
14+
}
15+
16+
17+
+#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_6_V)
18+
static int mod_avformat_alloc_output_context2(AVFormatContext **avctx, const char *format, const char *filename, av_file_context_t *context)
19+
{
20+
AVFormatContext *s = avformat_alloc_context();
21+
@@ -489,6 +490,7 @@ error:
22+
23+
return ret;
24+
}
25+
+#endif
26+
27+
static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)
28+
{
29+
@@ -2235,7 +2237,16 @@ static switch_status_t av_file_open(swit
30+
return SWITCH_STATUS_SUCCESS;
31+
}
32+
33+
+#if (LIBAVFORMAT_VERSION_MAJOR < LIBAVFORMAT_6_V)
34+
mod_avformat_alloc_output_context2(&context->fc, format, (char *)file, context);
35+
+#else
36+
+ avformat_alloc_output_context2(&context->fc, NULL, format, (char *)file);
37+
+
38+
+ if (context->fc) {
39+
+ context->fc->interrupt_callback.callback = interrupt_cb;
40+
+ context->fc->interrupt_callback.opaque = context;
41+
+ }
42+
+#endif
43+
44+
if (!context->fc) {
45+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not deduce output format from file extension\n");
46+
--- a/src/mod/applications/mod_av/mod_av.h
47+
+++ b/src/mod/applications/mod_av/mod_av.h
48+
@@ -42,6 +42,7 @@
49+
50+
#define LIBAVCODEC_V 59
51+
#define LIBAVFORMAT_V 59
52+
+#define LIBAVFORMAT_6_V 60
53+
#define LIBAVUTIL_V 57
54+
55+
struct mod_av_globals {
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
From 58776f3eed03951e3a712c5124a12616f5aa735f Mon Sep 17 00:00:00 2001
2+
From: Jakub Karolczyk <jakub.karolczyk@signalwire.com>
3+
Date: Wed, 8 May 2024 12:27:08 +0100
4+
Subject: [PATCH 2/4] [mod_av] Add support for FFmpeg 6.1
5+
6+
---
7+
src/mod/applications/mod_av/avcodec.c | 11 ++++++++++-
8+
src/mod/applications/mod_av/avformat.c | 13 ++++++++++++-
9+
src/mod/applications/mod_av/mod_av.h | 11 +++++++----
10+
3 files changed, 29 insertions(+), 6 deletions(-)
11+
12+
--- a/src/mod/applications/mod_av/avcodec.c
13+
+++ b/src/mod/applications/mod_av/avcodec.c
14+
@@ -1557,7 +1557,11 @@ static switch_status_t switch_h264_encod
15+
}
16+
17+
avframe->pict_type = AV_PICTURE_TYPE_I;
18+
+#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V)
19+
+ avframe->flags |= AV_FRAME_FLAG_KEY;
20+
+#else
21+
avframe->key_frame = 1;
22+
+#endif
23+
context->last_keyframe_request = switch_time_now();
24+
}
25+
26+
@@ -1600,9 +1604,14 @@ GCC_DIAG_ON(deprecated-declarations)
27+
}
28+
#endif
29+
30+
+#if (LIBAVCODEC_VERSION_MAJOR >= LIBAVCODEC_6_V && LIBAVCODEC_VERSION_MINOR >= LIBAVCODEC_61_V)
31+
+ if (context->need_key_frame && (avframe->flags & AV_FRAME_FLAG_KEY)) {
32+
+ avframe->flags &= ~AV_FRAME_FLAG_KEY;
33+
+#else
34+
if (context->need_key_frame && avframe->key_frame == 1) {
35+
- avframe->pict_type = 0;
36+
avframe->key_frame = 0;
37+
+#endif
38+
+ avframe->pict_type = 0;
39+
context->need_key_frame = 0;
40+
}
41+
42+
--- a/src/mod/applications/mod_av/avformat.c
43+
+++ b/src/mod/applications/mod_av/avformat.c
44+
@@ -623,8 +623,13 @@ static switch_status_t add_stream(av_fil
45+
c->rc_initial_buffer_occupancy = buffer_bytes * 8;
46+
47+
if (codec_id == AV_CODEC_ID_H264) {
48+
+#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
49+
+GCC_DIAG_OFF(deprecated-declarations)
50+
+#endif
51+
c->ticks_per_frame = 2;
52+
-
53+
+#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
54+
+GCC_DIAG_ON(deprecated-declarations)
55+
+#endif
56+
57+
c->flags|=AV_CODEC_FLAG_LOOP_FILTER; // flags=+loop
58+
c->me_cmp|= 1; // cmp=+chroma, where CHROMA = 1
59+
@@ -3212,6 +3217,9 @@ static switch_status_t av_file_read_vide
60+
61+
if ((c = av_get_codec_context(mst)) && c->time_base.num) {
62+
cp = av_stream_get_parser(st);
63+
+#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
64+
+GCC_DIAG_OFF(deprecated-declarations)
65+
+#endif
66+
ticks = cp ? cp->repeat_pict + 1 : c->ticks_per_frame;
67+
// mst->next_pts += ((int64_t)AV_TIME_BASE * st->codec->time_base.num * ticks) / st->codec->time_base.den;
68+
}
69+
@@ -3221,6 +3229,9 @@ static switch_status_t av_file_read_vide
70+
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,
71+
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));
72+
}
73+
+#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V)
74+
+GCC_DIAG_ON(deprecated-declarations)
75+
+#endif
76+
77+
again:
78+
79+
--- a/src/mod/applications/mod_av/mod_av.h
80+
+++ b/src/mod/applications/mod_av/mod_av.h
81+
@@ -40,10 +40,13 @@
82+
#ifndef MOD_AV_H
83+
#define MOD_AV_H
84+
85+
-#define LIBAVCODEC_V 59
86+
-#define LIBAVFORMAT_V 59
87+
-#define LIBAVFORMAT_6_V 60
88+
-#define LIBAVUTIL_V 57
89+
+#define LIBAVCODEC_V 59 /* FFmpeg version >= 5.1 */
90+
+#define LIBAVCODEC_6_V 60 /* FFmpeg version >= 6.0 */
91+
+#define LIBAVCODEC_61_V 31 /* FFmpeg version >= 6.1 */
92+
+#define LIBAVFORMAT_V 59 /* FFmpeg version >= 5.1 */
93+
+#define LIBAVFORMAT_6_V 60 /* FFmpeg version >= 6.0 */
94+
+#define LIBAVFORMAT_61_V 16 /* FFmpeg version >= 6.1 */
95+
+#define LIBAVUTIL_V 57 /* FFmpeg version >= 5.1 */
96+
97+
struct mod_av_globals {
98+
int debug;
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 066b92c5894b07a4879a26a9f6a1cdcf59e016ea Mon Sep 17 00:00:00 2001
2+
From: Andrey Volk <andywolk@gmail.com>
3+
Date: Fri, 11 Jul 2025 13:39:48 +0300
4+
Subject: [PATCH 4/4] [mod_av] Add support for FFmpeg 7.1
5+
6+
---
7+
src/mod/applications/mod_av/avformat.c | 14 ++++++++++++++
8+
1 file changed, 14 insertions(+)
9+
10+
--- a/src/mod/applications/mod_av/avformat.c
11+
+++ b/src/mod/applications/mod_av/avformat.c
12+
@@ -557,7 +557,21 @@ static switch_status_t add_stream(av_fil
13+
14+
switch ((*codec)->type) {
15+
case AVMEDIA_TYPE_AUDIO:
16+
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
17+
+ /*
18+
+ Changelog says 61.12.100 but commit changes version actually to 61.13.100
19+
+ https://github.com/FFmpeg/FFmpeg/commit/3305767560a6303f474fffa3afb10c500059b455
20+
+ */
21+
+ {
22+
+ const enum AVSampleFormat *sample_fmts = NULL;
23+
+ int fmts_count = 0;
24+
+ int ret = avcodec_get_supported_config(c, *codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void**)&sample_fmts, &fmts_count);
25+
+
26+
+ c->sample_fmt = (ret >= 0 && fmts_count && sample_fmts) ? sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
27+
+ }
28+
+#else
29+
c->sample_fmt = (*codec)->sample_fmts ? (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
30+
+#endif
31+
c->bit_rate = 128000;
32+
c->sample_rate = mst->sample_rate = context->handle->samplerate;
33+
#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_V)

0 commit comments

Comments
 (0)