| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 bool DataChannel::reliable() const { | 187 bool DataChannel::reliable() const { |
| 188 if (data_channel_type_ == cricket::DCT_RTP) { | 188 if (data_channel_type_ == cricket::DCT_RTP) { |
| 189 return false; | 189 return false; |
| 190 } else { | 190 } else { |
| 191 return config_.maxRetransmits == -1 && | 191 return config_.maxRetransmits == -1 && |
| 192 config_.maxRetransmitTime == -1; | 192 config_.maxRetransmitTime == -1; |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 uint64 DataChannel::buffered_amount() const { | 196 uint64_t DataChannel::buffered_amount() const { |
| 197 return queued_send_data_.byte_count(); | 197 return queued_send_data_.byte_count(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void DataChannel::Close() { | 200 void DataChannel::Close() { |
| 201 if (state_ == kClosed) | 201 if (state_ == kClosed) |
| 202 return; | 202 return; |
| 203 send_ssrc_ = 0; | 203 send_ssrc_ = 0; |
| 204 send_ssrc_set_ = false; | 204 send_ssrc_set_ = false; |
| 205 SetState(kClosing); | 205 SetState(kClosing); |
| 206 UpdateState(); | 206 UpdateState(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 232 | 232 |
| 233 bool success = SendDataMessage(buffer, true); | 233 bool success = SendDataMessage(buffer, true); |
| 234 if (data_channel_type_ == cricket::DCT_RTP) { | 234 if (data_channel_type_ == cricket::DCT_RTP) { |
| 235 return success; | 235 return success; |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Always return true for SCTP DataChannel per the spec. | 238 // Always return true for SCTP DataChannel per the spec. |
| 239 return true; | 239 return true; |
| 240 } | 240 } |
| 241 | 241 |
| 242 void DataChannel::SetReceiveSsrc(uint32 receive_ssrc) { | 242 void DataChannel::SetReceiveSsrc(uint32_t receive_ssrc) { |
| 243 ASSERT(data_channel_type_ == cricket::DCT_RTP); | 243 ASSERT(data_channel_type_ == cricket::DCT_RTP); |
| 244 | 244 |
| 245 if (receive_ssrc_set_) { | 245 if (receive_ssrc_set_) { |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 receive_ssrc_ = receive_ssrc; | 248 receive_ssrc_ = receive_ssrc; |
| 249 receive_ssrc_set_ = true; | 249 receive_ssrc_set_ = true; |
| 250 UpdateState(); | 250 UpdateState(); |
| 251 } | 251 } |
| 252 | 252 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 269 if (!connected_to_provider_) { | 269 if (!connected_to_provider_) { |
| 270 connected_to_provider_ = provider_->ConnectDataChannel(this); | 270 connected_to_provider_ = provider_->ConnectDataChannel(this); |
| 271 } | 271 } |
| 272 // The sid may have been unassigned when provider_->ConnectDataChannel was | 272 // The sid may have been unassigned when provider_->ConnectDataChannel was |
| 273 // done. So always add the streams even if connected_to_provider_ is true. | 273 // done. So always add the streams even if connected_to_provider_ is true. |
| 274 if (config_.id >= 0) { | 274 if (config_.id >= 0) { |
| 275 provider_->AddSctpDataStream(config_.id); | 275 provider_->AddSctpDataStream(config_.id); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 void DataChannel::SetSendSsrc(uint32 send_ssrc) { | 279 void DataChannel::SetSendSsrc(uint32_t send_ssrc) { |
| 280 ASSERT(data_channel_type_ == cricket::DCT_RTP); | 280 ASSERT(data_channel_type_ == cricket::DCT_RTP); |
| 281 if (send_ssrc_set_) { | 281 if (send_ssrc_set_) { |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 send_ssrc_ = send_ssrc; | 284 send_ssrc_ = send_ssrc; |
| 285 send_ssrc_set_ = true; | 285 send_ssrc_set_ = true; |
| 286 UpdateState(); | 286 UpdateState(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void DataChannel::OnMessage(rtc::Message* msg) { | 289 void DataChannel::OnMessage(rtc::Message* msg) { |
| 290 switch (msg->message_id) { | 290 switch (msg->message_id) { |
| 291 case MSG_CHANNELREADY: | 291 case MSG_CHANNELREADY: |
| 292 OnChannelReady(true); | 292 OnChannelReady(true); |
| 293 break; | 293 break; |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 // The underlaying data engine is closing. | 297 // The underlaying data engine is closing. |
| 298 // This function makes sure the DataChannel is disconnected and changes state to | 298 // This function makes sure the DataChannel is disconnected and changes state to |
| 299 // kClosed. | 299 // kClosed. |
| 300 void DataChannel::OnDataEngineClose() { | 300 void DataChannel::OnDataEngineClose() { |
| 301 DoClose(); | 301 DoClose(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void DataChannel::OnDataReceived(cricket::DataChannel* channel, | 304 void DataChannel::OnDataReceived(cricket::DataChannel* channel, |
| 305 const cricket::ReceiveDataParams& params, | 305 const cricket::ReceiveDataParams& params, |
| 306 const rtc::Buffer& payload) { | 306 const rtc::Buffer& payload) { |
| 307 uint32 expected_ssrc = | 307 uint32_t expected_ssrc = |
| 308 (data_channel_type_ == cricket::DCT_RTP) ? receive_ssrc_ : config_.id; | 308 (data_channel_type_ == cricket::DCT_RTP) ? receive_ssrc_ : config_.id; |
| 309 if (params.ssrc != expected_ssrc) { | 309 if (params.ssrc != expected_ssrc) { |
| 310 return; | 310 return; |
| 311 } | 311 } |
| 312 | 312 |
| 313 if (params.type == cricket::DMT_CONTROL) { | 313 if (params.type == cricket::DMT_CONTROL) { |
| 314 ASSERT(data_channel_type_ == cricket::DCT_SCTP); | 314 ASSERT(data_channel_type_ == cricket::DCT_SCTP); |
| 315 if (handshake_state_ != kHandshakeWaitingForAck) { | 315 if (handshake_state_ != kHandshakeWaitingForAck) { |
| 316 // Ignore it if we are not expecting an ACK message. | 316 // Ignore it if we are not expecting an ACK message. |
| 317 LOG(LS_WARNING) << "DataChannel received unexpected CONTROL message, " | 317 LOG(LS_WARNING) << "DataChannel received unexpected CONTROL message, " |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 void DataChannel::SendQueuedDataMessages() { | 472 void DataChannel::SendQueuedDataMessages() { |
| 473 if (queued_send_data_.Empty()) { | 473 if (queued_send_data_.Empty()) { |
| 474 return; | 474 return; |
| 475 } | 475 } |
| 476 | 476 |
| 477 ASSERT(state_ == kOpen || state_ == kClosing); | 477 ASSERT(state_ == kOpen || state_ == kClosing); |
| 478 | 478 |
| 479 uint64 start_buffered_amount = buffered_amount(); | 479 uint64_t start_buffered_amount = buffered_amount(); |
| 480 while (!queued_send_data_.Empty()) { | 480 while (!queued_send_data_.Empty()) { |
| 481 DataBuffer* buffer = queued_send_data_.Front(); | 481 DataBuffer* buffer = queued_send_data_.Front(); |
| 482 if (!SendDataMessage(*buffer, false)) { | 482 if (!SendDataMessage(*buffer, false)) { |
| 483 // Leave the message in the queue if sending is aborted. | 483 // Leave the message in the queue if sending is aborted. |
| 484 break; | 484 break; |
| 485 } | 485 } |
| 486 queued_send_data_.Pop(); | 486 queued_send_data_.Pop(); |
| 487 delete buffer; | 487 delete buffer; |
| 488 } | 488 } |
| 489 | 489 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 QueueControlMessage(buffer); | 598 QueueControlMessage(buffer); |
| 599 } else { | 599 } else { |
| 600 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" | 600 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" |
| 601 << " the CONTROL message, send_result = " << send_result; | 601 << " the CONTROL message, send_result = " << send_result; |
| 602 Close(); | 602 Close(); |
| 603 } | 603 } |
| 604 return retval; | 604 return retval; |
| 605 } | 605 } |
| 606 | 606 |
| 607 } // namespace webrtc | 607 } // namespace webrtc |
| OLD | NEW |