3 * Copyright 2004 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef TALK_MEDIA_WEBRTCVOE_H_
30 #define TALK_MEDIA_WEBRTCVOE_H_
32 #include "talk/media/webrtc/webrtccommon.h"
33 #include "webrtc/base/common.h"
35 #include "webrtc/common_types.h"
36 #include "webrtc/modules/audio_device/include/audio_device.h"
37 #include "webrtc/voice_engine/include/voe_audio_processing.h"
38 #include "webrtc/voice_engine/include/voe_base.h"
39 #include "webrtc/voice_engine/include/voe_codec.h"
40 #include "webrtc/voice_engine/include/voe_dtmf.h"
41 #include "webrtc/voice_engine/include/voe_errors.h"
42 #include "webrtc/voice_engine/include/voe_external_media.h"
43 #include "webrtc/voice_engine/include/voe_file.h"
44 #include "webrtc/voice_engine/include/voe_hardware.h"
45 #include "webrtc/voice_engine/include/voe_neteq_stats.h"
46 #include "webrtc/voice_engine/include/voe_network.h"
47 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
48 #include "webrtc/voice_engine/include/voe_video_sync.h"
49 #include "webrtc/voice_engine/include/voe_volume_control.h"
52 // automatically handles lifetime of WebRtc VoiceEngine
53 class scoped_voe_engine {
55 explicit scoped_voe_engine(webrtc::VoiceEngine* e) : ptr(e) {}
56 // VERIFY, to ensure that there are no leaks at shutdown
57 ~scoped_voe_engine() { if (ptr) VERIFY(webrtc::VoiceEngine::Delete(ptr)); }
58 // Releases the current pointer.
61 VERIFY(webrtc::VoiceEngine::Delete(ptr));
65 webrtc::VoiceEngine* get() const { return ptr; }
67 webrtc::VoiceEngine* ptr;
70 // scoped_ptr class to handle obtaining and releasing WebRTC interface pointers
72 class scoped_voe_ptr {
74 explicit scoped_voe_ptr(const scoped_voe_engine& e)
75 : ptr(T::GetInterface(e.get())) {}
76 explicit scoped_voe_ptr(T* p) : ptr(p) {}
77 ~scoped_voe_ptr() { if (ptr) ptr->Release(); }
78 T* operator->() const { return ptr; }
79 T* get() const { return ptr; }
81 // Releases the current pointer.
93 // Utility class for aggregating the various WebRTC interface.
94 // Fake implementations can also be injected for testing.
98 : engine_(webrtc::VoiceEngine::Create()), processing_(engine_),
99 base_(engine_), codec_(engine_), dtmf_(engine_), file_(engine_),
100 hw_(engine_), media_(engine_), neteq_(engine_), network_(engine_),
101 rtp_(engine_), sync_(engine_), volume_(engine_) {
103 VoEWrapper(webrtc::VoEAudioProcessing* processing,
104 webrtc::VoEBase* base,
105 webrtc::VoECodec* codec,
106 webrtc::VoEDtmf* dtmf,
107 webrtc::VoEFile* file,
108 webrtc::VoEHardware* hw,
109 webrtc::VoEExternalMedia* media,
110 webrtc::VoENetEqStats* neteq,
111 webrtc::VoENetwork* network,
112 webrtc::VoERTP_RTCP* rtp,
113 webrtc::VoEVideoSync* sync,
114 webrtc::VoEVolumeControl* volume)
116 processing_(processing),
130 webrtc::VoiceEngine* engine() const { return engine_.get(); }
131 webrtc::VoEAudioProcessing* processing() const { return processing_.get(); }
132 webrtc::VoEBase* base() const { return base_.get(); }
133 webrtc::VoECodec* codec() const { return codec_.get(); }
134 webrtc::VoEDtmf* dtmf() const { return dtmf_.get(); }
135 webrtc::VoEFile* file() const { return file_.get(); }
136 webrtc::VoEHardware* hw() const { return hw_.get(); }
137 webrtc::VoEExternalMedia* media() const { return media_.get(); }
138 webrtc::VoENetEqStats* neteq() const { return neteq_.get(); }
139 webrtc::VoENetwork* network() const { return network_.get(); }
140 webrtc::VoERTP_RTCP* rtp() const { return rtp_.get(); }
141 webrtc::VoEVideoSync* sync() const { return sync_.get(); }
142 webrtc::VoEVolumeControl* volume() const { return volume_.get(); }
143 int error() { return base_->LastError(); }
146 scoped_voe_engine engine_;
147 scoped_voe_ptr<webrtc::VoEAudioProcessing> processing_;
148 scoped_voe_ptr<webrtc::VoEBase> base_;
149 scoped_voe_ptr<webrtc::VoECodec> codec_;
150 scoped_voe_ptr<webrtc::VoEDtmf> dtmf_;
151 scoped_voe_ptr<webrtc::VoEFile> file_;
152 scoped_voe_ptr<webrtc::VoEHardware> hw_;
153 scoped_voe_ptr<webrtc::VoEExternalMedia> media_;
154 scoped_voe_ptr<webrtc::VoENetEqStats> neteq_;
155 scoped_voe_ptr<webrtc::VoENetwork> network_;
156 scoped_voe_ptr<webrtc::VoERTP_RTCP> rtp_;
157 scoped_voe_ptr<webrtc::VoEVideoSync> sync_;
158 scoped_voe_ptr<webrtc::VoEVolumeControl> volume_;
161 // Adds indirection to static WebRtc functions, allowing them to be mocked.
162 class VoETraceWrapper {
164 virtual ~VoETraceWrapper() {}
166 virtual int SetTraceFilter(const unsigned int filter) {
167 return webrtc::VoiceEngine::SetTraceFilter(filter);
169 virtual int SetTraceFile(const char* fileNameUTF8) {
170 return webrtc::VoiceEngine::SetTraceFile(fileNameUTF8);
172 virtual int SetTraceCallback(webrtc::TraceCallback* callback) {
173 return webrtc::VoiceEngine::SetTraceCallback(callback);
177 } // namespace cricket
179 #endif // TALK_MEDIA_WEBRTCVOE_H_