LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/modules/audio_coding/acm2 - rent_a_codec.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 15 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) 2015 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_CODING_ACM2_RENT_A_CODEC_H_
      12             : #define WEBRTC_MODULES_AUDIO_CODING_ACM2_RENT_A_CODEC_H_
      13             : 
      14             : #include <stddef.h>
      15             : #include <map>
      16             : #include <memory>
      17             : 
      18             : #include "webrtc/base/array_view.h"
      19             : #include "webrtc/base/constructormagic.h"
      20             : #include "webrtc/base/optional.h"
      21             : #include "webrtc/base/scoped_ref_ptr.h"
      22             : #include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
      23             : #include "webrtc/modules/audio_coding/codecs/audio_format.h"
      24             : #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
      25             : #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
      26             : #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h"
      27             : #include "webrtc/typedefs.h"
      28             : 
      29             : namespace webrtc {
      30             : 
      31             : struct CodecInst;
      32             : class LockedIsacBandwidthInfo;
      33             : 
      34             : namespace acm2 {
      35             : 
      36           0 : class RentACodec {
      37             :  public:
      38             :   enum class CodecId {
      39             : #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)
      40             :     kISAC,
      41             : #endif
      42             : #ifdef WEBRTC_CODEC_ISAC
      43             :     kISACSWB,
      44             : #endif
      45             :     // Mono
      46             :     kPCM16B,
      47             :     kPCM16Bwb,
      48             :     kPCM16Bswb32kHz,
      49             :     // Stereo
      50             :     kPCM16B_2ch,
      51             :     kPCM16Bwb_2ch,
      52             :     kPCM16Bswb32kHz_2ch,
      53             :     // Mono
      54             :     kPCMU,
      55             :     kPCMA,
      56             :     // Stereo
      57             :     kPCMU_2ch,
      58             :     kPCMA_2ch,
      59             : #ifdef WEBRTC_CODEC_ILBC
      60             :     kILBC,
      61             : #endif
      62             : #ifdef WEBRTC_CODEC_G722
      63             :     kG722,      // Mono
      64             :     kG722_2ch,  // Stereo
      65             : #endif
      66             : #ifdef WEBRTC_CODEC_OPUS
      67             :     kOpus,  // Mono and stereo
      68             : #endif
      69             :     kCNNB,
      70             :     kCNWB,
      71             :     kCNSWB,
      72             : #ifdef ENABLE_48000_HZ
      73             :     kCNFB,
      74             : #endif
      75             :     kAVT,
      76             :     kAVT16kHz,
      77             :     kAVT32kHz,
      78             :     kAVT48kHz,
      79             : #ifdef WEBRTC_CODEC_RED
      80             :     kRED,
      81             : #endif
      82             :     kNumCodecs,  // Implementation detail. Don't use.
      83             : 
      84             : // Set unsupported codecs to -1.
      85             : #if !defined(WEBRTC_CODEC_ISAC) && !defined(WEBRTC_CODEC_ISACFX)
      86             :     kISAC = -1,
      87             : #endif
      88             : #ifndef WEBRTC_CODEC_ISAC
      89             :     kISACSWB = -1,
      90             : #endif
      91             :     // 48 kHz not supported, always set to -1.
      92             :     kPCM16Bswb48kHz = -1,
      93             : #ifndef WEBRTC_CODEC_ILBC
      94             :     kILBC = -1,
      95             : #endif
      96             : #ifndef WEBRTC_CODEC_G722
      97             :     kG722 = -1,      // Mono
      98             :     kG722_2ch = -1,  // Stereo
      99             : #endif
     100             : #ifndef WEBRTC_CODEC_OPUS
     101             :     kOpus = -1,  // Mono and stereo
     102             : #endif
     103             : #ifndef WEBRTC_CODEC_RED
     104             :     kRED = -1,
     105             : #endif
     106             : #ifndef ENABLE_48000_HZ
     107             :     kCNFB = -1,
     108             : #endif
     109             : 
     110             :     kNone = -1
     111             :   };
     112             : 
     113             :   enum class NetEqDecoder {
     114             :     kDecoderPCMu,
     115             :     kDecoderPCMa,
     116             :     kDecoderPCMu_2ch,
     117             :     kDecoderPCMa_2ch,
     118             :     kDecoderILBC,
     119             :     kDecoderISAC,
     120             :     kDecoderISACswb,
     121             :     kDecoderPCM16B,
     122             :     kDecoderPCM16Bwb,
     123             :     kDecoderPCM16Bswb32kHz,
     124             :     kDecoderPCM16Bswb48kHz,
     125             :     kDecoderPCM16B_2ch,
     126             :     kDecoderPCM16Bwb_2ch,
     127             :     kDecoderPCM16Bswb32kHz_2ch,
     128             :     kDecoderPCM16Bswb48kHz_2ch,
     129             :     kDecoderPCM16B_5ch,
     130             :     kDecoderG722,
     131             :     kDecoderG722_2ch,
     132             :     kDecoderRED,
     133             :     kDecoderAVT,
     134             :     kDecoderAVT16kHz,
     135             :     kDecoderAVT32kHz,
     136             :     kDecoderAVT48kHz,
     137             :     kDecoderCNGnb,
     138             :     kDecoderCNGwb,
     139             :     kDecoderCNGswb32kHz,
     140             :     kDecoderCNGswb48kHz,
     141             :     kDecoderArbitrary,
     142             :     kDecoderOpus,
     143             :     kDecoderOpus_2ch,
     144             :   };
     145             : 
     146             :   static rtc::Optional<SdpAudioFormat> NetEqDecoderToSdpAudioFormat(
     147             :       NetEqDecoder nd);
     148             : 
     149           0 :   static inline size_t NumberOfCodecs() {
     150           0 :     return static_cast<size_t>(CodecId::kNumCodecs);
     151             :   }
     152             : 
     153           0 :   static inline rtc::Optional<int> CodecIndexFromId(CodecId codec_id) {
     154           0 :     const int i = static_cast<int>(codec_id);
     155           0 :     return i >= 0 && i < static_cast<int>(NumberOfCodecs())
     156           0 :                ? rtc::Optional<int>(i)
     157           0 :                : rtc::Optional<int>();
     158             :   }
     159             : 
     160           0 :   static inline rtc::Optional<CodecId> CodecIdFromIndex(int codec_index) {
     161           0 :     return static_cast<size_t>(codec_index) < NumberOfCodecs()
     162             :                ? rtc::Optional<RentACodec::CodecId>(
     163           0 :                      static_cast<RentACodec::CodecId>(codec_index))
     164           0 :                : rtc::Optional<RentACodec::CodecId>();
     165             :   }
     166             : 
     167             :   static rtc::Optional<CodecId> CodecIdByParams(const char* payload_name,
     168             :                                                 int sampling_freq_hz,
     169             :                                                 size_t channels);
     170             :   static rtc::Optional<CodecInst> CodecInstById(CodecId codec_id);
     171             :   static rtc::Optional<CodecId> CodecIdByInst(const CodecInst& codec_inst);
     172             :   static rtc::Optional<CodecInst> CodecInstByParams(const char* payload_name,
     173             :                                                     int sampling_freq_hz,
     174             :                                                     size_t channels);
     175             :   static bool IsCodecValid(const CodecInst& codec_inst);
     176             : 
     177           0 :   static inline bool IsPayloadTypeValid(int payload_type) {
     178           0 :     return payload_type >= 0 && payload_type <= 127;
     179             :   }
     180             : 
     181             :   static rtc::ArrayView<const CodecInst> Database();
     182             : 
     183             :   static rtc::Optional<bool> IsSupportedNumChannels(CodecId codec_id,
     184             :                                                     size_t num_channels);
     185             : 
     186             :   static rtc::Optional<NetEqDecoder> NetEqDecoderFromCodecId(
     187             :       CodecId codec_id,
     188             :       size_t num_channels);
     189             : 
     190             :   // Parse codec_inst and extract payload types. If the given CodecInst was for
     191             :   // the wrong sort of codec, return kSkip; otherwise, if the rate was illegal,
     192             :   // return kBadFreq; otherwise, update the given RTP timestamp rate (Hz) ->
     193             :   // payload type map and return kOk.
     194             :   enum class RegistrationResult { kOk, kSkip, kBadFreq };
     195             :   static RegistrationResult RegisterCngPayloadType(std::map<int, int>* pt_map,
     196             :                                                    const CodecInst& codec_inst);
     197             :   static RegistrationResult RegisterRedPayloadType(std::map<int, int>* pt_map,
     198             :                                                    const CodecInst& codec_inst);
     199             : 
     200             :   RentACodec();
     201             :   ~RentACodec();
     202             : 
     203             :   // Creates and returns an audio encoder built to the given specification.
     204             :   // Returns null in case of error.
     205             :   std::unique_ptr<AudioEncoder> RentEncoder(const CodecInst& codec_inst);
     206             : 
     207           0 :   struct StackParameters {
     208             :     StackParameters();
     209             :     ~StackParameters();
     210             : 
     211             :     std::unique_ptr<AudioEncoder> speech_encoder;
     212             : 
     213             :     bool use_codec_fec = false;
     214             :     bool use_red = false;
     215             :     bool use_cng = false;
     216             :     ACMVADMode vad_mode = VADNormal;
     217             : 
     218             :     // Maps from RTP timestamp rate (in Hz) to payload type.
     219             :     std::map<int, int> cng_payload_types;
     220             :     std::map<int, int> red_payload_types;
     221             :   };
     222             : 
     223             :   // Creates and returns an audio encoder stack constructed to the given
     224             :   // specification. If the specification isn't compatible with the encoder, it
     225             :   // will be changed to match (things will be switched off). The speech encoder
     226             :   // will be stolen. If the specification isn't complete, returns nullptr.
     227             :   std::unique_ptr<AudioEncoder> RentEncoderStack(StackParameters* param);
     228             : 
     229             :   // Creates and returns an iSAC decoder.
     230             :   std::unique_ptr<AudioDecoder> RentIsacDecoder(int sample_rate_hz);
     231             : 
     232             :  private:
     233             :   std::unique_ptr<AudioEncoder> speech_encoder_;
     234             :   std::unique_ptr<AudioEncoder> cng_encoder_;
     235             :   std::unique_ptr<AudioEncoder> red_encoder_;
     236             :   rtc::scoped_refptr<LockedIsacBandwidthInfo> isac_bandwidth_info_;
     237             : 
     238             :   RTC_DISALLOW_COPY_AND_ASSIGN(RentACodec);
     239             : };
     240             : 
     241             : }  // namespace acm2
     242             : }  // namespace webrtc
     243             : 
     244             : #endif  // WEBRTC_MODULES_AUDIO_CODING_ACM2_RENT_A_CODEC_H_

Generated by: LCOV version 1.13