Skip to content

Commit

Permalink
avio: add avio_tell macro as a replacement for url_ftell
Browse files Browse the repository at this point in the history
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
(cherry picked from commit a2704c9)
  • Loading branch information
elenril authored and michaelni committed Mar 5, 2011
1 parent 773947b commit 384c9c2
Show file tree
Hide file tree
Showing 87 changed files with 392 additions and 391 deletions.
4 changes: 2 additions & 2 deletions ffmpeg.c
Expand Up @@ -1365,7 +1365,7 @@ static void print_report(AVFormatContext **output_files,

total_size = url_fsize(oc->pb);
if(total_size<0) // FIXME improve url_fsize() so it works with non seekable output too
total_size= url_ftell(oc->pb);
total_size= avio_tell(oc->pb);

buf[0] = '\0';
ti1 = 1e10;
Expand Down Expand Up @@ -2571,7 +2571,7 @@ static int transcode(AVFormatContext **output_files,
}

/* finish if limit size exhausted */
if (limit_filesize != 0 && limit_filesize <= url_ftell(output_files[0]->pb))
if (limit_filesize != 0 && limit_filesize <= avio_tell(output_files[0]->pb))
break;

/* read a frame from it and output it in the fifo */
Expand Down
2 changes: 1 addition & 1 deletion ffplay.c
Expand Up @@ -2809,7 +2809,7 @@ static void event_loop(void)
}else if(cur_stream->audio_stream >= 0 && cur_stream->audio_pkt.pos>=0){
pos= cur_stream->audio_pkt.pos;
}else
pos = url_ftell(cur_stream->ic->pb);
pos = avio_tell(cur_stream->ic->pb);
if (cur_stream->ic->bit_rate)
incr *= cur_stream->ic->bit_rate / 8.0;
else
Expand Down
2 changes: 1 addition & 1 deletion libavformat/4xm.c
Expand Up @@ -283,7 +283,7 @@ static int fourxm_read_packet(AVFormatContext *s,
return AVERROR(EIO);
pkt->stream_index = fourxm->video_stream_index;
pkt->pts = fourxm->video_pts;
pkt->pos = url_ftell(s->pb);
pkt->pos = avio_tell(s->pb);
memcpy(pkt->data, header, 8);
ret = avio_read(s->pb, &pkt->data[8], size);

Expand Down
6 changes: 3 additions & 3 deletions libavformat/aiffdec.c
Expand Up @@ -232,10 +232,10 @@ static int aiff_read_header(AVFormatContext *s,
get_meta(s, "comment" , size);
break;
case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */
aiff->data_end = url_ftell(pb) + size;
aiff->data_end = avio_tell(pb) + size;
offset = avio_rb32(pb); /* Offset of sound data */
avio_rb32(pb); /* BlockSize... don't care */
offset += url_ftell(pb); /* Compute absolute data offset */
offset += avio_tell(pb); /* Compute absolute data offset */
if (st->codec->block_align) /* Assume COMM already parsed */
goto got_sound;
if (url_is_streamed(pb)) {
Expand Down Expand Up @@ -292,7 +292,7 @@ static int aiff_read_packet(AVFormatContext *s,
int res, size;

/* calculate size of remaining data */
max_size = aiff->data_end - url_ftell(s->pb);
max_size = aiff->data_end - avio_tell(s->pb);
if (max_size <= 0)
return AVERROR_EOF;

Expand Down
8 changes: 4 additions & 4 deletions libavformat/aiffenc.c
Expand Up @@ -45,7 +45,7 @@ static int aiff_write_header(AVFormatContext *s)

/* FORM AIFF header */
ffio_wfourcc(pb, "FORM");
aiff->form = url_ftell(pb);
aiff->form = avio_tell(pb);
avio_wb32(pb, 0); /* file length */
ffio_wfourcc(pb, aifc ? "AIFC" : "AIFF");

Expand All @@ -66,7 +66,7 @@ static int aiff_write_header(AVFormatContext *s)
avio_wb32(pb, aifc ? 24 : 18); /* size */
avio_wb16(pb, enc->channels); /* Number of channels */

aiff->frames = url_ftell(pb);
aiff->frames = avio_tell(pb);
avio_wb32(pb, 0); /* Number of frames */

if (!enc->bits_per_coded_sample)
Expand All @@ -90,7 +90,7 @@ static int aiff_write_header(AVFormatContext *s)

/* Sound data chunk */
ffio_wfourcc(pb, "SSND");
aiff->ssnd = url_ftell(pb); /* Sound chunk size */
aiff->ssnd = avio_tell(pb); /* Sound chunk size */
avio_wb32(pb, 0); /* Sound samples data size */
avio_wb32(pb, 0); /* Data offset */
avio_wb32(pb, 0); /* Block-size (block align) */
Expand Down Expand Up @@ -118,7 +118,7 @@ static int aiff_write_trailer(AVFormatContext *s)

/* Chunks sizes must be even */
int64_t file_size, end_size;
end_size = file_size = url_ftell(pb);
end_size = file_size = avio_tell(pb);
if (file_size & 1) {
avio_w8(pb, 0);
end_size++;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/amr.c
Expand Up @@ -154,7 +154,7 @@ static int amr_read_packet(AVFormatContext *s,
}

pkt->stream_index = 0;
pkt->pos= url_ftell(s->pb);
pkt->pos= avio_tell(s->pb);
pkt->data[0]=toc;
pkt->duration= enc->codec_id == CODEC_ID_AMR_NB ? 160 : 320;
read = avio_read(s->pb, pkt->data+1, size-1);
Expand Down
2 changes: 1 addition & 1 deletion libavformat/anm.c
Expand Up @@ -208,7 +208,7 @@ static int read_packet(AVFormatContext *s,
}

/* fetch record size */
tmp = url_ftell(pb);
tmp = avio_tell(pb);
avio_seek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) +
8 + anm->record * 2, SEEK_SET);
record_size = avio_rl16(pb);
Expand Down
36 changes: 18 additions & 18 deletions libavformat/asfdec.c
Expand Up @@ -160,7 +160,7 @@ static int get_value(AVIOContext *pb, int type){
static void get_tag(AVFormatContext *s, const char *key, int type, int len)
{
char *value;
int64_t off = url_ftell(s->pb);
int64_t off = avio_tell(s->pb);

if ((unsigned)len >= (UINT_MAX - 1)/2)
return;
Expand Down Expand Up @@ -225,7 +225,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
return AVERROR(EINVAL);
}

pos1 = url_ftell(pb);
pos1 = avio_tell(pb);

st = av_new_stream(s, 0);
if (!st)
Expand Down Expand Up @@ -300,7 +300,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
st->need_parsing = AVSTREAM_PARSE_FULL;
}
/* We have to init the frame size at some point .... */
pos2 = url_ftell(pb);
pos2 = avio_tell(pb);
if (size >= (pos2 + 8 - pos1 + 24)) {
asf_st->ds_span = avio_r8(pb);
asf_st->ds_packet_size = avio_rl16(pb);
Expand Down Expand Up @@ -337,7 +337,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
break;
}
} else if (type == AVMEDIA_TYPE_VIDEO &&
size - (url_ftell(pb) - pos1 + 24) >= 51) {
size - (avio_tell(pb) - pos1 + 24) >= 51) {
avio_rl32(pb);
avio_rl32(pb);
avio_r8(pb);
Expand Down Expand Up @@ -386,7 +386,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
if(st->codec->codec_id == CODEC_ID_H264)
st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
}
pos2 = url_ftell(pb);
pos2 = avio_tell(pb);
avio_seek(pb, size - (pos2 - pos1 + 24), SEEK_CUR);

return 0;
Expand Down Expand Up @@ -594,14 +594,14 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_r8(pb);
memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
for(;;) {
uint64_t gpos= url_ftell(pb);
uint64_t gpos= avio_tell(pb);
ff_get_guid(pb, &g);
gsize = avio_rl64(pb);
av_dlog(s, "%08"PRIx64": ", gpos);
print_guid(&g);
av_dlog(s, " size=0x%"PRIx64"\n", gsize);
if (!ff_guidcmp(&g, &ff_asf_data_header)) {
asf->data_object_offset = url_ftell(pb);
asf->data_object_offset = avio_tell(pb);
// if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
if (!(asf->hdr.flags & 0x01) && gsize >= 100) {
asf->data_object_size = gsize - 24;
Expand Down Expand Up @@ -651,8 +651,8 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
}
}
if(url_ftell(pb) != gpos + gsize)
av_log(s, AV_LOG_DEBUG, "gpos mismatch our pos=%"PRIu64", end=%"PRIu64"\n", url_ftell(pb)-gpos, gsize);
if(avio_tell(pb) != gpos + gsize)
av_log(s, AV_LOG_DEBUG, "gpos mismatch our pos=%"PRIu64", end=%"PRIu64"\n", avio_tell(pb)-gpos, gsize);
avio_seek(pb, gpos + gsize, SEEK_SET);
}
ff_get_guid(pb, &g);
Expand All @@ -661,7 +661,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_r8(pb);
if (url_feof(pb))
return -1;
asf->data_offset = url_ftell(pb);
asf->data_offset = avio_tell(pb);
asf->packet_size_left = 0;


Expand Down Expand Up @@ -725,7 +725,7 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
// if we do not know packet size, allow skipping up to 32 kB
off= 32768;
if (s->packet_size > 0)
off= (url_ftell(pb) - s->data_offset) % s->packet_size + 3;
off= (avio_tell(pb) - s->data_offset) % s->packet_size + 3;

c=d=e=-1;
while(off-- > 0){
Expand All @@ -745,7 +745,7 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
if (url_ferror(pb) == AVERROR(EAGAIN))
return AVERROR(EAGAIN);
if (!url_feof(pb))
av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, url_ftell(pb));
av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb));
}
if ((c & 0x8f) == 0x82) {
if (d || e) {
Expand All @@ -769,11 +769,11 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)

//the following checks prevent overflows and infinite loops
if(!packet_length || packet_length >= (1U<<29)){
av_log(s, AV_LOG_ERROR, "invalid packet_length %d at:%"PRId64"\n", packet_length, url_ftell(pb));
av_log(s, AV_LOG_ERROR, "invalid packet_length %d at:%"PRId64"\n", packet_length, avio_tell(pb));
return -1;
}
if(padsize >= packet_length){
av_log(s, AV_LOG_ERROR, "invalid padsize %d at:%"PRId64"\n", padsize, url_ftell(pb));
av_log(s, AV_LOG_ERROR, "invalid padsize %d at:%"PRId64"\n", padsize, avio_tell(pb));
return -1;
}

Expand Down Expand Up @@ -891,12 +891,12 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|| asf->packet_segments < 1) {
//asf->packet_size_left <= asf->packet_padsize) {
int ret = asf->packet_size_left + asf->packet_padsize;
//printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
//printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, avio_tell(pb));
assert(ret>=0);
/* fail safe */
avio_seek(pb, ret, SEEK_CUR);

asf->packet_pos= url_ftell(pb);
asf->packet_pos= avio_tell(pb);
if (asf->data_object_size != (uint64_t)-1 &&
(asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
return AVERROR_EOF; /* Do not exceed the size of the data object */
Expand Down Expand Up @@ -1184,7 +1184,7 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
{
ff_asf_guid g;
ASFContext *asf = s->priv_data;
int64_t current_pos= url_ftell(s->pb);
int64_t current_pos= avio_tell(s->pb);
int i;

avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
Expand Down Expand Up @@ -1267,7 +1267,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int
// avio_seek(s->pb, pos, SEEK_SET);
// key_pos = pos;
// for(i=0;i<16;i++){
// pos = url_ftell(s->pb);
// pos = avio_tell(s->pb);
// if (av_read_frame(s, &pkt) < 0){
// av_log(s, AV_LOG_INFO, "seek failed\n");
// return -1;
Expand Down
20 changes: 10 additions & 10 deletions libavformat/asfenc.c
Expand Up @@ -248,7 +248,7 @@ static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
{
int64_t pos;

pos = url_ftell(pb);
pos = avio_tell(pb);
put_guid(pb, g);
avio_wl64(pb, 24);
return pos;
Expand All @@ -259,7 +259,7 @@ static void end_header(AVIOContext *pb, int64_t pos)
{
int64_t pos1;

pos1 = url_ftell(pb);
pos1 = avio_tell(pb);
avio_seek(pb, pos + 16, SEEK_SET);
avio_wl64(pb, pos1 - pos);
avio_seek(pb, pos1, SEEK_SET);
Expand Down Expand Up @@ -337,7 +337,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
avio_w8(pb, 2); /* ??? */

/* file header */
header_offset = url_ftell(pb);
header_offset = avio_tell(pb);
hpos = put_header(pb, &ff_asf_file_header);
put_guid(pb, &ff_asf_my_guid);
avio_wl64(pb, file_size);
Expand Down Expand Up @@ -425,7 +425,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
put_guid(pb, &ff_asf_video_conceal_none);
}
avio_wl64(pb, 0); /* ??? */
es_pos = url_ftell(pb);
es_pos = avio_tell(pb);
avio_wl32(pb, extra_size); /* wav header len */
avio_wl32(pb, extra_size2); /* additional data len */
avio_wl16(pb, n + 1); /* stream number */
Expand All @@ -442,7 +442,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
if (wavsize < 0)
return -1;
if (wavsize != extra_size) {
cur_pos = url_ftell(pb);
cur_pos = avio_tell(pb);
avio_seek(pb, es_pos, SEEK_SET);
avio_wl32(pb, wavsize); /* wav header len */
avio_seek(pb, cur_pos, SEEK_SET);
Expand Down Expand Up @@ -525,7 +525,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data

/* patch the header size fields */

cur_pos = url_ftell(pb);
cur_pos = avio_tell(pb);
header_size = cur_pos - header_offset;
if (asf->is_streamed) {
header_size += 8 + 30 + 50;
Expand Down Expand Up @@ -605,7 +605,7 @@ static int put_payload_parsing_info(
ASFContext *asf = s->priv_data;
AVIOContext *pb = s->pb;
int ppi_size, i;
int64_t start= url_ftell(pb);
int64_t start= avio_tell(pb);

int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;

Expand Down Expand Up @@ -642,7 +642,7 @@ static int put_payload_parsing_info(
if (asf->multi_payloads_present)
avio_w8(pb, nb_payloads | ASF_PAYLOAD_FLAGS);

ppi_size = url_ftell(pb) - start;
ppi_size = avio_tell(pb) - start;

return ppi_size;
}
Expand Down Expand Up @@ -860,7 +860,7 @@ static int asf_write_trailer(AVFormatContext *s)
flush_packet(s);

/* write index */
data_size = url_ftell(s->pb);
data_size = avio_tell(s->pb);
if ((!asf->is_streamed) && (asf->nb_index_count != 0)) {
asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count);
}
Expand All @@ -870,7 +870,7 @@ static int asf_write_trailer(AVFormatContext *s)
put_chunk(s, 0x4524, 0, 0); /* end of stream */
} else {
/* rewrite an updated header */
file_size = url_ftell(s->pb);
file_size = avio_tell(s->pb);
avio_seek(s->pb, 0, SEEK_SET);
asf_write_header1(s, file_size, data_size - asf->data_offset);
}
Expand Down
2 changes: 1 addition & 1 deletion libavformat/au.c
Expand Up @@ -94,7 +94,7 @@ static int au_write_trailer(AVFormatContext *s)
if (!url_is_streamed(s->pb)) {

/* update file size */
file_size = url_ftell(pb);
file_size = avio_tell(pb);
avio_seek(pb, 8, SEEK_SET);
avio_wb32(pb, (uint32_t)(file_size - 24));
avio_seek(pb, file_size, SEEK_SET);
Expand Down

0 comments on commit 384c9c2

Please sign in to comment.