Chromium Code Reviews| 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 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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(), | |
| 
 
tommi
2016/04/23 16:00:09
I'd really like DeliverPacket to use rtc::CopyOnWr
 
mflodman
2016/04/27 13:42:17
SG without really looking into it. That should be
 
 | |
| 2255 webrtc_packet_time); | |
| 2256 | |
| 
 
the sun
2016/04/22 12:40:31
nit: delete line
 
mflodman
2016/04/27 13:42:17
Done.
 
 | |
| 2257 if (delivery_result != webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC) { | |
| 2258 return; | |
| 2259 } | |
| 2260 | |
| 2261 // Not a recognized ssrc, try if this is a match for the default channel. | |
| 2254 uint32_t ssrc = 0; | 2262 uint32_t ssrc = 0; | 
| 2255 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) { | 2263 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) { | 
| 2256 return; | 2264 return; | 
| 2257 } | 2265 } | 
| 2258 | 2266 | 
| 2267 if (default_recv_ssrc_ != -1) { | |
| 2268 LOG(LS_WARNING) << "Received unsignalled SSRC=" << ssrc << | |
| 2269 ", which doesn't match previous default ssrc."; | |
| 2270 return; | |
| 2271 } | |
| 2272 | |
| 2259 // If we don't have a default channel, and the SSRC is unknown, create a | 2273 // If we don't have a default channel, and the SSRC is unknown, create a | 
| 2260 // default channel. | 2274 // default channel. | 
| 2261 if (default_recv_ssrc_ == -1 && GetReceiveChannelId(ssrc) == -1) { | 2275 StreamParams sp; | 
| 2262 StreamParams sp; | 2276 sp.ssrcs.push_back(ssrc); | 
| 2263 sp.ssrcs.push_back(ssrc); | 2277 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; | 
| 2264 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; | 2278 if (!AddRecvStream(sp)) { | 
| 2265 if (!AddRecvStream(sp)) { | 2279 LOG(LS_WARNING) << "Could not create default receive stream."; | 
| 2266 LOG(LS_WARNING) << "Could not create default receive stream."; | 2280 return; | 
| 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 } | 2281 } | 
| 2277 | 2282 default_recv_ssrc_ = ssrc; | 
| 2278 // Forward packet to Call. If the SSRC is unknown we'll return after this. | 2283 SetOutputVolume(default_recv_ssrc_, default_recv_volume_); | 
| 2279 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2284 if (default_sink_) { | 
| 2280 packet_time.not_before); | 2285 std::unique_ptr<webrtc::AudioSinkInterface> proxy_sink( | 
| 2281 webrtc::PacketReceiver::DeliveryStatus delivery_result = | 2286 new ProxySink(default_sink_.get())); | 
| 2282 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2287 SetRawAudioSink(default_recv_ssrc_, std::move(proxy_sink)); | 
| 2283 packet->cdata(), packet->size(), webrtc_packet_time); | |
| 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 } | 2288 } | 
| 2293 | 2289 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 
| 
 
the sun
2016/04/22 12:40:31
RTC_DCHECK_NE(webrtc::PacketReceiver::DELIVERY_UNK
 
mflodman
2016/04/27 13:42:17
Done.
 
 | |
| 2294 // Find the channel to send this packet to. It must exist since webrtc::Call | 2290 packet->cdata(), | 
| 2295 // was able to demux the packet. | 2291 packet->size(), | 
| 2296 int channel = GetReceiveChannelId(ssrc); | 2292 webrtc_packet_time); | 
| 2297 RTC_DCHECK(channel != -1); | |
| 2298 | |
| 2299 // Pass it off to the decoder. | |
| 2300 engine()->voe()->network()->ReceivedRTPPacket( | |
| 2301 channel, packet->cdata(), packet->size(), webrtc_packet_time); | |
| 2302 } | 2293 } | 
| 2303 | 2294 | 
| 2304 void WebRtcVoiceMediaChannel::OnRtcpReceived( | 2295 void WebRtcVoiceMediaChannel::OnRtcpReceived( | 
| 2305 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { | 2296 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { | 
| 2306 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2297 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| 2307 | 2298 | 
| 2308 // Forward packet to Call as well. | 2299 // Forward packet to Call as well. | 
| 2309 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2300 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 
| 2310 packet_time.not_before); | 2301 packet_time.not_before); | 
| 2311 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2302 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 
| 2312 packet->cdata(), packet->size(), webrtc_packet_time); | 2303 packet->cdata(), packet->size(), webrtc_packet_time); | 
| 2313 | |
| 2314 // Sending channels need all RTCP packets with feedback information. | |
| 
 
the sun
2016/04/22 12:40:31
You're certain that the proper filtering of SR/RR
 
mflodman
2016/04/27 13:42:17
That's how it's always been done fore video, so th
 
 | |
| 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 } | 2304 } | 
| 2345 | 2305 | 
| 2346 void WebRtcVoiceMediaChannel::OnNetworkRouteChanged( | 2306 void WebRtcVoiceMediaChannel::OnNetworkRouteChanged( | 
| 2347 const std::string& transport_name, | 2307 const std::string& transport_name, | 
| 2348 const rtc::NetworkRoute& network_route) { | 2308 const rtc::NetworkRoute& network_route) { | 
| 2349 call_->OnNetworkRouteChanged(transport_name, network_route); | 2309 call_->OnNetworkRouteChanged(transport_name, network_route); | 
| 2350 } | 2310 } | 
| 2351 | 2311 | 
| 2352 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { | 2312 bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { | 
| 2353 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2313 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2575 } | 2535 } | 
| 2576 } else { | 2536 } else { | 
| 2577 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2537 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 
| 2578 engine()->voe()->base()->StopPlayout(channel); | 2538 engine()->voe()->base()->StopPlayout(channel); | 
| 2579 } | 2539 } | 
| 2580 return true; | 2540 return true; | 
| 2581 } | 2541 } | 
| 2582 } // namespace cricket | 2542 } // namespace cricket | 
| 2583 | 2543 | 
| 2584 #endif // HAVE_WEBRTC_VOICE | 2544 #endif // HAVE_WEBRTC_VOICE | 
| OLD | NEW |