OLD | NEW |
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_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ | 5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ |
6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ | 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
| 13 #include "base/files/file_path.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
16 #include "components/copresence/mediums/audio/audio_manager.h" | 17 #include "components/copresence/mediums/audio/audio_manager.h" |
17 #include "components/copresence/public/copresence_constants.h" | 18 #include "components/copresence/public/copresence_constants.h" |
18 #include "components/copresence/timed_map.h" | 19 #include "components/copresence/timed_map.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class Time; | 22 class Time; |
22 } | 23 } |
23 | 24 |
| 25 namespace media { |
| 26 class AudioBus; |
| 27 } |
| 28 |
24 namespace copresence { | 29 namespace copresence { |
25 | 30 |
26 class AudioPlayer; | 31 class AudioPlayer; |
27 class AudioRecorder; | 32 class AudioRecorder; |
28 class WhispernetClient; | 33 class WhispernetClient; |
29 | 34 |
30 // The AudioManagerImpl class manages the playback and recording of tokens. Once | 35 // The AudioManagerImpl class manages the playback and recording of tokens. Once |
31 // playback or recording is started, it is up to the audio manager to handle | 36 // playback or recording is started, it is up to the audio manager to handle |
32 // the specifics of how this is done. In the future, for example, this class | 37 // the specifics of how this is done. In the future, for example, this class |
33 // may pause recording and playback to implement carrier sense. | 38 // may pause recording and playback to implement carrier sense. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 74 |
70 // Update our currently playing token with the new token. Change the playing | 75 // Update our currently playing token with the new token. Change the playing |
71 // samples if needed. Prerequisite: Samples corresponding to this token | 76 // samples if needed. Prerequisite: Samples corresponding to this token |
72 // should already be in the samples cache. | 77 // should already be in the samples cache. |
73 void UpdateToken(AudioType type, const std::string& token); | 78 void UpdateToken(AudioType type, const std::string& token); |
74 | 79 |
75 void RestartPlaying(AudioType type); | 80 void RestartPlaying(AudioType type); |
76 | 81 |
77 void DecodeSamplesConnector(const std::string& samples); | 82 void DecodeSamplesConnector(const std::string& samples); |
78 | 83 |
| 84 void DumpToken(AudioType audio_type, |
| 85 const std::string& token, |
| 86 const media::AudioBus* samples); |
| 87 |
79 WhispernetClient* whispernet_client_; | 88 WhispernetClient* whispernet_client_; |
80 | 89 |
81 // Callbacks to send tokens back to the CopresenceManager. | 90 // Callbacks to send tokens back to the CopresenceManager. |
82 TokensCallback tokens_cb_; | 91 TokensCallback tokens_cb_; |
83 | 92 |
84 // This cancelable callback is passed to the recorder. The recorder's | 93 // This cancelable callback is passed to the recorder. The recorder's |
85 // destruction will happen on the audio thread, so it can outlive us. | 94 // destruction will happen on the audio thread, so it can outlive us. |
86 base::CancelableCallback<void(const std::string&)> decode_cancelable_cb_; | 95 base::CancelableCallback<void(const std::string&)> decode_cancelable_cb_; |
87 | 96 |
88 // We use the AudioType enum to index into all our data structures that work | 97 // We use the AudioType enum to index into all our data structures that work |
89 // on values for both audible and inaudible. | 98 // on values for both audible and inaudible. |
90 static_assert(AUDIBLE == 0, "AudioType::AUDIBLE should be 0."); | 99 static_assert(AUDIBLE == 0, "AudioType::AUDIBLE should be 0."); |
91 static_assert(INAUDIBLE == 1, "AudioType::INAUDIBLE should be 1."); | 100 static_assert(INAUDIBLE == 1, "AudioType::INAUDIBLE should be 1."); |
92 | 101 |
93 // Indexed using enum AudioType. | 102 // Indexed using enum AudioType. |
| 103 bool player_enabled_[2]; |
94 bool should_be_playing_[2]; | 104 bool should_be_playing_[2]; |
95 bool should_be_recording_[2]; | 105 bool should_be_recording_[2]; |
96 | 106 |
97 // AudioPlayer and AudioRecorder objects are self-deleting. When we call | 107 // AudioPlayer and AudioRecorder objects are self-deleting. When we call |
98 // Finalize on them, they clean themselves up on the Audio thread. | 108 // Finalize on them, they clean themselves up on the Audio thread. |
99 // Indexed using enum AudioType. | 109 // Indexed using enum AudioType. |
100 AudioPlayer* player_[2]; | 110 AudioPlayer* player_[2]; |
101 AudioRecorder* recorder_; | 111 AudioRecorder* recorder_; |
102 | 112 |
103 // Indexed using enum AudioType. | 113 // Indexed using enum AudioType. |
104 std::string playing_token_[2]; | 114 std::string playing_token_[2]; |
| 115 size_t token_length_[2]; |
105 base::Time started_playing_[2]; | 116 base::Time started_playing_[2]; |
106 base::Time heard_own_token_[2]; | 117 base::Time heard_own_token_[2]; |
107 | 118 |
108 // Cache that holds the encoded samples. After reaching its limit, the cache | 119 // Cache that holds the encoded samples. After reaching its limit, the cache |
109 // expires the oldest samples first. | 120 // expires the oldest samples first. |
110 // Indexed using enum AudioType. | 121 // Indexed using enum AudioType. |
111 ScopedVector<SamplesMap> samples_cache_; | 122 ScopedVector<SamplesMap> samples_cache_; |
112 | 123 |
113 size_t token_length_[2]; | 124 base::FilePath dump_tokens_dir_; |
114 | 125 |
115 DISALLOW_COPY_AND_ASSIGN(AudioManagerImpl); | 126 DISALLOW_COPY_AND_ASSIGN(AudioManagerImpl); |
116 }; | 127 }; |
117 | 128 |
118 } // namespace copresence | 129 } // namespace copresence |
119 | 130 |
120 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ | 131 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ |
OLD | NEW |