OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 enum { | 64 enum { |
65 MSG_EARLYMEDIATIMEOUT = 1, | 65 MSG_EARLYMEDIATIMEOUT = 1, |
66 MSG_SEND_RTP_PACKET, | 66 MSG_SEND_RTP_PACKET, |
67 MSG_SEND_RTCP_PACKET, | 67 MSG_SEND_RTCP_PACKET, |
68 MSG_CHANNEL_ERROR, | 68 MSG_CHANNEL_ERROR, |
69 MSG_READYTOSENDDATA, | 69 MSG_READYTOSENDDATA, |
70 MSG_DATARECEIVED, | 70 MSG_DATARECEIVED, |
71 MSG_FIRSTPACKETRECEIVED, | 71 MSG_FIRSTPACKETRECEIVED, |
| 72 MSG_STREAMCLOSEDREMOTELY, |
72 }; | 73 }; |
73 | 74 |
74 // Value specified in RFC 5764. | 75 // Value specified in RFC 5764. |
75 static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp"; | 76 static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp"; |
76 | 77 |
77 static const int kAgcMinus10db = -10; | 78 static const int kAgcMinus10db = -10; |
78 | 79 |
79 static void SafeSetError(const std::string& message, std::string* error_desc) { | 80 static void SafeSetError(const std::string& message, std::string* error_desc) { |
80 if (error_desc) { | 81 if (error_desc) { |
81 *error_desc = message; | 82 *error_desc = message; |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 << selected_candidate_pair_->local_candidate().ToSensitiveString() | 924 << selected_candidate_pair_->local_candidate().ToSensitiveString() |
924 << "->" | 925 << "->" |
925 << selected_candidate_pair_->remote_candidate().ToSensitiveString(); | 926 << selected_candidate_pair_->remote_candidate().ToSensitiveString(); |
926 | 927 |
927 was_ever_writable_ = true; | 928 was_ever_writable_ = true; |
928 MaybeSetupDtlsSrtp_n(); | 929 MaybeSetupDtlsSrtp_n(); |
929 writable_ = true; | 930 writable_ = true; |
930 UpdateMediaSendRecvState(); | 931 UpdateMediaSendRecvState(); |
931 } | 932 } |
932 | 933 |
933 void BaseChannel::SignalDtlsSrtpSetupFailure_n(bool rtcp) { | 934 void BaseChannel::SignalDtlsSetupFailure_n(bool rtcp) { |
934 RTC_DCHECK(network_thread_->IsCurrent()); | 935 RTC_DCHECK(network_thread_->IsCurrent()); |
935 invoker_.AsyncInvoke<void>( | 936 invoker_.AsyncInvoke<void>( |
936 RTC_FROM_HERE, signaling_thread(), | 937 RTC_FROM_HERE, signaling_thread(), |
937 Bind(&BaseChannel::SignalDtlsSrtpSetupFailure_s, this, rtcp)); | 938 Bind(&BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); |
938 } | 939 } |
939 | 940 |
940 void BaseChannel::SignalDtlsSrtpSetupFailure_s(bool rtcp) { | 941 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { |
941 RTC_DCHECK(signaling_thread() == rtc::Thread::Current()); | 942 RTC_DCHECK(signaling_thread() == rtc::Thread::Current()); |
942 SignalDtlsSrtpSetupFailure(this, rtcp); | 943 SignalDtlsSetupFailure(this, rtcp); |
943 } | 944 } |
944 | 945 |
945 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) { | 946 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) { |
946 std::vector<int> crypto_suites; | 947 std::vector<int> crypto_suites; |
947 // We always use the default SRTP crypto suites for RTCP, but we may use | 948 // We always use the default SRTP crypto suites for RTCP, but we may use |
948 // different crypto suites for RTP depending on the media type. | 949 // different crypto suites for RTP depending on the media type. |
949 if (!rtcp) { | 950 if (!rtcp) { |
950 GetSrtpCryptoSuites_n(&crypto_suites); | 951 GetSrtpCryptoSuites_n(&crypto_suites); |
951 } else { | 952 } else { |
952 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); | 953 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 void BaseChannel::MaybeSetupDtlsSrtp_n() { | 1054 void BaseChannel::MaybeSetupDtlsSrtp_n() { |
1054 if (srtp_filter_.IsActive()) { | 1055 if (srtp_filter_.IsActive()) { |
1055 return; | 1056 return; |
1056 } | 1057 } |
1057 | 1058 |
1058 if (!ShouldSetupDtlsSrtp_n()) { | 1059 if (!ShouldSetupDtlsSrtp_n()) { |
1059 return; | 1060 return; |
1060 } | 1061 } |
1061 | 1062 |
1062 if (!SetupDtlsSrtp_n(false)) { | 1063 if (!SetupDtlsSrtp_n(false)) { |
1063 SignalDtlsSrtpSetupFailure_n(false); | 1064 SignalDtlsSetupFailure_n(false); |
1064 return; | 1065 return; |
1065 } | 1066 } |
1066 | 1067 |
1067 if (rtcp_transport_channel_) { | 1068 if (rtcp_transport_channel_) { |
1068 if (!SetupDtlsSrtp_n(true)) { | 1069 if (!SetupDtlsSrtp_n(true)) { |
1069 SignalDtlsSrtpSetupFailure_n(true); | 1070 SignalDtlsSetupFailure_n(true); |
1070 return; | 1071 return; |
1071 } | 1072 } |
1072 } | 1073 } |
1073 } | 1074 } |
1074 | 1075 |
1075 void BaseChannel::ChannelNotWritable_n() { | 1076 void BaseChannel::ChannelNotWritable_n() { |
1076 RTC_DCHECK(network_thread_->IsCurrent()); | 1077 RTC_DCHECK(network_thread_->IsCurrent()); |
1077 if (!writable_) | 1078 if (!writable_) |
1078 return; | 1079 return; |
1079 | 1080 |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2139 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { | 2140 VideoMediaChannel* media_channel, const VideoMediaInfo &info) { |
2140 RTC_DCHECK(media_channel == this->media_channel()); | 2141 RTC_DCHECK(media_channel == this->media_channel()); |
2141 SignalMediaMonitor(this, info); | 2142 SignalMediaMonitor(this, info); |
2142 } | 2143 } |
2143 | 2144 |
2144 void VideoChannel::GetSrtpCryptoSuites_n( | 2145 void VideoChannel::GetSrtpCryptoSuites_n( |
2145 std::vector<int>* crypto_suites) const { | 2146 std::vector<int>* crypto_suites) const { |
2146 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); | 2147 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); |
2147 } | 2148 } |
2148 | 2149 |
2149 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread, | 2150 DataChannel::DataChannel(rtc::Thread* worker_thread, |
2150 rtc::Thread* network_thread, | 2151 rtc::Thread* network_thread, |
2151 DataMediaChannel* media_channel, | 2152 DataMediaChannel* media_channel, |
2152 TransportController* transport_controller, | 2153 TransportController* transport_controller, |
2153 const std::string& content_name, | 2154 const std::string& content_name, |
2154 bool rtcp, | 2155 bool rtcp, |
2155 bool srtp_required) | 2156 bool srtp_required) |
2156 : BaseChannel(worker_thread, | 2157 : BaseChannel(worker_thread, |
2157 network_thread, | 2158 network_thread, |
2158 media_channel, | 2159 media_channel, |
2159 transport_controller, | 2160 transport_controller, |
2160 content_name, | 2161 content_name, |
2161 rtcp, | 2162 rtcp, |
2162 srtp_required) {} | 2163 srtp_required), |
| 2164 data_channel_type_(cricket::DCT_NONE), |
| 2165 ready_to_send_data_(false) {} |
2163 | 2166 |
2164 RtpDataChannel::~RtpDataChannel() { | 2167 DataChannel::~DataChannel() { |
2165 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); | 2168 TRACE_EVENT0("webrtc", "DataChannel::~DataChannel"); |
2166 StopMediaMonitor(); | 2169 StopMediaMonitor(); |
2167 // this can't be done in the base class, since it calls a virtual | 2170 // this can't be done in the base class, since it calls a virtual |
2168 DisableMedia_w(); | 2171 DisableMedia_w(); |
2169 | 2172 |
2170 Deinit(); | 2173 Deinit(); |
2171 } | 2174 } |
2172 | 2175 |
2173 bool RtpDataChannel::Init_w(const std::string* bundle_transport_name) { | 2176 bool DataChannel::Init_w(const std::string* bundle_transport_name) { |
2174 if (!BaseChannel::Init_w(bundle_transport_name)) { | 2177 if (!BaseChannel::Init_w(bundle_transport_name)) { |
2175 return false; | 2178 return false; |
2176 } | 2179 } |
2177 media_channel()->SignalDataReceived.connect(this, | 2180 media_channel()->SignalDataReceived.connect( |
2178 &RtpDataChannel::OnDataReceived); | 2181 this, &DataChannel::OnDataReceived); |
2179 media_channel()->SignalReadyToSend.connect( | 2182 media_channel()->SignalReadyToSend.connect( |
2180 this, &RtpDataChannel::OnDataChannelReadyToSend); | 2183 this, &DataChannel::OnDataChannelReadyToSend); |
| 2184 media_channel()->SignalStreamClosedRemotely.connect( |
| 2185 this, &DataChannel::OnStreamClosedRemotely); |
2181 return true; | 2186 return true; |
2182 } | 2187 } |
2183 | 2188 |
2184 bool RtpDataChannel::SendData(const SendDataParams& params, | 2189 bool DataChannel::SendData(const SendDataParams& params, |
2185 const rtc::CopyOnWriteBuffer& payload, | 2190 const rtc::CopyOnWriteBuffer& payload, |
2186 SendDataResult* result) { | 2191 SendDataResult* result) { |
2187 return InvokeOnWorker( | 2192 return InvokeOnWorker( |
2188 RTC_FROM_HERE, Bind(&DataMediaChannel::SendData, media_channel(), params, | 2193 RTC_FROM_HERE, Bind(&DataMediaChannel::SendData, media_channel(), params, |
2189 payload, result)); | 2194 payload, result)); |
2190 } | 2195 } |
2191 | 2196 |
2192 const ContentInfo* RtpDataChannel::GetFirstContent( | 2197 const ContentInfo* DataChannel::GetFirstContent( |
2193 const SessionDescription* sdesc) { | 2198 const SessionDescription* sdesc) { |
2194 return GetFirstDataContent(sdesc); | 2199 return GetFirstDataContent(sdesc); |
2195 } | 2200 } |
2196 | 2201 |
2197 bool RtpDataChannel::CheckDataChannelTypeFromContent( | 2202 bool DataChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { |
| 2203 if (data_channel_type_ == DCT_SCTP) { |
| 2204 // TODO(pthatcher): Do this in a more robust way by checking for |
| 2205 // SCTP or DTLS. |
| 2206 return !IsRtpPacket(packet->data(), packet->size()); |
| 2207 } else if (data_channel_type_ == DCT_RTP) { |
| 2208 return BaseChannel::WantsPacket(rtcp, packet); |
| 2209 } |
| 2210 return false; |
| 2211 } |
| 2212 |
| 2213 bool DataChannel::SetDataChannelType(DataChannelType new_data_channel_type, |
| 2214 std::string* error_desc) { |
| 2215 // It hasn't been set before, so set it now. |
| 2216 if (data_channel_type_ == DCT_NONE) { |
| 2217 data_channel_type_ = new_data_channel_type; |
| 2218 return true; |
| 2219 } |
| 2220 |
| 2221 // It's been set before, but doesn't match. That's bad. |
| 2222 if (data_channel_type_ != new_data_channel_type) { |
| 2223 std::ostringstream desc; |
| 2224 desc << "Data channel type mismatch." |
| 2225 << " Expected " << data_channel_type_ |
| 2226 << " Got " << new_data_channel_type; |
| 2227 SafeSetError(desc.str(), error_desc); |
| 2228 return false; |
| 2229 } |
| 2230 |
| 2231 // It's hasn't changed. Nothing to do. |
| 2232 return true; |
| 2233 } |
| 2234 |
| 2235 bool DataChannel::SetDataChannelTypeFromContent( |
2198 const DataContentDescription* content, | 2236 const DataContentDescription* content, |
2199 std::string* error_desc) { | 2237 std::string* error_desc) { |
2200 bool is_sctp = ((content->protocol() == kMediaProtocolSctp) || | 2238 bool is_sctp = ((content->protocol() == kMediaProtocolSctp) || |
2201 (content->protocol() == kMediaProtocolDtlsSctp)); | 2239 (content->protocol() == kMediaProtocolDtlsSctp)); |
2202 // It's been set before, but doesn't match. That's bad. | 2240 DataChannelType data_channel_type = is_sctp ? DCT_SCTP : DCT_RTP; |
2203 if (is_sctp) { | 2241 return SetDataChannelType(data_channel_type, error_desc); |
2204 SafeSetError("Data channel type mismatch. Expected RTP, got SCTP.", | |
2205 error_desc); | |
2206 return false; | |
2207 } | |
2208 return true; | |
2209 } | 2242 } |
2210 | 2243 |
2211 bool RtpDataChannel::SetLocalContent_w(const MediaContentDescription* content, | 2244 bool DataChannel::SetLocalContent_w(const MediaContentDescription* content, |
2212 ContentAction action, | 2245 ContentAction action, |
2213 std::string* error_desc) { | 2246 std::string* error_desc) { |
2214 TRACE_EVENT0("webrtc", "RtpDataChannel::SetLocalContent_w"); | 2247 TRACE_EVENT0("webrtc", "DataChannel::SetLocalContent_w"); |
2215 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); | 2248 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); |
2216 LOG(LS_INFO) << "Setting local data description"; | 2249 LOG(LS_INFO) << "Setting local data description"; |
2217 | 2250 |
2218 const DataContentDescription* data = | 2251 const DataContentDescription* data = |
2219 static_cast<const DataContentDescription*>(content); | 2252 static_cast<const DataContentDescription*>(content); |
2220 RTC_DCHECK(data != NULL); | 2253 RTC_DCHECK(data != NULL); |
2221 if (!data) { | 2254 if (!data) { |
2222 SafeSetError("Can't find data content in local description.", error_desc); | 2255 SafeSetError("Can't find data content in local description.", error_desc); |
2223 return false; | 2256 return false; |
2224 } | 2257 } |
2225 | 2258 |
2226 if (!CheckDataChannelTypeFromContent(data, error_desc)) { | 2259 if (!SetDataChannelTypeFromContent(data, error_desc)) { |
2227 return false; | 2260 return false; |
2228 } | 2261 } |
2229 | 2262 |
2230 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { | 2263 if (data_channel_type_ == DCT_RTP) { |
2231 return false; | 2264 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { |
| 2265 return false; |
| 2266 } |
2232 } | 2267 } |
2233 | 2268 |
| 2269 // FYI: We send the SCTP port number (not to be confused with the |
| 2270 // underlying UDP port number) as a codec parameter. So even SCTP |
| 2271 // data channels need codecs. |
2234 DataRecvParameters recv_params = last_recv_params_; | 2272 DataRecvParameters recv_params = last_recv_params_; |
2235 RtpParametersFromMediaDescription(data, &recv_params); | 2273 RtpParametersFromMediaDescription(data, &recv_params); |
2236 if (!media_channel()->SetRecvParameters(recv_params)) { | 2274 if (!media_channel()->SetRecvParameters(recv_params)) { |
2237 SafeSetError("Failed to set remote data description recv parameters.", | 2275 SafeSetError("Failed to set remote data description recv parameters.", |
2238 error_desc); | 2276 error_desc); |
2239 return false; | 2277 return false; |
2240 } | 2278 } |
2241 for (const DataCodec& codec : data->codecs()) { | 2279 if (data_channel_type_ == DCT_RTP) { |
2242 bundle_filter()->AddPayloadType(codec.id); | 2280 for (const DataCodec& codec : data->codecs()) { |
| 2281 bundle_filter()->AddPayloadType(codec.id); |
| 2282 } |
2243 } | 2283 } |
2244 last_recv_params_ = recv_params; | 2284 last_recv_params_ = recv_params; |
2245 | 2285 |
2246 // TODO(pthatcher): Move local streams into DataSendParameters, and | 2286 // TODO(pthatcher): Move local streams into DataSendParameters, and |
2247 // only give it to the media channel once we have a remote | 2287 // only give it to the media channel once we have a remote |
2248 // description too (without a remote description, we won't be able | 2288 // description too (without a remote description, we won't be able |
2249 // to send them anyway). | 2289 // to send them anyway). |
2250 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { | 2290 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { |
2251 SafeSetError("Failed to set local data description streams.", error_desc); | 2291 SafeSetError("Failed to set local data description streams.", error_desc); |
2252 return false; | 2292 return false; |
2253 } | 2293 } |
2254 | 2294 |
2255 set_local_content_direction(content->direction()); | 2295 set_local_content_direction(content->direction()); |
2256 UpdateMediaSendRecvState_w(); | 2296 UpdateMediaSendRecvState_w(); |
2257 return true; | 2297 return true; |
2258 } | 2298 } |
2259 | 2299 |
2260 bool RtpDataChannel::SetRemoteContent_w(const MediaContentDescription* content, | 2300 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, |
2261 ContentAction action, | 2301 ContentAction action, |
2262 std::string* error_desc) { | 2302 std::string* error_desc) { |
2263 TRACE_EVENT0("webrtc", "RtpDataChannel::SetRemoteContent_w"); | 2303 TRACE_EVENT0("webrtc", "DataChannel::SetRemoteContent_w"); |
2264 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); | 2304 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); |
2265 | 2305 |
2266 const DataContentDescription* data = | 2306 const DataContentDescription* data = |
2267 static_cast<const DataContentDescription*>(content); | 2307 static_cast<const DataContentDescription*>(content); |
2268 RTC_DCHECK(data != NULL); | 2308 RTC_DCHECK(data != NULL); |
2269 if (!data) { | 2309 if (!data) { |
2270 SafeSetError("Can't find data content in remote description.", error_desc); | 2310 SafeSetError("Can't find data content in remote description.", error_desc); |
2271 return false; | 2311 return false; |
2272 } | 2312 } |
2273 | 2313 |
2274 // If the remote data doesn't have codecs and isn't an update, it | 2314 // If the remote data doesn't have codecs and isn't an update, it |
2275 // must be empty, so ignore it. | 2315 // must be empty, so ignore it. |
2276 if (!data->has_codecs() && action != CA_UPDATE) { | 2316 if (!data->has_codecs() && action != CA_UPDATE) { |
2277 return true; | 2317 return true; |
2278 } | 2318 } |
2279 | 2319 |
2280 if (!CheckDataChannelTypeFromContent(data, error_desc)) { | 2320 if (!SetDataChannelTypeFromContent(data, error_desc)) { |
2281 return false; | 2321 return false; |
2282 } | 2322 } |
2283 | 2323 |
2284 LOG(LS_INFO) << "Setting remote data description"; | 2324 LOG(LS_INFO) << "Setting remote data description"; |
2285 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { | 2325 if (data_channel_type_ == DCT_RTP && |
| 2326 !SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { |
2286 return false; | 2327 return false; |
2287 } | 2328 } |
2288 | 2329 |
| 2330 |
2289 DataSendParameters send_params = last_send_params_; | 2331 DataSendParameters send_params = last_send_params_; |
2290 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); | 2332 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); |
2291 if (!media_channel()->SetSendParameters(send_params)) { | 2333 if (!media_channel()->SetSendParameters(send_params)) { |
2292 SafeSetError("Failed to set remote data description send parameters.", | 2334 SafeSetError("Failed to set remote data description send parameters.", |
2293 error_desc); | 2335 error_desc); |
2294 return false; | 2336 return false; |
2295 } | 2337 } |
2296 last_send_params_ = send_params; | 2338 last_send_params_ = send_params; |
2297 | 2339 |
2298 // TODO(pthatcher): Move remote streams into DataRecvParameters, | 2340 // TODO(pthatcher): Move remote streams into DataRecvParameters, |
2299 // and only give it to the media channel once we have a local | 2341 // and only give it to the media channel once we have a local |
2300 // description too (without a local description, we won't be able to | 2342 // description too (without a local description, we won't be able to |
2301 // recv them anyway). | 2343 // recv them anyway). |
2302 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { | 2344 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { |
2303 SafeSetError("Failed to set remote data description streams.", | 2345 SafeSetError("Failed to set remote data description streams.", |
2304 error_desc); | 2346 error_desc); |
2305 return false; | 2347 return false; |
2306 } | 2348 } |
2307 | 2349 |
2308 set_remote_content_direction(content->direction()); | 2350 set_remote_content_direction(content->direction()); |
2309 UpdateMediaSendRecvState_w(); | 2351 UpdateMediaSendRecvState_w(); |
2310 return true; | 2352 return true; |
2311 } | 2353 } |
2312 | 2354 |
2313 void RtpDataChannel::UpdateMediaSendRecvState_w() { | 2355 void DataChannel::UpdateMediaSendRecvState_w() { |
2314 // Render incoming data if we're the active call, and we have the local | 2356 // Render incoming data if we're the active call, and we have the local |
2315 // content. We receive data on the default channel and multiplexed streams. | 2357 // content. We receive data on the default channel and multiplexed streams. |
2316 bool recv = IsReadyToReceiveMedia_w(); | 2358 bool recv = IsReadyToReceiveMedia_w(); |
2317 if (!media_channel()->SetReceive(recv)) { | 2359 if (!media_channel()->SetReceive(recv)) { |
2318 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; | 2360 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; |
2319 } | 2361 } |
2320 | 2362 |
2321 // Send outgoing data if we're the active call, we have the remote content, | 2363 // Send outgoing data if we're the active call, we have the remote content, |
2322 // and we have had some form of connectivity. | 2364 // and we have had some form of connectivity. |
2323 bool send = IsReadyToSendMedia_w(); | 2365 bool send = IsReadyToSendMedia_w(); |
2324 if (!media_channel()->SetSend(send)) { | 2366 if (!media_channel()->SetSend(send)) { |
2325 LOG(LS_ERROR) << "Failed to SetSend on data channel"; | 2367 LOG(LS_ERROR) << "Failed to SetSend on data channel"; |
2326 } | 2368 } |
2327 | 2369 |
2328 // Trigger SignalReadyToSendData asynchronously. | 2370 // Trigger SignalReadyToSendData asynchronously. |
2329 OnDataChannelReadyToSend(send); | 2371 OnDataChannelReadyToSend(send); |
2330 | 2372 |
2331 LOG(LS_INFO) << "Changing data state, recv=" << recv << " send=" << send; | 2373 LOG(LS_INFO) << "Changing data state, recv=" << recv << " send=" << send; |
2332 } | 2374 } |
2333 | 2375 |
2334 void RtpDataChannel::OnMessage(rtc::Message* pmsg) { | 2376 void DataChannel::OnMessage(rtc::Message *pmsg) { |
2335 switch (pmsg->message_id) { | 2377 switch (pmsg->message_id) { |
2336 case MSG_READYTOSENDDATA: { | 2378 case MSG_READYTOSENDDATA: { |
2337 DataChannelReadyToSendMessageData* data = | 2379 DataChannelReadyToSendMessageData* data = |
2338 static_cast<DataChannelReadyToSendMessageData*>(pmsg->pdata); | 2380 static_cast<DataChannelReadyToSendMessageData*>(pmsg->pdata); |
2339 ready_to_send_data_ = data->data(); | 2381 ready_to_send_data_ = data->data(); |
2340 SignalReadyToSendData(ready_to_send_data_); | 2382 SignalReadyToSendData(ready_to_send_data_); |
2341 delete data; | 2383 delete data; |
2342 break; | 2384 break; |
2343 } | 2385 } |
2344 case MSG_DATARECEIVED: { | 2386 case MSG_DATARECEIVED: { |
2345 DataReceivedMessageData* data = | 2387 DataReceivedMessageData* data = |
2346 static_cast<DataReceivedMessageData*>(pmsg->pdata); | 2388 static_cast<DataReceivedMessageData*>(pmsg->pdata); |
2347 SignalDataReceived(data->params, data->payload); | 2389 SignalDataReceived(this, data->params, data->payload); |
2348 delete data; | 2390 delete data; |
2349 break; | 2391 break; |
2350 } | 2392 } |
2351 case MSG_CHANNEL_ERROR: { | 2393 case MSG_CHANNEL_ERROR: { |
2352 const DataChannelErrorMessageData* data = | 2394 const DataChannelErrorMessageData* data = |
2353 static_cast<DataChannelErrorMessageData*>(pmsg->pdata); | 2395 static_cast<DataChannelErrorMessageData*>(pmsg->pdata); |
2354 delete data; | 2396 delete data; |
2355 break; | 2397 break; |
2356 } | 2398 } |
| 2399 case MSG_STREAMCLOSEDREMOTELY: { |
| 2400 rtc::TypedMessageData<uint32_t>* data = |
| 2401 static_cast<rtc::TypedMessageData<uint32_t>*>(pmsg->pdata); |
| 2402 SignalStreamClosedRemotely(data->data()); |
| 2403 delete data; |
| 2404 break; |
| 2405 } |
2357 default: | 2406 default: |
2358 BaseChannel::OnMessage(pmsg); | 2407 BaseChannel::OnMessage(pmsg); |
2359 break; | 2408 break; |
2360 } | 2409 } |
2361 } | 2410 } |
2362 | 2411 |
2363 void RtpDataChannel::OnConnectionMonitorUpdate( | 2412 void DataChannel::OnConnectionMonitorUpdate( |
2364 ConnectionMonitor* monitor, | 2413 ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos) { |
2365 const std::vector<ConnectionInfo>& infos) { | |
2366 SignalConnectionMonitor(this, infos); | 2414 SignalConnectionMonitor(this, infos); |
2367 } | 2415 } |
2368 | 2416 |
2369 void RtpDataChannel::StartMediaMonitor(int cms) { | 2417 void DataChannel::StartMediaMonitor(int cms) { |
2370 media_monitor_.reset(new DataMediaMonitor(media_channel(), worker_thread(), | 2418 media_monitor_.reset(new DataMediaMonitor(media_channel(), worker_thread(), |
2371 rtc::Thread::Current())); | 2419 rtc::Thread::Current())); |
2372 media_monitor_->SignalUpdate.connect(this, | 2420 media_monitor_->SignalUpdate.connect( |
2373 &RtpDataChannel::OnMediaMonitorUpdate); | 2421 this, &DataChannel::OnMediaMonitorUpdate); |
2374 media_monitor_->Start(cms); | 2422 media_monitor_->Start(cms); |
2375 } | 2423 } |
2376 | 2424 |
2377 void RtpDataChannel::StopMediaMonitor() { | 2425 void DataChannel::StopMediaMonitor() { |
2378 if (media_monitor_) { | 2426 if (media_monitor_) { |
2379 media_monitor_->Stop(); | 2427 media_monitor_->Stop(); |
2380 media_monitor_->SignalUpdate.disconnect(this); | 2428 media_monitor_->SignalUpdate.disconnect(this); |
2381 media_monitor_.reset(); | 2429 media_monitor_.reset(); |
2382 } | 2430 } |
2383 } | 2431 } |
2384 | 2432 |
2385 void RtpDataChannel::OnMediaMonitorUpdate(DataMediaChannel* media_channel, | 2433 void DataChannel::OnMediaMonitorUpdate( |
2386 const DataMediaInfo& info) { | 2434 DataMediaChannel* media_channel, const DataMediaInfo& info) { |
2387 RTC_DCHECK(media_channel == this->media_channel()); | 2435 RTC_DCHECK(media_channel == this->media_channel()); |
2388 SignalMediaMonitor(this, info); | 2436 SignalMediaMonitor(this, info); |
2389 } | 2437 } |
2390 | 2438 |
2391 void RtpDataChannel::OnDataReceived(const ReceiveDataParams& params, | 2439 void DataChannel::OnDataReceived( |
2392 const char* data, | 2440 const ReceiveDataParams& params, const char* data, size_t len) { |
2393 size_t len) { | |
2394 DataReceivedMessageData* msg = new DataReceivedMessageData( | 2441 DataReceivedMessageData* msg = new DataReceivedMessageData( |
2395 params, data, len); | 2442 params, data, len); |
2396 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_DATARECEIVED, msg); | 2443 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_DATARECEIVED, msg); |
2397 } | 2444 } |
2398 | 2445 |
2399 void RtpDataChannel::OnDataChannelError(uint32_t ssrc, | 2446 void DataChannel::OnDataChannelError(uint32_t ssrc, |
2400 DataMediaChannel::Error err) { | 2447 DataMediaChannel::Error err) { |
2401 DataChannelErrorMessageData* data = new DataChannelErrorMessageData( | 2448 DataChannelErrorMessageData* data = new DataChannelErrorMessageData( |
2402 ssrc, err); | 2449 ssrc, err); |
2403 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_CHANNEL_ERROR, data); | 2450 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_CHANNEL_ERROR, data); |
2404 } | 2451 } |
2405 | 2452 |
2406 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { | 2453 void DataChannel::OnDataChannelReadyToSend(bool writable) { |
2407 // This is usded for congestion control to indicate that the stream is ready | 2454 // This is usded for congestion control to indicate that the stream is ready |
2408 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates | 2455 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |
2409 // that the transport channel is ready. | 2456 // that the transport channel is ready. |
2410 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2457 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
2411 new DataChannelReadyToSendMessageData(writable)); | 2458 new DataChannelReadyToSendMessageData(writable)); |
2412 } | 2459 } |
2413 | 2460 |
2414 void RtpDataChannel::GetSrtpCryptoSuites_n( | 2461 void DataChannel::GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const { |
2415 std::vector<int>* crypto_suites) const { | |
2416 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); | 2462 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
2417 } | 2463 } |
2418 | 2464 |
| 2465 bool DataChannel::ShouldSetupDtlsSrtp_n() const { |
| 2466 return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n(); |
| 2467 } |
| 2468 |
| 2469 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2470 rtc::TypedMessageData<uint32_t>* message = |
| 2471 new rtc::TypedMessageData<uint32_t>(sid); |
| 2472 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, |
| 2473 message); |
| 2474 } |
| 2475 |
2419 } // namespace cricket | 2476 } // namespace cricket |
OLD | NEW |