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 |
11 #ifndef WEBRTC_BASE_STREAM_H_ | 11 #ifndef WEBRTC_BASE_STREAM_H_ |
12 #define WEBRTC_BASE_STREAM_H_ | 12 #define WEBRTC_BASE_STREAM_H_ |
13 | 13 |
| 14 #include <memory> |
14 #include <stdio.h> | 15 #include <stdio.h> |
15 | 16 |
16 #include "webrtc/base/basictypes.h" | 17 #include "webrtc/base/basictypes.h" |
17 #include "webrtc/base/buffer.h" | 18 #include "webrtc/base/buffer.h" |
18 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
19 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/messagehandler.h" | 21 #include "webrtc/base/messagehandler.h" |
21 #include "webrtc/base/messagequeue.h" | 22 #include "webrtc/base/messagequeue.h" |
22 #include "webrtc/base/scoped_ptr.h" | |
23 #include "webrtc/base/sigslot.h" | 23 #include "webrtc/base/sigslot.h" |
24 | 24 |
25 namespace rtc { | 25 namespace rtc { |
26 | 26 |
27 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
28 // StreamInterface is a generic asynchronous stream interface, supporting read, | 28 // StreamInterface is a generic asynchronous stream interface, supporting read, |
29 // write, and close operations, and asynchronous signalling of state changes. | 29 // write, and close operations, and asynchronous signalling of state changes. |
30 // The interface is designed with file, memory, and socket implementations in | 30 // The interface is designed with file, memory, and socket implementations in |
31 // mind. Some implementations offer extended operations, such as seeking. | 31 // mind. Some implementations offer extended operations, such as seeking. |
32 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 StreamResult Read(void* buffer, | 327 StreamResult Read(void* buffer, |
328 size_t buffer_len, | 328 size_t buffer_len, |
329 size_t* read, | 329 size_t* read, |
330 int* error) override; | 330 int* error) override; |
331 StreamResult Write(const void* data, | 331 StreamResult Write(const void* data, |
332 size_t data_len, | 332 size_t data_len, |
333 size_t* written, | 333 size_t* written, |
334 int* error) override; | 334 int* error) override; |
335 | 335 |
336 private: | 336 private: |
337 scoped_ptr<StreamInterface> tap_; | 337 std::unique_ptr<StreamInterface> tap_; |
338 StreamResult tap_result_; | 338 StreamResult tap_result_; |
339 int tap_error_; | 339 int tap_error_; |
340 RTC_DISALLOW_COPY_AND_ASSIGN(StreamTap); | 340 RTC_DISALLOW_COPY_AND_ASSIGN(StreamTap); |
341 }; | 341 }; |
342 | 342 |
343 /////////////////////////////////////////////////////////////////////////////// | 343 /////////////////////////////////////////////////////////////////////////////// |
344 // NullStream gives errors on read, and silently discards all written data. | 344 // NullStream gives errors on read, and silently discards all written data. |
345 /////////////////////////////////////////////////////////////////////////////// | 345 /////////////////////////////////////////////////////////////////////////////// |
346 | 346 |
347 class NullStream : public StreamInterface { | 347 class NullStream : public StreamInterface { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 547 |
548 // Helper method that implements WriteOffset. Caller must acquire a lock | 548 // Helper method that implements WriteOffset. Caller must acquire a lock |
549 // when calling this method. | 549 // when calling this method. |
550 StreamResult WriteOffsetLocked(const void* buffer, size_t bytes, | 550 StreamResult WriteOffsetLocked(const void* buffer, size_t bytes, |
551 size_t offset, size_t* bytes_written) | 551 size_t offset, size_t* bytes_written) |
552 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 552 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
553 | 553 |
554 // keeps the opened/closed state of the stream | 554 // keeps the opened/closed state of the stream |
555 StreamState state_ GUARDED_BY(crit_); | 555 StreamState state_ GUARDED_BY(crit_); |
556 // the allocated buffer | 556 // the allocated buffer |
557 scoped_ptr<char[]> buffer_ GUARDED_BY(crit_); | 557 std::unique_ptr<char[]> buffer_ GUARDED_BY(crit_); |
558 // size of the allocated buffer | 558 // size of the allocated buffer |
559 size_t buffer_length_ GUARDED_BY(crit_); | 559 size_t buffer_length_ GUARDED_BY(crit_); |
560 // amount of readable data in the buffer | 560 // amount of readable data in the buffer |
561 size_t data_length_ GUARDED_BY(crit_); | 561 size_t data_length_ GUARDED_BY(crit_); |
562 // offset to the readable data | 562 // offset to the readable data |
563 size_t read_position_ GUARDED_BY(crit_); | 563 size_t read_position_ GUARDED_BY(crit_); |
564 // stream callbacks are dispatched on this thread | 564 // stream callbacks are dispatched on this thread |
565 Thread* owner_; | 565 Thread* owner_; |
566 // object lock | 566 // object lock |
567 CriticalSection crit_; | 567 CriticalSection crit_; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 // as a pass in parameter, it indicates data in buffer that should move to sink | 703 // as a pass in parameter, it indicates data in buffer that should move to sink |
704 StreamResult Flow(StreamInterface* source, | 704 StreamResult Flow(StreamInterface* source, |
705 char* buffer, size_t buffer_len, | 705 char* buffer, size_t buffer_len, |
706 StreamInterface* sink, size_t* data_len = NULL); | 706 StreamInterface* sink, size_t* data_len = NULL); |
707 | 707 |
708 /////////////////////////////////////////////////////////////////////////////// | 708 /////////////////////////////////////////////////////////////////////////////// |
709 | 709 |
710 } // namespace rtc | 710 } // namespace rtc |
711 | 711 |
712 #endif // WEBRTC_BASE_STREAM_H_ | 712 #endif // WEBRTC_BASE_STREAM_H_ |
OLD | NEW |