Bug 1077086 - Update nestegg from upstream. r=giles

This commit is contained in:
Matthew Gregan 2014-10-08 13:08:36 +13:00
parent 9fc8a1b4bc
commit e5e0237a06
3 changed files with 43 additions and 135 deletions

View File

@ -5,4 +5,4 @@ Makefile.in build files for the Mozilla build system.
The nestegg git repository is: git://github.com/kinetiknz/nestegg.git
The git commit ID used was 59220ae3e801cbad0f8160129c4df315469af671.
The git commit ID used was fa610276b66c2a62415fc957483e9adc0a55de5e.

View File

@ -171,8 +171,8 @@ void nestegg_destroy(nestegg * context);
int nestegg_duration(nestegg * context, uint64_t * duration);
/** Query the tstamp scale of the media stream in nanoseconds.
Timecodes presented by nestegg have been scaled by this value
before presentation to the caller.
@note Timecodes presented by nestegg have been scaled by this value
before presentation to the caller.
@param context Stream context initialized by #nestegg_init.
@param scale Storage for the queried scale factor.
@retval 0 Success.
@ -201,8 +201,8 @@ int nestegg_get_cue_point(nestegg * context, unsigned int cluster_num,
int64_t * end_pos, uint64_t * tstamp);
/** Seek to @a offset. Stream will seek directly to offset.
Should be used to seek to the start of a resync point, i.e. cluster; the
parser will not be able to understand other offsets.
Must be used to seek to the start of a cluster; the parser will not be
able to understand other offsets.
@param context Stream context initialized by #nestegg_init.
@param offset Absolute offset in bytes.
@retval 0 Success.
@ -368,23 +368,18 @@ int nestegg_packet_discard_padding(nestegg_packet * packet,
@retval 1 The media has cues. */
int nestegg_has_cues(nestegg * context);
/**
* Try to determine if the buffer looks like the beginning of a WebM file.
*
* @param buffer A buffer containing the beginning of a media file.
* @param length The size of the buffer.
* @retval 0 The file is not a WebM file.
* @retval 1 The file is a WebM file. */
/** Try to determine if the buffer looks like the beginning of a WebM file.
@param buffer A buffer containing the beginning of a media file.
@param length The size of the buffer.
@retval 0 The file is not a WebM file.
@retval 1 The file is a WebM file. */
int nestegg_sniff(unsigned char const * buffer, size_t length);
/**
* Set the underlying allocation function for library allocations.
*
* @param realloc_func The desired function.
* @retval 0 realloc_func(p, 0) does not act as free()
* @retval 1 realloc_func(p, 0) acts as free()
* @retval -1 malloc failed during realloc_func test
*/
/** Set the underlying allocation function for library allocations.
@param realloc_func The desired function.
@retval 1 Success. realloc_func(p, 0) acts as free()
@retval 0 Failure. realloc_func(p, 0) does not act as free()
@retval -1 Failure. realloc_func(NULL, 1) failed. */
int nestegg_set_halloc_func(void * (* realloc_func)(void *, size_t));
#if defined(__cplusplus)

View File

@ -321,18 +321,9 @@ struct block_additional {
struct block_additional * next;
};
#define NE_IO_BUFSZ 16384
struct nestegg_io_buf {
nestegg_io io;
unsigned char buffer[NE_IO_BUFSZ];
size_t bufsz;
int offset;
};
/* Public (opaque) Structures */
struct nestegg {
struct nestegg_io_buf * io;
nestegg_io * io;
nestegg_log log;
struct pool_ctx * alloc_pool;
uint64_t last_id;
@ -555,99 +546,19 @@ ne_alloc(size_t size)
}
static int
ne_io_read(struct nestegg_io_buf * io, void * buffer, size_t length)
ne_io_read(nestegg_io * io, void * buffer, size_t length)
{
int64_t off;
int r;
size_t avail;
assert(io->offset == -1 || (io->offset >= 0 && (unsigned int) io->offset < io->bufsz));
/* Too big to buffer, invalidate buffer and read through */
if (length > io->bufsz) {
if (io->offset != -1) {
r = io->io.seek(-(io->bufsz - io->offset), NESTEGG_SEEK_CUR, io->io.userdata);
if (r != 0) {
return -1;
}
}
io->offset = -1;
return io->io.read(buffer, length, io->io.userdata);
}
/* Buffer invalid */
if (io->offset == -1) {
off = io->io.tell(io->io.userdata);
if (off == -1) {
return -1;
}
/* Refill buffer */
r = io->io.read(io->buffer, io->bufsz, io->io.userdata);
if (r != 1) {
/* Read truncated due to being within io->bufsz of EOS, reset read
position and switch to read through mode */
io->offset = -1;
io->bufsz = 0;
if (r == 0) {
r = io->io.seek(off, NESTEGG_SEEK_SET, io->io.userdata);
}
if (r == 0) {
return io->io.read(buffer, length, io->io.userdata);
}
return -1;
}
if (r == 1) {
io->offset = 0;
}
}
/* Service request with what we have */
avail = length;
if (io->bufsz - io->offset < length) {
avail = io->bufsz - io->offset;
}
memcpy(buffer, io->buffer + io->offset, avail);
io->offset += avail;
if ((unsigned int) io->offset == io->bufsz) {
io->offset = -1;
}
/* Still more to read, invalidate buffer and read more */
if (length - avail > 0) {
return ne_io_read(io, (char *) buffer + avail, length - avail);
}
return 1;
return io->read(buffer, length, io->userdata);
}
static int
ne_io_seek(struct nestegg_io_buf * io, int64_t offset, int whence)
ne_io_seek(nestegg_io * io, int64_t offset, int whence)
{
/* Invalidate buffer */
io->offset = -1;
return io->io.seek(offset, whence, io->io.userdata);
}
static int64_t
ne_io_tell(struct nestegg_io_buf * io)
{
int64_t off;
off = io->io.tell(io->io.userdata);
if (off == -1) {
return -1;
}
if (io->offset == -1) {
return off;
}
assert(off >= (int64_t) io->bufsz - io->offset);
return off - io->bufsz + (unsigned int) io->offset;
return io->seek(offset, whence, io->userdata);
}
static int
ne_io_read_skip(struct nestegg_io_buf * io, size_t length)
ne_io_read_skip(nestegg_io * io, size_t length)
{
size_t get;
unsigned char buf[8192];
@ -664,8 +575,14 @@ ne_io_read_skip(struct nestegg_io_buf * io, size_t length)
return r;
}
static int64_t
ne_io_tell(nestegg_io * io)
{
return io->tell(io->userdata);
}
static int
ne_bare_read_vint(struct nestegg_io_buf * io, uint64_t * value, uint64_t * length, enum vint_mask maskflag)
ne_bare_read_vint(nestegg_io * io, uint64_t * value, uint64_t * length, enum vint_mask maskflag)
{
int r;
unsigned char b;
@ -702,19 +619,19 @@ ne_bare_read_vint(struct nestegg_io_buf * io, uint64_t * value, uint64_t * lengt
}
static int
ne_read_id(struct nestegg_io_buf * io, uint64_t * value, uint64_t * length)
ne_read_id(nestegg_io * io, uint64_t * value, uint64_t * length)
{
return ne_bare_read_vint(io, value, length, MASK_NONE);
}
static int
ne_read_vint(struct nestegg_io_buf * io, uint64_t * value, uint64_t * length)
ne_read_vint(nestegg_io * io, uint64_t * value, uint64_t * length)
{
return ne_bare_read_vint(io, value, length, MASK_FIRST_BIT);
}
static int
ne_read_svint(struct nestegg_io_buf * io, int64_t * value, uint64_t * length)
ne_read_svint(nestegg_io * io, int64_t * value, uint64_t * length)
{
int r;
uint64_t uvalue;
@ -736,7 +653,7 @@ ne_read_svint(struct nestegg_io_buf * io, int64_t * value, uint64_t * length)
}
static int
ne_read_uint(struct nestegg_io_buf * io, uint64_t * val, uint64_t length)
ne_read_uint(nestegg_io * io, uint64_t * val, uint64_t length)
{
unsigned char b;
int r;
@ -758,7 +675,7 @@ ne_read_uint(struct nestegg_io_buf * io, uint64_t * val, uint64_t length)
}
static int
ne_read_int(struct nestegg_io_buf * io, int64_t * val, uint64_t length)
ne_read_int(nestegg_io * io, int64_t * val, uint64_t length)
{
int r;
uint64_t uval, base;
@ -785,7 +702,7 @@ ne_read_int(struct nestegg_io_buf * io, int64_t * val, uint64_t length)
}
static int
ne_read_float(struct nestegg_io_buf * io, double * val, uint64_t length)
ne_read_float(nestegg_io * io, double * val, uint64_t length)
{
union {
uint64_t u;
@ -1220,7 +1137,7 @@ ne_xiph_lace_value(unsigned char ** np)
}
static int
ne_read_xiph_lace_value(struct nestegg_io_buf * io, uint64_t * value, size_t * consumed)
ne_read_xiph_lace_value(nestegg_io * io, uint64_t * value, size_t * consumed)
{
int r;
uint64_t lace;
@ -1243,7 +1160,7 @@ ne_read_xiph_lace_value(struct nestegg_io_buf * io, uint64_t * value, size_t * c
}
static int
ne_read_xiph_lacing(struct nestegg_io_buf * io, size_t block, size_t * read, uint64_t n, uint64_t * sizes)
ne_read_xiph_lacing(nestegg_io * io, size_t block, size_t * read, uint64_t n, uint64_t * sizes)
{
int r;
size_t i = 0;
@ -1266,7 +1183,7 @@ ne_read_xiph_lacing(struct nestegg_io_buf * io, size_t block, size_t * read, uin
}
static int
ne_read_ebml_lacing(struct nestegg_io_buf * io, size_t block, size_t * read, uint64_t n, uint64_t * sizes)
ne_read_ebml_lacing(nestegg_io * io, size_t block, size_t * read, uint64_t n, uint64_t * sizes)
{
int r;
uint64_t lace, sum, length;
@ -1944,9 +1861,7 @@ ne_match_webm(nestegg_io io, int64_t max_offset)
nestegg_destroy(ctx);
return -1;
}
ctx->io->io = io;
ctx->io->bufsz = NE_IO_BUFSZ;
ctx->io->offset = -1;
*ctx->io = io;
ctx->alloc_pool = ne_pool_init();
if (!ctx->alloc_pool) {
nestegg_destroy(ctx);
@ -2004,9 +1919,7 @@ nestegg_init(nestegg ** context, nestegg_io io, nestegg_log callback, int64_t ma
nestegg_destroy(ctx);
return -1;
}
ctx->io->io = io;
ctx->io->bufsz = NE_IO_BUFSZ;
ctx->io->offset = -1;
*ctx->io = io;
ctx->log = callback;
ctx->alloc_pool = ne_pool_init();
if (!ctx->alloc_pool) {
@ -2157,7 +2070,7 @@ nestegg_get_cue_point(nestegg * ctx, unsigned int cluster_num, int64_t max_offse
while (cue_pos_node) {
assert(cue_pos_node->id == ID_CUE_TRACK_POSITIONS);
pos = cue_pos_node->data;
for (track = 0; track < track_count; track++) {
for (track = 0; track < track_count; ++track) {
if (ne_get_uint(pos->track, &track_number) != 0)
return -1;
@ -2168,12 +2081,12 @@ nestegg_get_cue_point(nestegg * ctx, unsigned int cluster_num, int64_t max_offse
if (ne_get_uint(pos->cluster_position, &seek_pos) != 0)
return -1;
if (cluster_count == cluster_num) {
*start_pos = ctx->segment_offset+seek_pos;
*start_pos = ctx->segment_offset + seek_pos;
if (ne_get_uint(cue_point->time, &time) != 0)
return -1;
*tstamp = time * tc_scale;
} else if (cluster_count == cluster_num+1) {
*end_pos = (ctx->segment_offset+seek_pos)-1;
} else if (cluster_count == cluster_num + 1) {
*end_pos = ctx->segment_offset + seek_pos - 1;
range_obtained = 1;
break;
}