Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine.cc

Issue 1741933002: Prevent a voice channel from sending data before a renderer is set. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding "need to apply options" flag, to retain the previous behavior with send_ and desired_send_ w… Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 15 matching lines...) Expand all
26 #include "webrtc/base/base64.h" 26 #include "webrtc/base/base64.h"
27 #include "webrtc/base/byteorder.h" 27 #include "webrtc/base/byteorder.h"
28 #include "webrtc/base/common.h" 28 #include "webrtc/base/common.h"
29 #include "webrtc/base/helpers.h" 29 #include "webrtc/base/helpers.h"
30 #include "webrtc/base/logging.h" 30 #include "webrtc/base/logging.h"
31 #include "webrtc/base/stringencode.h" 31 #include "webrtc/base/stringencode.h"
32 #include "webrtc/base/stringutils.h" 32 #include "webrtc/base/stringutils.h"
33 #include "webrtc/call/rtc_event_log.h" 33 #include "webrtc/call/rtc_event_log.h"
34 #include "webrtc/common.h" 34 #include "webrtc/common.h"
35 #include "webrtc/media/base/audioframe.h" 35 #include "webrtc/media/base/audioframe.h"
36 #include "webrtc/media/base/audiorenderer.h" 36 #include "webrtc/media/base/audiosource.h"
37 #include "webrtc/media/base/mediaconstants.h" 37 #include "webrtc/media/base/mediaconstants.h"
38 #include "webrtc/media/base/streamparams.h" 38 #include "webrtc/media/base/streamparams.h"
39 #include "webrtc/media/engine/webrtcmediaengine.h" 39 #include "webrtc/media/engine/webrtcmediaengine.h"
40 #include "webrtc/media/engine/webrtcvoe.h" 40 #include "webrtc/media/engine/webrtcvoe.h"
41 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" 41 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
42 #include "webrtc/modules/audio_processing/include/audio_processing.h" 42 #include "webrtc/modules/audio_processing/include/audio_processing.h"
43 #include "webrtc/system_wrappers/include/field_trial.h" 43 #include "webrtc/system_wrappers/include/field_trial.h"
44 #include "webrtc/system_wrappers/include/trace.h" 44 #include "webrtc/system_wrappers/include/trace.h"
45 45
46 namespace cricket { 46 namespace cricket {
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 } 1129 }
1130 LOG_RTCERR0(StopRtcEventLog); 1130 LOG_RTCERR0(StopRtcEventLog);
1131 } 1131 }
1132 1132
1133 int WebRtcVoiceEngine::CreateVoEChannel() { 1133 int WebRtcVoiceEngine::CreateVoEChannel() {
1134 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1134 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1135 return voe_wrapper_->base()->CreateChannel(voe_config_); 1135 return voe_wrapper_->base()->CreateChannel(voe_config_);
1136 } 1136 }
1137 1137
1138 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream 1138 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
1139 : public AudioRenderer::Sink { 1139 : public AudioSource::Sink {
1140 public: 1140 public:
1141 WebRtcAudioSendStream(int ch, webrtc::AudioTransport* voe_audio_transport, 1141 WebRtcAudioSendStream(int ch, webrtc::AudioTransport* voe_audio_transport,
1142 uint32_t ssrc, const std::string& c_name, 1142 uint32_t ssrc, const std::string& c_name,
1143 const std::vector<webrtc::RtpExtension>& extensions, 1143 const std::vector<webrtc::RtpExtension>& extensions,
1144 webrtc::Call* call) 1144 webrtc::Call* call)
1145 : voe_audio_transport_(voe_audio_transport), 1145 : voe_audio_transport_(voe_audio_transport),
1146 call_(call), 1146 call_(call),
1147 config_(nullptr) { 1147 config_(nullptr) {
1148 RTC_DCHECK_GE(ch, 0); 1148 RTC_DCHECK_GE(ch, 0);
1149 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: 1149 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore:
1150 // RTC_DCHECK(voe_audio_transport); 1150 // RTC_DCHECK(voe_audio_transport);
1151 RTC_DCHECK(call); 1151 RTC_DCHECK(call);
1152 audio_capture_thread_checker_.DetachFromThread(); 1152 audio_capture_thread_checker_.DetachFromThread();
1153 config_.rtp.ssrc = ssrc; 1153 config_.rtp.ssrc = ssrc;
1154 config_.rtp.c_name = c_name; 1154 config_.rtp.c_name = c_name;
1155 config_.voe_channel_id = ch; 1155 config_.voe_channel_id = ch;
1156 RecreateAudioSendStream(extensions); 1156 RecreateAudioSendStream(extensions);
1157 } 1157 }
1158 1158
1159 ~WebRtcAudioSendStream() override { 1159 ~WebRtcAudioSendStream() override {
1160 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1160 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1161 Stop(); 1161 ClearSource();
1162 call_->DestroyAudioSendStream(stream_); 1162 call_->DestroyAudioSendStream(stream_);
1163 } 1163 }
1164 1164
1165 void RecreateAudioSendStream( 1165 void RecreateAudioSendStream(
1166 const std::vector<webrtc::RtpExtension>& extensions) { 1166 const std::vector<webrtc::RtpExtension>& extensions) {
1167 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1167 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1168 if (stream_) { 1168 if (stream_) {
1169 call_->DestroyAudioSendStream(stream_); 1169 call_->DestroyAudioSendStream(stream_);
1170 stream_ = nullptr; 1170 stream_ = nullptr;
1171 } 1171 }
1172 config_.rtp.extensions = extensions; 1172 config_.rtp.extensions = extensions;
1173 RTC_DCHECK(!stream_); 1173 RTC_DCHECK(!stream_);
1174 stream_ = call_->CreateAudioSendStream(config_); 1174 stream_ = call_->CreateAudioSendStream(config_);
1175 RTC_CHECK(stream_); 1175 RTC_CHECK(stream_);
1176 } 1176 }
1177 1177
1178 bool SendTelephoneEvent(int payload_type, uint8_t event, 1178 bool SendTelephoneEvent(int payload_type, uint8_t event,
1179 uint32_t duration_ms) { 1179 uint32_t duration_ms) {
1180 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1180 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1181 RTC_DCHECK(stream_); 1181 RTC_DCHECK(stream_);
1182 return stream_->SendTelephoneEvent(payload_type, event, duration_ms); 1182 return stream_->SendTelephoneEvent(payload_type, event, duration_ms);
1183 } 1183 }
1184 1184
1185 void SetSend(bool send) {
1186 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1187 send_ = send;
1188 UpdateSendState();
1189 }
1190
1185 webrtc::AudioSendStream::Stats GetStats() const { 1191 webrtc::AudioSendStream::Stats GetStats() const {
1186 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1192 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1187 RTC_DCHECK(stream_); 1193 RTC_DCHECK(stream_);
1188 return stream_->GetStats(); 1194 return stream_->GetStats();
1189 } 1195 }
1190 1196
1191 // Starts the rendering by setting a sink to the renderer to get data 1197 // Starts the sending by setting ourselves as a sink to the AudioSource to
1192 // callback. 1198 // get data callbacks.
1193 // This method is called on the libjingle worker thread. 1199 // This method is called on the libjingle worker thread.
1194 // TODO(xians): Make sure Start() is called only once. 1200 // TODO(xians): Make sure Start() is called only once.
1195 void Start(AudioRenderer* renderer) { 1201 void SetSource(AudioSource* source) {
1196 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1202 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1197 RTC_DCHECK(renderer); 1203 RTC_DCHECK(source);
1198 if (renderer_) { 1204 if (source_) {
1199 RTC_DCHECK(renderer_ == renderer); 1205 RTC_DCHECK(source_ == source);
1200 return; 1206 return;
1201 } 1207 }
1202 renderer->SetSink(this); 1208 source->SetSink(this);
1203 renderer_ = renderer; 1209 source_ = source;
1210 UpdateSendState();
1204 } 1211 }
1205 1212
1206 // Stops rendering by setting the sink of the renderer to nullptr. No data 1213 // Stops sending by setting the sink of the AudioSource to nullptr. No data
1207 // callback will be received after this method. 1214 // callback will be received after this method.
1208 // This method is called on the libjingle worker thread. 1215 // This method is called on the libjingle worker thread.
1209 void Stop() { 1216 void ClearSource() {
1210 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1217 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1211 if (renderer_) { 1218 if (source_) {
1212 renderer_->SetSink(nullptr); 1219 source_->SetSink(nullptr);
1213 renderer_ = nullptr; 1220 source_ = nullptr;
1214 } 1221 }
1222 UpdateSendState();
1215 } 1223 }
1216 1224
1217 // AudioRenderer::Sink implementation. 1225 // AudioSource::Sink implementation.
1218 // This method is called on the audio thread. 1226 // This method is called on the audio thread.
1219 void OnData(const void* audio_data, 1227 void OnData(const void* audio_data,
1220 int bits_per_sample, 1228 int bits_per_sample,
1221 int sample_rate, 1229 int sample_rate,
1222 size_t number_of_channels, 1230 size_t number_of_channels,
1223 size_t number_of_frames) override { 1231 size_t number_of_frames) override {
1224 RTC_DCHECK(!worker_thread_checker_.CalledOnValidThread()); 1232 RTC_DCHECK(!worker_thread_checker_.CalledOnValidThread());
1225 RTC_DCHECK(audio_capture_thread_checker_.CalledOnValidThread()); 1233 RTC_DCHECK(audio_capture_thread_checker_.CalledOnValidThread());
1226 RTC_DCHECK(voe_audio_transport_); 1234 RTC_DCHECK(voe_audio_transport_);
1227 voe_audio_transport_->OnData(config_.voe_channel_id, 1235 voe_audio_transport_->OnData(config_.voe_channel_id,
1228 audio_data, 1236 audio_data,
1229 bits_per_sample, 1237 bits_per_sample,
1230 sample_rate, 1238 sample_rate,
1231 number_of_channels, 1239 number_of_channels,
1232 number_of_frames); 1240 number_of_frames);
1233 } 1241 }
1234 1242
1235 // Callback from the |renderer_| when it is going away. In case Start() has 1243 // Callback from the |source_| when it is going away. In case Start() has
1236 // never been called, this callback won't be triggered. 1244 // never been called, this callback won't be triggered.
1237 void OnClose() override { 1245 void OnClose() override {
1238 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1246 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1239 // Set |renderer_| to nullptr to make sure no more callback will get into 1247 // Set |source_| to nullptr to make sure no more callback will get into
1240 // the renderer. 1248 // the source.
1241 renderer_ = nullptr; 1249 source_ = nullptr;
1250 UpdateSendState();
1242 } 1251 }
1243 1252
1244 // Accessor to the VoE channel ID. 1253 // Accessor to the VoE channel ID.
1245 int channel() const { 1254 int channel() const {
1246 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1255 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1247 return config_.voe_channel_id; 1256 return config_.voe_channel_id;
1248 } 1257 }
1249 1258
1250 private: 1259 private:
1260 void UpdateSendState() {
1261 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1262 RTC_DCHECK(stream_);
1263 if (send_ && source_ != nullptr) {
1264 stream_->Start();
1265 } else { // !send || source_ = nullptr
1266 stream_->Stop();
1267 }
1268 }
1269
1251 rtc::ThreadChecker worker_thread_checker_; 1270 rtc::ThreadChecker worker_thread_checker_;
1252 rtc::ThreadChecker audio_capture_thread_checker_; 1271 rtc::ThreadChecker audio_capture_thread_checker_;
1253 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; 1272 webrtc::AudioTransport* const voe_audio_transport_ = nullptr;
1254 webrtc::Call* call_ = nullptr; 1273 webrtc::Call* call_ = nullptr;
1255 webrtc::AudioSendStream::Config config_; 1274 webrtc::AudioSendStream::Config config_;
1256 // The stream is owned by WebRtcAudioSendStream and may be reallocated if 1275 // The stream is owned by WebRtcAudioSendStream and may be reallocated if
1257 // configuration changes. 1276 // configuration changes.
1258 webrtc::AudioSendStream* stream_ = nullptr; 1277 webrtc::AudioSendStream* stream_ = nullptr;
1259 1278
1260 // Raw pointer to AudioRenderer owned by LocalAudioTrackHandler. 1279 // Raw pointer to AudioSource owned by LocalAudioTrackHandler.
1261 // PeerConnection will make sure invalidating the pointer before the object 1280 // PeerConnection will make sure invalidating the pointer before the object
1262 // goes away. 1281 // goes away.
1263 AudioRenderer* renderer_ = nullptr; 1282 AudioSource* source_ = nullptr;
1283 bool send_ = false;
1264 1284
1265 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream); 1285 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream);
1266 }; 1286 };
1267 1287
1268 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream { 1288 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream {
1269 public: 1289 public:
1270 WebRtcAudioReceiveStream(int ch, 1290 WebRtcAudioReceiveStream(int ch,
1271 uint32_t remote_ssrc, 1291 uint32_t remote_ssrc,
1272 uint32_t local_ssrc, 1292 uint32_t local_ssrc,
1273 bool use_transport_cc, 1293 bool use_transport_cc,
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 if (!SetPlayout(ch.second->channel(), playout)) { 1816 if (!SetPlayout(ch.second->channel(), playout)) {
1797 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " 1817 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel "
1798 << ch.second->channel() << " failed"; 1818 << ch.second->channel() << " failed";
1799 return false; 1819 return false;
1800 } 1820 }
1801 } 1821 }
1802 playout_ = playout; 1822 playout_ = playout;
1803 return true; 1823 return true;
1804 } 1824 }
1805 1825
1806 bool WebRtcVoiceMediaChannel::SetSend(SendFlags send) { 1826 void WebRtcVoiceMediaChannel::SetSend(bool send) {
1807 desired_send_ = send; 1827 // Apply channel specific options when channel is enabled for sending.
the sun 2016/03/08 10:54:12 Uhm, right, this becomes a bit messy. I'd rather c
Taylor Brandstetter 2016/03/08 16:24:42 Done.
1808 if (!send_streams_.empty()) { 1828 if (send && !send_streams_.empty() && need_to_apply_options_) {
1809 return ChangeSend(desired_send_); 1829 engine()->ApplyOptions(options_);
1810 } 1830 need_to_apply_options_ = false;
1811 return true;
1812 }
1813
1814 bool WebRtcVoiceMediaChannel::PauseSend() {
1815 return ChangeSend(SEND_NOTHING);
1816 }
1817
1818 bool WebRtcVoiceMediaChannel::ResumeSend() {
1819 return ChangeSend(desired_send_);
1820 }
1821
1822 bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) {
1823 if (send_ == send) {
1824 return true;
1825 } 1831 }
1826 1832
1827 // Apply channel specific options when channel is enabled for sending. 1833 if (send_ == send) {
1828 if (send == SEND_MICROPHONE) { 1834 return;
1829 engine()->ApplyOptions(options_);
1830 } 1835 }
1831 1836
1832 // Change the settings on each send channel. 1837 // Change the settings on each send channel.
1833 for (const auto& ch : send_streams_) { 1838 for (auto& kv : send_streams_) {
1834 if (!ChangeSend(ch.second->channel(), send)) { 1839 kv.second->SetSend(send);
1835 return false; 1840 }
1836 } 1841
1842 if (!send) {
1843 need_to_apply_options_ = true;
1837 } 1844 }
1838 1845
1839 send_ = send; 1846 send_ = send;
1840 return true;
1841 }
1842
1843 bool WebRtcVoiceMediaChannel::ChangeSend(int channel, SendFlags send) {
1844 if (send == SEND_MICROPHONE) {
1845 if (engine()->voe()->base()->StartSend(channel) == -1) {
1846 LOG_RTCERR1(StartSend, channel);
1847 return false;
1848 }
1849 } else { // SEND_NOTHING
1850 RTC_DCHECK(send == SEND_NOTHING);
1851 if (engine()->voe()->base()->StopSend(channel) == -1) {
1852 LOG_RTCERR1(StopSend, channel);
1853 return false;
1854 }
1855 }
1856
1857 return true;
1858 } 1847 }
1859 1848
1860 bool WebRtcVoiceMediaChannel::SetAudioSend(uint32_t ssrc, 1849 bool WebRtcVoiceMediaChannel::SetAudioSend(uint32_t ssrc,
1861 bool enable, 1850 bool enable,
1862 const AudioOptions* options, 1851 const AudioOptions* options,
1863 AudioRenderer* renderer) { 1852 AudioSource* source) {
1864 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1853 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1865 // TODO(solenberg): The state change should be fully rolled back if any one of 1854 // TODO(solenberg): The state change should be fully rolled back if any one of
1866 // these calls fail. 1855 // these calls fail.
1867 if (!SetLocalRenderer(ssrc, renderer)) { 1856 if (!SetLocalSource(ssrc, source)) {
1868 return false; 1857 return false;
1869 } 1858 }
1870 if (!MuteStream(ssrc, !enable)) { 1859 if (!MuteStream(ssrc, !enable)) {
1871 return false; 1860 return false;
1872 } 1861 }
1873 if (enable && options) { 1862 if (enable && options) {
1874 return SetOptions(*options); 1863 return SetOptions(*options);
1875 } 1864 }
1876 return true; 1865 return true;
1877 } 1866 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 if (engine()->voe()->rtp()->SetLocalSSRC(recv_channel, ssrc) != 0) { 1933 if (engine()->voe()->rtp()->SetLocalSSRC(recv_channel, ssrc) != 0) {
1945 LOG_RTCERR2(SetLocalSSRC, recv_channel, ssrc); 1934 LOG_RTCERR2(SetLocalSSRC, recv_channel, ssrc);
1946 return false; 1935 return false;
1947 } 1936 }
1948 engine()->voe()->base()->AssociateSendChannel(recv_channel, channel); 1937 engine()->voe()->base()->AssociateSendChannel(recv_channel, channel);
1949 LOG(LS_INFO) << "VoiceEngine channel #" << recv_channel 1938 LOG(LS_INFO) << "VoiceEngine channel #" << recv_channel
1950 << " is associated with channel #" << channel << "."; 1939 << " is associated with channel #" << channel << ".";
1951 } 1940 }
1952 } 1941 }
1953 1942
1954 return ChangeSend(channel, desired_send_); 1943 send_streams_[ssrc]->SetSend(send_);
1944 return true;
1955 } 1945 }
1956 1946
1957 bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) { 1947 bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) {
1958 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1948 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1959 LOG(LS_INFO) << "RemoveSendStream: " << ssrc; 1949 LOG(LS_INFO) << "RemoveSendStream: " << ssrc;
1960 1950
1961 auto it = send_streams_.find(ssrc); 1951 auto it = send_streams_.find(ssrc);
1962 if (it == send_streams_.end()) { 1952 if (it == send_streams_.end()) {
1963 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc 1953 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc
1964 << " which doesn't exist."; 1954 << " which doesn't exist.";
1965 return false; 1955 return false;
1966 } 1956 }
1967 1957
1968 int channel = it->second->channel(); 1958 it->second->SetSend(false);
1969 ChangeSend(channel, SEND_NOTHING);
1970 1959
1971 // Clean up and delete the send stream+channel. 1960 // Clean up and delete the send stream+channel.
1961 int channel = it->second->channel();
1972 LOG(LS_INFO) << "Removing audio send stream " << ssrc 1962 LOG(LS_INFO) << "Removing audio send stream " << ssrc
1973 << " with VoiceEngine channel #" << channel << "."; 1963 << " with VoiceEngine channel #" << channel << ".";
1974 delete it->second; 1964 delete it->second;
1975 send_streams_.erase(it); 1965 send_streams_.erase(it);
1976 if (!DeleteVoEChannel(channel)) { 1966 if (!DeleteVoEChannel(channel)) {
1977 return false; 1967 return false;
1978 } 1968 }
1979 if (send_streams_.empty()) { 1969 if (send_streams_.empty()) {
1980 ChangeSend(SEND_NOTHING); 1970 need_to_apply_options_ = true;
the sun 2016/03/08 10:54:12 Likewise, change back to: SetSend(false); Sorry.
Taylor Brandstetter 2016/03/08 16:24:42 Done.
1981 } 1971 }
1982 return true; 1972 return true;
1983 } 1973 }
1984 1974
1985 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { 1975 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) {
1986 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1976 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1987 LOG(LS_INFO) << "AddRecvStream: " << sp.ToString(); 1977 LOG(LS_INFO) << "AddRecvStream: " << sp.ToString();
1988 1978
1989 if (!ValidateStreamParams(sp)) { 1979 if (!ValidateStreamParams(sp)) {
1990 return false; 1980 return false;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 2071
2082 // Clean up and delete the receive stream+channel. 2072 // Clean up and delete the receive stream+channel.
2083 LOG(LS_INFO) << "Removing audio receive stream " << ssrc 2073 LOG(LS_INFO) << "Removing audio receive stream " << ssrc
2084 << " with VoiceEngine channel #" << channel << "."; 2074 << " with VoiceEngine channel #" << channel << ".";
2085 it->second->SetRawAudioSink(nullptr); 2075 it->second->SetRawAudioSink(nullptr);
2086 delete it->second; 2076 delete it->second;
2087 recv_streams_.erase(it); 2077 recv_streams_.erase(it);
2088 return DeleteVoEChannel(channel); 2078 return DeleteVoEChannel(channel);
2089 } 2079 }
2090 2080
2091 bool WebRtcVoiceMediaChannel::SetLocalRenderer(uint32_t ssrc, 2081 bool WebRtcVoiceMediaChannel::SetLocalSource(uint32_t ssrc,
2092 AudioRenderer* renderer) { 2082 AudioSource* source) {
2093 auto it = send_streams_.find(ssrc); 2083 auto it = send_streams_.find(ssrc);
2094 if (it == send_streams_.end()) { 2084 if (it == send_streams_.end()) {
2095 if (renderer) { 2085 if (source) {
2096 // Return an error if trying to set a valid renderer with an invalid ssrc. 2086 // Return an error if trying to set a valid source with an invalid ssrc.
2097 LOG(LS_ERROR) << "SetLocalRenderer failed with ssrc "<< ssrc; 2087 LOG(LS_ERROR) << "SetLocalSource failed with ssrc " << ssrc;
2098 return false; 2088 return false;
2099 } 2089 }
2100 2090
2101 // The channel likely has gone away, do nothing. 2091 // The channel likely has gone away, do nothing.
2102 return true; 2092 return true;
2103 } 2093 }
2104 2094
2105 if (renderer) { 2095 if (source) {
2106 it->second->Start(renderer); 2096 it->second->SetSource(source);
2107 } else { 2097 } else {
2108 it->second->Stop(); 2098 it->second->ClearSource();
2109 } 2099 }
2110 2100
2111 return true; 2101 return true;
2112 } 2102 }
2113 2103
2114 bool WebRtcVoiceMediaChannel::GetActiveStreams( 2104 bool WebRtcVoiceMediaChannel::GetActiveStreams(
2115 AudioInfo::StreamList* actives) { 2105 AudioInfo::StreamList* actives) {
2116 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2106 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2117 actives->clear(); 2107 actives->clear();
2118 for (const auto& ch : recv_streams_) { 2108 for (const auto& ch : recv_streams_) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 sinfo.codec_name = stats.codec_name; 2406 sinfo.codec_name = stats.codec_name;
2417 sinfo.ext_seqnum = stats.ext_seqnum; 2407 sinfo.ext_seqnum = stats.ext_seqnum;
2418 sinfo.jitter_ms = stats.jitter_ms; 2408 sinfo.jitter_ms = stats.jitter_ms;
2419 sinfo.rtt_ms = stats.rtt_ms; 2409 sinfo.rtt_ms = stats.rtt_ms;
2420 sinfo.audio_level = stats.audio_level; 2410 sinfo.audio_level = stats.audio_level;
2421 sinfo.aec_quality_min = stats.aec_quality_min; 2411 sinfo.aec_quality_min = stats.aec_quality_min;
2422 sinfo.echo_delay_median_ms = stats.echo_delay_median_ms; 2412 sinfo.echo_delay_median_ms = stats.echo_delay_median_ms;
2423 sinfo.echo_delay_std_ms = stats.echo_delay_std_ms; 2413 sinfo.echo_delay_std_ms = stats.echo_delay_std_ms;
2424 sinfo.echo_return_loss = stats.echo_return_loss; 2414 sinfo.echo_return_loss = stats.echo_return_loss;
2425 sinfo.echo_return_loss_enhancement = stats.echo_return_loss_enhancement; 2415 sinfo.echo_return_loss_enhancement = stats.echo_return_loss_enhancement;
2426 sinfo.typing_noise_detected = 2416 sinfo.typing_noise_detected = (send_ ? stats.typing_noise_detected : false);
2427 (send_ == SEND_NOTHING ? false : stats.typing_noise_detected);
2428 info->senders.push_back(sinfo); 2417 info->senders.push_back(sinfo);
2429 } 2418 }
2430 2419
2431 // Get SSRC and stats for each receiver. 2420 // Get SSRC and stats for each receiver.
2432 RTC_DCHECK(info->receivers.size() == 0); 2421 RTC_DCHECK(info->receivers.size() == 0);
2433 for (const auto& stream : recv_streams_) { 2422 for (const auto& stream : recv_streams_) {
2434 webrtc::AudioReceiveStream::Stats stats = stream.second->GetStats(); 2423 webrtc::AudioReceiveStream::Stats stats = stream.second->GetStats();
2435 VoiceReceiverInfo rinfo; 2424 VoiceReceiverInfo rinfo;
2436 rinfo.add_ssrc(stats.remote_ssrc); 2425 rinfo.add_ssrc(stats.remote_ssrc);
2437 rinfo.bytes_rcvd = stats.bytes_rcvd; 2426 rinfo.bytes_rcvd = stats.bytes_rcvd;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 } 2509 }
2521 } else { 2510 } else {
2522 LOG(LS_INFO) << "Stopping playout for channel #" << channel; 2511 LOG(LS_INFO) << "Stopping playout for channel #" << channel;
2523 engine()->voe()->base()->StopPlayout(channel); 2512 engine()->voe()->base()->StopPlayout(channel);
2524 } 2513 }
2525 return true; 2514 return true;
2526 } 2515 }
2527 } // namespace cricket 2516 } // namespace cricket
2528 2517
2529 #endif // HAVE_WEBRTC_VOICE 2518 #endif // HAVE_WEBRTC_VOICE
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.h ('k') | webrtc/media/engine/webrtcvoiceengine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698