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

Side by Side Diff: webrtc/pc/channel.cc

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

Powered by Google App Engine
This is Rietveld 408576698