OLD | NEW |
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 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 } | 1088 } |
1089 | 1089 |
1090 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 1090 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
1091 : public AudioSource::Sink { | 1091 : public AudioSource::Sink { |
1092 public: | 1092 public: |
1093 WebRtcAudioSendStream(int ch, | 1093 WebRtcAudioSendStream(int ch, |
1094 webrtc::AudioTransport* voe_audio_transport, | 1094 webrtc::AudioTransport* voe_audio_transport, |
1095 uint32_t ssrc, | 1095 uint32_t ssrc, |
1096 const std::string& c_name, | 1096 const std::string& c_name, |
1097 const std::vector<webrtc::RtpExtension>& extensions, | 1097 const std::vector<webrtc::RtpExtension>& extensions, |
1098 webrtc::Call* call) | 1098 webrtc::Call* call, |
| 1099 webrtc::Transport* send_transport) |
1099 : voe_audio_transport_(voe_audio_transport), | 1100 : voe_audio_transport_(voe_audio_transport), |
1100 call_(call), | 1101 call_(call), |
1101 config_(nullptr), | 1102 config_(send_transport), |
1102 rtp_parameters_(CreateRtpParametersWithOneEncoding()) { | 1103 rtp_parameters_(CreateRtpParametersWithOneEncoding()) { |
1103 RTC_DCHECK_GE(ch, 0); | 1104 RTC_DCHECK_GE(ch, 0); |
1104 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: | 1105 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: |
1105 // RTC_DCHECK(voe_audio_transport); | 1106 // RTC_DCHECK(voe_audio_transport); |
1106 RTC_DCHECK(call); | 1107 RTC_DCHECK(call); |
1107 audio_capture_thread_checker_.DetachFromThread(); | 1108 audio_capture_thread_checker_.DetachFromThread(); |
1108 config_.rtp.ssrc = ssrc; | 1109 config_.rtp.ssrc = ssrc; |
1109 config_.rtp.c_name = c_name; | 1110 config_.rtp.c_name = c_name; |
1110 config_.voe_channel_id = ch; | 1111 config_.voe_channel_id = ch; |
1111 RecreateAudioSendStream(extensions); | 1112 RecreateAudioSendStream(extensions); |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1919 } | 1920 } |
1920 return true; | 1921 return true; |
1921 } | 1922 } |
1922 | 1923 |
1923 int WebRtcVoiceMediaChannel::CreateVoEChannel() { | 1924 int WebRtcVoiceMediaChannel::CreateVoEChannel() { |
1924 int id = engine()->CreateVoEChannel(); | 1925 int id = engine()->CreateVoEChannel(); |
1925 if (id == -1) { | 1926 if (id == -1) { |
1926 LOG_RTCERR0(CreateVoEChannel); | 1927 LOG_RTCERR0(CreateVoEChannel); |
1927 return -1; | 1928 return -1; |
1928 } | 1929 } |
1929 if (engine()->voe()->network()->RegisterExternalTransport(id, *this) == -1) { | 1930 |
1930 LOG_RTCERR2(RegisterExternalTransport, id, this); | |
1931 engine()->voe()->base()->DeleteChannel(id); | |
1932 return -1; | |
1933 } | |
1934 return id; | 1931 return id; |
1935 } | 1932 } |
1936 | 1933 |
1937 bool WebRtcVoiceMediaChannel::DeleteVoEChannel(int channel) { | 1934 bool WebRtcVoiceMediaChannel::DeleteVoEChannel(int channel) { |
1938 if (engine()->voe()->network()->DeRegisterExternalTransport(channel) == -1) { | |
1939 LOG_RTCERR1(DeRegisterExternalTransport, channel); | |
1940 } | |
1941 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { | 1935 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { |
1942 LOG_RTCERR1(DeleteChannel, channel); | 1936 LOG_RTCERR1(DeleteChannel, channel); |
1943 return false; | 1937 return false; |
1944 } | 1938 } |
1945 return true; | 1939 return true; |
1946 } | 1940 } |
1947 | 1941 |
1948 bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { | 1942 bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { |
1949 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::AddSendStream"); | 1943 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::AddSendStream"); |
1950 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1944 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
(...skipping 10 matching lines...) Expand all Loading... |
1961 // Create a new channel for sending audio data. | 1955 // Create a new channel for sending audio data. |
1962 int channel = CreateVoEChannel(); | 1956 int channel = CreateVoEChannel(); |
1963 if (channel == -1) { | 1957 if (channel == -1) { |
1964 return false; | 1958 return false; |
1965 } | 1959 } |
1966 | 1960 |
1967 // Save the channel to send_streams_, so that RemoveSendStream() can still | 1961 // Save the channel to send_streams_, so that RemoveSendStream() can still |
1968 // delete the channel in case failure happens below. | 1962 // delete the channel in case failure happens below. |
1969 webrtc::AudioTransport* audio_transport = | 1963 webrtc::AudioTransport* audio_transport = |
1970 engine()->voe()->base()->audio_transport(); | 1964 engine()->voe()->base()->audio_transport(); |
| 1965 |
1971 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( | 1966 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( |
1972 channel, audio_transport, ssrc, sp.cname, send_rtp_extensions_, call_); | 1967 channel, audio_transport, ssrc, sp.cname, send_rtp_extensions_, call_, |
| 1968 this); |
1973 send_streams_.insert(std::make_pair(ssrc, stream)); | 1969 send_streams_.insert(std::make_pair(ssrc, stream)); |
1974 | 1970 |
1975 // Set the current codecs to be used for the new channel. We need to do this | 1971 // Set the current codecs to be used for the new channel. We need to do this |
1976 // after adding the channel to send_channels_, because of how max bitrate is | 1972 // after adding the channel to send_channels_, because of how max bitrate is |
1977 // currently being configured by SetSendCodec(). | 1973 // currently being configured by SetSendCodec(). |
1978 if (HasSendCodec() && !SetSendCodecs(channel, stream->rtp_parameters())) { | 1974 if (HasSendCodec() && !SetSendCodecs(channel, stream->rtp_parameters())) { |
1979 RemoveSendStream(ssrc); | 1975 RemoveSendStream(ssrc); |
1980 return false; | 1976 return false; |
1981 } | 1977 } |
1982 | 1978 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; | 2255 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; |
2260 return false; | 2256 return false; |
2261 } | 2257 } |
2262 return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration); | 2258 return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration); |
2263 } | 2259 } |
2264 | 2260 |
2265 void WebRtcVoiceMediaChannel::OnPacketReceived( | 2261 void WebRtcVoiceMediaChannel::OnPacketReceived( |
2266 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { | 2262 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { |
2267 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2263 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2268 | 2264 |
| 2265 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
| 2266 packet_time.not_before); |
| 2267 webrtc::PacketReceiver::DeliveryStatus delivery_result = |
| 2268 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
| 2269 packet->cdata(), packet->size(), |
| 2270 webrtc_packet_time); |
| 2271 |
| 2272 if (delivery_result != webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC) { |
| 2273 return; |
| 2274 } |
| 2275 |
| 2276 // Create a default receive stream for this unsignalled and previously not |
| 2277 // received ssrc. If there already is a default receive stream, delete it. |
| 2278 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5208 |
2269 uint32_t ssrc = 0; | 2279 uint32_t ssrc = 0; |
2270 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) { | 2280 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) { |
2271 return; | 2281 return; |
2272 } | 2282 } |
2273 | 2283 |
2274 // If we don't have a default channel, and the SSRC is unknown, create a | 2284 if (default_recv_ssrc_ != -1) { |
2275 // default channel. | 2285 LOG(LS_INFO) << "Removing default receive stream with ssrc " |
2276 if (default_recv_ssrc_ == -1 && GetReceiveChannelId(ssrc) == -1) { | 2286 << default_recv_ssrc_; |
2277 StreamParams sp; | 2287 RTC_DCHECK_NE(ssrc, default_recv_ssrc_); |
2278 sp.ssrcs.push_back(ssrc); | 2288 RemoveRecvStream(default_recv_ssrc_); |
2279 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; | 2289 default_recv_ssrc_ = -1; |
2280 if (!AddRecvStream(sp)) { | |
2281 LOG(LS_WARNING) << "Could not create default receive stream."; | |
2282 return; | |
2283 } | |
2284 default_recv_ssrc_ = ssrc; | |
2285 SetOutputVolume(default_recv_ssrc_, default_recv_volume_); | |
2286 if (default_sink_) { | |
2287 std::unique_ptr<webrtc::AudioSinkInterface> proxy_sink( | |
2288 new ProxySink(default_sink_.get())); | |
2289 SetRawAudioSink(default_recv_ssrc_, std::move(proxy_sink)); | |
2290 } | |
2291 } | 2290 } |
2292 | 2291 |
2293 // Forward packet to Call. If the SSRC is unknown we'll return after this. | 2292 StreamParams sp; |
2294 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2293 sp.ssrcs.push_back(ssrc); |
2295 packet_time.not_before); | 2294 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; |
2296 webrtc::PacketReceiver::DeliveryStatus delivery_result = | 2295 if (!AddRecvStream(sp)) { |
2297 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2296 LOG(LS_WARNING) << "Could not create default receive stream."; |
2298 packet->cdata(), packet->size(), webrtc_packet_time); | 2297 return; |
2299 if (webrtc::PacketReceiver::DELIVERY_OK != delivery_result) { | |
2300 // If the SSRC is unknown here, route it to the default channel, if we have | |
2301 // one. See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5208 | |
2302 if (default_recv_ssrc_ == -1) { | |
2303 return; | |
2304 } else { | |
2305 ssrc = default_recv_ssrc_; | |
2306 } | |
2307 } | 2298 } |
2308 | 2299 default_recv_ssrc_ = ssrc; |
2309 // Find the channel to send this packet to. It must exist since webrtc::Call | 2300 SetOutputVolume(default_recv_ssrc_, default_recv_volume_); |
2310 // was able to demux the packet. | 2301 if (default_sink_) { |
2311 int channel = GetReceiveChannelId(ssrc); | 2302 std::unique_ptr<webrtc::AudioSinkInterface> proxy_sink( |
2312 RTC_DCHECK(channel != -1); | 2303 new ProxySink(default_sink_.get())); |
2313 | 2304 SetRawAudioSink(default_recv_ssrc_, std::move(proxy_sink)); |
2314 // Pass it off to the decoder. | 2305 } |
2315 engine()->voe()->network()->ReceivedRTPPacket( | 2306 delivery_result = call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2316 channel, packet->cdata(), packet->size(), webrtc_packet_time); | 2307 packet->cdata(), |
| 2308 packet->size(), |
| 2309 webrtc_packet_time); |
| 2310 RTC_DCHECK_NE(webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC, delivery_result); |
2317 } | 2311 } |
2318 | 2312 |
2319 void WebRtcVoiceMediaChannel::OnRtcpReceived( | 2313 void WebRtcVoiceMediaChannel::OnRtcpReceived( |
2320 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { | 2314 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { |
2321 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2315 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2322 | 2316 |
2323 // Forward packet to Call as well. | 2317 // Forward packet to Call as well. |
2324 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2318 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2325 packet_time.not_before); | 2319 packet_time.not_before); |
2326 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2320 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2327 packet->cdata(), packet->size(), webrtc_packet_time); | 2321 packet->cdata(), packet->size(), webrtc_packet_time); |
2328 | |
2329 // Sending channels need all RTCP packets with feedback information. | |
2330 // Even sender reports can contain attached report blocks. | |
2331 // Receiving channels need sender reports in order to create | |
2332 // correct receiver reports. | |
2333 int type = 0; | |
2334 if (!GetRtcpType(packet->cdata(), packet->size(), &type)) { | |
2335 LOG(LS_WARNING) << "Failed to parse type from received RTCP packet"; | |
2336 return; | |
2337 } | |
2338 | |
2339 // If it is a sender report, find the receive channel that is listening. | |
2340 if (type == kRtcpTypeSR) { | |
2341 uint32_t ssrc = 0; | |
2342 if (!GetRtcpSsrc(packet->cdata(), packet->size(), &ssrc)) { | |
2343 return; | |
2344 } | |
2345 int recv_channel_id = GetReceiveChannelId(ssrc); | |
2346 if (recv_channel_id != -1) { | |
2347 engine()->voe()->network()->ReceivedRTCPPacket( | |
2348 recv_channel_id, packet->cdata(), packet->size()); | |
2349 } | |
2350 } | |
2351 | |
2352 // SR may continue RR and any RR entry may correspond to any one of the send | |
2353 // channels. So all RTCP packets must be forwarded all send channels. VoE | |
2354 // will filter out RR internally. | |
2355 for (const auto& ch : send_streams_) { | |
2356 engine()->voe()->network()->ReceivedRTCPPacket( | |
2357 ch.second->channel(), packet->cdata(), packet->size()); | |
2358 } | |
2359 } | 2322 } |
2360 | 2323 |
2361 void WebRtcVoiceMediaChannel::OnNetworkRouteChanged( | 2324 void WebRtcVoiceMediaChannel::OnNetworkRouteChanged( |
2362 const std::string& transport_name, | 2325 const std::string& transport_name, |
2363 const rtc::NetworkRoute& network_route) { | 2326 const rtc::NetworkRoute& network_route) { |
2364 call_->OnNetworkRouteChanged(transport_name, network_route); | 2327 call_->OnNetworkRouteChanged(transport_name, network_route); |
2365 } | 2328 } |
2366 | 2329 |
2367 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { | 2330 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { |
2368 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2331 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2594 } | 2557 } |
2595 } else { | 2558 } else { |
2596 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2559 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
2597 engine()->voe()->base()->StopPlayout(channel); | 2560 engine()->voe()->base()->StopPlayout(channel); |
2598 } | 2561 } |
2599 return true; | 2562 return true; |
2600 } | 2563 } |
2601 } // namespace cricket | 2564 } // namespace cricket |
2602 | 2565 |
2603 #endif // HAVE_WEBRTC_VOICE | 2566 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |