]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/aviobuf.c
init packet before calling the demuxer
[ffmpeg] / libavformat / aviobuf.c
index fe93546edd6dafb50f3b3c7d8304d2636369ca20..2cc247b62c9c7f02fddb2cc31fe919380a7c8789 100644 (file)
@@ -117,7 +117,7 @@ offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
     offset_t pos= s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer));
 
     if (whence != SEEK_CUR && whence != SEEK_SET)
-        return -EINVAL;
+        return AVERROR(EINVAL);
 
     if (whence == SEEK_CUR) {
         offset1 = pos + (s->buf_ptr - s->buffer);
@@ -136,18 +136,20 @@ offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
             fill_buffer(s);
         s->buf_ptr = s->buf_end + offset - s->pos;
     } else {
-#ifdef CONFIG_MUXERS
+        offset_t res = AVERROR(EPIPE);
+
+#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
         if (s->write_flag) {
             flush_buffer(s);
             s->must_flush = 1;
         } else
-#endif //CONFIG_MUXERS
+#endif /* defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK) */
         {
             s->buf_end = s->buffer;
         }
         s->buf_ptr = s->buffer;
-        if (!s->seek || s->seek(s->opaque, offset, SEEK_SET) == (offset_t)-EPIPE)
-            return -EPIPE;
+        if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
+            return res;
         s->pos = offset;
     }
     s->eof_reached = 0;
@@ -169,9 +171,14 @@ 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 AVERROR(EPIPE);
+    size = s->seek(s->opaque, 0, AVSEEK_SIZE);
+    if(size<0){
+        if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
+            return size;
+        size++;
+        s->seek(s->opaque, s->pos, SEEK_SET);
+    }
     return size;
 }
 
@@ -185,7 +192,6 @@ int url_ferror(ByteIOContext *s)
     return s->error;
 }
 
-#if defined(CONFIG_MUXERS) || defined(CONFIG_PROTOCOLS)
 void put_le32(ByteIOContext *s, unsigned int val)
 {
     put_byte(s, val);
@@ -252,7 +258,6 @@ void put_tag(ByteIOContext *s, const char *tag)
         put_byte(s, *tag++);
     }
 }
-#endif //CONFIG_MUXERS || CONFIG_PROTOCOLS
 
 /* Input stream */
 
@@ -298,8 +303,6 @@ void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned l
     }
 }
 
-/* NOTE: return 0 if EOF, so you cannot use it if EOF handling is
-   necessary */
 /* XXX: put an inline version */
 int get_byte(ByteIOContext *s)
 {
@@ -314,7 +317,6 @@ int get_byte(ByteIOContext *s)
     }
 }
 
-/* NOTE: return URL_EOF (-1) if EOF */
 int url_fgetc(ByteIOContext *s)
 {
     if (s->buf_ptr < s->buf_end) {
@@ -506,7 +508,7 @@ int url_fdopen(ByteIOContext *s, URLContext *h)
     }
     buffer = av_malloc(buffer_size);
     if (!buffer)
-        return -ENOMEM;
+        return AVERROR(ENOMEM);
 
     if (init_put_byte(s, buffer, buffer_size,
                       (h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
@@ -519,13 +521,12 @@ int url_fdopen(ByteIOContext *s, URLContext *h)
     return 0;
 }
 
-/* XXX: must be called before any I/O */
 int url_setbufsize(ByteIOContext *s, int buf_size)
 {
     uint8_t *buffer;
     buffer = av_malloc(buf_size);
     if (!buffer)
-        return -ENOMEM;
+        return AVERROR(ENOMEM);
 
     av_free(s->buffer);
     s->buffer = buffer;
@@ -538,8 +539,6 @@ int url_setbufsize(ByteIOContext *s, int buf_size)
     return 0;
 }
 
-/* NOTE: when opened as read/write, the buffers are only used for
-   reading */
 int url_fopen(ByteIOContext *s, const char *filename, int flags)
 {
     URLContext *h;
@@ -571,7 +570,6 @@ URLContext *url_fileno(ByteIOContext *s)
 }
 
 #ifdef CONFIG_MUXERS
-/* XXX: currently size is limited */
 int url_fprintf(ByteIOContext *s, const char *fmt, ...)
 {
     va_list ap;
@@ -586,8 +584,6 @@ int url_fprintf(ByteIOContext *s, const char *fmt, ...)
 }
 #endif //CONFIG_MUXERS
 
-/* note: unlike fgets, the EOL character is not returned and a whole
-   line is parsed. return NULL if first char read was EOF */
 char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
 {
     int c;
@@ -609,20 +605,14 @@ char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
     return buf;
 }
 
-/*
- * Return the maximum packet size associated to packetized buffered file
- * handle. If the file is not packetized (stream like http or file on
- * disk), then 0 is returned.
- *
- * @param h buffered file handle
- * @return maximum packet size in bytes
- */
 int url_fget_max_packet_size(ByteIOContext *s)
 {
     return s->max_packet_size;
 }
 
-#ifdef CONFIG_MUXERS
+/* url_open_dyn_buf and url_close_dyn_buf are used in rtp.c to send a response
+ * back to the server even if CONFIG_MUXERS is not set. */
+#if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK)
 /* buffer handling */
 int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags)
 {
@@ -631,7 +621,6 @@ int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags)
                          NULL, NULL, NULL, NULL);
 }
 
-/* return the written or read size */
 int url_close_buf(ByteIOContext *s)
 {
     put_flush_packet(s);
@@ -739,26 +728,11 @@ static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size)
     return ret;
 }
 
-/*
- * Open a write only memory stream.
- *
- * @param s new IO context
- * @return zero if no error.
- */
 int url_open_dyn_buf(ByteIOContext *s)
 {
     return url_open_dyn_buf_internal(s, 0);
 }
 
-/*
- * Open a write only packetized memory stream with a maximum packet
- * size of 'max_packet_size'.  The stream is stored in a memory buffer
- * with a big endian 4 byte header giving the packet size in bytes.
- *
- * @param s new IO context
- * @param max_packet_size maximum packet size (must be > 0)
- * @return zero if no error.
- */
 int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
 {
     if (max_packet_size <= 0)
@@ -766,13 +740,6 @@ int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
     return url_open_dyn_buf_internal(s, max_packet_size);
 }
 
-/*
- * Return the written size and a pointer to the buffer. The buffer
- *  must be freed with av_free().
- * @param s IO context
- * @param pointer to a byte buffer
- * @return the length of the byte buffer
- */
 int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
 {
     DynBuffer *d = s->opaque;
@@ -785,4 +752,4 @@ int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
     av_free(d);
     return size;
 }
-#endif //CONFIG_MUXERS
+#endif /* CONFIG_MUXERS || CONFIG_NETWORK */