OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cast/receiver/audio_decoder.h" | 5 #include "media/cast/receiver/audio_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 ImplBase::cast_initialization_status_ = | 111 ImplBase::cast_initialization_status_ = |
112 STATUS_INVALID_AUDIO_CONFIGURATION; | 112 STATUS_INVALID_AUDIO_CONFIGURATION; |
113 return; | 113 return; |
114 } | 114 } |
115 ImplBase::cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; | 115 ImplBase::cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; |
116 } | 116 } |
117 | 117 |
118 private: | 118 private: |
119 virtual ~OpusImpl() {} | 119 virtual ~OpusImpl() {} |
120 | 120 |
121 virtual void RecoverBecauseFramesWereDropped() OVERRIDE { | 121 virtual void RecoverBecauseFramesWereDropped() override { |
122 // Passing NULL for the input data notifies the decoder of frame loss. | 122 // Passing NULL for the input data notifies the decoder of frame loss. |
123 const opus_int32 result = | 123 const opus_int32 result = |
124 opus_decode_float( | 124 opus_decode_float( |
125 opus_decoder_, NULL, 0, buffer_.get(), max_samples_per_frame_, 0); | 125 opus_decoder_, NULL, 0, buffer_.get(), max_samples_per_frame_, 0); |
126 DCHECK_GE(result, 0); | 126 DCHECK_GE(result, 0); |
127 } | 127 } |
128 | 128 |
129 virtual scoped_ptr<AudioBus> Decode(uint8* data, int len) OVERRIDE { | 129 virtual scoped_ptr<AudioBus> Decode(uint8* data, int len) override { |
130 scoped_ptr<AudioBus> audio_bus; | 130 scoped_ptr<AudioBus> audio_bus; |
131 const opus_int32 num_samples_decoded = opus_decode_float( | 131 const opus_int32 num_samples_decoded = opus_decode_float( |
132 opus_decoder_, data, len, buffer_.get(), max_samples_per_frame_, 0); | 132 opus_decoder_, data, len, buffer_.get(), max_samples_per_frame_, 0); |
133 if (num_samples_decoded <= 0) | 133 if (num_samples_decoded <= 0) |
134 return audio_bus.Pass(); // Decode error. | 134 return audio_bus.Pass(); // Decode error. |
135 | 135 |
136 // Copy interleaved samples from |buffer_| into a new AudioBus (where | 136 // Copy interleaved samples from |buffer_| into a new AudioBus (where |
137 // samples are stored in planar format, for each channel). | 137 // samples are stored in planar format, for each channel). |
138 audio_bus = AudioBus::Create(num_channels_, num_samples_decoded).Pass(); | 138 audio_bus = AudioBus::Create(num_channels_, num_samples_decoded).Pass(); |
139 // TODO(miu): This should be moved into AudioBus::FromInterleaved(). | 139 // TODO(miu): This should be moved into AudioBus::FromInterleaved(). |
(...skipping 30 matching lines...) Expand all Loading... |
170 num_channels, | 170 num_channels, |
171 sampling_rate) { | 171 sampling_rate) { |
172 if (ImplBase::cast_initialization_status_ != STATUS_AUDIO_UNINITIALIZED) | 172 if (ImplBase::cast_initialization_status_ != STATUS_AUDIO_UNINITIALIZED) |
173 return; | 173 return; |
174 ImplBase::cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; | 174 ImplBase::cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; |
175 } | 175 } |
176 | 176 |
177 private: | 177 private: |
178 virtual ~Pcm16Impl() {} | 178 virtual ~Pcm16Impl() {} |
179 | 179 |
180 virtual scoped_ptr<AudioBus> Decode(uint8* data, int len) OVERRIDE { | 180 virtual scoped_ptr<AudioBus> Decode(uint8* data, int len) override { |
181 scoped_ptr<AudioBus> audio_bus; | 181 scoped_ptr<AudioBus> audio_bus; |
182 const int num_samples = len / sizeof(int16) / num_channels_; | 182 const int num_samples = len / sizeof(int16) / num_channels_; |
183 if (num_samples <= 0) | 183 if (num_samples <= 0) |
184 return audio_bus.Pass(); | 184 return audio_bus.Pass(); |
185 | 185 |
186 int16* const pcm_data = reinterpret_cast<int16*>(data); | 186 int16* const pcm_data = reinterpret_cast<int16*>(data); |
187 #if defined(ARCH_CPU_LITTLE_ENDIAN) | 187 #if defined(ARCH_CPU_LITTLE_ENDIAN) |
188 // Convert endianness. | 188 // Convert endianness. |
189 const int num_elements = num_samples * num_channels_; | 189 const int num_elements = num_samples * num_channels_; |
190 for (int i = 0; i < num_elements; ++i) | 190 for (int i = 0; i < num_elements; ++i) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 cast_environment_->PostTask(CastEnvironment::AUDIO, | 238 cast_environment_->PostTask(CastEnvironment::AUDIO, |
239 FROM_HERE, | 239 FROM_HERE, |
240 base::Bind(&AudioDecoder::ImplBase::DecodeFrame, | 240 base::Bind(&AudioDecoder::ImplBase::DecodeFrame, |
241 impl_, | 241 impl_, |
242 base::Passed(&encoded_frame), | 242 base::Passed(&encoded_frame), |
243 callback)); | 243 callback)); |
244 } | 244 } |
245 | 245 |
246 } // namespace cast | 246 } // namespace cast |
247 } // namespace media | 247 } // namespace media |
OLD | NEW |