| OLD | NEW |
| 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/opus_audio_decoder.h" | 5 #include "media/filters/opus_audio_decoder.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | |
| 10 #include "base/callback_helpers.h" | |
| 11 #include "base/location.h" | |
| 12 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 13 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
| 14 #include "media/base/audio_buffer.h" | 11 #include "media/base/audio_buffer.h" |
| 15 #include "media/base/audio_decoder_config.h" | 12 #include "media/base/audio_decoder_config.h" |
| 16 #include "media/base/audio_timestamp_helper.h" | 13 #include "media/base/audio_timestamp_helper.h" |
| 17 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 18 #include "media/base/buffers.h" | 15 #include "media/base/buffers.h" |
| 19 #include "media/base/decoder_buffer.h" | 16 #include "media/base/decoder_buffer.h" |
| 20 #include "media/base/demuxer.h" | |
| 21 #include "media/base/pipeline.h" | |
| 22 #include "third_party/opus/src/include/opus.h" | 17 #include "third_party/opus/src/include/opus.h" |
| 23 #include "third_party/opus/src/include/opus_multistream.h" | 18 #include "third_party/opus/src/include/opus_multistream.h" |
| 24 | 19 |
| 25 namespace media { | 20 namespace media { |
| 26 | 21 |
| 27 static uint16 ReadLE16(const uint8* data, size_t data_size, int read_offset) { | 22 static uint16 ReadLE16(const uint8* data, size_t data_size, int read_offset) { |
| 28 uint16 value = 0; | 23 uint16 value = 0; |
| 29 DCHECK_LE(read_offset + sizeof(value), data_size); | 24 DCHECK_LE(read_offset + sizeof(value), data_size); |
| 30 memcpy(&value, data + read_offset, sizeof(value)); | 25 memcpy(&value, data + read_offset, sizeof(value)); |
| 31 return base::ByteSwapToLE16(value); | 26 return base::ByteSwapToLE16(value); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 DVLOG(1) << "Inconsistent channel mapping."; | 243 DVLOG(1) << "Inconsistent channel mapping."; |
| 249 | 244 |
| 250 for (int i = 0; i < extra_data->channels; ++i) | 245 for (int i = 0; i < extra_data->channels; ++i) |
| 251 extra_data->stream_map[i] = *(data + kOpusExtraDataStreamMapOffset + i); | 246 extra_data->stream_map[i] = *(data + kOpusExtraDataStreamMapOffset + i); |
| 252 return true; | 247 return true; |
| 253 } | 248 } |
| 254 | 249 |
| 255 OpusAudioDecoder::OpusAudioDecoder( | 250 OpusAudioDecoder::OpusAudioDecoder( |
| 256 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | 251 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| 257 : task_runner_(task_runner), | 252 : task_runner_(task_runner), |
| 258 weak_factory_(this), | |
| 259 opus_decoder_(NULL), | 253 opus_decoder_(NULL), |
| 260 channel_layout_(CHANNEL_LAYOUT_NONE), | 254 channel_layout_(CHANNEL_LAYOUT_NONE), |
| 261 samples_per_second_(0), | 255 samples_per_second_(0), |
| 262 sample_format_(kSampleFormatF32), | 256 sample_format_(kSampleFormatF32), |
| 263 bits_per_channel_(SampleFormatToBytesPerChannel(sample_format_) * 8), | 257 bits_per_channel_(SampleFormatToBytesPerChannel(sample_format_) * 8), |
| 264 last_input_timestamp_(kNoTimestamp()), | 258 last_input_timestamp_(kNoTimestamp()), |
| 265 frames_to_discard_(0), | 259 frames_to_discard_(0), |
| 266 frame_delay_at_start_(0), | 260 frame_delay_at_start_(0), |
| 267 start_input_timestamp_(kNoTimestamp()) { | 261 start_input_timestamp_(kNoTimestamp()) {} |
| 268 } | |
| 269 | 262 |
| 270 void OpusAudioDecoder::Initialize(const AudioDecoderConfig& config, | 263 void OpusAudioDecoder::Initialize(const AudioDecoderConfig& config, |
| 271 const PipelineStatusCB& status_cb) { | 264 const PipelineStatusCB& status_cb) { |
| 272 DCHECK(task_runner_->BelongsToCurrentThread()); | 265 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 273 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); | 266 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); |
| 274 | 267 |
| 275 weak_this_ = weak_factory_.GetWeakPtr(); | |
| 276 config_ = config; | 268 config_ = config; |
| 277 | 269 |
| 278 if (!ConfigureDecoder()) { | 270 if (!ConfigureDecoder()) { |
| 279 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 271 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 280 return; | 272 return; |
| 281 } | 273 } |
| 282 | 274 |
| 283 initialize_cb.Run(PIPELINE_OK); | 275 initialize_cb.Run(PIPELINE_OK); |
| 284 } | 276 } |
| 285 | 277 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 output_timestamp_helper_->AddFrames(frames_decoded); | 569 output_timestamp_helper_->AddFrames(frames_decoded); |
| 578 | 570 |
| 579 // Discard the buffer to indicate we need more data. | 571 // Discard the buffer to indicate we need more data. |
| 580 if (!frames_to_output) | 572 if (!frames_to_output) |
| 581 *output_buffer = NULL; | 573 *output_buffer = NULL; |
| 582 | 574 |
| 583 return true; | 575 return true; |
| 584 } | 576 } |
| 585 | 577 |
| 586 } // namespace media | 578 } // namespace media |
| OLD | NEW |