1470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* 2270e9db039aeeeaa36d956151d4126c94d164bb8andrew@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * 4470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * Use of this source code is governed by a BSD-style license 5470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * that can be found in the LICENSE file in the root of the source 6470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * tree. An additional intellectual property rights grant can be found 7470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * in the file PATENTS. All contributing project authors may 8470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * be found in the AUTHORS file in the root of the source tree. 9470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */ 10470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 11470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// This sub-API supports the following functionalities: 12470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// 13470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// - Support of non-default codecs (e.g. iLBC, iSAC, etc.). 14470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// - Voice Activity Detection (VAD) on a per channel basis. 15470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// - Possibility to specify how to map received payload types to codecs. 16470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// 17470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// Usage example, omitting error checking: 18470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// 19470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// using namespace webrtc; 20470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// VoiceEngine* voe = VoiceEngine::Create(); 21470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// VoEBase* base = VoEBase::GetInterface(voe); 222098988d79c5851822067654db92a76b68a5fa1fajm@google.com// VoECodec* codec = VoECodec::GetInterface(voe); 23470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// base->Init(); 24470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// int num_of_codecs = codec->NumOfCodecs() 25470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// ... 26470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// base->Terminate(); 27470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// base->Release(); 28470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// codec->Release(); 29470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// VoiceEngine::Delete(voe); 30470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com// 31470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#ifndef WEBRTC_VOICE_ENGINE_VOE_CODEC_H 32470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#define WEBRTC_VOICE_ENGINE_VOE_CODEC_H 33470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 34956aa7e0874f2e08c335a82a2c32f400fac8b031pbos@webrtc.org#include "webrtc/common_types.h" 35470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 36470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comnamespace webrtc { 37470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 38b04965ccf83c2bc6e2758abab9bea0c18551a54civocclass RtcEventLog; 39470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comclass VoiceEngine; 40470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 410d266054acece70259fc1e85026194154f41e5a0Jelena Marusicclass WEBRTC_DLLEXPORT VoECodec { 420d266054acece70259fc1e85026194154f41e5a0Jelena Marusic public: 430d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Factory for the VoECodec sub-API. Increases an internal 440d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // reference counter if successful. Returns NULL if the API is not 450d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // supported or if construction fails. 460d266054acece70259fc1e85026194154f41e5a0Jelena Marusic static VoECodec* GetInterface(VoiceEngine* voiceEngine); 470d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 480d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Releases the VoECodec sub-API and decreases an internal 490d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // reference counter. Returns the new reference count. This value should 500d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // be zero for all sub-API:s before the VoiceEngine object can be safely 510d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // deleted. 520d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int Release() = 0; 530d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 540d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Gets the number of supported codecs. 550d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int NumOfCodecs() = 0; 560d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 570d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Get the |codec| information for a specified list |index|. 580d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int GetCodec(int index, CodecInst& codec) = 0; 590d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 600d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Sets the |codec| for the |channel| to be used for sending. 610d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetSendCodec(int channel, const CodecInst& codec) = 0; 620d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 630d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Gets the |codec| parameters for the sending codec on a specified 640d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // |channel|. 650d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int GetSendCodec(int channel, CodecInst& codec) = 0; 660d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 670d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Sets the bitrate on a specified |channel| to the specified value 680d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // (in bits/sec). If the value is not supported by the codec, the codec will 690d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // choose an appropriate value. 700d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Returns -1 on failure and 0 on success. 710d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetBitRate(int channel, int bitrate_bps) = 0; 720d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 730d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Gets the currently received |codec| for a specific |channel|. 740d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int GetRecCodec(int channel, CodecInst& codec) = 0; 750d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 760d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Sets the dynamic payload type number for a particular |codec| or 770d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // disables (ignores) a codec for receiving. For instance, when receiving 780d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // an invite from a SIP-based client, this function can be used to change 790d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // the dynamic payload type number to match that in the INVITE SDP- 800d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // message. The utilized parameters in the |codec| structure are: 810d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // plname, plfreq, pltype and channels. 820d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetRecPayloadType(int channel, const CodecInst& codec) = 0; 830d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 840d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Gets the actual payload type that is set for receiving a |codec| on a 850d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // |channel|. The value it retrieves will either be the default payload 860d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // type, or a value earlier set with SetRecPayloadType(). 870d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int GetRecPayloadType(int channel, CodecInst& codec) = 0; 880d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 890d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Sets the payload |type| for the sending of SID-frames with background 900d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // noise estimation during silence periods detected by the VAD. 910d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetSendCNPayloadType( 920d266054acece70259fc1e85026194154f41e5a0Jelena Marusic int channel, 930d266054acece70259fc1e85026194154f41e5a0Jelena Marusic int type, 940d266054acece70259fc1e85026194154f41e5a0Jelena Marusic PayloadFrequencies frequency = kFreq16000Hz) = 0; 950d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 960d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Sets the codec internal FEC (forward error correction) status for a 970d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // specified |channel|. Returns 0 if success, and -1 if failed. 980d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // TODO(minyue): Make SetFECStatus() pure virtual when fakewebrtcvoiceengine 990d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // in talk is ready. 1000d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetFECStatus(int channel, bool enable) { return -1; } 1010d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 1020d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Gets the codec internal FEC status for a specified |channel|. Returns 0 1030d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // with the status stored in |enabled| if success, and -1 if encountered 1040d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // error. 1050d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // TODO(minyue): Make GetFECStatus() pure virtual when fakewebrtcvoiceengine 1060d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // in talk is ready. 1070d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int GetFECStatus(int channel, bool& enabled) { return -1; } 1080d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 1090d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Sets the VAD/DTX (silence suppression) status and |mode| for a 1100d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // specified |channel|. Disabling VAD (through |enable|) will also disable 1110d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // DTX; it is not necessary to explictly set |disableDTX| in this case. 1120d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetVADStatus(int channel, 1130d266054acece70259fc1e85026194154f41e5a0Jelena Marusic bool enable, 1140d266054acece70259fc1e85026194154f41e5a0Jelena Marusic VadModes mode = kVadConventional, 1150d266054acece70259fc1e85026194154f41e5a0Jelena Marusic bool disableDTX = false) = 0; 1160d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 1170d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // Gets the VAD/DTX status and |mode| for a specified |channel|. 1180d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int GetVADStatus(int channel, 1190d266054acece70259fc1e85026194154f41e5a0Jelena Marusic bool& enabled, 1200d266054acece70259fc1e85026194154f41e5a0Jelena Marusic VadModes& mode, 1210d266054acece70259fc1e85026194154f41e5a0Jelena Marusic bool& disabledDTX) = 0; 1220d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 1230d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // If send codec is Opus on a specified |channel|, sets the maximum playback 1240d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // rate the receiver will render: |frequency_hz| (in Hz). 1250d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // TODO(minyue): Make SetOpusMaxPlaybackRate() pure virtual when 1260d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // fakewebrtcvoiceengine in talk is ready. 1270d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetOpusMaxPlaybackRate(int channel, int frequency_hz) { 1280d266054acece70259fc1e85026194154f41e5a0Jelena Marusic return -1; 1290d266054acece70259fc1e85026194154f41e5a0Jelena Marusic } 1300d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 1310d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // If send codec is Opus on a specified |channel|, set its DTX. Returns 0 if 1320d266054acece70259fc1e85026194154f41e5a0Jelena Marusic // success, and -1 if failed. 1330d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual int SetOpusDtx(int channel, bool enable_dtx) = 0; 1340d266054acece70259fc1e85026194154f41e5a0Jelena Marusic 135b04965ccf83c2bc6e2758abab9bea0c18551a54civoc // Get a pointer to the event logging object associated with this Voice 136b04965ccf83c2bc6e2758abab9bea0c18551a54civoc // Engine. This pointer will remain valid until VoiceEngine is destroyed. 137b04965ccf83c2bc6e2758abab9bea0c18551a54civoc virtual RtcEventLog* GetEventLog() = 0; 138b04965ccf83c2bc6e2758abab9bea0c18551a54civoc 1390d266054acece70259fc1e85026194154f41e5a0Jelena Marusic protected: 1400d266054acece70259fc1e85026194154f41e5a0Jelena Marusic VoECodec() {} 1410d266054acece70259fc1e85026194154f41e5a0Jelena Marusic virtual ~VoECodec() {} 142470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com}; 143470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 144d900e8bea84c474696bf0219aed1353ce65ffd8epbos@webrtc.org} // namespace webrtc 145470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 146470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#endif // WEBRTC_VOICE_ENGINE_VOE_CODEC_H 147