* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#undef NDEBUG
-#include <assert.h>
#include <stdarg.h>
#include <stdint.h>
return err;
}
- if (ic->pb && !ic->data_offset)
- ic->data_offset = avio_tell(ic->pb);
+ if (ic->pb && !ic->internal->data_offset)
+ ic->internal->data_offset = avio_tell(ic->pb);
return 0;
}
if (!copy.buf)
return AVERROR(ENOMEM);
- add_to_pktbuf(&s->raw_packet_buffer, ©,
- &s->raw_packet_buffer_end);
+ add_to_pktbuf(&s->internal->raw_packet_buffer, ©,
+ &s->internal->raw_packet_buffer_end);
}
return 0;
}
if ((ret = avformat_queue_attached_pictures(s)) < 0)
goto fail;
- if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)
- s->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);
- s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+ s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
if (options) {
av_dict_free(options);
}
}
- end= s->raw_packet_buffer_remaining_size <= 0
+ end= s->internal->raw_packet_buffer_remaining_size <= 0
|| st->probe_packets<= 0;
if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {
AVStream *st;
for (;;) {
- AVPacketList *pktl = s->raw_packet_buffer;
+ AVPacketList *pktl = s->internal->raw_packet_buffer;
if (pktl) {
*pkt = pktl->pkt;
st = s->streams[pkt->stream_index];
- if (s->raw_packet_buffer_remaining_size <= 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) {
- s->raw_packet_buffer = pktl->next;
- s->raw_packet_buffer_remaining_size += pkt->size;
+ s->internal->raw_packet_buffer = pktl->next;
+ s->internal->raw_packet_buffer_remaining_size += pkt->size;
av_free(pktl);
return 0;
}
if (!pktl && st->request_probe <= 0)
return ret;
- add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end);
- s->raw_packet_buffer_remaining_size -= pkt->size;
+ add_to_pktbuf(&s->internal->raw_packet_buffer, pkt,
+ &s->internal->raw_packet_buffer_end);
+ s->internal->raw_packet_buffer_remaining_size -= pkt->size;
if ((err = probe_codec(s, st, pkt)) < 0)
return err;
{
if (pktl->next)
return pktl->next;
- if (pktl == s->packet_buffer_end)
- return s->parse_queue;
+ if (pktl == s->internal->packet_buffer_end)
+ return s->internal->parse_queue;
return NULL;
}
int64_t dts, int64_t pts, AVPacket *pkt)
{
AVStream *st = s->streams[stream_index];
- AVPacketList *pktl = s->packet_buffer ? s->packet_buffer : s->parse_queue;
+ AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
int64_t pts_buffer[MAX_REORDER_DELAY+1];
int64_t shift;
int i, delay;
static void update_initial_durations(AVFormatContext *s, AVStream *st,
int stream_index, int duration)
{
- AVPacketList *pktl = s->packet_buffer ? s->packet_buffer : s->parse_queue;
+ AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
int64_t cur_dts = RELATIVE_TS_BASE;
if (st->first_dts != AV_NOPTS_VALUE) {
av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(st->first_dts));
return;
}
- pktl = s->packet_buffer ? s->packet_buffer : s->parse_queue;
+ pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
st->first_dts = cur_dts;
} else if (st->cur_dts != RELATIVE_TS_BASE)
return;
}
}
- if (pkt->duration != 0 && (s->packet_buffer || s->parse_queue))
+ if (pkt->duration != 0 && (s->internal->packet_buffer || s->internal->parse_queue))
update_initial_durations(s, st, pkt->stream_index, pkt->duration);
/* Correct timestamps with byte offset if demuxers only have timestamps
if ((ret = av_dup_packet(&out_pkt)) < 0)
goto fail;
- if (!add_to_pktbuf(&s->parse_queue, &out_pkt, &s->parse_queue_end)) {
+ if (!add_to_pktbuf(&s->internal->parse_queue, &out_pkt, &s->internal->parse_queue_end)) {
av_free_packet(&out_pkt);
ret = AVERROR(ENOMEM);
goto fail;
av_init_packet(pkt);
- while (!got_packet && !s->parse_queue) {
+ while (!got_packet && !s->internal->parse_queue) {
AVStream *st;
AVPacket cur_pkt;
}
}
- if (!got_packet && s->parse_queue)
- ret = read_from_packet_buffer(&s->parse_queue, &s->parse_queue_end, pkt);
+ if (!got_packet && s->internal->parse_queue)
+ ret = read_from_packet_buffer(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt);
if (ret >= 0) {
AVStream *st = s->streams[pkt->stream_index];
AVStream *st;
if (!genpts) {
- ret = s->packet_buffer
- ? read_from_packet_buffer(&s->packet_buffer,
- &s->packet_buffer_end, pkt)
+ ret = s->internal->packet_buffer
+ ? read_from_packet_buffer(&s->internal->packet_buffer,
+ &s->internal->packet_buffer_end, pkt)
: read_frame_internal(s, pkt);
if (ret < 0)
return ret;
}
for (;;) {
- AVPacketList *pktl = s->packet_buffer;
+ AVPacketList *pktl = s->internal->packet_buffer;
if (pktl) {
AVPacket *next_pkt = &pktl->pkt;
// 3. the packets for this stream at the end of the files had valid dts.
next_pkt->pts = last_dts + next_pkt->duration;
}
- pktl = s->packet_buffer;
+ pktl = s->internal->packet_buffer;
}
/* read packet from packet buffer, if there is data */
st = s->streams[next_pkt->stream_index];
if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL &&
next_pkt->dts != AV_NOPTS_VALUE && !eof)) {
- ret = read_from_packet_buffer(&s->packet_buffer,
- &s->packet_buffer_end, pkt);
+ ret = read_from_packet_buffer(&s->internal->packet_buffer,
+ &s->internal->packet_buffer_end, pkt);
goto return_packet;
}
}
return ret;
}
- if (av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt,
- &s->packet_buffer_end)) < 0)
+ if (av_dup_packet(add_to_pktbuf(&s->internal->packet_buffer, pkt,
+ &s->internal->packet_buffer_end)) < 0)
return AVERROR(ENOMEM);
}
/* XXX: suppress the packet queue */
static void flush_packet_queue(AVFormatContext *s)
{
- free_packet_buffer(&s->parse_queue, &s->parse_queue_end);
- free_packet_buffer(&s->packet_buffer, &s->packet_buffer_end);
- free_packet_buffer(&s->raw_packet_buffer, &s->raw_packet_buffer_end);
+ if (!s->internal)
+ return;
+ free_packet_buffer(&s->internal->parse_queue, &s->internal->parse_queue_end);
+ free_packet_buffer(&s->internal->packet_buffer, &s->internal->packet_buffer_end);
+ free_packet_buffer(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end);
- s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+ s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
}
/*******************************************************/
av_dlog(s, "gen_seek: %d %s\n", stream_index, av_ts2str(target_ts));
if (ts_min == AV_NOPTS_VALUE) {
- pos_min = s->data_offset;
+ pos_min = s->internal->data_offset;
ts_min = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp);
if (ts_min == AV_NOPTS_VALUE)
return -1;
{
int64_t pos_min, pos_max;
- pos_min = s->data_offset;
+ pos_min = s->internal->data_offset;
pos_max = avio_size(s->pb) - 1;
if (pos < pos_min)
return ret;
ff_update_cur_dts(s, st, ie->timestamp);
} else {
- if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0)
+ if ((ret = avio_seek(s->pb, s->internal->data_offset, SEEK_SET)) < 0)
return ret;
}
for (;;) {
if (ic->duration == AV_NOPTS_VALUE &&
ic->bit_rate != 0) {
filesize = ic->pb ? avio_size(ic->pb) : 0;
- if (filesize > ic->data_offset) {
- filesize -= ic->data_offset;
+ if (filesize > ic->internal->data_offset) {
+ filesize -= ic->internal->data_offset;
for (i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i];
if ( st->time_base.num <= INT64_MAX / ic->bit_rate
* And there are "variable" fps files this needs to detect as well. */
static int tb_unreliable(AVCodecContext *c)
{
- if (c->time_base.den >= 101L * c->time_base.num ||
- c->time_base.den < 5L * c->time_base.num ||
+ if (c->time_base.den >= 101LL * c->time_base.num ||
+ c->time_base.den < 5LL * c->time_base.num ||
// c->codec_tag == AV_RL32("DIVX") ||
// c->codec_tag == AV_RL32("XVID") ||
c->codec_tag == AV_RL32("mp4v") ||
}
if (ic->flags & AVFMT_FLAG_NOBUFFER)
- free_packet_buffer(&ic->packet_buffer, &ic->packet_buffer_end);
+ free_packet_buffer(&ic->internal->packet_buffer,
+ &ic->internal->packet_buffer_end);
{
- pkt = add_to_pktbuf(&ic->packet_buffer, &pkt1,
- &ic->packet_buffer_end);
+ pkt = add_to_pktbuf(&ic->internal->packet_buffer, &pkt1,
+ &ic->internal->packet_buffer_end);
if (!pkt) {
ret = AVERROR(ENOMEM);
goto find_stream_info_err;
if (percentd_found)
goto fail;
percentd_found = 1;
+ if (number < 0)
+ nd += 1;
snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
len = strlen(buf1);
if ((q - buf + len) > buf_size - 1)
ff_network_inited_globally = 1;
if ((ret = ff_network_init()) < 0)
return ret;
- ff_tls_init();
+ if ((ret = ff_tls_init()) < 0)
+ return ret;
#endif
return 0;
}
if (st->codec->ticks_per_frame > 1) {
- if ( codec_fr.num > 0 && codec_fr.den > 0 && av_q2d(codec_fr) < av_q2d(fr)*0.7
- && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1)
+ if ( codec_fr.num > 0 && codec_fr.den > 0 &&
+ (fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1))
fr = codec_fr;
}
}
return NULL;
}
+
+uint8_t *ff_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
+ int size)
+{
+ AVPacketSideData *sd, *tmp;
+ int i;
+ uint8_t *data = av_malloc(size);
+
+ if (!data)
+ return NULL;
+
+ for (i = 0; i < st->nb_side_data; i++) {
+ sd = &st->side_data[i];
+
+ if (sd->type == type) {
+ av_freep(&sd->data);
+ sd->data = data;
+ sd->size = size;
+ return sd->data;
+ }
+ }
+
+ tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
+ if (!tmp) {
+ av_freep(&data);
+ return NULL;
+ }
+
+ st->side_data = tmp;
+ st->nb_side_data++;
+
+ sd = &st->side_data[st->nb_side_data - 1];
+ sd->type = type;
+ sd->data = data;
+ sd->size = size;
+ return data;
+}