| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/media/cma/decoder/cast_audio_decoder.h" | 5 #include "chromecast/media/cma/decoder/cast_audio_decoder.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 decoded_chunks_.push_back(decoded); | 221 decoded_chunks_.push_back(decoded); |
| 222 } | 222 } |
| 223 | 223 |
| 224 scoped_refptr<media::DecoderBufferBase> ConvertDecoded() { | 224 scoped_refptr<media::DecoderBufferBase> ConvertDecoded() { |
| 225 DCHECK(!decoded_chunks_.empty()); | 225 DCHECK(!decoded_chunks_.empty()); |
| 226 int num_frames = 0; | 226 int num_frames = 0; |
| 227 for (auto& chunk : decoded_chunks_) | 227 for (auto& chunk : decoded_chunks_) |
| 228 num_frames += chunk->frame_count(); | 228 num_frames += chunk->frame_count(); |
| 229 | 229 |
| 230 // Copy decoded data into an AudioBus for conversion. | 230 // Copy decoded data into an AudioBus for conversion. |
| 231 scoped_ptr<::media::AudioBus> decoded = | 231 std::unique_ptr<::media::AudioBus> decoded = |
| 232 ::media::AudioBus::Create(config_.channel_number, num_frames); | 232 ::media::AudioBus::Create(config_.channel_number, num_frames); |
| 233 int bus_frame_offset = 0; | 233 int bus_frame_offset = 0; |
| 234 for (auto& chunk : decoded_chunks_) { | 234 for (auto& chunk : decoded_chunks_) { |
| 235 chunk->ReadFrames(chunk->frame_count(), 0, bus_frame_offset, | 235 chunk->ReadFrames(chunk->frame_count(), 0, bus_frame_offset, |
| 236 decoded.get()); | 236 decoded.get()); |
| 237 bus_frame_offset += chunk->frame_count(); | 237 bus_frame_offset += chunk->frame_count(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 if (mixer_) { | 240 if (mixer_) { |
| 241 // Convert to stereo if necessary. | 241 // Convert to stereo if necessary. |
| 242 scoped_ptr<::media::AudioBus> converted_to_stereo = | 242 std::unique_ptr<::media::AudioBus> converted_to_stereo = |
| 243 ::media::AudioBus::Create(kStereoOutputChannelCount, num_frames); | 243 ::media::AudioBus::Create(kStereoOutputChannelCount, num_frames); |
| 244 mixer_->Transform(decoded.get(), converted_to_stereo.get()); | 244 mixer_->Transform(decoded.get(), converted_to_stereo.get()); |
| 245 decoded.swap(converted_to_stereo); | 245 decoded.swap(converted_to_stereo); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // TODO(tianyuwang): Remove this hack for 7_1 USB test speaker. | 248 // TODO(tianyuwang): Remove this hack for 7_1 USB test speaker. |
| 249 if (mixer_7_1_) { | 249 if (mixer_7_1_) { |
| 250 // Convert to layout 7_1 if necessary. | 250 // Convert to layout 7_1 if necessary. |
| 251 scoped_ptr<::media::AudioBus> converted_to_7_1 = | 251 std::unique_ptr<::media::AudioBus> converted_to_7_1 = |
| 252 ::media::AudioBus::Create(num_output_channels_, num_frames); | 252 ::media::AudioBus::Create(num_output_channels_, num_frames); |
| 253 mixer_7_1_->Transform(decoded.get(), converted_to_7_1.get()); | 253 mixer_7_1_->Transform(decoded.get(), converted_to_7_1.get()); |
| 254 decoded.swap(converted_to_7_1); | 254 decoded.swap(converted_to_7_1); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Convert to the desired output format. | 257 // Convert to the desired output format. |
| 258 return FinishConversion(decoded.get()); | 258 return FinishConversion(decoded.get()); |
| 259 } | 259 } |
| 260 | 260 |
| 261 scoped_refptr<media::DecoderBufferBase> FinishConversion( | 261 scoped_refptr<media::DecoderBufferBase> FinishConversion( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 285 bus->frames() * base::Time::kMicrosecondsPerSecond / | 285 bus->frames() * base::Time::kMicrosecondsPerSecond / |
| 286 config_.samples_per_second)); | 286 config_.samples_per_second)); |
| 287 return make_scoped_refptr( | 287 return make_scoped_refptr( |
| 288 new media::DecoderBufferAdapter(config_.id, result)); | 288 new media::DecoderBufferAdapter(config_.id, result)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 291 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 292 InitializedCallback initialized_callback_; | 292 InitializedCallback initialized_callback_; |
| 293 OutputFormat output_format_; | 293 OutputFormat output_format_; |
| 294 media::AudioConfig config_; | 294 media::AudioConfig config_; |
| 295 scoped_ptr<::media::AudioDecoder> decoder_; | 295 std::unique_ptr<::media::AudioDecoder> decoder_; |
| 296 std::queue<DecodeBufferCallbackPair> decode_queue_; | 296 std::queue<DecodeBufferCallbackPair> decode_queue_; |
| 297 bool initialized_; | 297 bool initialized_; |
| 298 int num_output_channels_; | 298 int num_output_channels_; |
| 299 scoped_ptr<::media::ChannelMixer> mixer_; | 299 std::unique_ptr<::media::ChannelMixer> mixer_; |
| 300 scoped_ptr<::media::ChannelMixer> mixer_7_1_; | 300 std::unique_ptr<::media::ChannelMixer> mixer_7_1_; |
| 301 bool decode_pending_; | 301 bool decode_pending_; |
| 302 std::vector<scoped_refptr<::media::AudioBuffer>> decoded_chunks_; | 302 std::vector<scoped_refptr<::media::AudioBuffer>> decoded_chunks_; |
| 303 base::WeakPtrFactory<CastAudioDecoderImpl> weak_factory_; | 303 base::WeakPtrFactory<CastAudioDecoderImpl> weak_factory_; |
| 304 | 304 |
| 305 DISALLOW_COPY_AND_ASSIGN(CastAudioDecoderImpl); | 305 DISALLOW_COPY_AND_ASSIGN(CastAudioDecoderImpl); |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 } // namespace | 308 } // namespace |
| 309 | 309 |
| 310 // static | 310 // static |
| 311 scoped_ptr<CastAudioDecoder> CastAudioDecoder::Create( | 311 std::unique_ptr<CastAudioDecoder> CastAudioDecoder::Create( |
| 312 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 312 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 313 const media::AudioConfig& config, | 313 const media::AudioConfig& config, |
| 314 OutputFormat output_format, | 314 OutputFormat output_format, |
| 315 const InitializedCallback& initialized_callback) { | 315 const InitializedCallback& initialized_callback) { |
| 316 scoped_ptr<CastAudioDecoderImpl> decoder(new CastAudioDecoderImpl( | 316 std::unique_ptr<CastAudioDecoderImpl> decoder(new CastAudioDecoderImpl( |
| 317 task_runner, initialized_callback, output_format)); | 317 task_runner, initialized_callback, output_format)); |
| 318 decoder->Initialize(config); | 318 decoder->Initialize(config); |
| 319 return std::move(decoder); | 319 return std::move(decoder); |
| 320 } | 320 } |
| 321 | 321 |
| 322 // static | 322 // static |
| 323 int CastAudioDecoder::OutputFormatSizeInBytes( | 323 int CastAudioDecoder::OutputFormatSizeInBytes( |
| 324 CastAudioDecoder::OutputFormat format) { | 324 CastAudioDecoder::OutputFormat format) { |
| 325 switch (format) { | 325 switch (format) { |
| 326 case CastAudioDecoder::OutputFormat::kOutputSigned16: | 326 case CastAudioDecoder::OutputFormat::kOutputSigned16: |
| 327 return 2; | 327 return 2; |
| 328 case CastAudioDecoder::OutputFormat::kOutputPlanarFloat: | 328 case CastAudioDecoder::OutputFormat::kOutputPlanarFloat: |
| 329 return 4; | 329 return 4; |
| 330 } | 330 } |
| 331 NOTREACHED(); | 331 NOTREACHED(); |
| 332 return 1; | 332 return 1; |
| 333 } | 333 } |
| 334 | 334 |
| 335 } // namespace media | 335 } // namespace media |
| 336 } // namespace chromecast | 336 } // namespace chromecast |
| OLD | NEW |