Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 // platform version 2.3) or later, then we can still use the OpenSL ES APIs but | 48 // platform version 2.3) or later, then we can still use the OpenSL ES APIs but |
| 49 // the output latency may be higher. | 49 // the output latency may be higher. |
| 50 class OpenSLESPlayer { | 50 class OpenSLESPlayer { |
| 51 public: | 51 public: |
| 52 // The lower output latency path is used only if the application requests a | 52 // The lower output latency path is used only if the application requests a |
| 53 // buffer count of 2 or more, and a buffer size and sample rate that are | 53 // buffer count of 2 or more, and a buffer size and sample rate that are |
| 54 // compatible with the device's native output configuration provided via the | 54 // compatible with the device's native output configuration provided via the |
| 55 // audio manager at construction. | 55 // audio manager at construction. |
| 56 static const int kNumOfOpenSLESBuffers = 4; | 56 static const int kNumOfOpenSLESBuffers = 4; |
| 57 | 57 |
| 58 // There is no need for this class to use JNI. | |
| 59 static int32_t SetAndroidAudioDeviceObjects(void* javaVM, void* context) { | |
| 60 return 0; | |
| 61 } | |
| 62 static void ClearAndroidAudioDeviceObjects() {} | |
| 63 | |
| 64 explicit OpenSLESPlayer(AudioManager* audio_manager); | 58 explicit OpenSLESPlayer(AudioManager* audio_manager); |
| 65 ~OpenSLESPlayer(); | 59 ~OpenSLESPlayer(); |
| 66 | 60 |
| 67 int Init(); | 61 int Init(); |
| 68 int Terminate(); | 62 int Terminate(); |
| 69 | 63 |
| 70 int InitPlayout(); | 64 int InitPlayout(); |
| 71 bool PlayoutIsInitialized() const { return initialized_; } | 65 bool PlayoutIsInitialized() const { return initialized_; } |
| 72 | 66 |
| 73 int StartPlayout(); | 67 int StartPlayout(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 96 | 90 |
| 97 // Configures the SL_DATAFORMAT_PCM structure. | 91 // Configures the SL_DATAFORMAT_PCM structure. |
| 98 SLDataFormat_PCM CreatePCMConfiguration(size_t channels, | 92 SLDataFormat_PCM CreatePCMConfiguration(size_t channels, |
| 99 int sample_rate, | 93 int sample_rate, |
| 100 size_t bits_per_sample); | 94 size_t bits_per_sample); |
| 101 | 95 |
| 102 // Allocate memory for audio buffers which will be used to render audio | 96 // Allocate memory for audio buffers which will be used to render audio |
| 103 // via the SLAndroidSimpleBufferQueueItf interface. | 97 // via the SLAndroidSimpleBufferQueueItf interface. |
| 104 void AllocateDataBuffers(); | 98 void AllocateDataBuffers(); |
| 105 | 99 |
| 106 // Creates/destroys the main engine object and the SLEngineItf interface. | 100 // Gets the SL Engine Interface from the existing global Engine object. |
| 107 bool CreateEngine(); | 101 // This interface exposes creation methods of all the OpenSL ES object types. |
| 108 void DestroyEngine(); | 102 bool GetEngineInterface(); |
|
magjed_webrtc
2016/05/31 11:24:07
I don't think calling this function 'GetEngineInte
henrika_webrtc
2016/05/31 12:04:03
Good point. However, the OpenSL ES API is a bit me
| |
| 109 | 103 |
| 110 // Creates/destroys the output mix object. | 104 // Creates/destroys the output mix object. |
| 111 bool CreateMix(); | 105 bool CreateMix(); |
| 112 void DestroyMix(); | 106 void DestroyMix(); |
| 113 | 107 |
| 114 // Creates/destroys the audio player and the simple-buffer object. | 108 // Creates/destroys the audio player and the simple-buffer object. |
| 115 // Also creates the volume object. | 109 // Also creates the volume object. |
| 116 bool CreateAudioPlayer(); | 110 bool CreateAudioPlayer(); |
| 117 void DestroyAudioPlayer(); | 111 void DestroyAudioPlayer(); |
| 118 | 112 |
| 119 SLuint32 GetPlayState() const; | 113 SLuint32 GetPlayState() const; |
| 120 | 114 |
| 121 // Ensures that methods are called from the same thread as this object is | 115 // Ensures that methods are called from the same thread as this object is |
| 122 // created on. | 116 // created on. |
| 123 rtc::ThreadChecker thread_checker_; | 117 rtc::ThreadChecker thread_checker_; |
| 124 | 118 |
| 125 // Stores thread ID in first call to SimpleBufferQueueCallback() from internal | 119 // Stores thread ID in first call to SimpleBufferQueueCallback() from internal |
| 126 // non-application thread which is not attached to the Dalvik JVM. | 120 // non-application thread which is not attached to the Dalvik JVM. |
| 127 // Detached during construction of this object. | 121 // Detached during construction of this object. |
| 128 rtc::ThreadChecker thread_checker_opensles_; | 122 rtc::ThreadChecker thread_checker_opensles_; |
| 129 | 123 |
| 124 // Raw pointer to the audio manager injected at construction. Used to cache | |
| 125 // audio parameters and to access the global SL engine object needed by the | |
| 126 // GetEngineInterface() method. | |
| 127 AudioManager* audio_manager_; | |
|
magjed_webrtc
2016/05/31 11:24:07
Can you comment on the lifetime of AudioManager? I
henrika_webrtc
2016/05/31 12:04:03
Done.
| |
| 128 | |
| 130 // Contains audio parameters provided to this class at construction by the | 129 // Contains audio parameters provided to this class at construction by the |
| 131 // AudioManager. | 130 // AudioManager. |
| 132 const AudioParameters audio_parameters_; | 131 const AudioParameters audio_parameters_; |
| 133 | 132 |
| 134 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the | 133 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the |
| 135 // AudioDeviceModuleImpl class and called by AudioDeviceModule::Create(). | 134 // AudioDeviceModuleImpl class and called by AudioDeviceModule::Create(). |
| 136 AudioDeviceBuffer* audio_device_buffer_; | 135 AudioDeviceBuffer* audio_device_buffer_; |
| 137 | 136 |
| 138 bool initialized_; | 137 bool initialized_; |
| 139 bool playing_; | 138 bool playing_; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 162 // WebRTC will provide 480 audio frames per 10ms but OpenSL ES asks for 240 | 161 // WebRTC will provide 480 audio frames per 10ms but OpenSL ES asks for 240 |
| 163 // in each callback (one every 5ms). This class can then ask for 240 and the | 162 // in each callback (one every 5ms). This class can then ask for 240 and the |
| 164 // FineAudioBuffer will ask WebRTC for new data only every second callback | 163 // FineAudioBuffer will ask WebRTC for new data only every second callback |
| 165 // and also cach non-utilized audio. | 164 // and also cach non-utilized audio. |
| 166 std::unique_ptr<FineAudioBuffer> fine_buffer_; | 165 std::unique_ptr<FineAudioBuffer> fine_buffer_; |
| 167 | 166 |
| 168 // Keeps track of active audio buffer 'n' in the audio_buffers_[n] queue. | 167 // Keeps track of active audio buffer 'n' in the audio_buffers_[n] queue. |
| 169 // Example (kNumOfOpenSLESBuffers = 2): counts 0, 1, 0, 1, ... | 168 // Example (kNumOfOpenSLESBuffers = 2): counts 0, 1, 0, 1, ... |
| 170 int buffer_index_; | 169 int buffer_index_; |
| 171 | 170 |
| 172 // The engine object which provides the SLEngineItf interface. | |
| 173 // Created by the global Open SL ES constructor slCreateEngine(). | |
| 174 webrtc::ScopedSLObjectItf engine_object_; | |
| 175 | |
| 176 // This interface exposes creation methods for all the OpenSL ES object types. | 171 // This interface exposes creation methods for all the OpenSL ES object types. |
| 177 // It is the OpenSL ES API entry point. | 172 // It is the OpenSL ES API entry point. |
| 178 SLEngineItf engine_; | 173 SLEngineItf engine_; |
| 179 | 174 |
| 180 // Output mix object to be used by the player object. | 175 // Output mix object to be used by the player object. |
| 181 webrtc::ScopedSLObjectItf output_mix_; | 176 webrtc::ScopedSLObjectItf output_mix_; |
| 182 | 177 |
| 183 // The audio player media object plays out audio to the speakers. It also | 178 // The audio player media object plays out audio to the speakers. It also |
| 184 // supports volume control. | 179 // supports volume control. |
| 185 webrtc::ScopedSLObjectItf player_object_; | 180 webrtc::ScopedSLObjectItf player_object_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 197 // properties. This interface is supported on the Audio Player object. | 192 // properties. This interface is supported on the Audio Player object. |
| 198 SLVolumeItf volume_; | 193 SLVolumeItf volume_; |
| 199 | 194 |
| 200 // Last time the OpenSL ES layer asked for audio data to play out. | 195 // Last time the OpenSL ES layer asked for audio data to play out. |
| 201 uint32_t last_play_time_; | 196 uint32_t last_play_time_; |
| 202 }; | 197 }; |
| 203 | 198 |
| 204 } // namespace webrtc | 199 } // namespace webrtc |
| 205 | 200 |
| 206 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_PLAYER_H_ | 201 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_PLAYER_H_ |
| OLD | NEW |