* Wrapper for NeAACDecInit() which works around some API * inconsistencies in libfaad. * * Throws #std::runtime_error on error. */
| 233 | * Throws #std::runtime_error on error. |
| 234 | */ |
| 235 | static void |
| 236 | faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer &buffer, |
| 237 | AudioFormat &audio_format) |
| 238 | { |
| 239 | auto data = FromBytesStrict<const uint8_t>(buffer.Read()); |
| 240 | if (data.empty()) |
| 241 | throw std::runtime_error("Empty file"); |
| 242 | |
| 243 | uint8_t channels; |
| 244 | unsigned long sample_rate; |
| 245 | long nbytes = NeAACDecInit(decoder, |
| 246 | /* deconst hack, libfaad requires this */ |
| 247 | const_cast<unsigned char *>(data.data()), |
| 248 | data.size(), |
| 249 | &sample_rate, &channels); |
| 250 | if (nbytes < 0) |
| 251 | throw std::runtime_error("Not an AAC stream"); |
| 252 | |
| 253 | buffer.Consume(nbytes); |
| 254 | |
| 255 | audio_format = CheckAudioFormat(sample_rate, SampleFormat::S16, |
| 256 | channels); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Wrapper for NeAACDecDecode() which works around some API |
no test coverage detected