Skip to content

Commit ff2e8b4

Browse files
committed
Fixes related to signalwire#2202
AVOutputFormat::priv_data_size is marked private and no longer exists in the public API as of FFMPEG 6.0, but found hidden in AVOutputFormat as part of FFOutputFormat. AVCodecContext::ticks_per_frame was deprecated as of FFMPEG 6.1. libavcodec notes 'do not use avcodec_close()' as of FFMPEG 3.1, use avcodec_free_context() instead. AVFrame::key_frame was deprecated as of FFMPEG 6.1, use AVFrame::flags instead. AVInputFormat::read_seek and AVInputFormat::read_seek2 no longer exists as of FFMPEG 7.0. This seems to only be used for logging purposes, so guard this functionality accordingly.
1 parent ec25d5d commit ff2e8b4

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/mod/applications/mod_av/avcodec.c

+26-1
Original file line numberDiff line numberDiff line change
@@ -1226,9 +1226,13 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt
12261226
}
12271227

12281228
if (context->encoder_ctx) {
1229+
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,48,101))
12291230
if (avcodec_is_open(context->encoder_ctx)) {
12301231
avcodec_close(context->encoder_ctx);
12311232
}
1233+
#else
1234+
avcodec_free_context(&(context->encoder_ctx));
1235+
#endif
12321236
av_free(context->encoder_ctx);
12331237
context->encoder_ctx = NULL;
12341238
}
@@ -1319,9 +1323,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
13191323
}
13201324

13211325
if (context->encoder_ctx) {
1326+
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,48,101))
13221327
if (avcodec_is_open(context->encoder_ctx)) {
13231328
avcodec_close(context->encoder_ctx);
13241329
}
1330+
#else
1331+
avcodec_free_context(&(context->encoder_ctx));
1332+
#endif
13251333
av_free(context->encoder_ctx);
13261334
context->encoder_ctx = NULL;
13271335
}
@@ -1557,7 +1565,11 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec, switch_frame_t
15571565
}
15581566

15591567
avframe->pict_type = AV_PICTURE_TYPE_I;
1568+
#if (LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58,29,100))
15601569
avframe->key_frame = 1;
1570+
#else
1571+
avframe->flags |= AV_FRAME_FLAG_KEY;
1572+
#endif
15611573
context->last_keyframe_request = switch_time_now();
15621574
}
15631575

@@ -1600,9 +1612,14 @@ GCC_DIAG_ON(deprecated-declarations)
16001612
}
16011613
#endif
16021614

1615+
#if (LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58,29,100))
16031616
if (context->need_key_frame && avframe->key_frame == 1) {
1604-
avframe->pict_type = 0;
16051617
avframe->key_frame = 0;
1618+
#else
1619+
if (context->need_key_frame && avframe->flags & AV_FRAME_FLAG_KEY) {
1620+
avframe->flags ^= AV_FRAME_FLAG_KEY;
1621+
#endif
1622+
avframe->pict_type = 0;
16061623
context->need_key_frame = 0;
16071624
}
16081625

@@ -1862,14 +1879,22 @@ static switch_status_t switch_h264_destroy(switch_codec_t *codec)
18621879

18631880
switch_buffer_destroy(&context->nalu_buffer);
18641881
if (context->decoder_ctx) {
1882+
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,48,101))
18651883
if (avcodec_is_open(context->decoder_ctx)) avcodec_close(context->decoder_ctx);
1884+
#else
1885+
avcodec_free_context(&(context->decoder_ctx));
1886+
#endif
18661887
av_free(context->decoder_ctx);
18671888
}
18681889

18691890
switch_img_free(&context->img);
18701891

18711892
if (context->encoder_ctx) {
1893+
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,48,101))
18721894
if (avcodec_is_open(context->encoder_ctx)) avcodec_close(context->encoder_ctx);
1895+
#else
1896+
avcodec_free_context(&(context->encoder_ctx));
1897+
#endif
18731898
av_free(context->encoder_ctx);
18741899
}
18751900

src/mod/applications/mod_av/avformat.c

+28-3
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ struct av_file_context {
184184

185185
typedef struct av_file_context av_file_context_t;
186186

187+
#if (LIBAVFORMAT_VERSION_MAJOR >= 60)
188+
typedef struct FFOutputFormat {
189+
int priv_data_size;
190+
} FFOutputFormat;
191+
192+
static inline int priv_data_size(const AVOutputFormat *fmt)
193+
{
194+
return ((const struct FFOutputFormat*)fmt)->priv_data_size;
195+
}
196+
#endif
187197

188198
/**
189199
* Fill the provided buffer with a string containing a timestamp
@@ -455,8 +465,13 @@ static int mod_avformat_alloc_output_context2(AVFormatContext **avctx, const cha
455465
}
456466

457467
s->oformat = oformat;
468+
#if (LIBAVFORMAT_VERSION_MAJOR < 60)
458469
if (s->oformat->priv_data_size > 0) {
459470
s->priv_data = av_mallocz(s->oformat->priv_data_size);
471+
#else
472+
if (priv_data_size(s->oformat) > 0) {
473+
s->priv_data = av_mallocz(priv_data_size(s->oformat));
474+
#endif
460475
if (!s->priv_data) {
461476
goto nomem;
462477
}
@@ -621,7 +636,9 @@ static switch_status_t add_stream(av_file_context_t *context, MediaStream *mst,
621636
c->rc_initial_buffer_occupancy = buffer_bytes * 8;
622637

623638
if (codec_id == AV_CODEC_ID_H264) {
639+
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60,31,102))
624640
c->ticks_per_frame = 2;
641+
#endif
625642

626643

627644
c->flags|=AV_CODEC_FLAG_LOOP_FILTER; // flags=+loop
@@ -1410,8 +1427,10 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
14101427
switch_goto_status(SWITCH_STATUS_FALSE, err);
14111428
}
14121429

1430+
#if (LIBAVFORMAT_VERSION_MAJOR < 61)
14131431
handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0);
14141432
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "file %s is %sseekable\n", filename, handle->seekable ? "" : "not ");
1433+
#endif
14151434

14161435
/** Get information on the input file (number of streams etc.). */
14171436
if ((error = avformat_find_stream_info(context->fc, opts ? &opts : NULL)) < 0) {
@@ -1502,7 +1521,11 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
15021521

15031522
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)));
15041523
if ((cc = av_get_codec_context(&context->audio_st[0]))) {
1524+
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,48,101))
15051525
avcodec_close(cc);
1526+
#else
1527+
avcodec_free_context(&cc);
1528+
#endif
15061529
}
15071530

15081531
context->has_audio = 0;
@@ -3084,14 +3107,11 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
30843107
void *pop;
30853108
MediaStream *mst = &context->video_st;
30863109
AVStream *st = mst->st;
3087-
int ticks = 0;
30883110
int64_t max_delta = 1 * AV_TIME_BASE; // 1 second
30893111
switch_status_t status = SWITCH_STATUS_SUCCESS;
30903112
double fl_to = 0.02;
30913113
int do_fl = 0;
30923114
int smaller_ts = context->read_fps;
3093-
AVCodecContext *c = NULL;
3094-
AVCodecParserContext *cp = NULL;
30953115

30963116
if (!context->has_video) return SWITCH_STATUS_FALSE;
30973117

@@ -3199,6 +3219,10 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
31993219
}
32003220
#endif
32013221

3222+
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60,31,102))
3223+
int ticks = 0;
3224+
AVCodecContext *c = NULL;
3225+
AVCodecParserContext *cp = NULL;
32023226
if ((c = av_get_codec_context(mst)) && c->time_base.num) {
32033227
cp = av_stream_get_parser(st);
32043228
ticks = cp ? cp->repeat_pict + 1 : c->ticks_per_frame;
@@ -3210,6 +3234,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
32103234
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,
32113235
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));
32123236
}
3237+
#endif
32133238

32143239
again:
32153240

0 commit comments

Comments
 (0)