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

Side by Side Diff: components/copresence/handlers/directive_handler.cc

Issue 461803003: Stop playing/recording when not needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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/directive_handler.h" 5 #include "components/copresence/handlers/directive_handler.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "components/copresence/handlers/audio/audio_directive_handler.h" 8 #include "components/copresence/handlers/audio/audio_directive_handler.h"
9 #include "components/copresence/proto/data.pb.h" 9 #include "components/copresence/proto/data.pb.h"
10 10
11 namespace copresence { 11 namespace copresence {
12 12
13 DirectiveHandler::DirectiveHandler() {} 13 DirectiveHandler::DirectiveHandler() {}
14 14
15 void DirectiveHandler::Initialize( 15 void DirectiveHandler::Initialize(
16 const AudioRecorder::DecodeSamplesCallback& decode_cb, 16 const AudioRecorder::DecodeSamplesCallback& decode_cb,
17 const AudioDirectiveList::EncodeTokenCallback& encode_cb) { 17 const AudioDirectiveHandler::EncodeTokenCallback& encode_cb) {
18 audio_handler_.reset(new AudioDirectiveHandler(decode_cb, encode_cb)); 18 audio_handler_.reset(new AudioDirectiveHandler(decode_cb, encode_cb));
19 audio_handler_->Initialize(); 19 audio_handler_->Initialize();
20 } 20 }
21 21
22 DirectiveHandler::~DirectiveHandler() { 22 DirectiveHandler::~DirectiveHandler() {
23 } 23 }
24 24
25 void DirectiveHandler::AddDirective(const Directive& directive) { 25 void DirectiveHandler::AddDirective(const Directive& directive) {
26 // We only handle Token directives; wifi/ble requests aren't implemented. 26 // We only handle Token directives; wifi/ble requests aren't implemented.
27 DCHECK_EQ(directive.instruction_type(), TOKEN); 27 DCHECK_EQ(directive.instruction_type(), TOKEN);
28 28
29 std::string op_id;
30 if (directive.has_published_message_id()) {
31 op_id = directive.published_message_id();
32 } else if (directive.has_subscription_id()) {
33 op_id = directive.subscription_id();
34 } else {
35 NOTREACHED() << "No operation associated with directive!";
36 return;
37 }
38
29 const TokenInstruction& ti = directive.token_instruction(); 39 const TokenInstruction& ti = directive.token_instruction();
30 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before " 40 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before "
31 << "any other DirectiveHandler methods."; 41 << "any other DirectiveHandler methods.";
32 // We currently only support audio. 42 // We currently only support audio.
33 if (ti.medium() == AUDIO_ULTRASOUND_PASSBAND || 43 if (ti.medium() == AUDIO_ULTRASOUND_PASSBAND ||
34 ti.medium() == AUDIO_AUDIBLE_DTMF) { 44 ti.medium() == AUDIO_AUDIBLE_DTMF) {
35 audio_handler_->AddInstruction( 45 audio_handler_->AddInstruction(
36 ti, base::TimeDelta::FromMilliseconds(directive.ttl_millis())); 46 ti, op_id, base::TimeDelta::FromMilliseconds(directive.ttl_millis()));
37 } 47 }
38 } 48 }
39 49
40 void DirectiveHandler::RemoveDirectives(const std::string& /* op_id */) { 50 void DirectiveHandler::RemoveDirectives(const std::string& op_id) {
41 // TODO(rkc): Forward the remove directive call to all the directive handlers.
42 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before " 51 DCHECK(audio_handler_.get()) << "Clients must call Initialize() before "
43 << "any other DirectiveHandler methods."; 52 << "any other DirectiveHandler methods.";
53 audio_handler_->RemoveInstructions(op_id);
54 }
55
56 const std::string& DirectiveHandler::CurrentAudibleToken() const {
57 return audio_handler_->PlayingAudibleToken();
58 }
59
60 const std::string& DirectiveHandler::CurrentInaudibleToken() const {
61 return audio_handler_->PlayingInaudibleToken();
44 } 62 }
45 63
46 } // namespace copresence 64 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/handlers/directive_handler.h ('k') | components/copresence/mediums/audio/audio_player.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698