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

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: Remove extraneous #include 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
« no previous file with comments | « media/filters/opus_audio_decoder.h ('k') | no next file » | 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/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);
325
326 // A demuxer read is pending, we'll wait until it finishes.
327 if (!read_cb_.is_null())
328 return;
329
330 DoReset();
331 }
332
333 void OpusAudioDecoder::Stop(const base::Closure& closure) {
334 DCHECK(task_runner_->BelongsToCurrentThread());
335 stop_cb_ = BindToCurrentLoop(closure);
336
337 // A demuxer read is pending, we'll wait until it finishes.
338 if (!read_cb_.is_null())
339 return;
340
341 if (!reset_cb_.is_null()) {
342 DoReset();
343 return;
344 }
345
346 DoStop();
347 }
348
349 OpusAudioDecoder::~OpusAudioDecoder() {}
350
351 void OpusAudioDecoder::DoReset() {
352 DCHECK(!reset_cb_.is_null());
324 353
325 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE); 354 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
326 ResetTimestampState(); 355 ResetTimestampState();
327 reset_cb.Run(); 356 base::ResetAndReturn(&reset_cb_).Run();
357
358 if (!stop_cb_.is_null())
359 DoStop();
328 } 360 }
329 361
330 OpusAudioDecoder::~OpusAudioDecoder() { 362 void OpusAudioDecoder::DoStop() {
331 // TODO(scherkus): should we require Stop() to be called? this might end up 363 DCHECK(!stop_cb_.is_null());
332 // getting called on a random thread due to refcounting. 364
365 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
366 ResetTimestampState();
333 CloseDecoder(); 367 CloseDecoder();
368 base::ResetAndReturn(&stop_cb_).Run();
334 } 369 }
335 370
336 void OpusAudioDecoder::ReadFromDemuxerStream() { 371 void OpusAudioDecoder::ReadFromDemuxerStream() {
337 DCHECK(!read_cb_.is_null()); 372 DCHECK(!read_cb_.is_null());
338 demuxer_stream_->Read(base::Bind(&OpusAudioDecoder::BufferReady, weak_this_)); 373 demuxer_stream_->Read(base::Bind(&OpusAudioDecoder::BufferReady, weak_this_));
339 } 374 }
340 375
341 void OpusAudioDecoder::BufferReady( 376 void OpusAudioDecoder::BufferReady(
342 DemuxerStream::Status status, 377 DemuxerStream::Status status,
343 const scoped_refptr<DecoderBuffer>& input) { 378 const scoped_refptr<DecoderBuffer>& input) {
344 DCHECK(task_runner_->BelongsToCurrentThread()); 379 DCHECK(task_runner_->BelongsToCurrentThread());
345 DCHECK(!read_cb_.is_null()); 380 DCHECK(!read_cb_.is_null());
346 DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status; 381 DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status;
347 382
383 // Drop the buffer, fire |read_cb_| and complete the pending Reset().
384 // If there happens to also be a pending Stop(), that will be handled at
385 // the end of DoReset().
386 if (!reset_cb_.is_null()) {
387 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
388 DoReset();
389 return;
390 }
391
392 // Drop the buffer, fire |read_cb_| and complete the pending Stop().
393 if (!stop_cb_.is_null()) {
394 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
395 DoStop();
396 return;
397 }
398
348 if (status == DemuxerStream::kAborted) { 399 if (status == DemuxerStream::kAborted) {
349 DCHECK(!input.get()); 400 DCHECK(!input.get());
350 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); 401 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
351 return; 402 return;
352 } 403 }
353 404
354 if (status == DemuxerStream::kConfigChanged) { 405 if (status == DemuxerStream::kConfigChanged) {
355 DCHECK(!input.get()); 406 DCHECK(!input.get());
356 DVLOG(1) << "Config changed."; 407 DVLOG(1) << "Config changed.";
357 408
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 output_timestamp_helper_->AddFrames(frames_decoded); 670 output_timestamp_helper_->AddFrames(frames_decoded);
620 671
621 // Discard the buffer to indicate we need more data. 672 // Discard the buffer to indicate we need more data.
622 if (!frames_to_output) 673 if (!frames_to_output)
623 *output_buffer = NULL; 674 *output_buffer = NULL;
624 675
625 return true; 676 return true;
626 } 677 }
627 678
628 } // namespace media 679 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/opus_audio_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698