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
This commit is contained in:
Aurelien Jacobs 2005-05-19 00:06:27 +00:00
parent 3b5ffe7a39
commit a965c478b2
11 changed files with 26 additions and 16 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {