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

Side by Side Diff: webrtc/base/stream.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. 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/base/sslsocketfactory.cc ('k') | webrtc/base/task.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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 427 }
428 } 428 }
429 429
430 bool FileStream::SetPosition(size_t position) { 430 bool FileStream::SetPosition(size_t position) {
431 if (!file_) 431 if (!file_)
432 return false; 432 return false;
433 return (fseek(file_, static_cast<int>(position), SEEK_SET) == 0); 433 return (fseek(file_, static_cast<int>(position), SEEK_SET) == 0);
434 } 434 }
435 435
436 bool FileStream::GetPosition(size_t* position) const { 436 bool FileStream::GetPosition(size_t* position) const {
437 ASSERT(NULL != position); 437 RTC_DCHECK(NULL != position);
438 if (!file_) 438 if (!file_)
439 return false; 439 return false;
440 long result = ftell(file_); 440 long result = ftell(file_);
441 if (result < 0) 441 if (result < 0)
442 return false; 442 return false;
443 if (position) 443 if (position)
444 *position = result; 444 *position = result;
445 return true; 445 return true;
446 } 446 }
447 447
448 bool FileStream::GetSize(size_t* size) const { 448 bool FileStream::GetSize(size_t* size) const {
449 ASSERT(NULL != size); 449 RTC_DCHECK(NULL != size);
450 if (!file_) 450 if (!file_)
451 return false; 451 return false;
452 struct stat file_stats; 452 struct stat file_stats;
453 if (fstat(fileno(file_), &file_stats) != 0) 453 if (fstat(fileno(file_), &file_stats) != 0)
454 return false; 454 return false;
455 if (size) 455 if (size)
456 *size = file_stats.st_size; 456 *size = file_stats.st_size;
457 return true; 457 return true;
458 } 458 }
459 459
460 bool FileStream::GetAvailable(size_t* size) const { 460 bool FileStream::GetAvailable(size_t* size) const {
461 ASSERT(NULL != size); 461 RTC_DCHECK(NULL != size);
462 if (!GetSize(size)) 462 if (!GetSize(size))
463 return false; 463 return false;
464 long result = ftell(file_); 464 long result = ftell(file_);
465 if (result < 0) 465 if (result < 0)
466 return false; 466 return false;
467 if (size) 467 if (size)
468 *size -= result; 468 *size -= result;
469 return true; 469 return true;
470 } 470 }
471 471
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 if (0 == available) { 556 if (0 == available) {
557 // Increase buffer size to the larger of: 557 // Increase buffer size to the larger of:
558 // a) new position rounded up to next 256 bytes 558 // a) new position rounded up to next 256 bytes
559 // b) double the previous length 559 // b) double the previous length
560 size_t new_buffer_length = 560 size_t new_buffer_length =
561 std::max(((seek_position_ + bytes) | 0xFF) + 1, buffer_length_ * 2); 561 std::max(((seek_position_ + bytes) | 0xFF) + 1, buffer_length_ * 2);
562 StreamResult result = DoReserve(new_buffer_length, error); 562 StreamResult result = DoReserve(new_buffer_length, error);
563 if (SR_SUCCESS != result) { 563 if (SR_SUCCESS != result) {
564 return result; 564 return result;
565 } 565 }
566 ASSERT(buffer_length_ >= new_buffer_length); 566 RTC_DCHECK(buffer_length_ >= new_buffer_length);
567 available = buffer_length_ - seek_position_; 567 available = buffer_length_ - seek_position_;
568 } 568 }
569 569
570 if (bytes > available) { 570 if (bytes > available) {
571 bytes = available; 571 bytes = available;
572 } 572 }
573 memcpy(&buffer_[seek_position_], buffer, bytes); 573 memcpy(&buffer_[seek_position_], buffer, bytes);
574 seek_position_ += bytes; 574 seek_position_ += bytes;
575 if (data_length_ < seek_position_) { 575 if (data_length_ < seek_position_) {
576 data_length_ = seek_position_; 576 data_length_ = seek_position_;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 801
802 const void* FifoBuffer::GetReadData(size_t* size) { 802 const void* FifoBuffer::GetReadData(size_t* size) {
803 CritScope cs(&crit_); 803 CritScope cs(&crit_);
804 *size = (read_position_ + data_length_ <= buffer_length_) ? 804 *size = (read_position_ + data_length_ <= buffer_length_) ?
805 data_length_ : buffer_length_ - read_position_; 805 data_length_ : buffer_length_ - read_position_;
806 return &buffer_[read_position_]; 806 return &buffer_[read_position_];
807 } 807 }
808 808
809 void FifoBuffer::ConsumeReadData(size_t size) { 809 void FifoBuffer::ConsumeReadData(size_t size) {
810 CritScope cs(&crit_); 810 CritScope cs(&crit_);
811 ASSERT(size <= data_length_); 811 RTC_DCHECK(size <= data_length_);
812 const bool was_writable = data_length_ < buffer_length_; 812 const bool was_writable = data_length_ < buffer_length_;
813 read_position_ = (read_position_ + size) % buffer_length_; 813 read_position_ = (read_position_ + size) % buffer_length_;
814 data_length_ -= size; 814 data_length_ -= size;
815 if (!was_writable && size > 0) { 815 if (!was_writable && size > 0) {
816 PostEvent(owner_, SE_WRITE, 0); 816 PostEvent(owner_, SE_WRITE, 0);
817 } 817 }
818 } 818 }
819 819
820 void* FifoBuffer::GetWriteBuffer(size_t* size) { 820 void* FifoBuffer::GetWriteBuffer(size_t* size) {
821 CritScope cs(&crit_); 821 CritScope cs(&crit_);
822 if (state_ == SS_CLOSED) { 822 if (state_ == SS_CLOSED) {
823 return NULL; 823 return NULL;
824 } 824 }
825 825
826 // if empty, reset the write position to the beginning, so we can get 826 // if empty, reset the write position to the beginning, so we can get
827 // the biggest possible block 827 // the biggest possible block
828 if (data_length_ == 0) { 828 if (data_length_ == 0) {
829 read_position_ = 0; 829 read_position_ = 0;
830 } 830 }
831 831
832 const size_t write_position = (read_position_ + data_length_) 832 const size_t write_position = (read_position_ + data_length_)
833 % buffer_length_; 833 % buffer_length_;
834 *size = (write_position > read_position_ || data_length_ == 0) ? 834 *size = (write_position > read_position_ || data_length_ == 0) ?
835 buffer_length_ - write_position : read_position_ - write_position; 835 buffer_length_ - write_position : read_position_ - write_position;
836 return &buffer_[write_position]; 836 return &buffer_[write_position];
837 } 837 }
838 838
839 void FifoBuffer::ConsumeWriteBuffer(size_t size) { 839 void FifoBuffer::ConsumeWriteBuffer(size_t size) {
840 CritScope cs(&crit_); 840 CritScope cs(&crit_);
841 ASSERT(size <= buffer_length_ - data_length_); 841 RTC_DCHECK(size <= buffer_length_ - data_length_);
842 const bool was_readable = (data_length_ > 0); 842 const bool was_readable = (data_length_ > 0);
843 data_length_ += size; 843 data_length_ += size;
844 if (!was_readable && size > 0) { 844 if (!was_readable && size > 0) {
845 PostEvent(owner_, SE_READ, 0); 845 PostEvent(owner_, SE_READ, 0);
846 } 846 }
847 } 847 }
848 848
849 bool FifoBuffer::GetWriteRemaining(size_t* size) const { 849 bool FifoBuffer::GetWriteRemaining(size_t* size) const {
850 CritScope cs(&crit_); 850 CritScope cs(&crit_);
851 *size = buffer_length_ - data_length_; 851 *size = buffer_length_ - data_length_;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 : StreamAdapterInterface(stream, false), 1063 : StreamAdapterInterface(stream, false),
1064 stream_ref_count_(stream_ref_count) { 1064 stream_ref_count_(stream_ref_count) {
1065 } 1065 }
1066 1066
1067 /////////////////////////////////////////////////////////////////////////////// 1067 ///////////////////////////////////////////////////////////////////////////////
1068 1068
1069 StreamResult Flow(StreamInterface* source, 1069 StreamResult Flow(StreamInterface* source,
1070 char* buffer, size_t buffer_len, 1070 char* buffer, size_t buffer_len,
1071 StreamInterface* sink, 1071 StreamInterface* sink,
1072 size_t* data_len /* = NULL */) { 1072 size_t* data_len /* = NULL */) {
1073 ASSERT(buffer_len > 0); 1073 RTC_DCHECK(buffer_len > 0);
1074 1074
1075 StreamResult result; 1075 StreamResult result;
1076 size_t count, read_pos, write_pos; 1076 size_t count, read_pos, write_pos;
1077 if (data_len) { 1077 if (data_len) {
1078 read_pos = *data_len; 1078 read_pos = *data_len;
1079 } else { 1079 } else {
1080 read_pos = 0; 1080 read_pos = 0;
1081 } 1081 }
1082 1082
1083 bool end_of_stream = false; 1083 bool end_of_stream = false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1120
1121 if (data_len) { 1121 if (data_len) {
1122 *data_len = 0; 1122 *data_len = 0;
1123 } 1123 }
1124 return SR_SUCCESS; 1124 return SR_SUCCESS;
1125 } 1125 }
1126 1126
1127 /////////////////////////////////////////////////////////////////////////////// 1127 ///////////////////////////////////////////////////////////////////////////////
1128 1128
1129 } // namespace rtc 1129 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/sslsocketfactory.cc ('k') | webrtc/base/task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698