/* TODO: Support offset > INT64_MAX */ int64_t lsmash_bs_read_seek( lsmash_bs_t *bs, int64_t offset, int whence ) { if( whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END ) return LSMASH_ERR_FUNCTION_PARAM; if( whence == SEEK_CUR ) offset -= lsmash_bs_get_remaining_buffer_size( bs ); /* Check whether we can seek on the buffer. */ if( !bs->buffer.unseekable ) { assert( bs->offset >= bs->buffer.store ); uint64_t dst_offset = bs_estimate_seek_offset( bs, offset, whence ); uint64_t offset_s = bs->offset - bs->buffer.store; uint64_t offset_e = bs->offset; if( bs->unseekable || (dst_offset >= offset_s && dst_offset < offset_e) ) { /* OK, we can. So, seek on the buffer. */ bs->buffer.pos = dst_offset - offset_s; bs->eob = 0; return lsmash_bs_get_stream_pos( bs ); } } if( bs->unseekable ) return LSMASH_ERR_NAMELESS; /* Try to seek the stream. */ int64_t ret = bs->seek( bs->stream, offset, whence ); if( ret < 0 ) return ret; bs->offset = ret; bs->written = LSMASH_MAX( bs->written, bs->offset ); bs->eof = 0; bs->eob = 0; /* The data on the buffer is invalid. */ lsmash_bs_empty( bs ); return ret; }
/* TODO: Support offset > INT64_MAX */ int64_t lsmash_bs_write_seek( lsmash_bs_t *bs, int64_t offset, int whence ) { if( bs->unseekable || (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) ) return -1; /* Try to seek the stream. */ int64_t ret = bs->seek( bs->stream, offset, whence ); if( ret < 0 ) return ret; bs->offset = bs_estimate_seek_offset( bs, offset, whence ); bs->eof = 0; bs->eob = 0; return ret; }
/* TODO: Support offset > INT64_MAX */ int64_t lsmash_bs_write_seek( lsmash_bs_t *bs, int64_t offset, int whence ) { if( bs->unseekable ) return LSMASH_ERR_NAMELESS; if( whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END ) return LSMASH_ERR_FUNCTION_PARAM; /* Try to seek the stream. */ int64_t ret = bs->seek( bs->stream, offset, whence ); if( ret < 0 ) return ret; bs->offset = bs_estimate_seek_offset( bs, offset, whence ); bs->eof = 0; bs->eob = 0; return ret; }