]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Some cleanup and comment
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 6 May 2010 20:25:34 +0000 (22:25 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 6 May 2010 20:25:34 +0000 (22:25 +0200)
libavformat/aviobuf.c

index 491e7c76d8689ca129261158f8a4c0bcfb90330d..04e519916e41549f2145a77d44d7d34ec0c5185a 100644 (file)
@@ -84,10 +84,19 @@ ByteIOContext *av_alloc_put_byte(
 static void flush_buffer(ByteIOContext *s)
 {
     size_t data_len = s->buf_ptr - s->buffer;
+
+    /* Write all the 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);
-    av_log(NULL, AV_LOG_ERROR, "YYY dl=%u, tw=%u\n", data_len, to_write);
-    if (s->buf_ptr > s->buffer) {
+    av_log(NULL, AV_LOG_ERROR, "YYY dl=%zd, tw=%zd\n", data_len, to_write);
+    if (data_len > 0) {
         if (s->write_packet && !s->error){
             int ret= s->write_packet(s->opaque, s->buffer, to_write);
             if(ret < 0){
@@ -99,15 +108,15 @@ static void flush_buffer(ByteIOContext *s)
             s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
             s->checksum_ptr= s->buffer;
         }
-        s->pos += to_write - BLOCK_SIZE;
-       memcpy(s->buffer, &s->buffer[to_write], data_len - to_write + BLOCK_SIZE);
-       s->buf_ptr -= to_write - BLOCK_SIZE;
+        s->pos += whole_blocks;
+       memcpy(s->buffer, &s->buffer[whole_blocks], data_len - whole_blocks);
+       s->buf_ptr -= whole_blocks;
 
         if (s->seek)
            res = s->seek(s->opaque, s->pos, SEEK_SET);
        if (res < 0)
            av_log(NULL, AV_LOG_ERROR, "seek error inside flush_buffer: %lld\n", res);
-       av_log(NULL, AV_LOG_ERROR, "ZZZ tw=%u, pos=%d\n", to_write, s->pos);
+       av_log(NULL, AV_LOG_ERROR, "ZZZ tw=%zu, pos=%zd\n", to_write, s->pos);
     }
 }