*@brief Decode how the data in the frame is split into subframes. * Every WMA frame contains the encoded data for a fixed number of * samples per channel. The data for every channel might be split * into several subframes. This function will reconstruct the list of * subframes for every channel. * * If the subframes are not evenly split, the algorithm estimates
| 662 | *@return 0 on success, < 0 in case of an error |
| 663 | */ |
| 664 | static int decode_tilehdr(WMAProDecodeCtx *s) |
| 665 | { |
| 666 | uint16_t num_samples[WMAPRO_MAX_CHANNELS] = { 0 };/**< sum of samples for all currently known subframes of a channel */ |
| 667 | uint8_t contains_subframe[WMAPRO_MAX_CHANNELS]; /**< flag indicating if a channel contains the current subframe */ |
| 668 | int channels_for_cur_subframe = s->nb_channels; /**< number of channels that contain the current subframe */ |
| 669 | int fixed_channel_layout = 0; /**< flag indicating that all channels use the same subframe offsets and sizes */ |
| 670 | int min_channel_len = 0; /**< smallest sum of samples (channels with this length will be processed first) */ |
| 671 | int c; |
| 672 | |
| 673 | /* Should never consume more than 3073 bits (256 iterations for the |
| 674 | * while loop when always the minimum amount of 128 samples is subtracted |
| 675 | * from missing samples in the 8 channel case). |
| 676 | * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS + 4) |
| 677 | */ |
| 678 | |
| 679 | /** reset tiling information */ |
| 680 | for (c = 0; c < s->nb_channels; c++) |
| 681 | s->channel[c].num_subframes = 0; |
| 682 | |
| 683 | if (s->max_num_subframes == 1 || get_bits1(&s->gb)) |
| 684 | fixed_channel_layout = 1; |
| 685 | |
| 686 | /** loop until the frame data is split between the subframes */ |
| 687 | do { |
| 688 | int subframe_len; |
| 689 | |
| 690 | /** check which channels contain the subframe */ |
| 691 | for (c = 0; c < s->nb_channels; c++) { |
| 692 | if (num_samples[c] == min_channel_len) { |
| 693 | if (fixed_channel_layout || channels_for_cur_subframe == 1 || |
| 694 | (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) |
| 695 | contains_subframe[c] = 1; |
| 696 | else |
| 697 | contains_subframe[c] = get_bits1(&s->gb); |
| 698 | } else |
| 699 | contains_subframe[c] = 0; |
| 700 | } |
| 701 | |
| 702 | /** get subframe length, subframe_len == 0 is not allowed */ |
| 703 | if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0) |
| 704 | return AVERROR_INVALIDDATA; |
| 705 | |
| 706 | /** add subframes to the individual channels and find new min_channel_len */ |
| 707 | min_channel_len += subframe_len; |
| 708 | for (c = 0; c < s->nb_channels; c++) { |
| 709 | WMAProChannelCtx* chan = &s->channel[c]; |
| 710 | |
| 711 | if (contains_subframe[c]) { |
| 712 | if (chan->num_subframes >= MAX_SUBFRAMES) { |
| 713 | av_log(s->avctx, AV_LOG_ERROR, |
| 714 | "broken frame: num subframes > 31\n"); |
| 715 | return AVERROR_INVALIDDATA; |
| 716 | } |
| 717 | chan->subframe_len[chan->num_subframes] = subframe_len; |
| 718 | num_samples[c] += subframe_len; |
| 719 | ++chan->num_subframes; |
| 720 | if (num_samples[c] > s->samples_per_frame) { |
| 721 | av_log(s->avctx, AV_LOG_ERROR, "broken frame: " |
no test coverage detected