Home | History | Annotate | Download | only in include
      1 /*
      2  *  Copyright (c) 2011 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_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H
     12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H
     13 
     14 #include "webrtc/typedefs.h"
     15 
     16 namespace webrtc {
     17 
     18 static const int kAdmMaxDeviceNameSize = 128;
     19 static const int kAdmMaxFileNameSize = 512;
     20 static const int kAdmMaxGuidSize = 128;
     21 
     22 static const int kAdmMinPlayoutBufferSizeMs = 10;
     23 static const int kAdmMaxPlayoutBufferSizeMs = 250;
     24 
     25 // ----------------------------------------------------------------------------
     26 //  AudioDeviceObserver
     27 // ----------------------------------------------------------------------------
     28 
     29 class AudioDeviceObserver
     30 {
     31 public:
     32     enum ErrorCode
     33     {
     34         kRecordingError = 0,
     35         kPlayoutError = 1
     36     };
     37     enum WarningCode
     38     {
     39         kRecordingWarning = 0,
     40         kPlayoutWarning = 1
     41     };
     42 
     43     virtual void OnErrorIsReported(const ErrorCode error) = 0;
     44     virtual void OnWarningIsReported(const WarningCode warning) = 0;
     45 
     46 protected:
     47     virtual ~AudioDeviceObserver() {}
     48 };
     49 
     50 // ----------------------------------------------------------------------------
     51 //  AudioTransport
     52 // ----------------------------------------------------------------------------
     53 
     54 class AudioTransport
     55 {
     56 public:
     57     virtual int32_t RecordedDataIsAvailable(const void* audioSamples,
     58                                             const uint32_t nSamples,
     59                                             const uint8_t nBytesPerSample,
     60                                             const uint8_t nChannels,
     61                                             const uint32_t samplesPerSec,
     62                                             const uint32_t totalDelayMS,
     63                                             const int32_t clockDrift,
     64                                             const uint32_t currentMicLevel,
     65                                             const bool keyPressed,
     66                                             uint32_t& newMicLevel) = 0;
     67 
     68     virtual int32_t NeedMorePlayData(const uint32_t nSamples,
     69                                      const uint8_t nBytesPerSample,
     70                                      const uint8_t nChannels,
     71                                      const uint32_t samplesPerSec,
     72                                      void* audioSamples,
     73                                      uint32_t& nSamplesOut,
     74                                      int64_t* elapsed_time_ms,
     75                                      int64_t* ntp_time_ms) = 0;
     76 
     77     // Method to pass captured data directly and unmixed to network channels.
     78     // |channel_ids| contains a list of VoE channels which are the
     79     // sinks to the capture data. |audio_delay_milliseconds| is the sum of
     80     // recording delay and playout delay of the hardware. |current_volume| is
     81     // in the range of [0, 255], representing the current microphone analog
     82     // volume. |key_pressed| is used by the typing detection.
     83     // |need_audio_processing| specify if the data needs to be processed by APM.
     84     // Currently WebRtc supports only one APM, and Chrome will make sure only
     85     // one stream goes through APM. When |need_audio_processing| is false, the
     86     // values of |audio_delay_milliseconds|, |current_volume| and |key_pressed|
     87     // will be ignored.
     88     // The return value is the new microphone volume, in the range of |0, 255].
     89     // When the volume does not need to be updated, it returns 0.
     90     // TODO(xians): Remove this interface after Chrome and Libjingle switches
     91     // to OnData().
     92     virtual int OnDataAvailable(const int voe_channels[],
     93                                 int number_of_voe_channels,
     94                                 const int16_t* audio_data,
     95                                 int sample_rate,
     96                                 int number_of_channels,
     97                                 int number_of_frames,
     98                                 int audio_delay_milliseconds,
     99                                 int current_volume,
    100                                 bool key_pressed,
    101                                 bool need_audio_processing) { return 0; }
    102 
    103     // Method to pass the captured audio data to the specific VoE channel.
    104     // |voe_channel| is the id of the VoE channel which is the sink to the
    105     // capture data.
    106     // TODO(xians): Remove this interface after Libjingle switches to
    107     // PushCaptureData().
    108     virtual void OnData(int voe_channel, const void* audio_data,
    109                         int bits_per_sample, int sample_rate,
    110                         int number_of_channels,
    111                         int number_of_frames) {}
    112 
    113     // Method to push the captured audio data to the specific VoE channel.
    114     // The data will not undergo audio processing.
    115     // |voe_channel| is the id of the VoE channel which is the sink to the
    116     // capture data.
    117     // TODO(xians): Make the interface pure virtual after Libjingle
    118     // has its implementation.
    119     virtual void PushCaptureData(int voe_channel, const void* audio_data,
    120                                  int bits_per_sample, int sample_rate,
    121                                  int number_of_channels,
    122                                  int number_of_frames) {}
    123 
    124     // Method to pull mixed render audio data from all active VoE channels.
    125     // The data will not be passed as reference for audio processing internally.
    126     // TODO(xians): Support getting the unmixed render data from specific VoE
    127     // channel.
    128     virtual void PullRenderData(int bits_per_sample, int sample_rate,
    129                                 int number_of_channels, int number_of_frames,
    130                                 void* audio_data,
    131                                 int64_t* elapsed_time_ms,
    132                                 int64_t* ntp_time_ms) {}
    133 
    134 protected:
    135     virtual ~AudioTransport() {}
    136 };
    137 
    138 }  // namespace webrtc
    139 
    140 #endif  // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H
    141