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

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

Issue 331863004: Revert 276344 "Add callback in VideoDecoder and AudioDecoder to ..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2049/src/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « media/filters/opus_audio_decoder.h ('k') | media/filters/opus_audio_decoder_unittest.cc » ('j') | 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/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/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 return true; 242 return true;
243 } 243 }
244 244
245 OpusAudioDecoder::OpusAudioDecoder( 245 OpusAudioDecoder::OpusAudioDecoder(
246 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) 246 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
247 : task_runner_(task_runner), 247 : task_runner_(task_runner),
248 opus_decoder_(NULL), 248 opus_decoder_(NULL),
249 start_input_timestamp_(kNoTimestamp()) {} 249 start_input_timestamp_(kNoTimestamp()) {}
250 250
251 void OpusAudioDecoder::Initialize(const AudioDecoderConfig& config, 251 void OpusAudioDecoder::Initialize(const AudioDecoderConfig& config,
252 const PipelineStatusCB& status_cb, 252 const PipelineStatusCB& status_cb) {
253 const OutputCB& output_cb) {
254 DCHECK(task_runner_->BelongsToCurrentThread()); 253 DCHECK(task_runner_->BelongsToCurrentThread());
255 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); 254 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb);
256 255
257 config_ = config; 256 config_ = config;
258 output_cb_ = BindToCurrentLoop(output_cb);
259 257
260 if (!ConfigureDecoder()) { 258 if (!ConfigureDecoder()) {
261 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); 259 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
262 return; 260 return;
263 } 261 }
264 262
265 initialize_cb.Run(PIPELINE_OK); 263 initialize_cb.Run(PIPELINE_OK);
266 } 264 }
267 265
268 void OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 266 void OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
269 const DecodeCB& decode_cb) { 267 const DecodeCB& decode_cb) {
270 DCHECK(task_runner_->BelongsToCurrentThread()); 268 DCHECK(task_runner_->BelongsToCurrentThread());
271 DCHECK(!decode_cb.is_null()); 269 DCHECK(!decode_cb.is_null());
272 270
273 DecodeBuffer(buffer, BindToCurrentLoop(decode_cb)); 271 DecodeBuffer(buffer, BindToCurrentLoop(decode_cb));
274 } 272 }
275 273
276 void OpusAudioDecoder::Reset(const base::Closure& closure) { 274 void OpusAudioDecoder::Reset(const base::Closure& closure) {
277 DCHECK(task_runner_->BelongsToCurrentThread()); 275 DCHECK(task_runner_->BelongsToCurrentThread());
278 276
279 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE); 277 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
(...skipping 18 matching lines...) Expand all
298 const scoped_refptr<DecoderBuffer>& input, 296 const scoped_refptr<DecoderBuffer>& input,
299 const DecodeCB& decode_cb) { 297 const DecodeCB& decode_cb) {
300 DCHECK(task_runner_->BelongsToCurrentThread()); 298 DCHECK(task_runner_->BelongsToCurrentThread());
301 DCHECK(!decode_cb.is_null()); 299 DCHECK(!decode_cb.is_null());
302 300
303 DCHECK(input.get()); 301 DCHECK(input.get());
304 302
305 // Libopus does not buffer output. Decoding is complete when an end of stream 303 // Libopus does not buffer output. Decoding is complete when an end of stream
306 // input buffer is received. 304 // input buffer is received.
307 if (input->end_of_stream()) { 305 if (input->end_of_stream()) {
308 output_cb_.Run(AudioBuffer::CreateEOSBuffer()); 306 decode_cb.Run(kOk, AudioBuffer::CreateEOSBuffer());
309 decode_cb.Run(kOk);
310 return; 307 return;
311 } 308 }
312 309
313 // Make sure we are notified if http://crbug.com/49709 returns. Issue also 310 // Make sure we are notified if http://crbug.com/49709 returns. Issue also
314 // occurs with some damaged files. 311 // occurs with some damaged files.
315 if (input->timestamp() == kNoTimestamp()) { 312 if (input->timestamp() == kNoTimestamp()) {
316 DLOG(ERROR) << "Received a buffer without timestamps!"; 313 DLOG(ERROR) << "Received a buffer without timestamps!";
317 decode_cb.Run(kDecodeError); 314 decode_cb.Run(kDecodeError, NULL);
318 return; 315 return;
319 } 316 }
320 317
321 // Apply the necessary codec delay. 318 // Apply the necessary codec delay.
322 if (start_input_timestamp_ == kNoTimestamp()) 319 if (start_input_timestamp_ == kNoTimestamp())
323 start_input_timestamp_ = input->timestamp(); 320 start_input_timestamp_ = input->timestamp();
324 if (!discard_helper_->initialized() && 321 if (!discard_helper_->initialized() &&
325 input->timestamp() == start_input_timestamp_) { 322 input->timestamp() == start_input_timestamp_) {
326 discard_helper_->Reset(config_.codec_delay()); 323 discard_helper_->Reset(config_.codec_delay());
327 } 324 }
328 325
329 scoped_refptr<AudioBuffer> output_buffer; 326 scoped_refptr<AudioBuffer> output_buffer;
330 327
331 if (!Decode(input, &output_buffer)) { 328 if (!Decode(input, &output_buffer)) {
332 decode_cb.Run(kDecodeError); 329 decode_cb.Run(kDecodeError, NULL);
333 return; 330 return;
334 } 331 }
335 332
336 if (output_buffer) { 333 if (output_buffer.get()) {
337 output_cb_.Run(output_buffer); 334 // Execute callback to return the decoded audio.
335 decode_cb.Run(kOk, output_buffer);
336 } else {
337 // We exhausted the input data, but it wasn't enough for a frame.
338 decode_cb.Run(kNotEnoughData, NULL);
338 } 339 }
339
340 decode_cb.Run(kOk);
341 } 340 }
342 341
343 bool OpusAudioDecoder::ConfigureDecoder() { 342 bool OpusAudioDecoder::ConfigureDecoder() {
344 if (config_.codec() != kCodecOpus) { 343 if (config_.codec() != kCodecOpus) {
345 DVLOG(1) << "Codec must be kCodecOpus."; 344 DVLOG(1) << "Codec must be kCodecOpus.";
346 return false; 345 return false;
347 } 346 }
348 347
349 const int channel_count = 348 const int channel_count =
350 ChannelLayoutToChannelCount(config_.channel_layout()); 349 ChannelLayoutToChannelCount(config_.channel_layout());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 output_buffer->get()->TrimEnd(trim_frames); 476 output_buffer->get()->TrimEnd(trim_frames);
478 477
479 // Handles discards and timestamping. Discard the buffer if more data needed. 478 // Handles discards and timestamping. Discard the buffer if more data needed.
480 if (!discard_helper_->ProcessBuffers(input, *output_buffer)) 479 if (!discard_helper_->ProcessBuffers(input, *output_buffer))
481 *output_buffer = NULL; 480 *output_buffer = NULL;
482 481
483 return true; 482 return true;
484 } 483 }
485 484
486 } // namespace media 485 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/opus_audio_decoder.h ('k') | media/filters/opus_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698