| 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_to_current_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/sys_byteorder.h" | 11 #include "base/sys_byteorder.h" |
| 11 #include "media/base/audio_buffer.h" | 12 #include "media/base/audio_buffer.h" |
| 12 #include "media/base/audio_decoder_config.h" | 13 #include "media/base/audio_decoder_config.h" |
| 13 #include "media/base/audio_discard_helper.h" | 14 #include "media/base/audio_discard_helper.h" |
| 14 #include "media/base/bind_to_current_loop.h" | |
| 15 #include "media/base/buffers.h" | 15 #include "media/base/buffers.h" |
| 16 #include "media/base/decoder_buffer.h" | 16 #include "media/base/decoder_buffer.h" |
| 17 #include "third_party/opus/src/include/opus.h" | 17 #include "third_party/opus/src/include/opus.h" |
| 18 #include "third_party/opus/src/include/opus_multistream.h" | 18 #include "third_party/opus/src/include/opus_multistream.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 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) { |
| 23 uint16 value = 0; | 23 uint16 value = 0; |
| 24 DCHECK_LE(read_offset + sizeof(value), data_size); | 24 DCHECK_LE(read_offset + sizeof(value), data_size); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 start_input_timestamp_(kNoTimestamp()) {} | 250 start_input_timestamp_(kNoTimestamp()) {} |
| 251 | 251 |
| 252 std::string OpusAudioDecoder::GetDisplayName() const { | 252 std::string OpusAudioDecoder::GetDisplayName() const { |
| 253 return "OpusAudioDecoder"; | 253 return "OpusAudioDecoder"; |
| 254 } | 254 } |
| 255 | 255 |
| 256 void OpusAudioDecoder::Initialize(const AudioDecoderConfig& config, | 256 void OpusAudioDecoder::Initialize(const AudioDecoderConfig& config, |
| 257 const PipelineStatusCB& status_cb, | 257 const PipelineStatusCB& status_cb, |
| 258 const OutputCB& output_cb) { | 258 const OutputCB& output_cb) { |
| 259 DCHECK(task_runner_->BelongsToCurrentThread()); | 259 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 260 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); | 260 PipelineStatusCB initialize_cb = base::BindToCurrentLoop(status_cb); |
| 261 | 261 |
| 262 config_ = config; | 262 config_ = config; |
| 263 output_cb_ = BindToCurrentLoop(output_cb); | 263 output_cb_ = base::BindToCurrentLoop(output_cb); |
| 264 | 264 |
| 265 if (!ConfigureDecoder()) { | 265 if (!ConfigureDecoder()) { |
| 266 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 266 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 267 return; | 267 return; |
| 268 } | 268 } |
| 269 | 269 |
| 270 initialize_cb.Run(PIPELINE_OK); | 270 initialize_cb.Run(PIPELINE_OK); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 273 void OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 274 const DecodeCB& decode_cb) { | 274 const DecodeCB& decode_cb) { |
| 275 DCHECK(task_runner_->BelongsToCurrentThread()); | 275 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 276 DCHECK(!decode_cb.is_null()); | 276 DCHECK(!decode_cb.is_null()); |
| 277 | 277 |
| 278 DecodeBuffer(buffer, BindToCurrentLoop(decode_cb)); | 278 DecodeBuffer(buffer, base::BindToCurrentLoop(decode_cb)); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void OpusAudioDecoder::Reset(const base::Closure& closure) { | 281 void OpusAudioDecoder::Reset(const base::Closure& closure) { |
| 282 DCHECK(task_runner_->BelongsToCurrentThread()); | 282 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 283 | 283 |
| 284 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE); | 284 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE); |
| 285 ResetTimestampState(); | 285 ResetTimestampState(); |
| 286 task_runner_->PostTask(FROM_HERE, closure); | 286 task_runner_->PostTask(FROM_HERE, closure); |
| 287 } | 287 } |
| 288 | 288 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 output_buffer->get()->TrimEnd(trim_frames); | 478 output_buffer->get()->TrimEnd(trim_frames); |
| 479 | 479 |
| 480 // Handles discards and timestamping. Discard the buffer if more data needed. | 480 // Handles discards and timestamping. Discard the buffer if more data needed. |
| 481 if (!discard_helper_->ProcessBuffers(input, *output_buffer)) | 481 if (!discard_helper_->ProcessBuffers(input, *output_buffer)) |
| 482 *output_buffer = NULL; | 482 *output_buffer = NULL; |
| 483 | 483 |
| 484 return true; | 484 return true; |
| 485 } | 485 } |
| 486 | 486 |
| 487 } // namespace media | 487 } // namespace media |
| OLD | NEW |