| 263 | } |
| 264 | |
| 265 | static uint64_t truehd_downmix_mask(int hb_mixdown, int normalized, const AVChannelLayout *input_layout) |
| 266 | { |
| 267 | /* |
| 268 | * TrueHD bitstreams are made up of multiple "substreams" which are |
| 269 | * combined in order to obtain the final output. Any given substream |
| 270 | * depends on the previous substream(s), but not the next; by only |
| 271 | * decoding up to specific substream, a TrueHD decoder can extract |
| 272 | * an embedded downmix. |
| 273 | */ |
| 274 | if (normalized == 0) |
| 275 | { |
| 276 | uint64_t mask = 0; |
| 277 | switch (hb_mixdown) |
| 278 | { |
| 279 | /* |
| 280 | * We cannot use an embedded Stereo downmix as we have no way |
| 281 | * of knowing whether it is Dolby Surround or PLII-compatible. |
| 282 | * Request 5.1 instead and let hb_audio_resample downmix that. |
| 283 | */ |
| 284 | case HB_AMIXDOWN_DOLBY: |
| 285 | case HB_AMIXDOWN_DOLBYPLII: |
| 286 | mask = AV_CH_LAYOUT_5POINT1; |
| 287 | break; |
| 288 | |
| 289 | default: |
| 290 | mask = hb_ff_mixdown_xlat(hb_mixdown, NULL); |
| 291 | break; |
| 292 | } |
| 293 | if (mask) |
| 294 | { |
| 295 | AVChannelLayout mask_layout = {0}; |
| 296 | av_channel_layout_from_mask(&mask_layout, mask); |
| 297 | |
| 298 | if (downmix_required(&mask_layout, input_layout)) |
| 299 | { |
| 300 | if (mask == AV_CH_LAYOUT_STEREO) |
| 301 | { |
| 302 | /* |
| 303 | * The majority of TrueHD tracks have a Stereo first |
| 304 | * substream, even when the second substream is Mono. |
| 305 | */ |
| 306 | return mask; |
| 307 | } |
| 308 | if (hb_mixdown == HB_AMIXDOWN_MONO) |
| 309 | { |
| 310 | /* |
| 311 | * It is unlikely that any substream configuration will |
| 312 | * give us an embedded Mono downmix (except in the case |
| 313 | * where the full input layout is Mono, but in said case |
| 314 | * a downmix is not required) however it may be possible |
| 315 | * to extract a Stereo downmix and let hb_audio_resample |
| 316 | * take care of downmixing that to Mono for final output. |
| 317 | * |
| 318 | * Do it after downmix_required() so we don't accidentally |
| 319 | * request a Stereo downmix when the input is already Mono. |
| 320 | */ |
| 321 | return AV_CH_LAYOUT_STEREO; |
| 322 | } |
no test coverage detected