| Index: components/copresence/handlers/audio/audio_directive_handler_impl.cc
|
| diff --git a/components/copresence/handlers/audio/audio_directive_handler_impl.cc b/components/copresence/handlers/audio/audio_directive_handler_impl.cc
|
| index a27f88f02ae1cadfa497c35bf556fadb9d174e64..16b0269b8ffdb8d17f59d36caefd8b44dc501b85 100644
|
| --- a/components/copresence/handlers/audio/audio_directive_handler_impl.cc
|
| +++ b/components/copresence/handlers/audio/audio_directive_handler_impl.cc
|
| @@ -13,13 +13,16 @@
|
| #include "base/time/default_tick_clock.h"
|
| #include "base/time/time.h"
|
| #include "base/timer/timer.h"
|
| +#include "components/audio_modem/public/modem.h"
|
| #include "components/copresence/handlers/audio/audio_directive_list.h"
|
| #include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
|
| -#include "components/copresence/mediums/audio/audio_manager_impl.h"
|
| #include "components/copresence/proto/data.pb.h"
|
| #include "components/copresence/public/copresence_constants.h"
|
| #include "media/base/audio_bus.h"
|
|
|
| +using audio_modem::AUDIBLE;
|
| +using audio_modem::INAUDIBLE;
|
| +
|
| namespace copresence {
|
|
|
| namespace {
|
| @@ -48,27 +51,27 @@ void ConvertDirectives(const std::vector<AudioDirective>& in_directives,
|
| AudioDirectiveHandlerImpl::AudioDirectiveHandlerImpl(
|
| const DirectivesCallback& update_directives_callback)
|
| : update_directives_callback_(update_directives_callback),
|
| - audio_manager_(new AudioManagerImpl),
|
| + audio_modem_(audio_modem::Modem::Create()),
|
| audio_event_timer_(new base::OneShotTimer<AudioDirectiveHandler>),
|
| clock_(new TickClockRefCounted(new base::DefaultTickClock)) {}
|
|
|
| AudioDirectiveHandlerImpl::AudioDirectiveHandlerImpl(
|
| const DirectivesCallback& update_directives_callback,
|
| - scoped_ptr<AudioManager> audio_manager,
|
| + scoped_ptr<audio_modem::Modem> audio_modem,
|
| scoped_ptr<base::Timer> timer,
|
| const scoped_refptr<TickClockRefCounted>& clock)
|
| : update_directives_callback_(update_directives_callback),
|
| - audio_manager_(audio_manager.Pass()),
|
| + audio_modem_(audio_modem.Pass()),
|
| audio_event_timer_(timer.Pass()),
|
| clock_(clock) {}
|
|
|
| AudioDirectiveHandlerImpl::~AudioDirectiveHandlerImpl() {}
|
|
|
| -void AudioDirectiveHandlerImpl::Initialize(WhispernetClient* whispernet_client,
|
| - const TokensCallback& tokens_cb) {
|
| - if (!audio_manager_)
|
| - audio_manager_.reset(new AudioManagerImpl());
|
| - audio_manager_->Initialize(whispernet_client, tokens_cb);
|
| +void AudioDirectiveHandlerImpl::Initialize(
|
| + audio_modem::WhispernetClient* whispernet_client,
|
| + const audio_modem::TokensCallback& tokens_cb) {
|
| + DCHECK(audio_modem_);
|
| + audio_modem_->Initialize(whispernet_client, tokens_cb);
|
|
|
| DCHECK(transmits_lists_.empty());
|
| transmits_lists_.push_back(new AudioDirectiveList(clock_));
|
| @@ -99,14 +102,14 @@ void AudioDirectiveHandlerImpl::AddInstruction(
|
| DCHECK_GT(token_length, 0u);
|
| switch (instruction.medium()) {
|
| case AUDIO_ULTRASOUND_PASSBAND:
|
| - audio_manager_->SetTokenLength(INAUDIBLE, token_length);
|
| + audio_modem_->SetTokenLength(INAUDIBLE, token_length);
|
| transmits_lists_[INAUDIBLE]->AddDirective(op_id, directive);
|
| - audio_manager_->SetToken(INAUDIBLE, instruction.token_id());
|
| + audio_modem_->SetToken(INAUDIBLE, instruction.token_id());
|
| break;
|
| case AUDIO_AUDIBLE_DTMF:
|
| - audio_manager_->SetTokenLength(AUDIBLE, token_length);
|
| + audio_modem_->SetTokenLength(AUDIBLE, token_length);
|
| transmits_lists_[AUDIBLE]->AddDirective(op_id, directive);
|
| - audio_manager_->SetToken(AUDIBLE, instruction.token_id());
|
| + audio_modem_->SetToken(AUDIBLE, instruction.token_id());
|
| break;
|
| default:
|
| NOTREACHED();
|
| @@ -120,11 +123,11 @@ void AudioDirectiveHandlerImpl::AddInstruction(
|
| DCHECK_GT(token_length, 0u);
|
| switch (instruction.medium()) {
|
| case AUDIO_ULTRASOUND_PASSBAND:
|
| - audio_manager_->SetTokenLength(INAUDIBLE, token_length);
|
| + audio_modem_->SetTokenLength(INAUDIBLE, token_length);
|
| receives_lists_[INAUDIBLE]->AddDirective(op_id, directive);
|
| break;
|
| case AUDIO_AUDIBLE_DTMF:
|
| - audio_manager_->SetTokenLength(AUDIBLE, token_length);
|
| + audio_modem_->SetTokenLength(AUDIBLE, token_length);
|
| receives_lists_[AUDIBLE]->AddDirective(op_id, directive);
|
| break;
|
| default:
|
| @@ -154,12 +157,13 @@ void AudioDirectiveHandlerImpl::RemoveInstructions(const std::string& op_id) {
|
| }
|
|
|
| const std::string AudioDirectiveHandlerImpl::PlayingToken(
|
| - AudioType type) const {
|
| - return audio_manager_->GetToken(type);
|
| + audio_modem::AudioType type) const {
|
| + return audio_modem_->GetToken(type);
|
| }
|
|
|
| -bool AudioDirectiveHandlerImpl::IsPlayingTokenHeard(AudioType type) const {
|
| - return audio_manager_->IsPlayingTokenHeard(type);
|
| +bool AudioDirectiveHandlerImpl::IsPlayingTokenHeard(
|
| + audio_modem::AudioType type) const {
|
| + return audio_modem_->IsPlayingTokenHeard(type);
|
| }
|
|
|
|
|
| @@ -169,29 +173,29 @@ void AudioDirectiveHandlerImpl::ProcessNextInstruction() {
|
| DCHECK(audio_event_timer_);
|
| audio_event_timer_->Stop();
|
|
|
| - // Change |audio_manager_| state for audible transmits.
|
| + // Change |audio_modem_| state for audible transmits.
|
| if (transmits_lists_[AUDIBLE]->GetActiveDirective())
|
| - audio_manager_->StartPlaying(AUDIBLE);
|
| + audio_modem_->StartPlaying(AUDIBLE);
|
| else
|
| - audio_manager_->StopPlaying(AUDIBLE);
|
| + audio_modem_->StopPlaying(AUDIBLE);
|
|
|
| - // Change audio_manager_ state for inaudible transmits.
|
| + // Change audio_modem_ state for inaudible transmits.
|
| if (transmits_lists_[INAUDIBLE]->GetActiveDirective())
|
| - audio_manager_->StartPlaying(INAUDIBLE);
|
| + audio_modem_->StartPlaying(INAUDIBLE);
|
| else
|
| - audio_manager_->StopPlaying(INAUDIBLE);
|
| + audio_modem_->StopPlaying(INAUDIBLE);
|
|
|
| - // Change audio_manager_ state for audible receives.
|
| + // Change audio_modem_ state for audible receives.
|
| if (receives_lists_[AUDIBLE]->GetActiveDirective())
|
| - audio_manager_->StartRecording(AUDIBLE);
|
| + audio_modem_->StartRecording(AUDIBLE);
|
| else
|
| - audio_manager_->StopRecording(AUDIBLE);
|
| + audio_modem_->StopRecording(AUDIBLE);
|
|
|
| - // Change audio_manager_ state for inaudible receives.
|
| + // Change audio_modem_ state for inaudible receives.
|
| if (receives_lists_[INAUDIBLE]->GetActiveDirective())
|
| - audio_manager_->StartRecording(INAUDIBLE);
|
| + audio_modem_->StartRecording(INAUDIBLE);
|
| else
|
| - audio_manager_->StopRecording(INAUDIBLE);
|
| + audio_modem_->StopRecording(INAUDIBLE);
|
|
|
| base::TimeTicks next_event_time;
|
| if (GetNextInstructionExpiry(&next_event_time)) {
|
|
|