X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Faviobuf.c;h=e943aacb3293b01a5ef212ff900c8e4bab84f1a0;hb=0cb233cf46e057c4d4d9352470305de3f569a036;hp=dd250277f21949eefa0ab182632a26a9cd9f6d2c;hpb=5958df341de69d94b9958c10cc4aaca510b8cd24;p=ffmpeg diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index dd250277f21..e943aacb329 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -2,20 +2,20 @@ * Buffered I/O for ffmpeg system * Copyright (c) 2000,2001 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -38,9 +38,7 @@ #define SHORT_SEEK_THRESHOLD 4096 static void fill_buffer(AVIOContext *s); -#if !FF_API_URL_RESETBUF static int url_resetbuf(AVIOContext *s, int flags); -#endif int ffio_init_context(AVIOContext *s, unsigned char *buffer, @@ -55,7 +53,7 @@ int ffio_init_context(AVIOContext *s, s->buffer_size = buffer_size; s->buf_ptr = buffer; s->opaque = opaque; - url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY); + url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ); s->write_packet = write_packet; s->read_packet = read_packet; s->seek = seek; @@ -115,6 +113,8 @@ AVIOContext *avio_alloc_context( int64_t (*seek)(void *opaque, int64_t offset, int whence)) { AVIOContext *s = av_mallocz(sizeof(AVIOContext)); + if (!s) + return NULL; ffio_init_context(s, buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek); return s; @@ -237,6 +237,11 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence) return offset; } +int64_t avio_skip(AVIOContext *s, int64_t offset) +{ + return avio_seek(s, offset, SEEK_CUR); +} + #if FF_API_OLD_AVIO int url_fskip(AVIOContext *s, int64_t offset) { @@ -269,14 +274,18 @@ int64_t avio_size(AVIOContext *s) return size; } -#if FF_API_OLD_AVIO int url_feof(AVIOContext *s) { if(!s) return 0; + if(s->eof_reached){ + s->eof_reached=0; + fill_buffer(s); + } return s->eof_reached; } +#if FF_API_OLD_AVIO int url_ferror(AVIOContext *s) { if(!s) @@ -403,12 +412,12 @@ void put_flush_packet(AVIOContext *s) } int av_url_read_fpause(AVIOContext *s, int pause) { - return ffio_read_pause(s, pause); + return avio_pause(s, pause); } int64_t av_url_read_fseek(AVIOContext *s, int stream_index, int64_t timestamp, int flags) { - return ffio_read_seek(s, stream_index, timestamp, flags); + return avio_seek_time(s, stream_index, timestamp, flags); } void init_checksum(AVIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), @@ -548,7 +557,7 @@ static void fill_buffer(AVIOContext *s) } /* make buffer smaller in case it ended up large after probing */ - if (s->buffer_size > max_buffer_size) { + if (s->read_packet && s->buffer_size > max_buffer_size) { ffio_set_buf_size(s, max_buffer_size); s->checksum_ptr = dst = s->buffer; @@ -658,8 +667,8 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) } } if (size1 == size) { - if (s->error) return s->error; - if (s->eof_reached) return AVERROR_EOF; + if (s->error) return s->error; + if (url_feof(s)) return AVERROR_EOF; } return size1 - size; } @@ -681,8 +690,8 @@ int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size) memcpy(buf, s->buf_ptr, len); s->buf_ptr += len; if (!len) { - if (s->error) return s->error; - if (s->eof_reached) return AVERROR_EOF; + if (s->error) return s->error; + if (url_feof(s)) return AVERROR_EOF; } return len; } @@ -838,19 +847,13 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) if (!buffer) return AVERROR(ENOMEM); - *s = av_mallocz(sizeof(AVIOContext)); - if(!*s) { + *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h, + ffurl_read, ffurl_write, ffurl_seek); + if (!*s) { av_free(buffer); return AVERROR(ENOMEM); } - if (ffio_init_context(*s, buffer, buffer_size, - (h->flags & URL_WRONLY || h->flags & URL_RDWR), h, - ffurl_read, ffurl_write, ffurl_seek) < 0) { - av_free(buffer); - av_freep(s); - return AVERROR(EIO); - } #if FF_API_OLD_AVIO (*s)->is_streamed = h->is_streamed; #endif @@ -874,24 +877,15 @@ int ffio_set_buf_size(AVIOContext *s, int buf_size) s->buffer = buffer; s->buffer_size = buf_size; s->buf_ptr = buffer; - url_resetbuf(s, s->write_flag ? URL_WRONLY : URL_RDONLY); + url_resetbuf(s, s->write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ); return 0; } -#if FF_API_URL_RESETBUF -int url_resetbuf(AVIOContext *s, int flags) -#else static int url_resetbuf(AVIOContext *s, int flags) -#endif { -#if FF_API_URL_RESETBUF - if (flags & URL_RDWR) - return AVERROR(EINVAL); -#else - assert(flags == URL_WRONLY || flags == URL_RDONLY); -#endif + assert(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ); - if (flags & URL_WRONLY) { + if (flags & AVIO_FLAG_WRITE) { s->buf_end = s->buffer + s->buffer_size; s->write_flag = 1; } else { @@ -992,11 +986,11 @@ char *url_fgets(AVIOContext *s, char *buf, int buf_size) char *q; c = avio_r8(s); - if (s->eof_reached) + if (url_feof(s)) return NULL; q = buf; for(;;) { - if (s->eof_reached || c == '\n') + if (url_feof(s) || c == '\n') break; if ((q - buf) < buf_size - 1) *q++ = c; @@ -1013,14 +1007,14 @@ int url_fget_max_packet_size(AVIOContext *s) } #endif -int ffio_read_pause(AVIOContext *s, int pause) +int avio_pause(AVIOContext *s, int pause) { if (!s->read_pause) return AVERROR(ENOSYS); return s->read_pause(s->opaque, pause); } -int64_t ffio_read_seek(AVIOContext *s, int stream_index, +int64_t avio_seek_time(AVIOContext *s, int stream_index, int64_t timestamp, int flags) { URLContext *h = s->opaque; @@ -1040,9 +1034,6 @@ int64_t ffio_read_seek(AVIOContext *s, int stream_index, return ret; } -/* avio_open_dyn_buf and avio_close_dyn_buf are used in rtp.c to send a response - * back to the server even if CONFIG_MUXERS is false. */ -#if CONFIG_MUXERS || CONFIG_NETWORK /* buffer handling */ #if FF_API_OLD_AVIO int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags) @@ -1052,7 +1043,7 @@ int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags) if(!*s) return AVERROR(ENOMEM); ret = ffio_init_context(*s, buf, buf_size, - (flags & URL_WRONLY || flags & URL_RDWR), + flags & AVIO_FLAG_WRITE, NULL, NULL, NULL, NULL); if(ret != 0) av_freep(s); @@ -1189,4 +1180,3 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) av_free(s); return size - padding; } -#endif /* CONFIG_MUXERS || CONFIG_NETWORK */