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

Side by Side Diff: media/audio/audio_input_controller.cc

Issue 1911913002: Convert //media/audio from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix cast + windows build Created 4 years, 8 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/audio/audio_input_controller.h" 5 #include "media/audio/audio_input_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 508 }
509 509
510 void AudioInputController::OnData(AudioInputStream* stream, 510 void AudioInputController::OnData(AudioInputStream* stream,
511 const AudioBus* source, 511 const AudioBus* source,
512 uint32_t hardware_delay_bytes, 512 uint32_t hardware_delay_bytes,
513 double volume) { 513 double volume) {
514 // |input_writer_| should only be accessed on the audio thread, but as a means 514 // |input_writer_| should only be accessed on the audio thread, but as a means
515 // to avoid copying data and posting on the audio thread, we just check for 515 // to avoid copying data and posting on the audio thread, we just check for
516 // non-null here. 516 // non-null here.
517 if (input_writer_) { 517 if (input_writer_) {
518 scoped_ptr<AudioBus> source_copy = 518 std::unique_ptr<AudioBus> source_copy =
danakj 2016/04/22 22:47:35 include memory
dcheng 2016/04/22 23:13:19 Already included in related header.
519 AudioBus::Create(source->channels(), source->frames()); 519 AudioBus::Create(source->channels(), source->frames());
520 source->CopyTo(source_copy.get()); 520 source->CopyTo(source_copy.get());
521 task_runner_->PostTask( 521 task_runner_->PostTask(
522 FROM_HERE, 522 FROM_HERE,
523 base::Bind( 523 base::Bind(
524 &AudioInputController::WriteInputDataForDebugging, 524 &AudioInputController::WriteInputDataForDebugging,
525 this, 525 this,
526 base::Passed(&source_copy))); 526 base::Passed(&source_copy)));
527 } 527 }
528 528
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 575
576 last_audio_level_log_time_ = base::TimeTicks::Now(); 576 last_audio_level_log_time_ = base::TimeTicks::Now();
577 } 577 }
578 #endif 578 #endif
579 return; 579 return;
580 } 580 }
581 581
582 // TODO(henrika): Investigate if we can avoid the extra copy here. 582 // TODO(henrika): Investigate if we can avoid the extra copy here.
583 // (see http://crbug.com/249316 for details). AFAIK, this scope is only 583 // (see http://crbug.com/249316 for details). AFAIK, this scope is only
584 // active for WebSpeech clients. 584 // active for WebSpeech clients.
585 scoped_ptr<AudioBus> audio_data = 585 std::unique_ptr<AudioBus> audio_data =
586 AudioBus::Create(source->channels(), source->frames()); 586 AudioBus::Create(source->channels(), source->frames());
587 source->CopyTo(audio_data.get()); 587 source->CopyTo(audio_data.get());
588 588
589 // Ownership of the audio buffer will be with the callback until it is run, 589 // Ownership of the audio buffer will be with the callback until it is run,
590 // when ownership is passed to the callback function. 590 // when ownership is passed to the callback function.
591 task_runner_->PostTask( 591 task_runner_->PostTask(
592 FROM_HERE, 592 FROM_HERE,
593 base::Bind( 593 base::Bind(
594 &AudioInputController::DoOnData, this, base::Passed(&audio_data))); 594 &AudioInputController::DoOnData, this, base::Passed(&audio_data)));
595 } 595 }
596 596
597 void AudioInputController::DoOnData(scoped_ptr<AudioBus> data) { 597 void AudioInputController::DoOnData(std::unique_ptr<AudioBus> data) {
598 DCHECK(task_runner_->BelongsToCurrentThread()); 598 DCHECK(task_runner_->BelongsToCurrentThread());
599 if (handler_) 599 if (handler_)
600 handler_->OnData(this, data.get()); 600 handler_->OnData(this, data.get());
601 } 601 }
602 602
603 void AudioInputController::DoLogAudioLevels(float level_dbfs, 603 void AudioInputController::DoLogAudioLevels(float level_dbfs,
604 int microphone_volume_percent) { 604 int microphone_volume_percent) {
605 #if defined(AUDIO_POWER_MONITORING) 605 #if defined(AUDIO_POWER_MONITORING)
606 DCHECK(task_runner_->BelongsToCurrentThread()); 606 DCHECK(task_runner_->BelongsToCurrentThread());
607 if (!handler_) 607 if (!handler_)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 DCHECK(!input_writer_); 722 DCHECK(!input_writer_);
723 input_writer_ = input_writer; 723 input_writer_ = input_writer;
724 } 724 }
725 725
726 void AudioInputController::DoDisableDebugRecording() { 726 void AudioInputController::DoDisableDebugRecording() {
727 DCHECK(task_runner_->BelongsToCurrentThread()); 727 DCHECK(task_runner_->BelongsToCurrentThread());
728 input_writer_ = nullptr; 728 input_writer_ = nullptr;
729 } 729 }
730 730
731 void AudioInputController::WriteInputDataForDebugging( 731 void AudioInputController::WriteInputDataForDebugging(
732 scoped_ptr<AudioBus> data) { 732 std::unique_ptr<AudioBus> data) {
733 DCHECK(task_runner_->BelongsToCurrentThread()); 733 DCHECK(task_runner_->BelongsToCurrentThread());
734 if (input_writer_) 734 if (input_writer_)
735 input_writer_->Write(std::move(data)); 735 input_writer_->Write(std::move(data));
736 } 736 }
737 737
738 } // namespace media 738 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698