---
libavformat/internal.h | 6 +++
libavformat/utils.c | 132 ++++++++++++++++++++++++++++++++++---------------
2 files changed, 98 insertions(+), 40 deletions(-)
diff --git a/libavformat/internal.h b/libavformat/internal.h
index d4fb448..ec40f10 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -110,6 +110,12 @@ struct AVStreamInternal {
* 1 if avctx has been initialized with the values from the codec
parameters
*/
int avctx_inited;
+
+#if FF_API_LAVF_AVCTX
+ // whether the deprecated stream codec context needs
+ // to be filled from the codec parameters
+ int need_codec_update;
+#endif
};
void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 50ca1db..e8cd9bb 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -167,8 +167,14 @@ static int set_codec_from_probe_data(AVFormatContext *s,
AVStream *st,
fmt->name, score);
for (i = 0; fmt_id_type[i].name; i++) {
if (!strcmp(fmt->name, fmt_id_type[i].name)) {
- st->codec->codec_id = fmt_id_type[i].id;
- st->codec->codec_type = fmt_id_type[i].type;
+ st->codecpar->codec_id = fmt_id_type[i].id;
+ st->codecpar->codec_type = fmt_id_type[i].type;
+#if FF_API_LAVF_AVCTX
+FF_DISABLE_DEPRECATION_WARNINGS
+ st->codec->codec_type = st->codecpar->codec_type;
+ st->codec->codec_id = st->codecpar->codec_id;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
break;
}
}
@@ -253,6 +259,28 @@ static int queue_attached_pictures(AVFormatContext *s)
return 0;
}
+#if FF_API_LAVF_AVCTX
+FF_DISABLE_DEPRECATION_WARNINGS
+static int update_stream_avctx(AVFormatContext *s)
+{
+ int i, ret;
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *st = s->streams[i];
+
+ if (!st->internal->need_codec_update)
+ continue;
+
+ ret = avcodec_parameters_to_context(st->codec, st->codecpar);
+ if (ret < 0)
+ return ret;
+
+ st->internal->need_codec_update = 0;
+ }
+ return 0;
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
int avformat_open_input(AVFormatContext **ps, const char *filename,
AVInputFormat *fmt, AVDictionary **options)
{
@@ -321,6 +349,10 @@ int avformat_open_input(AVFormatContext **ps, const char
*filename,
s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+#if FF_API_LAVF_AVCTX
+ update_stream_avctx(s);
+#endif
+
if (options) {
av_dict_free(options);
*options = tmp;
@@ -342,7 +374,7 @@ fail:
static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
{
- if (st->codec->codec_id == AV_CODEC_ID_PROBE) {
+ if (st->codecpar->codec_id == AV_CODEC_ID_PROBE) {
AVProbeData *pd = &st->probe_data;
av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index);
--st->probe_packets;
@@ -368,7 +400,7 @@ static int probe_codec(AVFormatContext *s, AVStream *st,
const AVPacket *pkt)
av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {
set_codec_from_probe_data(s, st, pd, st->probe_packets > 0
? AVPROBE_SCORE_MAX / 4 : 0);
- if (st->codec->codec_id != AV_CODEC_ID_PROBE) {
+ if (st->codecpar->codec_id != AV_CODEC_ID_PROBE) {
pd->buf_size = 0;
av_freep(&pd->buf);
av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
@@ -389,7 +421,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
if (pktl) {
*pkt = pktl->pkt;
st = s->streams[pkt->stream_index];
- if (st->codec->codec_id != AV_CODEC_ID_PROBE ||
+ if (st->codecpar->codec_id != AV_CODEC_ID_PROBE ||
!st->probe_packets ||
s->internal->raw_packet_buffer_remaining_size < pkt->size) {
AVProbeData *pd;
@@ -441,22 +473,22 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
st = s->streams[pkt->stream_index];
- switch (st->codec->codec_type) {
+ switch (st->codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (s->video_codec_id)
- st->codec->codec_id = s->video_codec_id;
+ st->codecpar->codec_id = s->video_codec_id;
break;
case AVMEDIA_TYPE_AUDIO:
if (s->audio_codec_id)
- st->codec->codec_id = s->audio_codec_id;
+ st->codecpar->codec_id = s->audio_codec_id;
break;
case AVMEDIA_TYPE_SUBTITLE:
if (s->subtitle_codec_id)
- st->codec->codec_id = s->subtitle_codec_id;
+ st->codecpar->codec_id = s->subtitle_codec_id;
break;
}
- if (!pktl && (st->codec->codec_id != AV_CODEC_ID_PROBE ||
+ if (!pktl && (st->codecpar->codec_id != AV_CODEC_ID_PROBE ||
!st->probe_packets))
return ret;
@@ -479,13 +511,13 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden,
AVStream *st,
AVCodecParserContext *pc, AVPacket *pkt)
{
- AVRational codec_framerate = s->iformat ? st->codec->framerate :
- av_inv_q(st->codec->time_base);
+ AVRational codec_framerate = s->iformat ? st->internal->avctx->framerate :
+ (AVRational){ 0, 1 };
int frame_size;
*pnum = 0;
*pden = 0;
- switch (st->codec->codec_type) {
+ switch (st->codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (st->avg_frame_rate.num) {
*pnum = st->avg_frame_rate.den;
@@ -505,16 +537,16 @@ void ff_compute_frame_duration(AVFormatContext *s, int
*pnum, int *pden, AVStrea
/* If this codec can be interlaced or progressive then we need
* a parser to compute duration of a packet. Thus if we have
* no parser in such case leave duration undefined. */
- if (st->codec->ticks_per_frame > 1 && !pc)
+ if (st->internal->avctx->ticks_per_frame > 1 && !pc)
*pnum = *pden = 0;
}
break;
case AVMEDIA_TYPE_AUDIO:
- frame_size = av_get_audio_frame_duration(st->codec, pkt->size);
- if (frame_size <= 0 || st->codec->sample_rate <= 0)
+ frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size);
+ if (frame_size <= 0 || st->codecpar->sample_rate <= 0)
break;
*pnum = frame_size;
- *pden = st->codec->sample_rate;
+ *pden = st->codecpar->sample_rate;
break;
default:
break;
@@ -591,10 +623,10 @@ static void update_initial_durations(AVFormatContext *s,
AVStream *st,
pktl->pkt.dts == AV_NOPTS_VALUE &&
!pktl->pkt.duration) {
pktl->pkt.dts = cur_dts;
- if (!st->codec->has_b_frames)
+ if (!st->internal->avctx->has_b_frames)
pktl->pkt.pts = cur_dts;
cur_dts += duration;
- if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO)
+ if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
pktl->pkt.duration = duration;
} else
break;
@@ -616,7 +648,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream
*st,
pkt->dts = AV_NOPTS_VALUE;
/* do we have a video B-frame ? */
- delay = st->codec->has_b_frames;
+ delay = st->internal->avctx->has_b_frames;
presentation_delayed = 0;
/* XXX: need has_b_frame, but cannot get it if the codec is
@@ -641,7 +673,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream
*st,
pkt->dts = AV_NOPTS_VALUE;
}
- if (pkt->duration == 0 && st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
+ if (pkt->duration == 0 && st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
ff_compute_frame_duration(s, &num, &den, st, pc, pkt);
if (den && num) {
pkt->duration = av_rescale_rnd(1, num * (int64_t)
st->time_base.den,
@@ -679,7 +711,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream
*st,
/* Interpolate PTS and DTS if they are not present. We skip H.264
* currently because delay and has_b_frames are not reliably set. */
if ((delay == 0 || (delay == 1 && pc)) &&
- st->codec->codec_id != AV_CODEC_ID_H264) {
+ st->codecpar->codec_id != AV_CODEC_ID_H264) {
if (presentation_delayed) {
/* DTS = decompression timestamp */
/* PTS = presentation timestamp */
@@ -702,9 +734,9 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream
*st,
} else if (pkt->pts != AV_NOPTS_VALUE ||
pkt->dts != AV_NOPTS_VALUE ||
pkt->duration ||
- st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
int duration = pkt->duration;
- if (!duration && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (!duration && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
ff_compute_frame_duration(s, &num, &den, st, pc, pkt);
if (den && num) {
duration = av_rescale_rnd(1,
@@ -740,7 +772,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream
*st,
if (pkt->dts == AV_NOPTS_VALUE)
pkt->dts = st->pts_buffer[0];
// We skipped it above so we try here.
- if (st->codec->codec_id == AV_CODEC_ID_H264)
+ if (st->codecpar->codec_id == AV_CODEC_ID_H264)
// This should happen on the first packet
update_initial_timestamps(s, pkt->stream_index, pkt->dts,
pkt->pts);
if (pkt->dts > st->cur_dts)
@@ -752,7 +784,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream
*st,
presentation_delayed, delay, pkt->pts, pkt->dts, st->cur_dts);
/* update flags */
- if (is_intra_only(st->codec->codec_id))
+ if (is_intra_only(st->codecpar->codec_id))
pkt->flags |= AV_PKT_FLAG_KEY;
#if FF_API_CONVERGENCE_DURATION
FF_DISABLE_DEPRECATION_WARNINGS
@@ -796,7 +828,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
int stream_index)
int len;
av_init_packet(&out_pkt);
- len = av_parser_parse2(st->parser, st->codec,
+ len = av_parser_parse2(st->parser, st->internal->avctx,
&out_pkt.data, &out_pkt.size, data, size,
pkt->pts, pkt->dts, pkt->pos);
@@ -819,11 +851,11 @@ static int parse_packet(AVFormatContext *s, AVPacket
*pkt, int stream_index)
/* set the duration */
out_pkt.duration = 0;
- if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- if (st->codec->sample_rate > 0) {
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (st->internal->avctx->sample_rate > 0) {
out_pkt.duration =
av_rescale_q_rnd(st->parser->duration,
- (AVRational) { 1, st->codec->sample_rate
},
+ (AVRational) { 1,
st->internal->avctx->sample_rate },
st->time_base,
AV_ROUND_DOWN);
}
@@ -928,7 +960,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket
*pkt)
cur_pkt.size, cur_pkt.duration, cur_pkt.flags);
if (st->need_parsing && !st->parser && !(s->flags &
AVFMT_FLAG_NOPARSE)) {
- st->parser = av_parser_init(st->codec->codec_id);
+ st->parser = av_parser_init(st->codecpar->codec_id);
if (!st->parser)
/* no parser available: just output the raw packets */
st->need_parsing = AVSTREAM_PARSE_NONE;
@@ -969,6 +1001,10 @@ static int read_frame_internal(AVFormatContext *s,
AVPacket *pkt)
av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN);
}
+#if FF_API_LAVF_AVCTX
+ update_stream_avctx(s);
+#endif
+
if (s->debug & FF_FDEBUG_TS)
av_log(s, AV_LOG_DEBUG,
"read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", "
@@ -1057,12 +1093,12 @@ int av_find_default_stream_index(AVFormatContext *s)
return -1;
for (i = 0; i < s->nb_streams; i++) {
st = s->streams[i];
- if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) {
return i;
}
if (first_audio_index < 0 &&
- st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
first_audio_index = i;
}
return first_audio_index >= 0 ? first_audio_index : 0;
@@ -1665,12 +1701,12 @@ static void
estimate_timings_from_bit_rate(AVFormatContext *ic)
int bit_rate = 0;
for (i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i];
- if (st->codec->bit_rate > 0) {
- if (INT_MAX - st->codec->bit_rate < bit_rate) {
+ if (st->codecpar->bit_rate > 0) {
+ if (INT_MAX - st->codecpar->bit_rate < bit_rate) {
bit_rate = 0;
break;
}
- bit_rate += st->codec->bit_rate;
+ bit_rate += st->codecpar->bit_rate;
}
}
ic->bit_rate = bit_rate;
@@ -1712,7 +1748,7 @@ static void estimate_timings_from_pts(AVFormatContext
*ic, int64_t old_offset)
for (i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i];
if (st->start_time == AV_NOPTS_VALUE && st->first_dts ==
AV_NOPTS_VALUE)
- av_log(st->codec, AV_LOG_WARNING,
+ av_log(ic, AV_LOG_WARNING,
"start time is not set in estimate_timings_from_pts\n");
if (st->parser) {
@@ -2460,8 +2496,8 @@ int av_find_best_stream(AVFormatContext *ic, enum
AVMediaType type,
for (i = 0; i < nb_streams; i++) {
int real_stream_index = program ? program[i] : i;
AVStream *st = ic->streams[real_stream_index];
- AVCodecContext *avctx = st->codec;
- if (avctx->codec_type != type)
+ AVCodecParameters *par = st->codecpar;
+ if (par->codec_type != type)
continue;
if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
continue;
@@ -2469,7 +2505,7 @@ int av_find_best_stream(AVFormatContext *ic, enum
AVMediaType type,
AV_DISPOSITION_VISUAL_IMPAIRED))
continue;
if (decoder_ret) {
- decoder = avcodec_find_decoder(st->codec->codec_id);
+ decoder = avcodec_find_decoder(par->codec_id);
if (!decoder) {
if (ret < 0)
ret = AVERROR_DECODER_NOT_FOUND;
@@ -2540,9 +2576,13 @@ static void free_stream(AVStream **pst)
avcodec_parameters_free(&st->codecpar);
av_freep(&st->probe_data.buf);
av_free(st->index_entries);
+#if FF_API_LAVF_AVCTX
+FF_DISABLE_DEPRECATION_WARNINGS
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
av_free(st->priv_data);
av_free(st->info);
@@ -2622,20 +2662,28 @@ AVStream *avformat_new_stream(AVFormatContext *s, const
AVCodec *c)
return NULL;
}
+#if FF_API_LAVF_AVCTX
+FF_DISABLE_DEPRECATION_WARNINGS
st->codec = avcodec_alloc_context3(c);
if (!st->codec) {
av_free(st->info);
av_free(st);
return NULL;
}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
st->internal = av_mallocz(sizeof(*st->internal));
if (!st->internal)
goto fail;
if (s->iformat) {
+#if FF_API_LAVF_AVCTX
+FF_DISABLE_DEPRECATION_WARNINGS
/* no default bitrate if decoding */
st->codec->bit_rate = 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
/* default pts setting is MPEG-like */
avpriv_set_pts_info(st, 33, 1, 90000);
@@ -2671,6 +2719,10 @@ AVStream *avformat_new_stream(AVFormatContext *s, const
AVCodec *c)
st->info->fps_first_dts = AV_NOPTS_VALUE;
st->info->fps_last_dts = AV_NOPTS_VALUE;
+#if FF_API_LAVF_AVCTX
+ st->internal->need_codec_update = 1;
+#endif
+
s->streams[s->nb_streams++] = st;
return st;
fail:
--
2.0.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel