niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 270e9db | 2012-05-09 19:09:03 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | // This sub-API supports the following functionalities: |
| 12 | // |
| 13 | // - Support of non-default codecs (e.g. iLBC, iSAC, etc.). |
| 14 | // - Voice Activity Detection (VAD) on a per channel basis. |
| 15 | // - Possibility to specify how to map received payload types to codecs. |
| 16 | // |
| 17 | // Usage example, omitting error checking: |
| 18 | // |
| 19 | // using namespace webrtc; |
| 20 | // VoiceEngine* voe = VoiceEngine::Create(); |
| 21 | // VoEBase* base = VoEBase::GetInterface(voe); |
ajm@google.com | 2098988 | 2011-07-25 15:31:13 +0000 | [diff] [blame] | 22 | // VoECodec* codec = VoECodec::GetInterface(voe); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | // base->Init(); |
| 24 | // int num_of_codecs = codec->NumOfCodecs() |
| 25 | // ... |
| 26 | // base->Terminate(); |
| 27 | // base->Release(); |
| 28 | // codec->Release(); |
| 29 | // VoiceEngine::Delete(voe); |
| 30 | // |
| 31 | #ifndef WEBRTC_VOICE_ENGINE_VOE_CODEC_H |
| 32 | #define WEBRTC_VOICE_ENGINE_VOE_CODEC_H |
| 33 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 34 | #include "webrtc/common_types.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
| 36 | namespace webrtc { |
| 37 | |
| 38 | class VoiceEngine; |
| 39 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 40 | class WEBRTC_DLLEXPORT VoECodec { |
| 41 | public: |
| 42 | // Factory for the VoECodec sub-API. Increases an internal |
| 43 | // reference counter if successful. Returns NULL if the API is not |
| 44 | // supported or if construction fails. |
| 45 | static VoECodec* GetInterface(VoiceEngine* voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 47 | // Releases the VoECodec sub-API and decreases an internal |
| 48 | // reference counter. Returns the new reference count. This value should |
| 49 | // be zero for all sub-API:s before the VoiceEngine object can be safely |
| 50 | // deleted. |
| 51 | virtual int Release() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 53 | // Gets the number of supported codecs. |
| 54 | virtual int NumOfCodecs() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 56 | // Get the |codec| information for a specified list |index|. |
| 57 | virtual int GetCodec(int index, CodecInst& codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 59 | // Sets the |codec| for the |channel| to be used for sending. |
| 60 | virtual int SetSendCodec(int channel, const CodecInst& codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 62 | // Gets the |codec| parameters for the sending codec on a specified |
| 63 | // |channel|. |
| 64 | virtual int GetSendCodec(int channel, CodecInst& codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 66 | // Sets the bitrate on a specified |channel| to the specified value |
| 67 | // (in bits/sec). If the value is not supported by the codec, the codec will |
| 68 | // choose an appropriate value. |
| 69 | // Returns -1 on failure and 0 on success. |
| 70 | virtual int SetBitRate(int channel, int bitrate_bps) = 0; |
Ivo Creusen | adf89b7 | 2015-04-29 16:03:33 +0200 | [diff] [blame] | 71 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 72 | // Gets the currently received |codec| for a specific |channel|. |
| 73 | virtual int GetRecCodec(int channel, CodecInst& codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 75 | // Sets the dynamic payload type number for a particular |codec| or |
| 76 | // disables (ignores) a codec for receiving. For instance, when receiving |
| 77 | // an invite from a SIP-based client, this function can be used to change |
| 78 | // the dynamic payload type number to match that in the INVITE SDP- |
| 79 | // message. The utilized parameters in the |codec| structure are: |
| 80 | // plname, plfreq, pltype and channels. |
| 81 | virtual int SetRecPayloadType(int channel, const CodecInst& codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 83 | // Gets the actual payload type that is set for receiving a |codec| on a |
| 84 | // |channel|. The value it retrieves will either be the default payload |
| 85 | // type, or a value earlier set with SetRecPayloadType(). |
| 86 | virtual int GetRecPayloadType(int channel, CodecInst& codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 88 | // Sets the payload |type| for the sending of SID-frames with background |
| 89 | // noise estimation during silence periods detected by the VAD. |
| 90 | virtual int SetSendCNPayloadType( |
| 91 | int channel, |
| 92 | int type, |
| 93 | PayloadFrequencies frequency = kFreq16000Hz) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 95 | // Sets the codec internal FEC (forward error correction) status for a |
| 96 | // specified |channel|. Returns 0 if success, and -1 if failed. |
| 97 | // TODO(minyue): Make SetFECStatus() pure virtual when fakewebrtcvoiceengine |
| 98 | // in talk is ready. |
| 99 | virtual int SetFECStatus(int channel, bool enable) { return -1; } |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 100 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 101 | // Gets the codec internal FEC status for a specified |channel|. Returns 0 |
| 102 | // with the status stored in |enabled| if success, and -1 if encountered |
| 103 | // error. |
| 104 | // TODO(minyue): Make GetFECStatus() pure virtual when fakewebrtcvoiceengine |
| 105 | // in talk is ready. |
| 106 | virtual int GetFECStatus(int channel, bool& enabled) { return -1; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 108 | // Sets the VAD/DTX (silence suppression) status and |mode| for a |
| 109 | // specified |channel|. Disabling VAD (through |enable|) will also disable |
| 110 | // DTX; it is not necessary to explictly set |disableDTX| in this case. |
| 111 | virtual int SetVADStatus(int channel, |
| 112 | bool enable, |
| 113 | VadModes mode = kVadConventional, |
| 114 | bool disableDTX = false) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 116 | // Gets the VAD/DTX status and |mode| for a specified |channel|. |
| 117 | virtual int GetVADStatus(int channel, |
| 118 | bool& enabled, |
| 119 | VadModes& mode, |
| 120 | bool& disabledDTX) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 122 | // If send codec is Opus on a specified |channel|, sets the maximum playback |
| 123 | // rate the receiver will render: |frequency_hz| (in Hz). |
| 124 | // TODO(minyue): Make SetOpusMaxPlaybackRate() pure virtual when |
| 125 | // fakewebrtcvoiceengine in talk is ready. |
| 126 | virtual int SetOpusMaxPlaybackRate(int channel, int frequency_hz) { |
| 127 | return -1; |
| 128 | } |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 129 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 130 | // If send codec is Opus on a specified |channel|, set its DTX. Returns 0 if |
| 131 | // success, and -1 if failed. |
| 132 | virtual int SetOpusDtx(int channel, bool enable_dtx) = 0; |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 133 | |
ivoc | 85228d6 | 2016-07-27 04:53:47 -0700 | [diff] [blame] | 134 | // If send codec is Opus on a specified |channel|, return its DTX status. |
| 135 | // Returns 0 on success, and -1 if failed. |
| 136 | // TODO(ivoc): Make GetOpusDtxStatus() pure virtual when all deriving classes |
| 137 | // are updated. |
| 138 | virtual int GetOpusDtxStatus(int channel, bool* enabled) { return -1; } |
| 139 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 140 | protected: |
| 141 | VoECodec() {} |
| 142 | virtual ~VoECodec() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 145 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
| 147 | #endif // WEBRTC_VOICE_ENGINE_VOE_CODEC_H |