| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 411 |
| 412 protected: | 412 protected: |
| 413 virtual void DoClose(); | 413 virtual void DoClose(); |
| 414 | 414 |
| 415 FILE* file_; | 415 FILE* file_; |
| 416 | 416 |
| 417 private: | 417 private: |
| 418 DISALLOW_COPY_AND_ASSIGN(FileStream); | 418 DISALLOW_COPY_AND_ASSIGN(FileStream); |
| 419 }; | 419 }; |
| 420 | 420 |
| 421 // A stream that caps the output at a certain size, dropping content from the | |
| 422 // middle of the logical stream and maintaining equal parts of the start/end of | |
| 423 // the logical stream. | |
| 424 class CircularFileStream : public FileStream { | |
| 425 public: | |
| 426 explicit CircularFileStream(size_t max_size); | |
| 427 | |
| 428 bool Open(const std::string& filename, const char* mode, int* error) override; | |
| 429 StreamResult Read(void* buffer, | |
| 430 size_t buffer_len, | |
| 431 size_t* read, | |
| 432 int* error) override; | |
| 433 StreamResult Write(const void* data, | |
| 434 size_t data_len, | |
| 435 size_t* written, | |
| 436 int* error) override; | |
| 437 | |
| 438 private: | |
| 439 enum ReadSegment { | |
| 440 READ_MARKED, // Read 0 .. marked_position_ | |
| 441 READ_MIDDLE, // Read position_ .. file_size | |
| 442 READ_LATEST, // Read marked_position_ .. position_ if the buffer was | |
| 443 // overwritten or 0 .. position_ otherwise. | |
| 444 }; | |
| 445 | |
| 446 size_t max_write_size_; | |
| 447 size_t position_; | |
| 448 size_t marked_position_; | |
| 449 size_t last_write_position_; | |
| 450 ReadSegment read_segment_; | |
| 451 size_t read_segment_available_; | |
| 452 }; | |
| 453 | |
| 454 /////////////////////////////////////////////////////////////////////////////// | 421 /////////////////////////////////////////////////////////////////////////////// |
| 455 // MemoryStream is a simple implementation of a StreamInterface over in-memory | 422 // MemoryStream is a simple implementation of a StreamInterface over in-memory |
| 456 // data. Data is read and written at the current seek position. Reads return | 423 // data. Data is read and written at the current seek position. Reads return |
| 457 // end-of-stream when they reach the end of data. Writes actually extend the | 424 // end-of-stream when they reach the end of data. Writes actually extend the |
| 458 // end of data mark. | 425 // end of data mark. |
| 459 /////////////////////////////////////////////////////////////////////////////// | 426 /////////////////////////////////////////////////////////////////////////////// |
| 460 | 427 |
| 461 class MemoryStreamBase : public StreamInterface { | 428 class MemoryStreamBase : public StreamInterface { |
| 462 public: | 429 public: |
| 463 StreamState GetState() const override; | 430 StreamState GetState() const override; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 // as a pass in parameter, it indicates data in buffer that should move to sink | 694 // as a pass in parameter, it indicates data in buffer that should move to sink |
| 728 StreamResult Flow(StreamInterface* source, | 695 StreamResult Flow(StreamInterface* source, |
| 729 char* buffer, size_t buffer_len, | 696 char* buffer, size_t buffer_len, |
| 730 StreamInterface* sink, size_t* data_len = NULL); | 697 StreamInterface* sink, size_t* data_len = NULL); |
| 731 | 698 |
| 732 /////////////////////////////////////////////////////////////////////////////// | 699 /////////////////////////////////////////////////////////////////////////////// |
| 733 | 700 |
| 734 } // namespace rtc | 701 } // namespace rtc |
| 735 | 702 |
| 736 #endif // WEBRTC_BASE_STREAM_H_ | 703 #endif // WEBRTC_BASE_STREAM_H_ |
| OLD | NEW |