From 7155be6ca49ee71f565c8d5e196e189540edf2c8 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Tue, 2 Aug 2011 19:08:29 +0000 Subject: Sync rockbox to r475 of musepack's svn. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30240 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libmusepack/internal.h | 7 +- apps/codecs/libmusepack/mpc_bits_reader.c | 2 + apps/codecs/libmusepack/mpc_decoder.c | 8 +- apps/codecs/libmusepack/mpc_demux.c | 190 +++++++++++++++++++----------- apps/codecs/libmusepack/mpc_types.h | 9 +- apps/codecs/libmusepack/streaminfo.c | 9 +- 6 files changed, 140 insertions(+), 85 deletions(-) diff --git a/apps/codecs/libmusepack/internal.h b/apps/codecs/libmusepack/internal.h index 0f29060a7d..3f8b29f9f5 100644 --- a/apps/codecs/libmusepack/internal.h +++ b/apps/codecs/libmusepack/internal.h @@ -88,12 +88,12 @@ struct mpc_demux_t { /** * checks if a block key is valid * @param key the two caracters key to check - * @return MPC_STATUS_INVALIDSV if the key is invalid, MPC_STATUS_OK else + * @return MPC_STATUS_FAIL if the key is invalid, MPC_STATUS_OK else */ static mpc_inline mpc_status mpc_check_key(char * key) { if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90) - return MPC_STATUS_INVALIDSV; + return MPC_STATUS_FAIL; return MPC_STATUS_OK; } @@ -114,6 +114,9 @@ void streaminfo_gain(mpc_streaminfo* si, const mpc_bits_reader * r_in); // mpc_decoder.c void mpc_decoder_reset_scf(mpc_decoder * d, int value); +#define MPC_IS_FAILURE(X) ((int)(X) < (int)MPC_STATUS_OK) +#define MPC_AUTO_FAIL(X) { mpc_status s = (X); if (MPC_IS_FAILURE(s)) return s; } + #ifdef __cplusplus } #endif diff --git a/apps/codecs/libmusepack/mpc_bits_reader.c b/apps/codecs/libmusepack/mpc_bits_reader.c index 58b3f37e08..c917ad510a 100644 --- a/apps/codecs/libmusepack/mpc_bits_reader.c +++ b/apps/codecs/libmusepack/mpc_bits_reader.c @@ -136,6 +136,8 @@ mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k) mpc_uint32_t mpc_bits_log_dec(mpc_bits_reader * r, mpc_uint_t max) { mpc_uint32_t value = 0; + if (max == 0) + return 0; if (log2[max - 1] > 1) value = mpc_bits_read(r, log2[max - 1] - 1); if (value >= log2_lost[max - 1]) diff --git a/apps/codecs/libmusepack/mpc_decoder.c b/apps/codecs/libmusepack/mpc_decoder.c index 7bf7935d39..eb8916f343 100644 --- a/apps/codecs/libmusepack/mpc_decoder.c +++ b/apps/codecs/libmusepack/mpc_decoder.c @@ -610,7 +610,7 @@ static void mpc_decoder_read_bitstream_sv8(mpc_decoder * d, mpc_bits_reader * r, } if (d->ms) { - int cnt = 0, tot = 0; + mpc_uint_t cnt = 0, tot = 0; mpc_uint32_t tmp = 0; for( n = 0; n < Max_used_Band; n++) if ( d->Res_L[n] != 0 || d->Res_R[n] != 0 ) @@ -687,10 +687,10 @@ static void mpc_decoder_read_bitstream_sv8(mpc_decoder * d, mpc_bits_reader * r, /***************************** Samples ****************************/ for ( n = 0; n < Max_used_Band; n++ ) { mpc_int16_t *q = d->Q[n].L, Res = d->Res_L[n]; - static const int thres[] = {0, 0, 3, 0, 0, 1, 3, 4, 8}; + static const mpc_uint32_t thres[] = {0, 0, 3, 0, 0, 1, 3, 4, 8}; do { mpc_uint32_t nbit; - mpc_int32_t k = 0, idx = 1, dc; + mpc_uint32_t k = 0, idx = 1, dc; if (Res != 0) { if (Res == 2) { Tables[0] = & mpc_can_Q [0][0]; @@ -706,7 +706,7 @@ static void mpc_decoder_read_bitstream_sv8(mpc_decoder * d, mpc_bits_reader * r, } else if (Res == 1) { Table = & mpc_can_Q1; for( ; k < 36; ){ - int kmax = k + 18; + mpc_uint32_t kmax = k + 18; mpc_uint_t cnt = mpc_bits_can_dec(r, Table); idx = 0; if (cnt > 0 && cnt < 18) diff --git a/apps/codecs/libmusepack/mpc_demux.c b/apps/codecs/libmusepack/mpc_demux.c index 499170c135..97a431e597 100644 --- a/apps/codecs/libmusepack/mpc_demux.c +++ b/apps/codecs/libmusepack/mpc_demux.c @@ -124,7 +124,7 @@ mpc_demux_fill(mpc_demux * d, mpc_uint32_t min_bytes, int flags) * @param fpos position in the stream in bits from the beginning of mpc datas * @param min_bytes number of bytes to load after seeking */ -static void +static mpc_status mpc_demux_seek(mpc_demux * d, mpc_seek_t fpos, mpc_uint32_t min_bytes) { // d->bits_reader.buff - d->buffer = current byte position within buffer // d->bytes_total = buffer is filled with bytes_total bytes @@ -143,7 +143,8 @@ mpc_demux_seek(mpc_demux * d, mpc_seek_t fpos, mpc_uint32_t min_bytes) { if (d->si.stream_version == 7) next_pos = ((next_pos - d->si.header_position) & (-1 << 2)) + d->si.header_position; buf_fpos = fpos - (next_pos << 3); - d->r->seek(d->r, (mpc_int32_t) next_pos); + if (!d->r->seek(d->r, (mpc_int32_t) next_pos)) + return MPC_STATUS_FAIL; mpc_demux_clear_buff(d); if (d->si.stream_version == 7) mpc_demux_fill(d, MAX_BUFFER_SIZE, MPC_BUFFER_FULL | MPC_BUFFER_SWAP); @@ -152,6 +153,8 @@ mpc_demux_seek(mpc_demux * d, mpc_seek_t fpos, mpc_uint32_t min_bytes) { d->bits_reader.buff += buf_fpos >> 3; d->bits_reader.count = 8 - (buf_fpos & 7); } + + return MPC_STATUS_OK; } /** @@ -171,7 +174,7 @@ static mpc_seek_t mpc_demux_pos(mpc_demux * d) * * @param d demuxer context * @return size of tag, in bytes - * @return MPC_STATUS_FILE on errors of any kind + * @return MPC_STATUS_FAIL on errors of any kind */ static mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d) { @@ -194,7 +197,7 @@ static mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d) tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read flags footerPresent = tmp[0] & 0x10; if ( tmp[0] & 0x0F ) - return MPC_STATUS_FILE; // not (yet???) allowed + return MPC_STATUS_FAIL; // not (yet???) allowed tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read size tmp[1] = mpc_bits_read(&d->bits_reader, 8); // read size @@ -202,7 +205,7 @@ static mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d) tmp[3] = mpc_bits_read(&d->bits_reader, 8); // read size if ( (tmp[0] | tmp[1] | tmp[2] | tmp[3]) & 0x80 ) - return MPC_STATUS_FILE; // not allowed + return MPC_STATUS_FAIL; // not allowed // read headerSize (syncsave: 4 * $0xxxxxxx = 28 significant bits) size = tmp[0] << 21; @@ -216,7 +219,8 @@ static mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d) // This is called before file headers get read, streamversion etc isn't yet known, demuxing isn't properly initialized and we can't call mpc_demux_seek() from here. mpc_demux_clear_buff(d); - if (!d->r->seek(d->r, size)) return MPC_STATUS_FILE; + if (!d->r->seek(d->r, size)) + return MPC_STATUS_FAIL; return size; } @@ -237,7 +241,7 @@ static mpc_status mpc_demux_seek_init(mpc_demux * d) } d->seek_table = g_seek_table; if (d->seek_table == 0) - return MPC_STATUS_FILE; + return MPC_STATUS_FAIL; d->seek_table[0] = (mpc_seek_t)mpc_demux_pos(d); d->seek_table_size = 1; @@ -245,7 +249,7 @@ static mpc_status mpc_demux_seek_init(mpc_demux * d) } /* rockbox: do not use -static void mpc_demux_ST(mpc_demux * d) +static mpc_status mpc_demux_ST(mpc_demux * d) { mpc_uint64_t tmp; mpc_seek_t * table, last[2]; @@ -254,7 +258,7 @@ static void mpc_demux_ST(mpc_demux * d) mpc_uint32_t file_table_size; if (d->seek_table != 0) - return; + return MPC_STATUS_OK; mpc_bits_get_size(&r, &tmp); file_table_size = (mpc_seek_t) tmp; @@ -276,7 +280,7 @@ static void mpc_demux_ST(mpc_demux * d) table[0] = last[0] = (mpc_seek_t) (tmp + d->si.header_position) * 8; if (d->seek_table_size == 1) - return; + return MPC_STATUS_OK; mpc_bits_get_size(&r, &tmp); last[1] = (mpc_seek_t) (tmp + d->si.header_position) * 8; @@ -292,9 +296,10 @@ static void mpc_demux_ST(mpc_demux * d) if ((i & mask) == 0) table[i >> diff_pwr] = last[i & 1]; } + return MPC_STATUS_OK; } -static void mpc_demux_SP(mpc_demux * d, int size, int block_size) +static mpc_status mpc_demux_SP(mpc_demux * d, int size, int block_size) { mpc_seek_t cur; mpc_uint64_t ptr; @@ -303,19 +308,27 @@ static void mpc_demux_SP(mpc_demux * d, int size, int block_size) cur = mpc_demux_pos(d); mpc_bits_get_size(&d->bits_reader, &ptr); - mpc_demux_seek(d, (ptr - size) * 8 + cur, 11); + MPC_AUTO_FAIL( mpc_demux_seek(d, (ptr - size) * 8 + cur, 11) ); st_head_size = mpc_bits_get_block(&d->bits_reader, &b); if (memcmp(b.key, "ST", 2) == 0) { d->chap_pos = (ptr - size + b.size + st_head_size) * 8 + cur; d->chap_nb = -1; - mpc_demux_fill(d, (mpc_uint32_t) b.size, 0); - mpc_demux_ST(d); + if (mpc_demux_fill(d, (mpc_uint32_t) b.size, 0) < b.size) + return MPC_STATUS_FAIL; + MPC_AUTO_FAIL( mpc_demux_ST(d) ); } - mpc_demux_seek(d, cur, 11 + block_size); + return mpc_demux_seek(d, cur, 11 + block_size); +} +*/ +/* rockbox: not used +static void mpc_demux_chap_empty(mpc_demux * d) { + free(d->chap); d->chap = 0; + d->chap_nb = 0; // -1 for undefined, 0 for no chapters + d->chap_pos = 0; } */ /* rockbox: not used -static void mpc_demux_chap_find(mpc_demux * d) +static mpc_status mpc_demux_chap_find_inner(mpc_demux * d) { mpc_block b; int tag_size = 0, chap_size = 0, size, i = 0; @@ -323,21 +336,26 @@ static void mpc_demux_chap_find(mpc_demux * d) d->chap_nb = 0; if (d->si.stream_version < 8) - return; + return MPC_STATUS_OK; if (d->chap_pos == 0) { mpc_uint64_t cur_pos = (d->si.header_position + 4) * 8; - mpc_demux_seek(d, cur_pos, 11); // seek to the beginning of the stream + MPC_AUTO_FAIL( mpc_demux_seek(d, cur_pos, 11) ); // seek to the beginning of the stream size = mpc_bits_get_block(&d->bits_reader, &b); while (memcmp(b.key, "SE", 2) != 0) { - if (mpc_check_key(b.key) != MPC_STATUS_OK) - return; + mpc_uint64_t new_pos = cur_pos + (size + b.size) * 8; + MPC_AUTO_FAIL(mpc_check_key(b.key)); + if (memcmp(b.key, "CT", 2) == 0) { if (d->chap_pos == 0) d->chap_pos = cur_pos; - } else + } else { d->chap_pos = 0; - cur_pos += (size + b.size) * 8; - mpc_demux_seek(d, cur_pos, 11); + } + if (new_pos <= cur_pos) + return MPC_STATUS_FAIL; + cur_pos = new_pos; + + MPC_AUTO_FAIL( mpc_demux_seek(d, cur_pos, 11) ); size = mpc_bits_get_block(&d->bits_reader, &b); } if (d->chap_pos == 0) @@ -353,24 +371,42 @@ static void mpc_demux_chap_find(mpc_demux * d) size = mpc_bits_get_size(&d->bits_reader, &chap_sample) + 4; chap_size += size; tag_size += b.size - size; - mpc_demux_seek(d, d->chap_pos + (chap_size + tag_size) * 8, 20); + MPC_AUTO_FAIL( mpc_demux_seek(d, d->chap_pos + (chap_size + tag_size) * 8, 20) ); size = mpc_bits_get_block(&d->bits_reader, &b); } if (d->chap_nb > 0) { char * ptag; d->chap = malloc(sizeof(mpc_chap_info) * d->chap_nb + tag_size); + if (d->chap == 0) + return MPC_STATUS_FAIL; + ptag = (char*)(d->chap + d->chap_nb); - mpc_demux_seek(d, d->chap_pos, 11); + MPC_AUTO_FAIL( mpc_demux_seek(d, d->chap_pos, 11) ); size = mpc_bits_get_block(&d->bits_reader, &b); while (memcmp(b.key, "CT", 2) == 0) { - mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0); + mpc_uint_t tmp_size; + char * tmp_ptag = ptag; + if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0) < b.size) + return MPC_STATUS_FAIL; size = mpc_bits_get_size(&d->bits_reader, &d->chap[i].sample) + 4; d->chap[i].gain = (mpc_uint16_t) mpc_bits_read(&d->bits_reader, 16); d->chap[i].peak = (mpc_uint16_t) mpc_bits_read(&d->bits_reader, 16); - memcpy(ptag, d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3), b.size - size); - d->bits_reader.buff += b.size - size; + + tmp_size = b.size - size; + do { + mpc_uint_t rd_size = tmp_size; + mpc_uint8_t * tmp_buff = d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3); + mpc_uint32_t avail_bytes = d->bytes_total + d->buffer - tmp_buff; + rd_size = mini(rd_size, avail_bytes); + memcpy(tmp_ptag, tmp_buff, rd_size); + tmp_size -= rd_size; + tmp_ptag += rd_size; + d->bits_reader.buff += rd_size; + mpc_demux_fill(d, tmp_size, 0); + } while (tmp_size > 0); + d->chap[i].tag_size = b.size - size; d->chap[i].tag = ptag; ptag += b.size - size; @@ -380,9 +416,17 @@ static void mpc_demux_chap_find(mpc_demux * d) } d->bits_reader.buff -= size; + return MPC_STATUS_OK; +} +*/ +/* rockbox: not used +static mpc_status mpc_demux_chap_find(mpc_demux * d) { + mpc_status s = mpc_demux_chap_find_inner(d); + if (MPC_IS_FAILURE(s)) + mpc_demux_chap_empty(d); + return s; } */ - /** * Gets the number of chapters in the stream * @param d pointer to a musepack demuxer @@ -424,7 +468,8 @@ static mpc_status mpc_demux_header(mpc_demux * d) */ // get header position d->si.header_position = mpc_demux_skip_id3v2(d); - if(d->si.header_position < 0) return MPC_STATUS_FILE; + if(d->si.header_position < 0) + return MPC_STATUS_FAIL; d->si.tag_offset = d->si.total_file_length = d->r->get_size(d->r); @@ -437,14 +482,11 @@ static mpc_status mpc_demux_header(mpc_demux * d) if (memcmp(magic, "MP+", 3) == 0) { d->si.stream_version = magic[3] & 15; d->si.pns = magic[3] >> 4; - if (d->si.stream_version == 7) { - mpc_status ret; - mpc_demux_fill(d, 6 * 4, MPC_BUFFER_SWAP); // header block size + endian convertion - ret = streaminfo_read_header_sv7(&d->si, &d->bits_reader); - if (ret != MPC_STATUS_OK) return ret; - } else { - return MPC_STATUS_INVALIDSV; - } + if (d->si.stream_version != 7) + return MPC_STATUS_FAIL; + if (mpc_demux_fill(d, 6 * 4, MPC_BUFFER_SWAP) < 6 * 4) // header block size + endian convertion + return MPC_STATUS_FAIL; + MPC_AUTO_FAIL( streaminfo_read_header_sv7(&d->si, &d->bits_reader) ); } else if (memcmp(magic, "MPCK", 4) == 0) { mpc_block b; int size; @@ -452,31 +494,35 @@ static mpc_status mpc_demux_header(mpc_demux * d) size = mpc_bits_get_block(&d->bits_reader, &b); while( memcmp(b.key, "AP", 2) != 0 ){ // scan all blocks until audio if (mpc_check_key(b.key) != MPC_STATUS_OK) - return MPC_STATUS_INVALIDSV; + return MPC_STATUS_FAIL; if (b.size > (mpc_uint64_t) MAX_BUFFER_SIZE - 11) - return MPC_STATUS_INVALIDSV; - mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0); - if (memcmp(b.key, "SH", 2) == 0){ - int ret = streaminfo_read_header_sv8(&d->si, &d->bits_reader, (mpc_uint32_t) b.size); - if (ret != MPC_STATUS_OK) return ret; - } else if (memcmp(b.key, "RG", 2) == 0) + return MPC_STATUS_FAIL; + + if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0) <= b.size) + return MPC_STATUS_FAIL; + + if (memcmp(b.key, "SH", 2) == 0) { + MPC_AUTO_FAIL( streaminfo_read_header_sv8(&d->si, &d->bits_reader, (mpc_uint32_t) b.size) ); + } else if (memcmp(b.key, "RG", 2) == 0) { streaminfo_gain(&d->si, &d->bits_reader); - else if (memcmp(b.key, "EI", 2) == 0) + } else if (memcmp(b.key, "EI", 2) == 0) { streaminfo_encoder_info(&d->si, &d->bits_reader); /* rockbox: do not use - else if (memcmp(b.key, "SO", 2) == 0) - mpc_demux_SP(d, size, (mpc_uint32_t) b.size); - else if (memcmp(b.key, "ST", 2) == 0) - mpc_demux_ST(d); + } else if (memcmp(b.key, "SO", 2) == 0) { + MPC_AUTO_FAIL( mpc_demux_SP(d, size, (mpc_uint32_t) b.size) ); + } else if (memcmp(b.key, "ST", 2) == 0) { + MPC_AUTO_FAIL( mpc_demux_ST(d) ); */ + } d->bits_reader.buff += b.size; size = mpc_bits_get_block(&d->bits_reader, &b); } d->bits_reader.buff -= size; if (d->si.stream_version == 0) // si not initialized !!! - return MPC_STATUS_INVALIDSV; - } else - return MPC_STATUS_INVALIDSV; + return MPC_STATUS_FAIL; + } else { + return MPC_STATUS_FAIL; + } return MPC_STATUS_OK; } @@ -519,7 +565,7 @@ void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i) memcpy(i, &d->si, sizeof d->si); } -mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) +static mpc_status mpc_demux_decode_inner(mpc_demux * d, mpc_frame_info * i) { mpc_bits_reader r; if (d->si.stream_version >= 8) { @@ -532,17 +578,19 @@ mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); d->seek_table_size ++; } - mpc_demux_fill(d, 11, 0); // max header block size + mpc_demux_fill(d, 11, MPC_BUFFER_FULL); // max header block size mpc_bits_get_block(&d->bits_reader, &b); while( memcmp(b.key, "AP", 2) != 0 ) { // scan all blocks until audio - if (mpc_check_key(b.key) != MPC_STATUS_OK) - goto error; + MPC_AUTO_FAIL( mpc_check_key(b.key) ); + if (memcmp(b.key, "SE", 2) == 0) { // end block i->bits = -1; return MPC_STATUS_OK; } - if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0) == 0) - goto error; + + if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, MPC_BUFFER_FULL) < b.size) + return MPC_STATUS_FAIL; + d->bits_reader.buff += b.size; mpc_bits_get_block(&d->bits_reader, &b); } @@ -556,7 +604,7 @@ mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) d->block_bits -= ((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count; d->block_frames--; if (d->block_bits < 0 || (d->block_frames == 0 && d->block_bits > 7)) - goto error; + return MPC_STATUS_FAIL; } else { if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); @@ -568,15 +616,19 @@ mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) r = d->bits_reader; mpc_decoder_decode_frame(d->d, &d->bits_reader, i); if (i->bits != -1 && d->block_bits != (mpc_int32_t)(((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count)) - goto error; + return MPC_STATUS_FAIL; } if (i->bits != -1 && d->buffer + d->bytes_total < d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3)) - goto error; + return MPC_STATUS_FAIL; return MPC_STATUS_OK; -error: - i->bits = -1; // we pretend it's end of file - return MPC_STATUS_INVALIDSV; +} + +mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) { + mpc_status s = mpc_demux_decode_inner(d, i); + if (MPC_IS_FAILURE(s)) + i->bits = -1; // we pretend it's end of file + return s; } /* rockbox: not used @@ -654,8 +706,8 @@ mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample) void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain, mpc_bool_t use_title, mpc_bool_t clip_prevention) { - float peak = use_title ? d->si.peak_title : d->si.peak_album; - float gain = use_title ? d->si.gain_title : d->si.gain_album; + float peak = (float) ( use_title ? d->si.peak_title : d->si.peak_album ); + float gain = (float) ( use_title ? d->si.gain_title : d->si.gain_album ); if(!use_gain && !clip_prevention) return; @@ -663,12 +715,12 @@ void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain, if(!peak) peak = 1.; else - peak = (1 << 15) / pow(10, peak / (20 * 256)); + peak = (float) ( (1 << 15) / pow(10, peak / (20 * 256)) ); if(!gain) gain = 1.; else - gain = pow(10, (level - gain / 256) / 20); + gain = (float) pow(10, (level - gain / 256) / 20); if(clip_prevention && (peak < gain || !use_gain)) gain = peak; diff --git a/apps/codecs/libmusepack/mpc_types.h b/apps/codecs/libmusepack/mpc_types.h index aa25f3df99..0e7aa9d2c3 100644 --- a/apps/codecs/libmusepack/mpc_types.h +++ b/apps/codecs/libmusepack/mpc_types.h @@ -88,13 +88,10 @@ typedef struct mpc_quantizer { /// Libmpcdec error codes typedef enum mpc_status { + // Success. MPC_STATUS_OK = 0, - MPC_STATUS_FILE = -1, - MPC_STATUS_SV7BETA = -2, - MPC_STATUS_CBR = -3, - MPC_STATUS_IS = -4, - MPC_STATUS_BLOCKSIZE = -5, - MPC_STATUS_INVALIDSV = -6 + // Generic failure (I/O error or invalid file). + MPC_STATUS_FAIL = -1 } mpc_status; #define MPC_FIXED_POINT diff --git a/apps/codecs/libmusepack/streaminfo.c b/apps/codecs/libmusepack/streaminfo.c index 3303bc4d7d..b31e5f605a 100644 --- a/apps/codecs/libmusepack/streaminfo.c +++ b/apps/codecs/libmusepack/streaminfo.c @@ -101,8 +101,8 @@ mpc_get_encoder_string(mpc_streaminfo* si) static mpc_status check_streaminfo(mpc_streaminfo * si) { if (si->max_band == 0 || si->max_band >= 32 - || si->channels > 2) - return MPC_STATUS_FILE; + || si->channels > 2 || si->channels == 0 || si->sample_freq == 0) + return MPC_STATUS_FAIL; return MPC_STATUS_OK; } @@ -160,6 +160,7 @@ streaminfo_read_header_sv7(mpc_streaminfo* si, mpc_bits_reader * r) */ if (last_frame_samples == 0) last_frame_samples = MPC_FRAME_LENGTH; + else if (last_frame_samples > MPC_FRAME_LENGTH) return MPC_STATUS_FAIL; si->samples = (mpc_int64_t) frames * MPC_FRAME_LENGTH; if (si->is_true_gapless) si->samples -= (MPC_FRAME_LENGTH - last_frame_samples); @@ -196,11 +197,11 @@ streaminfo_read_header_sv8(mpc_streaminfo* si, const mpc_bits_reader * r_in, CRC = (mpc_bits_read(&r, 16) << 16) | mpc_bits_read(&r, 16); if (CRC != mpc_crc32(r.buff + 1 - (r.count >> 3), (int)block_size - 4)) - return MPC_STATUS_FILE; + return MPC_STATUS_FAIL; si->stream_version = mpc_bits_read(&r, 8); if (si->stream_version != 8) - return MPC_STATUS_INVALIDSV; + return MPC_STATUS_FAIL; mpc_bits_get_size(&r, &si->samples); mpc_bits_get_size(&r, &si->beg_silence); -- cgit v1.2.3