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

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

Issue 126793002: Add Stop() to AudioDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
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/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 292
293 statistics_cb_ = statistics_cb; 293 statistics_cb_ = statistics_cb;
294 initialize_cb.Run(PIPELINE_OK); 294 initialize_cb.Run(PIPELINE_OK);
295 } 295 }
296 296
297 void OpusAudioDecoder::Read(const ReadCB& read_cb) { 297 void OpusAudioDecoder::Read(const ReadCB& read_cb) {
298 DCHECK(task_runner_->BelongsToCurrentThread()); 298 DCHECK(task_runner_->BelongsToCurrentThread());
299 DCHECK(!read_cb.is_null()); 299 DCHECK(!read_cb.is_null());
300 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 300 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
301 DCHECK(stop_cb_.is_null());
301 read_cb_ = BindToCurrentLoop(read_cb); 302 read_cb_ = BindToCurrentLoop(read_cb);
302 303
303 ReadFromDemuxerStream(); 304 ReadFromDemuxerStream();
304 } 305 }
305 306
306 int OpusAudioDecoder::bits_per_channel() { 307 int OpusAudioDecoder::bits_per_channel() {
307 DCHECK(task_runner_->BelongsToCurrentThread()); 308 DCHECK(task_runner_->BelongsToCurrentThread());
308 return bits_per_channel_; 309 return bits_per_channel_;
309 } 310 }
310 311
311 ChannelLayout OpusAudioDecoder::channel_layout() { 312 ChannelLayout OpusAudioDecoder::channel_layout() {
312 DCHECK(task_runner_->BelongsToCurrentThread()); 313 DCHECK(task_runner_->BelongsToCurrentThread());
313 return channel_layout_; 314 return channel_layout_;
314 } 315 }
315 316
316 int OpusAudioDecoder::samples_per_second() { 317 int OpusAudioDecoder::samples_per_second() {
317 DCHECK(task_runner_->BelongsToCurrentThread()); 318 DCHECK(task_runner_->BelongsToCurrentThread());
318 return samples_per_second_; 319 return samples_per_second_;
319 } 320 }
320 321
321 void OpusAudioDecoder::Reset(const base::Closure& closure) { 322 void OpusAudioDecoder::Reset(const base::Closure& closure) {
322 DCHECK(task_runner_->BelongsToCurrentThread()); 323 DCHECK(task_runner_->BelongsToCurrentThread());
323 base::Closure reset_cb = BindToCurrentLoop(closure); 324 reset_cb_ = BindToCurrentLoop(closure);
DaleCurtis 2014/01/09 23:04:21 Do we need the BTCL here and below? Ditto for FFm
rileya (GONE FROM CHROMIUM) 2014/01/10 00:04:05 I saw Reset using BTCL originally and figured ther
325
326 if (read_cb_.is_null())
327 DoReset();
328 // Otherwise we have to wait for the pending demuxer read.
329 }
330
331 void OpusAudioDecoder::Stop(const base::Closure& closure) {
332 DCHECK(task_runner_->BelongsToCurrentThread());
333 stop_cb_ = BindToCurrentLoop(closure);
334
335 if (read_cb_.is_null())
336 DoStop();
337 // Otherwise we have to wait for the pending demuxer read.
338 }
339
340 OpusAudioDecoder::~OpusAudioDecoder() {}
341
342 void OpusAudioDecoder::DoReset() {
343 DCHECK(!reset_cb_.is_null());
324 344
325 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE); 345 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
326 ResetTimestampState(); 346 ResetTimestampState();
327 reset_cb.Run(); 347 base::ResetAndReturn(&reset_cb_).Run();
328 } 348 }
329 349
330 OpusAudioDecoder::~OpusAudioDecoder() { 350 void OpusAudioDecoder::DoStop() {
331 // TODO(scherkus): should we require Stop() to be called? this might end up 351 DCHECK(!stop_cb_.is_null());
332 // getting called on a random thread due to refcounting. 352
353 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
354 ResetTimestampState();
333 CloseDecoder(); 355 CloseDecoder();
356 base::ResetAndReturn(&stop_cb_).Run();
334 } 357 }
335 358
336 void OpusAudioDecoder::ReadFromDemuxerStream() { 359 void OpusAudioDecoder::ReadFromDemuxerStream() {
337 DCHECK(!read_cb_.is_null()); 360 DCHECK(!read_cb_.is_null());
338 demuxer_stream_->Read(base::Bind(&OpusAudioDecoder::BufferReady, weak_this_)); 361 demuxer_stream_->Read(base::Bind(&OpusAudioDecoder::BufferReady, weak_this_));
339 } 362 }
340 363
341 void OpusAudioDecoder::BufferReady( 364 void OpusAudioDecoder::BufferReady(
342 DemuxerStream::Status status, 365 DemuxerStream::Status status,
343 const scoped_refptr<DecoderBuffer>& input) { 366 const scoped_refptr<DecoderBuffer>& input) {
344 DCHECK(task_runner_->BelongsToCurrentThread()); 367 DCHECK(task_runner_->BelongsToCurrentThread());
345 DCHECK(!read_cb_.is_null()); 368 DCHECK(!read_cb_.is_null());
346 DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status; 369 DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status;
347 370
371 // Drop the buffer, fire |read_cb_| and complete the pending Stop().
372 if (!stop_cb_.is_null()) {
373 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
374 DoStop();
375 return;
376 }
377
378 // Drop the buffer, fire |read_cb_| and complete the pending Reset().
379 if (!reset_cb_.is_null()) {
380 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
381 DoReset();
382 return;
383 }
384
348 if (status == DemuxerStream::kAborted) { 385 if (status == DemuxerStream::kAborted) {
349 DCHECK(!input.get()); 386 DCHECK(!input.get());
350 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); 387 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
351 return; 388 return;
352 } 389 }
353 390
354 if (status == DemuxerStream::kConfigChanged) { 391 if (status == DemuxerStream::kConfigChanged) {
355 DCHECK(!input.get()); 392 DCHECK(!input.get());
356 DVLOG(1) << "Config changed."; 393 DVLOG(1) << "Config changed.";
357 394
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 output_timestamp_helper_->AddFrames(frames_decoded); 656 output_timestamp_helper_->AddFrames(frames_decoded);
620 657
621 // Discard the buffer to indicate we need more data. 658 // Discard the buffer to indicate we need more data.
622 if (!frames_to_output) 659 if (!frames_to_output)
623 *output_buffer = NULL; 660 *output_buffer = NULL;
624 661
625 return true; 662 return true;
626 } 663 }
627 664
628 } // namespace media 665 } // namespace media
OLDNEW
« media/filters/ffmpeg_audio_decoder.cc ('K') | « media/filters/opus_audio_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698