LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/modules/audio_device/include - audio_device_defines.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 4 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFINES_H_
      12             : #define WEBRTC_MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFINES_H_
      13             : 
      14             : #include <stddef.h>
      15             : 
      16             : #include "webrtc/typedefs.h"
      17             : 
      18             : namespace webrtc {
      19             : 
      20             : static const int kAdmMaxDeviceNameSize = 128;
      21             : static const int kAdmMaxFileNameSize = 512;
      22             : static const int kAdmMaxGuidSize = 128;
      23             : 
      24             : static const int kAdmMinPlayoutBufferSizeMs = 10;
      25             : static const int kAdmMaxPlayoutBufferSizeMs = 250;
      26             : 
      27             : // ----------------------------------------------------------------------------
      28             : //  AudioDeviceObserver
      29             : // ----------------------------------------------------------------------------
      30             : 
      31           0 : class AudioDeviceObserver {
      32             :  public:
      33             :   enum ErrorCode { kRecordingError = 0, kPlayoutError = 1 };
      34             :   enum WarningCode { kRecordingWarning = 0, kPlayoutWarning = 1 };
      35             : 
      36             :   virtual void OnErrorIsReported(const ErrorCode error) = 0;
      37             :   virtual void OnWarningIsReported(const WarningCode warning) = 0;
      38             : 
      39             :  protected:
      40           0 :   virtual ~AudioDeviceObserver() {}
      41             : };
      42             : 
      43             : // ----------------------------------------------------------------------------
      44             : //  AudioTransport
      45             : // ----------------------------------------------------------------------------
      46             : 
      47           0 : class AudioTransport {
      48             :  public:
      49             :   virtual int32_t RecordedDataIsAvailable(const void* audioSamples,
      50             :                                           const size_t nSamples,
      51             :                                           const size_t nBytesPerSample,
      52             :                                           const size_t nChannels,
      53             :                                           const uint32_t samplesPerSec,
      54             :                                           const uint32_t totalDelayMS,
      55             :                                           const int32_t clockDrift,
      56             :                                           const uint32_t currentMicLevel,
      57             :                                           const bool keyPressed,
      58             :                                           uint32_t& newMicLevel) = 0;
      59             : 
      60             :   virtual int32_t NeedMorePlayData(const size_t nSamples,
      61             :                                    const size_t nBytesPerSample,
      62             :                                    const size_t nChannels,
      63             :                                    const uint32_t samplesPerSec,
      64             :                                    void* audioSamples,
      65             :                                    size_t& nSamplesOut,
      66             :                                    int64_t* elapsed_time_ms,
      67             :                                    int64_t* ntp_time_ms) = 0;
      68             : 
      69             :   // Method to push the captured audio data to the specific VoE channel.
      70             :   // The data will not undergo audio processing.
      71             :   // |voe_channel| is the id of the VoE channel which is the sink to the
      72             :   // capture data.
      73             :   virtual void PushCaptureData(int voe_channel,
      74             :                                const void* audio_data,
      75             :                                int bits_per_sample,
      76             :                                int sample_rate,
      77             :                                size_t number_of_channels,
      78             :                                size_t number_of_frames) = 0;
      79             : 
      80             :   // Method to pull mixed render audio data from all active VoE channels.
      81             :   // The data will not be passed as reference for audio processing internally.
      82             :   // TODO(xians): Support getting the unmixed render data from specific VoE
      83             :   // channel.
      84             :   virtual void PullRenderData(int bits_per_sample,
      85             :                               int sample_rate,
      86             :                               size_t number_of_channels,
      87             :                               size_t number_of_frames,
      88             :                               void* audio_data,
      89             :                               int64_t* elapsed_time_ms,
      90             :                               int64_t* ntp_time_ms) = 0;
      91             : 
      92             :  protected:
      93           0 :   virtual ~AudioTransport() {}
      94             : };
      95             : 
      96             : // Helper class for storage of fundamental audio parameters such as sample rate,
      97             : // number of channels, native buffer size etc.
      98             : // Note that one audio frame can contain more than one channel sample and each
      99             : // sample is assumed to be a 16-bit PCM sample. Hence, one audio frame in
     100             : // stereo contains 2 * (16/8) = 4 bytes of data.
     101             : class AudioParameters {
     102             :  public:
     103             :   // This implementation does only support 16-bit PCM samples.
     104             :   static const size_t kBitsPerSample = 16;
     105             :   AudioParameters()
     106             :       : sample_rate_(0),
     107             :         channels_(0),
     108             :         frames_per_buffer_(0),
     109             :         frames_per_10ms_buffer_(0) {}
     110             :   AudioParameters(int sample_rate, size_t channels, size_t frames_per_buffer)
     111             :       : sample_rate_(sample_rate),
     112             :         channels_(channels),
     113             :         frames_per_buffer_(frames_per_buffer),
     114             :         frames_per_10ms_buffer_(static_cast<size_t>(sample_rate / 100)) {}
     115             :   void reset(int sample_rate, size_t channels, size_t frames_per_buffer) {
     116             :     sample_rate_ = sample_rate;
     117             :     channels_ = channels;
     118             :     frames_per_buffer_ = frames_per_buffer;
     119             :     frames_per_10ms_buffer_ = static_cast<size_t>(sample_rate / 100);
     120             :   }
     121             :   size_t bits_per_sample() const { return kBitsPerSample; }
     122             :   void reset(int sample_rate, size_t channels, double ms_per_buffer) {
     123             :     reset(sample_rate, channels,
     124             :           static_cast<size_t>(sample_rate * ms_per_buffer + 0.5));
     125             :   }
     126             :   void reset(int sample_rate, size_t channels) {
     127             :     reset(sample_rate, channels, static_cast<size_t>(0));
     128             :   }
     129             :   int sample_rate() const { return sample_rate_; }
     130             :   size_t channels() const { return channels_; }
     131             :   size_t frames_per_buffer() const { return frames_per_buffer_; }
     132             :   size_t frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; }
     133             :   size_t GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; }
     134             :   size_t GetBytesPerBuffer() const {
     135             :     return frames_per_buffer_ * GetBytesPerFrame();
     136             :   }
     137             :   // The WebRTC audio device buffer (ADB) only requires that the sample rate
     138             :   // and number of channels are configured. Hence, to be "valid", only these
     139             :   // two attributes must be set.
     140             :   bool is_valid() const { return ((sample_rate_ > 0) && (channels_ > 0)); }
     141             :   // Most platforms also require that a native buffer size is defined.
     142             :   // An audio parameter instance is considered to be "complete" if it is both
     143             :   // "valid" (can be used by the ADB) and also has a native frame size.
     144             :   bool is_complete() const { return (is_valid() && (frames_per_buffer_ > 0)); }
     145             :   size_t GetBytesPer10msBuffer() const {
     146             :     return frames_per_10ms_buffer_ * GetBytesPerFrame();
     147             :   }
     148             :   double GetBufferSizeInMilliseconds() const {
     149             :     if (sample_rate_ == 0)
     150             :       return 0.0;
     151             :     return frames_per_buffer_ / (sample_rate_ / 1000.0);
     152             :   }
     153             :   double GetBufferSizeInSeconds() const {
     154             :     if (sample_rate_ == 0)
     155             :       return 0.0;
     156             :     return static_cast<double>(frames_per_buffer_) / (sample_rate_);
     157             :   }
     158             : 
     159             :  private:
     160             :   int sample_rate_;
     161             :   size_t channels_;
     162             :   size_t frames_per_buffer_;
     163             :   size_t frames_per_10ms_buffer_;
     164             : };
     165             : 
     166             : }  // namespace webrtc
     167             : 
     168             : #endif  // WEBRTC_MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFINES_H_

Generated by: LCOV version 1.13