]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
O_DIRECT works!!!
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 8 May 2010 20:41:49 +0000 (22:41 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 8 May 2010 20:41:49 +0000 (22:41 +0200)
libavformat/avio.h
libavformat/aviobuf.c

index b8b35afe84e4b25ce7b5ba93073ac3a5707bec76..d031096bd469e3e7add711c9eb09225efbfd8a75 100644 (file)
@@ -199,6 +199,7 @@ typedef struct {
     int eof_reached; /**< true if eof reached */
     int write_flag;  /**< true if open for writing */
     int o_direct_flag; /**< true if the underlaying file is open with O_DIRECT */
+    int flush_all; /**< Used during seek when o_direct_flag is set */
     int is_streamed;
     int max_packet_size;
     unsigned long checksum;
index 5a67959a811fe696ef6a664734af38dec3c4b7d7..601ea4fc70a949988add8c6ca1c5859be4c02e2a 100644 (file)
@@ -84,17 +84,12 @@ ByteIOContext *av_alloc_put_byte(
 static void flush_buffer_o_direct(ByteIOContext *s)
 {
     size_t data_len = s->buf_ptr - s->buffer;
+    size_t to_write = data_len & ~(BLOCK_SIZE - 1);
 
-    /* Write all data in the buffer to the disk together with any
-     * additional space at the end of the buffer up to the first
-     * multiple of BLOCK_SIZE. The last block is always written to the
-     * disk despite not being fully filled. If the last block is not
-     * fully filled, we keep it (moved to the begginig of the buffer)
-     * and any subsequent call to this function will rewrite the block
-     * together with the additional data added to the buffer. */
-    size_t to_write = (data_len + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1);
-    size_t whole_blocks = data_len & ~(BLOCK_SIZE - 1);
-    int64_t res = AVERROR(EPIPE);
+    if (s->flush_all) {
+       s->flush_all = 0;
+       to_write = (data_len + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1);
+    }
 
     av_log(NULL, AV_LOG_ERROR, "          really writing %zx\n", to_write);
     if (data_len > 0) {
@@ -110,13 +105,13 @@ static void flush_buffer_o_direct(ByteIOContext *s)
             s->checksum_ptr= s->buffer;
         }
         s->pos += to_write;
-       memcpy(s->buffer, &s->buffer[whole_blocks], data_len - whole_blocks);
-       s->buf_ptr -= whole_blocks;
+       if (data_len > to_write) {
+           /* flush_all was not set */
+           memcpy(s->buffer, &s->buffer[to_write], data_len - to_write);
+           s->buf_ptr -= to_write;
+       } else
+           s->buf_ptr = s->buffer;
 
-        if (s->seek)
-           res = s->seek(s->opaque, s->pos - to_write + whole_blocks, SEEK_SET);
-       if (res < 0)
-           av_log(NULL, AV_LOG_ERROR, "seek error inside %s: %lld\n", __func__, res);
        //av_log(NULL, AV_LOG_ERROR, "ZZZ tw=%zu, pos=%zd\n", to_write, s->pos);
     }
 }
@@ -217,6 +212,7 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)
 
 #if CONFIG_MUXERS || CONFIG_NETWORK
         if (s->write_flag) {
+           s->flush_all = 1;
             flush_buffer(s);
             s->must_flush = 1;
         }
@@ -232,7 +228,7 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)
            if (!s->seek || (res = s->seek(s->opaque, offset1, SEEK_SET)) < 0)
                return res;
            s->buf_ptr = s->buffer + offset - offset1;
-           s->pos = offset;
+           s->pos = offset1;
        } else {
            if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
                return res;