Home | History | Annotate | Download | only in android
      1 /*
      2  *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
      3  *
      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
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
     12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
     13 
     14 #include "webrtc/modules/audio_device/audio_device_generic.h"
     15 
     16 #include "webrtc/system_wrappers/interface/trace.h"
     17 
     18 namespace webrtc {
     19 
     20 // InputType/OutputType can be any class that implements the capturing/rendering
     21 // part of the AudioDeviceGeneric API.
     22 template <class InputType, class OutputType>
     23 class AudioDeviceTemplate : public AudioDeviceGeneric {
     24  public:
     25   static int32_t SetAndroidAudioDeviceObjects(void* javaVM,
     26                                        void* env,
     27                                        void* context) {
     28     if (OutputType::SetAndroidAudioDeviceObjects(javaVM, env, context) == -1) {
     29       return -1;
     30     }
     31     return InputType::SetAndroidAudioDeviceObjects(javaVM, env, context);
     32   }
     33 
     34   static void ClearAndroidAudioDeviceObjects() {
     35     OutputType::ClearAndroidAudioDeviceObjects();
     36     InputType::ClearAndroidAudioDeviceObjects();
     37   }
     38 
     39   explicit AudioDeviceTemplate(const int32_t id)
     40       : output_(id),
     41         input_(id, &output_) {
     42   }
     43 
     44   virtual ~AudioDeviceTemplate() {
     45   }
     46 
     47   int32_t ActiveAudioLayer(
     48       AudioDeviceModule::AudioLayer& audioLayer) const { // NOLINT
     49     audioLayer = AudioDeviceModule::kPlatformDefaultAudio;
     50     return 0;
     51   }
     52 
     53   int32_t Init() {
     54     return output_.Init() | input_.Init();
     55   }
     56 
     57   int32_t Terminate()  {
     58     return output_.Terminate() | input_.Terminate();
     59   }
     60 
     61   bool Initialized() const {
     62     return output_.Initialized() && input_.Initialized();
     63   }
     64 
     65   int16_t PlayoutDevices() {
     66     return output_.PlayoutDevices();
     67   }
     68 
     69   int16_t RecordingDevices() {
     70     return input_.RecordingDevices();
     71   }
     72 
     73   int32_t PlayoutDeviceName(
     74       uint16_t index,
     75       char name[kAdmMaxDeviceNameSize],
     76       char guid[kAdmMaxGuidSize]) {
     77     return output_.PlayoutDeviceName(index, name, guid);
     78   }
     79 
     80   int32_t RecordingDeviceName(
     81       uint16_t index,
     82       char name[kAdmMaxDeviceNameSize],
     83       char guid[kAdmMaxGuidSize]) {
     84     return input_.RecordingDeviceName(index, name, guid);
     85   }
     86 
     87   int32_t SetPlayoutDevice(uint16_t index) {
     88     return output_.SetPlayoutDevice(index);
     89   }
     90 
     91   int32_t SetPlayoutDevice(
     92       AudioDeviceModule::WindowsDeviceType device) {
     93     return output_.SetPlayoutDevice(device);
     94   }
     95 
     96   int32_t SetRecordingDevice(uint16_t index) {
     97     return input_.SetRecordingDevice(index);
     98   }
     99 
    100   int32_t SetRecordingDevice(
    101       AudioDeviceModule::WindowsDeviceType device) {
    102     return input_.SetRecordingDevice(device);
    103   }
    104 
    105   int32_t PlayoutIsAvailable(
    106       bool& available) {  // NOLINT
    107     return output_.PlayoutIsAvailable(available);
    108   }
    109 
    110   int32_t InitPlayout() {
    111     return output_.InitPlayout();
    112   }
    113 
    114   bool PlayoutIsInitialized() const {
    115     return output_.PlayoutIsInitialized();
    116   }
    117 
    118   int32_t RecordingIsAvailable(
    119       bool& available) {  // NOLINT
    120     return input_.RecordingIsAvailable(available);
    121   }
    122 
    123   int32_t InitRecording() {
    124     return input_.InitRecording();
    125   }
    126 
    127   bool RecordingIsInitialized() const {
    128     return input_.RecordingIsInitialized();
    129   }
    130 
    131   int32_t StartPlayout() {
    132     return output_.StartPlayout();
    133   }
    134 
    135   int32_t StopPlayout() {
    136     return output_.StopPlayout();
    137   }
    138 
    139   bool Playing() const {
    140     return output_.Playing();
    141   }
    142 
    143   int32_t StartRecording() {
    144     return input_.StartRecording();
    145   }
    146 
    147   int32_t StopRecording() {
    148     return input_.StopRecording();
    149   }
    150 
    151   bool Recording() const {
    152     return input_.Recording() ;
    153   }
    154 
    155   int32_t SetAGC(bool enable) {
    156     return input_.SetAGC(enable);
    157   }
    158 
    159   bool AGC() const {
    160     return input_.AGC();
    161   }
    162 
    163   int32_t SetWaveOutVolume(uint16_t volumeLeft,
    164                            uint16_t volumeRight) {
    165     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, 0,
    166                  "  API call not supported on this platform");
    167     return -1;
    168   }
    169 
    170   int32_t WaveOutVolume(
    171       uint16_t& volumeLeft,           // NOLINT
    172       uint16_t& volumeRight) const {  // NOLINT
    173     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, 0,
    174                  "  API call not supported on this platform");
    175     return -1;
    176   }
    177 
    178   int32_t InitSpeaker() {
    179     return output_.InitSpeaker();
    180   }
    181 
    182   bool SpeakerIsInitialized() const {
    183     return output_.SpeakerIsInitialized();
    184   }
    185 
    186   int32_t InitMicrophone() {
    187     return input_.InitMicrophone();
    188   }
    189 
    190   bool MicrophoneIsInitialized() const {
    191     return input_.MicrophoneIsInitialized();
    192   }
    193 
    194   int32_t SpeakerVolumeIsAvailable(
    195       bool& available) {  // NOLINT
    196     return output_.SpeakerVolumeIsAvailable(available);
    197   }
    198 
    199   int32_t SetSpeakerVolume(uint32_t volume) {
    200     return output_.SetSpeakerVolume(volume);
    201   }
    202 
    203   int32_t SpeakerVolume(
    204       uint32_t& volume) const {  // NOLINT
    205     return output_.SpeakerVolume(volume);
    206   }
    207 
    208   int32_t MaxSpeakerVolume(
    209       uint32_t& maxVolume) const {  // NOLINT
    210     return output_.MaxSpeakerVolume(maxVolume);
    211   }
    212 
    213   int32_t MinSpeakerVolume(
    214       uint32_t& minVolume) const {  // NOLINT
    215     return output_.MinSpeakerVolume(minVolume);
    216   }
    217 
    218   int32_t SpeakerVolumeStepSize(
    219       uint16_t& stepSize) const {  // NOLINT
    220     return output_.SpeakerVolumeStepSize(stepSize);
    221   }
    222 
    223   int32_t MicrophoneVolumeIsAvailable(
    224       bool& available) {  // NOLINT
    225     return input_.MicrophoneVolumeIsAvailable(available);
    226   }
    227 
    228   int32_t SetMicrophoneVolume(uint32_t volume) {
    229     return input_.SetMicrophoneVolume(volume);
    230   }
    231 
    232   int32_t MicrophoneVolume(
    233       uint32_t& volume) const {  // NOLINT
    234     return input_.MicrophoneVolume(volume);
    235   }
    236 
    237   int32_t MaxMicrophoneVolume(
    238       uint32_t& maxVolume) const {  // NOLINT
    239     return input_.MaxMicrophoneVolume(maxVolume);
    240   }
    241 
    242   int32_t MinMicrophoneVolume(
    243       uint32_t& minVolume) const {  // NOLINT
    244     return input_.MinMicrophoneVolume(minVolume);
    245   }
    246 
    247   int32_t MicrophoneVolumeStepSize(
    248       uint16_t& stepSize) const {  // NOLINT
    249     return input_.MicrophoneVolumeStepSize(stepSize);
    250   }
    251 
    252   int32_t SpeakerMuteIsAvailable(
    253       bool& available) {  // NOLINT
    254     return output_.SpeakerMuteIsAvailable(available);
    255   }
    256 
    257   int32_t SetSpeakerMute(bool enable) {
    258     return output_.SetSpeakerMute(enable);
    259   }
    260 
    261   int32_t SpeakerMute(
    262       bool& enabled) const {  // NOLINT
    263     return output_.SpeakerMute(enabled);
    264   }
    265 
    266   int32_t MicrophoneMuteIsAvailable(
    267       bool& available) {  // NOLINT
    268     return input_.MicrophoneMuteIsAvailable(available);
    269   }
    270 
    271   int32_t SetMicrophoneMute(bool enable) {
    272     return input_.SetMicrophoneMute(enable);
    273   }
    274 
    275   int32_t MicrophoneMute(
    276       bool& enabled) const {  // NOLINT
    277     return input_.MicrophoneMute(enabled);
    278   }
    279 
    280   int32_t MicrophoneBoostIsAvailable(
    281       bool& available) {  // NOLINT
    282     return input_.MicrophoneBoostIsAvailable(available);
    283   }
    284 
    285   int32_t SetMicrophoneBoost(bool enable) {
    286     return input_.SetMicrophoneBoost(enable);
    287   }
    288 
    289   int32_t MicrophoneBoost(
    290       bool& enabled) const {  // NOLINT
    291     return input_.MicrophoneBoost(enabled);
    292   }
    293 
    294   int32_t StereoPlayoutIsAvailable(
    295       bool& available) {  // NOLINT
    296     return output_.StereoPlayoutIsAvailable(available);
    297   }
    298 
    299   int32_t SetStereoPlayout(bool enable) {
    300     return output_.SetStereoPlayout(enable);
    301   }
    302 
    303   int32_t StereoPlayout(
    304       bool& enabled) const {  // NOLINT
    305     return output_.StereoPlayout(enabled);
    306   }
    307 
    308   int32_t StereoRecordingIsAvailable(
    309       bool& available) {  // NOLINT
    310     return input_.StereoRecordingIsAvailable(available);
    311   }
    312 
    313   int32_t SetStereoRecording(bool enable) {
    314     return input_.SetStereoRecording(enable);
    315   }
    316 
    317   int32_t StereoRecording(
    318       bool& enabled) const {  // NOLINT
    319     return input_.StereoRecording(enabled);
    320   }
    321 
    322   int32_t SetPlayoutBuffer(
    323       const AudioDeviceModule::BufferType type,
    324       uint16_t sizeMS) {
    325     return output_.SetPlayoutBuffer(type, sizeMS);
    326   }
    327 
    328   int32_t PlayoutBuffer(
    329       AudioDeviceModule::BufferType& type,
    330       uint16_t& sizeMS) const {  // NOLINT
    331     return output_.PlayoutBuffer(type, sizeMS);
    332   }
    333 
    334   int32_t PlayoutDelay(
    335       uint16_t& delayMS) const {  // NOLINT
    336     return output_.PlayoutDelay(delayMS);
    337   }
    338 
    339   int32_t RecordingDelay(
    340       uint16_t& delayMS) const {  // NOLINT
    341     return input_.RecordingDelay(delayMS);
    342   }
    343 
    344   int32_t CPULoad(
    345       uint16_t& load) const {  // NOLINT
    346     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, 0,
    347                  "  API call not supported on this platform");
    348     return -1;
    349   }
    350 
    351   bool PlayoutWarning() const {
    352     return output_.PlayoutWarning();
    353   }
    354 
    355   bool PlayoutError() const {
    356     return output_.PlayoutError();
    357   }
    358 
    359   bool RecordingWarning() const {
    360     return input_.RecordingWarning();
    361   }
    362 
    363   bool RecordingError() const {
    364     return input_.RecordingError();
    365   }
    366 
    367   void ClearPlayoutWarning() {
    368     return output_.ClearPlayoutWarning();
    369   }
    370 
    371   void ClearPlayoutError() {
    372     return output_.ClearPlayoutError();
    373   }
    374 
    375   void ClearRecordingWarning() {
    376     return input_.ClearRecordingWarning();
    377   }
    378 
    379   void ClearRecordingError() {
    380     return input_.ClearRecordingError();
    381   }
    382 
    383   void AttachAudioBuffer(
    384       AudioDeviceBuffer* audioBuffer) {
    385     output_.AttachAudioBuffer(audioBuffer);
    386     input_.AttachAudioBuffer(audioBuffer);
    387   }
    388 
    389   int32_t SetRecordingSampleRate(
    390       const uint32_t samplesPerSec) {
    391     return input_.SetRecordingSampleRate(samplesPerSec);
    392   }
    393 
    394   int32_t SetPlayoutSampleRate(
    395       const uint32_t samplesPerSec) {
    396     return output_.SetPlayoutSampleRate(samplesPerSec);
    397   }
    398 
    399   int32_t SetLoudspeakerStatus(bool enable) {
    400     return output_.SetLoudspeakerStatus(enable);
    401   }
    402 
    403   int32_t GetLoudspeakerStatus(
    404       bool& enable) const {  // NOLINT
    405     return output_.GetLoudspeakerStatus(enable);
    406   }
    407 
    408  private:
    409   OutputType output_;
    410   InputType input_;
    411 };
    412 
    413 }  // namespace webrtc
    414 
    415 #endif  // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
    416