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, " really writing %zx\n", to_write);
if (data_len > 0) {
if (s->write_packet && !s->error){
int ret= s->write_packet(s->opaque, s->buffer, to_write);
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);
+ av_log(NULL, AV_LOG_ERROR, "WRITE %p: pos=%zx len=%zx\n", s, s->pos, s->buf_ptr - s->buffer);
if (s->o_direct_flag) {
flush_buffer_o_direct(s);
return;
offset += offset1;
}
//if (s->o_direct_flag)
- av_log(NULL, AV_LOG_ERROR, "SEEK %p: from %llu to %llu\n", s, pos, offset);
+ av_log(NULL, AV_LOG_ERROR, "SEEK %p: from %llx to %llx\n", s, pos, offset);
offset1 = offset - pos;
if (!s->must_flush &&
/* can do the seek inside the buffer */
s->buf_ptr = s->buffer + offset1;
if (s->o_direct_flag)
- av_log(NULL, AV_LOG_ERROR, "Internal seek by %llu\n", offset1);
+ av_log(NULL, AV_LOG_ERROR, "Internal seek by %llx\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)
s->must_flush = 1;
}
#endif /* CONFIG_MUXERS || CONFIG_NETWORK */
-#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;
+ }
}
s->eof_reached = 0;
return offset;
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;