78 int state_before =
state;
83 LOGE(
"ATRAC header parser is not progressing");
109 while ((
size_t)
hdr.
size() < need && n > 0) {
115 return (
size_t)
hdr.
size() >= need;
125 int block_align,
const uint8_t *extra =
nullptr,
126 size_t extra_size = 0,
bool known =
false,
128 if (!
dec.
begin(type, sample_rate, channels, block_align, extra,
130 fail(
"ATRAC decoder could not be started");
137 if (known && length == 0)
is_done =
true;
154 static uint16_t
be16(
const uint8_t *p) {
return (p[0] << 8) | p[1]; }
156 return (p[0] << 16) | (p[1] << 8) | p[2];
171 const char *
mime()
override {
return "audio/oma"; }
183 if (memcmp(
hdr.
data(),
"ea3", 3) == 0 ||
184 memcmp(
hdr.
data(),
"ID3", 3) == 0) {
187 if (
hdr.
data()[5] & 0x10) tag_size += 10;
190 }
else if (memcmp(
hdr.
data(),
"EA3", 3) != 0) {
191 fail(
"Not an OMA stream");
206 return ((p[0] & 0x7F) << 21) | ((p[1] & 0x7F) << 14) |
207 ((p[2] & 0x7F) << 7) | (p[3] & 0x7F);
212 if (memcmp(h,
"EA3", 3) != 0 || h[4] != 0 || h[5] !=
EA3_HEADER_SIZE) {
213 fail(
"OMA: EA3 header not found");
217 uint16_t encryption_id =
be16(h + 6);
218 if (encryption_id != 0xFFFF && encryption_id != 0xFF80) {
219 fail(
"OMA: encrypted files are not supported");
224 static const int rates[] = {32000, 44100, 48000, 88200, 96000};
225 unsigned rate_idx = (params >> 13) & 7;
226 if (rate_idx >=
sizeof(rates) /
sizeof(rates[0])) {
227 fail(
"OMA: invalid sample rate");
230 int sample_rate = rates[rate_idx];
231 int frame_size = (params & 0x3FF) * 8;
235 uint16_t js = (params >> 17) & 1;
241 static const int channel_ids[] = {0, 1, 2, 3, 4, 6, 7, 8};
242 int channels = channel_ids[(params >> 10) & 7];
244 fail(
"OMA: invalid channel configuration");
248 startDecoder(ATRAC3PLUS, sample_rate, channels, frame_size + 8);
250 fail(
"OMA: unsupported codec (only ATRAC3 and ATRAC3+)");
265 const char *
mime()
override {
return "audio/aea"; }
274 static const uint8_t magic[4] = {0x00, 0x08, 0x00, 0x00};
275 if (memcmp(
hdr.
data(), magic, 4) != 0) {
276 fail(
"Not an AEA stream");
281 if (channels != 1 && channels != 2) {
282 fail(
"AEA: invalid number of channels");
#define LOGE(...)
Definition AudioLoggerIDF.h:30
@ ATRAC3
Sony ATRAC3 (the tag is called SONY_SCX in some lists)