* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/timestamp.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/internal.h"
#include "libavcodec/raw.h"
#include "libavutil/timestamp.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/internal.h"
#include "libavcodec/raw.h"
av_codec_is_decoder(probe_codec) &&
!(probe_codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_EXPERIMENTAL))) {
return probe_codec;
av_codec_is_decoder(probe_codec) &&
!(probe_codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_EXPERIMENTAL))) {
return probe_codec;
* Return the number of bytes read or an error. */
static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
{
* Return the number of bytes read or an error. */
static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
{
fmt->name, score);
for (i = 0; fmt_id_type[i].name; i++) {
if (!strcmp(fmt->name, fmt_id_type[i].name)) {
fmt->name, score);
for (i = 0; fmt_id_type[i].name; i++) {
if (!strcmp(fmt->name, fmt_id_type[i].name)) {
- // TODO: Adapt callers in this file so the line below can use
- // av_packet_move_ref() to effectively move the reference
- // to the list.
- pktl->pkt = *pkt;
+ ret = av_packet_make_refcounted(pkt);
+ if (ret < 0) {
+ av_free(pktl);
+ return ret;
+ }
+ av_packet_move_ref(&pktl->pkt, pkt);
s->metadata = s->internal->id3v2_meta;
s->internal->id3v2_meta = NULL;
} else if (s->internal->id3v2_meta) {
s->metadata = s->internal->id3v2_meta;
s->internal->id3v2_meta = NULL;
} else if (s->internal->id3v2_meta) {
- int level = AV_LOG_WARNING;
- if (s->error_recognition & AV_EF_COMPLIANT)
- level = AV_LOG_ERROR;
- av_log(s, level, "Discarding ID3 tags because more suitable tags were found.\n");
+ av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n");
}
if (id3v2_extra_meta) {
if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") ||
!strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name, "wav")) {
}
if (id3v2_extra_meta) {
if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") ||
!strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name, "wav")) {
- if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0)
- goto fail;
- if ((ret = ff_id3v2_parse_chapters(s, &id3v2_extra_meta)) < 0)
- goto fail;
- if ((ret = ff_id3v2_parse_priv(s, &id3v2_extra_meta)) < 0)
- goto fail;
+ if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0)
+ goto close;
+ if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0)
+ goto close;
+ if ((ret = ff_id3v2_parse_priv(s, id3v2_extra_meta)) < 0)
+ goto close;
} else
av_log(s, AV_LOG_DEBUG, "demuxer does not support additional id3 data, skipping\n");
}
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
if ((ret = avformat_queue_attached_pictures(s)) < 0)
} else
av_log(s, AV_LOG_DEBUG, "demuxer does not support additional id3 data, skipping\n");
}
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
if ((ret = avformat_queue_attached_pictures(s)) < 0)
if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->internal->data_offset)
s->internal->data_offset = avio_tell(s->pb);
if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->internal->data_offset)
s->internal->data_offset = avio_tell(s->pb);
if (s->internal->raw_packet_buffer_remaining_size <= 0)
if ((err = probe_codec(s, st, NULL)) < 0)
return err;
if (st->request_probe <= 0) {
if (s->internal->raw_packet_buffer_remaining_size <= 0)
if ((err = probe_codec(s, st, NULL)) < 0)
return err;
if (st->request_probe <= 0) {
/* Some demuxers return FFERROR_REDO when they consume
data and discard it (ignored streams, junk, extradata).
We must re-call the demuxer to get the real packet. */
/* Some demuxers return FFERROR_REDO when they consume
data and discard it (ignored streams, junk, extradata).
We must re-call the demuxer to get the real packet. */
- "Dropped corrupted packet (stream = %d)\n",
- pkt->stream_index);
- av_packet_unref(pkt);
- continue;
+ "Packet corrupt (stream = %d, dts = %s)",
+ pkt->stream_index, av_ts2str(pkt->dts));
+ if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
+ av_log(s, AV_LOG_WARNING, ", dropping it.\n");
+ av_packet_unref(pkt);
+ continue;
+ }
+ av_log(s, AV_LOG_WARNING, ".\n");
- if (pkt->stream_index >= (unsigned)s->nb_streams) {
- av_log(s, AV_LOG_ERROR, "Invalid stream index %d\n", pkt->stream_index);
- continue;
- }
+ av_assert0(pkt->stream_index < (unsigned)s->nb_streams &&
+ "Invalid stream index.\n");
err = ff_packet_list_put(&s->internal->raw_packet_buffer,
&s->internal->raw_packet_buffer_end,
pkt, 0);
err = ff_packet_list_put(&s->internal->raw_packet_buffer,
&s->internal->raw_packet_buffer_end,
pkt, 0);
if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) {
st->start_time = pktl_it->pkt.pts;
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate)
if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) {
st->start_time = pktl_it->pkt.pts;
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate)
- st->start_time += av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base);
+ st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base));
- st->start_time += av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base);
+ st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base));
{
AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
int64_t cur_dts = RELATIVE_TS_BASE;
{
AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
int64_t cur_dts = RELATIVE_TS_BASE;
ff_compute_frame_duration(s, &num, &den, st, pc, pkt);
if (den && num) {
duration = (AVRational) {num, den};
ff_compute_frame_duration(s, &num, &den, st, pc, pkt);
if (den && num) {
duration = (AVRational) {num, den};
update_initial_durations(s, st, pkt->stream_index, pkt->duration);
/* Correct timestamps with byte offset if demuxers only have timestamps
update_initial_durations(s, st, pkt->stream_index, pkt->duration);
/* Correct timestamps with byte offset if demuxers only have timestamps
if (st->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX)
st->last_IP_duration = pkt->duration;
if (pkt->dts != AV_NOPTS_VALUE)
if (st->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX)
st->last_IP_duration = pkt->duration;
if (pkt->dts != AV_NOPTS_VALUE)
if (pkt->dts != AV_NOPTS_VALUE &&
pkt->pts == AV_NOPTS_VALUE &&
st->last_IP_duration > 0 &&
if (pkt->dts != AV_NOPTS_VALUE &&
pkt->pts == AV_NOPTS_VALUE &&
st->last_IP_duration > 0 &&
* by knowing the future. */
} else if (pkt->pts != AV_NOPTS_VALUE ||
pkt->dts != AV_NOPTS_VALUE ||
* by knowing the future. */
} else if (pkt->pts != AV_NOPTS_VALUE ||
pkt->dts != AV_NOPTS_VALUE ||
st->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1);
}
}
st->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1);
}
}
presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), st->index, st->id);
/* update flags */
presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), st->index, st->id);
/* update flags */
pkt->flags |= AV_PKT_FLAG_KEY;
#if FF_API_CONVERGENCE_DURATION
FF_DISABLE_DEPRECATION_WARNINGS
pkt->flags |= AV_PKT_FLAG_KEY;
#if FF_API_CONVERGENCE_DURATION
FF_DISABLE_DEPRECATION_WARNINGS
-static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
+static int parse_packet(AVFormatContext *s, AVPacket *pkt,
+ int stream_index, int flush)
- uint8_t *data = pkt ? pkt->data : NULL;
- int size = pkt ? pkt->size : 0;
- int ret = 0, got_output = 0;
-
- if (!pkt) {
- av_init_packet(&flush_pkt);
- pkt = &flush_pkt;
- got_output = 1;
- } else if (!size && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ uint8_t *data = pkt->data;
+ int size = pkt->size;
+ int ret = 0, got_output = flush;
+
+ if (size || flush) {
+ av_init_packet(&out_pkt);
+ } else if (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
// preserve 0-size sync packets
compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
}
// preserve 0-size sync packets
compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
}
len = av_parser_parse2(st->parser, st->internal->avctx,
&out_pkt.data, &out_pkt.size, data, size,
pkt->pts, pkt->dts, pkt->pos);
len = av_parser_parse2(st->parser, st->internal->avctx,
&out_pkt.data, &out_pkt.size, data, size,
pkt->pts, pkt->dts, pkt->pos);
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
/* update deprecated public codec context */
ret = avcodec_parameters_to_context(st->codec, st->codecpar);
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
/* update deprecated public codec context */
ret = avcodec_parameters_to_context(st->codec, st->codecpar);
- if (cur_pkt.pts != AV_NOPTS_VALUE &&
- cur_pkt.dts != AV_NOPTS_VALUE &&
- cur_pkt.pts < cur_pkt.dts) {
+ if (pkt->pts != AV_NOPTS_VALUE &&
+ pkt->dts != AV_NOPTS_VALUE &&
+ pkt->pts < pkt->dts) {
av_log(s, AV_LOG_WARNING,
"Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n",
av_log(s, AV_LOG_WARNING,
"Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n",
}
if (s->debug & FF_FDEBUG_TS)
av_log(s, AV_LOG_DEBUG,
"ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n",
}
if (s->debug & FF_FDEBUG_TS)
av_log(s, AV_LOG_DEBUG,
"ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n",
- cur_pkt.stream_index,
- av_ts2str(cur_pkt.pts),
- av_ts2str(cur_pkt.dts),
- cur_pkt.size, cur_pkt.duration, cur_pkt.flags);
+ pkt->stream_index,
+ av_ts2str(pkt->pts),
+ av_ts2str(pkt->dts),
+ pkt->size, pkt->duration, pkt->flags);
if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) {
st->parser = av_parser_init(st->codecpar->codec_id);
if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) {
st->parser = av_parser_init(st->codecpar->codec_id);
compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&
(pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) {
compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&
(pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) {
- if ((ret = parse_packet(s, &cur_pkt, cur_pkt.stream_index)) < 0)
+ if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0)
return ret;
st->codecpar->sample_rate = st->internal->avctx->sample_rate;
st->codecpar->bit_rate = st->internal->avctx->bit_rate;
return ret;
st->codecpar->sample_rate = st->internal->avctx->sample_rate;
st->codecpar->bit_rate = st->internal->avctx->bit_rate;
}
if (pkt->flags & AV_PKT_FLAG_KEY)
st->skip_to_keyframe = 0;
if (st->skip_to_keyframe) {
}
if (pkt->flags & AV_PKT_FLAG_KEY)
st->skip_to_keyframe = 0;
if (st->skip_to_keyframe) {
ret = ff_packet_list_put(&s->internal->packet_buffer,
&s->internal->packet_buffer_end,
ret = ff_packet_list_put(&s->internal->packet_buffer,
&s->internal->packet_buffer_end,
//We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable
const char *proto = avio_find_protocol_name(s->url);
//We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable
const char *proto = avio_find_protocol_name(s->url);
for (; i2 < st2->nb_index_entries; i2++) {
AVIndexEntry *e2 = &st2->index_entries[i2];
int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q);
for (; i2 < st2->nb_index_entries; i2++) {
AVIndexEntry *e2 = &st2->index_entries[i2];
int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q);
/* XXX This could be adjusted depending on protocol*/
if (s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) {
av_log(s, AV_LOG_VERBOSE, "Reconfiguring buffers to size %"PRId64"\n", pos_delta);
/* XXX This could be adjusted depending on protocol*/
if (s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) {
av_log(s, AV_LOG_VERBOSE, "Reconfiguring buffers to size %"PRId64"\n", pos_delta);
- ffio_set_buf_size(s->pb, pos_delta);
+
+ /* realloc the buffer and the original data will be retained */
+ if (ffio_realloc_buf(s->pb, pos_delta)) {
+ av_log(s, AV_LOG_ERROR, "Realloc buffer fail.\n");
+ return;
+ }
+
- av_log(ic, AV_LOG_DEBUG, "stream %d : no PTS found at end of file, duration not set\n", i);
+ av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i);
- av_log(ic, AV_LOG_DEBUG, "stream %d : no TS found at start of file, duration not set\n", i);
+ av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i);
+/* 1:1 map to AVDurationEstimationMethod */
+static const char *duration_name[] = {
+ [AVFMT_DURATION_FROM_PTS] = "pts",
+ [AVFMT_DURATION_FROM_STREAM] = "stream",
+ [AVFMT_DURATION_FROM_BITRATE] = "bit rate",
+};
+
+static const char *duration_estimate_name(enum AVDurationEstimationMethod method)
+{
+ return duration_name[method];
+}
+
- ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM;
+ /* nut demuxer estimate the duration from PTS */
+ if(!strcmp(ic->iformat->name, "nut"))
+ ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
+ else
+ ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM;
- av_log(ic, AV_LOG_TRACE, "stream %d: start_time: %0.3f duration: %0.3f\n", i,
- (double) st->start_time * av_q2d(st->time_base),
- (double) st->duration * av_q2d(st->time_base));
+ if (st->time_base.den)
+ av_log(ic, AV_LOG_TRACE, "stream %d: start_time: %s duration: %s\n", i,
+ av_ts2timestr(st->start_time, &st->time_base),
+ av_ts2timestr(st->duration, &st->time_base));
- "format: start_time: %0.3f duration: %0.3f bitrate=%"PRId64" kb/s\n",
- (double) ic->start_time / AV_TIME_BASE,
- (double) ic->duration / AV_TIME_BASE,
- (int64_t)ic->bit_rate / 1000);
+ "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64" kb/s\n",
+ av_ts2timestr(ic->start_time, &AV_TIME_BASE_Q),
+ av_ts2timestr(ic->duration, &AV_TIME_BASE_Q),
+ duration_estimate_name(ic->duration_estimation_method),
+ (int64_t)ic->bit_rate / 1000);
-static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt,
- AVDictionary **options)
+static int try_decode_frame(AVFormatContext *s, AVStream *st,
+ const AVPacket *avpkt, AVDictionary **options)
} else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
ret = avcodec_decode_subtitle2(avctx, &subtitle,
&got_picture, &pkt);
} else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
ret = avcodec_decode_subtitle2(avctx, &subtitle,
&got_picture, &pkt);
- st->info->duration_count++;
- st->info->rfps_duration_sum += duration;
+ if (st->info->rfps_duration_sum <= INT64_MAX - duration) {
+ st->info->duration_count++;
+ st->info->rfps_duration_sum += duration;
+ }
+static int add_coded_side_data(AVStream *st, AVCodecContext *avctx)
+{
+ int i;
+
+ for (i = 0; i < avctx->nb_coded_side_data; i++) {
+ const AVPacketSideData *sd_src = &avctx->coded_side_data[i];
+ uint8_t *dst_data;
+ dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size);
+ if (!dst_data)
+ return AVERROR(ENOMEM);
+ memcpy(dst_data, sd_src->data, sd_src->size);
+ }
+ return 0;
+}
+
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
{
int i, count = 0, ret = 0, j;
int64_t read_size;
AVStream *st;
AVCodecContext *avctx;
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
{
int i, count = 0, ret = 0, j;
int64_t read_size;
AVStream *st;
AVCodecContext *avctx;
int64_t old_offset = avio_tell(ic->pb);
// new streams might appear, no options for those
int orig_nb_streams = ic->nb_streams;
int64_t old_offset = avio_tell(ic->pb);
// new streams might appear, no options for those
int orig_nb_streams = ic->nb_streams;
- if (i == ic->nb_streams) {
- analyzed_all_streams = 1;
- /* NOTE: If the format has no header, then we need to read some
- * packets to get most of the streams, so we cannot stop here. */
- if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) {
- /* If we found the info for all the codecs, we can stop. */
- ret = count;
- av_log(ic, AV_LOG_DEBUG, "All info found\n");
- flush_codecs = 0;
- break;
+ if (i == ic->nb_streams) {
+ analyzed_all_streams = 1;
+ /* NOTE: If the format has no header, then we need to read some
+ * packets to get most of the streams, so we cannot stop here. */
+ if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) {
+ /* If we found the info for all the codecs, we can stop. */
+ ret = count;
+ av_log(ic, AV_LOG_DEBUG, "All info found\n");
+ flush_codecs = 0;
+ break;
+ }
/* We did not get all the codec info, but we read too much data. */
if (read_size >= probesize) {
ret = count;
/* We did not get all the codec info, but we read too much data. */
if (read_size >= probesize) {
ret = count;
if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
ret = ff_packet_list_put(&ic->internal->packet_buffer,
&ic->internal->packet_buffer_end,
if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
ret = ff_packet_list_put(&ic->internal->packet_buffer,
&ic->internal->packet_buffer_end,
if (!st->internal->avctx_inited) {
ret = avcodec_parameters_to_context(avctx, st->codecpar);
if (ret < 0)
if (!st->internal->avctx_inited) {
ret = avcodec_parameters_to_context(avctx, st->codecpar);
if (ret < 0)
if (!st->internal->avctx->extradata) {
ret = extract_extradata(st, pkt);
if (ret < 0)
if (!st->internal->avctx->extradata) {
ret = extract_extradata(st, pkt);
if (ret < 0)
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
avctx->time_base.den, (int64_t)avctx->time_base.num * avctx->ticks_per_frame, INT_MAX);
} else {
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
avctx->time_base.den, (int64_t)avctx->time_base.num * avctx->ticks_per_frame, INT_MAX);
} else {
avcodec_string(buf, sizeof(buf), st->internal->avctx, 0);
av_log(ic, AV_LOG_WARNING,
"Could not find codec parameters for stream %d (%s): %s\n"
avcodec_string(buf, sizeof(buf), st->internal->avctx, 0);
av_log(ic, AV_LOG_WARNING,
"Could not find codec parameters for stream %d (%s): %s\n"
- "Consider increasing the value for the 'analyzeduration' and 'probesize' options\n",
- i, buf, errmsg);
+ "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n",
+ i, buf, errmsg, ic->max_analyze_duration, ic->probesize);
ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx);
if (ret < 0)
goto find_stream_info_err;
ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx);
if (ret < 0)
goto find_stream_info_err;
#if FF_API_LOWRES
// The decoder might reduce the video size by the lowres factor.
if (st->internal->avctx->lowres && orig_w) {
#if FF_API_LOWRES
// The decoder might reduce the video size by the lowres factor.
if (st->internal->avctx->lowres && orig_w) {
av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n",
avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count, count);
return ret;
av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n",
avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count, count);
return ret;
count = st->codec_info_nb_frames;
bitrate = par->bit_rate;
multiframe = FFMIN(5, count);
count = st->codec_info_nb_frames;
bitrate = par->bit_rate;
multiframe = FFMIN(5, count);
av_freep(&st->internal->priv_pts);
av_bsf_free(&st->internal->extract_extradata.bsf);
av_packet_free(&st->internal->extract_extradata.pkt);
av_freep(&st->internal->priv_pts);
av_bsf_free(&st->internal->extract_extradata.bsf);
av_packet_free(&st->internal->extract_extradata.pkt);
av_opt_free(s);
if (s->iformat && s->iformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
if (s->oformat && s->oformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
av_opt_free(s);
if (s->iformat && s->iformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
if (s->oformat && s->oformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
- for (i = s->nb_streams - 1; i >= 0; i--)
- ff_free_stream(s, s->streams[i]);
-
+ for (i = 0; i < s->nb_streams; i++)
+ free_stream(&s->streams[i]);
+ s->nb_streams = 0;
av_dict_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_dict_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
st->start_time = AV_NOPTS_VALUE;
st->duration = AV_NOPTS_VALUE;
st->first_dts = AV_NOPTS_VALUE;
st->start_time = AV_NOPTS_VALUE;
st->duration = AV_NOPTS_VALUE;
st->first_dts = AV_NOPTS_VALUE;
char *hostname, int hostname_size,
int *port_ptr, char *path, int path_size, const char *url)
{
char *hostname, int hostname_size,
int *port_ptr, char *path, int path_size, const char *url)
{
- const char *p, *ls, *ls2, *ls3, *at, *at2, *col, *brk;
+ const char *p, *ls, *at, *at2, *col, *brk;
- ls = strchr(p, '/');
- ls2 = strchr(p, '?');
- ls3 = strchr(p, '@');
- if (ls3 && ls3 > ls && (!ls2 || ls2 > ls3))
- ls = strchr(ls3, '/');
- if (!ls)
- ls = ls2;
- else if (ls && ls2)
- ls = FFMIN(ls, ls2);
- if (ls)
- av_strlcpy(path, ls, path_size);
- else
- ls = &p[strlen(p)]; // XXX
+ ls = p + strcspn(p, "/?#");
+ av_strlcpy(path, ls, path_size);
* >0 if st is a matching stream
*/
static int match_stream_specifier(AVFormatContext *s, AVStream *st,
* >0 if st is a matching stream
*/
static int match_stream_specifier(AVFormatContext *s, AVStream *st,
for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
if (st->index == s->programs[i]->stream_index[j]) {
found = 1;
for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
if (st->index == s->programs[i]->stream_index[j]) {
found = 1;
- ret = match_stream_specifier(s, st, spec, &indexptr);
+ ret = match_stream_specifier(s, st, spec, &indexptr, &p);
return (index == st->index);
/* If we requested a matching stream index, we have to ensure st is that. */
return (index == st->index);
/* If we requested a matching stream index, we have to ensure st is that. */
- for (int i = 0; i < s->nb_streams && index >= 0; i++) {
- ret = match_stream_specifier(s, s->streams[i], spec, NULL);
+ nb_streams = p ? p->nb_stream_indexes : s->nb_streams;
+ for (int i = 0; i < nb_streams && index >= 0; i++) {
+ AVStream *candidate = p ? s->streams[p->stream_index[i]] : s->streams[i];
+ ret = match_stream_specifier(s, candidate, spec, NULL, NULL);
- av_freep(&st->codecpar->extradata);
- if (ff_alloc_extradata(st->codecpar, size))
- return AVERROR(ENOMEM);
+ if ((ret = ff_alloc_extradata(st->codecpar, size)) < 0)
+ return ret;
if (!(bsf = av_bsf_get_by_name(name))) {
av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
if (!(bsf = av_bsf_get_by_name(name))) {
av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
- if (st->internal->nb_bsfcs) {
- in_par = st->internal->bsfcs[st->internal->nb_bsfcs - 1]->par_out;
- bsfc->time_base_in = st->internal->bsfcs[st->internal->nb_bsfcs - 1]->time_base_out;
- } else {
- in_par = st->codecpar;
- bsfc->time_base_in = st->time_base;
- }
-
- if ((ret = avcodec_parameters_copy(bsfc->par_in, in_par)) < 0) {
+ bsfc->time_base_in = st->time_base;
+ if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
av_log(NULL, AV_LOG_VERBOSE,
"Automatically inserted bitstream filter '%s'; args='%s'\n",
av_log(NULL, AV_LOG_VERBOSE,
"Automatically inserted bitstream filter '%s'; args='%s'\n",