Chromium Code Reviews| 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 ValidateTokenDir(); | |
|
rkc
2015/02/05 01:54:45
This is completely unnecessary. Once you are using
Charlie
2015/02/05 02:01:56
Very well. Deleted.
| |
| 85 | |
| 86 void DumpToken(AudioType audio_type, | |
| 87 const std::string& token, | |
| 88 const media::AudioBus* samples); | |
| 89 | |
| 79 WhispernetClient* whispernet_client_; | 90 WhispernetClient* whispernet_client_; |
| 80 | 91 |
| 81 // Callbacks to send tokens back to the CopresenceManager. | 92 // Callbacks to send tokens back to the CopresenceManager. |
| 82 TokensCallback tokens_cb_; | 93 TokensCallback tokens_cb_; |
| 83 | 94 |
| 84 // This cancelable callback is passed to the recorder. The recorder's | 95 // This cancelable callback is passed to the recorder. The recorder's |
| 85 // destruction will happen on the audio thread, so it can outlive us. | 96 // destruction will happen on the audio thread, so it can outlive us. |
| 86 base::CancelableCallback<void(const std::string&)> decode_cancelable_cb_; | 97 base::CancelableCallback<void(const std::string&)> decode_cancelable_cb_; |
| 87 | 98 |
| 88 // We use the AudioType enum to index into all our data structures that work | 99 // We use the AudioType enum to index into all our data structures that work |
| 89 // on values for both audible and inaudible. | 100 // on values for both audible and inaudible. |
| 90 static_assert(AUDIBLE == 0, "AudioType::AUDIBLE should be 0."); | 101 static_assert(AUDIBLE == 0, "AudioType::AUDIBLE should be 0."); |
| 91 static_assert(INAUDIBLE == 1, "AudioType::INAUDIBLE should be 1."); | 102 static_assert(INAUDIBLE == 1, "AudioType::INAUDIBLE should be 1."); |
| 92 | 103 |
| 93 // Indexed using enum AudioType. | 104 // Indexed using enum AudioType. |
| 105 bool player_enabled_[2]; | |
| 94 bool should_be_playing_[2]; | 106 bool should_be_playing_[2]; |
| 95 bool should_be_recording_[2]; | 107 bool should_be_recording_[2]; |
| 96 | 108 |
| 97 // AudioPlayer and AudioRecorder objects are self-deleting. When we call | 109 // AudioPlayer and AudioRecorder objects are self-deleting. When we call |
| 98 // Finalize on them, they clean themselves up on the Audio thread. | 110 // Finalize on them, they clean themselves up on the Audio thread. |
| 99 // Indexed using enum AudioType. | 111 // Indexed using enum AudioType. |
| 100 AudioPlayer* player_[2]; | 112 AudioPlayer* player_[2]; |
| 101 AudioRecorder* recorder_; | 113 AudioRecorder* recorder_; |
| 102 | 114 |
| 103 // Indexed using enum AudioType. | 115 // Indexed using enum AudioType. |
| 104 std::string playing_token_[2]; | 116 std::string playing_token_[2]; |
| 117 size_t token_length_[2]; | |
| 105 base::Time started_playing_[2]; | 118 base::Time started_playing_[2]; |
| 106 base::Time heard_own_token_[2]; | 119 base::Time heard_own_token_[2]; |
| 107 | 120 |
| 108 // Cache that holds the encoded samples. After reaching its limit, the cache | 121 // Cache that holds the encoded samples. After reaching its limit, the cache |
| 109 // expires the oldest samples first. | 122 // expires the oldest samples first. |
| 110 // Indexed using enum AudioType. | 123 // Indexed using enum AudioType. |
| 111 ScopedVector<SamplesMap> samples_cache_; | 124 ScopedVector<SamplesMap> samples_cache_; |
| 112 | 125 |
| 113 size_t token_length_[2]; | 126 base::FilePath dump_tokens_dir_; |
| 114 | 127 |
| 115 DISALLOW_COPY_AND_ASSIGN(AudioManagerImpl); | 128 DISALLOW_COPY_AND_ASSIGN(AudioManagerImpl); |
| 116 }; | 129 }; |
| 117 | 130 |
| 118 } // namespace copresence | 131 } // namespace copresence |
| 119 | 132 |
| 120 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ | 133 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_MANAGER_IMPL_H_ |
| OLD | NEW |