]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Started attempt to fix seek handling - still not completed
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 7 May 2010 21:42:32 +0000 (23:42 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 7 May 2010 21:42:32 +0000 (23:42 +0200)
libavformat/aviobuf.c

index 865a76ad1980a5ad52f337a54f28a78abd0320e5..1dac20298db2a4b6490f89e8159e8260b790849b 100644 (file)
@@ -85,7 +85,7 @@ static void flush_buffer_o_direct(ByteIOContext *s)
 {
     size_t data_len = s->buf_ptr - s->buffer;
 
-    /* Write all the data in the buffer to the disk together with any
+    /* 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
@@ -95,7 +95,6 @@ static void flush_buffer_o_direct(ByteIOContext *s)
     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, "%p: YYY dl=%zd, tw=%zd\n", s, 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);
@@ -108,20 +107,21 @@ static void flush_buffer_o_direct(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 += whole_blocks;
+        s->pos += to_write;
        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);
+           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 flush_buffer: %lld\n", res);
+           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);
     }
 }
 
 static void flush_buffer(ByteIOContext *s)
 {
+    av_log(NULL, AV_LOG_ERROR, "WRITE %p: pos=%zd len=%zd\n", s, s->pos, s->buf_ptr - s->buffer);
     if (s->o_direct_flag) {
        flush_buffer_o_direct(s);
        return;
@@ -193,14 +193,16 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)
             return offset1;
         offset += offset1;
     }
-    av_log(NULL, AV_LOG_ERROR, "%p: SEEK from %llu to %llu\n", s, pos, offset);
+    //if (s->o_direct_flag)
+    av_log(NULL, AV_LOG_ERROR, "SEEK  %p: from %llu to %llu\n", s, pos, offset);
 
     offset1 = offset - pos;
     if (!s->must_flush &&
         offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
         /* can do the seek inside the buffer */
         s->buf_ptr = s->buffer + offset1;
-       av_log(NULL, AV_LOG_ERROR, "Internal seek by %llu\n", offset1);
+       if (s->o_direct_flag)
+           av_log(NULL, AV_LOG_ERROR, "Internal seek by %llu\n", offset1);
     } else if(s->is_streamed && !s->write_flag &&
               offset1 >= 0 && offset1 < (s->buf_end - s->buffer) + (1<<16)){
         while(s->pos < offset && !s->eof_reached)
@@ -658,6 +660,7 @@ int url_fopen(ByteIOContext **s, const char *filename, int flags)
     URLContext *h;
     int err;
 
+    av_log(NULL, AV_LOG_ERROR, "%s: %p %s\n", __func__, s, filename);
     err = url_open(&h, filename, flags);
     if (err < 0)
         return err;