mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
lavf: move AVStream.*index_entries* to AVStreamInternal
Those are private fields, no reason to have them exposed in a public header. Since there are some (semi-)public fields located after these, even though this section is supposed to be private, keep some dummy padding there until the next major bump to preserve ABI compatibility.
This commit is contained in:
parent
7e87288f73
commit
cea7c19cda
@ -444,7 +444,7 @@ static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
|
||||
if (index < 0)
|
||||
return -1;
|
||||
|
||||
if ((ret = avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET)) < 0)
|
||||
if ((ret = avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET)) < 0)
|
||||
return ret;
|
||||
ape->currentframe = index;
|
||||
return 0;
|
||||
|
@ -1682,11 +1682,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
|
||||
asf->index_read = -1;
|
||||
}
|
||||
|
||||
if (asf->index_read > 0 && st->index_entries) {
|
||||
if (asf->index_read > 0 && st->internal->index_entries) {
|
||||
int index = av_index_search_timestamp(st, pts, flags);
|
||||
if (index >= 0) {
|
||||
/* find the position */
|
||||
uint64_t pos = st->index_entries[index].pos;
|
||||
uint64_t pos = st->internal->index_entries[index].pos;
|
||||
|
||||
/* do the seek */
|
||||
av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
|
||||
|
@ -1640,11 +1640,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
|
||||
ASFContext *asf = s->priv_data;
|
||||
int idx, ret;
|
||||
|
||||
if (s->streams[stream_index]->nb_index_entries && asf->is_simple_index) {
|
||||
if (s->streams[stream_index]->internal->nb_index_entries && asf->is_simple_index) {
|
||||
idx = av_index_search_timestamp(s->streams[stream_index], timestamp, flags);
|
||||
if (idx < 0 || idx >= s->streams[stream_index]->nb_index_entries)
|
||||
if (idx < 0 || idx >= s->streams[stream_index]->internal->nb_index_entries)
|
||||
return AVERROR_INVALIDDATA;
|
||||
avio_seek(s->pb, s->streams[stream_index]->index_entries[idx].pos, SEEK_SET);
|
||||
avio_seek(s->pb, s->streams[stream_index]->internal->index_entries[idx].pos, SEEK_SET);
|
||||
} else {
|
||||
if ((ret = ff_seek_frame_binary(s, stream_index, timestamp, flags)) < 0)
|
||||
return ret;
|
||||
|
@ -1087,10 +1087,12 @@ typedef struct AVStream {
|
||||
#define MAX_REORDER_DELAY 16
|
||||
int64_t pts_buffer[MAX_REORDER_DELAY+1];
|
||||
|
||||
AVIndexEntry *index_entries; /**< Only used if the format does not
|
||||
support seeking natively. */
|
||||
int nb_index_entries;
|
||||
unsigned int index_entries_allocated_size;
|
||||
#if LIBAVFORMAT_VERSION_MAJOR < 59
|
||||
// kept for ABI compatibility only, do not access in any way
|
||||
void *unused2;
|
||||
int unused3;
|
||||
unsigned int unused4;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Stream Identifier
|
||||
|
@ -272,7 +272,7 @@ static void clean_index(AVFormatContext *s)
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
AVStream *st = s->streams[i];
|
||||
AVIStream *ast = st->priv_data;
|
||||
int n = st->nb_index_entries;
|
||||
int n = st->internal->nb_index_entries;
|
||||
int max = ast->sample_size;
|
||||
int64_t pos, size, ts;
|
||||
|
||||
@ -282,9 +282,9 @@ static void clean_index(AVFormatContext *s)
|
||||
while (max < 1024)
|
||||
max += max;
|
||||
|
||||
pos = st->index_entries[0].pos;
|
||||
size = st->index_entries[0].size;
|
||||
ts = st->index_entries[0].timestamp;
|
||||
pos = st->internal->index_entries[0].pos;
|
||||
size = st->internal->index_entries[0].size;
|
||||
ts = st->internal->index_entries[0].timestamp;
|
||||
|
||||
for (j = 0; j < size; j += max)
|
||||
av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0,
|
||||
@ -432,12 +432,12 @@ static int calculate_bitrate(AVFormatContext *s)
|
||||
int64_t len = 0;
|
||||
AVStream *st = s->streams[i];
|
||||
|
||||
if (!st->nb_index_entries)
|
||||
if (!st->internal->nb_index_entries)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < st->nb_index_entries; j++)
|
||||
len += st->index_entries[j].size;
|
||||
maxpos = FFMAX(maxpos, st->index_entries[j-1].pos);
|
||||
for (j = 0; j < st->internal->nb_index_entries; j++)
|
||||
len += st->internal->index_entries[j].size;
|
||||
maxpos = FFMAX(maxpos, st->internal->index_entries[j-1].pos);
|
||||
lensum += len;
|
||||
}
|
||||
if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file
|
||||
@ -451,12 +451,12 @@ static int calculate_bitrate(AVFormatContext *s)
|
||||
int64_t duration;
|
||||
int64_t bitrate;
|
||||
|
||||
for (j = 0; j < st->nb_index_entries; j++)
|
||||
len += st->index_entries[j].size;
|
||||
for (j = 0; j < st->internal->nb_index_entries; j++)
|
||||
len += st->internal->index_entries[j].size;
|
||||
|
||||
if (st->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
|
||||
if (st->internal->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
|
||||
continue;
|
||||
duration = st->index_entries[j-1].timestamp - st->index_entries[0].timestamp;
|
||||
duration = st->internal->index_entries[j-1].timestamp - st->internal->index_entries[0].timestamp;
|
||||
bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num);
|
||||
if (bitrate > 0) {
|
||||
st->codecpar->bit_rate = bitrate;
|
||||
@ -1034,7 +1034,7 @@ end_of_header:
|
||||
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
AVStream *st = s->streams[i];
|
||||
if (st->nb_index_entries)
|
||||
if (st->internal->nb_index_entries)
|
||||
break;
|
||||
}
|
||||
// DV-in-AVI cannot be non-interleaved, if set this must be
|
||||
@ -1320,8 +1320,8 @@ start_sync:
|
||||
|
||||
if (size) {
|
||||
uint64_t pos = avio_tell(pb) - 8;
|
||||
if (!st->index_entries || !st->nb_index_entries ||
|
||||
st->index_entries[st->nb_index_entries - 1].pos < pos) {
|
||||
if (!st->internal->index_entries || !st->internal->nb_index_entries ||
|
||||
st->internal->index_entries[st->internal->nb_index_entries - 1].pos < pos) {
|
||||
av_add_index_entry(st, pos, ast->frame_offset, size,
|
||||
0, AVINDEX_KEYFRAME);
|
||||
}
|
||||
@ -1351,10 +1351,10 @@ static int ni_prepare_read(AVFormatContext *s)
|
||||
int64_t ts = ast->frame_offset;
|
||||
int64_t last_ts;
|
||||
|
||||
if (!st->nb_index_entries)
|
||||
if (!st->internal->nb_index_entries)
|
||||
continue;
|
||||
|
||||
last_ts = st->index_entries[st->nb_index_entries - 1].timestamp;
|
||||
last_ts = st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp;
|
||||
if (!ast->remaining && ts > last_ts)
|
||||
continue;
|
||||
|
||||
@ -1383,11 +1383,11 @@ static int ni_prepare_read(AVFormatContext *s)
|
||||
} else {
|
||||
i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
|
||||
if (i >= 0)
|
||||
best_ast->frame_offset = best_st->index_entries[i].timestamp;
|
||||
best_ast->frame_offset = best_st->internal->index_entries[i].timestamp;
|
||||
}
|
||||
|
||||
if (i >= 0) {
|
||||
int64_t pos = best_st->index_entries[i].pos;
|
||||
int64_t pos = best_st->internal->index_entries[i].pos;
|
||||
pos += best_ast->packet_size - best_ast->remaining;
|
||||
if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
|
||||
return AVERROR_EOF;
|
||||
@ -1397,7 +1397,7 @@ static int ni_prepare_read(AVFormatContext *s)
|
||||
avi->stream_index = best_stream_index;
|
||||
if (!best_ast->remaining)
|
||||
best_ast->packet_size =
|
||||
best_ast->remaining = best_st->index_entries[i].size;
|
||||
best_ast->remaining = best_st->internal->index_entries[i].size;
|
||||
}
|
||||
else
|
||||
return AVERROR_EOF;
|
||||
@ -1487,15 +1487,15 @@ resync:
|
||||
pkt->dts /= ast->sample_size;
|
||||
pkt->stream_index = avi->stream_index;
|
||||
|
||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) {
|
||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->index_entries) {
|
||||
AVIndexEntry *e;
|
||||
int index;
|
||||
|
||||
index = av_index_search_timestamp(st, ast->frame_offset, AVSEEK_FLAG_ANY);
|
||||
e = &st->index_entries[index];
|
||||
e = &st->internal->index_entries[index];
|
||||
|
||||
if (index >= 0 && e->timestamp == ast->frame_offset) {
|
||||
if (index == st->nb_index_entries-1) {
|
||||
if (index == st->internal->nb_index_entries-1) {
|
||||
int key=1;
|
||||
uint32_t state=-1;
|
||||
if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
|
||||
@ -1531,7 +1531,7 @@ resync:
|
||||
}
|
||||
ast->seek_pos= 0;
|
||||
|
||||
if (!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1) {
|
||||
if (!avi->non_interleaved && st->internal->nb_index_entries>1 && avi->index_loaded>1) {
|
||||
int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
|
||||
|
||||
if (avi->dts_max < dts) {
|
||||
@ -1631,8 +1631,8 @@ static int avi_read_idx1(AVFormatContext *s, int size)
|
||||
if (!anykey) {
|
||||
for (index = 0; index < s->nb_streams; index++) {
|
||||
st = s->streams[index];
|
||||
if (st->nb_index_entries)
|
||||
st->index_entries[0].flags |= AVINDEX_KEYFRAME;
|
||||
if (st->internal->nb_index_entries)
|
||||
st->internal->index_entries[0].flags |= AVINDEX_KEYFRAME;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -1657,16 +1657,16 @@ static int check_stream_max_drift(AVFormatContext *s)
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
AVStream *st = s->streams[i];
|
||||
AVIStream *ast = st->priv_data;
|
||||
int n = st->nb_index_entries;
|
||||
while (idx[i] < n && st->index_entries[idx[i]].pos < pos)
|
||||
int n = st->internal->nb_index_entries;
|
||||
while (idx[i] < n && st->internal->index_entries[idx[i]].pos < pos)
|
||||
idx[i]++;
|
||||
if (idx[i] < n) {
|
||||
int64_t dts;
|
||||
dts = av_rescale_q(st->index_entries[idx[i]].timestamp /
|
||||
dts = av_rescale_q(st->internal->index_entries[idx[i]].timestamp /
|
||||
FFMAX(ast->sample_size, 1),
|
||||
st->time_base, AV_TIME_BASE_Q);
|
||||
min_dts = FFMIN(min_dts, dts);
|
||||
min_pos = FFMIN(min_pos, st->index_entries[idx[i]].pos);
|
||||
min_pos = FFMIN(min_pos, st->internal->index_entries[idx[i]].pos);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
@ -1675,7 +1675,7 @@ static int check_stream_max_drift(AVFormatContext *s)
|
||||
|
||||
if (idx[i] && min_dts != INT64_MAX / 2) {
|
||||
int64_t dts;
|
||||
dts = av_rescale_q(st->index_entries[idx[i] - 1].timestamp /
|
||||
dts = av_rescale_q(st->internal->index_entries[idx[i] - 1].timestamp /
|
||||
FFMAX(ast->sample_size, 1),
|
||||
st->time_base, AV_TIME_BASE_Q);
|
||||
max_dts = FFMAX(max_dts, dts);
|
||||
@ -1704,30 +1704,30 @@ static int guess_ni_flag(AVFormatContext *s)
|
||||
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
AVStream *st = s->streams[i];
|
||||
int n = st->nb_index_entries;
|
||||
int n = st->internal->nb_index_entries;
|
||||
unsigned int size;
|
||||
|
||||
if (n <= 0)
|
||||
continue;
|
||||
|
||||
if (n >= 2) {
|
||||
int64_t pos = st->index_entries[0].pos;
|
||||
int64_t pos = st->internal->index_entries[0].pos;
|
||||
unsigned tag[2];
|
||||
avio_seek(s->pb, pos, SEEK_SET);
|
||||
tag[0] = avio_r8(s->pb);
|
||||
tag[1] = avio_r8(s->pb);
|
||||
avio_rl16(s->pb);
|
||||
size = avio_rl32(s->pb);
|
||||
if (get_stream_idx(tag) == i && pos + size > st->index_entries[1].pos)
|
||||
if (get_stream_idx(tag) == i && pos + size > st->internal->index_entries[1].pos)
|
||||
last_start = INT64_MAX;
|
||||
if (get_stream_idx(tag) == i && size == st->index_entries[0].size + 8)
|
||||
if (get_stream_idx(tag) == i && size == st->internal->index_entries[0].size + 8)
|
||||
last_start = INT64_MAX;
|
||||
}
|
||||
|
||||
if (st->index_entries[0].pos > last_start)
|
||||
last_start = st->index_entries[0].pos;
|
||||
if (st->index_entries[n - 1].pos < first_end)
|
||||
first_end = st->index_entries[n - 1].pos;
|
||||
if (st->internal->index_entries[0].pos > last_start)
|
||||
last_start = st->internal->index_entries[0].pos;
|
||||
if (st->internal->index_entries[n - 1].pos < first_end)
|
||||
first_end = st->internal->index_entries[n - 1].pos;
|
||||
}
|
||||
avio_seek(s->pb, oldpos, SEEK_SET);
|
||||
|
||||
@ -1815,20 +1815,20 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
|
||||
timestamp * FFMAX(ast->sample_size, 1),
|
||||
flags);
|
||||
if (index < 0) {
|
||||
if (st->nb_index_entries > 0)
|
||||
if (st->internal->nb_index_entries > 0)
|
||||
av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
|
||||
timestamp * FFMAX(ast->sample_size, 1),
|
||||
st->index_entries[0].timestamp,
|
||||
st->index_entries[st->nb_index_entries - 1].timestamp);
|
||||
st->internal->index_entries[0].timestamp,
|
||||
st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
/* find the position */
|
||||
pos = st->index_entries[index].pos;
|
||||
timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
|
||||
pos = st->internal->index_entries[index].pos;
|
||||
timestamp = st->internal->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
|
||||
|
||||
av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
|
||||
timestamp, index, st->index_entries[index].timestamp);
|
||||
timestamp, index, st->internal->index_entries[index].timestamp);
|
||||
|
||||
if (CONFIG_DV_DEMUXER && avi->dv_demux) {
|
||||
/* One and only one real stream for DV in AVI, and it has video */
|
||||
@ -1859,7 +1859,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (st2->nb_index_entries <= 0)
|
||||
if (st2->internal->nb_index_entries <= 0)
|
||||
continue;
|
||||
|
||||
// av_assert1(st2->codecpar->block_align);
|
||||
@ -1873,14 +1873,14 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
|
||||
(st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
ast2->seek_pos = st2->index_entries[index].pos;
|
||||
ast2->seek_pos = st2->internal->index_entries[index].pos;
|
||||
pos_min = FFMIN(pos_min,ast2->seek_pos);
|
||||
}
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
AVStream *st2 = s->streams[i];
|
||||
AVIStream *ast2 = st2->priv_data;
|
||||
|
||||
if (ast2->sub_ctx || st2->nb_index_entries <= 0)
|
||||
if (ast2->sub_ctx || st2->internal->nb_index_entries <= 0)
|
||||
continue;
|
||||
|
||||
index = av_index_search_timestamp(
|
||||
@ -1889,9 +1889,9 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
|
||||
flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min)
|
||||
while (!avi->non_interleaved && index>0 && st2->internal->index_entries[index-1].pos >= pos_min)
|
||||
index--;
|
||||
ast2->frame_offset = st2->index_entries[index].timestamp;
|
||||
ast2->frame_offset = st2->internal->index_entries[index].timestamp;
|
||||
}
|
||||
|
||||
/* do the seek */
|
||||
|
@ -225,8 +225,8 @@ static int read_header(AVFormatContext *s)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (vst->index_entries)
|
||||
avio_seek(pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET);
|
||||
if (vst->internal->index_entries)
|
||||
avio_seek(pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET);
|
||||
else
|
||||
avio_skip(pb, 4);
|
||||
|
||||
@ -256,8 +256,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
return AVERROR(EIO);
|
||||
}
|
||||
|
||||
bink->remain_packet_size = st->index_entries[index_entry].size;
|
||||
bink->flags = st->index_entries[index_entry].flags;
|
||||
bink->remain_packet_size = st->internal->index_entries[index_entry].size;
|
||||
bink->flags = st->internal->index_entries[index_entry].flags;
|
||||
bink->current_track = 0;
|
||||
}
|
||||
|
||||
@ -313,7 +313,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
|
||||
return -1;
|
||||
|
||||
/* seek to the first frame */
|
||||
ret = avio_seek(s->pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET);
|
||||
ret = avio_seek(s->pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
@ -329,7 +329,7 @@ found_data:
|
||||
if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
|
||||
if (caf->data_size > 0)
|
||||
st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
|
||||
} else if (st->nb_index_entries && st->duration > 0) {
|
||||
} else if (st->internal->nb_index_entries && st->duration > 0) {
|
||||
if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) {
|
||||
av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * 8 * %"PRId64"\n",
|
||||
st->codecpar->sample_rate, caf->data_size / st->duration);
|
||||
@ -382,13 +382,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
pkt_size = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size;
|
||||
pkt_size = FFMIN(pkt_size, left);
|
||||
pkt_frames = pkt_size / caf->bytes_per_packet;
|
||||
} else if (st->nb_index_entries) {
|
||||
if (caf->packet_cnt < st->nb_index_entries - 1) {
|
||||
pkt_size = st->index_entries[caf->packet_cnt + 1].pos - st->index_entries[caf->packet_cnt].pos;
|
||||
pkt_frames = st->index_entries[caf->packet_cnt + 1].timestamp - st->index_entries[caf->packet_cnt].timestamp;
|
||||
} else if (caf->packet_cnt == st->nb_index_entries - 1) {
|
||||
pkt_size = caf->num_bytes - st->index_entries[caf->packet_cnt].pos;
|
||||
pkt_frames = st->duration - st->index_entries[caf->packet_cnt].timestamp;
|
||||
} else if (st->internal->nb_index_entries) {
|
||||
if (caf->packet_cnt < st->internal->nb_index_entries - 1) {
|
||||
pkt_size = st->internal->index_entries[caf->packet_cnt + 1].pos - st->internal->index_entries[caf->packet_cnt].pos;
|
||||
pkt_frames = st->internal->index_entries[caf->packet_cnt + 1].timestamp - st->internal->index_entries[caf->packet_cnt].timestamp;
|
||||
} else if (caf->packet_cnt == st->internal->nb_index_entries - 1) {
|
||||
pkt_size = caf->num_bytes - st->internal->index_entries[caf->packet_cnt].pos;
|
||||
pkt_frames = st->duration - st->internal->index_entries[caf->packet_cnt].timestamp;
|
||||
} else {
|
||||
return AVERROR(EIO);
|
||||
}
|
||||
@ -427,10 +427,10 @@ static int read_seek(AVFormatContext *s, int stream_index,
|
||||
pos = FFMIN(pos, caf->data_size);
|
||||
packet_cnt = pos / caf->bytes_per_packet;
|
||||
frame_cnt = caf->frames_per_packet * packet_cnt;
|
||||
} else if (st->nb_index_entries) {
|
||||
} else if (st->internal->nb_index_entries) {
|
||||
packet_cnt = av_index_search_timestamp(st, timestamp, flags);
|
||||
frame_cnt = st->index_entries[packet_cnt].timestamp;
|
||||
pos = st->index_entries[packet_cnt].pos;
|
||||
frame_cnt = st->internal->index_entries[packet_cnt].timestamp;
|
||||
pos = st->internal->index_entries[packet_cnt].pos;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
||||
if (cine->pts >= st->duration)
|
||||
return AVERROR_EOF;
|
||||
|
||||
avio_seek(pb, st->index_entries[cine->pts].pos, SEEK_SET);
|
||||
avio_seek(pb, st->internal->index_entries[cine->pts].pos, SEEK_SET);
|
||||
n = avio_rl32(pb);
|
||||
if (n < 8)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
@ -441,10 +441,10 @@ static int dhav_read_seek(AVFormatContext *s, int stream_index,
|
||||
|
||||
if (index < 0)
|
||||
return -1;
|
||||
if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
|
||||
if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
|
||||
return -1;
|
||||
|
||||
pts = st->index_entries[index].timestamp;
|
||||
pts = st->internal->index_entries[index].timestamp;
|
||||
|
||||
for (int n = 0; n < s->nb_streams; n++) {
|
||||
AVStream *st = s->streams[n];
|
||||
|
@ -40,8 +40,8 @@ static void reset_index_position(int64_t metadata_head_size, AVStream *st)
|
||||
{
|
||||
/* the real seek index offset should be the size of metadata blocks with the offset in the frame blocks */
|
||||
int i;
|
||||
for(i=0; i<st->nb_index_entries; i++) {
|
||||
st->index_entries[i].pos += metadata_head_size;
|
||||
for(i=0; i<st->internal->nb_index_entries; i++) {
|
||||
st->internal->index_entries[i].pos += metadata_head_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,10 +319,10 @@ static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
|
||||
}
|
||||
|
||||
index = av_index_search_timestamp(s->streams[0], timestamp, flags);
|
||||
if(index<0 || index >= s->streams[0]->nb_index_entries)
|
||||
if(index<0 || index >= s->streams[0]->internal->nb_index_entries)
|
||||
return -1;
|
||||
|
||||
e = s->streams[0]->index_entries[index];
|
||||
e = s->streams[0]->internal->index_entries[index];
|
||||
pos = avio_seek(s->pb, e.pos, SEEK_SET);
|
||||
if (pos >= 0) {
|
||||
return 0;
|
||||
|
@ -268,7 +268,7 @@ static int flic_read_seek(AVFormatContext *s, int stream_index,
|
||||
int64_t pos, ts;
|
||||
int index;
|
||||
|
||||
if (!st->index_entries || stream_index != flic->video_stream_index)
|
||||
if (!st->internal->index_entries || stream_index != flic->video_stream_index)
|
||||
return -1;
|
||||
|
||||
index = av_index_search_timestamp(st, pts, flags);
|
||||
@ -278,8 +278,8 @@ static int flic_read_seek(AVFormatContext *s, int stream_index,
|
||||
if (index < 0)
|
||||
return -1;
|
||||
|
||||
pos = st->index_entries[index].pos;
|
||||
ts = st->index_entries[index].timestamp;
|
||||
pos = st->internal->index_entries[index].pos;
|
||||
ts = st->internal->index_entries[index].timestamp;
|
||||
flic->frame_number = ts;
|
||||
avio_seek(s->pb, pos, SEEK_SET);
|
||||
return 0;
|
||||
|
@ -140,7 +140,7 @@ static void add_keyframes_index(AVFormatContext *s)
|
||||
av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
|
||||
stream = s->streams[flv->last_keyframe_stream_index];
|
||||
|
||||
if (stream->nb_index_entries == 0) {
|
||||
if (stream->internal->nb_index_entries == 0) {
|
||||
for (i = 0; i < flv->keyframe_count; i++) {
|
||||
av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
|
||||
flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000);
|
||||
@ -830,10 +830,10 @@ static void clear_index_entries(AVFormatContext *s, int64_t pos)
|
||||
AVStream *st = s->streams[i];
|
||||
/* Remove all index entries that point to >= pos */
|
||||
out = 0;
|
||||
for (j = 0; j < st->nb_index_entries; j++)
|
||||
if (st->index_entries[j].pos < pos)
|
||||
st->index_entries[out++] = st->index_entries[j];
|
||||
st->nb_index_entries = out;
|
||||
for (j = 0; j < st->internal->nb_index_entries; j++)
|
||||
if (st->internal->index_entries[j].pos < pos)
|
||||
st->internal->index_entries[out++] = st->internal->index_entries[j];
|
||||
st->internal->nb_index_entries = out;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -572,9 +572,9 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int
|
||||
AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
|
||||
if (idx < 0)
|
||||
return -1;
|
||||
pos = st->index_entries[idx].pos;
|
||||
if (idx < st->nb_index_entries - 2)
|
||||
maxlen = st->index_entries[idx + 2].pos - pos;
|
||||
pos = st->internal->index_entries[idx].pos;
|
||||
if (idx < st->internal->nb_index_entries - 2)
|
||||
maxlen = st->internal->index_entries[idx + 2].pos - pos;
|
||||
maxlen = FFMAX(maxlen, 200 * 1024);
|
||||
res = avio_seek(s->pb, pos, SEEK_SET);
|
||||
if (res < 0)
|
||||
|
@ -195,15 +195,15 @@ static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
|
||||
if (ifv->next_video_index < ifv->total_vframes) {
|
||||
st = s->streams[ifv->video_stream_index];
|
||||
if (ifv->next_video_index < st->nb_index_entries)
|
||||
e_next = ev = &st->index_entries[ifv->next_video_index];
|
||||
if (ifv->next_video_index < st->internal->nb_index_entries)
|
||||
e_next = ev = &st->internal->index_entries[ifv->next_video_index];
|
||||
}
|
||||
|
||||
if (ifv->is_audio_present &&
|
||||
ifv->next_audio_index < ifv->total_aframes) {
|
||||
st = s->streams[ifv->audio_stream_index];
|
||||
if (ifv->next_audio_index < st->nb_index_entries) {
|
||||
ea = &st->index_entries[ifv->next_audio_index];
|
||||
if (ifv->next_audio_index < st->internal->nb_index_entries) {
|
||||
ea = &st->internal->index_entries[ifv->next_audio_index];
|
||||
if (!ev || ea->timestamp < ev->timestamp)
|
||||
e_next = ea;
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
|
||||
int index = av_index_search_timestamp(st, timestamp, flags);
|
||||
if(index < 0)
|
||||
return -1;
|
||||
s1->img_number = st->index_entries[index].pos;
|
||||
s1->img_number = st->internal->index_entries[index].pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -225,6 +225,11 @@ struct AVStreamInternal {
|
||||
|
||||
} *info;
|
||||
|
||||
AVIndexEntry *index_entries; /**< Only used if the format does not
|
||||
support seeking natively. */
|
||||
int nb_index_entries;
|
||||
unsigned int index_entries_allocated_size;
|
||||
|
||||
int64_t interleaver_chunk_size;
|
||||
int64_t interleaver_chunk_duration;
|
||||
|
||||
|
@ -92,7 +92,7 @@ static int read_header(AVFormatContext *s)
|
||||
vst->codecpar->height = avio_rl16(pb);
|
||||
vst->duration =
|
||||
vst->nb_frames =
|
||||
ast->nb_index_entries = avio_rl16(pb);
|
||||
ast->internal->nb_index_entries = avio_rl16(pb);
|
||||
avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000);
|
||||
|
||||
avio_skip(pb, 4);
|
||||
@ -107,19 +107,19 @@ static int read_header(AVFormatContext *s)
|
||||
|
||||
avio_skip(pb, 10);
|
||||
|
||||
ast->index_entries = av_malloc(ast->nb_index_entries *
|
||||
sizeof(*ast->index_entries));
|
||||
if (!ast->index_entries)
|
||||
ast->internal->index_entries = av_malloc(ast->internal->nb_index_entries *
|
||||
sizeof(*ast->internal->index_entries));
|
||||
if (!ast->internal->index_entries)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
jv->frames = av_malloc(ast->nb_index_entries * sizeof(JVFrame));
|
||||
jv->frames = av_malloc(ast->internal->nb_index_entries * sizeof(JVFrame));
|
||||
if (!jv->frames) {
|
||||
av_freep(&ast->index_entries);
|
||||
av_freep(&ast->internal->index_entries);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
offset = 0x68 + ast->nb_index_entries * 16;
|
||||
for (i = 0; i < ast->nb_index_entries; i++) {
|
||||
AVIndexEntry *e = ast->index_entries + i;
|
||||
offset = 0x68 + ast->internal->nb_index_entries * 16;
|
||||
for (i = 0; i < ast->internal->nb_index_entries; i++) {
|
||||
AVIndexEntry *e = ast->internal->index_entries + i;
|
||||
JVFrame *jvf = jv->frames + i;
|
||||
|
||||
/* total frame size including audio, video, palette data and padding */
|
||||
@ -139,7 +139,7 @@ static int read_header(AVFormatContext *s)
|
||||
if (s->error_recognition & AV_EF_EXPLODE) {
|
||||
read_close(s);
|
||||
av_freep(&jv->frames);
|
||||
av_freep(&ast->index_entries);
|
||||
av_freep(&ast->internal->index_entries);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
jvf->audio_size =
|
||||
@ -170,8 +170,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
AVStream *ast = s->streams[0];
|
||||
int ret;
|
||||
|
||||
while (!avio_feof(s->pb) && jv->pts < ast->nb_index_entries) {
|
||||
const AVIndexEntry *e = ast->index_entries + jv->pts;
|
||||
while (!avio_feof(s->pb) && jv->pts < ast->internal->nb_index_entries) {
|
||||
const AVIndexEntry *e = ast->internal->index_entries + jv->pts;
|
||||
const JVFrame *jvf = jv->frames + jv->pts;
|
||||
|
||||
switch (jv->state) {
|
||||
@ -244,9 +244,9 @@ static int read_seek(AVFormatContext *s, int stream_index,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (i < 0 || i >= ast->nb_index_entries)
|
||||
if (i < 0 || i >= ast->internal->nb_index_entries)
|
||||
return 0;
|
||||
if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0)
|
||||
if (avio_seek(s->pb, ast->internal->index_entries[i].pos, SEEK_SET) < 0)
|
||||
return -1;
|
||||
|
||||
jv->state = JV_AUDIO;
|
||||
|
@ -3766,13 +3766,13 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
|
||||
matroska_parse_cues(matroska);
|
||||
}
|
||||
|
||||
if (!st->nb_index_entries)
|
||||
if (!st->internal->nb_index_entries)
|
||||
goto err;
|
||||
timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
|
||||
timestamp = FFMAX(timestamp, st->internal->index_entries[0].timestamp);
|
||||
|
||||
if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) {
|
||||
matroska_reset_status(matroska, 0, st->index_entries[st->nb_index_entries - 1].pos);
|
||||
while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) {
|
||||
if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) {
|
||||
matroska_reset_status(matroska, 0, st->internal->index_entries[st->internal->nb_index_entries - 1].pos);
|
||||
while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) {
|
||||
matroska_clear_queue(matroska);
|
||||
if (matroska_parse_cluster(matroska) < 0)
|
||||
break;
|
||||
@ -3780,7 +3780,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
|
||||
}
|
||||
|
||||
matroska_clear_queue(matroska);
|
||||
if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->nb_index_entries - 1))
|
||||
if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->internal->nb_index_entries - 1))
|
||||
goto err;
|
||||
|
||||
tracks = matroska->tracks.elem;
|
||||
@ -3792,17 +3792,17 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
|
||||
}
|
||||
|
||||
/* We seek to a level 1 element, so set the appropriate status. */
|
||||
matroska_reset_status(matroska, 0, st->index_entries[index].pos);
|
||||
matroska_reset_status(matroska, 0, st->internal->index_entries[index].pos);
|
||||
if (flags & AVSEEK_FLAG_ANY) {
|
||||
st->internal->skip_to_keyframe = 0;
|
||||
matroska->skip_to_timecode = timestamp;
|
||||
} else {
|
||||
st->internal->skip_to_keyframe = 1;
|
||||
matroska->skip_to_timecode = st->index_entries[index].timestamp;
|
||||
matroska->skip_to_timecode = st->internal->index_entries[index].timestamp;
|
||||
}
|
||||
matroska->skip_to_keyframe = 1;
|
||||
matroska->done = 0;
|
||||
ff_update_cur_dts(s, st, st->index_entries[index].timestamp);
|
||||
ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp);
|
||||
return 0;
|
||||
err:
|
||||
// slightly hackish but allows proper fallback to
|
||||
@ -3847,8 +3847,8 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start)
|
||||
MatroskaDemuxContext *matroska = s->priv_data;
|
||||
CueDesc cue_desc;
|
||||
int i;
|
||||
int nb_index_entries = s->streams[0]->nb_index_entries;
|
||||
AVIndexEntry *index_entries = s->streams[0]->index_entries;
|
||||
int nb_index_entries = s->streams[0]->internal->nb_index_entries;
|
||||
AVIndexEntry *index_entries = s->streams[0]->internal->index_entries;
|
||||
if (ts >= matroska->duration * matroska->time_scale) return (CueDesc) {-1, -1, -1, -1};
|
||||
for (i = 1; i < nb_index_entries; i++) {
|
||||
if (index_entries[i - 1].timestamp * matroska->time_scale <= ts &&
|
||||
@ -3878,11 +3878,11 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s)
|
||||
uint32_t id = matroska->current_id;
|
||||
int64_t cluster_pos, before_pos;
|
||||
int index, rv = 1;
|
||||
if (s->streams[0]->nb_index_entries <= 0) return 0;
|
||||
if (s->streams[0]->internal->nb_index_entries <= 0) return 0;
|
||||
// seek to the first cluster using cues.
|
||||
index = av_index_search_timestamp(s->streams[0], 0, 0);
|
||||
if (index < 0) return 0;
|
||||
cluster_pos = s->streams[0]->index_entries[index].pos;
|
||||
cluster_pos = s->streams[0]->internal->index_entries[index].pos;
|
||||
before_pos = avio_tell(s->pb);
|
||||
while (1) {
|
||||
uint64_t cluster_id, cluster_length;
|
||||
@ -4006,9 +4006,9 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t
|
||||
double bandwidth = 0.0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < st->nb_index_entries; i++) {
|
||||
for (i = 0; i < st->internal->nb_index_entries; i++) {
|
||||
int64_t prebuffer_ns = 1000000000;
|
||||
int64_t time_ns = st->index_entries[i].timestamp * matroska->time_scale;
|
||||
int64_t time_ns = st->internal->index_entries[i].timestamp * matroska->time_scale;
|
||||
double nano_seconds_per_second = 1000000000.0;
|
||||
int64_t prebuffered_ns = time_ns + prebuffer_ns;
|
||||
double prebuffer_bytes = 0.0;
|
||||
@ -4146,14 +4146,14 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range)
|
||||
|
||||
// store cue point timestamps as a comma separated list for checking subsegment alignment in
|
||||
// the muxer. assumes that each timestamp cannot be more than 20 characters long.
|
||||
buf = av_malloc_array(s->streams[0]->nb_index_entries, 20);
|
||||
buf = av_malloc_array(s->streams[0]->internal->nb_index_entries, 20);
|
||||
if (!buf) return -1;
|
||||
strcpy(buf, "");
|
||||
for (i = 0; i < s->streams[0]->nb_index_entries; i++) {
|
||||
for (i = 0; i < s->streams[0]->internal->nb_index_entries; i++) {
|
||||
int ret = snprintf(buf + end, 20,
|
||||
"%" PRId64"%s", s->streams[0]->index_entries[i].timestamp,
|
||||
i != s->streams[0]->nb_index_entries - 1 ? "," : "");
|
||||
if (ret <= 0 || (ret == 20 && i == s->streams[0]->nb_index_entries - 1)) {
|
||||
"%" PRId64"%s", s->streams[0]->internal->index_entries[i].timestamp,
|
||||
i != s->streams[0]->internal->nb_index_entries - 1 ? "," : "");
|
||||
if (ret <= 0 || (ret == 20 && i == s->streams[0]->internal->nb_index_entries - 1)) {
|
||||
av_log(s, AV_LOG_ERROR, "timestamp too long.\n");
|
||||
av_free(buf);
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
@ -191,12 +191,12 @@ static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f
|
||||
}
|
||||
} else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) {
|
||||
uint64_t pts = avio_rl32(pb);
|
||||
ff_add_index_entry(&vst->index_entries, &vst->nb_index_entries, &vst->index_entries_allocated_size,
|
||||
ff_add_index_entry(&vst->internal->index_entries, &vst->internal->nb_index_entries, &vst->internal->index_entries_allocated_size,
|
||||
avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
|
||||
size -= 4;
|
||||
} else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) {
|
||||
uint64_t pts = avio_rl32(pb);
|
||||
ff_add_index_entry(&ast->index_entries, &ast->nb_index_entries, &ast->index_entries_allocated_size,
|
||||
ff_add_index_entry(&ast->internal->index_entries, &ast->internal->nb_index_entries, &ast->internal->index_entries_allocated_size,
|
||||
avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
|
||||
size -= 4;
|
||||
} else if (vst && type == MKTAG('W','B','A','L') && size >= 28) {
|
||||
@ -374,22 +374,22 @@ static int read_header(AVFormatContext *avctx)
|
||||
}
|
||||
|
||||
if (vst)
|
||||
vst->duration = vst->nb_index_entries;
|
||||
vst->duration = vst->internal->nb_index_entries;
|
||||
if (ast)
|
||||
ast->duration = ast->nb_index_entries;
|
||||
ast->duration = ast->internal->nb_index_entries;
|
||||
|
||||
if ((vst && !vst->nb_index_entries) || (ast && !ast->nb_index_entries)) {
|
||||
if ((vst && !vst->internal->nb_index_entries) || (ast && !ast->internal->nb_index_entries)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "no index entries found\n");
|
||||
read_close(avctx);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (vst && ast)
|
||||
avio_seek(pb, FFMIN(vst->index_entries[0].pos, ast->index_entries[0].pos), SEEK_SET);
|
||||
avio_seek(pb, FFMIN(vst->internal->index_entries[0].pos, ast->internal->index_entries[0].pos), SEEK_SET);
|
||||
else if (vst)
|
||||
avio_seek(pb, vst->index_entries[0].pos, SEEK_SET);
|
||||
avio_seek(pb, vst->internal->index_entries[0].pos, SEEK_SET);
|
||||
else if (ast)
|
||||
avio_seek(pb, ast->index_entries[0].pos, SEEK_SET);
|
||||
avio_seek(pb, ast->internal->index_entries[0].pos, SEEK_SET);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -415,12 +415,12 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
||||
return AVERROR(EIO);
|
||||
}
|
||||
|
||||
pb = mlv->pb[st->index_entries[index].size];
|
||||
pb = mlv->pb[st->internal->index_entries[index].size];
|
||||
if (!pb) {
|
||||
ret = FFERROR_REDO;
|
||||
goto next_packet;
|
||||
}
|
||||
avio_seek(pb, st->index_entries[index].pos, SEEK_SET);
|
||||
avio_seek(pb, st->internal->index_entries[index].pos, SEEK_SET);
|
||||
|
||||
avio_skip(pb, 4); // blockType
|
||||
size = avio_rl32(pb);
|
||||
|
@ -3179,8 +3179,8 @@ static int find_prev_closest_index(AVStream *st,
|
||||
int64_t* ctts_sample)
|
||||
{
|
||||
MOVStreamContext *msc = st->priv_data;
|
||||
AVIndexEntry *e_keep = st->index_entries;
|
||||
int nb_keep = st->nb_index_entries;
|
||||
AVIndexEntry *e_keep = st->internal->index_entries;
|
||||
int nb_keep = st->internal->nb_index_entries;
|
||||
int64_t i = 0;
|
||||
int64_t index_ctts_count;
|
||||
|
||||
@ -3193,8 +3193,8 @@ static int find_prev_closest_index(AVStream *st,
|
||||
timestamp_pts -= msc->dts_shift;
|
||||
}
|
||||
|
||||
st->index_entries = e_old;
|
||||
st->nb_index_entries = nb_old;
|
||||
st->internal->index_entries = e_old;
|
||||
st->internal->nb_index_entries = nb_old;
|
||||
*index = av_index_search_timestamp(st, timestamp_pts, flag | AVSEEK_FLAG_BACKWARD);
|
||||
|
||||
// Keep going backwards in the index entries until the timestamp is the same.
|
||||
@ -3247,14 +3247,14 @@ static int find_prev_closest_index(AVStream *st,
|
||||
}
|
||||
|
||||
/* restore AVStream state*/
|
||||
st->index_entries = e_keep;
|
||||
st->nb_index_entries = nb_keep;
|
||||
st->internal->index_entries = e_keep;
|
||||
st->internal->nb_index_entries = nb_keep;
|
||||
return *index >= 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add index entry with the given values, to the end of st->index_entries.
|
||||
* Returns the new size st->index_entries if successful, else returns -1.
|
||||
* Add index entry with the given values, to the end of st->internal->index_entries.
|
||||
* Returns the new size st->internal->index_entries if successful, else returns -1.
|
||||
*
|
||||
* This function is similar to ff_add_index_entry in libavformat/utils.c
|
||||
* except that here we are always unconditionally adding an index entry to
|
||||
@ -3268,27 +3268,27 @@ static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
|
||||
{
|
||||
AVIndexEntry *entries, *ie;
|
||||
int64_t index = -1;
|
||||
const size_t min_size_needed = (st->nb_index_entries + 1) * sizeof(AVIndexEntry);
|
||||
const size_t min_size_needed = (st->internal->nb_index_entries + 1) * sizeof(AVIndexEntry);
|
||||
|
||||
// Double the allocation each time, to lower memory fragmentation.
|
||||
// Another difference from ff_add_index_entry function.
|
||||
const size_t requested_size =
|
||||
min_size_needed > st->index_entries_allocated_size ?
|
||||
FFMAX(min_size_needed, 2 * st->index_entries_allocated_size) :
|
||||
min_size_needed > st->internal->index_entries_allocated_size ?
|
||||
FFMAX(min_size_needed, 2 * st->internal->index_entries_allocated_size) :
|
||||
min_size_needed;
|
||||
|
||||
if (st->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry))
|
||||
if (st->internal->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry))
|
||||
return -1;
|
||||
|
||||
entries = av_fast_realloc(st->index_entries,
|
||||
&st->index_entries_allocated_size,
|
||||
entries = av_fast_realloc(st->internal->index_entries,
|
||||
&st->internal->index_entries_allocated_size,
|
||||
requested_size);
|
||||
if (!entries)
|
||||
return -1;
|
||||
|
||||
st->index_entries= entries;
|
||||
st->internal->index_entries= entries;
|
||||
|
||||
index= st->nb_index_entries++;
|
||||
index= st->internal->nb_index_entries++;
|
||||
ie= &entries[index];
|
||||
|
||||
ie->pos = pos;
|
||||
@ -3307,10 +3307,10 @@ static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_
|
||||
int64_t* frame_duration_buffer,
|
||||
int frame_duration_buffer_size) {
|
||||
int i = 0;
|
||||
av_assert0(end_index >= 0 && end_index <= st->nb_index_entries);
|
||||
av_assert0(end_index >= 0 && end_index <= st->internal->nb_index_entries);
|
||||
for (i = 0; i < frame_duration_buffer_size; i++) {
|
||||
end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 - i];
|
||||
st->index_entries[end_index - 1 - i].timestamp = end_ts;
|
||||
st->internal->index_entries[end_index - 1 - i].timestamp = end_ts;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3362,14 +3362,14 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st)
|
||||
if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
|
||||
st->codecpar->codec_id == AV_CODEC_ID_H264) {
|
||||
st->codecpar->video_delay = 0;
|
||||
for (ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) {
|
||||
for (ind = 0; ind < st->internal->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) {
|
||||
// Point j to the last elem of the buffer and insert the current pts there.
|
||||
j = buf_start;
|
||||
buf_start = (buf_start + 1);
|
||||
if (buf_start == MAX_REORDER_DELAY + 1)
|
||||
buf_start = 0;
|
||||
|
||||
pts_buf[j] = st->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration;
|
||||
pts_buf[j] = st->internal->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration;
|
||||
|
||||
// The timestamps that are already in the sorted buffer, and are greater than the
|
||||
// current pts, are exactly the timestamps that need to be buffered to output PTS
|
||||
@ -3449,7 +3449,7 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix st->index_entries, so that it contains only the entries (and the entries
|
||||
* Fix st->internal->index_entries, so that it contains only the entries (and the entries
|
||||
* which are needed to decode them) that fall in the edit list time ranges.
|
||||
* Also fixes the timestamps of the index entries to match the timeline
|
||||
* specified the edit lists.
|
||||
@ -3457,8 +3457,8 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample)
|
||||
static void mov_fix_index(MOVContext *mov, AVStream *st)
|
||||
{
|
||||
MOVStreamContext *msc = st->priv_data;
|
||||
AVIndexEntry *e_old = st->index_entries;
|
||||
int nb_old = st->nb_index_entries;
|
||||
AVIndexEntry *e_old = st->internal->index_entries;
|
||||
int nb_old = st->internal->nb_index_entries;
|
||||
const AVIndexEntry *e_old_end = e_old + nb_old;
|
||||
const AVIndexEntry *current = NULL;
|
||||
MOVStts *ctts_data_old = msc->ctts_data;
|
||||
@ -3503,9 +3503,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
|
||||
current_index_range = msc->index_ranges - 1;
|
||||
|
||||
// Clean AVStream from traces of old index
|
||||
st->index_entries = NULL;
|
||||
st->index_entries_allocated_size = 0;
|
||||
st->nb_index_entries = 0;
|
||||
st->internal->index_entries = NULL;
|
||||
st->internal->index_entries_allocated_size = 0;
|
||||
st->internal->nb_index_entries = 0;
|
||||
|
||||
// Clean ctts fields of MOVStreamContext
|
||||
msc->ctts_data = NULL;
|
||||
@ -3634,7 +3634,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
|
||||
// Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for
|
||||
// discarded packets.
|
||||
if (frame_duration_buffer) {
|
||||
fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter,
|
||||
fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter,
|
||||
frame_duration_buffer, num_discarded_begin);
|
||||
av_freep(&frame_duration_buffer);
|
||||
}
|
||||
@ -3673,7 +3673,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
|
||||
// Make timestamps strictly monotonically increasing by rewriting timestamps for
|
||||
// discarded packets.
|
||||
if (frame_duration_buffer) {
|
||||
fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter,
|
||||
fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter,
|
||||
frame_duration_buffer, num_discarded_begin);
|
||||
av_freep(&frame_duration_buffer);
|
||||
}
|
||||
@ -3734,8 +3734,8 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
|
||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
if (msc->min_corrected_pts > 0) {
|
||||
av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts);
|
||||
for (i = 0; i < st->nb_index_entries; ++i) {
|
||||
st->index_entries[i].timestamp -= msc->min_corrected_pts;
|
||||
for (i = 0; i < st->internal->nb_index_entries; ++i) {
|
||||
st->internal->index_entries[i].timestamp -= msc->min_corrected_pts;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3828,17 +3828,17 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
||||
current_dts -= sc->dts_shift;
|
||||
last_dts = current_dts;
|
||||
|
||||
if (!sc->sample_count || st->nb_index_entries)
|
||||
if (!sc->sample_count || st->internal->nb_index_entries)
|
||||
return;
|
||||
if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
|
||||
if (sc->sample_count >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries)
|
||||
return;
|
||||
if (av_reallocp_array(&st->index_entries,
|
||||
st->nb_index_entries + sc->sample_count,
|
||||
sizeof(*st->index_entries)) < 0) {
|
||||
st->nb_index_entries = 0;
|
||||
if (av_reallocp_array(&st->internal->index_entries,
|
||||
st->internal->nb_index_entries + sc->sample_count,
|
||||
sizeof(*st->internal->index_entries)) < 0) {
|
||||
st->internal->nb_index_entries = 0;
|
||||
return;
|
||||
}
|
||||
st->index_entries_allocated_size = (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries);
|
||||
st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + sc->sample_count) * sizeof(*st->internal->index_entries);
|
||||
|
||||
if (ctts_data_old) {
|
||||
// Expand ctts entries such that we have a 1-1 mapping with samples
|
||||
@ -3921,7 +3921,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
||||
av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", sample_size);
|
||||
return;
|
||||
}
|
||||
e = &st->index_entries[st->nb_index_entries++];
|
||||
e = &st->internal->index_entries[st->internal->nb_index_entries++];
|
||||
e->pos = current_offset;
|
||||
e->timestamp = current_dts;
|
||||
e->size = sample_size;
|
||||
@ -3930,7 +3930,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
||||
av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", "
|
||||
"size %u, distance %u, keyframe %d\n", st->index, current_sample,
|
||||
current_offset, current_dts, sample_size, distance, keyframe);
|
||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100)
|
||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries < 100)
|
||||
ff_rfps_add_frame(mov->fc, st, current_dts);
|
||||
}
|
||||
|
||||
@ -4002,15 +4002,15 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
||||
}
|
||||
|
||||
av_log(mov->fc, AV_LOG_TRACE, "chunk count %u\n", total);
|
||||
if (total >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
|
||||
if (total >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries)
|
||||
return;
|
||||
if (av_reallocp_array(&st->index_entries,
|
||||
st->nb_index_entries + total,
|
||||
sizeof(*st->index_entries)) < 0) {
|
||||
st->nb_index_entries = 0;
|
||||
if (av_reallocp_array(&st->internal->index_entries,
|
||||
st->internal->nb_index_entries + total,
|
||||
sizeof(*st->internal->index_entries)) < 0) {
|
||||
st->internal->nb_index_entries = 0;
|
||||
return;
|
||||
}
|
||||
st->index_entries_allocated_size = (st->nb_index_entries + total) * sizeof(*st->index_entries);
|
||||
st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + total) * sizeof(*st->internal->index_entries);
|
||||
|
||||
// populate index
|
||||
for (i = 0; i < sc->chunk_count; i++) {
|
||||
@ -4045,7 +4045,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
||||
}
|
||||
}
|
||||
|
||||
if (st->nb_index_entries >= total) {
|
||||
if (st->internal->nb_index_entries >= total) {
|
||||
av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %u\n", total);
|
||||
return;
|
||||
}
|
||||
@ -4053,7 +4053,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
||||
av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", size);
|
||||
return;
|
||||
}
|
||||
e = &st->index_entries[st->nb_index_entries++];
|
||||
e = &st->internal->index_entries[st->internal->nb_index_entries++];
|
||||
e->pos = current_offset;
|
||||
e->timestamp = current_dts;
|
||||
e->size = size;
|
||||
@ -4076,8 +4076,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
||||
}
|
||||
|
||||
// Update start time of the stream.
|
||||
if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries > 0) {
|
||||
st->start_time = st->index_entries[0].timestamp + sc->dts_shift;
|
||||
if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries > 0) {
|
||||
st->start_time = st->internal->index_entries[0].timestamp + sc->dts_shift;
|
||||
if (sc->ctts_data) {
|
||||
st->start_time += sc->ctts_data[0].duration;
|
||||
}
|
||||
@ -4775,7 +4775,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
// A valid index_entry means the trun for the fragment was read
|
||||
// and it's samples are in index_entries at the given position.
|
||||
// New index entries will be inserted before the index_entry found.
|
||||
index_entry_pos = st->nb_index_entries;
|
||||
index_entry_pos = st->internal->nb_index_entries;
|
||||
for (i = c->frag_index.current + 1; i < c->frag_index.nb_items; i++) {
|
||||
frag_stream_info = get_frag_stream_info(&c->frag_index, i, frag->track_id);
|
||||
if (frag_stream_info && frag_stream_info->index_entry >= 0) {
|
||||
@ -4784,7 +4784,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
break;
|
||||
}
|
||||
}
|
||||
av_assert0(index_entry_pos <= st->nb_index_entries);
|
||||
av_assert0(index_entry_pos <= st->internal->nb_index_entries);
|
||||
|
||||
avio_r8(pb); /* version */
|
||||
flags = avio_rb24(pb);
|
||||
@ -4835,22 +4835,22 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
av_log(c->fc, AV_LOG_TRACE, "first sample flags 0x%x\n", first_sample_flags);
|
||||
|
||||
// realloc space for new index entries
|
||||
if((uint64_t)st->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) {
|
||||
entries = UINT_MAX / sizeof(AVIndexEntry) - st->nb_index_entries;
|
||||
if((uint64_t)st->internal->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) {
|
||||
entries = UINT_MAX / sizeof(AVIndexEntry) - st->internal->nb_index_entries;
|
||||
av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n");
|
||||
}
|
||||
if (entries == 0)
|
||||
return 0;
|
||||
|
||||
requested_size = (st->nb_index_entries + entries) * sizeof(AVIndexEntry);
|
||||
new_entries = av_fast_realloc(st->index_entries,
|
||||
&st->index_entries_allocated_size,
|
||||
requested_size = (st->internal->nb_index_entries + entries) * sizeof(AVIndexEntry);
|
||||
new_entries = av_fast_realloc(st->internal->index_entries,
|
||||
&st->internal->index_entries_allocated_size,
|
||||
requested_size);
|
||||
if (!new_entries)
|
||||
return AVERROR(ENOMEM);
|
||||
st->index_entries= new_entries;
|
||||
st->internal->index_entries= new_entries;
|
||||
|
||||
requested_size = (st->nb_index_entries + entries) * sizeof(*sc->ctts_data);
|
||||
requested_size = (st->internal->nb_index_entries + entries) * sizeof(*sc->ctts_data);
|
||||
old_ctts_allocated_size = sc->ctts_allocated_size;
|
||||
ctts_data = av_fast_realloc(sc->ctts_data, &sc->ctts_allocated_size,
|
||||
requested_size);
|
||||
@ -4864,12 +4864,12 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
memset((uint8_t*)(sc->ctts_data) + old_ctts_allocated_size, 0,
|
||||
sc->ctts_allocated_size - old_ctts_allocated_size);
|
||||
|
||||
if (index_entry_pos < st->nb_index_entries) {
|
||||
if (index_entry_pos < st->internal->nb_index_entries) {
|
||||
// Make hole in index_entries and ctts_data for new samples
|
||||
memmove(st->index_entries + index_entry_pos + entries,
|
||||
st->index_entries + index_entry_pos,
|
||||
sizeof(*st->index_entries) *
|
||||
(st->nb_index_entries - index_entry_pos));
|
||||
memmove(st->internal->index_entries + index_entry_pos + entries,
|
||||
st->internal->index_entries + index_entry_pos,
|
||||
sizeof(*st->internal->index_entries) *
|
||||
(st->internal->nb_index_entries - index_entry_pos));
|
||||
memmove(sc->ctts_data + index_entry_pos + entries,
|
||||
sc->ctts_data + index_entry_pos,
|
||||
sizeof(*sc->ctts_data) * (sc->ctts_count - index_entry_pos));
|
||||
@ -4878,15 +4878,15 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
}
|
||||
}
|
||||
|
||||
st->nb_index_entries += entries;
|
||||
sc->ctts_count = st->nb_index_entries;
|
||||
st->internal->nb_index_entries += entries;
|
||||
sc->ctts_count = st->internal->nb_index_entries;
|
||||
|
||||
// Record the index_entry position in frag_index of this fragment
|
||||
if (frag_stream_info)
|
||||
frag_stream_info->index_entry = index_entry_pos;
|
||||
|
||||
if (index_entry_pos > 0)
|
||||
prev_dts = st->index_entries[index_entry_pos-1].timestamp;
|
||||
prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp;
|
||||
|
||||
for (i = 0; i < entries && !pb->eof_reached; i++) {
|
||||
unsigned sample_size = frag->size;
|
||||
@ -4935,11 +4935,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
if (prev_dts >= dts)
|
||||
index_entry_flags |= AVINDEX_DISCARD_FRAME;
|
||||
|
||||
st->index_entries[index_entry_pos].pos = offset;
|
||||
st->index_entries[index_entry_pos].timestamp = dts;
|
||||
st->index_entries[index_entry_pos].size= sample_size;
|
||||
st->index_entries[index_entry_pos].min_distance= distance;
|
||||
st->index_entries[index_entry_pos].flags = index_entry_flags;
|
||||
st->internal->index_entries[index_entry_pos].pos = offset;
|
||||
st->internal->index_entries[index_entry_pos].timestamp = dts;
|
||||
st->internal->index_entries[index_entry_pos].size= sample_size;
|
||||
st->internal->index_entries[index_entry_pos].min_distance= distance;
|
||||
st->internal->index_entries[index_entry_pos].flags = index_entry_flags;
|
||||
|
||||
sc->ctts_data[index_entry_pos].count = 1;
|
||||
sc->ctts_data[index_entry_pos].duration = ctts_duration;
|
||||
@ -4966,16 +4966,16 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
// EOF found before reading all entries. Fix the hole this would
|
||||
// leave in index_entries and ctts_data
|
||||
int gap = entries - i;
|
||||
memmove(st->index_entries + index_entry_pos,
|
||||
st->index_entries + index_entry_pos + gap,
|
||||
sizeof(*st->index_entries) *
|
||||
(st->nb_index_entries - (index_entry_pos + gap)));
|
||||
memmove(st->internal->index_entries + index_entry_pos,
|
||||
st->internal->index_entries + index_entry_pos + gap,
|
||||
sizeof(*st->internal->index_entries) *
|
||||
(st->internal->nb_index_entries - (index_entry_pos + gap)));
|
||||
memmove(sc->ctts_data + index_entry_pos,
|
||||
sc->ctts_data + index_entry_pos + gap,
|
||||
sizeof(*sc->ctts_data) *
|
||||
(sc->ctts_count - (index_entry_pos + gap)));
|
||||
|
||||
st->nb_index_entries -= gap;
|
||||
st->internal->nb_index_entries -= gap;
|
||||
sc->ctts_count -= gap;
|
||||
if (index_entry_pos < sc->current_sample) {
|
||||
sc->current_sample -= gap;
|
||||
@ -4988,11 +4988,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
// fragment that overlap with AVINDEX_DISCARD_FRAME
|
||||
prev_dts = AV_NOPTS_VALUE;
|
||||
if (index_entry_pos > 0)
|
||||
prev_dts = st->index_entries[index_entry_pos-1].timestamp;
|
||||
for (i = index_entry_pos; i < st->nb_index_entries; i++) {
|
||||
if (prev_dts < st->index_entries[i].timestamp)
|
||||
prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp;
|
||||
for (i = index_entry_pos; i < st->internal->nb_index_entries; i++) {
|
||||
if (prev_dts < st->internal->index_entries[i].timestamp)
|
||||
break;
|
||||
st->index_entries[i].flags |= AVINDEX_DISCARD_FRAME;
|
||||
st->internal->index_entries[i].flags |= AVINDEX_DISCARD_FRAME;
|
||||
}
|
||||
|
||||
// If a hole was created to insert the new index_entries into,
|
||||
@ -7172,9 +7172,9 @@ static void mov_read_chapters(AVFormatContext *s)
|
||||
|
||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
st->disposition |= AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS;
|
||||
if (st->nb_index_entries) {
|
||||
if (st->internal->nb_index_entries) {
|
||||
// Retrieve the first frame, if possible
|
||||
AVIndexEntry *sample = &st->index_entries[0];
|
||||
AVIndexEntry *sample = &st->internal->index_entries[0];
|
||||
if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
|
||||
av_log(s, AV_LOG_ERROR, "Failed to retrieve first frame\n");
|
||||
goto finish;
|
||||
@ -7190,9 +7190,9 @@ static void mov_read_chapters(AVFormatContext *s)
|
||||
st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
|
||||
st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA;
|
||||
st->discard = AVDISCARD_ALL;
|
||||
for (i = 0; i < st->nb_index_entries; i++) {
|
||||
AVIndexEntry *sample = &st->index_entries[i];
|
||||
int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration;
|
||||
for (i = 0; i < st->internal->nb_index_entries; i++) {
|
||||
AVIndexEntry *sample = &st->internal->index_entries[i];
|
||||
int64_t end = i+1 < st->internal->nb_index_entries ? st->internal->index_entries[i+1].timestamp : st->duration;
|
||||
uint8_t *title;
|
||||
uint16_t ch;
|
||||
int len, title_len;
|
||||
@ -7265,10 +7265,10 @@ static int mov_read_rtmd_track(AVFormatContext *s, AVStream *st)
|
||||
int64_t cur_pos = avio_tell(sc->pb);
|
||||
int hh, mm, ss, ff, drop;
|
||||
|
||||
if (!st->nb_index_entries)
|
||||
if (!st->internal->nb_index_entries)
|
||||
return -1;
|
||||
|
||||
avio_seek(sc->pb, st->index_entries->pos, SEEK_SET);
|
||||
avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET);
|
||||
avio_skip(s->pb, 13);
|
||||
hh = avio_r8(s->pb);
|
||||
mm = avio_r8(s->pb);
|
||||
@ -7290,10 +7290,10 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st)
|
||||
int64_t cur_pos = avio_tell(sc->pb);
|
||||
uint32_t value;
|
||||
|
||||
if (!st->nb_index_entries)
|
||||
if (!st->internal->nb_index_entries)
|
||||
return -1;
|
||||
|
||||
avio_seek(sc->pb, st->index_entries->pos, SEEK_SET);
|
||||
avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET);
|
||||
value = avio_rb32(s->pb);
|
||||
|
||||
if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME;
|
||||
@ -7758,8 +7758,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st)
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
AVStream *avst = s->streams[i];
|
||||
MOVStreamContext *msc = avst->priv_data;
|
||||
if (msc->pb && msc->current_sample < avst->nb_index_entries) {
|
||||
AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample];
|
||||
if (msc->pb && msc->current_sample < avst->internal->nb_index_entries) {
|
||||
AVIndexEntry *current_sample = &avst->internal->index_entries[msc->current_sample];
|
||||
int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
|
||||
av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
|
||||
if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) ||
|
||||
@ -7962,8 +7962,8 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
sc->ctts_sample = 0;
|
||||
}
|
||||
} else {
|
||||
int64_t next_dts = (sc->current_sample < st->nb_index_entries) ?
|
||||
st->index_entries[sc->current_sample].timestamp : st->duration;
|
||||
int64_t next_dts = (sc->current_sample < st->internal->nb_index_entries) ?
|
||||
st->internal->index_entries[sc->current_sample].timestamp : st->duration;
|
||||
|
||||
if (next_dts >= pkt->dts)
|
||||
pkt->duration = next_dts - pkt->dts;
|
||||
@ -8044,7 +8044,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
|
||||
|
||||
sample = av_index_search_timestamp(st, timestamp, flags);
|
||||
av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample);
|
||||
if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)
|
||||
if (sample < 0 && st->internal->nb_index_entries && timestamp < st->internal->index_entries[0].timestamp)
|
||||
sample = 0;
|
||||
if (sample < 0) /* not sure what to do */
|
||||
return AVERROR_INVALIDDATA;
|
||||
@ -8099,7 +8099,7 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti
|
||||
|
||||
if (mc->seek_individually) {
|
||||
/* adjust seek timestamp to found sample timestamp */
|
||||
int64_t seek_timestamp = st->index_entries[sample].timestamp;
|
||||
int64_t seek_timestamp = st->internal->index_entries[sample].timestamp;
|
||||
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
int64_t timestamp;
|
||||
|
@ -431,8 +431,8 @@ static int mp3_read_header(AVFormatContext *s)
|
||||
}
|
||||
|
||||
// the seek index is relative to the end of the xing vbr headers
|
||||
for (i = 0; i < st->nb_index_entries; i++)
|
||||
st->index_entries[i].pos += avio_tell(s->pb);
|
||||
for (i = 0; i < st->internal->nb_index_entries; i++)
|
||||
st->internal->index_entries[i].pos += avio_tell(s->pb);
|
||||
|
||||
/* the parameters will be extracted from the compressed bitstream */
|
||||
return 0;
|
||||
@ -567,7 +567,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ie = &st->index_entries[ret];
|
||||
ie = &st->internal->index_entries[ret];
|
||||
} else if (fast_seek && st->duration > 0 && filesize > 0) {
|
||||
if (!mp3->is_cbr)
|
||||
av_log(s, AV_LOG_WARNING, "Using scaling to seek VBR MP3; may be imprecise.\n");
|
||||
|
@ -194,8 +194,8 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
|
||||
uint32_t lastframe;
|
||||
|
||||
/* if found, seek there */
|
||||
if (index >= 0 && st->index_entries[st->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){
|
||||
c->curframe = st->index_entries[index].pos;
|
||||
if (index >= 0 && st->internal->index_entries[st->internal->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){
|
||||
c->curframe = st->internal->index_entries[index].pos;
|
||||
return 0;
|
||||
}
|
||||
/* if timestamp is out of bounds, return error */
|
||||
|
@ -310,9 +310,9 @@ static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestam
|
||||
int index = av_index_search_timestamp(st, timestamp, flags);
|
||||
|
||||
if(index < 0) return -1;
|
||||
if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
|
||||
if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
|
||||
return -1;
|
||||
ff_update_cur_dts(s, st, st->index_entries[index].timestamp);
|
||||
ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1285,7 +1285,7 @@ int av_write_trailer(AVFormatContext *s)
|
||||
ret = s->pb ? s->pb->error : 0;
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
av_freep(&s->streams[i]->priv_data);
|
||||
av_freep(&s->streams[i]->index_entries);
|
||||
av_freep(&s->streams[i]->internal->index_entries);
|
||||
}
|
||||
if (s->oformat->priv_class)
|
||||
av_opt_free(s->priv_data);
|
||||
|
@ -431,8 +431,8 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
||||
int64_t ret;
|
||||
uint64_t pos;
|
||||
|
||||
if (frame < st->nb_index_entries) {
|
||||
index = &st->index_entries[frame];
|
||||
if (frame < st->internal->nb_index_entries) {
|
||||
index = &st->internal->index_entries[frame];
|
||||
pos = avio_tell(pb);
|
||||
if (index->pos > pos)
|
||||
avio_skip(pb, index->pos - pos);
|
||||
|
@ -682,10 +682,10 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
|
||||
if(index < 0)
|
||||
return -1;
|
||||
|
||||
if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
|
||||
if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
|
||||
return -1;
|
||||
|
||||
nst->frame_offset = st->index_entries[index].timestamp;
|
||||
nst->frame_offset = st->internal->index_entries[index].timestamp;
|
||||
nsv->state = NSV_UNSYNC;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1235,15 +1235,15 @@ static int read_seek(AVFormatContext *s, int stream_index,
|
||||
return AVERROR(ENOSYS);
|
||||
}
|
||||
|
||||
if (st->index_entries) {
|
||||
if (st->internal->index_entries) {
|
||||
int index = av_index_search_timestamp(st, pts, flags);
|
||||
if (index < 0)
|
||||
index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD);
|
||||
if (index < 0)
|
||||
return -1;
|
||||
|
||||
pos2 = st->index_entries[index].pos;
|
||||
ts = st->index_entries[index].timestamp;
|
||||
pos2 = st->internal->index_entries[index].pos;
|
||||
ts = st->internal->index_entries[index].timestamp;
|
||||
} else {
|
||||
av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp,
|
||||
(void **) next_node);
|
||||
|
@ -1013,12 +1013,12 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
int index = av_index_search_timestamp(st, dts_tb,
|
||||
AVSEEK_FLAG_BACKWARD);
|
||||
if (index >= 0) {
|
||||
sp_pos = FFMIN(sp_pos, st->index_entries[index].pos);
|
||||
if (!nut->write_index && 2*index > st->nb_index_entries) {
|
||||
memmove(st->index_entries,
|
||||
st->index_entries + index,
|
||||
sizeof(*st->index_entries) * (st->nb_index_entries - index));
|
||||
st->nb_index_entries -= index;
|
||||
sp_pos = FFMIN(sp_pos, st->internal->index_entries[index].pos);
|
||||
if (!nut->write_index && 2*index > st->internal->nb_index_entries) {
|
||||
memmove(st->internal->index_entries,
|
||||
st->internal->index_entries + index,
|
||||
sizeof(*st->internal->index_entries) * (st->internal->nb_index_entries - index));
|
||||
st->internal->nb_index_entries -= index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,9 +237,9 @@ static int rl2_read_packet(AVFormatContext *s,
|
||||
|
||||
/** check if there is a valid video or audio entry that can be used */
|
||||
for(i=0; i<s->nb_streams; i++){
|
||||
if(rl2->index_pos[i] < s->streams[i]->nb_index_entries
|
||||
&& s->streams[i]->index_entries[ rl2->index_pos[i] ].pos < pos){
|
||||
sample = &s->streams[i]->index_entries[ rl2->index_pos[i] ];
|
||||
if(rl2->index_pos[i] < s->streams[i]->internal->nb_index_entries
|
||||
&& s->streams[i]->internal->index_entries[ rl2->index_pos[i] ].pos < pos){
|
||||
sample = &s->streams[i]->internal->index_entries[ rl2->index_pos[i] ];
|
||||
pos= sample->pos;
|
||||
stream_id= i;
|
||||
}
|
||||
@ -283,7 +283,7 @@ static int rl2_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
|
||||
return -1;
|
||||
|
||||
rl2->index_pos[stream_index] = index;
|
||||
timestamp = st->index_entries[index].timestamp;
|
||||
timestamp = st->internal->index_entries[index].timestamp;
|
||||
|
||||
for(i=0; i < s->nb_streams; i++){
|
||||
AVStream *st2 = s->streams[i];
|
||||
|
@ -314,10 +314,10 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
|
||||
stream = s->streams[rpl->chunk_part];
|
||||
|
||||
if (rpl->chunk_number >= stream->nb_index_entries)
|
||||
if (rpl->chunk_number >= stream->internal->nb_index_entries)
|
||||
return AVERROR_EOF;
|
||||
|
||||
index_entry = &stream->index_entries[rpl->chunk_number];
|
||||
index_entry = &stream->internal->index_entries[rpl->chunk_number];
|
||||
|
||||
if (rpl->frame_in_part == 0)
|
||||
if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0)
|
||||
|
@ -324,7 +324,7 @@ static int film_read_seek(AVFormatContext *s, int stream_index, int64_t timestam
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
pos = avio_seek(s->pb, st->index_entries[ret].pos, SEEK_SET);
|
||||
pos = avio_seek(s->pb, st->internal->index_entries[ret].pos, SEEK_SET);
|
||||
if (pos < 0)
|
||||
return pos;
|
||||
|
||||
|
@ -155,15 +155,15 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
if (c->currentframe >= c->totalframes)
|
||||
return AVERROR_EOF;
|
||||
|
||||
if (st->nb_index_entries < c->totalframes) {
|
||||
if (st->internal->nb_index_entries < c->totalframes) {
|
||||
av_log(s, AV_LOG_ERROR, "Index entry disappeared\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
size = st->index_entries[c->currentframe].size;
|
||||
size = st->internal->index_entries[c->currentframe].size;
|
||||
|
||||
ret = av_get_packet(s->pb, pkt, size);
|
||||
pkt->dts = st->index_entries[c->currentframe++].timestamp;
|
||||
pkt->dts = st->internal->index_entries[c->currentframe++].timestamp;
|
||||
pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size :
|
||||
c->frame_size;
|
||||
return ret;
|
||||
@ -176,7 +176,7 @@ static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
|
||||
int index = av_index_search_timestamp(st, timestamp, flags);
|
||||
if (index < 0)
|
||||
return -1;
|
||||
if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
|
||||
if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
|
||||
return -1;
|
||||
|
||||
c->currentframe = index;
|
||||
|
@ -1914,11 +1914,11 @@ void ff_reduce_index(AVFormatContext *s, int stream_index)
|
||||
AVStream *st = s->streams[stream_index];
|
||||
unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry);
|
||||
|
||||
if ((unsigned) st->nb_index_entries >= max_entries) {
|
||||
if ((unsigned) st->internal->nb_index_entries >= max_entries) {
|
||||
int i;
|
||||
for (i = 0; 2 * i < st->nb_index_entries; i++)
|
||||
st->index_entries[i] = st->index_entries[2 * i];
|
||||
st->nb_index_entries = i;
|
||||
for (i = 0; 2 * i < st->internal->nb_index_entries; i++)
|
||||
st->internal->index_entries[i] = st->internal->index_entries[2 * i];
|
||||
st->internal->nb_index_entries = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1985,8 +1985,8 @@ int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
|
||||
int size, int distance, int flags)
|
||||
{
|
||||
timestamp = wrap_timestamp(st, timestamp);
|
||||
return ff_add_index_entry(&st->index_entries, &st->nb_index_entries,
|
||||
&st->index_entries_allocated_size, pos,
|
||||
return ff_add_index_entry(&st->internal->index_entries, &st->internal->nb_index_entries,
|
||||
&st->internal->index_entries_allocated_size, pos,
|
||||
timestamp, size, distance, flags);
|
||||
}
|
||||
|
||||
@ -2062,13 +2062,13 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
|
||||
if (ist1 == ist2)
|
||||
continue;
|
||||
|
||||
for (i1 = i2 = 0; i1 < st1->nb_index_entries; i1++) {
|
||||
AVIndexEntry *e1 = &st1->index_entries[i1];
|
||||
for (i1 = i2 = 0; i1 < st1->internal->nb_index_entries; i1++) {
|
||||
AVIndexEntry *e1 = &st1->internal->index_entries[i1];
|
||||
int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q);
|
||||
|
||||
skip = FFMAX(skip, e1->size);
|
||||
for (; i2 < st2->nb_index_entries; i2++) {
|
||||
AVIndexEntry *e2 = &st2->index_entries[i2];
|
||||
for (; i2 < st2->internal->nb_index_entries; i2++) {
|
||||
AVIndexEntry *e2 = &st2->internal->index_entries[i2];
|
||||
int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q);
|
||||
if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
|
||||
continue;
|
||||
@ -2100,7 +2100,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
|
||||
|
||||
int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)
|
||||
{
|
||||
return ff_index_search_timestamp(st->index_entries, st->nb_index_entries,
|
||||
return ff_index_search_timestamp(st->internal->index_entries, st->internal->nb_index_entries,
|
||||
wanted_timestamp, flags);
|
||||
}
|
||||
|
||||
@ -2133,7 +2133,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
|
||||
pos_limit = -1; // GCC falsely says it may be uninitialized.
|
||||
|
||||
st = s->streams[stream_index];
|
||||
if (st->index_entries) {
|
||||
if (st->internal->index_entries) {
|
||||
AVIndexEntry *e;
|
||||
|
||||
/* FIXME: Whole function must be checked for non-keyframe entries in
|
||||
@ -2141,7 +2141,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
|
||||
index = av_index_search_timestamp(st, target_ts,
|
||||
flags | AVSEEK_FLAG_BACKWARD);
|
||||
index = FFMAX(index, 0);
|
||||
e = &st->index_entries[index];
|
||||
e = &st->internal->index_entries[index];
|
||||
|
||||
if (e->timestamp <= target_ts || e->pos == e->min_distance) {
|
||||
pos_min = e->pos;
|
||||
@ -2154,9 +2154,9 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
|
||||
|
||||
index = av_index_search_timestamp(st, target_ts,
|
||||
flags & ~AVSEEK_FLAG_BACKWARD);
|
||||
av_assert0(index < st->nb_index_entries);
|
||||
av_assert0(index < st->internal->nb_index_entries);
|
||||
if (index >= 0) {
|
||||
e = &st->index_entries[index];
|
||||
e = &st->internal->index_entries[index];
|
||||
av_assert1(e->timestamp >= target_ts);
|
||||
pos_max = e->pos;
|
||||
ts_max = e->timestamp;
|
||||
@ -2357,17 +2357,17 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index,
|
||||
|
||||
index = av_index_search_timestamp(st, timestamp, flags);
|
||||
|
||||
if (index < 0 && st->nb_index_entries &&
|
||||
timestamp < st->index_entries[0].timestamp)
|
||||
if (index < 0 && st->internal->nb_index_entries &&
|
||||
timestamp < st->internal->index_entries[0].timestamp)
|
||||
return -1;
|
||||
|
||||
if (index < 0 || index == st->nb_index_entries - 1) {
|
||||
if (index < 0 || index == st->internal->nb_index_entries - 1) {
|
||||
AVPacket pkt;
|
||||
int nonkey = 0;
|
||||
|
||||
if (st->nb_index_entries) {
|
||||
av_assert0(st->index_entries);
|
||||
ie = &st->index_entries[st->nb_index_entries - 1];
|
||||
if (st->internal->nb_index_entries) {
|
||||
av_assert0(st->internal->index_entries);
|
||||
ie = &st->internal->index_entries[st->internal->nb_index_entries - 1];
|
||||
if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
|
||||
return ret;
|
||||
ff_update_cur_dts(s, st, ie->timestamp);
|
||||
@ -2404,7 +2404,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index,
|
||||
if (s->iformat->read_seek)
|
||||
if (s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)
|
||||
return 0;
|
||||
ie = &st->index_entries[index];
|
||||
ie = &st->internal->index_entries[index];
|
||||
if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
|
||||
return ret;
|
||||
ff_update_cur_dts(s, st, ie->timestamp);
|
||||
@ -4342,6 +4342,7 @@ static void free_stream(AVStream **pst)
|
||||
avcodec_free_context(&st->internal->avctx);
|
||||
av_bsf_free(&st->internal->bsfc);
|
||||
av_freep(&st->internal->priv_pts);
|
||||
av_freep(&st->internal->index_entries);
|
||||
av_bsf_free(&st->internal->extract_extradata.bsf);
|
||||
av_packet_free(&st->internal->extract_extradata.pkt);
|
||||
|
||||
@ -4354,7 +4355,6 @@ static void free_stream(AVStream **pst)
|
||||
av_dict_free(&st->metadata);
|
||||
avcodec_parameters_free(&st->codecpar);
|
||||
av_freep(&st->probe_data.buf);
|
||||
av_freep(&st->index_entries);
|
||||
#if FF_API_LAVF_AVCTX
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
avcodec_free_context(&st->codec);
|
||||
|
@ -83,14 +83,14 @@ static int voc_read_seek(AVFormatContext *s, int stream_index,
|
||||
st = s->streams[stream_index];
|
||||
index = av_index_search_timestamp(st, timestamp, flags);
|
||||
|
||||
if (index >= 0 && index < st->nb_index_entries - 1) {
|
||||
AVIndexEntry *e = &st->index_entries[index];
|
||||
if (index >= 0 && index < st->internal->nb_index_entries - 1) {
|
||||
AVIndexEntry *e = &st->internal->index_entries[index];
|
||||
avio_seek(s->pb, e->pos, SEEK_SET);
|
||||
voc->pts = e->timestamp;
|
||||
voc->remaining_size = e->size;
|
||||
return 0;
|
||||
} else if (st->nb_index_entries && st->index_entries[0].timestamp <= timestamp) {
|
||||
AVIndexEntry *e = &st->index_entries[st->nb_index_entries - 1];
|
||||
} else if (st->internal->nb_index_entries && st->internal->index_entries[0].timestamp <= timestamp) {
|
||||
AVIndexEntry *e = &st->internal->index_entries[st->internal->nb_index_entries - 1];
|
||||
// prepare context for seek_frame_generic()
|
||||
voc->pts = e->timestamp;
|
||||
voc->remaining_size = e->size;
|
||||
|
Loading…
Reference in New Issue
Block a user