diff --git a/trunk/src/rtmp/srs_protocol_rtmp.hpp b/trunk/src/rtmp/srs_protocol_rtmp.hpp index 177da5d9f..b59896965 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.hpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.hpp @@ -61,48 +61,47 @@ public: std::string pageUrl; std::string swfUrl; double objectEncoding; - +// data discovery from request. +public: + // discovery from tcUrl and play/publish. std::string schema; std::string vhost; std::string host; std::string port; std::string app; std::string stream; - // for play live stream, // used to specified the stop when exceed the duration. // @see https://github.com/winlinvip/simple-rtmp-server/issues/45 // in ms. double duration; - // the token in the connect request, // used for edge traverse to origin authentication, // @see https://github.com/winlinvip/simple-rtmp-server/issues/104 SrsAmf0Object* args; - +public: SrsRequest(); virtual ~SrsRequest(); - +public: /** * deep copy the request, for source to use it to support reload, * for when initialize the source, the request is valid, * when reload it, the request maybe invalid, so need to copy it. */ virtual SrsRequest* copy(); - /** * update the auth info of request, * to keep the current request ptr is ok, * for many components use the ptr of request. */ virtual void update_auth(SrsRequest* req); - /** * get the stream identify, vhost/app/stream. */ virtual std::string get_stream_url(); - - // strip url, user must strip when update the url. + /** + * strip url, user must strip when update the url. + */ virtual void strip(); }; @@ -112,8 +111,11 @@ public: class SrsResponse { public: + /** + * the stream id to response client createStream. + */ int stream_id; - +public: SrsResponse(); virtual ~SrsResponse(); }; diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 18453fcff..2b8f0de44 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -29,6 +29,8 @@ using namespace std; #include #include #include +#include +#include MockEmptyIO::MockEmptyIO() { @@ -91,6 +93,114 @@ int MockEmptyIO::read(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) return ERROR_SUCCESS; } +MockBufferIO::MockBufferIO() +{ + recv_timeout = send_timeout = ST_UTIME_NO_TIMEOUT; + recv_bytes = send_bytes = 0; +} + +MockBufferIO::~MockBufferIO() +{ +} + +bool MockBufferIO::is_never_timeout(int64_t timeout_us) +{ + return (int64_t)ST_UTIME_NO_TIMEOUT == timeout_us; +} + +int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread) +{ + if (in_buffer.length() < (int)size) { + return ERROR_SOCKET_READ; + } + memcpy(buf, in_buffer.bytes(), size); + + recv_bytes += size; + if (nread) { + *nread = size; + } + in_buffer.erase(size); + return ERROR_SUCCESS; +} + +int MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite) +{ + send_bytes += size; + if (nwrite) { + *nwrite = size; + } + out_buffer.append((char*)buf, size); + return ERROR_SUCCESS; +} + +void MockBufferIO::set_recv_timeout(int64_t timeout_us) +{ + recv_timeout = timeout_us; +} + +int64_t MockBufferIO::get_recv_timeout() +{ + return recv_timeout; +} + +int64_t MockBufferIO::get_recv_bytes() +{ + return recv_bytes; +} + +void MockBufferIO::set_send_timeout(int64_t timeout_us) +{ + send_timeout = timeout_us; +} + +int64_t MockBufferIO::get_send_timeout() +{ + return send_timeout; +} + +int64_t MockBufferIO::get_send_bytes() +{ + return send_bytes; +} + +int MockBufferIO::writev(const iovec *iov, int iov_size, ssize_t* nwrite) +{ + int ret = ERROR_SUCCESS; + + ssize_t total = 0; + for (int i = 0; i #include +#include #ifdef SRS_AUTO_SSL using namespace _srs_internal; @@ -69,4 +70,41 @@ public: virtual int read(void* buf, size_t size, ssize_t* nread); }; +class MockBufferIO : public ISrsProtocolReaderWriter +{ +public: + int64_t recv_timeout; + int64_t send_timeout; + int64_t recv_bytes; + int64_t send_bytes; + // data source for socket read. + SrsBuffer in_buffer; + // data buffer for socket send. + SrsBuffer out_buffer; +public: + MockBufferIO(); + virtual ~MockBufferIO(); +// for protocol +public: + virtual bool is_never_timeout(int64_t timeout_us); +// for handshake. +public: + virtual int read_fully(void* buf, size_t size, ssize_t* nread); + virtual int write(void* buf, size_t size, ssize_t* nwrite); +// for protocol +public: + virtual void set_recv_timeout(int64_t timeout_us); + virtual int64_t get_recv_timeout(); + virtual int64_t get_recv_bytes(); +// for protocol +public: + virtual void set_send_timeout(int64_t timeout_us); + virtual int64_t get_send_timeout(); + virtual int64_t get_send_bytes(); + virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite); +// for protocol/amf0/msg-codec +public: + virtual int read(void* buf, size_t size, ssize_t* nread); +}; + #endif