+ memcpy(s->output[ch + offset], output[ch], AC3_BLOCK_SIZE*sizeof(SHORTFLOAT));
+
+ /* check if there is dependent frame */
+ if (buf_size > s->frame_size) {
+ AC3HeaderInfo hdr;
+ int err;
+
+ if (buf_size - s->frame_size <= 16) {
+ skip = buf_size - s->frame_size;
+ goto skip;
+ }
+
+ if ((ret = init_get_bits8(&s->gbc, buf + s->frame_size, buf_size - s->frame_size)) < 0)
+ return ret;
+
+ err = ff_ac3_parse_header(&s->gbc, &hdr);
+ if (err)
+ return err;
+
+ if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
+ if (hdr.num_blocks != s->num_blocks || s->sample_rate != hdr.sample_rate) {
+ av_log(avctx, AV_LOG_WARNING, "Ignoring non-compatible dependent frame.\n");
+ } else {
+ buf += s->frame_size;
+ buf_size -= s->frame_size;
+ s->prev_output_mode = s->output_mode;
+ s->prev_bit_rate = s->bit_rate;
+ got_independent_frame = 1;
+ goto dependent_frame;
+ }
+ }
+ }
+skip:
+
+ frame->decode_error_flags = err ? FF_DECODE_ERROR_INVALID_BITSTREAM : 0;
+
+ /* if frame is ok, set audio parameters */
+ if (!err) {
+ avctx->sample_rate = s->sample_rate;
+ avctx->bit_rate = s->bit_rate + s->prev_bit_rate;
+ }
+
+ for (ch = 0; ch < EAC3_MAX_CHANNELS; ch++)
+ extended_channel_map[ch] = ch;
+
+ if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
+ uint64_t ich_layout = avpriv_ac3_channel_layout_tab[s->prev_output_mode & ~AC3_OUTPUT_LFEON];
+ int channel_map_size = ff_ac3_channels_tab[s->output_mode & ~AC3_OUTPUT_LFEON] + s->lfe_on;
+ uint64_t channel_layout;
+ int extend = 0;
+
+ if (s->prev_output_mode & AC3_OUTPUT_LFEON)
+ ich_layout |= AV_CH_LOW_FREQUENCY;
+
+ channel_layout = ich_layout;
+ for (ch = 0; ch < 16; ch++) {
+ if (s->channel_map & (1 << (EAC3_MAX_CHANNELS - ch - 1))) {
+ channel_layout |= ff_eac3_custom_channel_map_locations[ch][1];
+ }
+ }
+ if (av_get_channel_layout_nb_channels(channel_layout) > EAC3_MAX_CHANNELS) {
+ av_log(avctx, AV_LOG_ERROR, "Too many channels (%d) coded\n",
+ av_get_channel_layout_nb_channels(channel_layout));
+ return AVERROR_INVALIDDATA;
+ }
+
+ avctx->channel_layout = channel_layout;
+ avctx->channels = av_get_channel_layout_nb_channels(channel_layout);
+
+ for (ch = 0; ch < EAC3_MAX_CHANNELS; ch++) {
+ if (s->channel_map & (1 << (EAC3_MAX_CHANNELS - ch - 1))) {
+ if (ff_eac3_custom_channel_map_locations[ch][0]) {
+ int index = av_get_channel_layout_channel_index(channel_layout,
+ ff_eac3_custom_channel_map_locations[ch][1]);
+ if (index < 0)
+ return AVERROR_INVALIDDATA;
+ if (extend >= channel_map_size)
+ return AVERROR_INVALIDDATA;
+
+ extended_channel_map[index] = offset + channel_map[extend++];
+ } else {
+ int i;
+
+ for (i = 0; i < 64; i++) {
+ if ((1ULL << i) & ff_eac3_custom_channel_map_locations[ch][1]) {
+ int index = av_get_channel_layout_channel_index(channel_layout,
+ 1ULL << i);
+ if (index < 0)
+ return AVERROR_INVALIDDATA;
+ if (extend >= channel_map_size)
+ return AVERROR_INVALIDDATA;
+
+ extended_channel_map[index] = offset + channel_map[extend++];
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* get output buffer */
+ frame->nb_samples = s->num_blocks * AC3_BLOCK_SIZE;
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+ return ret;
+
+ for (ch = 0; ch < avctx->channels; ch++) {
+ int map = extended_channel_map[ch];
+ av_assert0(ch>=AV_NUM_DATA_POINTERS || frame->extended_data[ch] == frame->data[ch]);
+ memcpy((SHORTFLOAT *)frame->extended_data[ch],
+ s->output_buffer[map],
+ s->num_blocks * AC3_BLOCK_SIZE * sizeof(SHORTFLOAT));
+ }