demux_mkv: use new EBML parser to read Audio element

This commit is contained in:
Uoti Urpala 2010-01-26 14:41:07 +02:00
parent fc907b7488
commit db41501f23
3 changed files with 25 additions and 45 deletions

View File

@ -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)

View File

@ -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");

View File

@ -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;
};