-#warning TODO read the whole block from the file to the buffer
- if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
- return res;
- if (!s->write_flag)
- s->buf_end = s->buffer;
- s->buf_ptr = s->buffer;
- s->pos = offset;
+ if (s->o_direct_flag) {
+ /* Read the whole block from the seek destination */
+ offset1 = offset & ~(BLOCK_SIZE - 1);
+ if (!s->seek || (res = s->seek(s->opaque, offset1, SEEK_SET)) < 0)
+ return res;
+ av_log(NULL, AV_LOG_ERROR, "READ block from %llx\n", offset1);
+ if ((res = s->read_packet(s->opaque, s->buffer, BLOCK_SIZE)) < 0)
+ return res;
+ if (!s->seek || (res = s->seek(s->opaque, offset1, SEEK_SET)) < 0)
+ return res;
+ s->buf_ptr = s->buffer + offset - offset1;
+ s->pos = offset;
+ } else {
+ if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
+ return res;
+ if (!s->write_flag)
+ s->buf_end = s->buffer;
+ s->buf_ptr = s->buffer;
+ s->pos = offset;
+ }