summaryrefslogtreecommitdiff
path: root/libavformat/avio.h
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2017-06-04 01:15:50 +0200
committerMarton Balint <cus@passwd.hu>2017-06-24 18:51:29 +0200
commitc14fa7a330f634738003bee731f17ff4c5717228 (patch)
treec0a48fc4bd9c2a5b8b4642c833c9f9245de1cbb4 /libavformat/avio.h
parentdc81f1a2cef11538401ee1ca13b76e61838283e6 (diff)
downloadffmpeg-c14fa7a330f634738003bee731f17ff4c5717228.tar.gz
avformat/aviobuf: fix flushing write buffers after seeking backward or forward
This patch makes aviobuf work more like traditinal file IO, which is how people think about it. For example, in the past, aviobuf only flushed buffers until the current buffer position, even if more data was written to it previously, and a backward seek was used to reposition the IO context. From now, aviobuf will keep track of the written data, so no explicit seek will be required till the end of the buffer, or till the end of file before flushing. This fixes at least one regression, fate-vsynth3-flv was broken if flush_packets option was set to false, an explicit seek was removed in 4e3cc4bdd8acedbcc703607ed0efbb64bb5c3cc4. Also from now on, if a forward seek in the write buffer were to cause a gap between the already written data and the new file position, a flush will happen. The must_flush varable is also removed, which might have caused needless flushes with multiple seeks whithin the write buffer. Since we know the amount of data written to it, we will know when to flush. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/avio.h')
-rw-r--r--libavformat/avio.h42
1 files changed, 26 insertions, 16 deletions
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 525eb7129e..844a5723d3 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -168,8 +168,9 @@ typedef struct AVIOContext {
const AVClass *av_class;
/*
- * The following shows the relationship between buffer, buf_ptr, buf_end, buf_size,
- * and pos, when reading and when writing (since AVIOContext is used for both):
+ * The following shows the relationship between buffer, buf_ptr,
+ * buf_ptr_max, buf_end, buf_size, and pos, when reading and when writing
+ * (since AVIOContext is used for both):
*
**********************************************************************************
* READING
@@ -196,21 +197,24 @@ typedef struct AVIOContext {
* WRITING
**********************************************************************************
*
- * | buffer_size |
- * |-------------------------------|
- * | |
+ * | buffer_size |
+ * |--------------------------------------|
+ * | |
*
- * buffer buf_ptr buf_end
- * +-------------------+-----------+
- * |/ / / / / / / / / /| |
- * write buffer: | / to be flushed / | |
- * |/ / / / / / / / / /| |
- * +-------------------+-----------+
+ * buf_ptr_max
+ * buffer (buf_ptr) buf_end
+ * +-----------------------+--------------+
+ * |/ / / / / / / / / / / /| |
+ * write buffer: | / / to be flushed / / | |
+ * |/ / / / / / / / / / / /| |
+ * +-----------------------+--------------+
+ * buf_ptr can be in this
+ * due to a backward seek
*
- * pos
- * +--------------------------+-----------------------------------+
- * output file: | | |
- * +--------------------------+-----------------------------------+
+ * pos
+ * +-------------+----------------------------------------------+
+ * output file: | | |
+ * +-------------+----------------------------------------------+
*
*/
unsigned char *buffer; /**< Start of the buffer. */
@@ -226,7 +230,7 @@ typedef struct AVIOContext {
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
int64_t (*seek)(void *opaque, int64_t offset, int whence);
int64_t pos; /**< position in the file of the current buffer */
- int must_flush; /**< true if the next seek should flush */
+ int must_flush; /**< unused */
int eof_reached; /**< true if eof reached */
int write_flag; /**< true if open for writing */
int max_packet_size;
@@ -329,6 +333,12 @@ typedef struct AVIOContext {
int (*short_seek_get)(void *opaque);
int64_t written;
+
+ /**
+ * Maximum reached position before a backward seek in the write buffer,
+ * used keeping track of already written data for a later flush.
+ */
+ unsigned char *buf_ptr_max;
} AVIOContext;
/**