正在显示
9 个修改的文件
包含
73 行增加
和
33 行删除
| @@ -41,7 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -41,7 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 41 | /** | 41 | /** |
| 42 | * file writer, to write to file. | 42 | * file writer, to write to file. |
| 43 | */ | 43 | */ |
| 44 | -class SrsFileWriter : public ISrsBufferWriter | 44 | +class SrsFileWriter : public ISrsWriter |
| 45 | { | 45 | { |
| 46 | private: | 46 | private: |
| 47 | std::string path; | 47 | std::string path; |
| @@ -85,7 +85,7 @@ public: | @@ -85,7 +85,7 @@ public: | ||
| 85 | /** | 85 | /** |
| 86 | * file reader, to read from file. | 86 | * file reader, to read from file. |
| 87 | */ | 87 | */ |
| 88 | -class SrsFileReader : public ISrsBufferReader | 88 | +class SrsFileReader : public ISrsReader |
| 89 | { | 89 | { |
| 90 | private: | 90 | private: |
| 91 | std::string path; | 91 | std::string path; |
| @@ -23,19 +23,35 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -23,19 +23,35 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | 23 | ||
| 24 | #include <srs_kernel_io.hpp> | 24 | #include <srs_kernel_io.hpp> |
| 25 | 25 | ||
| 26 | -ISrsBufferReader::ISrsBufferReader() | 26 | +ISrsReader::ISrsReader() |
| 27 | { | 27 | { |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | -ISrsBufferReader::~ISrsBufferReader() | 30 | +ISrsReader::~ISrsReader() |
| 31 | { | 31 | { |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | -ISrsBufferWriter::ISrsBufferWriter() | 34 | +ISrsStreamWriter::ISrsStreamWriter() |
| 35 | { | 35 | { |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | -ISrsBufferWriter::~ISrsBufferWriter() | 38 | +ISrsStreamWriter::~ISrsStreamWriter() |
| 39 | +{ | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +ISrsVectorWriter::ISrsVectorWriter() | ||
| 43 | +{ | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +ISrsVectorWriter::~ISrsVectorWriter() | ||
| 47 | +{ | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +ISrsWriter::ISrsWriter() | ||
| 51 | +{ | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +ISrsWriter::~ISrsWriter() | ||
| 39 | { | 55 | { |
| 40 | } | 56 | } |
| 41 | 57 |
| @@ -36,33 +36,42 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -36,33 +36,42 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 36 | #endif | 36 | #endif |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | - * the reader for the buffer to read from whatever channel. | 39 | + * The reader to read data from channel. |
| 40 | */ | 40 | */ |
| 41 | -class ISrsBufferReader | 41 | +class ISrsReader |
| 42 | { | 42 | { |
| 43 | public: | 43 | public: |
| 44 | - ISrsBufferReader(); | ||
| 45 | - virtual ~ISrsBufferReader(); | ||
| 46 | - // for protocol/amf0/msg-codec | 44 | + ISrsReader(); |
| 45 | + virtual ~ISrsReader(); | ||
| 47 | public: | 46 | public: |
| 48 | virtual int read(void* buf, size_t size, ssize_t* nread) = 0; | 47 | virtual int read(void* buf, size_t size, ssize_t* nread) = 0; |
| 49 | }; | 48 | }; |
| 50 | 49 | ||
| 51 | /** | 50 | /** |
| 52 | - * the writer for the buffer to write to whatever channel. | 51 | + * The writer to write stream data to channel. |
| 53 | */ | 52 | */ |
| 54 | -class ISrsBufferWriter | 53 | +class ISrsStreamWriter |
| 55 | { | 54 | { |
| 56 | public: | 55 | public: |
| 57 | - ISrsBufferWriter(); | ||
| 58 | - virtual ~ISrsBufferWriter(); | ||
| 59 | - // for protocol | 56 | + ISrsStreamWriter(); |
| 57 | + virtual ~ISrsStreamWriter(); | ||
| 60 | public: | 58 | public: |
| 61 | /** | 59 | /** |
| 62 | * write bytes over writer. | 60 | * write bytes over writer. |
| 63 | * @nwrite the actual written bytes. NULL to ignore. | 61 | * @nwrite the actual written bytes. NULL to ignore. |
| 64 | */ | 62 | */ |
| 65 | virtual int write(void* buf, size_t size, ssize_t* nwrite) = 0; | 63 | virtual int write(void* buf, size_t size, ssize_t* nwrite) = 0; |
| 64 | +}; | ||
| 65 | + | ||
| 66 | +/** | ||
| 67 | + * The vector writer to write vector(iovc) to channel. | ||
| 68 | + */ | ||
| 69 | +class ISrsVectorWriter | ||
| 70 | +{ | ||
| 71 | +public: | ||
| 72 | + ISrsVectorWriter(); | ||
| 73 | + virtual ~ISrsVectorWriter(); | ||
| 74 | +public: | ||
| 66 | /** | 75 | /** |
| 67 | * write iov over writer. | 76 | * write iov over writer. |
| 68 | * @nwrite the actual written bytes. NULL to ignore. | 77 | * @nwrite the actual written bytes. NULL to ignore. |
| @@ -70,5 +79,15 @@ public: | @@ -70,5 +79,15 @@ public: | ||
| 70 | virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite) = 0; | 79 | virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite) = 0; |
| 71 | }; | 80 | }; |
| 72 | 81 | ||
| 82 | +/** | ||
| 83 | + * The generally writer, stream and vector writer. | ||
| 84 | + */ | ||
| 85 | +class ISrsWriter : virtual public ISrsStreamWriter, virtual public ISrsVectorWriter | ||
| 86 | +{ | ||
| 87 | +public: | ||
| 88 | + ISrsWriter(); | ||
| 89 | + virtual ~ISrsWriter(); | ||
| 90 | +}; | ||
| 91 | + | ||
| 73 | #endif | 92 | #endif |
| 74 | 93 |
| @@ -341,7 +341,7 @@ int SimpleSocketStream::connect(const char* server_ip, int port) | @@ -341,7 +341,7 @@ int SimpleSocketStream::connect(const char* server_ip, int port) | ||
| 341 | return srs_hijack_io_connect(io, server_ip, port); | 341 | return srs_hijack_io_connect(io, server_ip, port); |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | -// ISrsBufferReader | 344 | +// ISrsReader |
| 345 | int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) | 345 | int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) |
| 346 | { | 346 | { |
| 347 | srs_assert(io); | 347 | srs_assert(io); |
| @@ -53,7 +53,7 @@ public: | @@ -53,7 +53,7 @@ public: | ||
| 53 | virtual srs_hijack_io_t hijack_io(); | 53 | virtual srs_hijack_io_t hijack_io(); |
| 54 | virtual int create_socket(srs_rtmp_t owner); | 54 | virtual int create_socket(srs_rtmp_t owner); |
| 55 | virtual int connect(const char* server, int port); | 55 | virtual int connect(const char* server, int port); |
| 56 | -// ISrsBufferReader | 56 | +// ISrsReader |
| 57 | public: | 57 | public: |
| 58 | virtual int read(void* buf, size_t size, ssize_t* nread); | 58 | virtual int read(void* buf, size_t size, ssize_t* nread); |
| 59 | // ISrsProtocolReader | 59 | // ISrsProtocolReader |
| @@ -34,15 +34,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,15 +34,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * the system io reader/writer architecture: | 36 | * the system io reader/writer architecture: |
| 37 | -+---------------+ +--------------------+ +---------------+ | ||
| 38 | -| IBufferReader | | IStatistic | | IBufferWriter | | ||
| 39 | -+---------------+ +--------------------+ +---------------+ | ||
| 40 | -| + read() | | + get_recv_bytes() | | + write() | | ||
| 41 | -+------+--------+ | + get_send_bytes() | | + writev() | | ||
| 42 | - / \ +---+--------------+-+ +-------+-------+ | ||
| 43 | - | / \ / \ / \ | ||
| 44 | - | | | | | ||
| 45 | -+------+------------------+-+ +-----+----------------+--+ | 37 | + +---------------+ +---------------+ |
| 38 | + | IStreamWriter | | IVectorWriter | | ||
| 39 | + +---------------+ +---------------+ | ||
| 40 | + | + write() | | + writev() | | ||
| 41 | + +-------------+-+ ++--------------+ | ||
| 42 | ++----------+ +--------------------+ /\ /\ | ||
| 43 | +| IReader | | IStatistic | \ / | ||
| 44 | ++----------+ +--------------------+ V | ||
| 45 | +| + read() | | + get_recv_bytes() | +------+----+ | ||
| 46 | ++------+---+ | + get_send_bytes() | | IWriter | | ||
| 47 | + / \ +---+--------------+-+ +-------+---+ | ||
| 48 | + | / \ / \ / \ | ||
| 49 | + | | | | | ||
| 50 | ++------+-------------+------+ ++---------------------+--+ | ||
| 46 | | IProtocolReader | | IProtocolWriter | | 51 | | IProtocolReader | | IProtocolWriter | |
| 47 | +---------------------------+ +-------------------------+ | 52 | +---------------------------+ +-------------------------+ |
| 48 | | + readfully() | | + set_send_timeout() | | 53 | | + readfully() | | + set_send_timeout() | |
| @@ -80,7 +85,7 @@ public: | @@ -80,7 +85,7 @@ public: | ||
| 80 | /** | 85 | /** |
| 81 | * the reader for the protocol to read from whatever channel. | 86 | * the reader for the protocol to read from whatever channel. |
| 82 | */ | 87 | */ |
| 83 | -class ISrsProtocolReader : public virtual ISrsBufferReader, public virtual ISrsProtocolStatistic | 88 | +class ISrsProtocolReader : public virtual ISrsReader, public virtual ISrsProtocolStatistic |
| 84 | { | 89 | { |
| 85 | public: | 90 | public: |
| 86 | ISrsProtocolReader(); | 91 | ISrsProtocolReader(); |
| @@ -108,7 +113,7 @@ public: | @@ -108,7 +113,7 @@ public: | ||
| 108 | /** | 113 | /** |
| 109 | * the writer for the protocol to write to whatever channel. | 114 | * the writer for the protocol to write to whatever channel. |
| 110 | */ | 115 | */ |
| 111 | -class ISrsProtocolWriter : public virtual ISrsBufferWriter, public virtual ISrsProtocolStatistic | 116 | +class ISrsProtocolWriter : public virtual ISrsWriter, public virtual ISrsProtocolStatistic |
| 112 | { | 117 | { |
| 113 | public: | 118 | public: |
| 114 | ISrsProtocolWriter(); | 119 | ISrsProtocolWriter(); |
| @@ -131,7 +131,7 @@ void SrsFastStream::skip(int size) | @@ -131,7 +131,7 @@ void SrsFastStream::skip(int size) | ||
| 131 | p += size; | 131 | p += size; |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | -int SrsFastStream::grow(ISrsBufferReader* reader, int required_size) | 134 | +int SrsFastStream::grow(ISrsReader* reader, int required_size) |
| 135 | { | 135 | { |
| 136 | int ret = ERROR_SUCCESS; | 136 | int ret = ERROR_SUCCESS; |
| 137 | 137 |
| @@ -60,7 +60,7 @@ public: | @@ -60,7 +60,7 @@ public: | ||
| 60 | * the buffer provices bytes cache for protocol. generally, | 60 | * the buffer provices bytes cache for protocol. generally, |
| 61 | * protocol recv data from socket, put into buffer, decode to RTMP message. | 61 | * protocol recv data from socket, put into buffer, decode to RTMP message. |
| 62 | * Usage: | 62 | * Usage: |
| 63 | -* ISrsBufferReader* r = ......; | 63 | +* ISrsReader* r = ......; |
| 64 | * SrsFastStream* fb = ......; | 64 | * SrsFastStream* fb = ......; |
| 65 | * fb->grow(r, 1024); | 65 | * fb->grow(r, 1024); |
| 66 | * char* header = fb->read_slice(100); | 66 | * char* header = fb->read_slice(100); |
| @@ -138,7 +138,7 @@ public: | @@ -138,7 +138,7 @@ public: | ||
| 138 | * @return an int error code, error if required_size negative. | 138 | * @return an int error code, error if required_size negative. |
| 139 | * @remark, we actually maybe read more than required_size, maybe 4k for example. | 139 | * @remark, we actually maybe read more than required_size, maybe 4k for example. |
| 140 | */ | 140 | */ |
| 141 | - virtual int grow(ISrsBufferReader* reader, int required_size); | 141 | + virtual int grow(ISrsReader* reader, int required_size); |
| 142 | public: | 142 | public: |
| 143 | #ifdef SRS_PERF_MERGED_READ | 143 | #ifdef SRS_PERF_MERGED_READ |
| 144 | /** | 144 | /** |
| @@ -33,7 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,7 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | #include <srs_kernel_file.hpp> | 33 | #include <srs_kernel_file.hpp> |
| 34 | #include <srs_protocol_stream.hpp> | 34 | #include <srs_protocol_stream.hpp> |
| 35 | 35 | ||
| 36 | -class MockBufferReader: public ISrsBufferReader | 36 | +class MockBufferReader: public ISrsReader |
| 37 | { | 37 | { |
| 38 | private: | 38 | private: |
| 39 | std::string str; | 39 | std::string str; |
-
请 注册 或 登录 后发表评论