| 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 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_H_ | 12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_H_ |
| 13 | 13 |
| 14 #include <jni.h> | 14 #include <jni.h> |
| 15 | 15 |
| 16 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
| 17 #include "webrtc/base/thread_checker.h" | 17 #include "webrtc/base/thread_checker.h" |
| 18 #include "webrtc/modules/audio_device/android/audio_common.h" | 18 #include "webrtc/modules/audio_device/android/audio_common.h" |
| 19 #include "webrtc/modules/audio_device/audio_device_config.h" |
| 19 #include "webrtc/modules/audio_device/include/audio_device_defines.h" | 20 #include "webrtc/modules/audio_device/include/audio_device_defines.h" |
| 20 #include "webrtc/modules/audio_device/audio_device_generic.h" | 21 #include "webrtc/modules/audio_device/audio_device_generic.h" |
| 21 #include "webrtc/modules/utility/interface/helpers_android.h" | 22 #include "webrtc/modules/utility/interface/helpers_android.h" |
| 22 #include "webrtc/modules/utility/interface/jvm_android.h" | 23 #include "webrtc/modules/utility/interface/jvm_android.h" |
| 23 | 24 |
| 24 namespace webrtc { | 25 namespace webrtc { |
| 25 | 26 |
| 26 class AudioParameters { | |
| 27 public: | |
| 28 enum { kBitsPerSample = 16 }; | |
| 29 AudioParameters() | |
| 30 : sample_rate_(0), | |
| 31 channels_(0), | |
| 32 frames_per_buffer_(0), | |
| 33 frames_per_10ms_buffer_(0), | |
| 34 bits_per_sample_(kBitsPerSample) {} | |
| 35 AudioParameters(int sample_rate, int channels, int frames_per_buffer) | |
| 36 : sample_rate_(sample_rate), | |
| 37 channels_(channels), | |
| 38 frames_per_buffer_(frames_per_buffer), | |
| 39 frames_per_10ms_buffer_(sample_rate / 100), | |
| 40 bits_per_sample_(kBitsPerSample) {} | |
| 41 void reset(int sample_rate, int channels, int frames_per_buffer) { | |
| 42 sample_rate_ = sample_rate; | |
| 43 channels_ = channels; | |
| 44 frames_per_buffer_ = frames_per_buffer; | |
| 45 frames_per_10ms_buffer_ = (sample_rate / 100); | |
| 46 } | |
| 47 int sample_rate() const { return sample_rate_; } | |
| 48 int channels() const { return channels_; } | |
| 49 int frames_per_buffer() const { return frames_per_buffer_; } | |
| 50 int frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; } | |
| 51 int bits_per_sample() const { return bits_per_sample_; } | |
| 52 bool is_valid() const { | |
| 53 return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0)); | |
| 54 } | |
| 55 int GetBytesPerFrame() const { return channels_ * bits_per_sample_ / 8; } | |
| 56 int GetBytesPerBuffer() const { | |
| 57 return frames_per_buffer_ * GetBytesPerFrame(); | |
| 58 } | |
| 59 int GetBytesPer10msBuffer() const { | |
| 60 return frames_per_10ms_buffer_ * GetBytesPerFrame(); | |
| 61 } | |
| 62 float GetBufferSizeInMilliseconds() const { | |
| 63 if (sample_rate_ == 0) | |
| 64 return 0.0f; | |
| 65 return frames_per_buffer_ / (sample_rate_ / 1000.0f); | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 int sample_rate_; | |
| 70 int channels_; | |
| 71 // Lowest possible size of native audio buffer. Measured in number of frames. | |
| 72 // This size is injected into the OpenSL ES output (since it does not "talk | |
| 73 // Java") implementation but is currently not utilized by the Java | |
| 74 // implementation since it aquires the same value internally. | |
| 75 int frames_per_buffer_; | |
| 76 int frames_per_10ms_buffer_; | |
| 77 int bits_per_sample_; | |
| 78 }; | |
| 79 | |
| 80 // Implements support for functions in the WebRTC audio stack for Android that | 27 // Implements support for functions in the WebRTC audio stack for Android that |
| 81 // relies on the AudioManager in android.media. It also populates an | 28 // relies on the AudioManager in android.media. It also populates an |
| 82 // AudioParameter structure with native audio parameters detected at | 29 // AudioParameter structure with native audio parameters detected at |
| 83 // construction. This class does not make any audio-related modifications | 30 // construction. This class does not make any audio-related modifications |
| 84 // unless Init() is called. Caching audio parameters makes no changes but only | 31 // unless Init() is called. Caching audio parameters makes no changes but only |
| 85 // reads data from the Java side. | 32 // reads data from the Java side. |
| 86 class AudioManager { | 33 class AudioManager { |
| 87 public: | 34 public: |
| 88 // Wraps the Java specific parts of the AudioManager into one helper class. | 35 // Wraps the Java specific parts of the AudioManager into one helper class. |
| 89 // Stores method IDs for all supported methods at construction and then | 36 // Stores method IDs for all supported methods at construction and then |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Contains native parameters (e.g. sample rate, channel configuration). | 148 // Contains native parameters (e.g. sample rate, channel configuration). |
| 202 // Set at construction in OnCacheAudioParameters() which is called from | 149 // Set at construction in OnCacheAudioParameters() which is called from |
| 203 // Java on the same thread as this object is created on. | 150 // Java on the same thread as this object is created on. |
| 204 AudioParameters playout_parameters_; | 151 AudioParameters playout_parameters_; |
| 205 AudioParameters record_parameters_; | 152 AudioParameters record_parameters_; |
| 206 }; | 153 }; |
| 207 | 154 |
| 208 } // namespace webrtc | 155 } // namespace webrtc |
| 209 | 156 |
| 210 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_H_ | 157 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_H_ |
| OLD | NEW |