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 458 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 while (!queued_send_data_.Empty()) { | 480 while (!queued_send_data_.Empty()) { |
480 DataBuffer* buffer = queued_send_data_.Front(); | 481 DataBuffer* buffer = queued_send_data_.Front(); |
481 if (!SendDataMessage(*buffer, false)) { | 482 if (!SendDataMessage(*buffer, false)) { |
482 // Leave the message in the queue if sending is aborted. | 483 // Leave the message in the queue if sending is aborted. |
483 break; | 484 break; |
484 } | 485 } |
485 queued_send_data_.Pop(); | 486 queued_send_data_.Pop(); |
486 delete buffer; | 487 delete buffer; |
487 } | 488 } |
| 489 |
| 490 if (observer_ && buffered_amount() < start_buffered_amount) { |
| 491 observer_->OnBufferedAmountChange(start_buffered_amount); |
| 492 } |
488 } | 493 } |
489 | 494 |
490 bool DataChannel::SendDataMessage(const DataBuffer& buffer, | 495 bool DataChannel::SendDataMessage(const DataBuffer& buffer, |
491 bool queue_if_blocked) { | 496 bool queue_if_blocked) { |
492 cricket::SendDataParams send_params; | 497 cricket::SendDataParams send_params; |
493 | 498 |
494 if (data_channel_type_ == cricket::DCT_SCTP) { | 499 if (data_channel_type_ == cricket::DCT_SCTP) { |
495 send_params.ordered = config_.ordered; | 500 send_params.ordered = config_.ordered; |
496 // Send as ordered if it is still going through OPEN/ACK signaling. | 501 // Send as ordered if it is still going through OPEN/ACK signaling. |
497 if (handshake_state_ != kHandshakeReady && !config_.ordered) { | 502 if (handshake_state_ != kHandshakeReady && !config_.ordered) { |
(...skipping 29 matching lines...) Expand all Loading... |
527 // Close the channel if the error is not SDR_BLOCK, or if queuing the | 532 // Close the channel if the error is not SDR_BLOCK, or if queuing the |
528 // message failed. | 533 // message failed. |
529 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send data, " | 534 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send data, " |
530 << "send_result = " << send_result; | 535 << "send_result = " << send_result; |
531 Close(); | 536 Close(); |
532 | 537 |
533 return false; | 538 return false; |
534 } | 539 } |
535 | 540 |
536 bool DataChannel::QueueSendDataMessage(const DataBuffer& buffer) { | 541 bool DataChannel::QueueSendDataMessage(const DataBuffer& buffer) { |
537 if (queued_send_data_.byte_count() >= kMaxQueuedSendDataBytes) { | 542 size_t start_buffered_amount = buffered_amount(); |
| 543 if (start_buffered_amount >= kMaxQueuedSendDataBytes) { |
538 LOG(LS_ERROR) << "Can't buffer any more data for the data channel."; | 544 LOG(LS_ERROR) << "Can't buffer any more data for the data channel."; |
539 return false; | 545 return false; |
540 } | 546 } |
541 queued_send_data_.Push(new DataBuffer(buffer)); | 547 queued_send_data_.Push(new DataBuffer(buffer)); |
| 548 |
| 549 // The buffer can have length zero, in which case there is no change. |
| 550 if (observer_ && buffered_amount() > start_buffered_amount) { |
| 551 observer_->OnBufferedAmountChange(start_buffered_amount); |
| 552 } |
542 return true; | 553 return true; |
543 } | 554 } |
544 | 555 |
545 void DataChannel::SendQueuedControlMessages() { | 556 void DataChannel::SendQueuedControlMessages() { |
546 PacketQueue control_packets; | 557 PacketQueue control_packets; |
547 control_packets.Swap(&queued_control_data_); | 558 control_packets.Swap(&queued_control_data_); |
548 | 559 |
549 while (!control_packets.Empty()) { | 560 while (!control_packets.Empty()) { |
550 rtc::scoped_ptr<DataBuffer> buf(control_packets.Front()); | 561 rtc::scoped_ptr<DataBuffer> buf(control_packets.Front()); |
551 SendControlMessage(buf->data); | 562 SendControlMessage(buf->data); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 QueueControlMessage(buffer); | 598 QueueControlMessage(buffer); |
588 } else { | 599 } else { |
589 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" |
590 << " the CONTROL message, send_result = " << send_result; | 601 << " the CONTROL message, send_result = " << send_result; |
591 Close(); | 602 Close(); |
592 } | 603 } |
593 return retval; | 604 return retval; |
594 } | 605 } |
595 | 606 |
596 } // namespace webrtc | 607 } // namespace webrtc |
OLD | NEW |