Skip to content

Commit

Permalink
avformat: remove deprecated AVStream.codec
Browse files Browse the repository at this point in the history
Signed-off-by: James Almer <jamrial@gmail.com>
  • Loading branch information
jamrial committed Apr 27, 2021
1 parent e5af920 commit 3749eed
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 333 deletions.
13 changes: 0 additions & 13 deletions fftools/ffmpeg_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2442,19 +2442,6 @@ static int open_output_file(OptionsContext *o, const char *filename)
avio_closep(&pb);
}

#if FF_API_LAVF_AVCTX
for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file
AVDictionaryEntry *e;
ost = output_streams[i];

if ((ost->stream_copy || ost->attachment_filename)
&& (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX))
&& (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6)))
if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0)
exit_program(1);
}
#endif

if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
av_dump_format(oc, nb_output_files - 1, oc->url, 1);
av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
Expand Down
16 changes: 4 additions & 12 deletions libavformat/avformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -839,13 +839,7 @@ typedef struct AVStream {
* encoding: set by the user, replaced by libavformat if left unset
*/
int id;
#if FF_API_LAVF_AVCTX
/**
* @deprecated use the codecpar struct instead
*/
attribute_deprecated
AVCodecContext *codec;
#endif

void *priv_data;

/**
Expand Down Expand Up @@ -1837,13 +1831,11 @@ const AVClass *avformat_get_class(void);
*
* When muxing, should be called by the user before avformat_write_header().
*
* User is required to call avcodec_close() and avformat_free_context() to
* clean up the allocation by avformat_new_stream().
* User is required to call avformat_free_context() to clean up the allocation
* by avformat_new_stream().
*
* @param s media file handle
* @param c If non-NULL, the AVCodecContext corresponding to the new stream
* will be initialized to use this codec. This is needed for e.g. codec-specific
* defaults to be set, so codec should be provided if it is known.
* @param c unused, does nothing
*
* @return newly created stream or NULL on error.
*/
Expand Down
29 changes: 7 additions & 22 deletions libavformat/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "libavutil/timecode.h"

#include "avformat.h"
#include "internal.h"

#define HEXDUMP_PRINT(...) \
do { \
Expand Down Expand Up @@ -522,17 +523,13 @@ static void dump_stream_format(const AVFormatContext *ic, int i,
return;
}

#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
// Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext
avctx->properties = st->codec->properties;
avctx->codec = st->codec->codec;
avctx->qmin = st->codec->qmin;
avctx->qmax = st->codec->qmax;
avctx->coded_width = st->codec->coded_width;
avctx->coded_height = st->codec->coded_height;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
avctx->properties = st->internal->avctx->properties;
avctx->codec = st->internal->avctx->codec;
avctx->qmin = st->internal->avctx->qmin;
avctx->qmax = st->internal->avctx->qmax;
avctx->coded_width = st->internal->avctx->coded_width;
avctx->coded_height = st->internal->avctx->coded_height;

if (separator)
av_opt_set(avctx, "dump_separator", separator, 0);
Expand Down Expand Up @@ -567,13 +564,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
int tbr = st->r_frame_rate.den && st->r_frame_rate.num;
int tbn = st->time_base.den && st->time_base.num;
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
int tbc = st->codec->time_base.den && st->codec->time_base.num;
FF_ENABLE_DEPRECATION_WARNINGS
#else
int tbc = 0;
#endif

if (fps || tbr || tbn || tbc)
av_log(NULL, AV_LOG_INFO, "%s", separator);
Expand All @@ -584,12 +575,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
if (tbn)
print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
if (tbc)
print_fps(1 / av_q2d(st->codec->time_base), "tbc");
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}

if (st->disposition & AV_DISPOSITION_DEFAULT)
Expand Down
12 changes: 1 addition & 11 deletions libavformat/isom.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,12 @@ static const AVCodecTag mp4_audio_types[] = {
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
{
enum AVCodecID codec_id;
unsigned v;
int len, tag;
int ret;
int object_type_id = avio_r8(pb);
avio_r8(pb); /* stream type */
avio_rb24(pb); /* buffer size db */

v = avio_rb32(pb);

// TODO: fix this with codecpar
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
if (v < INT32_MAX)
st->codec->rc_max_rate = v;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
avio_rb32(pb); /* rc_max_rate */

st->codecpar->bit_rate = avio_rb32(pb); /* avg bitrate */

Expand Down
17 changes: 0 additions & 17 deletions libavformat/mov.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,6 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if (st->codecpar->channels > 1 && bsmod == 0x7)
*ast = AV_AUDIO_SERVICE_TYPE_KARAOKE;

#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
st->codec->audio_service_type = *ast;
FF_ENABLE_DEPRECATION_WARNINGS
#endif

return 0;
}

Expand Down Expand Up @@ -844,12 +838,6 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if (st->codecpar->channels > 1 && bsmod == 0x7)
*ast = AV_AUDIO_SERVICE_TYPE_KARAOKE;

#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
st->codec->audio_service_type = *ast;
FF_ENABLE_DEPRECATION_WARNINGS
#endif

return 0;
}

Expand Down Expand Up @@ -2340,11 +2328,6 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb,
tmcd_ctx->tmcd_flags = val;
st->avg_frame_rate.num = AV_RB32(st->codecpar->extradata + 8); /* timescale */
st->avg_frame_rate.den = AV_RB32(st->codecpar->extradata + 12); /* frameDuration */
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
st->codec->time_base = av_inv_q(st->avg_frame_rate);
FF_ENABLE_DEPRECATION_WARNINGS
#endif
if (size > 30) {
uint32_t len = AV_RB32(st->codecpar->extradata + 18); /* name atom length */
uint32_t format = AV_RB32(st->codecpar->extradata + 22);
Expand Down
38 changes: 3 additions & 35 deletions libavformat/movenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1459,27 +1459,9 @@ static int mov_get_dv_codec_tag(AVFormatContext *s, MOVTrack *track)
return tag;
}

static AVRational find_fps(AVFormatContext *s, AVStream *st)
{
AVRational rate = st->avg_frame_rate;

#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
rate = av_inv_q(st->codec->time_base);
if (av_timecode_check_frame_rate(rate) < 0) {
av_log(s, AV_LOG_DEBUG, "timecode: tbc=%d/%d invalid, fallback on %d/%d\n",
rate.num, rate.den, st->avg_frame_rate.num, st->avg_frame_rate.den);
rate = st->avg_frame_rate;
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif

return rate;
}

static int defined_frame_rate(AVFormatContext *s, AVStream *st)
{
AVRational rational_framerate = find_fps(s, st);
AVRational rational_framerate = st->avg_frame_rate;
int rate = 0;
if (rational_framerate.den != 0)
rate = av_q2d(rational_framerate);
Expand Down Expand Up @@ -2234,13 +2216,6 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
track->par->codec_id != AV_CODEC_ID_DNXHD) {
int field_order = track->par->field_order;

#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
if (field_order != track->st->codec->field_order && track->st->codec->field_order != AV_FIELD_UNKNOWN)
field_order = track->st->codec->field_order;
FF_ENABLE_DEPRECATION_WARNINGS
#endif

if (field_order != AV_FIELD_UNKNOWN)
mov_write_fiel_tag(pb, track, field_order);
}
Expand Down Expand Up @@ -2354,15 +2329,8 @@ static int mov_write_tmcd_tag(AVIOContext *pb, MOVTrack *track)
AVDictionaryEntry *t = NULL;

if (!track->st->avg_frame_rate.num || !track->st->avg_frame_rate.den) {
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
frame_duration = av_rescale(track->timescale, track->st->codec->time_base.num, track->st->codec->time_base.den);
nb_frames = ROUNDED_DIV(track->st->codec->time_base.den, track->st->codec->time_base.num);
FF_ENABLE_DEPRECATION_WARNINGS
#else
av_log(NULL, AV_LOG_ERROR, "avg_frame_rate not set for tmcd track.\n");
return AVERROR(EINVAL);
#endif
} else {
frame_duration = av_rescale(track->timescale, track->st->avg_frame_rate.den, track->st->avg_frame_rate.num);
nb_frames = ROUNDED_DIV(track->st->avg_frame_rate.num, track->st->avg_frame_rate.den);
Expand Down Expand Up @@ -6199,7 +6167,7 @@ static int mov_check_timecode_track(AVFormatContext *s, AVTimecode *tc, int src_
int ret;

/* compute the frame number */
ret = av_timecode_init_from_string(tc, find_fps(s, s->streams[src_index]), tcstr, s);
ret = av_timecode_init_from_string(tc, s->streams[src_index]->avg_frame_rate, tcstr, s);
return ret;
}

Expand All @@ -6210,7 +6178,7 @@ static int mov_create_timecode_track(AVFormatContext *s, int index, int src_inde
AVStream *src_st = s->streams[src_index];
uint8_t data[4];
AVPacket *pkt = mov->pkt;
AVRational rate = find_fps(s, src_st);
AVRational rate = src_st->avg_frame_rate;
int ret;

/* tmcd track based on video stream */
Expand Down
27 changes: 0 additions & 27 deletions libavformat/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,6 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
goto fail;
}

#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
if (s->nb_streams && s->streams[0]->codec->flags & AV_CODEC_FLAG_BITEXACT) {
if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
av_log(s, AV_LOG_WARNING,
"The AVFormatContext is not in set to bitexact mode, only "
"the AVCodecContext. If this is not intended, set "
"AVFormatContext.flags |= AVFMT_FLAG_BITEXACT.\n");
}
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif

// some sanity checks
if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) {
av_log(s, AV_LOG_ERROR, "No streams to mux were specified\n");
Expand All @@ -271,20 +258,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
st = s->streams[i];
par = st->codecpar;

#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
if (st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN &&
st->codec->codec_type != AVMEDIA_TYPE_UNKNOWN) {
av_log(s, AV_LOG_WARNING, "Using AVStream.codec to pass codec "
"parameters to muxers is deprecated, use AVStream.codecpar "
"instead.\n");
ret = avcodec_parameters_from_context(st->codecpar, st->codec);
if (ret < 0)
goto fail;
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif

if (!st->time_base.num) {
/* fall back on the default timebase values */
if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->sample_rate)
Expand Down
18 changes: 0 additions & 18 deletions libavformat/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,24 +704,6 @@ static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int
case AV_CODEC_ID_SPEEX:
av_strlcatf(buff, size, "a=rtpmap:%d speex/%d\r\n",
payload_type, p->sample_rate);
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
if (st->codec) {
const char *mode;
uint64_t vad_option;

if (st->codec->flags & AV_CODEC_FLAG_QSCALE)
mode = "on";
else if (!av_opt_get_int(st->codec, "vad", AV_OPT_FLAG_ENCODING_PARAM, &vad_option) && vad_option)
mode = "vad";
else
mode = "off";

av_strlcatf(buff, size, "a=fmtp:%d vbr=%s\r\n",
payload_type, mode);
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif
break;
case AV_CODEC_ID_OPUS:
/* The opus RTP draft says that all opus streams MUST be declared
Expand Down
6 changes: 0 additions & 6 deletions libavformat/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@ static int segment_mux_init(AVFormatContext *s)
} else {
opar->codec_tag = 0;
}
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
if (ipar->codec_tag == MKTAG('t','m','c','d'))
st->codec->time_base = ist->codec->time_base;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}

return 0;
Expand Down
Loading

0 comments on commit 3749eed

Please sign in to comment.