From a965c478b2b2fe7d9d0a2c60561bb4ee171a2119 Mon Sep 17 00:00:00 2001 From: Aurelien Jacobs Date: Thu, 19 May 2005 00:06:27 +0000 Subject: drop most url_fileno() calls (allows to use ByteIOContext directly in caller apps instead of URLProtocol) Originally committed as revision 4275 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/avidec.c | 4 ++-- libavformat/avio.h | 1 + libavformat/aviobuf.c | 11 +++++++++++ libavformat/dv.c | 2 +- libavformat/ffm.c | 2 +- libavformat/img2.c | 2 +- libavformat/mov.c | 2 +- libavformat/mp3.c | 2 +- libavformat/ogg2.c | 5 ++--- libavformat/utils.c | 8 +++----- libavformat/yuv.c | 3 ++- 11 files changed, 26 insertions(+), 16 deletions(-) (limited to 'libavformat') diff --git a/libavformat/avidec.c b/libavformat/avidec.c index bf020187e1..1f636a0a50 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -125,7 +125,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) if (tag1 == MKTAG('m', 'o', 'v', 'i')) { avi->movi_list = url_ftell(pb) - 4; if(size) avi->movi_end = avi->movi_list + size; - else avi->movi_end = url_filesize(url_fileno(pb)); + else avi->movi_end = url_fsize(pb); #ifdef DEBUG printf("movi end=%Lx\n", avi->movi_end); #endif @@ -486,7 +486,7 @@ resync: if (i >= avi->movi_end) { if (avi->is_odml) { url_fskip(pb, avi->riff_end - i); - avi->riff_end = avi->movi_end = url_filesize(url_fileno(pb)); + avi->riff_end = avi->movi_end = url_fsize(pb); } else break; } diff --git a/libavformat/avio.h b/libavformat/avio.h index f834ef34a7..109d20a4ff 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -109,6 +109,7 @@ void put_strz(ByteIOContext *s, const char *buf); offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence); void url_fskip(ByteIOContext *s, offset_t offset); offset_t url_ftell(ByteIOContext *s); +offset_t url_fsize(ByteIOContext *s); int url_feof(ByteIOContext *s); int url_ferror(ByteIOContext *s); diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 6eab0e18f3..993ba449f0 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -172,6 +172,17 @@ offset_t url_ftell(ByteIOContext *s) return url_fseek(s, 0, SEEK_CUR); } +offset_t url_fsize(ByteIOContext *s) +{ + offset_t size; + + if (!s->seek) + return -EPIPE; + size = s->seek(s->opaque, -1, SEEK_END) + 1; + s->seek(s->opaque, s->pos, SEEK_SET); + return size; +} + int url_feof(ByteIOContext *s) { return s->eof_reached; diff --git a/libavformat/dv.c b/libavformat/dv.c index ed6a740cf6..ff5f4bedb0 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -815,7 +815,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) const DVprofile* sys = dv_codec_profile(&c->vst->codec); int64_t offset; - int64_t size = url_filesize(url_fileno(&s->pb)); + int64_t size = url_fsize(&s->pb); int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size; offset = sys->frame_size * timestamp; diff --git a/libavformat/ffm.c b/libavformat/ffm.c index c705a8e597..c8641ec87b 100644 --- a/libavformat/ffm.c +++ b/libavformat/ffm.c @@ -462,7 +462,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) ffm->write_index = get_be64(pb); /* get also filesize */ if (!url_is_streamed(pb)) { - ffm->file_size = url_filesize(url_fileno(pb)); + ffm->file_size = url_fsize(pb); adjust_write_index(s); } else { ffm->file_size = (uint64_t_C(1) << 63) - 1; diff --git a/libavformat/img2.c b/libavformat/img2.c index fe225e970a..2214a1e9e5 100644 --- a/libavformat/img2.c +++ b/libavformat/img2.c @@ -244,7 +244,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) for(i=0; i<3; i++){ if (url_fopen(f[i], filename, URL_RDONLY) < 0) return AVERROR_IO; - size[i]= url_filesize(url_fileno(f[i])); + size[i]= url_fsize(f[i]); if(codec->codec_id != CODEC_ID_RAWVIDEO) break; diff --git a/libavformat/mov.c b/libavformat/mov.c index ca82a036b8..88239f18dc 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1740,7 +1740,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) mov->mp4 = 1; #endif if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */ - atom.size = url_filesize(url_fileno(pb)); + atom.size = url_fsize(pb); else atom.size = 0x7FFFFFFFFFFFFFFFLL; diff --git a/libavformat/mp3.c b/libavformat/mp3.c index dc4ec3dfc2..ebd7ef4be1 100644 --- a/libavformat/mp3.c +++ b/libavformat/mp3.c @@ -258,7 +258,7 @@ static int mp3_read_header(AVFormatContext *s, /* try to get the TAG */ if (!url_is_streamed(&s->pb)) { /* XXX: change that */ - filesize = url_filesize(url_fileno(&s->pb)); + filesize = url_fsize(&s->pb); if (filesize > 128) { url_fseek(&s->pb, filesize - 128, SEEK_SET); ret = get_buffer(&s->pb, buf, ID3_TAG_SIZE); diff --git a/libavformat/ogg2.c b/libavformat/ogg2.c index 05147f89fb..6f9638b005 100644 --- a/libavformat/ogg2.c +++ b/libavformat/ogg2.c @@ -449,7 +449,6 @@ static int ogg_get_length (AVFormatContext * s) { ogg_t *ogg = s->priv_data; - URLContext *h = url_fileno (&s->pb); int idx = -1, i; //FIXME: get the right ctx flag to know if is seekable or not // if(ogg->f->flags & URL_FLAG_STREAMED) @@ -460,7 +459,7 @@ ogg_get_length (AVFormatContext * s) return 0; ogg_save (s); - url_seek (h, -MAX_PAGE_SIZE, SEEK_END); + url_fseek (&s->pb, -MAX_PAGE_SIZE, SEEK_END); while (!ogg_read_page (s, &i)){ if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0) @@ -472,7 +471,7 @@ ogg_get_length (AVFormatContext * s) ogg_gptopts (s, idx, ogg->streams[idx].granule); } - ogg->size = url_filesize(h); + ogg->size = url_fsize(&s->pb); ogg_restore (s, 0); return 0; diff --git a/libavformat/utils.c b/libavformat/utils.c index 868ff81c49..9927cfca66 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1192,7 +1192,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts if(ts_max == AV_NOPTS_VALUE){ int step= 1024; - pos_max = url_filesize(url_fileno(&s->pb)) - 1; + pos_max = url_fsize(&s->pb) - 1; do{ pos_max -= step; ts_max = avif->read_timestamp(s, stream_index, &pos_max, pos_max + step); @@ -1289,7 +1289,7 @@ static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, #endif pos_min = s->data_offset; - pos_max = url_filesize(url_fileno(&s->pb)) - 1; + pos_max = url_fsize(&s->pb) - 1; if (pos < pos_min) pos= pos_min; else if(pos > pos_max) pos= pos_max; @@ -1586,15 +1586,13 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic) static void av_estimate_timings(AVFormatContext *ic) { - URLContext *h; int64_t file_size; /* get the file size, if possible */ if (ic->iformat->flags & AVFMT_NOFILE) { file_size = 0; } else { - h = url_fileno(&ic->pb); - file_size = url_filesize(h); + file_size = url_fsize(&ic->pb); if (file_size < 0) file_size = 0; } diff --git a/libavformat/yuv.c b/libavformat/yuv.c index 7037bb46fd..c4bce68b29 100644 --- a/libavformat/yuv.c +++ b/libavformat/yuv.c @@ -54,9 +54,10 @@ static int yuv_read(ByteIOContext *f, URLContext *h; AVImageInfo info1, *info = &info1; + img_size = url_fsize(f); + /* XXX: hack hack */ h = url_fileno(f); - img_size = url_seek(h, 0, SEEK_END); url_get_filename(h, fname, sizeof(fname)); if (infer_size(&info->width, &info->height, img_size) < 0) { -- cgit v1.2.3