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

Side by Side Diff: components/copresence/handlers/audio/audio_directive_handler_impl.h

Issue 764673003: Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing overzealous DCHECK Created 6 years 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 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "components/copresence/handlers/audio/audio_directive_handler.h" 14 #include "components/copresence/handlers/audio/audio_directive_handler.h"
15 #include "components/copresence/public/copresence_constants.h"
15 16
16 namespace base { 17 namespace base {
17 class TimeTicks; 18 class TimeTicks;
18 class Timer; 19 class Timer;
19 } 20 }
20 21
21 namespace media { 22 namespace media {
22 class AudioBusRefCounted; 23 class AudioBusRefCounted;
23 } 24 }
24 25
25 namespace copresence { 26 namespace copresence {
26 27
27 class AudioDirectiveList; 28 class AudioDirectiveList;
28 class TickClockRefCounted; 29 class TickClockRefCounted;
29 30
30 // The AudioDirectiveHandler handles audio transmit and receive instructions. 31 // The AudioDirectiveHandler handles audio transmit and receive instructions.
31 // TODO(rkc): Currently since WhispernetClient can only have one token encoded 32 // TODO(rkc): Currently since WhispernetClient can only have one token encoded
32 // callback at a time, we need to have both the audible and inaudible in this 33 // callback at a time, we need to have both the audible and inaudible in this
33 // class. Investigate a better way to do this; a few options are abstracting 34 // class. Investigate a better way to do this; a few options are abstracting
34 // out token encoding to a separate class, or allowing whispernet to have 35 // out token encoding to a separate class, or allowing whispernet to have
35 // multiple callbacks for encoded tokens being sent back and have two versions 36 // multiple callbacks for encoded tokens being sent back and have two versions
36 // of this class. 37 // of this class.
37 class AudioDirectiveHandlerImpl final : public AudioDirectiveHandler { 38 class AudioDirectiveHandlerImpl final : public AudioDirectiveHandler {
38 public: 39 public:
39 AudioDirectiveHandlerImpl(); 40 explicit AudioDirectiveHandlerImpl(
40 AudioDirectiveHandlerImpl(scoped_ptr<AudioManager> audio_manager, 41 const DirectivesCallback& update_directives_callback);
41 scoped_ptr<base::Timer> timer, 42 AudioDirectiveHandlerImpl(
42 const scoped_refptr<TickClockRefCounted>& clock); 43 const DirectivesCallback& update_directives_callback,
44 scoped_ptr<AudioManager> audio_manager,
45 scoped_ptr<base::Timer> timer,
46 const scoped_refptr<TickClockRefCounted>& clock);
43 47
44 ~AudioDirectiveHandlerImpl(); 48 ~AudioDirectiveHandlerImpl();
xiyuan 2014/12/18 18:10:52 nit: override?
Charlie 2014/12/19 03:53:33 Done.
45 49
46 // AudioDirectiveHandler overrides: 50 // AudioDirectiveHandler overrides:
47 void Initialize(WhispernetClient* whispernet_client, 51 void Initialize(WhispernetClient* whispernet_client,
48 const TokensCallback& tokens_cb) override; 52 const TokensCallback& tokens_cb) override;
49 void AddInstruction(const copresence::TokenInstruction& instruction, 53 void AddInstruction(const Directive& directive,
50 const std::string& op_id, 54 const std::string& op_id) override;
51 base::TimeDelta ttl) override;
52 void RemoveInstructions(const std::string& op_id) override; 55 void RemoveInstructions(const std::string& op_id) override;
53 const std::string PlayingToken(AudioType type) const override; 56 const std::string PlayingToken(AudioType type) const override;
54 bool IsPlayingTokenHeard(AudioType type) const override; 57 bool IsPlayingTokenHeard(AudioType type) const override;
55 58
56 private: 59 private:
57 // Processes the next active instruction, 60 // Processes the next active instruction,
58 // updating our audio manager state accordingly. 61 // updating our audio manager state accordingly.
59 void ProcessNextInstruction(); 62 void ProcessNextInstruction();
60 63
61 // Returns the time that an instruction expires at. This will always return 64 // Returns the time that an instruction expires at. This will always return
62 // the earliest expiry time among all the active receive and transmit 65 // the earliest expiry time among all the active receive and transmit
63 // instructions. If we don't have any active instructions, returns false. 66 // instructions. If we don't have any active instructions, returns false.
64 bool GetNextInstructionExpiry(base::TimeTicks* next_event); 67 bool GetNextInstructionExpiry(base::TimeTicks* next_event);
65 68
69 DirectivesCallback update_directives_callback_;
66 scoped_ptr<AudioManager> audio_manager_; 70 scoped_ptr<AudioManager> audio_manager_;
67
68 scoped_ptr<base::Timer> audio_event_timer_; 71 scoped_ptr<base::Timer> audio_event_timer_;
69 scoped_refptr<TickClockRefCounted> clock_; 72 scoped_refptr<TickClockRefCounted> clock_;
70 73
71 // Lists of transmits and receives, for both audible and inaudible tokens. 74 // Lists of transmits and receives, for both audible and inaudible tokens.
72 // AUDIBLE = element 0, INAUDIBLE = element 1 (see copresence_constants.h). 75 // AUDIBLE = element 0, INAUDIBLE = element 1 (see copresence_constants.h).
73 ScopedVector<AudioDirectiveList> transmits_lists_; 76 ScopedVector<AudioDirectiveList> transmits_lists_;
74 ScopedVector<AudioDirectiveList> receives_lists_; 77 ScopedVector<AudioDirectiveList> receives_lists_;
75 78
76
77 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandlerImpl); 79 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandlerImpl);
78 }; 80 };
79 81
80 } // namespace copresence 82 } // namespace copresence
81 83
82 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ 84 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698