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

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

Issue 1909333002: Switch voice transport to use Call and Stream instead of VoENetwork. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: VoE::Channel external transport fix Created 4 years, 7 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 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 } 1073 }
1074 1074
1075 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream 1075 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
1076 : public AudioSource::Sink { 1076 : public AudioSource::Sink {
1077 public: 1077 public:
1078 WebRtcAudioSendStream(int ch, 1078 WebRtcAudioSendStream(int ch,
1079 webrtc::AudioTransport* voe_audio_transport, 1079 webrtc::AudioTransport* voe_audio_transport,
1080 uint32_t ssrc, 1080 uint32_t ssrc,
1081 const std::string& c_name, 1081 const std::string& c_name,
1082 const std::vector<webrtc::RtpExtension>& extensions, 1082 const std::vector<webrtc::RtpExtension>& extensions,
1083 webrtc::Call* call) 1083 webrtc::Call* call,
1084 webrtc::Transport* send_transport)
1084 : voe_audio_transport_(voe_audio_transport), 1085 : voe_audio_transport_(voe_audio_transport),
1085 call_(call), 1086 call_(call),
1086 config_(nullptr), 1087 config_(send_transport),
1087 rtp_parameters_(CreateRtpParametersWithOneEncoding()) { 1088 rtp_parameters_(CreateRtpParametersWithOneEncoding()) {
1088 RTC_DCHECK_GE(ch, 0); 1089 RTC_DCHECK_GE(ch, 0);
1089 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: 1090 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore:
1090 // RTC_DCHECK(voe_audio_transport); 1091 // RTC_DCHECK(voe_audio_transport);
1091 RTC_DCHECK(call); 1092 RTC_DCHECK(call);
1092 audio_capture_thread_checker_.DetachFromThread(); 1093 audio_capture_thread_checker_.DetachFromThread();
1093 config_.rtp.ssrc = ssrc; 1094 config_.rtp.ssrc = ssrc;
1094 config_.rtp.c_name = c_name; 1095 config_.rtp.c_name = c_name;
1095 config_.voe_channel_id = ch; 1096 config_.voe_channel_id = ch;
1096 RecreateAudioSendStream(extensions); 1097 RecreateAudioSendStream(extensions);
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 } 1905 }
1905 return true; 1906 return true;
1906 } 1907 }
1907 1908
1908 int WebRtcVoiceMediaChannel::CreateVoEChannel() { 1909 int WebRtcVoiceMediaChannel::CreateVoEChannel() {
1909 int id = engine()->CreateVoEChannel(); 1910 int id = engine()->CreateVoEChannel();
1910 if (id == -1) { 1911 if (id == -1) {
1911 LOG_RTCERR0(CreateVoEChannel); 1912 LOG_RTCERR0(CreateVoEChannel);
1912 return -1; 1913 return -1;
1913 } 1914 }
1914 if (engine()->voe()->network()->RegisterExternalTransport(id, *this) == -1) { 1915
1915 LOG_RTCERR2(RegisterExternalTransport, id, this);
1916 engine()->voe()->base()->DeleteChannel(id);
1917 return -1;
1918 }
1919 return id; 1916 return id;
1920 } 1917 }
1921 1918
1922 bool WebRtcVoiceMediaChannel::DeleteVoEChannel(int channel) { 1919 bool WebRtcVoiceMediaChannel::DeleteVoEChannel(int channel) {
1923 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) {
1924 LOG_RTCERR1(DeRegisterExternalTransport, channel);
1925 }
1926 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { 1920 if (engine()->voe()->base()->DeleteChannel(channel) == -1) {
1927 LOG_RTCERR1(DeleteChannel, channel); 1921 LOG_RTCERR1(DeleteChannel, channel);
1928 return false; 1922 return false;
1929 } 1923 }
1930 return true; 1924 return true;
1931 } 1925 }
1932 1926
1933 bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { 1927 bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) {
1934 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::AddSendStream"); 1928 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::AddSendStream");
1935 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1929 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
(...skipping 10 matching lines...) Expand all
1946 // Create a new channel for sending audio data. 1940 // Create a new channel for sending audio data.
1947 int channel = CreateVoEChannel(); 1941 int channel = CreateVoEChannel();
1948 if (channel == -1) { 1942 if (channel == -1) {
1949 return false; 1943 return false;
1950 } 1944 }
1951 1945
1952 // Save the channel to send_streams_, so that RemoveSendStream() can still 1946 // Save the channel to send_streams_, so that RemoveSendStream() can still
1953 // delete the channel in case failure happens below. 1947 // delete the channel in case failure happens below.
1954 webrtc::AudioTransport* audio_transport = 1948 webrtc::AudioTransport* audio_transport =
1955 engine()->voe()->base()->audio_transport(); 1949 engine()->voe()->base()->audio_transport();
1950
1956 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( 1951 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream(
1957 channel, audio_transport, ssrc, sp.cname, send_rtp_extensions_, call_); 1952 channel, audio_transport, ssrc, sp.cname, send_rtp_extensions_, call_,
1953 this);
1958 send_streams_.insert(std::make_pair(ssrc, stream)); 1954 send_streams_.insert(std::make_pair(ssrc, stream));
1959 1955
1960 // Set the current codecs to be used for the new channel. We need to do this 1956 // Set the current codecs to be used for the new channel. We need to do this
1961 // after adding the channel to send_channels_, because of how max bitrate is 1957 // after adding the channel to send_channels_, because of how max bitrate is
1962 // currently being configured by SetSendCodec(). 1958 // currently being configured by SetSendCodec().
1963 if (HasSendCodec() && !SetSendCodecs(channel, stream->rtp_parameters())) { 1959 if (HasSendCodec() && !SetSendCodecs(channel, stream->rtp_parameters())) {
1964 RemoveSendStream(ssrc); 1960 RemoveSendStream(ssrc);
1965 return false; 1961 return false;
1966 } 1962 }
1967 1963
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; 2240 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range.";
2245 return false; 2241 return false;
2246 } 2242 }
2247 return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration); 2243 return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration);
2248 } 2244 }
2249 2245
2250 void WebRtcVoiceMediaChannel::OnPacketReceived( 2246 void WebRtcVoiceMediaChannel::OnPacketReceived(
2251 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { 2247 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) {
2252 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2248 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2253 2249
2250 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
2251 packet_time.not_before);
2252 webrtc::PacketReceiver::DeliveryStatus delivery_result =
2253 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO,
2254 packet->cdata(), packet->size(),
2255 webrtc_packet_time);
2256
the sun 2016/04/28 09:15:56 nit: remove blank line
mflodman 2016/04/29 05:54:00 Done.
2257 if (delivery_result != webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC) {
2258 return;
2259 }
2260
2261 // Create a default receive stream for this unsignalled annd previously not
the sun 2016/04/28 09:15:56 s/annd/and
mflodman 2016/04/29 05:54:00 Done.
2262 // received ssrc. If there already is a default receive stream, delete it.
the sun 2016/04/28 09:15:56 Add: // See: https://bugs.chromium.org/p/webrtc/is
mflodman 2016/04/29 05:54:00 Done.
2254 uint32_t ssrc = 0; 2263 uint32_t ssrc = 0;
2255 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) { 2264 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) {
2256 return; 2265 return;
2257 } 2266 }
2258 2267
2259 // If we don't have a default channel, and the SSRC is unknown, create a 2268 if (default_recv_ssrc_ != -1) {
the sun 2016/04/28 09:15:56 Thanks! This logic is actually easier to follow no
mflodman 2016/04/29 05:54:00 Agree, thanks!
2260 // default channel. 2269 LOG(LS_INFO) << "Removing default receive stream with ssrc "
2261 if (default_recv_ssrc_ == -1 && GetReceiveChannelId(ssrc) == -1) { 2270 << default_recv_ssrc_;
2262 StreamParams sp; 2271 RTC_DCHECK_NE(ssrc, default_recv_ssrc_);
2263 sp.ssrcs.push_back(ssrc); 2272 RemoveRecvStream(default_recv_ssrc_);
2264 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; 2273 default_recv_ssrc_ = -1;
2265 if (!AddRecvStream(sp)) {
2266 LOG(LS_WARNING) << "Could not create default receive stream.";
2267 return;
2268 }
2269 default_recv_ssrc_ = ssrc;
2270 SetOutputVolume(default_recv_ssrc_, default_recv_volume_);
2271 if (default_sink_) {
2272 std::unique_ptr<webrtc::AudioSinkInterface> proxy_sink(
2273 new ProxySink(default_sink_.get()));
2274 SetRawAudioSink(default_recv_ssrc_, std::move(proxy_sink));
2275 }
2276 } 2274 }
2277 2275
2278 // Forward packet to Call. If the SSRC is unknown we'll return after this. 2276 StreamParams sp;
2279 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 2277 sp.ssrcs.push_back(ssrc);
2280 packet_time.not_before); 2278 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << ".";
2281 webrtc::PacketReceiver::DeliveryStatus delivery_result = 2279 if (!AddRecvStream(sp)) {
2282 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, 2280 LOG(LS_WARNING) << "Could not create default receive stream.";
2283 packet->cdata(), packet->size(), webrtc_packet_time); 2281 return;
2284 if (webrtc::PacketReceiver::DELIVERY_OK != delivery_result) {
2285 // If the SSRC is unknown here, route it to the default channel, if we have
2286 // one. See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5208
2287 if (default_recv_ssrc_ == -1) {
2288 return;
2289 } else {
2290 ssrc = default_recv_ssrc_;
2291 }
2292 } 2282 }
2293 2283 default_recv_ssrc_ = ssrc;
2294 // Find the channel to send this packet to. It must exist since webrtc::Call 2284 SetOutputVolume(default_recv_ssrc_, default_recv_volume_);
2295 // was able to demux the packet. 2285 if (default_sink_) {
2296 int channel = GetReceiveChannelId(ssrc); 2286 std::unique_ptr<webrtc::AudioSinkInterface> proxy_sink(
2297 RTC_DCHECK(channel != -1); 2287 new ProxySink(default_sink_.get()));
2298 2288 SetRawAudioSink(default_recv_ssrc_, std::move(proxy_sink));
2299 // Pass it off to the decoder. 2289 }
2300 engine()->voe()->network()->ReceivedRTPPacket( 2290 delivery_result = call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO,
2301 channel, packet->cdata(), packet->size(), webrtc_packet_time); 2291 packet->cdata(),
2292 packet->size(),
2293 webrtc_packet_time);
2294 RTC_DCHECK_NE(webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC, delivery_result);
2302 } 2295 }
2303 2296
2304 void WebRtcVoiceMediaChannel::OnRtcpReceived( 2297 void WebRtcVoiceMediaChannel::OnRtcpReceived(
2305 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { 2298 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) {
2306 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2299 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2307 2300
2308 // Forward packet to Call as well. 2301 // Forward packet to Call as well.
2309 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 2302 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
2310 packet_time.not_before); 2303 packet_time.not_before);
2311 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, 2304 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO,
2312 packet->cdata(), packet->size(), webrtc_packet_time); 2305 packet->cdata(), packet->size(), webrtc_packet_time);
2313
2314 // Sending channels need all RTCP packets with feedback information.
2315 // Even sender reports can contain attached report blocks.
2316 // Receiving channels need sender reports in order to create
2317 // correct receiver reports.
2318 int type = 0;
2319 if (!GetRtcpType(packet->cdata(), packet->size(), &type)) {
2320 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet";
2321 return;
2322 }
2323
2324 // If it is a sender report, find the receive channel that is listening.
2325 if (type == kRtcpTypeSR) {
2326 uint32_t ssrc = 0;
2327 if (!GetRtcpSsrc(packet->cdata(), packet->size(), &ssrc)) {
2328 return;
2329 }
2330 int recv_channel_id = GetReceiveChannelId(ssrc);
2331 if (recv_channel_id != -1) {
2332 engine()->voe()->network()->ReceivedRTCPPacket(
2333 recv_channel_id, packet->cdata(), packet->size());
2334 }
2335 }
2336
2337 // SR may continue RR and any RR entry may correspond to any one of the send
2338 // channels. So all RTCP packets must be forwarded all send channels. VoE
2339 // will filter out RR internally.
2340 for (const auto& ch : send_streams_) {
2341 engine()->voe()->network()->ReceivedRTCPPacket(
2342 ch.second->channel(), packet->cdata(), packet->size());
2343 }
2344 } 2306 }
2345 2307
2346 void WebRtcVoiceMediaChannel::OnNetworkRouteChanged( 2308 void WebRtcVoiceMediaChannel::OnNetworkRouteChanged(
2347 const std::string& transport_name, 2309 const std::string& transport_name,
2348 const rtc::NetworkRoute& network_route) { 2310 const rtc::NetworkRoute& network_route) {
2349 call_->OnNetworkRouteChanged(transport_name, network_route); 2311 call_->OnNetworkRouteChanged(transport_name, network_route);
2350 } 2312 }
2351 2313
2352 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { 2314 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) {
2353 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2315 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 } 2537 }
2576 } else { 2538 } else {
2577 LOG(LS_INFO) << "Stopping playout for channel #" << channel; 2539 LOG(LS_INFO) << "Stopping playout for channel #" << channel;
2578 engine()->voe()->base()->StopPlayout(channel); 2540 engine()->voe()->base()->StopPlayout(channel);
2579 } 2541 }
2580 return true; 2542 return true;
2581 } 2543 }
2582 } // namespace cricket 2544 } // namespace cricket
2583 2545
2584 #endif // HAVE_WEBRTC_VOICE 2546 #endif // HAVE_WEBRTC_VOICE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698