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

Side by Side Diff: components/copresence/handlers/audio/audio_directive_handler.cc

Issue 665353002: Add AudioDirectiveHandler timed tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_redesign
Patch Set: Created 6 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/copresence/handlers/audio/audio_directive_handler.h" 5 #include "components/copresence/handlers/audio/audio_directive_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/default_tick_clock.h" 10 #include "base/time/default_tick_clock.h"
11 #include "base/time/tick_clock.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
13 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
14 #include "components/copresence/proto/data.pb.h" 14 #include "components/copresence/proto/data.pb.h"
15 #include "components/copresence/public/copresence_constants.h" 15 #include "components/copresence/public/copresence_constants.h"
16 #include "media/base/audio_bus.h" 16 #include "media/base/audio_bus.h"
17 17
18 namespace copresence { 18 namespace copresence {
19 19
20 namespace { 20 namespace {
21 21
22 base::TimeTicks GetEarliestEventTime(AudioDirectiveList* list, 22 base::TimeTicks GetEarliestEventTime(AudioDirectiveList* list,
23 base::TimeTicks event_time) { 23 base::TimeTicks event_time) {
24 if (list->GetActiveDirective()) 24 if (list->GetActiveDirective())
25 return std::min(list->GetActiveDirective()->end_time, event_time); 25 return std::min(list->GetActiveDirective()->end_time, event_time);
26 return event_time; 26 return event_time;
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 // Public methods. 31 // Public methods.
32 32
33 AudioDirectiveHandler::AudioDirectiveHandler() 33 AudioDirectiveHandler::AudioDirectiveHandler()
34 : audio_event_timer_(new base::OneShotTimer<AudioDirectiveHandler>), 34 : audio_event_timer_(new base::OneShotTimer<AudioDirectiveHandler>),
35 clock_(new base::DefaultTickClock) { 35 clock_(new TickClockRefCounted(new base::DefaultTickClock)) {
36 } 36 }
37 37
38 AudioDirectiveHandler::~AudioDirectiveHandler() { 38 AudioDirectiveHandler::~AudioDirectiveHandler() {
39 } 39 }
40 40
41 void AudioDirectiveHandler::Initialize( 41 void AudioDirectiveHandler::Initialize(
42 const AudioManager::DecodeSamplesCallback& decode_cb, 42 const AudioManager::DecodeSamplesCallback& decode_cb,
43 const AudioManager::EncodeTokenCallback& encode_cb) { 43 const AudioManager::EncodeTokenCallback& encode_cb) {
44 if (!audio_manager_.get()) 44 if (!audio_manager_.get())
45 audio_manager_.reset(new AudioManagerImpl()); 45 audio_manager_.reset(new AudioManagerImpl());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 void AudioDirectiveHandler::RemoveInstructions(const std::string& op_id) { 94 void AudioDirectiveHandler::RemoveInstructions(const std::string& op_id) {
95 transmits_list_[AUDIBLE].RemoveDirective(op_id); 95 transmits_list_[AUDIBLE].RemoveDirective(op_id);
96 transmits_list_[INAUDIBLE].RemoveDirective(op_id); 96 transmits_list_[INAUDIBLE].RemoveDirective(op_id);
97 receives_list_[AUDIBLE].RemoveDirective(op_id); 97 receives_list_[AUDIBLE].RemoveDirective(op_id);
98 receives_list_[INAUDIBLE].RemoveDirective(op_id); 98 receives_list_[INAUDIBLE].RemoveDirective(op_id);
99 99
100 ProcessNextInstruction(); 100 ProcessNextInstruction();
101 } 101 }
102 102
103 void AudioDirectiveHandler::set_clock_for_testing(
104 const scoped_refptr<TickClockRefCounted>& clock) {
105 clock_ = clock;
106
107 transmits_list_[AUDIBLE].set_clock_for_testing(clock);
108 transmits_list_[INAUDIBLE].set_clock_for_testing(clock);
109 receives_list_[AUDIBLE].set_clock_for_testing(clock);
110 receives_list_[INAUDIBLE].set_clock_for_testing(clock);
111 }
112
113 void AudioDirectiveHandler::set_timer_for_testing(
114 scoped_ptr<base::Timer> timer) {
115 audio_event_timer_.swap(timer);
116 }
117
103 // Private methods. 118 // Private methods.
104 119
105 void AudioDirectiveHandler::ProcessNextInstruction() { 120 void AudioDirectiveHandler::ProcessNextInstruction() {
106 DCHECK(audio_event_timer_); 121 DCHECK(audio_event_timer_);
107 audio_event_timer_->Stop(); 122 audio_event_timer_->Stop();
108 123
109 // Change audio_manager_ state for audible transmits. 124 // Change audio_manager_ state for audible transmits.
110 if (transmits_list_[AUDIBLE].GetActiveDirective()) 125 if (transmits_list_[AUDIBLE].GetActiveDirective())
111 audio_manager_->StartPlaying(AUDIBLE); 126 audio_manager_->StartPlaying(AUDIBLE);
112 else 127 else
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // directives; or that they are all due to expire a bazzilion years from now. 172 // directives; or that they are all due to expire a bazzilion years from now.
158 // The latter is not possible since the max life of a directive is 1 day, 173 // The latter is not possible since the max life of a directive is 1 day,
159 // this is enforced by the API. 174 // this is enforced by the API.
160 if (next_event == max) 175 if (next_event == max)
161 return false; 176 return false;
162 else 177 else
163 return true; 178 return true;
164 } 179 }
165 180
166 } // namespace copresence 181 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698