summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
Diffstat (limited to 'demux')
-rw-r--r--demux/demux_mkv.c30
-rw-r--r--demux/ebml.c27
-rw-r--r--demux/ebml.h9
3 files changed, 27 insertions, 39 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 172ff5bde2..f805c24c0a 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -773,7 +773,7 @@ static void read_deferred_cues(demuxer_t *demuxer)
MP_WARN(demuxer, "Failed to seek to cues\n");
return;
}
- if (ebml_read_id(s, NULL) != MATROSKA_ID_CUES) {
+ if (ebml_read_id(s) != MATROSKA_ID_CUES) {
MP_WARN(demuxer, "Expected element not found\n");
return;
}
@@ -1044,7 +1044,7 @@ static bool seek_pos_id(struct demuxer *demuxer, int64_t pos, uint32_t id)
MP_WARN(demuxer, "Failed to seek in file\n");
return false;
}
- if (ebml_read_id(s, NULL) != id) {
+ if (ebml_read_id(s) != id) {
MP_WARN(demuxer, "Expected element not found\n");
return false;
}
@@ -1708,7 +1708,7 @@ static int read_ebml_header(demuxer_t *demuxer)
{
stream_t *s = demuxer->stream;
- if (ebml_read_id(s, NULL) != EBML_ID_EBML)
+ if (ebml_read_id(s) != EBML_ID_EBML)
return 0;
struct ebml_ebml ebml_master = {{0}};
struct ebml_parse_ctx parse_ctx = { demuxer->log, .no_error_messages = true };
@@ -1755,12 +1755,12 @@ static int read_mkv_segment_header(demuxer_t *demuxer)
num_skip = demuxer->params->matroska_wanted_segment;
while (!s->eof) {
- if (ebml_read_id(s, NULL) != MATROSKA_ID_SEGMENT) {
+ if (ebml_read_id(s) != MATROSKA_ID_SEGMENT) {
MP_VERBOSE(demuxer, "segment not found\n");
return 0;
}
MP_VERBOSE(demuxer, "+ a segment...\n");
- uint64_t len = ebml_read_length(s, NULL);
+ uint64_t len = ebml_read_length(s);
if (num_skip <= 0)
return 1;
num_skip--;
@@ -1806,7 +1806,7 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check)
*demuxer->params->matroska_was_valid = true;
while (1) {
- uint32_t id = ebml_read_id(s, NULL);
+ uint32_t id = ebml_read_id(s);
if (s->eof) {
MP_WARN(demuxer, "Unexpected end of file (no clusters found)\n");
break;
@@ -2277,7 +2277,7 @@ static int read_block(demuxer_t *demuxer, int64_t end, struct block_info *block)
int res = -1;
free_block(block);
- length = ebml_read_length(s, NULL);
+ length = ebml_read_length(s);
if (length > 500000000 || stream_tell(s) + length > (uint64_t)end)
goto exit;
block->alloc = malloc(length + AV_LZO_INPUT_PADDING);
@@ -2430,9 +2430,9 @@ static int read_block_group(demuxer_t *demuxer, int64_t end,
*block = (struct block_info){ .keyframe = true };
while (stream_tell(s) < end) {
- switch (ebml_read_id(s, NULL)) {
+ switch (ebml_read_id(s)) {
case MATROSKA_ID_BLOCKDURATION:
- block->duration = ebml_read_uint(s, NULL);
+ block->duration = ebml_read_uint(s);
if (block->duration == EBML_UINT_INVALID)
goto error;
block->duration *= mkv_d->tc_scale;
@@ -2444,7 +2444,7 @@ static int read_block_group(demuxer_t *demuxer, int64_t end,
break;
case MATROSKA_ID_REFERENCEBLOCK:;
- int64_t num = ebml_read_int(s, NULL);
+ int64_t num = ebml_read_int(s);
if (num == EBML_INT_INVALID)
goto error;
if (num)
@@ -2477,9 +2477,9 @@ static int read_next_block(demuxer_t *demuxer, struct block_info *block)
while (1) {
while (stream_tell(s) < mkv_d->cluster_end) {
int64_t start_filepos = stream_tell(s);
- switch (ebml_read_id(s, NULL)) {
+ switch (ebml_read_id(s)) {
case MATROSKA_ID_TIMECODE: {
- uint64_t num = ebml_read_uint(s, NULL);
+ uint64_t num = ebml_read_uint(s);
if (num == EBML_UINT_INVALID)
goto find_next_cluster;
mkv_d->cluster_tc = num * mkv_d->tc_scale;
@@ -2487,7 +2487,7 @@ static int read_next_block(demuxer_t *demuxer, struct block_info *block)
}
case MATROSKA_ID_BLOCKGROUP: {
- int64_t end = ebml_read_length(s, NULL);
+ int64_t end = ebml_read_length(s);
end += stream_tell(s);
if (end > mkv_d->cluster_end)
goto find_next_cluster;
@@ -2527,7 +2527,7 @@ static int read_next_block(demuxer_t *demuxer, struct block_info *block)
mkv_d->cluster_end = 0;
for (;;) {
mkv_d->cluster_start = stream_tell(s);
- uint32_t id = ebml_read_id(s, NULL);
+ uint32_t id = ebml_read_id(s);
if (id == MATROSKA_ID_CLUSTER)
break;
if (s->eof)
@@ -2541,7 +2541,7 @@ static int read_next_block(demuxer_t *demuxer, struct block_info *block)
}
}
next_cluster:
- mkv_d->cluster_end = ebml_read_length(s, NULL);
+ mkv_d->cluster_end = ebml_read_length(s);
// mkv files for "streaming" can have this legally
if (mkv_d->cluster_end != EBML_UINT_INVALID)
mkv_d->cluster_end += stream_tell(s);
diff --git a/demux/ebml.c b/demux/ebml.c
index d50647e5f0..f420616aa9 100644
--- a/demux/ebml.c
+++ b/demux/ebml.c
@@ -65,7 +65,7 @@ bool ebml_is_mkv_level1_id(uint32_t id)
* Read: the element content data ID.
* Return: the ID.
*/
-uint32_t ebml_read_id(stream_t *s, int *length)
+uint32_t ebml_read_id(stream_t *s)
{
int i, len_mask = 0x80;
uint32_t id;
@@ -74,8 +74,6 @@ uint32_t ebml_read_id(stream_t *s, int *length)
len_mask >>= 1;
if (i >= 4)
return EBML_ID_INVALID;
- if (length)
- *length = i + 1;
while (i--)
id = (id << 8) | stream_read_char(s);
return id;
@@ -134,7 +132,7 @@ int64_t ebml_read_vlen_int(bstr *buffer)
/*
* Read: element content length.
*/
-uint64_t ebml_read_length(stream_t *s, int *length)
+uint64_t ebml_read_length(stream_t *s)
{
int i, j, num_ffs = 0, len_mask = 0x80;
uint64_t len;
@@ -144,8 +142,6 @@ uint64_t ebml_read_length(stream_t *s, int *length)
if (i >= 8)
return EBML_UINT_INVALID;
j = i + 1;
- if (length)
- *length = j;
if ((int) (len &= (len_mask - 1)) == len_mask - 1)
num_ffs++;
while (i--) {
@@ -163,16 +159,13 @@ uint64_t ebml_read_length(stream_t *s, int *length)
/*
* Read the next element as an unsigned int.
*/
-uint64_t ebml_read_uint(stream_t *s, uint64_t *length)
+uint64_t ebml_read_uint(stream_t *s)
{
uint64_t len, value = 0;
- int l;
- len = ebml_read_length(s, &l);
+ len = ebml_read_length(s);
if (len == EBML_UINT_INVALID || len < 1 || len > 8)
return EBML_UINT_INVALID;
- if (length)
- *length = len + l;
while (len--)
value = (value << 8) | stream_read_char(s);
@@ -183,17 +176,15 @@ uint64_t ebml_read_uint(stream_t *s, uint64_t *length)
/*
* Read the next element as a signed int.
*/
-int64_t ebml_read_int(stream_t *s, uint64_t *length)
+int64_t ebml_read_int(stream_t *s)
{
int64_t value = 0;
uint64_t len;
int l;
- len = ebml_read_length(s, &l);
+ len = ebml_read_length(s);
if (len == EBML_UINT_INVALID || len < 1 || len > 8)
return EBML_INT_INVALID;
- if (length)
- *length = len + l;
len--;
l = stream_read_char(s);
@@ -213,11 +204,10 @@ int64_t ebml_read_int(stream_t *s, uint64_t *length)
int ebml_read_skip(struct mp_log *log, int64_t end, stream_t *s)
{
uint64_t len;
- int l;
int64_t pos = stream_tell(s);
- len = ebml_read_length(s, &l);
+ len = ebml_read_length(s);
if (len == EBML_UINT_INVALID)
goto invalid;
@@ -613,7 +603,7 @@ int ebml_read_element(struct stream *s, struct ebml_parse_ctx *ctx,
{
ctx->has_errors = false;
int msglevel = ctx->no_error_messages ? MSGL_DEBUG : MSGL_WARN;
- uint64_t length = ebml_read_length(s, &ctx->bytes_read);
+ uint64_t length = ebml_read_length(s);
if (s->eof) {
MP_MSG(ctx, msglevel, "Unexpected end of file "
"- partial or corrupt file?\n");
@@ -625,7 +615,6 @@ int ebml_read_element(struct stream *s, struct ebml_parse_ctx *ctx,
}
ctx->talloc_ctx = talloc_size(NULL, length + 8);
int read_len = stream_read(s, ctx->talloc_ctx, length);
- ctx->bytes_read += read_len;
if (read_len < length)
MP_MSG(ctx, msglevel, "Unexpected end of file - partial or corrupt file?\n");
ebml_parse_element(ctx, target, ctx->talloc_ctx, read_len, desc, 0);
diff --git a/demux/ebml.h b/demux/ebml.h
index 80943d33e4..5a0af48e8c 100644
--- a/demux/ebml.h
+++ b/demux/ebml.h
@@ -61,7 +61,6 @@ struct ebml_elem_desc {
struct ebml_parse_ctx {
struct mp_log *log;
void *talloc_ctx;
- int bytes_read;
bool has_errors;
bool no_error_messages;
};
@@ -93,12 +92,12 @@ struct ebml_parse_ctx {
bool ebml_is_mkv_level1_id(uint32_t id);
-uint32_t ebml_read_id (stream_t *s, int *length);
+uint32_t ebml_read_id (stream_t *s);
uint64_t ebml_read_vlen_uint (bstr *buffer);
int64_t ebml_read_vlen_int (bstr *buffer);
-uint64_t ebml_read_length (stream_t *s, int *length);
-uint64_t ebml_read_uint (stream_t *s, uint64_t *length);
-int64_t ebml_read_int (stream_t *s, uint64_t *length);
+uint64_t ebml_read_length (stream_t *s);
+uint64_t ebml_read_uint (stream_t *s);
+int64_t ebml_read_int (stream_t *s);
int ebml_read_skip(struct mp_log *log, int64_t end, stream_t *s);
int ebml_resync_cluster(struct mp_log *log, stream_t *s);