Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: media/filters/ffmpeg_audio_decoder.cc

Issue 2748023004: Fix unsupported audio channel layout (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/ffmpeg_audio_decoder.h" 5 #include "media/filters/ffmpeg_audio_decoder.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // how big each channel data is in order to meet the alignment policy, so 88 // how big each channel data is in order to meet the alignment policy, so
89 // we need to take this into consideration. 89 // we need to take this into consideration.
90 int buffer_size_in_bytes = av_samples_get_buffer_size( 90 int buffer_size_in_bytes = av_samples_get_buffer_size(
91 &frame->linesize[0], channels, frame->nb_samples, format, 91 &frame->linesize[0], channels, frame->nb_samples, format,
92 0 /* align, use ffmpeg default */); 92 0 /* align, use ffmpeg default */);
93 // Check for errors from av_samples_get_buffer_size(). 93 // Check for errors from av_samples_get_buffer_size().
94 if (buffer_size_in_bytes < 0) 94 if (buffer_size_in_bytes < 0)
95 return buffer_size_in_bytes; 95 return buffer_size_in_bytes;
96 int frames_required = buffer_size_in_bytes / bytes_per_channel / channels; 96 int frames_required = buffer_size_in_bytes / bytes_per_channel / channels;
97 DCHECK_GE(frames_required, frame->nb_samples); 97 DCHECK_GE(frames_required, frame->nb_samples);
98
99 ChannelLayout channel_layout =
100 ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels);
101
102 if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED) {
103 DLOG(ERROR) << "Unsupported channel layout.";
104 return AVERROR(EINVAL);
105 }
106
98 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateBuffer( 107 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateBuffer(
99 sample_format, 108 sample_format, channel_layout, channels, s->sample_rate, frames_required);
100 ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels),
101 channels,
102 s->sample_rate,
103 frames_required);
104 109
105 // Initialize the data[] and extended_data[] fields to point into the memory 110 // Initialize the data[] and extended_data[] fields to point into the memory
106 // allocated for AudioBuffer. |number_of_planes| will be 1 for interleaved 111 // allocated for AudioBuffer. |number_of_planes| will be 1 for interleaved
107 // audio and equal to |channels| for planar audio. 112 // audio and equal to |channels| for planar audio.
108 int number_of_planes = buffer->channel_data().size(); 113 int number_of_planes = buffer->channel_data().size();
109 if (number_of_planes <= AV_NUM_DATA_POINTERS) { 114 if (number_of_planes <= AV_NUM_DATA_POINTERS) {
110 DCHECK_EQ(frame->extended_data, frame->data); 115 DCHECK_EQ(frame->extended_data, frame->data);
111 for (int i = 0; i < number_of_planes; ++i) 116 for (int i = 0; i < number_of_planes; ++i)
112 frame->data[i] = buffer->channel_data()[i]; 117 frame->data[i] = buffer->channel_data()[i];
113 } else { 118 } else {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // Opus codec delay is handled by ffmpeg. 440 // Opus codec delay is handled by ffmpeg.
436 const int codec_delay = 441 const int codec_delay =
437 config_.codec() == kCodecOpus ? 0 : config_.codec_delay(); 442 config_.codec() == kCodecOpus ? 0 : config_.codec_delay();
438 discard_helper_.reset( 443 discard_helper_.reset(
439 new AudioDiscardHelper(config_.samples_per_second(), codec_delay, 444 new AudioDiscardHelper(config_.samples_per_second(), codec_delay,
440 config_.codec() == kCodecVorbis)); 445 config_.codec() == kCodecVorbis));
441 discard_helper_->Reset(codec_delay); 446 discard_helper_->Reset(codec_delay);
442 } 447 }
443 448
444 } // namespace media 449 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698