OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "webrtc/call.h" | 46 #include "webrtc/call.h" |
47 #include "webrtc/common.h" | 47 #include "webrtc/common.h" |
48 #include "webrtc/config.h" | 48 #include "webrtc/config.h" |
49 | 49 |
50 namespace cricket { | 50 namespace cricket { |
51 | 51 |
52 class AudioDeviceModule; | 52 class AudioDeviceModule; |
53 class AudioRenderer; | 53 class AudioRenderer; |
54 class VoETraceWrapper; | 54 class VoETraceWrapper; |
55 class VoEWrapper; | 55 class VoEWrapper; |
56 class VoiceProcessor; | |
57 class WebRtcVoiceMediaChannel; | 56 class WebRtcVoiceMediaChannel; |
58 | 57 |
59 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. | 58 // WebRtcVoiceEngine is a class to be used with CompositeMediaEngine. |
60 // It uses the WebRtc VoiceEngine library for audio handling. | 59 // It uses the WebRtc VoiceEngine library for audio handling. |
61 class WebRtcVoiceEngine | 60 class WebRtcVoiceEngine |
62 : public webrtc::VoiceEngineObserver, | 61 : public webrtc::VoiceEngineObserver, |
63 public webrtc::TraceCallback, | 62 public webrtc::TraceCallback { |
64 public webrtc::VoEMediaProcess { | |
65 friend class WebRtcVoiceMediaChannel; | 63 friend class WebRtcVoiceMediaChannel; |
66 | 64 |
67 public: | 65 public: |
68 WebRtcVoiceEngine(); | 66 WebRtcVoiceEngine(); |
69 // Dependency injection for testing. | 67 // Dependency injection for testing. |
70 WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing); | 68 WebRtcVoiceEngine(VoEWrapper* voe_wrapper, VoETraceWrapper* tracing); |
71 ~WebRtcVoiceEngine(); | 69 ~WebRtcVoiceEngine(); |
72 bool Init(rtc::Thread* worker_thread); | 70 bool Init(rtc::Thread* worker_thread); |
73 void Terminate(); | 71 void Terminate(); |
74 | 72 |
(...skipping 11 matching lines...) Expand all Loading... |
86 int GetInputLevel(); | 84 int GetInputLevel(); |
87 | 85 |
88 const std::vector<AudioCodec>& codecs(); | 86 const std::vector<AudioCodec>& codecs(); |
89 bool FindCodec(const AudioCodec& codec); | 87 bool FindCodec(const AudioCodec& codec); |
90 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec); | 88 bool FindWebRtcCodec(const AudioCodec& codec, webrtc::CodecInst* gcodec); |
91 | 89 |
92 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const; | 90 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const; |
93 | 91 |
94 void SetLogging(int min_sev, const char* filter); | 92 void SetLogging(int min_sev, const char* filter); |
95 | 93 |
96 bool RegisterProcessor(uint32 ssrc, | |
97 VoiceProcessor* voice_processor, | |
98 MediaProcessorDirection direction); | |
99 bool UnregisterProcessor(uint32 ssrc, | |
100 VoiceProcessor* voice_processor, | |
101 MediaProcessorDirection direction); | |
102 | |
103 // Method from webrtc::VoEMediaProcess | |
104 void Process(int channel, | |
105 webrtc::ProcessingTypes type, | |
106 int16_t audio10ms[], | |
107 size_t length, | |
108 int sampling_freq, | |
109 bool is_stereo) override; | |
110 | |
111 // For tracking WebRtc channels. Needed because we have to pause them | 94 // For tracking WebRtc channels. Needed because we have to pause them |
112 // all when switching devices. | 95 // all when switching devices. |
113 // May only be called by WebRtcVoiceMediaChannel. | 96 // May only be called by WebRtcVoiceMediaChannel. |
114 void RegisterChannel(WebRtcVoiceMediaChannel *channel); | 97 void RegisterChannel(WebRtcVoiceMediaChannel *channel); |
115 void UnregisterChannel(WebRtcVoiceMediaChannel *channel); | 98 void UnregisterChannel(WebRtcVoiceMediaChannel *channel); |
116 | 99 |
117 // Called by WebRtcVoiceMediaChannel to set a gain offset from | 100 // Called by WebRtcVoiceMediaChannel to set a gain offset from |
118 // the default AGC target level. | 101 // the default AGC target level. |
119 bool AdjustAgcLevel(int delta); | 102 bool AdjustAgcLevel(int delta); |
120 | 103 |
121 VoEWrapper* voe() { return voe_wrapper_.get(); } | 104 VoEWrapper* voe() { return voe_wrapper_.get(); } |
122 int GetLastEngineError(); | 105 int GetLastEngineError(); |
123 | 106 |
124 // Set the external ADM. This can only be called before Init. | 107 // Set the external ADM. This can only be called before Init. |
125 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm); | 108 bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm); |
126 | 109 |
127 // Starts AEC dump using existing file. | 110 // Starts AEC dump using existing file. |
128 bool StartAecDump(rtc::PlatformFile file); | 111 bool StartAecDump(rtc::PlatformFile file); |
129 | 112 |
130 // Check whether the supplied trace should be ignored. | 113 // Check whether the supplied trace should be ignored. |
131 bool ShouldIgnoreTrace(const std::string& trace); | 114 bool ShouldIgnoreTrace(const std::string& trace); |
132 | 115 |
133 // Create a VoiceEngine Channel. | 116 // Create a VoiceEngine Channel. |
134 int CreateMediaVoiceChannel(); | 117 int CreateMediaVoiceChannel(); |
135 | 118 |
136 private: | 119 private: |
137 typedef std::vector<WebRtcVoiceMediaChannel*> ChannelList; | 120 typedef std::vector<WebRtcVoiceMediaChannel*> ChannelList; |
138 typedef sigslot:: | |
139 signal3<uint32, MediaProcessorDirection, AudioFrame*> FrameSignal; | |
140 | 121 |
141 void Construct(); | 122 void Construct(); |
142 void ConstructCodecs(); | 123 void ConstructCodecs(); |
143 bool GetVoeCodec(int index, webrtc::CodecInst* codec); | 124 bool GetVoeCodec(int index, webrtc::CodecInst* codec); |
144 bool InitInternal(); | 125 bool InitInternal(); |
145 void SetTraceFilter(int filter); | 126 void SetTraceFilter(int filter); |
146 void SetTraceOptions(const std::string& options); | 127 void SetTraceOptions(const std::string& options); |
147 // Applies either options or overrides. Every option that is "set" | 128 // Applies either options or overrides. Every option that is "set" |
148 // will be applied. Every option not "set" will be ignored. This | 129 // will be applied. Every option not "set" will be ignored. This |
149 // allows us to selectively turn on and off different options easily | 130 // allows us to selectively turn on and off different options easily |
(...skipping 19 matching lines...) Expand all Loading... |
169 // webrtc::VoiceEngineObserver: | 150 // webrtc::VoiceEngineObserver: |
170 void CallbackOnError(int channel, int errCode) override; | 151 void CallbackOnError(int channel, int errCode) override; |
171 | 152 |
172 // Given the device type, name, and id, find device id. Return true and | 153 // Given the device type, name, and id, find device id. Return true and |
173 // set the output parameter rtc_id if successful. | 154 // set the output parameter rtc_id if successful. |
174 bool FindWebRtcAudioDeviceId( | 155 bool FindWebRtcAudioDeviceId( |
175 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id); | 156 bool is_input, const std::string& dev_name, int dev_id, int* rtc_id); |
176 bool FindChannelAndSsrc(int channel_num, | 157 bool FindChannelAndSsrc(int channel_num, |
177 WebRtcVoiceMediaChannel** channel, | 158 WebRtcVoiceMediaChannel** channel, |
178 uint32* ssrc) const; | 159 uint32* ssrc) const; |
179 bool FindChannelNumFromSsrc(uint32 ssrc, | |
180 MediaProcessorDirection direction, | |
181 int* channel_num); | |
182 | |
183 bool UnregisterProcessorChannel(MediaProcessorDirection channel_direction, | |
184 uint32 ssrc, | |
185 VoiceProcessor* voice_processor, | |
186 MediaProcessorDirection processor_direction); | |
187 | 160 |
188 void StartAecDump(const std::string& filename); | 161 void StartAecDump(const std::string& filename); |
189 void StopAecDump(); | 162 void StopAecDump(); |
190 int CreateVoiceChannel(VoEWrapper* voe); | 163 int CreateVoiceChannel(VoEWrapper* voe); |
191 | 164 |
192 // When a voice processor registers with the engine, it is connected | |
193 // to either the Rx or Tx signals, based on the direction parameter. | |
194 // SignalXXMediaFrame will be invoked for every audio packet. | |
195 FrameSignal SignalRxMediaFrame; | |
196 FrameSignal SignalTxMediaFrame; | |
197 | |
198 static const int kDefaultLogSeverity = rtc::LS_WARNING; | 165 static const int kDefaultLogSeverity = rtc::LS_WARNING; |
199 | 166 |
200 // The primary instance of WebRtc VoiceEngine. | 167 // The primary instance of WebRtc VoiceEngine. |
201 rtc::scoped_ptr<VoEWrapper> voe_wrapper_; | 168 rtc::scoped_ptr<VoEWrapper> voe_wrapper_; |
202 rtc::scoped_ptr<VoETraceWrapper> tracing_; | 169 rtc::scoped_ptr<VoETraceWrapper> tracing_; |
203 // The external audio device manager | 170 // The external audio device manager |
204 webrtc::AudioDeviceModule* adm_; | 171 webrtc::AudioDeviceModule* adm_; |
205 int log_filter_; | 172 int log_filter_; |
206 std::string log_options_; | 173 std::string log_options_; |
207 bool is_dumping_aec_; | 174 bool is_dumping_aec_; |
(...skipping 10 matching lines...) Expand all Loading... |
218 bool initialized_; | 185 bool initialized_; |
219 // See SetOptions and SetOptionOverrides for a description of the | 186 // See SetOptions and SetOptionOverrides for a description of the |
220 // difference between options and overrides. | 187 // difference between options and overrides. |
221 // options_ are the base options, which combined with the | 188 // options_ are the base options, which combined with the |
222 // option_overrides_, create the current options being used. | 189 // option_overrides_, create the current options being used. |
223 // options_ is stored so that when option_overrides_ is cleared, we | 190 // options_ is stored so that when option_overrides_ is cleared, we |
224 // can restore the options_ without the option_overrides. | 191 // can restore the options_ without the option_overrides. |
225 AudioOptions options_; | 192 AudioOptions options_; |
226 AudioOptions option_overrides_; | 193 AudioOptions option_overrides_; |
227 | 194 |
228 // When the media processor registers with the engine, the ssrc is cached | |
229 // here so that a look up need not be made when the callback is invoked. | |
230 // This is necessary because the lookup results in mux_channels_cs lock being | |
231 // held and if a remote participant leaves the hangout at the same time | |
232 // we hit a deadlock. | |
233 uint32 tx_processor_ssrc_; | |
234 uint32 rx_processor_ssrc_; | |
235 | |
236 rtc::CriticalSection signal_media_critical_; | |
237 | |
238 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns | 195 // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns |
239 // values, and apply them in case they are missing in the audio options. We | 196 // values, and apply them in case they are missing in the audio options. We |
240 // need to do this because SetExtraOptions() will revert to defaults for | 197 // need to do this because SetExtraOptions() will revert to defaults for |
241 // options which are not provided. | 198 // options which are not provided. |
242 Settable<bool> extended_filter_aec_; | 199 Settable<bool> extended_filter_aec_; |
243 Settable<bool> delay_agnostic_aec_; | 200 Settable<bool> delay_agnostic_aec_; |
244 Settable<bool> experimental_ns_; | 201 Settable<bool> experimental_ns_; |
245 }; | 202 }; |
246 | 203 |
247 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses | 204 // WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; | 377 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; |
421 | 378 |
422 // Do not lock this on the VoE media processor thread; potential for deadlock | 379 // Do not lock this on the VoE media processor thread; potential for deadlock |
423 // exists. | 380 // exists. |
424 mutable rtc::CriticalSection receive_channels_cs_; | 381 mutable rtc::CriticalSection receive_channels_cs_; |
425 }; | 382 }; |
426 | 383 |
427 } // namespace cricket | 384 } // namespace cricket |
428 | 385 |
429 #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_ | 386 #endif // TALK_MEDIA_WEBRTCVOICEENGINE_H_ |
OLD | NEW |