From db41501f230f8f29c1c32584bc4d12dfc87ce498 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Tue, 26 Jan 2010 14:41:07 +0200 Subject: [PATCH] demux_mkv: use new EBML parser to read Audio element --- libmpdemux/demux_mkv.c | 66 ++++++++++++++---------------------------- libmpdemux/ebml.c | 3 +- libmpdemux/ebml.h | 1 + 3 files changed, 25 insertions(+), 45 deletions(-) diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index 288335c39c..3234171256 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -599,52 +599,30 @@ static int demux_mkv_read_trackencodings(demuxer_t *demuxer, static int demux_mkv_read_trackaudio(demuxer_t *demuxer, mkv_track_t *track) { stream_t *s = demuxer->stream; - uint64_t len, length, l; - uint64_t num; - double fnum; - int il; - track->a_sfreq = 8000.0; - track->a_channels = 1; - - len = length = ebml_read_length(s, &il); - len += il; - while (length > 0) { - switch (ebml_read_id(s, &il)) { - case MATROSKA_ID_SAMPLINGFREQUENCY: - fnum = ebml_read_float(s, &l); - if (fnum == EBML_FLOAT_INVALID) - return 0; - track->a_sfreq = fnum; - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] | + Sampling frequency: %f\n", track->a_sfreq); - break; - - case MATROSKA_ID_BITDEPTH: - num = ebml_read_uint(s, &l); - if (num == EBML_UINT_INVALID) - return 0; - track->a_bps = num; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n", - track->a_bps); - break; - - case MATROSKA_ID_CHANNELS: - num = ebml_read_uint(s, &l); - if (num == EBML_UINT_INVALID) - return 0; - track->a_channels = num; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n", - track->a_channels); - break; - - default: - ebml_read_skip(s, &l); - break; - } - length -= l + il; + struct ebml_audio audio = {}; + struct ebml_parse_ctx parse_ctx = {}; + if (ebml_read_element(s, &parse_ctx, &audio, &ebml_audio_desc) < 0) + return 0; + if (audio.n_sampling_frequency) { + track->a_sfreq = audio.sampling_frequency; + mp_msg(MSGT_DEMUX, MSGL_V, + "[mkv] | + Sampling frequency: %f\n", track->a_sfreq); + } else + track->a_sfreq = 8000; + if (audio.n_bit_depth) { + track->a_bps = audio.bit_depth; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n", + track->a_bps); } - return len; + if (audio.n_channels) { + track->a_channels = audio.channels; + mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n", + track->a_channels); + } else + track->a_channels = 1; + talloc_free(parse_ctx.talloc_ctx); + return parse_ctx.bytes_read; } static int demux_mkv_read_trackvideo(demuxer_t *demuxer, mkv_track_t *track) diff --git a/libmpdemux/ebml.c b/libmpdemux/ebml.c index 8bbcad4db0..ab35237a44 100644 --- a/libmpdemux/ebml.c +++ b/libmpdemux/ebml.c @@ -643,7 +643,7 @@ int ebml_read_element(struct stream *s, struct ebml_parse_ctx *ctx, { ctx->has_errors = false; int msglevel = ctx->no_error_messages ? MSGL_DBG2 : MSGL_WARN; - uint64_t length = ebml_read_length(s, NULL); + uint64_t length = ebml_read_length(s, &ctx->bytes_read); if (s->eof) { mp_msg(MSGT_DEMUX, msglevel, "[mkv] Unexpected end of file " "- partial or corrupt file?\n"); @@ -656,6 +656,7 @@ 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(MSGT_DEMUX, msglevel, "[mkv] Unexpected end of file " "- partial or corrupt file?\n"); diff --git a/libmpdemux/ebml.h b/libmpdemux/ebml.h index efa3634141..b2fed46fb9 100644 --- a/libmpdemux/ebml.h +++ b/libmpdemux/ebml.h @@ -57,6 +57,7 @@ struct ebml_elem_desc { struct ebml_parse_ctx { void *talloc_ctx; + int bytes_read; bool has_errors; bool no_error_messages; };