From 76ec55cc49e306a54ac7e43acf8a7f70ba7905a0 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Wed, 24 Jan 2024 12:28:27 +0200 Subject: Remove ATRAC3 specific fields (channels, extradata_size) from mp3entry Also fixes typo of using never initialized id3->channels in wav metadata (introduced in 2d1937a1) Change-Id: I28cddec2b9d9bd1e756ffaa004b4f6e8528a7566 --- lib/rbcodec/codecs/atrac3_oma.c | 11 +++++++---- lib/rbcodec/codecs/atrac3_rm.c | 3 +-- lib/rbcodec/codecs/libatrac/atrac3.c | 12 ++++++------ lib/rbcodec/codecs/libatrac/atrac3.h | 2 +- lib/rbcodec/metadata/metadata.h | 4 ---- lib/rbcodec/metadata/mpc.c | 2 +- lib/rbcodec/metadata/oma.c | 5 ----- lib/rbcodec/metadata/rm.c | 2 -- lib/rbcodec/metadata/tta.c | 8 ++++---- lib/rbcodec/metadata/wave.c | 6 ++---- lib/rbcodec/test/warble.c | 2 -- 11 files changed, 22 insertions(+), 35 deletions(-) diff --git a/lib/rbcodec/codecs/atrac3_oma.c b/lib/rbcodec/codecs/atrac3_oma.c index d394fffdcb..2b212ad5f8 100644 --- a/lib/rbcodec/codecs/atrac3_oma.c +++ b/lib/rbcodec/codecs/atrac3_oma.c @@ -23,7 +23,6 @@ #include "logf.h" #include "codeclib.h" -#include "inttypes.h" #include "libatrac/atrac3.h" CODEC_HEADER @@ -66,12 +65,16 @@ enum codec_status codec_run(void) ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); ci->configure(DSP_SET_SAMPLE_DEPTH, 17); /* Remark: atrac3 uses s15.0 by default, s15.2 was hacked. */ - ci->configure(DSP_SET_STEREO_MODE, ci->id3->channels == 1 ? + const uint8_t channels = 2; + ci->configure(DSP_SET_STEREO_MODE, channels == 1 ? STEREO_MONO : STEREO_NONINTERLEAVED); ci->seek_buffer(0); - res = atrac3_decode_init(&q, ci->id3); + /* fake the atrac3 extradata (wav format, makes stream copy to wav work) */ + /* ATRAC3 expects and extra-data size of 14 bytes for wav format, and * + * looks for that in the id3v2buf. */ + res = atrac3_decode_init(&q, ci->id3, channels, 14); if(res < 0) { DEBUGF("failed to initialize OMA atrac decoder\n"); return CODEC_ERROR; @@ -143,7 +146,7 @@ enum codec_status codec_run(void) if(datasize) ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024, - q.samples_per_frame / ci->id3->channels); + q.samples_per_frame / channels); elapsed += (FRAMESIZE * 8) / BITRATE; ci->set_elapsed(elapsed); diff --git a/lib/rbcodec/codecs/atrac3_rm.c b/lib/rbcodec/codecs/atrac3_rm.c index af38b79fc4..b365dac926 100644 --- a/lib/rbcodec/codecs/atrac3_rm.c +++ b/lib/rbcodec/codecs/atrac3_rm.c @@ -22,7 +22,6 @@ #include #include "codeclib.h" -#include "inttypes.h" #include "libatrac/atrac3.h" CODEC_HEADER @@ -109,7 +108,7 @@ enum codec_status codec_run(void) scrambling_unit_size = h * (fs + packet_header_size); spn = h * fs / sps; - res = atrac3_decode_init(&q, ci->id3); + res = atrac3_decode_init(&q, ci->id3, rmctx.nb_channels, rmctx.extradata_size); if(res < 0) { DEBUGF("failed to initialize RM atrac decoder\n"); return CODEC_ERROR; diff --git a/lib/rbcodec/codecs/libatrac/atrac3.c b/lib/rbcodec/codecs/libatrac/atrac3.c index bb52dd4cf0..f0098258b3 100644 --- a/lib/rbcodec/codecs/libatrac/atrac3.c +++ b/lib/rbcodec/codecs/libatrac/atrac3.c @@ -1156,8 +1156,8 @@ int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q, * Atrac3 initialization * * @param rmctx pointer to the RMContext - */ -int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3) + */ +int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3, uint16_t channels, uint32_t extradata_size) { int i; uint8_t *edata_ptr = (uint8_t*)&id3->id3v2buf; @@ -1168,14 +1168,14 @@ int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3) /* Take data from the RM container. */ q->sample_rate = id3->frequency; - q->channels = id3->channels; + q->channels = channels; q->bit_rate = id3->bitrate * 1000; q->bits_per_frame = id3->bytesperframe * 8; q->bytes_per_frame = id3->bytesperframe; /* Take care of the codec-specific extradata. */ - if (id3->extradata_size == 14) { + if (extradata_size == 14) { /* Parse the extradata, WAV format */ DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); /* Unknown value always 1 */ q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]); @@ -1200,7 +1200,7 @@ int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3) return -1; } - } else if (id3->extradata_size == 10) { + } else if (extradata_size == 10) { /* Parse the extradata, RM format. */ q->atrac3version = rm_get_uint32be(&edata_ptr[0]); q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]); @@ -1239,7 +1239,7 @@ int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3) return -1; } - if (id3->channels <= 0 || id3->channels > 2 ) { + if (channels <= 0 || channels > 2 ) { DEBUGF("Channel configuration error!\n"); return -1; } diff --git a/lib/rbcodec/codecs/libatrac/atrac3.h b/lib/rbcodec/codecs/libatrac/atrac3.h index 64086b6411..912924cf6c 100644 --- a/lib/rbcodec/codecs/libatrac/atrac3.h +++ b/lib/rbcodec/codecs/libatrac/atrac3.h @@ -107,7 +107,7 @@ typedef struct { //@} } ATRAC3Context; -int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3); +int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3, uint16_t channels, uint32_t extradata_size); int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q, int *data_size, const uint8_t *buf, int buf_size); diff --git a/lib/rbcodec/metadata/metadata.h b/lib/rbcodec/metadata/metadata.h index eda1fb0d7d..b30979334a 100644 --- a/lib/rbcodec/metadata/metadata.h +++ b/lib/rbcodec/metadata/metadata.h @@ -272,10 +272,6 @@ struct mp3entry { bool has_toc; /* True if there is a VBR header in the file */ unsigned char toc[100]; /* table of contents */ - /* Added for ATRAC3 */ - unsigned int channels; /* Number of channels in the stream */ - unsigned int extradata_size; /* Size (in bytes) of the codec's extradata from the container */ - /* Added for AAC HE SBR */ bool needs_upsampling_correction; /* flag used by aac codec */ diff --git a/lib/rbcodec/metadata/mpc.c b/lib/rbcodec/metadata/mpc.c index 3c0ee0707d..346053dd3e 100644 --- a/lib/rbcodec/metadata/mpc.c +++ b/lib/rbcodec/metadata/mpc.c @@ -163,7 +163,7 @@ bool get_musepack_metadata(int fd, struct mp3entry *id3) id3->frequency = sfreqs[(sv8_header[k++] >> 5) & 0x0003]; /* Number of channels */ - id3->channels = (sv8_header[k++] >> 4) + 1; + //uint8_t channels = (sv8_header[k++] >> 4) + 1; /* Skip to next tag: k = size -2 */ k = size - 2; diff --git a/lib/rbcodec/metadata/oma.c b/lib/rbcodec/metadata/oma.c index 3573d58808..3afa1aad70 100644 --- a/lib/rbcodec/metadata/oma.c +++ b/lib/rbcodec/metadata/oma.c @@ -149,10 +149,6 @@ static int oma_read_header(int fd, struct mp3entry* id3) id3->bitrate = id3->frequency * id3->bytesperframe * 8 / (1024 * 1000); - /* fake the atrac3 extradata (wav format, makes stream copy to wav work) */ - /* ATRAC3 expects and extra-data size of 14 bytes for wav format, and * - * looks for that in the id3v2buf. */ - id3->extradata_size = 14; AV_WL16(&id3->id3v2buf[0], 1); // always 1 AV_WL32(&id3->id3v2buf[2], id3->frequency); // samples rate AV_WL16(&id3->id3v2buf[6], jsflag); // coding mode @@ -160,7 +156,6 @@ static int oma_read_header(int fd, struct mp3entry* id3) AV_WL16(&id3->id3v2buf[10], 1); // always 1 AV_WL16(&id3->id3v2buf[12], 0); // always 0 - id3->channels = 2; DEBUGF("sample_rate = %d\n", id3->frequency); DEBUGF("frame_size = %d\n", id3->bytesperframe); DEBUGF("stereo_coding_mode = %d\n", jsflag); diff --git a/lib/rbcodec/metadata/rm.c b/lib/rbcodec/metadata/rm.c index 1e33f0b0ac..16ffe17b14 100644 --- a/lib/rbcodec/metadata/rm.c +++ b/lib/rbcodec/metadata/rm.c @@ -502,8 +502,6 @@ bool get_rm_metadata(int fd, struct mp3entry* id3) break; } - id3->channels = rmctx->nb_channels; - id3->extradata_size = rmctx->extradata_size; id3->bitrate = (rmctx->bit_rate + 500) / 1000; id3->frequency = rmctx->sample_rate; id3->length = rmctx->duration; diff --git a/lib/rbcodec/metadata/tta.c b/lib/rbcodec/metadata/tta.c index 5f99c4776e..a481d8dd21 100644 --- a/lib/rbcodec/metadata/tta.c +++ b/lib/rbcodec/metadata/tta.c @@ -93,21 +93,21 @@ bool get_tta_metadata(int fd, struct mp3entry* id3) /* skip check CRC */ - id3->channels = (GET_HEADER(ttahdr, NUM_CHANNELS)); + unsigned short channels = (GET_HEADER(ttahdr, NUM_CHANNELS)); id3->frequency = (GET_HEADER(ttahdr, SAMPLE_RATE)); id3->length = ((GET_HEADER(ttahdr, DATA_LENGTH)) / id3->frequency) * 1000LL; bps = (GET_HEADER(ttahdr, BITS_PER_SAMPLE)); datasize = id3->filesize - id3->first_frame_offset; - origsize = (GET_HEADER(ttahdr, DATA_LENGTH)) * ((bps + 7) / 8) * id3->channels; + origsize = (GET_HEADER(ttahdr, DATA_LENGTH)) * ((bps + 7) / 8) * channels; - id3->bitrate = (int) ((uint64_t) datasize * id3->frequency * id3->channels * bps + id3->bitrate = (int) ((uint64_t) datasize * id3->frequency * channels * bps / (origsize * 1000LL)); /* output header info (for debug) */ DEBUGF("TTA header info ----\n"); DEBUGF("id: %x\n", (unsigned int)(GET_HEADER(ttahdr, ID))); - DEBUGF("channels: %d\n", id3->channels); + DEBUGF("channels: %d\n", channels); DEBUGF("frequency: %ld\n", id3->frequency); DEBUGF("length: %ld\n", id3->length); DEBUGF("bitrate: %d\n", id3->bitrate); diff --git a/lib/rbcodec/metadata/wave.c b/lib/rbcodec/metadata/wave.c index 3fb051dd3c..2c918d1357 100644 --- a/lib/rbcodec/metadata/wave.c +++ b/lib/rbcodec/metadata/wave.c @@ -160,7 +160,7 @@ static void set_totalsamples(struct wave_fmt *fmt, struct mp3entry* id3) fmt->samplesperblock = 1; break; case WAVE_FORMAT_YAMAHA_ADPCM: - if (id3->channels != 0) + if (fmt->channels != 0) { fmt->samplesperblock = (fmt->blockalign == ((id3->frequency / 60) + 4) * fmt->channels)? @@ -172,7 +172,7 @@ static void set_totalsamples(struct wave_fmt *fmt, struct mp3entry* id3) fmt->samplesperblock = 2; break; case WAVE_FORMAT_SWF_ADPCM: - if (fmt->bitspersample != 0 && id3->channels != 0) + if (fmt->bitspersample != 0 && fmt->channels != 0) { fmt->samplesperblock = (((fmt->blockalign << 3) - 2) / fmt->channels - 22) @@ -226,8 +226,6 @@ static void parse_riff_format(unsigned char* buf, int fmtsize, struct wave_fmt * if(id3->bitrate == 66 || id3->bitrate == 94) jsflag = 1; - id3->extradata_size = 14; - id3->channels = 2; id3->codectype = AFMT_OMA_ATRAC3; id3->bytesperframe = fmt->blockalign; diff --git a/lib/rbcodec/test/warble.c b/lib/rbcodec/test/warble.c index cb7a85ff25..e6e53d7991 100644 --- a/lib/rbcodec/test/warble.c +++ b/lib/rbcodec/test/warble.c @@ -749,8 +749,6 @@ static void print_mp3entry(const struct mp3entry *id3, FILE *f) if (id3->bytesperframe) fprintf(f, "Bytes per frame: %lu\n", id3->bytesperframe); if (id3->vbr) fprintf(f, "VBR: true\n"); if (id3->has_toc) fprintf(f, "Has TOC: true\n"); - if (id3->channels) fprintf(f, "Number of channels: %u\n", id3->channels); - if (id3->extradata_size) fprintf(f, "Size of extra data: %u\n", id3->extradata_size); if (id3->needs_upsampling_correction) fprintf(f, "Needs upsampling correction: true\n"); /* TODO: replaygain; albumart; cuesheet */ if (id3->mb_track_id) fprintf(f, "Musicbrainz track ID: %s\n", id3->mb_track_id); -- cgit v1.2.3