| 283 | } |
| 284 | |
| 285 | av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, |
| 286 | OpusParseContext *s) |
| 287 | { |
| 288 | static const uint8_t default_channel_map[2] = { 0, 1 }; |
| 289 | |
| 290 | int (*channel_reorder)(int, int) = channel_reorder_unknown; |
| 291 | int channels = avctx->ch_layout.nb_channels; |
| 292 | |
| 293 | const uint8_t *extradata, *channel_map; |
| 294 | int extradata_size; |
| 295 | int version, map_type, streams, stereo_streams, i, j, ret; |
| 296 | AVChannelLayout layout = { 0 }; |
| 297 | |
| 298 | if (!avctx->extradata) { |
| 299 | if (channels > 2) { |
| 300 | av_log(avctx, AV_LOG_ERROR, |
| 301 | "Multichannel configuration without extradata.\n"); |
| 302 | return AVERROR(EINVAL); |
| 303 | } |
| 304 | extradata = opus_default_extradata; |
| 305 | extradata_size = sizeof(opus_default_extradata); |
| 306 | } else { |
| 307 | extradata = avctx->extradata; |
| 308 | extradata_size = avctx->extradata_size; |
| 309 | } |
| 310 | |
| 311 | if (extradata_size < 19) { |
| 312 | av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n", |
| 313 | extradata_size); |
| 314 | return AVERROR_INVALIDDATA; |
| 315 | } |
| 316 | |
| 317 | version = extradata[8]; |
| 318 | if (version > 15) { |
| 319 | avpriv_request_sample(avctx, "Extradata version %d", version); |
| 320 | return AVERROR_PATCHWELCOME; |
| 321 | } |
| 322 | |
| 323 | avctx->delay = AV_RL16(extradata + 10); |
| 324 | |
| 325 | channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2; |
| 326 | if (!channels) { |
| 327 | av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the extradata\n"); |
| 328 | return AVERROR_INVALIDDATA; |
| 329 | } |
| 330 | |
| 331 | s->gain_i = AV_RL16(extradata + 16); |
| 332 | |
| 333 | map_type = extradata[18]; |
| 334 | if (!map_type) { |
| 335 | if (channels > 2) { |
| 336 | av_log(avctx, AV_LOG_ERROR, |
| 337 | "Channel mapping 0 is only specified for up to 2 channels\n"); |
| 338 | ret = AVERROR_INVALIDDATA; |
| 339 | goto fail; |
| 340 | } |
| 341 | layout = (channels == 1) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO : |
| 342 | (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; |
no test coverage detected