From 8bc77387ff7f17997e6b6a9bc642379433739eaf Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 23 Apr 2019 08:06:50 +0800 Subject: [PATCH] Refine typo in protocol. --- trunk/src/protocol/srs_http_stack.hpp | 360 ++--- trunk/src/protocol/srs_protocol_json.hpp | 56 +- trunk/src/protocol/srs_raw_avc.hpp | 98 +- trunk/src/protocol/srs_rtmp_handshake.hpp | 490 +++--- trunk/src/protocol/srs_rtmp_msg_array.hpp | 40 +- trunk/src/protocol/srs_rtmp_stack.hpp | 1741 ++++++++------------- trunk/src/protocol/srs_rtsp_stack.hpp | 660 ++++---- 7 files changed, 1328 insertions(+), 2117 deletions(-) diff --git a/trunk/src/protocol/srs_http_stack.hpp b/trunk/src/protocol/srs_http_stack.hpp index f20a7aaa1..e68fe7b4e 100644 --- a/trunk/src/protocol/srs_http_stack.hpp +++ b/trunk/src/protocol/srs_http_stack.hpp @@ -26,7 +26,7 @@ #include -// default http listen port. +// Default http listen port. #define SRS_DEFAULT_HTTP_PORT 80 #if !defined(SRS_EXPORT_LIBRTMP) @@ -35,7 +35,7 @@ #include #include -// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213 +// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213 #ifndef _WIN32 #include #endif @@ -46,7 +46,7 @@ class ISrsHttpMessage; class SrsHttpMuxEntry; class ISrsHttpResponseWriter; -// http specification +// From http specification // CR = #define SRS_HTTP_CR SRS_CONSTS_CR // 0x0D // LF = @@ -65,10 +65,10 @@ class ISrsHttpResponseWriter; // @see ISrsHttpMessage._http_ts_send_buffer #define SRS_HTTP_TS_SEND_BUFFER_SIZE 4096 -// for ead all of http body, read each time. +// For ead all of http body, read each time. #define SRS_HTTP_READ_CACHE_BYTES 4096 -// for http parser macros +// For http parser macros #define SRS_CONSTS_HTTP_OPTIONS HTTP_OPTIONS #define SRS_CONSTS_HTTP_GET HTTP_GET #define SRS_CONSTS_HTTP_POST HTTP_POST @@ -80,10 +80,10 @@ class ISrsHttpResponseWriter; extern srs_error_t srs_go_http_error(ISrsHttpResponseWriter* w, int code); extern srs_error_t srs_go_http_error(ISrsHttpResponseWriter* w, int code, std::string error); -// get the status text of code. +// Get the status text of code. extern std::string srs_generate_http_status_text(int status); -// bodyAllowedForStatus reports whether a given response status code +// It reports whether a given response status code // permits a body. See RFC2616, section 4.4. extern bool srs_go_http_body_allowd(int status); @@ -95,7 +95,7 @@ extern bool srs_go_http_body_allowd(int status); // returns "application/octet-stream". extern std::string srs_go_http_detect(char* data, int size); -// state of message +// The state of HTTP message enum SrsHttpParseState { SrsHttpParseStateInit = 0, SrsHttpParseStateStart, @@ -121,27 +121,17 @@ public: // with CanonicalHeaderKey. virtual std::string get(std::string key); public: - /** - * get the content length. -1 if not set. - */ + // Get the content length. -1 if not set. virtual int64_t content_length(); - /** - * set the content length by header "Content-Length" - */ + // set the content length by header "Content-Length" virtual void set_content_length(int64_t size); public: - /** - * get the content type. empty string if not set. - */ + // Get the content type. empty string if not set. virtual std::string content_type(); - /** - * set the content type by header "Content-Type" - */ + // set the content type by header "Content-Type" virtual void set_content_type(std::string ct); public: - /** - * write all headers to string stream. - */ + // write all headers to string stream. virtual void write(std::stringstream& ss); }; @@ -176,9 +166,9 @@ public: ISrsHttpResponseWriter(); virtual ~ISrsHttpResponseWriter(); public: - // when chunked mode, + // When chunked mode, // final the request to complete the chunked encoding. - // for no-chunked mode, + // For no-chunked mode, // final to send request, for example, content-length is 0. virtual srs_error_t final_request() = 0; @@ -191,13 +181,11 @@ public: // If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) // before writing the data. If the Header does not contain a // Content-Type line, Write adds a Content-Type set to the result of passing - // the initial 512 bytes of written data to DetectContentType. + // The initial 512 bytes of written data to DetectContentType. // @param data, the data to send. NULL to flush header only. virtual srs_error_t write(char* data, int size) = 0; - /** - * for the HTTP FLV, to writev to improve performance. - * @see https://github.com/ossrs/srs/issues/405 - */ + // for the HTTP FLV, to writev to improve performance. + // @see https://github.com/ossrs/srs/issues/405 virtual srs_error_t writev(const iovec* iov, int iovcnt, ssize_t* pnwrite) = 0; // WriteHeader sends an HTTP response header with status code. @@ -209,32 +197,26 @@ public: virtual void write_header(int code) = 0; }; -/** - * the reader interface for http response. - */ +// The reader interface for http response. class ISrsHttpResponseReader { public: ISrsHttpResponseReader(); virtual ~ISrsHttpResponseReader(); public: - /** - * whether response read EOF. - */ + // Whether response read EOF. virtual bool eof() = 0; - /** - * read from the response body. - * @param data, the buffer to read data buffer to. - * @param nb_data, the max size of data buffer. - * @param nb_read, the actual read size of bytes. NULL to ignore. - * @remark when eof(), return error. - * @remark for some server, the content-length not specified and not chunked, - * which is actually the infinite chunked encoding, which after http header - * is http response data, it's ok for browser. that is, - * when user call this read, please ensure there is data to read(by content-length - * or by chunked), because the sdk never know whether there is no data or - * infinite chunked. - */ + // Read from the response body. + // @param data, the buffer to read data buffer to. + // @param nb_data, the max size of data buffer. + // @param nb_read, the actual read size of bytes. NULL to ignore. + // @remark when eof(), return error. + // @remark for some server, the content-length not specified and not chunked, + // which is actually the infinite chunked encoding, which after http header + // is http response data, it's ok for browser. that is, + // when user call this read, please ensure there is data to read(by content-length + // or by chunked), because the sdk never know whether there is no data or + // infinite chunked. virtual srs_error_t read(char* data, int nb_data, int* nb_read) = 0; }; @@ -245,7 +227,7 @@ public: // ServeHTTP should write reply headers and data to the ResponseWriter // and then return. Returning signals that the request is finished // and that the HTTP server can move on to the next request on -// the connection. +// The connection. class ISrsHttpHandler { public: @@ -300,33 +282,25 @@ public: public: virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); private: - /** - * serve the file by specified path - */ + // Serve the file by specified path virtual srs_error_t serve_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); virtual srs_error_t serve_flv_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); virtual srs_error_t serve_mp4_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); protected: - /** - * when access flv file with x.flv?start=xxx - */ + // When access flv file with x.flv?start=xxx virtual srs_error_t serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int offset); - /** - * when access mp4 file with x.mp4?range=start-end - * @param start the start offset in bytes. - * @param end the end offset in bytes. -1 to end of file. - * @remark response data in [start, end]. - */ + // When access mp4 file with x.mp4?range=start-end + // @param start the start offset in bytes. + // @param end the end offset in bytes. -1 to end of file. + // @remark response data in [start, end]. virtual srs_error_t serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int start, int end); protected: - /** - * copy the fs to response writer in size bytes. - */ + // Copy the fs to response writer in size bytes. virtual srs_error_t copy(ISrsHttpResponseWriter* w, SrsFileReader* fs, ISrsHttpMessage* r, int size); }; -// the mux entry for server mux. -// the matcher info, for example, the pattern and handler. +// The mux entry for server mux. +// The matcher info, for example, the pattern and handler. class SrsHttpMuxEntry { public: @@ -339,26 +313,20 @@ public: virtual ~SrsHttpMuxEntry(); }; -/** - * the hijacker for http pattern match. - */ +// The hijacker for http pattern match. class ISrsHttpMatchHijacker { public: ISrsHttpMatchHijacker(); virtual ~ISrsHttpMatchHijacker(); public: - /** - * when match the request failed, no handler to process request. - * @param request the http request message to match the handler. - * @param ph the already matched handler, hijack can rewrite it. - */ + // When match the request failed, no handler to process request. + // @param request the http request message to match the handler. + // @param ph the already matched handler, hijack can rewrite it. virtual srs_error_t hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph) = 0; }; -/** - * the server mux, all http server should implements it. - */ +// The server mux, all http server should implements it. class ISrsHttpServeMux { public: @@ -383,7 +351,7 @@ public: // "/images/" subtree. // // Note that since a pattern ending in a slash names a rooted subtree, -// the pattern "/" matches all paths not matched by other registered +// The pattern "/" matches all paths not matched by other registered // patterns, not just the URL with Path == "/". // // Patterns may optionally begin with a host name, restricting matches to @@ -398,29 +366,25 @@ public: class SrsHttpServeMux : public ISrsHttpServeMux { private: - // the pattern handler, to handle the http request. + // The pattern handler, to handle the http request. std::map entries; - // the vhost handler. - // when find the handler to process the request, + // The vhost handler. + // When find the handler to process the request, // append the matched vhost when pattern not starts with /, - // for example, for pattern /live/livestream.flv of vhost ossrs.net, - // the path will rewrite to ossrs.net/live/livestream.flv + // For example, for pattern /live/livestream.flv of vhost ossrs.net, + // The path will rewrite to ossrs.net/live/livestream.flv std::map vhosts; // all hijackers for http match. - // for example, the hstrs(http stream trigger rtmp source) + // For example, the hstrs(http stream trigger rtmp source) // can hijack and install handler when request incoming and no handler. std::vector hijackers; public: SrsHttpServeMux(); virtual ~SrsHttpServeMux(); public: - /** - * initialize the http serve mux. - */ + // Initialize the http serve mux. virtual srs_error_t initialize(); - /** - * hijack the http match. - */ + // hijack the http match. virtual void hijack(ISrsHttpMatchHijacker* h); virtual void unhijack(ISrsHttpMatchHijacker* h); public: @@ -437,10 +401,8 @@ private: virtual bool path_match(std::string pattern, std::string path); }; -/** - * The filter http mux, directly serve the http CORS requests, - * while proxy to the worker mux for services. - */ +// The filter http mux, directly serve the http CORS requests, +// while proxy to the worker mux for services. class SrsHttpCorsMux : public ISrsHttpServeMux { private: @@ -457,7 +419,7 @@ public: virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); }; -// for http header. +// For http header. typedef std::pair SrsHttpHeaderField; // A Request represents an HTTP request received by a server @@ -473,34 +435,28 @@ typedef std::pair SrsHttpHeaderField; // 3. no body or user not confirmed infinite chunked. // For example: // ISrsHttpMessage* r = ...; -// while (!r->eof()) r->read(); // read in mode 1 or 3. +// while (!r->eof()) r->read(); // Read in mode 1 or 3. // For some server, we can confirm the body is infinite chunked: // ISrsHttpMessage* r = ...; // r->enter_infinite_chunked(); -// while (!r->eof()) r->read(); // read in mode 2 +// while (!r->eof()) r->read(); // Read in mode 2 // @rmark for mode 2, the infinite chunked, all left data is body. class ISrsHttpMessage { private: - /** - * use a buffer to read and send ts file. - */ + // Use a buffer to read and send ts file. // TODO: FIXME: remove it. char* _http_ts_send_buffer; public: ISrsHttpMessage(); virtual ~ISrsHttpMessage(); public: - /** - * the http request level cache. - */ + // The http request level cache. virtual char* http_ts_send_buffer(); public: virtual uint8_t method() = 0; virtual uint16_t status_code() = 0; - /** - * method helpers. - */ + // Method helpers. virtual std::string method_str() = 0; virtual bool is_http_get() = 0; virtual bool is_http_put() = 0; @@ -508,94 +464,74 @@ public: virtual bool is_http_delete() = 0; virtual bool is_http_options() = 0; public: - /** - * whether should keep the connection alive. - */ + // Whether should keep the connection alive. virtual bool is_keep_alive() = 0; - /** - * the uri contains the host and path. - */ + // The uri contains the host and path. virtual std::string uri() = 0; - /** - * the url maybe the path. - */ + // The url maybe the path. virtual std::string url() = 0; virtual std::string host() = 0; virtual std::string path() = 0; virtual std::string query() = 0; virtual std::string ext() = 0; - /** - * get the RESTful id, - * for example, pattern is /api/v1/streams, path is /api/v1/streams/100, - * then the rest id is 100. - * @param pattern the handler pattern which will serve the request. - * @return the REST id; -1 if not matched. - */ + // Get the RESTful id, + // for example, pattern is /api/v1/streams, path is /api/v1/streams/100, + // then the rest id is 100. + // @param pattern the handler pattern which will serve the request. + // @return the REST id; -1 if not matched. virtual int parse_rest_id(std::string pattern) = 0; public: - /** - * the left all data is chunked body, the infinite chunked mode, - * which is chunked encoding without chunked header. - * @remark error when message is in chunked or content-length specified. - */ + // The left all data is chunked body, the infinite chunked mode, + // which is chunked encoding without chunked header. + // @remark error when message is in chunked or content-length specified. virtual srs_error_t enter_infinite_chunked() = 0; - /** - * read body to string. - * @remark for small http body. - */ + // Read body to string. + // @remark for small http body. virtual srs_error_t body_read_all(std::string& body) = 0; - /** - * get the body reader, to read one by one. - * @remark when body is very large, or chunked, use this. - */ + // Get the body reader, to read one by one. + // @remark when body is very large, or chunked, use this. virtual ISrsHttpResponseReader* body_reader() = 0; - /** - * the content length, -1 for chunked or not set. - */ + // The content length, -1 for chunked or not set. virtual int64_t content_length() = 0; public: - /** - * get the param in query string, - * for instance, query is "start=100&end=200", - * then query_get("start") is "100", and query_get("end") is "200" - */ + // Get the param in query string, + // for instance, query is "start=100&end=200", + // then query_get("start") is "100", and query_get("end") is "200" virtual std::string query_get(std::string key) = 0; - /** - * get the headers. - */ + // Get the headers. virtual int request_header_count() = 0; virtual std::string request_header_key_at(int index) = 0; virtual std::string request_header_value_at(int index) = 0; public: - /** - * whether the current request is JSONP, - * which has a "callback=xxx" in QueryString. - */ + // Whether the current request is JSONP, + // which has a "callback=xxx" in QueryString. virtual bool is_jsonp() = 0; }; #endif -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ +// The http-parser is license under MIT at https://github.com/nodejs/http-parser/blob/master/LICENSE-MIT +// Version: 2.1 from https://github.com/nodejs/http-parser/releases/tag/v2.1 + +//Copyright Joyent, Inc. and other Node contributors. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// The SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. #ifndef http_parser_h #define http_parser_h #ifdef __cplusplus @@ -621,9 +557,8 @@ extern "C" { #include #endif - /* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run - * faster - */ + // Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run + // faster #ifndef HTTP_PARSER_STRICT # define HTTP_PARSER_STRICT 1 #endif @@ -636,19 +571,18 @@ extern "C" { typedef struct http_parser_settings http_parser_settings; - /* Callbacks should return non-zero to indicate an error. The parser will - * then halt execution. - * - * The one exception is on_headers_complete. In a HTTP_RESPONSE parser - * returning '1' from on_headers_complete will tell the parser that it - * should not expect a body. This is used when receiving a response to a - * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding: - * chunked' headers that indicate the presence of a body. - * - * http_data_cb does not return data chunks. It will be call arbitrarally - * many times for each string. E.G. you might get 10 callbacks for "on_url" - * each providing just a few characters more data. - */ + // Callbacks should return non-zero to indicate an error. The parser will + // then halt execution. + // + // The one exception is on_headers_complete. In a HTTP_RESPONSE parser + // returning '1' from on_headers_complete will tell the parser that it + // should not expect a body. This is used when receiving a response to a + // HEAD request which may contain 'Content-Length' or 'Transfer-Encoding: + // chunked' headers that indicate the presence of a body. + // + // http_data_cb does not return data chunks. It will be call arbitrarally + // many times for each string. E.G. you might get 10 callbacks for "on_url" + // each providing just a few characters more data. typedef int (*http_data_cb) (http_parser*, const char *at, size_t length); typedef int (*http_cb) (http_parser*); @@ -709,10 +643,8 @@ extern "C" { }; - /* Map for errno-related constants - * - * The provided argument should be a macro that takes 2 arguments. - */ + // Map for errno-related constants + // The provided argument should be a macro that takes 2 arguments. #define HTTP_ERRNO_MAP(XX) \ /* No error */ \ XX(OK, "success") \ @@ -785,11 +717,10 @@ extern "C" { unsigned char method; /* requests only */ unsigned char http_errno : 7; - /* 1 = Upgrade header was present and the parser has exited because of that. - * 0 = No upgrade header present. - * Should be checked when http_parser_execute() returns in addition to - * error checking. - */ + // 1 = Upgrade header was present and the parser has exited because of that. + // 0 = No upgrade header present. + // Should be checked when http_parser_execute() returns in addition to + // error checking. unsigned char upgrade : 1; /** PUBLIC **/ @@ -821,13 +752,11 @@ extern "C" { }; - /* Result structure for http_parser_parse_url(). - * - * Callers should index into field_data[] with UF_* values iff field_set - * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and - * because we probably have padding left over), we convert any port to - * a uint16_t. - */ + // Result structure for http_parser_parse_url(). + // Callers should index into field_data[] with UF_* values iff field_set + // has the relevant (1 << UF_*) bit set. As a courtesy to clients (and + // because we probably have padding left over), we convert any port to + // a uint16_t. struct http_parser_url { uint16_t field_set; /* Bitmask of (1 << UF_*) values */ uint16_t port; /* Converted UF_PORT string */ @@ -848,12 +777,11 @@ extern "C" { size_t len); - /* If http_should_keep_alive() in the on_headers_complete or - * on_message_complete callback returns 0, then this should be - * the last message on the connection. - * If you are the server, respond with the "Connection: close" header. - * If you are the client, close the connection. - */ + // If http_should_keep_alive() in the on_headers_complete or + // on_message_complete callback returns 0, then this should be + // The last message on the connection. + // If you are the server, respond with the "Connection: close" header. + // If you are the client, close the connection. int http_should_keep_alive(const http_parser *parser); /* Returns a string version of the HTTP method. */ @@ -881,9 +809,7 @@ extern "C" { #endif #endif -/** - * used to resolve the http uri. - */ +// Used to resolve the http uri. class SrsHttpUri { private: @@ -897,9 +823,7 @@ public: SrsHttpUri(); virtual ~SrsHttpUri(); public: - /** - * initialize the http uri. - */ + // Initialize the http uri. virtual srs_error_t initialize(std::string _url); public: virtual std::string get_url(); @@ -909,10 +833,8 @@ public: virtual std::string get_path(); virtual std::string get_query(); private: - /** - * get the parsed url field. - * @return return empty string if not set. - */ + // Get the parsed url field. + // @return return empty string if not set. virtual std::string get_uri_field(std::string uri, http_parser_url* hp_u, http_parser_url_fields field); }; diff --git a/trunk/src/protocol/srs_protocol_json.hpp b/trunk/src/protocol/srs_protocol_json.hpp index 4fa5702cc..1eedd9b23 100644 --- a/trunk/src/protocol/srs_protocol_json.hpp +++ b/trunk/src/protocol/srs_protocol_json.hpp @@ -32,7 +32,7 @@ //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -// json decode +// JSON decode // 1. SrsJsonAny: read any from str:char* // SrsJsonAny* any = NULL; // if ((any = SrsJsonAny::loads(str)) == NULL) { @@ -45,7 +45,7 @@ // string v = any->to_str(); // } // -// for detail usage, see interfaces of each object. +// For detail usage, see interfaces of each object. //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// @@ -59,8 +59,8 @@ class SrsJsonAny { public: char marker; - // donot directly create this object, - // instead, for examle, use SrsJsonAny::str() to create a concreated one. + // Don't directly create this object, + // please use SrsJsonAny::str() to create a concreated one. protected: SrsJsonAny(); public: @@ -74,35 +74,23 @@ public: virtual bool is_array(); virtual bool is_null(); public: - /** - * get the string of any when is_string() indicates true. - * user must ensure the type is a string, or assert failed. - */ + // Get the string of any when is_string() indicates true. + // user must ensure the type is a string, or assert failed. virtual std::string to_str(); - /** - * get the boolean of any when is_boolean() indicates true. - * user must ensure the type is a boolean, or assert failed. - */ + // Get the boolean of any when is_boolean() indicates true. + // user must ensure the type is a boolean, or assert failed. virtual bool to_boolean(); - /** - * get the integer of any when is_integer() indicates true. - * user must ensure the type is a integer, or assert failed. - */ + // Get the integer of any when is_integer() indicates true. + // user must ensure the type is a integer, or assert failed. virtual int64_t to_integer(); - /** - * get the number of any when is_number() indicates true. - * user must ensure the type is a number, or assert failed. - */ + // Get the number of any when is_number() indicates true. + // user must ensure the type is a number, or assert failed. virtual double to_number(); - /** - * get the object of any when is_object() indicates true. - * user must ensure the type is a object, or assert failed. - */ + // Get the object of any when is_object() indicates true. + // user must ensure the type is a object, or assert failed. virtual SrsJsonObject* to_object(); - /** - * get the ecma array of any when is_ecma_array() indicates true. - * user must ensure the type is a ecma array, or assert failed. - */ + // Get the ecma array of any when is_ecma_array() indicates true. + // user must ensure the type is a ecma array, or assert failed. virtual SrsJsonArray* to_array(); public: virtual std::string dumps(); @@ -117,10 +105,8 @@ public: static SrsJsonObject* object(); static SrsJsonArray* array(); public: - /** - * read json tree from string. - * @return json object. NULL if error. - */ + // Read json tree from string. + // @return json object. NULL if error. static SrsJsonAny* loads(const std::string& str); }; @@ -130,7 +116,7 @@ private: typedef std::pair SrsJsonObjectPropertyType; std::vector properties; private: - // use SrsJsonAny::object() to create it. + // Use SrsJsonAny::object() to create it. friend class SrsJsonAny; SrsJsonObject(); public: @@ -161,7 +147,7 @@ private: std::vector properties; private: - // use SrsJsonAny::array() to create it. + // Use SrsJsonAny::array() to create it. friend class SrsJsonAny; SrsJsonArray(); public: @@ -181,6 +167,6 @@ public: //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -// json encode, please use JSON.dumps() to encode json object. +// JSON encode, please use JSON.dumps() to encode json object. #endif diff --git a/trunk/src/protocol/srs_raw_avc.hpp b/trunk/src/protocol/srs_raw_avc.hpp index 620534bf4..36fbfe411 100644 --- a/trunk/src/protocol/srs_raw_avc.hpp +++ b/trunk/src/protocol/srs_raw_avc.hpp @@ -32,61 +32,45 @@ class SrsBuffer; -/** - * the raw h.264 stream, in annexb. - */ +// The raw h.264 stream, in annexb. class SrsRawH264Stream { public: SrsRawH264Stream(); virtual ~SrsRawH264Stream(); public: - /** - * demux the stream in annexb format. - * @param stream the input stream bytes. - * @param pframe the output h.264 frame in stream. user should never free it. - * @param pnb_frame the output h.264 frame size. - */ + // Demux the stream in annexb format. + // @param stream the input stream bytes. + // @param pframe the output h.264 frame in stream. user should never free it. + // @param pnb_frame the output h.264 frame size. virtual srs_error_t annexb_demux(SrsBuffer* stream, char** pframe, int* pnb_frame); - /** - * whether the frame is sps or pps. - */ + // whether the frame is sps or pps. virtual bool is_sps(char* frame, int nb_frame); virtual bool is_pps(char* frame, int nb_frame); - /** - * demux the sps or pps to string. - * @param sps/pps output the sps/pps. - */ + // Demux the sps or pps to string. + // @param sps/pps output the sps/pps. virtual srs_error_t sps_demux(char* frame, int nb_frame, std::string& sps); virtual srs_error_t pps_demux(char* frame, int nb_frame, std::string& pps); public: - /** - * h264 raw data to h264 packet, without flv payload header. - * mux the sps/pps to flv sequence header packet. - * @param sh output the sequence header. - */ + // The h264 raw data to h264 packet, without flv payload header. + // Mux the sps/pps to flv sequence header packet. + // @param sh output the sequence header. virtual srs_error_t mux_sequence_header(std::string sps, std::string pps, uint32_t dts, uint32_t pts, std::string& sh); - /** - * h264 raw data to h264 packet, without flv payload header. - * mux the ibp to flv ibp packet. - * @param ibp output the packet. - * @param frame_type output the frame type. - */ + // The h264 raw data to h264 packet, without flv payload header. + // Mux the ibp to flv ibp packet. + // @param ibp output the packet. + // @param frame_type output the frame type. virtual srs_error_t mux_ipb_frame(char* frame, int nb_frame, std::string& ibp); - /** - * mux the avc video packet to flv video packet. - * @param frame_type, SrsVideoAvcFrameTypeKeyFrame or SrsVideoAvcFrameTypeInterFrame. - * @param avc_packet_type, SrsVideoAvcFrameTraitSequenceHeader or SrsVideoAvcFrameTraitNALU. - * @param video the h.264 raw data. - * @param flv output the muxed flv packet. - * @param nb_flv output the muxed flv size. - */ + // Mux the avc video packet to flv video packet. + // @param frame_type, SrsVideoAvcFrameTypeKeyFrame or SrsVideoAvcFrameTypeInterFrame. + // @param avc_packet_type, SrsVideoAvcFrameTraitSequenceHeader or SrsVideoAvcFrameTraitNALU. + // @param video the h.264 raw data. + // @param flv output the muxed flv packet. + // @param nb_flv output the muxed flv size. virtual srs_error_t mux_avc2flv(std::string video, int8_t frame_type, int8_t avc_packet_type, uint32_t dts, uint32_t pts, char** flv, int* nb_flv); }; -/** - * the header of adts sample. - */ +// The header of adts sample. struct SrsRawAacStreamCodec { int8_t protection_absent; @@ -103,37 +87,29 @@ struct SrsRawAacStreamCodec int8_t aac_packet_type; }; -/** - * the raw aac stream, in adts. - */ +// The raw aac stream, in adts. class SrsRawAacStream { public: SrsRawAacStream(); virtual ~SrsRawAacStream(); public: - /** - * demux the stream in adts format. - * @param stream the input stream bytes. - * @param pframe the output aac frame in stream. user should never free it. - * @param pnb_frame the output aac frame size. - * @param codec the output codec info. - */ + // Demux the stream in adts format. + // @param stream the input stream bytes. + // @param pframe the output aac frame in stream. user should never free it. + // @param pnb_frame the output aac frame size. + // @param codec the output codec info. virtual srs_error_t adts_demux(SrsBuffer* stream, char** pframe, int* pnb_frame, SrsRawAacStreamCodec& codec); - /** - * aac raw data to aac packet, without flv payload header. - * mux the aac specific config to flv sequence header packet. - * @param sh output the sequence header. - */ + // Mux aac raw data to aac packet, without flv payload header. + // Mux the aac specific config to flv sequence header packet. + // @param sh output the sequence header. virtual srs_error_t mux_sequence_header(SrsRawAacStreamCodec* codec, std::string& sh); - /** - * mux the aac audio packet to flv audio packet. - * @param frame the aac raw data. - * @param nb_frame the count of aac frame. - * @param codec the codec info of aac. - * @param flv output the muxed flv packet. - * @param nb_flv output the muxed flv size. - */ + // Mux the aac audio packet to flv audio packet. + // @param frame the aac raw data. + // @param nb_frame the count of aac frame. + // @param codec the codec info of aac. + // @param flv output the muxed flv packet. + // @param nb_flv output the muxed flv size. virtual srs_error_t mux_aac2flv(char* frame, int nb_frame, SrsRawAacStreamCodec* codec, uint32_t dts, char** flv, int* nb_flv); }; diff --git a/trunk/src/protocol/srs_rtmp_handshake.hpp b/trunk/src/protocol/srs_rtmp_handshake.hpp index befdb2d78..9029e55fd 100644 --- a/trunk/src/protocol/srs_rtmp_handshake.hpp +++ b/trunk/src/protocol/srs_rtmp_handshake.hpp @@ -31,21 +31,19 @@ class SrsComplexHandshake; class SrsHandshakeBytes; class SrsBuffer; -// for openssl. +// For openssl. #include namespace _srs_internal { - // the digest key generate size. + // The digest key generate size. #define SRS_OpensslHashSize 512 extern uint8_t SrsGenuineFMSKey[]; extern uint8_t SrsGenuineFPKey[]; srs_error_t openssl_HMACsha256(const void* key, int key_size, const void* data, int data_size, void* digest); srs_error_t openssl_generate_key(char* public_key, int32_t size); - /** - * the DH wrapper. - */ + // The DH wrapper. class SrsDH { private: @@ -56,62 +54,48 @@ namespace _srs_internal private: virtual void close(); public: - /** - * initialize dh, generate the public and private key. - * @param ensure_128bytes_public_key whether ensure public key is 128bytes, - * sometimes openssl generate 127bytes public key. - * default to false to donot ensure. - */ + // Initialize dh, generate the public and private key. + // @param ensure_128bytes_public_key whether ensure public key is 128bytes, + // sometimes openssl generate 127bytes public key. + // default to false to donot ensure. virtual srs_error_t initialize(bool ensure_128bytes_public_key = false); - /** - * copy the public key. - * @param pkey the bytes to copy the public key. - * @param pkey_size the max public key size, output the actual public key size. - * user should never ignore this size. - * @remark, when ensure_128bytes_public_key, the size always 128. - */ + // Copy the public key. + // @param pkey the bytes to copy the public key. + // @param pkey_size the max public key size, output the actual public key size. + // user should never ignore this size. + // @remark, when ensure_128bytes_public_key, the size always 128. virtual srs_error_t copy_public_key(char* pkey, int32_t& pkey_size); - /** - * generate and copy the shared key. - * generate the shared key with peer public key. - * @param ppkey peer public key. - * @param ppkey_size the size of ppkey. - * @param skey the computed shared key. - * @param skey_size the max shared key size, output the actual shared key size. - * user should never ignore this size. - */ + // Generate and copy the shared key. + // Generate the shared key with peer public key. + // @param ppkey peer public key. + // @param ppkey_size the size of ppkey. + // @param skey the computed shared key. + // @param skey_size the max shared key size, output the actual shared key size. + // user should never ignore this size. virtual srs_error_t copy_shared_key(const char* ppkey, int32_t ppkey_size, char* skey, int32_t& skey_size); private: virtual srs_error_t do_initialize(); }; - /** - * the schema type. - */ + // The schema type. enum srs_schema_type { srs_schema_invalid = 2, - /** - * key-digest sequence - */ + // The key-digest sequence srs_schema0 = 0, - /** - * digest-key sequence - * @remark, FMS requires the schema1(digest-key), or connect failed. - */ + // The digest-key sequence + // @remark, FMS requires the schema1(digest-key), or connect failed. // srs_schema1 = 1, }; - /** - * 764bytes key structure - * random-data: (offset)bytes - * key-data: 128bytes - * random-data: (764-offset-128-4)bytes - * offset: 4bytes - * @see also: http://blog.csdn.net/win_lin/article/details/13006803 - */ + // The 764bytes key structure + // random-data: (offset)bytes + // key-data: 128bytes + // random-data: (764-offset-128-4)bytes + // offset: 4bytes + // @see also: http://blog.csdn.net/win_lin/article/details/13006803 class key_block { public: @@ -132,24 +116,22 @@ namespace _srs_internal key_block(); virtual ~key_block(); public: - // parse key block from c1s1. + // Parse key block from c1s1. // if created, user must free it by srs_key_block_free // @stream contains c1s1_key_bytes the key start bytes srs_error_t parse(SrsBuffer* stream); private: - // calc the offset of key, - // the key->offset cannot be used as the offset of key. + // Calculate the offset of key, + // The key->offset cannot be used as the offset of key. int calc_valid_offset(); }; - /** - * 764bytes digest structure - * offset: 4bytes - * random-data: (offset)bytes - * digest-data: 32bytes - * random-data: (764-4-offset-32)bytes - * @see also: http://blog.csdn.net/win_lin/article/details/13006803 - */ + // The 764bytes digest structure + // offset: 4bytes + // random-data: (offset)bytes + // digest-data: 32bytes + // random-data: (764-4-offset-32)bytes + // @see also: http://blog.csdn.net/win_lin/article/details/13006803 class digest_block { public: @@ -170,23 +152,21 @@ namespace _srs_internal digest_block(); virtual ~digest_block(); public: - // parse digest block from c1s1. + // Parse digest block from c1s1. // if created, user must free it by srs_digest_block_free // @stream contains c1s1_digest_bytes the digest start bytes srs_error_t parse(SrsBuffer* stream); private: - // calc the offset of digest, - // the key->offset cannot be used as the offset of digest. + // Calculate the offset of digest, + // The key->offset cannot be used as the offset of digest. int calc_valid_offset(); }; class c1s1; - /** - * the c1s1 strategy, use schema0 or schema1. - * the template method class to defines common behaviors, - * while the concrete class to implements in schema0 or schema1. - */ + // The c1s1 strategy, use schema0 or schema1. + // The template method class to defines common behaviors, + // while the concrete class to implements in schema0 or schema1. class c1s1_strategy { protected: @@ -196,114 +176,82 @@ namespace _srs_internal c1s1_strategy(); virtual ~c1s1_strategy(); public: - /** - * get the scema. - */ + // Get the scema. virtual srs_schema_type schema() = 0; - /** - * get the digest. - */ + // Get the digest. virtual char* get_digest(); - /** - * get the key. - */ + // Get the key. virtual char* get_key(); - /** - * copy to bytes. - * @param size must be 1536. - */ + // Copy to bytes. + // @param size must be 1536. virtual srs_error_t dump(c1s1* owner, char* _c1s1, int size); - /** - * server: parse the c1s1, discovery the key and digest by schema. - * use the c1_validate_digest() to valid the digest of c1. - */ + // For server: parse the c1s1, discovery the key and digest by schema. + // use the c1_validate_digest() to valid the digest of c1. virtual srs_error_t parse(char* _c1s1, int size) = 0; public: - /** - * client: create and sign c1 by schema. - * sign the c1, generate the digest. - * calc_c1_digest(c1, schema) { - * get c1s1-joined from c1 by specified schema - * digest-data = HMACsha256(c1s1-joined, FPKey, 30) - * return digest-data; - * } - * random fill 1536bytes c1 // also fill the c1-128bytes-key - * time = time() // c1[0-3] - * version = [0x80, 0x00, 0x07, 0x02] // c1[4-7] - * schema = choose schema0 or schema1 - * digest-data = calc_c1_digest(c1, schema) - * copy digest-data to c1 - */ + // For client: create and sign c1 by schema. + // sign the c1, generate the digest. + // calc_c1_digest(c1, schema) { + // get c1s1-joined from c1 by specified schema + // digest-data = HMACsha256(c1s1-joined, FPKey, 30) + // return digest-data; + // } + // random fill 1536bytes c1 // also fill the c1-128bytes-key + // time = time() // c1[0-3] + // version = [0x80, 0x00, 0x07, 0x02] // c1[4-7] + // schema = choose schema0 or schema1 + // digest-data = calc_c1_digest(c1, schema) + // copy digest-data to c1 virtual srs_error_t c1_create(c1s1* owner); - /** - * server: validate the parsed c1 schema - */ + // For server: validate the parsed c1 schema virtual srs_error_t c1_validate_digest(c1s1* owner, bool& is_valid); - /** - * server: create and sign the s1 from c1. - * // decode c1 try schema0 then schema1 - * c1-digest-data = get-c1-digest-data(schema0) - * if c1-digest-data equals to calc_c1_digest(c1, schema0) { - * c1-key-data = get-c1-key-data(schema0) - * schema = schema0 - * } else { - * c1-digest-data = get-c1-digest-data(schema1) - * if c1-digest-data not equals to calc_c1_digest(c1, schema1) { - * switch to simple handshake. - * return - * } - * c1-key-data = get-c1-key-data(schema1) - * schema = schema1 - * } - * - * // generate s1 - * random fill 1536bytes s1 - * time = time() // c1[0-3] - * version = [0x04, 0x05, 0x00, 0x01] // s1[4-7] - * s1-key-data=shared_key=DH_compute_key(peer_pub_key=c1-key-data) - * get c1s1-joined by specified schema - * s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36) - * copy s1-digest-data and s1-key-data to s1. - * @param c1, to get the peer_pub_key of client. - */ + // For server: create and sign the s1 from c1. + // // decode c1 try schema0 then schema1 + // c1-digest-data = get-c1-digest-data(schema0) + // if c1-digest-data equals to calc_c1_digest(c1, schema0) { + // c1-key-data = get-c1-key-data(schema0) + // schema = schema0 + // } else { + // c1-digest-data = get-c1-digest-data(schema1) + // if c1-digest-data not equals to calc_c1_digest(c1, schema1) { + // switch to simple handshake. + // return + // } + // c1-key-data = get-c1-key-data(schema1) + // schema = schema1 + // } + // + // // Generate s1 + // random fill 1536bytes s1 + // time = time() // c1[0-3] + // version = [0x04, 0x05, 0x00, 0x01] // s1[4-7] + // s1-key-data=shared_key=DH_compute_key(peer_pub_key=c1-key-data) + // get c1s1-joined by specified schema + // s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36) + // copy s1-digest-data and s1-key-data to s1. + // @param c1, to get the peer_pub_key of client. virtual srs_error_t s1_create(c1s1* owner, c1s1* c1); - /** - * server: validate the parsed s1 schema - */ + // For server: validate the parsed s1 schema virtual srs_error_t s1_validate_digest(c1s1* owner, bool& is_valid); public: - /** - * calc the digest for c1 - */ + // Calculate the digest for c1 virtual srs_error_t calc_c1_digest(c1s1* owner, char*& c1_digest); - /** - * calc the digest for s1 - */ + // Calculate the digest for s1 virtual srs_error_t calc_s1_digest(c1s1* owner, char*& s1_digest); - /** - * copy whole c1s1 to bytes. - * @param size must always be 1536 with digest, and 1504 without digest. - */ + // Copy whole c1s1 to bytes. + // @param size must always be 1536 with digest, and 1504 without digest. virtual srs_error_t copy_to(c1s1* owner, char* bytes, int size, bool with_digest) = 0; - /** - * copy time and version to stream. - */ + // Copy time and version to stream. virtual void copy_time_version(SrsBuffer* stream, c1s1* owner); - /** - * copy key to stream. - */ + // Copy key to stream. virtual void copy_key(SrsBuffer* stream); - /** - * copy digest to stream. - */ + // Copy digest to stream. virtual void copy_digest(SrsBuffer* stream, bool with_digest); }; - /** - * c1s1 schema0 - * key: 764bytes - * digest: 764bytes - */ + // The c1s1 schema0 + // key: 764bytes + // digest: 764bytes class c1s1_strategy_schema0 : public c1s1_strategy { public: @@ -316,11 +264,9 @@ namespace _srs_internal virtual srs_error_t copy_to(c1s1* owner, char* bytes, int size, bool with_digest); }; - /** - * c1s1 schema1 - * digest: 764bytes - * key: 764bytes - */ + // The c1s1 schema1 + // digest: 764bytes + // key: 764bytes class c1s1_strategy_schema1 : public c1s1_strategy { public: @@ -333,19 +279,17 @@ namespace _srs_internal virtual srs_error_t copy_to(c1s1* owner, char* bytes, int size, bool with_digest); }; - /** - * c1s1 schema0 - * time: 4bytes - * version: 4bytes - * key: 764bytes - * digest: 764bytes - * c1s1 schema1 - * time: 4bytes - * version: 4bytes - * digest: 764bytes - * key: 764bytes - * @see also: http://blog.csdn.net/win_lin/article/details/13006803 - */ + // The c1s1 schema0 + // time: 4bytes + // version: 4bytes + // key: 764bytes + // digest: 764bytes + // The c1s1 schema1 + // time: 4bytes + // version: 4bytes + // digest: 764bytes + // key: 764bytes + // @see also: http://blog.csdn.net/win_lin/article/details/13006803 class c1s1 { public: @@ -359,92 +303,72 @@ namespace _srs_internal c1s1(); virtual ~c1s1(); public: - /** - * get the scema. - */ + // Get the scema. virtual srs_schema_type schema(); - /** - * get the digest key. - */ + // Get the digest key. virtual char* get_digest(); - /** - * get the key. - */ + // Get the key. virtual char* get_key(); public: - /** - * copy to bytes. - * @param size, must always be 1536. - */ + // Copy to bytes. + // @param size, must always be 1536. virtual srs_error_t dump(char* _c1s1, int size); - /** - * server: parse the c1s1, discovery the key and digest by schema. - * @param size, must always be 1536. - * use the c1_validate_digest() to valid the digest of c1. - * use the s1_validate_digest() to valid the digest of s1. - */ + // For server: parse the c1s1, discovery the key and digest by schema. + // @param size, must always be 1536. + // use the c1_validate_digest() to valid the digest of c1. + // use the s1_validate_digest() to valid the digest of s1. virtual srs_error_t parse(char* _c1s1, int size, srs_schema_type _schema); public: - /** - * client: create and sign c1 by schema. - * sign the c1, generate the digest. - * calc_c1_digest(c1, schema) { - * get c1s1-joined from c1 by specified schema - * digest-data = HMACsha256(c1s1-joined, FPKey, 30) - * return digest-data; - * } - * random fill 1536bytes c1 // also fill the c1-128bytes-key - * time = time() // c1[0-3] - * version = [0x80, 0x00, 0x07, 0x02] // c1[4-7] - * schema = choose schema0 or schema1 - * digest-data = calc_c1_digest(c1, schema) - * copy digest-data to c1 - */ + // For client: create and sign c1 by schema. + // sign the c1, generate the digest. + // calc_c1_digest(c1, schema) { + // get c1s1-joined from c1 by specified schema + // digest-data = HMACsha256(c1s1-joined, FPKey, 30) + // return digest-data; + // } + // random fill 1536bytes c1 // also fill the c1-128bytes-key + // time = time() // c1[0-3] + // version = [0x80, 0x00, 0x07, 0x02] // c1[4-7] + // schema = choose schema0 or schema1 + // digest-data = calc_c1_digest(c1, schema) + // copy digest-data to c1 virtual srs_error_t c1_create(srs_schema_type _schema); - /** - * server: validate the parsed c1 schema - */ + // For server: validate the parsed c1 schema virtual srs_error_t c1_validate_digest(bool& is_valid); public: - /** - * server: create and sign the s1 from c1. - * // decode c1 try schema0 then schema1 - * c1-digest-data = get-c1-digest-data(schema0) - * if c1-digest-data equals to calc_c1_digest(c1, schema0) { - * c1-key-data = get-c1-key-data(schema0) - * schema = schema0 - * } else { - * c1-digest-data = get-c1-digest-data(schema1) - * if c1-digest-data not equals to calc_c1_digest(c1, schema1) { - * switch to simple handshake. - * return - * } - * c1-key-data = get-c1-key-data(schema1) - * schema = schema1 - * } - * - * // generate s1 - * random fill 1536bytes s1 - * time = time() // c1[0-3] - * version = [0x04, 0x05, 0x00, 0x01] // s1[4-7] - * s1-key-data=shared_key=DH_compute_key(peer_pub_key=c1-key-data) - * get c1s1-joined by specified schema - * s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36) - * copy s1-digest-data and s1-key-data to s1. - */ + // For server: create and sign the s1 from c1. + // // decode c1 try schema0 then schema1 + // c1-digest-data = get-c1-digest-data(schema0) + // if c1-digest-data equals to calc_c1_digest(c1, schema0) { + // c1-key-data = get-c1-key-data(schema0) + // schema = schema0 + // } else { + // c1-digest-data = get-c1-digest-data(schema1) + // if c1-digest-data not equals to calc_c1_digest(c1, schema1) { + // switch to simple handshake. + // return + // } + // c1-key-data = get-c1-key-data(schema1) + // schema = schema1 + // } + // + // // Generate s1 + // random fill 1536bytes s1 + // time = time() // c1[0-3] + // version = [0x04, 0x05, 0x00, 0x01] // s1[4-7] + // s1-key-data=shared_key=DH_compute_key(peer_pub_key=c1-key-data) + // get c1s1-joined by specified schema + // s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36) + // copy s1-digest-data and s1-key-data to s1. virtual srs_error_t s1_create(c1s1* c1); - /** - * server: validate the parsed s1 schema - */ + // For server: validate the parsed s1 schema virtual srs_error_t s1_validate_digest(bool& is_valid); }; - /** - * the c2s2 complex handshake structure. - * random-data: 1504bytes - * digest-data: 32bytes - * @see also: http://blog.csdn.net/win_lin/article/details/13006803 - */ + // The c2s2 complex handshake structure. + // random-data: 1504bytes + // digest-data: 32bytes + // @see also: http://blog.csdn.net/win_lin/article/details/13006803 class c2s2 { public: @@ -454,85 +378,65 @@ namespace _srs_internal c2s2(); virtual ~c2s2(); public: - /** - * copy to bytes. - * @param size, must always be 1536. - */ + // Copy to bytes. + // @param size, must always be 1536. virtual srs_error_t dump(char* _c2s2, int size); - /** - * parse the c2s2 - * @param size, must always be 1536. - */ + // Parse the c2s2 + // @param size, must always be 1536. virtual srs_error_t parse(char* _c2s2, int size); public: - /** - * create c2. - * random fill c2s2 1536 bytes - * - * // client generate C2, or server valid C2 - * temp-key = HMACsha256(s1-digest, FPKey, 62) - * c2-digest-data = HMACsha256(c2-random-data, temp-key, 32) - */ + // Create c2. + // random fill c2s2 1536 bytes + // + // // client generate C2, or server valid C2 + // temp-key = HMACsha256(s1-digest, FPKey, 62) + // c2-digest-data = HMACsha256(c2-random-data, temp-key, 32) virtual srs_error_t c2_create(c1s1* s1); - /** - * validate the c2 from client. - */ + // Validate the c2 from client. virtual srs_error_t c2_validate(c1s1* s1, bool& is_valid); public: - /** - * create s2. - * random fill c2s2 1536 bytes - * - * // server generate S2, or client valid S2 - * temp-key = HMACsha256(c1-digest, FMSKey, 68) - * s2-digest-data = HMACsha256(s2-random-data, temp-key, 32) - */ + // Create s2. + // random fill c2s2 1536 bytes + // + // For server generate S2, or client valid S2 + // temp-key = HMACsha256(c1-digest, FMSKey, 68) + // s2-digest-data = HMACsha256(s2-random-data, temp-key, 32) virtual srs_error_t s2_create(c1s1* c1); - /** - * validate the s2 from server. - */ + // Validate the s2 from server. virtual srs_error_t s2_validate(c1s1* c1, bool& is_valid); }; } -/** - * simple handshake. - * user can try complex handshake first, - * rollback to simple handshake if error ERROR_RTMP_TRY_SIMPLE_HS - */ +// Simple handshake. +// user can try complex handshake first, +// rollback to simple handshake if error ERROR_RTMP_TRY_SIMPLE_HS class SrsSimpleHandshake { public: SrsSimpleHandshake(); virtual ~SrsSimpleHandshake(); public: - /** - * simple handshake. - */ + // Simple handshake. virtual srs_error_t handshake_with_client(SrsHandshakeBytes* hs_bytes, ISrsProtocolReadWriter* io); virtual srs_error_t handshake_with_server(SrsHandshakeBytes* hs_bytes, ISrsProtocolReadWriter* io); }; -/** - * rtmp complex handshake, - * @see also crtmp(crtmpserver) or librtmp, - * @see also: http://blog.csdn.net/win_lin/article/details/13006803 - */ +// Complex handshake, +// @see also crtmp(crtmpserver) or librtmp, +// @see also: http://blog.csdn.net/win_lin/article/details/13006803 class SrsComplexHandshake { public: SrsComplexHandshake(); virtual ~SrsComplexHandshake(); public: - /** - * complex hanshake. - * @return user must: - * continue connect app if success, - * try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS, - * otherwise, disconnect - */ + // Complex hanshake. + // @return user must: + // continue connect app if success, + // try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS, + // otherwise, disconnect virtual srs_error_t handshake_with_client(SrsHandshakeBytes* hs_bytes, ISrsProtocolReadWriter* io); virtual srs_error_t handshake_with_server(SrsHandshakeBytes* hs_bytes, ISrsProtocolReadWriter* io); }; diff --git a/trunk/src/protocol/srs_rtmp_msg_array.hpp b/trunk/src/protocol/srs_rtmp_msg_array.hpp index 90b67f158..6364829fd 100644 --- a/trunk/src/protocol/srs_rtmp_msg_array.hpp +++ b/trunk/src/protocol/srs_rtmp_msg_array.hpp @@ -28,43 +28,31 @@ class SrsSharedPtrMessage; -/** - * the class to auto free the shared ptr message array. - * when need to get some messages, for instance, from Consumer queue, - * create a message array, whose msgs can used to accept the msgs, - * then send each message and set to NULL. - * - * @remark: user must free all msgs in array, for the SRS2.0 protocol stack - * provides an api to send messages, @see send_and_free_messages - */ +// The class to auto free the shared ptr message array. +// When need to get some messages, for instance, from Consumer queue, +// create a message array, whose msgs can used to accept the msgs, +// then send each message and set to NULL. +// +// @remark: user must free all msgs in array, for the SRS2.0 protocol stack +// provides an api to send messages, @see send_and_free_messages class SrsMessageArray { public: - /** - * when user already send all msgs, please set to NULL, - * for instance, msg= msgs.msgs[i], msgs.msgs[i]=NULL, send(msg), - * where send(msg) will always send and free it. - */ + // When user already send all msgs, please set to NULL, + // for instance, msg= msgs.msgs[i], msgs.msgs[i]=NULL, send(msg), + // where send(msg) will always send and free it. SrsSharedPtrMessage** msgs; int max; public: - /** - * create msg array, initialize array to NULL ptrs. - */ + // Create msg array, initialize array to NULL ptrs. SrsMessageArray(int max_msgs); - /** - * free the msgs not sent out(not NULL). - */ + // Free the msgs not sent out(not NULL). virtual ~SrsMessageArray(); public: - /** - * free specified count of messages. - */ + // Free specified count of messages. virtual void free(int count); private: - /** - * zero initialize the message array. - */ + // Zero initialize the message array. virtual void zero(int count); }; diff --git a/trunk/src/protocol/srs_rtmp_stack.hpp b/trunk/src/protocol/srs_rtmp_stack.hpp index dd4c497bf..0159485fa 100644 --- a/trunk/src/protocol/srs_rtmp_stack.hpp +++ b/trunk/src/protocol/srs_rtmp_stack.hpp @@ -30,7 +30,7 @@ #include #include -// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213 +// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213 #ifndef _WIN32 #include #endif @@ -61,12 +61,7 @@ class SrsAmf0Object; class IMergeReadHandler; class SrsCallPacket; -/**************************************************************************** - ***************************************************************************** - ****************************************************************************/ -/** - * amf0 command message, command name macros - */ +// The amf0 command message, command name macros #define RTMP_AMF0_COMMAND_CONNECT "connect" #define RTMP_AMF0_COMMAND_CREATE_STREAM "createStream" #define RTMP_AMF0_COMMAND_CLOSE_STREAM "closeStream" @@ -82,26 +77,22 @@ class SrsCallPacket; #define RTMP_AMF0_COMMAND_PUBLISH "publish" #define RTMP_AMF0_DATA_SAMPLE_ACCESS "|RtmpSampleAccess" -/** - * the signature for packets to client. - */ +// The signature for packets to client. #define RTMP_SIG_FMS_VER "3,5,3,888" #define RTMP_SIG_AMF0_VER 0 #define RTMP_SIG_CLIENT_ID "ASAICiss" -/** - * onStatus consts. - */ +// The onStatus consts. #define StatusLevel "level" #define StatusCode "code" #define StatusDescription "description" #define StatusDetails "details" #define StatusClientId "clientid" -// status value +// The status value #define StatusLevelStatus "status" -// status error +// The status error #define StatusLevelError "error" -// code value +// The code value #define StatusCodeConnectSuccess "NetConnection.Connect.Success" #define StatusCodeConnectRejected "NetConnection.Connect.Rejected" #define StatusCodeStreamReset "NetStream.Play.Reset" @@ -112,69 +103,49 @@ class SrsCallPacket; #define StatusCodeDataStart "NetStream.Data.Start" #define StatusCodeUnpublishSuccess "NetStream.Unpublish.Success" -/**************************************************************************** - ***************************************************************************** - ****************************************************************************/ - -/** - * the decoded message payload. - * @remark we seperate the packet from message, - * for the packet focus on logic and domain data, - * the message bind to the protocol and focus on protocol, such as header. - * we can merge the message and packet, using OOAD hierachy, packet extends from message, - * it's better for me to use components -- the message use the packet as payload. - */ +// The decoded message payload. +// @remark we seperate the packet from message, +// for the packet focus on logic and domain data, +// the message bind to the protocol and focus on protocol, such as header. +// we can merge the message and packet, using OOAD hierachy, packet extends from message, +// it's better for me to use components -- the message use the packet as payload. class SrsPacket { public: SrsPacket(); virtual ~SrsPacket(); public: - /** - * the subpacket can override this encode, - * for example, video and audio will directly set the payload withou memory copy, - * other packet which need to serialize/encode to bytes by override the - * get_size and encode_packet. - */ + // The subpacket can override this encode, + // For example, video and audio will directly set the payload withou memory copy, + // other packet which need to serialize/encode to bytes by override the + // get_size and encode_packet. virtual srs_error_t encode(int& size, char*& payload); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: - /** - * subpacket must override to decode packet from stream. - * @remark never invoke the super.decode, it always failed. - */ + // The subpacket must override to decode packet from stream. + // @remark never invoke the super.decode, it always failed. virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: - /** - * the cid(chunk id) specifies the chunk to send data over. - * generally, each message perfer some cid, for example, - * all protocol control messages perfer RTMP_CID_ProtocolControl, - * SrsSetWindowAckSizePacket is protocol control message. - */ + // The cid(chunk id) specifies the chunk to send data over. + // Generally, each message perfer some cid, for example, + // all protocol control messages perfer RTMP_CID_ProtocolControl, + // SrsSetWindowAckSizePacket is protocol control message. virtual int get_prefer_cid(); - /** - * subpacket must override to provide the right message type. - * the message type set the RTMP message type in header. - */ + // The subpacket must override to provide the right message type. + // The message type set the RTMP message type in header. virtual int get_message_type(); protected: - /** - * subpacket can override to calc the packet size. - */ + // The subpacket can override to calc the packet size. virtual int get_size(); - /** - * subpacket can override to encode the payload to stream. - * @remark never invoke the super.encode_packet, it always failed. - */ + // The subpacket can override to encode the payload to stream. + // @remark never invoke the super.encode_packet, it always failed. virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * the protocol provides the rtmp-message-protocol services, - * to recv RTMP message from RTMP chunk stream, - * and to send out RTMP message over RTMP chunk stream. - */ +// The protocol provides the rtmp-message-protocol services, +// To recv RTMP message from RTMP chunk stream, +// and to send out RTMP message over RTMP chunk stream. class SrsProtocol { private: @@ -189,40 +160,28 @@ private: AckWindowSize(); }; - // peer in/out +// For peer in/out private: - /** - * underlayer socket object, send/recv bytes. - */ + // The underlayer socket object, send/recv bytes. ISrsProtocolReadWriter* skt; - /** - * requests sent out, used to build the response. - * key: transactionId - * value: the request command name - */ + // The requests sent out, used to build the response. + // key: transactionId + // value: the request command name std::map requests; -// peer in +// For peer in private: - /** - * chunk stream to decode RTMP messages. - */ + // The chunk stream to decode RTMP messages. std::map chunk_streams; - /** - * cache some frequently used chunk header. - * cs_cache, the chunk stream cache. - * @see https://github.com/ossrs/srs/issues/249 - */ + // Cache some frequently used chunk header. + // cs_cache, the chunk stream cache. + // @see https://github.com/ossrs/srs/issues/249 SrsChunkStream** cs_cache; - /** - * bytes buffer cache, recv from skt, provide services for stream. - */ + // The bytes buffer cache, recv from skt, provide services for stream. SrsFastStream* in_buffer; - /** - * input chunk size, default to 128, set by peer packet. - */ + // The input chunk size, default to 128, set by peer packet. int32_t in_chunk_size; // The input ack window, to response acknowledge to peer, - // for example, to respose the encoder, for server got lots of packets. + // For example, to respose the encoder, for server got lots of packets. AckWindowSize in_ack_size; // The output ack window, to require peer to response the ack. AckWindowSize out_ack_size; @@ -231,93 +190,69 @@ private: // Whether print the protocol level debug info. // Generally we print the debug info when got or send first A/V packet. bool show_debug_info; - /** - * whether auto response when recv messages. - * default to true for it's very easy to use the protocol stack. - * @see: https://github.com/ossrs/srs/issues/217 - */ + // Whether auto response when recv messages. + // default to true for it's very easy to use the protocol stack. + // @see: https://github.com/ossrs/srs/issues/217 bool auto_response_when_recv; - /** - * when not auto response message, manual flush the messages in queue. - */ + // When not auto response message, manual flush the messages in queue. std::vector manual_response_queue; -// peer out +// For peer out private: - /** - * cache for multiple messages send, - * initialize to iovec[SRS_CONSTS_IOVS_MAX] and realloc when consumed, - * it's ok to realloc the iovs cache, for all ptr is ok. - */ + // Cache for multiple messages send, + // initialize to iovec[SRS_CONSTS_IOVS_MAX] and realloc when consumed, + // it's ok to realloc the iovs cache, for all ptr is ok. iovec* out_iovs; int nb_out_iovs; - /** - * output header cache. - * used for type0, 11bytes(or 15bytes with extended timestamp) header. - * or for type3, 1bytes(or 5bytes with extended timestamp) header. - * the c0c3 caches must use unit SRS_CONSTS_RTMP_MAX_FMT0_HEADER_SIZE bytes. - * - * @remark, the c0c3 cache cannot be realloc. - */ + // The output header cache. + // used for type0, 11bytes(or 15bytes with extended timestamp) header. + // or for type3, 1bytes(or 5bytes with extended timestamp) header. + // The c0c3 caches must use unit SRS_CONSTS_RTMP_MAX_FMT0_HEADER_SIZE bytes. + // + // @remark, the c0c3 cache cannot be realloc. char out_c0c3_caches[SRS_CONSTS_C0C3_HEADERS_MAX]; - // whether warned user to increase the c0c3 header cache. + // Whether warned user to increase the c0c3 header cache. bool warned_c0c3_cache_dry; - /** - * output chunk size, default to 128, set by config. - */ + // The output chunk size, default to 128, set by config. int32_t out_chunk_size; public: SrsProtocol(ISrsProtocolReadWriter* io); virtual ~SrsProtocol(); public: - /** - * set the auto response message when recv for protocol stack. - * @param v, whether auto response message when recv message. - * @see: https://github.com/ossrs/srs/issues/217 - */ + // Set the auto response message when recv for protocol stack. + // @param v, whether auto response message when recv message. + // @see: https://github.com/ossrs/srs/issues/217 virtual void set_auto_response(bool v); - /** - * flush for manual response when the auto response is disabled - * by set_auto_response(false), we default use auto response, so donot - * need to call this api(the protocol sdk will auto send message). - * @see the auto_response_when_recv and manual_response_queue. - */ + // Flush for manual response when the auto response is disabled + // by set_auto_response(false), we default use auto response, so donot + // need to call this api(the protocol sdk will auto send message). + // @see the auto_response_when_recv and manual_response_queue. virtual srs_error_t manual_response_flush(); public: #ifdef SRS_PERF_MERGED_READ - /** - * to improve read performance, merge some packets then read, - * when it on and read small bytes, we sleep to wait more data., - * that is, we merge some data to read together. - * @param v true to ename merged read. - * @param handler the handler when merge read is enabled. - * @see https://github.com/ossrs/srs/issues/241 - */ + // To improve read performance, merge some packets then read, + // When it on and read small bytes, we sleep to wait more data., + // that is, we merge some data to read together. + // @param v true to ename merged read. + // @param handler the handler when merge read is enabled. + // @see https://github.com/ossrs/srs/issues/241 virtual void set_merge_read(bool v, IMergeReadHandler* handler); - /** - * create buffer with specifeid size. - * @param buffer the size of buffer. - * @remark when MR(SRS_PERF_MERGED_READ) disabled, always set to 8K. - * @remark when buffer changed, the previous ptr maybe invalid. - * @see https://github.com/ossrs/srs/issues/241 - */ + // Create buffer with specifeid size. + // @param buffer the size of buffer. + // @remark when MR(SRS_PERF_MERGED_READ) disabled, always set to 8K. + // @remark when buffer changed, the previous ptr maybe invalid. + // @see https://github.com/ossrs/srs/issues/241 virtual void set_recv_buffer(int buffer_size); #endif public: - /** - * set/get the recv timeout in srs_utime_t. - * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. - */ + // To set/get the recv timeout in srs_utime_t. + // if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. virtual void set_recv_timeout(srs_utime_t tm); virtual srs_utime_t get_recv_timeout(); - /** - * set/get the send timeout in srs_utime_t. - * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. - */ + // To set/get the send timeout in srs_utime_t. + // if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. virtual void set_send_timeout(srs_utime_t tm); virtual srs_utime_t get_send_timeout(); - /** - * get recv/send bytes. - */ + // Get recv/send bytes. virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); public: @@ -325,70 +260,58 @@ public: // but for some encoder, it never send the ack message while it default to a none zone size. // This will cause the encoder to block after publishing some messages to server, // because it wait for server to send acknowledge, but server default to 0 which means no need - // to ack encoder. We can change the default input ack size. We will always response the + // To ack encoder. We can change the default input ack size. We will always response the // ack size whatever the encoder set or not. virtual srs_error_t set_in_window_ack_size(int ack_size); public: - /** - * recv a RTMP message, which is bytes oriented. - * user can use decode_message to get the decoded RTMP packet. - * @param pmsg, set the received message, - * always NULL if error, - * NULL for unknown packet but return success. - * never NULL if decode success. - * @remark, drop message when msg is empty or payload length is empty. - */ + // Recv a RTMP message, which is bytes oriented. + // user can use decode_message to get the decoded RTMP packet. + // @param pmsg, set the received message, + // always NULL if error, + // NULL for unknown packet but return success. + // never NULL if decode success. + // @remark, drop message when msg is empty or payload length is empty. virtual srs_error_t recv_message(SrsCommonMessage** pmsg); - /** - * decode bytes oriented RTMP message to RTMP packet, - * @param ppacket, output decoded packet, - * always NULL if error, never NULL if success. - * @return error when unknown packet, error when decode failed. - */ + // Decode bytes oriented RTMP message to RTMP packet, + // @param ppacket, output decoded packet, + // always NULL if error, never NULL if success. + // @return error when unknown packet, error when decode failed. virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); - /** - * send the RTMP message and always free it. - * user must never free or use the msg after this method, - * for it will always free the msg. - * @param msg, the msg to send out, never be NULL. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ + // Send the RTMP message and always free it. + // user must never free or use the msg after this method, + // For it will always free the msg. + // @param msg, the msg to send out, never be NULL. + // @param stream_id, the stream id of packet to send over, 0 for control message. virtual srs_error_t send_and_free_message(SrsSharedPtrMessage* msg, int stream_id); - /** - * send the RTMP message and always free it. - * user must never free or use the msg after this method, - * for it will always free the msg. - * @param msgs, the msgs to send out, never be NULL. - * @param nb_msgs, the size of msgs to send out. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ + // Send the RTMP message and always free it. + // user must never free or use the msg after this method, + // For it will always free the msg. + // @param msgs, the msgs to send out, never be NULL. + // @param nb_msgs, the size of msgs to send out. + // @param stream_id, the stream id of packet to send over, 0 for control message. virtual srs_error_t send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id); - /** - * send the RTMP packet and always free it. - * user must never free or use the packet after this method, - * for it will always free the packet. - * @param packet, the packet to send out, never be NULL. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ + // Send the RTMP packet and always free it. + // user must never free or use the packet after this method, + // For it will always free the packet. + // @param packet, the packet to send out, never be NULL. + // @param stream_id, the stream id of packet to send over, 0 for control message. virtual srs_error_t send_and_free_packet(SrsPacket* packet, int stream_id); public: - /** - * expect a specified message, drop others util got specified one. - * @pmsg, user must free it. NULL if not success. - * @ppacket, user must free it, which decode from payload of message. NULL if not success. - * @remark, only when success, user can use and must free the pmsg and ppacket. - * for example: - * SrsCommonMessage* msg = NULL; - * SrsConnectAppResPacket* pkt = NULL; - * if ((ret = protocol->expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { - * return ret; - * } - * // use then free msg and pkt - * srs_freep(msg); - * srs_freep(pkt); - * user should never recv message and convert it, use this method instead. - * if need to set timeout, use set timeout of SrsProtocol. - */ + // Expect a specified message, drop others util got specified one. + // @pmsg, user must free it. NULL if not success. + // @ppacket, user must free it, which decode from payload of message. NULL if not success. + // @remark, only when success, user can use and must free the pmsg and ppacket. + // For example: + // SrsCommonMessage* msg = NULL; + // SrsConnectAppResPacket* pkt = NULL; + // if ((ret = protocol->expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + // return ret; + // } + // // Use then free msg and pkt + // srs_freep(msg); + // srs_freep(pkt); + // user should never recv message and convert it, use this method instead. + // if need to set timeout, use set timeout of SrsProtocol. template srs_error_t expect_message(SrsCommonMessage** pmsg, T** ppacket) { @@ -425,150 +348,106 @@ public: return err; } private: - /** - * send out the messages, donot free it, - * the caller must free the param msgs. - */ + // Send out the messages, donot free it, + // The caller must free the param msgs. virtual srs_error_t do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs); - /** - * send iovs. send multiple times if exceed limits. - */ + // Send iovs. send multiple times if exceed limits. virtual srs_error_t do_iovs_send(iovec* iovs, int size); - /** - * underlayer api for send and free packet. - */ + // The underlayer api for send and free packet. virtual srs_error_t do_send_and_free_packet(SrsPacket* packet, int stream_id); - /** - * use simple algorithm to send the header and bytes. - * @remark, for do_send_and_free_packet to send. - */ + // Use simple algorithm to send the header and bytes. + // @remark, for do_send_and_free_packet to send. virtual srs_error_t do_simple_send(SrsMessageHeader* mh, char* payload, int size); - /** - * imp for decode_message - */ + // The imp for decode_message virtual srs_error_t do_decode_message(SrsMessageHeader& header, SrsBuffer* stream, SrsPacket** ppacket); - /** - * recv bytes oriented RTMP message from protocol stack. - * return error if error occur and nerver set the pmsg, - * return success and pmsg set to NULL if no entire message got, - * return success and pmsg set to entire message if got one. - */ + // Recv bytes oriented RTMP message from protocol stack. + // return error if error occur and nerver set the pmsg, + // return success and pmsg set to NULL if no entire message got, + // return success and pmsg set to entire message if got one. virtual srs_error_t recv_interlaced_message(SrsCommonMessage** pmsg); - /** - * read the chunk basic header(fmt, cid) from chunk stream. - * user can discovery a SrsChunkStream by cid. - */ + // Read the chunk basic header(fmt, cid) from chunk stream. + // user can discovery a SrsChunkStream by cid. virtual srs_error_t read_basic_header(char& fmt, int& cid); - /** - * read the chunk message header(timestamp, payload_length, message_type, stream_id) - * from chunk stream and save to SrsChunkStream. - */ + // Read the chunk message header(timestamp, payload_length, message_type, stream_id) + // From chunk stream and save to SrsChunkStream. virtual srs_error_t read_message_header(SrsChunkStream* chunk, char fmt); - /** - * read the chunk payload, remove the used bytes in buffer, - * if got entire message, set the pmsg. - */ + // Read the chunk payload, remove the used bytes in buffer, + // if got entire message, set the pmsg. virtual srs_error_t read_message_payload(SrsChunkStream* chunk, SrsCommonMessage** pmsg); - /** - * when recv message, update the context. - */ + // When recv message, update the context. virtual srs_error_t on_recv_message(SrsCommonMessage* msg); - /** - * when message sentout, update the context. - */ + // When message sentout, update the context. virtual srs_error_t on_send_packet(SrsMessageHeader* mh, SrsPacket* packet); private: - /** - * auto response the ack message. - */ + // Auto response the ack message. virtual srs_error_t response_acknowledgement_message(); - /** - * auto response the ping message. - */ + // Auto response the ping message. virtual srs_error_t response_ping_message(int32_t timestamp); private: virtual void print_debug_info(); }; -/** - * incoming chunk stream maybe interlaced, - * use the chunk stream to cache the input RTMP chunk streams. - */ +// incoming chunk stream maybe interlaced, +// Use the chunk stream to cache the input RTMP chunk streams. class SrsChunkStream { public: - /** - * represents the basic header fmt, - * which used to identify the variant message header type. - */ + // Represents the basic header fmt, + // which used to identify the variant message header type. char fmt; - /** - * represents the basic header cid, - * which is the chunk stream id. - */ + // Represents the basic header cid, + // which is the chunk stream id. int cid; - /** - * cached message header - */ + // Cached message header SrsMessageHeader header; - /** - * whether the chunk message header has extended timestamp. - */ + // Whether the chunk message header has extended timestamp. bool extended_timestamp; - /** - * partially read message. - */ + // The partially read message. SrsCommonMessage* msg; - /** - * decoded msg count, to identify whether the chunk stream is fresh. - */ + // Decoded msg count, to identify whether the chunk stream is fresh. int64_t msg_count; public: SrsChunkStream(int _cid); virtual ~SrsChunkStream(); }; -/** - * the original request from client. - */ +// The original request from client. class SrsRequest { public: - // client ip. + // The client ip. std::string ip; public: - /** - * tcUrl: rtmp://request_vhost:port/app/stream - * support pass vhost in query string, such as: - * rtmp://ip:port/app?vhost=request_vhost/stream - * rtmp://ip:port/app...vhost...request_vhost/stream - */ + // The tcUrl: rtmp://request_vhost:port/app/stream + // support pass vhost in query string, such as: + // rtmp://ip:port/app?vhost=request_vhost/stream + // rtmp://ip:port/app...vhost...request_vhost/stream std::string tcUrl; std::string pageUrl; std::string swfUrl; double objectEncoding; - // data discovery from request. +// The data discovery from request. public: - // discovery from tcUrl and play/publish. + // Discovery from tcUrl and play/publish. std::string schema; - // the vhost in tcUrl. + // The vhost in tcUrl. std::string vhost; - // the host in tcUrl. + // The host in tcUrl. std::string host; - // the port in tcUrl. + // The port in tcUrl. int port; - // the app in tcUrl, without param. + // The app in tcUrl, without param. std::string app; - // the param in tcUrl(app). + // The param in tcUrl(app). std::string param; - // the stream in play/publish + // The stream in play/publish std::string stream; - // for play live stream, + // For play live stream, // used to specified the stop when exceed the duration. // @see https://github.com/ossrs/srs/issues/45 // in srs_utime_t. srs_utime_t duration; - // the token in the connect request, + // The token in the connect request, // used for edge traverse to origin authentication, // @see https://github.com/ossrs/srs/issues/104 SrsAmf0Object* args; @@ -576,49 +455,35 @@ 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. - */ + // 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. - */ + // 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. - */ + // Get the stream identify, vhost/app/stream. virtual std::string get_stream_url(); - /** - * strip url, user must strip when update the url. - */ + // To strip url, user must strip when update the url. virtual void strip(); public: // Transform it as HTTP request. virtual SrsRequest* as_http(); }; -/** - * the response to client. - */ +// The response to client. class SrsResponse { public: - /** - * the stream id to response client createStream. - */ + // The stream id to response client createStream. int stream_id; public: SrsResponse(); virtual ~SrsResponse(); }; -/** - * the rtmp client type. - */ +// The rtmp client type. enum SrsRtmpConnType { SrsRtmpConnUnknown, @@ -630,10 +495,8 @@ enum SrsRtmpConnType std::string srs_client_type_string(SrsRtmpConnType type); bool srs_client_type_is_publish(SrsRtmpConnType type); -/** - * store the handshake bytes, - * for smart switch between complex and simple handshake. - */ +// store the handshake bytes, +// For smart switch between complex and simple handshake. class SrsHandshakeBytes { public: @@ -655,9 +518,7 @@ public: virtual srs_error_t create_c2(); }; -/** - * The information return from RTMP server. - */ +// The information return from RTMP server. struct SrsServerInfo { std::string ip; @@ -672,9 +533,7 @@ struct SrsServerInfo SrsServerInfo(); }; -/** - * implements the client role protocol. - */ +// implements the client role protocol. class SrsRtmpClient { private: @@ -685,7 +544,7 @@ protected: public: SrsRtmpClient(ISrsProtocolReadWriter* skt); virtual ~SrsRtmpClient(); -// protocol methods proxy +// Protocol methods proxy public: virtual void set_recv_timeout(srs_utime_t tm); virtual void set_send_timeout(srs_utime_t tm); @@ -697,64 +556,46 @@ public: virtual srs_error_t send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id); virtual srs_error_t send_and_free_packet(SrsPacket* packet, int stream_id); public: - /** - * handshake with server, try complex, then simple handshake. - */ + // handshake with server, try complex, then simple handshake. virtual srs_error_t handshake(); - /** - * only use simple handshake - */ + // only use simple handshake virtual srs_error_t simple_handshake(); - /** - * only use complex handshake - */ + // only use complex handshake virtual srs_error_t complex_handshake(); - /** - * Connect to RTMP tcUrl and app, get the server info. - * - * @param app, The app to connect at, for example, live. - * @param tcUrl, The tcUrl to connect at, for example, rtmp://ossrs.net/live. - * @param req, the optional req object, use the swfUrl/pageUrl if specified. NULL to ignore. - * @param dsu, Whether debug SRS upnode. For edge, set to true to send its info to upnode. - * @param si, The server information, retrieve from response of connect app request. NULL to ignore. - */ + // Connect to RTMP tcUrl and app, get the server info. + // + // @param app, The app to connect at, for example, live. + // @param tcUrl, The tcUrl to connect at, for example, rtmp://ossrs.net/live. + // @param req, the optional req object, use the swfUrl/pageUrl if specified. NULL to ignore. + // @param dsu, Whether debug SRS upnode. For edge, set to true to send its info to upnode. + // @param si, The server information, retrieve from response of connect app request. NULL to ignore. virtual srs_error_t connect_app(std::string app, std::string tcUrl, SrsRequest* r, bool dsu, SrsServerInfo* si); - /** - * create a stream, then play/publish data over this stream. - */ + // Create a stream, then play/publish data over this stream. virtual srs_error_t create_stream(int& stream_id); - /** - * start play stream. - */ + // start play stream. virtual srs_error_t play(std::string stream, int stream_id, int chunk_size); - /** - * start publish stream. use flash publish workflow: - * connect-app => create-stream => flash-publish - */ + // start publish stream. use flash publish workflow: + // connect-app => create-stream => flash-publish virtual srs_error_t publish(std::string stream, int stream_id, int chunk_size); - /** - * start publish stream. use FMLE publish workflow: - * connect-app => FMLE publish - */ + // start publish stream. use FMLE publish workflow: + // connect-app => FMLE publish virtual srs_error_t fmle_publish(std::string stream, int& stream_id); public: - /** - * expect a specified message, drop others util got specified one. - * @pmsg, user must free it. NULL if not success. - * @ppacket, user must free it, which decode from payload of message. NULL if not success. - * @remark, only when success, user can use and must free the pmsg and ppacket. - * for example: - * SrsCommonMessage* msg = NULL; - * SrsConnectAppResPacket* pkt = NULL; - * if ((ret = client->expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { - * return ret; - * } - * // use then free msg and pkt - * srs_freep(msg); - * srs_freep(pkt); - * user should never recv message and convert it, use this method instead. - * if need to set timeout, use set timeout of SrsProtocol. - */ + // Expect a specified message, drop others util got specified one. + // @pmsg, user must free it. NULL if not success. + // @ppacket, user must free it, which decode from payload of message. NULL if not success. + // @remark, only when success, user can use and must free the pmsg and ppacket. + // For example: + // SrsCommonMessage* msg = NULL; + // SrsConnectAppResPacket* pkt = NULL; + // if ((ret = client->expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + // return ret; + // } + // // Use then free msg and pkt + // srs_freep(msg); + // srs_freep(pkt); + // user should never recv message and convert it, use this method instead. + // if need to set timeout, use set timeout of SrsProtocol. template srs_error_t expect_message(SrsCommonMessage** pmsg, T** ppacket) { @@ -762,11 +603,9 @@ public: } }; -/** - * the rtmp provices rtmp-command-protocol services, - * a high level protocol, media stream oriented services, - * such as connect to vhost/app, play stream, get audio/video data. - */ +// The rtmp provices rtmp-command-protocol services, +// a high level protocol, media stream oriented services, +// such as connect to vhost/app, play stream, get audio/video data. class SrsRtmpServer { private: @@ -776,207 +615,151 @@ private: public: SrsRtmpServer(ISrsProtocolReadWriter* skt); virtual ~SrsRtmpServer(); -// protocol methods proxy +// Protocol methods proxy public: - /** - * set the auto response message when recv for protocol stack. - * @param v, whether auto response message when recv message. - * @see: https://github.com/ossrs/srs/issues/217 - */ + // Set the auto response message when recv for protocol stack. + // @param v, whether auto response message when recv message. + // @see: https://github.com/ossrs/srs/issues/217 virtual void set_auto_response(bool v); #ifdef SRS_PERF_MERGED_READ - /** - * to improve read performance, merge some packets then read, - * when it on and read small bytes, we sleep to wait more data., - * that is, we merge some data to read together. - * @param v true to ename merged read. - * @param handler the handler when merge read is enabled. - * @see https://github.com/ossrs/srs/issues/241 - */ + // To improve read performance, merge some packets then read, + // When it on and read small bytes, we sleep to wait more data., + // that is, we merge some data to read together. + // @param v true to ename merged read. + // @param handler the handler when merge read is enabled. + // @see https://github.com/ossrs/srs/issues/241 virtual void set_merge_read(bool v, IMergeReadHandler* handler); - /** - * create buffer with specifeid size. - * @param buffer the size of buffer. - * @remark when MR(SRS_PERF_MERGED_READ) disabled, always set to 8K. - * @remark when buffer changed, the previous ptr maybe invalid. - * @see https://github.com/ossrs/srs/issues/241 - */ + // Create buffer with specifeid size. + // @param buffer the size of buffer. + // @remark when MR(SRS_PERF_MERGED_READ) disabled, always set to 8K. + // @remark when buffer changed, the previous ptr maybe invalid. + // @see https://github.com/ossrs/srs/issues/241 virtual void set_recv_buffer(int buffer_size); #endif - /** - * set/get the recv timeout in srs_utime_t. - * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. - */ + // To set/get the recv timeout in srs_utime_t. + // if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. virtual void set_recv_timeout(srs_utime_t tm); virtual srs_utime_t get_recv_timeout(); - /** - * set/get the send timeout in srs_utime_t. - * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. - */ + // To set/get the send timeout in srs_utime_t. + // if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. virtual void set_send_timeout(srs_utime_t tm); virtual srs_utime_t get_send_timeout(); - /** - * get recv/send bytes. - */ + // Get recv/send bytes. virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); - /** - * recv a RTMP message, which is bytes oriented. - * user can use decode_message to get the decoded RTMP packet. - * @param pmsg, set the received message, - * always NULL if error, - * NULL for unknown packet but return success. - * never NULL if decode success. - * @remark, drop message when msg is empty or payload length is empty. - */ + // Recv a RTMP message, which is bytes oriented. + // user can use decode_message to get the decoded RTMP packet. + // @param pmsg, set the received message, + // always NULL if error, + // NULL for unknown packet but return success. + // never NULL if decode success. + // @remark, drop message when msg is empty or payload length is empty. virtual srs_error_t recv_message(SrsCommonMessage** pmsg); - /** - * decode bytes oriented RTMP message to RTMP packet, - * @param ppacket, output decoded packet, - * always NULL if error, never NULL if success. - * @return error when unknown packet, error when decode failed. - */ + // Decode bytes oriented RTMP message to RTMP packet, + // @param ppacket, output decoded packet, + // always NULL if error, never NULL if success. + // @return error when unknown packet, error when decode failed. virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); - /** - * send the RTMP message and always free it. - * user must never free or use the msg after this method, - * for it will always free the msg. - * @param msg, the msg to send out, never be NULL. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ + // Send the RTMP message and always free it. + // user must never free or use the msg after this method, + // For it will always free the msg. + // @param msg, the msg to send out, never be NULL. + // @param stream_id, the stream id of packet to send over, 0 for control message. virtual srs_error_t send_and_free_message(SrsSharedPtrMessage* msg, int stream_id); - /** - * send the RTMP message and always free it. - * user must never free or use the msg after this method, - * for it will always free the msg. - * @param msgs, the msgs to send out, never be NULL. - * @param nb_msgs, the size of msgs to send out. - * @param stream_id, the stream id of packet to send over, 0 for control message. - * - * @remark performance issue, to support 6k+ 250kbps client, - * @see https://github.com/ossrs/srs/issues/194 - */ + // Send the RTMP message and always free it. + // user must never free or use the msg after this method, + // For it will always free the msg. + // @param msgs, the msgs to send out, never be NULL. + // @param nb_msgs, the size of msgs to send out. + // @param stream_id, the stream id of packet to send over, 0 for control message. + // + // @remark performance issue, to support 6k+ 250kbps client, + // @see https://github.com/ossrs/srs/issues/194 virtual srs_error_t send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id); - /** - * send the RTMP packet and always free it. - * user must never free or use the packet after this method, - * for it will always free the packet. - * @param packet, the packet to send out, never be NULL. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ + // Send the RTMP packet and always free it. + // user must never free or use the packet after this method, + // For it will always free the packet. + // @param packet, the packet to send out, never be NULL. + // @param stream_id, the stream id of packet to send over, 0 for control message. virtual srs_error_t send_and_free_packet(SrsPacket* packet, int stream_id); public: - /** - * handshake with client, try complex then simple. - */ + // Do handshake with client, try complex then simple. virtual srs_error_t handshake(); - /** - * do connect app with client, to discovery tcUrl. - */ + // Do connect app with client, to discovery tcUrl. virtual srs_error_t connect_app(SrsRequest* req); - /** - * set output ack size to client, client will send ack-size for each ack window - */ + // Set output ack size to client, client will send ack-size for each ack window virtual srs_error_t set_window_ack_size(int ack_size); // Set the default input ack size value. virtual srs_error_t set_in_window_ack_size(int ack_size); - /** - * @type: The sender can mark this message hard (0), soft (1), or dynamic (2) - * using the Limit type field. - */ + // @type: The sender can mark this message hard (0), soft (1), or dynamic (2) + // using the Limit type field. virtual srs_error_t set_peer_bandwidth(int bandwidth, int type); - /** - * @param server_ip the ip of server. - */ + // @param server_ip the ip of server. virtual srs_error_t response_connect_app(SrsRequest* req, const char* server_ip = NULL); - /** - * redirect the connection to another rtmp server. - * @param the hostname or ip of target. - * @param whether the client accept the redirect. - */ + // Redirect the connection to another rtmp server. + // @param the hostname or ip of target. + // @param whether the client accept the redirect. virtual srs_error_t redirect(SrsRequest* r, std::string host, int port, bool& accepted); - /** - * reject the connect app request. - */ + // Reject the connect app request. virtual void response_connect_reject(SrsRequest* req, const char* desc); - /** - * response client the onBWDone message. - */ + // Response client the onBWDone message. virtual srs_error_t on_bw_done(); - /** - * recv some message to identify the client. - * @stream_id, client will createStream to play or publish by flash, - * the stream_id used to response the createStream request. - * @type, output the client type. - * @stream_name, output the client publish/play stream name. @see: SrsRequest.stream - * @duration, output the play client duration. @see: SrsRequest.duration - */ + // Recv some message to identify the client. + // @stream_id, client will createStream to play or publish by flash, + // the stream_id used to response the createStream request. + // @type, output the client type. + // @stream_name, output the client publish/play stream name. @see: SrsRequest.stream + // @duration, output the play client duration. @see: SrsRequest.duration virtual srs_error_t identify_client(int stream_id, SrsRtmpConnType& type, std::string& stream_name, srs_utime_t& duration); - /** - * set the chunk size when client type identified. - */ + // Set the chunk size when client type identified. virtual srs_error_t set_chunk_size(int chunk_size); - /** - * when client type is play, response with packets: - * StreamBegin, - * onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start)., - * |RtmpSampleAccess(false, false), - * onStatus(NetStream.Data.Start). - */ + // When client type is play, response with packets: + // StreamBegin, + // onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start)., + // |RtmpSampleAccess(false, false), + // onStatus(NetStream.Data.Start). virtual srs_error_t start_play(int stream_id); - /** - * when client(type is play) send pause message, - * if is_pause, response the following packets: - * onStatus(NetStream.Pause.Notify) - * StreamEOF - * if not is_pause, response the following packets: - * onStatus(NetStream.Unpause.Notify) - * StreamBegin - */ + // When client(type is play) send pause message, + // if is_pause, response the following packets: + // onStatus(NetStream.Pause.Notify) + // StreamEOF + // if not is_pause, response the following packets: + // onStatus(NetStream.Unpause.Notify) + // StreamBegin virtual srs_error_t on_play_client_pause(int stream_id, bool is_pause); - /** - * when client type is publish, response with packets: - * releaseStream response - * FCPublish - * FCPublish response - * createStream response - * onFCPublish(NetStream.Publish.Start) - * onStatus(NetStream.Publish.Start) - */ + // When client type is publish, response with packets: + // releaseStream response + // FCPublish + // FCPublish response + // createStream response + // onFCPublish(NetStream.Publish.Start) + // onStatus(NetStream.Publish.Start) virtual srs_error_t start_fmle_publish(int stream_id); - /** - * For encoder of Haivision, response the startup request. - * @see https://github.com/ossrs/srs/issues/844 - */ + // For encoder of Haivision, response the startup request. + // @see https://github.com/ossrs/srs/issues/844 virtual srs_error_t start_haivision_publish(int stream_id); - /** - * process the FMLE unpublish event. - * @unpublish_tid the unpublish request transaction id. - */ + // process the FMLE unpublish event. + // @unpublish_tid the unpublish request transaction id. virtual srs_error_t fmle_unpublish(int stream_id, double unpublish_tid); - /** - * when client type is publish, response with packets: - * onStatus(NetStream.Publish.Start) - */ + // When client type is publish, response with packets: + // onStatus(NetStream.Publish.Start) virtual srs_error_t start_flash_publish(int stream_id); public: - /** - * expect a specified message, drop others util got specified one. - * @pmsg, user must free it. NULL if not success. - * @ppacket, user must free it, which decode from payload of message. NULL if not success. - * @remark, only when success, user can use and must free the pmsg and ppacket. - * for example: - * SrsCommonMessage* msg = NULL; - * SrsConnectAppResPacket* pkt = NULL; - * if ((ret = server->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { - * return ret; - * } - * // use then free msg and pkt - * srs_freep(msg); - * srs_freep(pkt); - * user should never recv message and convert it, use this method instead. - * if need to set timeout, use set timeout of SrsProtocol. - */ + // Expect a specified message, drop others util got specified one. + // @pmsg, user must free it. NULL if not success. + // @ppacket, user must free it, which decode from payload of message. NULL if not success. + // @remark, only when success, user can use and must free the pmsg and ppacket. + // For example: + // SrsCommonMessage* msg = NULL; + // SrsConnectAppResPacket* pkt = NULL; + // if ((ret = server->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { + // return ret; + // } + // // Use then free msg and pkt + // srs_freep(msg); + // srs_freep(pkt); + // user should never recv message and convert it, use this method instead. + // if need to set timeout, use set timeout of SrsProtocol. template srs_error_t expect_message(SrsCommonMessage** pmsg, T** ppacket) { @@ -991,41 +774,31 @@ private: virtual srs_error_t identify_play_client(SrsPlayPacket* req, SrsRtmpConnType& type, std::string& stream_name, srs_utime_t& duration); }; -/** - * 4.1.1. connect - * The client sends the connect command to the server to request - * connection to a server application instance. - */ +// 4.1.1. connect +// The client sends the connect command to the server to request +// connection to a server application instance. class SrsConnectAppPacket : public SrsPacket { public: - /** - * Name of the command. Set to "connect". - */ + // Name of the command. Set to "connect". std::string command_name; - /** - * Always set to 1. - */ + // Always set to 1. double transaction_id; - /** - * Command information object which has the name-value pairs. - * @remark: alloc in packet constructor, user can directly use it, - * user should never alloc it again which will cause memory leak. - * @remark, never be NULL. - */ + // Command information object which has the name-value pairs. + // @remark: alloc in packet constructor, user can directly use it, + // user should never alloc it again which will cause memory leak. + // @remark, never be NULL. SrsAmf0Object* command_object; - /** - * Any optional information - * @remark, optional, init to and maybe NULL. - */ + // Any optional information + // @remark, optional, init to and maybe NULL. SrsAmf0Object* args; public: SrsConnectAppPacket(); virtual ~SrsConnectAppPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1033,38 +806,28 @@ protected: virtual int get_size(); virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * response for SrsConnectAppPacket. - */ +// Response for SrsConnectAppPacket. class SrsConnectAppResPacket : public SrsPacket { public: - /** - * _result or _error; indicates whether the response is result or error. - */ + // The _result or _error; indicates whether the response is result or error. std::string command_name; - /** - * Transaction ID is 1 for call connect responses - */ + // Transaction ID is 1 for call connect responses double transaction_id; - /** - * Name-value pairs that describe the properties(fmsver etc.) of the connection. - * @remark, never be NULL. - */ + // Name-value pairs that describe the properties(fmsver etc.) of the connection. + // @remark, never be NULL. SrsAmf0Object* props; - /** - * Name-value pairs that describe the response from|the server. 'code', - * 'level', 'description' are names of few among such information. - * @remark, never be NULL. - */ + // Name-value pairs that describe the response from|the server. 'code', + // 'level', 'description' are names of few among such information. + // @remark, never be NULL. SrsAmf0Object* info; public: SrsConnectAppResPacket(); virtual ~SrsConnectAppResPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1073,41 +836,31 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * 4.1.2. Call - * The call method of the NetConnection object runs remote procedure - * calls (RPC) at the receiving end. The called RPC name is passed as a - * parameter to the call command. - */ +// 4.1.2. Call +// The call method of the NetConnection object runs remote procedure +// calls (RPC) at the receiving end. The called RPC name is passed as a +// parameter to the call command. class SrsCallPacket : public SrsPacket { public: - /** - * Name of the remote procedure that is called. - */ + // Name of the remote procedure that is called. std::string command_name; - /** - * If a response is expected we give a transaction Id. Else we pass a value of 0 - */ + // If a response is expected we give a transaction Id. Else we pass a value of 0 double transaction_id; - /** - * If there exists any command info this - * is set, else this is set to null type. - * @remark, optional, init to and maybe NULL. - */ + // If there exists any command info this + // is set, else this is set to null type. + // @remark, optional, init to and maybe NULL. SrsAmf0Any* command_object; - /** - * Any optional arguments to be provided - * @remark, optional, init to and maybe NULL. - */ + // Any optional arguments to be provided + // @remark, optional, init to and maybe NULL. SrsAmf0Any* arguments; public: SrsCallPacket(); virtual ~SrsCallPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1115,34 +868,24 @@ protected: virtual int get_size(); virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * response for SrsCallPacket. - */ +// Response for SrsCallPacket. class SrsCallResPacket : public SrsPacket { public: - /** - * Name of the command. - */ + // Name of the command. std::string command_name; - /** - * ID of the command, to which the response belongs to - */ + // ID of the command, to which the response belongs to double transaction_id; - /** - * If there exists any command info this is set, else this is set to null type. - * @remark, optional, init to and maybe NULL. - */ + // If there exists any command info this is set, else this is set to null type. + // @remark, optional, init to and maybe NULL. SrsAmf0Any* command_object; - /** - * Response from the method that was called. - * @remark, optional, init to and maybe NULL. - */ + // Response from the method that was called. + // @remark, optional, init to and maybe NULL. SrsAmf0Any* response; public: SrsCallResPacket(double _transaction_id); virtual ~SrsCallResPacket(); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1151,36 +894,28 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * 4.1.3. createStream - * The client sends this command to the server to create a logical - * channel for message communication The publishing of audio, video, and - * metadata is carried out over stream channel created using the - * createStream command. - */ +// 4.1.3. createStream +// The client sends this command to the server to create a logical +// channel for message communication The publishing of audio, video, and +// metadata is carried out over stream channel created using the +// createStream command. class SrsCreateStreamPacket : public SrsPacket { public: - /** - * Name of the command. Set to "createStream". - */ + // Name of the command. Set to "createStream". std::string command_name; - /** - * Transaction ID of the command. - */ + // Transaction ID of the command. double transaction_id; - /** - * If there exists any command info this is set, else this is set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // If there exists any command info this is set, else this is set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null public: SrsCreateStreamPacket(); virtual ~SrsCreateStreamPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1188,36 +923,26 @@ protected: virtual int get_size(); virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * response for SrsCreateStreamPacket. - */ +// Response for SrsCreateStreamPacket. class SrsCreateStreamResPacket : public SrsPacket { public: - /** - * _result or _error; indicates whether the response is result or error. - */ + // The _result or _error; indicates whether the response is result or error. std::string command_name; - /** - * ID of the command that response belongs to. - */ + // ID of the command that response belongs to. double transaction_id; - /** - * If there exists any command info this is set, else this is set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // If there exists any command info this is set, else this is set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null - /** - * The return value is either a stream ID or an error information object. - */ + // The return value is either a stream ID or an error information object. double stream_id; public: SrsCreateStreamResPacket(double _transaction_id, double _stream_id); virtual ~SrsCreateStreamResPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1226,105 +951,77 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * client close stream packet. - */ +// client close stream packet. class SrsCloseStreamPacket : public SrsPacket { public: - /** - * Name of the command, set to "closeStream". - */ + // Name of the command, set to "closeStream". std::string command_name; - /** - * Transaction ID set to 0. - */ + // Transaction ID set to 0. double transaction_id; - /** - * Command information object does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information object does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null public: SrsCloseStreamPacket(); virtual ~SrsCloseStreamPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); }; -/** - * FMLE start publish: ReleaseStream/PublishStream/FCPublish/FCUnpublish - */ +// FMLE start publish: ReleaseStream/PublishStream/FCPublish/FCUnpublish class SrsFMLEStartPacket : public SrsPacket { public: - /** - * Name of the command - */ + // Name of the command std::string command_name; - /** - * the transaction ID to get the response. - */ + // The transaction ID to get the response. double transaction_id; - /** - * If there exists any command info this is set, else this is set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // If there exists any command info this is set, else this is set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null - /** - * the stream name to start publish or release. - */ + // The stream name to start publish or release. std::string stream_name; public: SrsFMLEStartPacket(); virtual ~SrsFMLEStartPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); protected: virtual int get_size(); virtual srs_error_t encode_packet(SrsBuffer* stream); -// factory method to create specified FMLE packet. +// Factory method to create specified FMLE packet. public: static SrsFMLEStartPacket* create_release_stream(std::string stream); static SrsFMLEStartPacket* create_FC_publish(std::string stream); }; -/** - * response for SrsFMLEStartPacket. - */ +// Response for SrsFMLEStartPacket. class SrsFMLEStartResPacket : public SrsPacket { public: - /** - * Name of the command - */ + // Name of the command std::string command_name; - /** - * the transaction ID to get the response. - */ + // The transaction ID to get the response. double transaction_id; - /** - * If there exists any command info this is set, else this is set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // If there exists any command info this is set, else this is set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null - /** - * the optional args, set to undefined. - * @remark, never be NULL, an AMF0 undefined instance. - */ + // The optional args, set to undefined. + // @remark, never be NULL, an AMF0 undefined instance. SrsAmf0Any* args; // undefined public: SrsFMLEStartResPacket(double _transaction_id); virtual ~SrsFMLEStartResPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1333,53 +1030,41 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * FMLE/flash publish - * 4.2.6. Publish - * The client sends the publish command to publish a named stream to the - * server. Using this name, any client can play this stream and receive - * the published audio, video, and data messages. - */ +// FMLE/flash publish +// 4.2.6. Publish +// The client sends the publish command to publish a named stream to the +// server. Using this name, any client can play this stream and receive +// The published audio, video, and data messages. class SrsPublishPacket : public SrsPacket { public: - /** - * Name of the command, set to "publish". - */ + // Name of the command, set to "publish". std::string command_name; - /** - * Transaction ID set to 0. - */ + // Transaction ID set to 0. double transaction_id; - /** - * Command information object does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information object does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null - /** - * Name with which the stream is published. - */ + // Name with which the stream is published. std::string stream_name; - /** - * Type of publishing. Set to "live", "record", or "append". - * record: The stream is published and the data is recorded to a new file.The file - * is stored on the server in a subdirectory within the directory that - * contains the server application. If the file already exists, it is - * overwritten. - * append: The stream is published and the data is appended to a file. If no file - * is found, it is created. - * live: Live data is published without recording it in a file. - * @remark, SRS only support live. - * @remark, optional, default to live. - */ + // Type of publishing. Set to "live", "record", or "append". + // record: The stream is published and the data is recorded to a new file.The file + // is stored on the server in a subdirectory within the directory that + // contains the server application. If the file already exists, it is + // overwritten. + // append: The stream is published and the data is appended to a file. If no file + // is found, it is created. + // live: Live data is published without recording it in a file. + // @remark, SRS only support live. + // @remark, optional, default to live. std::string type; public: SrsPublishPacket(); virtual ~SrsPublishPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1388,117 +1073,89 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * 4.2.8. pause - * The client sends the pause command to tell the server to pause or - * start playing. - */ +// 4.2.8. pause +// The client sends the pause command to tell the server to pause or +// start playing. class SrsPausePacket : public SrsPacket { public: - /** - * Name of the command, set to "pause". - */ + // Name of the command, set to "pause". std::string command_name; - /** - * There is no transaction ID for this command. Set to 0. - */ + // There is no transaction ID for this command. Set to 0. double transaction_id; - /** - * Command information object does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information object does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null - /** - * true or false, to indicate pausing or resuming play - */ + // true or false, to indicate pausing or resuming play bool is_pause; - /** - * Number of milliseconds at which the the stream is paused or play resumed. - * This is the current stream time at the Client when stream was paused. When the - * playback is resumed, the server will only send messages with timestamps - * greater than this value. - */ + // Number of milliseconds at which the the stream is paused or play resumed. + // This is the current stream time at the Client when stream was paused. When the + // playback is resumed, the server will only send messages with timestamps + // greater than this value. double time_ms; public: SrsPausePacket(); virtual ~SrsPausePacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); }; -/** - * 4.2.1. play - * The client sends this command to the server to play a stream. - */ +// 4.2.1. play +// The client sends this command to the server to play a stream. class SrsPlayPacket : public SrsPacket { public: - /** - * Name of the command. Set to "play". - */ + // Name of the command. Set to "play". std::string command_name; - /** - * Transaction ID set to 0. - */ + // Transaction ID set to 0. double transaction_id; - /** - * Command information does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null - /** - * Name of the stream to play. - * To play video (FLV) files, specify the name of the stream without a file - * extension (for example, "sample"). - * To play back MP3 or ID3 tags, you must precede the stream name with mp3: - * (for example, "mp3:sample".) - * To play H.264/AAC files, you must precede the stream name with mp4: and specify the - * file extension. For example, to play the file sample.m4v, specify - * "mp4:sample.m4v" - */ + // Name of the stream to play. + // To play video (FLV) files, specify the name of the stream without a file + // extension (for example, "sample"). + // To play back MP3 or ID3 tags, you must precede the stream name with mp3: + // (for example, "mp3:sample".) + // To play H.264/AAC files, you must precede the stream name with mp4: and specify the + // file extension. For example, to play the file sample.m4v, specify + // "mp4:sample.m4v" std::string stream_name; - /** - * An optional parameter that specifies the start time in seconds. - * The default value is -2, which means the subscriber first tries to play the live - * stream specified in the Stream Name field. If a live stream of that name is - * not found, it plays the recorded stream specified in the Stream Name field. - * If you pass -1 in the Start field, only the live stream specified in the Stream - * Name field is played. - * If you pass 0 or a positive number in the Start field, a recorded stream specified - * in the Stream Name field is played beginning from the time specified in the - * Start field. - * If no recorded stream is found, the next item in the playlist is played. - */ + // An optional parameter that specifies the start time in seconds. + // The default value is -2, which means the subscriber first tries to play the live + // stream specified in the Stream Name field. If a live stream of that name is + // not found, it plays the recorded stream specified in the Stream Name field. + // If you pass -1 in the Start field, only the live stream specified in the Stream + // Name field is played. + // If you pass 0 or a positive number in the Start field, a recorded stream specified + // in the Stream Name field is played beginning from the time specified in the + // Start field. + // If no recorded stream is found, the next item in the playlist is played. double start; - /** - * An optional parameter that specifies the duration of playback in seconds. - * The default value is -1. The -1 value means a live stream is played until it is no - * longer available or a recorded stream is played until it ends. - * If u pass 0, it plays the single frame since the time specified in the Start field - * from the beginning of a recorded stream. It is assumed that the value specified - * in the Start field is equal to or greater than 0. - * If you pass a positive number, it plays a live stream for the time period specified - * in the Duration field. After that it becomes available or plays a recorded - * stream for the time specified in the Duration field. (If a stream ends before the - * time specified in the Duration field, playback ends when the stream ends.) - * If you pass a negative number other than -1 in the Duration field, it interprets the - * value as if it were -1. - */ + // An optional parameter that specifies the duration of playback in seconds. + // The default value is -1. The -1 value means a live stream is played until it is no + // longer available or a recorded stream is played until it ends. + // If u pass 0, it plays the single frame since the time specified in the Start field + // from the beginning of a recorded stream. It is assumed that the value specified + // in the Start field is equal to or greater than 0. + // If you pass a positive number, it plays a live stream for the time period specified + // in the Duration field. After that it becomes available or plays a recorded + // stream for the time specified in the Duration field. (If a stream ends before the + // time specified in the Duration field, playback ends when the stream ends.) + // If you pass a negative number other than -1 in the Duration field, it interprets the + // value as if it were -1. double duration; - /** - * An optional Boolean value or number that specifies whether to flush any - * previous playlist. - */ + // An optional Boolean value or number that specifies whether to flush any + // previous playlist. bool reset; public: SrsPlayPacket(); virtual ~SrsPlayPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1507,38 +1164,28 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * response for SrsPlayPacket. - * @remark, user must set the stream_id in header. - */ +// Response for SrsPlayPacket. +// @remark, user must set the stream_id in header. class SrsPlayResPacket : public SrsPacket { public: - /** - * Name of the command. If the play command is successful, the command - * name is set to onStatus. - */ + // Name of the command. If the play command is successful, the command + // name is set to onStatus. std::string command_name; - /** - * Transaction ID set to 0. - */ + // Transaction ID set to 0. double transaction_id; - /** - * Command information does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* command_object; // null - /** - * If the play command is successful, the client receives OnStatus message from - * server which is NetStream.Play.Start. If the specified stream is not found, - * NetStream.Play.StreamNotFound is received. - * @remark, never be NULL, an AMF0 object instance. - */ + // If the play command is successful, the client receives OnStatus message from + // server which is NetStream.Play.Start. If the specified stream is not found, + // NetStream.Play.StreamNotFound is received. + // @remark, never be NULL, an AMF0 object instance. SrsAmf0Object* desc; public: SrsPlayResPacket(); virtual ~SrsPlayResPacket(); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1547,29 +1194,21 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * when bandwidth test done, notice client. - */ +// When bandwidth test done, notice client. class SrsOnBWDonePacket : public SrsPacket { public: - /** - * Name of command. Set to "onBWDone" - */ + // Name of command. Set to "onBWDone" std::string command_name; - /** - * Transaction ID set to 0. - */ + // Transaction ID set to 0. double transaction_id; - /** - * Command information does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* args; // null public: SrsOnBWDonePacket(); virtual ~SrsOnBWDonePacket(); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1578,36 +1217,26 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * onStatus command, AMF0 Call - * @remark, user must set the stream_id by SrsCommonMessage.set_packet(). - */ +// onStatus command, AMF0 Call +// @remark, user must set the stream_id by SrsCommonMessage.set_packet(). class SrsOnStatusCallPacket : public SrsPacket { public: - /** - * Name of command. Set to "onStatus" - */ + // Name of command. Set to "onStatus" std::string command_name; - /** - * Transaction ID set to 0. - */ + // Transaction ID set to 0. double transaction_id; - /** - * Command information does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* args; // null - /** - * Name-value pairs that describe the response from the server. - * 'code','level', 'description' are names of few among such information. - * @remark, never be NULL, an AMF0 object instance. - */ + // Name-value pairs that describe the response from the server. + // 'code','level', 'description' are names of few among such information. + // @remark, never be NULL, an AMF0 object instance. SrsAmf0Object* data; public: SrsOnStatusCallPacket(); virtual ~SrsOnStatusCallPacket(); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1616,41 +1245,31 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * the special packet for the bandwidth test. - * actually, it's a SrsOnStatusCallPacket, but - * 1. encode with data field, to send data to client. - * 2. decode ignore the data field, donot care. - */ +// The special packet for the bandwidth test. +// actually, it's a SrsOnStatusCallPacket, but +// 1. encode with data field, to send data to client. +// 2. decode ignore the data field, donot care. class SrsBandwidthPacket : public SrsPacket { public: - /** - * Name of command. - */ + // Name of command. std::string command_name; - /** - * Transaction ID set to 0. - */ + // Transaction ID set to 0. double transaction_id; - /** - * Command information does not exist. Set to null type. - * @remark, never be NULL, an AMF0 null instance. - */ + // Command information does not exist. Set to null type. + // @remark, never be NULL, an AMF0 null instance. SrsAmf0Any* args; // null - /** - * Name-value pairs that describe the response from the server. - * 'code','level', 'description' are names of few among such information. - * @remark, never be NULL, an AMF0 object instance. - */ + // Name-value pairs that describe the response from the server. + // 'code','level', 'description' are names of few among such information. + // @remark, never be NULL, an AMF0 object instance. SrsAmf0Object* data; public: SrsBandwidthPacket(); virtual ~SrsBandwidthPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1685,27 +1304,21 @@ private: virtual SrsBandwidthPacket* set_command(std::string command); }; -/** - * onStatus data, AMF0 Data - * @remark, user must set the stream_id by SrsCommonMessage.set_packet(). - */ +// onStatus data, AMF0 Data +// @remark, user must set the stream_id by SrsCommonMessage.set_packet(). class SrsOnStatusDataPacket : public SrsPacket { public: - /** - * Name of command. Set to "onStatus" - */ + // Name of command. Set to "onStatus" std::string command_name; - /** - * Name-value pairs that describe the response from the server. - * 'code', are names of few among such information. - * @remark, never be NULL, an AMF0 object instance. - */ + // Name-value pairs that describe the response from the server. + // 'code', are names of few among such information. + // @remark, never be NULL, an AMF0 object instance. SrsAmf0Object* data; public: SrsOnStatusDataPacket(); virtual ~SrsOnStatusDataPacket(); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1714,33 +1327,25 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * AMF0Data RtmpSampleAccess - * @remark, user must set the stream_id by SrsCommonMessage.set_packet(). - */ +// AMF0Data RtmpSampleAccess +// @remark, user must set the stream_id by SrsCommonMessage.set_packet(). class SrsSampleAccessPacket : public SrsPacket { public: - /** - * Name of command. Set to "|RtmpSampleAccess". - */ + // Name of command. Set to "|RtmpSampleAccess". std::string command_name; - /** - * whether allow access the sample of video. - * @see: https://github.com/ossrs/srs/issues/49 - * @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#videoSampleAccess - */ + // Whether allow access the sample of video. + // @see: https://github.com/ossrs/srs/issues/49 + // @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#videoSampleAccess bool video_sample_access; - /** - * whether allow access the sample of audio. - * @see: https://github.com/ossrs/srs/issues/49 - * @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#audioSampleAccess - */ + // Whether allow access the sample of audio. + // @see: https://github.com/ossrs/srs/issues/49 + // @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#audioSampleAccess bool audio_sample_access; public: SrsSampleAccessPacket(); virtual ~SrsSampleAccessPacket(); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1749,30 +1354,24 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * the stream metadata. - * FMLE: @setDataFrame - * others: onMetaData - */ +// The stream metadata. +// FMLE: @setDataFrame +// others: onMetaData class SrsOnMetaDataPacket : public SrsPacket { public: - /** - * Name of metadata. Set to "onMetaData" - */ + // Name of metadata. Set to "onMetaData" std::string name; - /** - * Metadata of stream. - * @remark, never be NULL, an AMF0 object instance. - */ + // Metadata of stream. + // @remark, never be NULL, an AMF0 object instance. SrsAmf0Object* metadata; public: SrsOnMetaDataPacket(); virtual ~SrsOnMetaDataPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1781,11 +1380,9 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * 5.5. Window Acknowledgement Size (5) - * The client or the server sends this message to inform the peer which - * window size to use when sending acknowledgment. - */ +// 5.5. Window Acknowledgement Size (5) +// The client or the server sends this message to inform the peer which +// window size to use when sending acknowledgment. class SrsSetWindowAckSizePacket : public SrsPacket { public: @@ -1793,10 +1390,10 @@ public: public: SrsSetWindowAckSizePacket(); virtual ~SrsSetWindowAckSizePacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1805,11 +1402,9 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * 5.3. Acknowledgement (3) - * The client or the server sends the acknowledgment to the peer after - * receiving bytes equal to the window size. - */ +// 5.3. Acknowledgement (3) +// The client or the server sends the acknowledgment to the peer after +// receiving bytes equal to the window size. class SrsAcknowledgementPacket : public SrsPacket { public: @@ -1817,10 +1412,10 @@ public: public: SrsAcknowledgementPacket(); virtual ~SrsAcknowledgementPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1829,26 +1424,22 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -/** - * 7.1. Set Chunk Size - * Protocol control message 1, Set Chunk Size, is used to notify the - * peer about the new maximum chunk size. - */ +// 7.1. Set Chunk Size +// Protocol control message 1, Set Chunk Size, is used to notify the +// peer about the new maximum chunk size. class SrsSetChunkSizePacket : public SrsPacket { public: - /** - * The maximum chunk size can be 65536 bytes. The chunk size is - * maintained independently for each direction. - */ + // The maximum chunk size can be 65536 bytes. The chunk size is + // maintained independently for each direction. int32_t chunk_size; public: SrsSetChunkSizePacket(); virtual ~SrsSetChunkSizePacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1867,11 +1458,9 @@ enum SrsPeerBandwidthType SrsPeerBandwidthDynamic = 2, }; -/** - * 5.6. Set Peer Bandwidth (6) - * The client or the server sends this message to update the output - * bandwidth of the peer. - */ +// 5.6. Set Peer Bandwidth (6) +// The client or the server sends this message to update the output +// bandwidth of the peer. class SrsSetPeerBandwidthPacket : public SrsPacket { public: @@ -1881,7 +1470,7 @@ public: public: SrsSetPeerBandwidthPacket(); virtual ~SrsSetPeerBandwidthPacket(); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); @@ -1893,130 +1482,106 @@ protected: // 3.7. User Control message enum SrcPCUCEventType { - // generally, 4bytes event-data + // Generally, 4bytes event-data - /** - * The server sends this event to notify the client - * that a stream has become functional and can be - * used for communication. By default, this event - * is sent on ID 0 after the application connect - * command is successfully received from the - * client. The event data is 4-byte and represents - * the stream ID of the stream that became - * functional. - */ + // The server sends this event to notify the client + // that a stream has become functional and can be + // used for communication. By default, this event + // is sent on ID 0 after the application connect + // command is successfully received from the + // client. The event data is 4-byte and represents + // The stream ID of the stream that became + // Functional. SrcPCUCStreamBegin = 0x00, - /** - * The server sends this event to notify the client - * that the playback of data is over as requested - * on this stream. No more data is sent without - * issuing additional commands. The client discards - * the messages received for the stream. The - * 4 bytes of event data represent the ID of the - * stream on which playback has ended. - */ + // The server sends this event to notify the client + // that the playback of data is over as requested + // on this stream. No more data is sent without + // issuing additional commands. The client discards + // The messages received for the stream. The + // 4 bytes of event data represent the ID of the + // stream on which playback has ended. SrcPCUCStreamEOF = 0x01, - /** - * The server sends this event to notify the client - * that there is no more data on the stream. If the - * server does not detect any message for a time - * period, it can notify the subscribed clients - * that the stream is dry. The 4 bytes of event - * data represent the stream ID of the dry stream. - */ + // The server sends this event to notify the client + // that there is no more data on the stream. If the + // server does not detect any message for a time + // period, it can notify the subscribed clients + // that the stream is dry. The 4 bytes of event + // data represent the stream ID of the dry stream. SrcPCUCStreamDry = 0x02, - /** - * The client sends this event to inform the server - * of the buffer size (in milliseconds) that is - * used to buffer any data coming over a stream. - * This event is sent before the server starts - * processing the stream. The first 4 bytes of the - * event data represent the stream ID and the next - * 4 bytes represent the buffer length, in - * milliseconds. - */ + // The client sends this event to inform the server + // of the buffer size (in milliseconds) that is + // used to buffer any data coming over a stream. + // This event is sent before the server starts + // processing the stream. The first 4 bytes of the + // event data represent the stream ID and the next + // 4 bytes represent the buffer length, in + // milliseconds. SrcPCUCSetBufferLength = 0x03, // 8bytes event-data - /** - * The server sends this event to notify the client - * that the stream is a recorded stream. The - * 4 bytes event data represent the stream ID of - * the recorded stream. - */ + // The server sends this event to notify the client + // that the stream is a recorded stream. The + // 4 bytes event data represent the stream ID of + // The recorded stream. SrcPCUCStreamIsRecorded = 0x04, - /** - * The server sends this event to test whether the - * client is reachable. Event data is a 4-byte - * timestamp, representing the local server time - * when the server dispatched the command. The - * client responds with kMsgPingResponse on - * receiving kMsgPingRequest. - */ + // The server sends this event to test whether the + // client is reachable. Event data is a 4-byte + // timestamp, representing the local server time + // When the server dispatched the command. The + // client responds with kMsgPingResponse on + // receiving kMsgPingRequest. SrcPCUCPingRequest = 0x06, - /** - * The client sends this event to the server in - * response to the ping request. The event data is - * a 4-byte timestamp, which was received with the - * kMsgPingRequest request. - */ + // The client sends this event to the server in + // Response to the ping request. The event data is + // a 4-byte timestamp, which was received with the + // kMsgPingRequest request. SrcPCUCPingResponse = 0x07, - /** - * For PCUC size=3, for example the payload is "00 1A 01", - * it's a FMS control event, where the event type is 0x001a and event data is 0x01, - * please notice that the event data is only 1 byte for this event. - */ + // For PCUC size=3, for example the payload is "00 1A 01", + // it's a FMS control event, where the event type is 0x001a and event data is 0x01, + // please notice that the event data is only 1 byte for this event. SrsPCUCFmsEvent0 = 0x1a, }; -/** - * 5.4. User Control Message (4) - * - * for the EventData is 4bytes. - * Stream Begin(=0) 4-bytes stream ID - * Stream EOF(=1) 4-bytes stream ID - * StreamDry(=2) 4-bytes stream ID - * SetBufferLength(=3) 8-bytes 4bytes stream ID, 4bytes buffer length. - * StreamIsRecorded(=4) 4-bytes stream ID - * PingRequest(=6) 4-bytes timestamp local server time - * PingResponse(=7) 4-bytes timestamp received ping request. - * - * 3.7. User Control message - * +------------------------------+------------------------- - * | Event Type ( 2- bytes ) | Event Data - * +------------------------------+------------------------- - * Figure 5 Pay load for the 'User Control Message'. - */ +// 5.4. User Control Message (4) +// +// For the EventData is 4bytes. +// Stream Begin(=0) 4-bytes stream ID +// Stream EOF(=1) 4-bytes stream ID +// StreamDry(=2) 4-bytes stream ID +// SetBufferLength(=3) 8-bytes 4bytes stream ID, 4bytes buffer length. +// StreamIsRecorded(=4) 4-bytes stream ID +// PingRequest(=6) 4-bytes timestamp local server time +// PingResponse(=7) 4-bytes timestamp received ping request. +// +// 3.7. User Control message +// +------------------------------+------------------------- +// | Event Type ( 2- bytes ) | Event Data +// +------------------------------+------------------------- +// Figure 5 Pay load for the 'User Control Message'. class SrsUserControlPacket : public SrsPacket { public: - /** - * Event type is followed by Event data. - * @see: SrcPCUCEventType - */ + // Event type is followed by Event data. + // @see: SrcPCUCEventType int16_t event_type; - /** - * the event data generally in 4bytes. - * @remark for event type is 0x001a, only 1bytes. - * @see SrsPCUCFmsEvent0 - */ + // The event data generally in 4bytes. + // @remark for event type is 0x001a, only 1bytes. + // @see SrsPCUCFmsEvent0 int32_t event_data; - /** - * 4bytes if event_type is SetBufferLength; otherwise 0. - */ + // 4bytes if event_type is SetBufferLength; otherwise 0. int32_t extra_data; public: SrsUserControlPacket(); virtual ~SrsUserControlPacket(); -// decode functions for concrete packet to override. +// Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); -// encode functions for concrete packet to override. +// Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); virtual int get_message_type(); diff --git a/trunk/src/protocol/srs_rtsp_stack.hpp b/trunk/src/protocol/srs_rtsp_stack.hpp index 3efdbb192..7732c4138 100644 --- a/trunk/src/protocol/srs_rtsp_stack.hpp +++ b/trunk/src/protocol/srs_rtsp_stack.hpp @@ -38,7 +38,7 @@ class SrsSimpleStream; class SrsAudioFrame; class ISrsProtocolReadWriter; -// rtsp specification +// From rtsp specification // CR = #define SRS_RTSP_CR SRS_CONSTS_CR // 0x0D // LF = @@ -78,38 +78,28 @@ class ISrsProtocolReadWriter; // RTSP-Version #define SRS_RTSP_VERSION "RTSP/1.0" -/** - * the rtsp sdp parse state. - */ +// The rtsp sdp parse state. enum SrsRtspSdpState { - /** - * other sdp properties. - */ + // Other sdp properties. SrsRtspSdpStateOthers, - /** - * parse sdp audio state. - */ + // Parse sdp audio state. SrsRtspSdpStateAudio, - /** - * parse sdp video state. - */ + // Parse sdp video state. SrsRtspSdpStateVideo, }; -/** - * 10 Method Definitions, @see rfc2326-1998-rtsp.pdf, page 57 - * The method token indicates the method to be performed on the resource - * identified by the Request-URI. The method is case-sensitive. New - * methods may be defined in the future. Method names may not start with - * a $ character (decimal 24) and must be a token. Methods are - * summarized in Table 2. - * Notes on Table 2: PAUSE is recommended, but not required in that a - * fully functional server can be built that does not support this - * method, for example, for live feeds. If a server does not support a - * particular method, it MUST return "501 Not Implemented" and a client - * SHOULD not try this method again for this server. - */ +// 10 Method Definitions, @see rfc2326-1998-rtsp.pdf, page 57 +// The method token indicates the method to be performed on the resource +// identified by the Request-URI. The method is case-sensitive. New +// methods may be defined in the future. Method names may not start with +// a $ character (decimal 24) and must be a token. Methods are +// summarized in Table 2. +// Notes on Table 2: PAUSE is recommended, but not required in that a +// fully functional server can be built that does not support this +// method, for example, for live feeds. If a server does not support a +// particular method, it MUST return "501 Not Implemented" and a client +// SHOULD not try this method again for this server. enum SrsRtspMethod { SrsRtspMethodDescribe = 0x0001, @@ -125,237 +115,187 @@ enum SrsRtspMethod SrsRtspMethodTeardown = 0x0400, }; -/** - * the state of rtsp token. - */ +// The state of rtsp token. enum SrsRtspTokenState { - /** - * parse token failed, default state. - */ + // Parse token failed, default state. SrsRtspTokenStateError = 100, - /** - * when SP follow the token. - */ + // When SP follow the token. SrsRtspTokenStateNormal = 101, - /** - * when CRLF follow the token. - */ + // When CRLF follow the token. SrsRtspTokenStateEOF = 102, }; -/** - * the rtp packet. - * 5. RTP Data Transfer Protocol, @see rfc3550-2003-rtp.pdf, page 12 - */ +// The rtp packet. +// 5. RTP Data Transfer Protocol, @see rfc3550-2003-rtp.pdf, page 12 class SrsRtpPacket { public: - /** - * version (V): 2 bits - * This field identifies the version of RTP. The version defined by this specification is two (2). - * (The value 1 is used by the first draft version of RTP and the value 0 is used by the protocol - * initially implemented in the \vat" audio tool.) - */ + // The version (V): 2 bits + // This field identifies the version of RTP. The version defined by this specification is two (2). + // (The value 1 is used by the first draft version of RTP and the value 0 is used by the protocol + // initially implemented in the \vat" audio tool.) int8_t version; //2bits - /** - * padding (P): 1 bit - * If the padding bit is set, the packet contains one or more additional padding octets at the - * end which are not part of the payload. The last octet of the padding contains a count of - * how many padding octets should be ignored, including itself. Padding may be needed by - * some encryption algorithms with fixed block sizes or for carrying several RTP packets in a - * lower-layer protocol data unit. - */ + // The padding (P): 1 bit + // If the padding bit is set, the packet contains one or more additional padding octets at the + // end which are not part of the payload. The last octet of the padding contains a count of + // how many padding octets should be ignored, including itself. Padding may be needed by + // some encryption algorithms with fixed block sizes or for carrying several RTP packets in a + // lower-layer protocol data unit. int8_t padding; //1bit - /** - * extension (X): 1 bit - * If the extension bit is set, the fixed header must be followed by exactly one header extension, - * with a format defined in Section 5.3.1. - */ + // The extension (X): 1 bit + // If the extension bit is set, the fixed header must be followed by exactly one header extension, + // with a format defined in Section 5.3.1. int8_t extension; //1bit - /** - * CSRC count (CC): 4 bits - * The CSRC count contains the number of CSRC identifiers that follow the fixed header. - */ + // The CSRC count (CC): 4 bits + // The CSRC count contains the number of CSRC identifiers that follow the fixed header. int8_t csrc_count; //4bits - /** - * marker (M): 1 bit - * The interpretation of the marker is defined by a profile. It is intended to allow significant - * events such as frame boundaries to be marked in the packet stream. A profile may define - * additional marker bits or specify that there is no marker bit by changing the number of bits - * in the payload type field (see Section 5.3). - */ + // The marker (M): 1 bit + // The interpretation of the marker is defined by a profile. It is intended to allow significant + // events such as frame boundaries to be marked in the packet stream. A profile may define + // additional marker bits or specify that there is no marker bit by changing the number of bits + // in the payload type field (see Section 5.3). int8_t marker; //1bit - /** - * payload type (PT): 7 bits - * This field identifies the format of the RTP payload and determines its interpretation by the - * application. A profile may specify a default static mapping of payload type codes to payload - * formats. Additional payload type codes may be defined dynamically through non-RTP means - * (see Section 3). A set of default mappings for audio and video is specified in the companion - * RFC 3551 [1]. An RTP source may change the payload type during a session, but this field - * should not be used for multiplexing separate media streams (see Section 5.2). - * A receiver must ignore packets with payload types that it does not understand. - */ + // The payload type (PT): 7 bits + // This field identifies the format of the RTP payload and determines its interpretation by the + // application. A profile may specify a default static mapping of payload type codes to payload + // formats. Additional payload type codes may be defined dynamically through non-RTP means + // (see Section 3). A set of default mappings for audio and video is specified in the companion + // RFC 3551 [1]. An RTP source may change the payload type during a session, but this field + // should not be used for multiplexing separate media streams (see Section 5.2). + // A receiver must ignore packets with payload types that it does not understand. int8_t payload_type; //7bits - /** - * sequence number: 16 bits - * The sequence number increments by one for each RTP data packet sent, and may be used - * by the receiver to detect packet loss and to restore packet sequence. The initial value of the - * sequence number should be random (unpredictable) to make known-plaintext attacks on - * encryption more dicult, even if the source itself does not encrypt according to the method - * in Section 9.1, because the packets may flow through a translator that does. Techniques for - * choosing unpredictable numbers are discussed in [17]. - */ + // The sequence number: 16 bits + // The sequence number increments by one for each RTP data packet sent, and may be used + // by the receiver to detect packet loss and to restore packet sequence. The initial value of the + // sequence number should be random (unpredictable) to make known-plaintext attacks on + // encryption more dicult, even if the source itself does not encrypt according to the method + // in Section 9.1, because the packets may flow through a translator that does. Techniques for + // choosing unpredictable numbers are discussed in [17]. uint16_t sequence_number; //16bits - /** - * timestamp: 32 bits - * The timestamp reflects the sampling instant of the first octet in the RTP data packet. The - * sampling instant must be derived from a clock that increments monotonically and linearly - * in time to allow synchronization and jitter calculations (see Section 6.4.1). The resolution - * of the clock must be sucient for the desired synchronization accuracy and for measuring - * packet arrival jitter (one tick per video frame is typically not sucient). The clock frequency - * is dependent on the format of data carried as payload and is specified statically in the profile - * or payload format specification that defines the format, or may be specified dynamically for - * payload formats defined through non-RTP means. If RTP packets are generated periodically, - * the nominal sampling instant as determined from the sampling clock is to be used, not a - * reading of the system clock. As an example, for fixed-rate audio the timestamp clock would - * likely increment by one for each sampling period. If an audio application reads blocks covering - * 160 sampling periods from the input device, the timestamp would be increased by 160 for - * each such block, regardless of whether the block is transmitted in a packet or dropped as - * silent. - * - * The initial value of the timestamp should be random, as for the sequence number. Several - * consecutive RTP packets will have equal timestamps if they are (logically) generated at once, - * e.g., belong to the same video frame. Consecutive RTP packets may contain timestamps that - * are not monotonic if the data is not transmitted in the order it was sampled, as in the case - * of MPEG interpolated video frames. (The sequence numbers of the packets as transmitted - * will still be monotonic.) - * - * RTP timestamps from different media streams may advance at different rates and usually - * have independent, random offsets. Therefore, although these timestamps are sucient to - * reconstruct the timing of a single stream, directly comparing RTP timestamps from different - * media is not effective for synchronization. Instead, for each medium the RTP timestamp - * is related to the sampling instant by pairing it with a timestamp from a reference clock - * (wallclock) that represents the time when the data corresponding to the RTP timestamp was - * sampled. The reference clock is shared by all media to be synchronized. The timestamp - * pairs are not transmitted in every data packet, but at a lower rate in RTCP SR packets as - * described in Section 6.4. - * - * The sampling instant is chosen as the point of reference for the RTP timestamp because it is - * known to the transmitting endpoint and has a common definition for all media, independent - * of encoding delays or other processing. The purpose is to allow synchronized presentation of - * all media sampled at the same time. - * - * Applications transmitting stored data rather than data sampled in real time typically use a - * virtual presentation timeline derived from wallclock time to determine when the next frame - * or other unit of each medium in the stored data should be presented. In this case, the RTP - * timestamp would reflect the presentation time for each unit. That is, the RTP timestamp for - * each unit would be related to the wallclock time at which the unit becomes current on the - * virtual presentation timeline. Actual presentation occurs some time later as determined by - * the receiver. - * - * An example describing live audio narration of prerecorded video illustrates the significance - * of choosing the sampling instant as the reference point. In this scenario, the video would - * be presented locally for the narrator to view and would be simultaneously transmitted using - * RTP. The sampling instant" of a video frame transmitted in RTP would be established by - * referencing its timestamp to the wallclock time when that video frame was presented to the - * narrator. The sampling instant for the audio RTP packets containing the narrator's speech - * would be established by referencing the same wallclock time when the audio was sampled. - * The audio and video may even be transmitted by different hosts if the reference clocks on - * the two hosts are synchronized by some means such as NTP. A receiver can then synchronize - * presentation of the audio and video packets by relating their RTP timestamps using the - * timestamp pairs in RTCP SR packets. - */ + // The timestamp: 32 bits + // The timestamp reflects the sampling instant of the first octet in the RTP data packet. The + // sampling instant must be derived from a clock that increments monotonically and linearly + // in time to allow synchronization and jitter calculations (see Section 6.4.1). The resolution + // of the clock must be sucient for the desired synchronization accuracy and for measuring + // packet arrival jitter (one tick per video frame is typically not sucient). The clock frequency + // is dependent on the format of data carried as payload and is specified statically in the profile + // or payload format specification that defines the format, or may be specified dynamically for + // payload formats defined through non-RTP means. If RTP packets are generated periodically, + // The nominal sampling instant as determined from the sampling clock is to be used, not a + // reading of the system clock. As an example, for fixed-rate audio the timestamp clock would + // likely increment by one for each sampling period. If an audio application reads blocks covering + // 160 sampling periods from the input device, the timestamp would be increased by 160 for + // each such block, regardless of whether the block is transmitted in a packet or dropped as + // silent. + // + // The initial value of the timestamp should be random, as for the sequence number. Several + // consecutive RTP packets will have equal timestamps if they are (logically) generated at once, + // e.g., belong to the same video frame. Consecutive RTP packets may contain timestamps that + // are not monotonic if the data is not transmitted in the order it was sampled, as in the case + // of MPEG interpolated video frames. (The sequence numbers of the packets as transmitted + // will still be monotonic.) + // + // RTP timestamps from different media streams may advance at different rates and usually + // have independent, random offsets. Therefore, although these timestamps are sucient to + // reconstruct the timing of a single stream, directly comparing RTP timestamps from different + // media is not effective for synchronization. Instead, for each medium the RTP timestamp + // is related to the sampling instant by pairing it with a timestamp from a reference clock + // (wallclock) that represents the time when the data corresponding to the RTP timestamp was + // sampled. The reference clock is shared by all media to be synchronized. The timestamp + // pairs are not transmitted in every data packet, but at a lower rate in RTCP SR packets as + // described in Section 6.4. + // + // The sampling instant is chosen as the point of reference for the RTP timestamp because it is + // known to the transmitting endpoint and has a common definition for all media, independent + // of encoding delays or other processing. The purpose is to allow synchronized presentation of + // all media sampled at the same time. + // + // Applications transmitting stored data rather than data sampled in real time typically use a + // virtual presentation timeline derived from wallclock time to determine when the next frame + // or other unit of each medium in the stored data should be presented. In this case, the RTP + // timestamp would reflect the presentation time for each unit. That is, the RTP timestamp for + // each unit would be related to the wallclock time at which the unit becomes current on the + // virtual presentation timeline. Actual presentation occurs some time later as determined by + // The receiver. + // + // An example describing live audio narration of prerecorded video illustrates the significance + // of choosing the sampling instant as the reference point. In this scenario, the video would + // be presented locally for the narrator to view and would be simultaneously transmitted using + // RTP. The sampling instant" of a video frame transmitted in RTP would be established by + // referencing its timestamp to the wallclock time when that video frame was presented to the + // narrator. The sampling instant for the audio RTP packets containing the narrator's speech + // would be established by referencing the same wallclock time when the audio was sampled. + // The audio and video may even be transmitted by different hosts if the reference clocks on + // The two hosts are synchronized by some means such as NTP. A receiver can then synchronize + // presentation of the audio and video packets by relating their RTP timestamps using the + // timestamp pairs in RTCP SR packets. uint32_t timestamp; //32bits - /** - * SSRC: 32 bits - * The SSRC field identifies the synchronization source. This identifier should be chosen - * randomly, with the intent that no two synchronization sources within the same RTP session - * will have the same SSRC identifier. An example algorithm for generating a random identifier - * is presented in Appendix A.6. Although the probability of multiple sources choosing the same - * identifier is low, all RTP implementations must be prepared to detect and resolve collisions. - * Section 8 describes the probability of collision along with a mechanism for resolving collisions - * and detecting RTP-level forwarding loops based on the uniqueness of the SSRC identifier. If - * a source changes its source transport address, it must also choose a new SSRC identifier to - * avoid being interpreted as a looped source (see Section 8.2). - */ + // The SSRC: 32 bits + // The SSRC field identifies the synchronization source. This identifier should be chosen + // randomly, with the intent that no two synchronization sources within the same RTP session + // will have the same SSRC identifier. An example algorithm for generating a random identifier + // is presented in Appendix A.6. Although the probability of multiple sources choosing the same + // identifier is low, all RTP implementations must be prepared to detect and resolve collisions. + // Section 8 describes the probability of collision along with a mechanism for resolving collisions + // and detecting RTP-level forwarding loops based on the uniqueness of the SSRC identifier. If + // a source changes its source transport address, it must also choose a new SSRC identifier to + // avoid being interpreted as a looped source (see Section 8.2). uint32_t ssrc; //32bits - // the payload. + // The payload. SrsSimpleStream* payload; - // whether transport in chunked payload. + // Whether transport in chunked payload. bool chunked; - // whether message is completed. + // Whether message is completed. // normal message always completed. // while chunked completed when the last chunk arriaved. bool completed; - /** - * the audio samples, one rtp packets may contains multiple audio samples. - */ + // The audio samples, one rtp packets may contains multiple audio samples. SrsAudioFrame* audio; public: SrsRtpPacket(); virtual ~SrsRtpPacket(); public: - /** - * copy the header from src. - */ + // copy the header from src. virtual void copy(SrsRtpPacket* src); - /** - * reap the src to this packet, reap the payload. - */ + // reap the src to this packet, reap the payload. virtual void reap(SrsRtpPacket* src); - /** - * decode rtp packet from stream. - */ + // decode rtp packet from stream. virtual srs_error_t decode(SrsBuffer* stream); private: virtual srs_error_t decode_97(SrsBuffer* stream); virtual srs_error_t decode_96(SrsBuffer* stream); }; -/** - * the sdp in announce, @see rfc2326-1998-rtsp.pdf, page 159 - * Appendix C: Use of SDP for RTSP Session Descriptions - * The Session Description Protocol (SDP, RFC 2327 [6]) may be used to - * describe streams or presentations in RTSP. - */ +// The sdp in announce, @see rfc2326-1998-rtsp.pdf, page 159 +// Appendix C: Use of SDP for RTSP Session Descriptions +// The Session Description Protocol (SDP, RFC 2327 [6]) may be used to +// describe streams or presentations in RTSP. class SrsRtspSdp { private: SrsRtspSdpState state; public: - /** - * the version of sdp. - */ + // The version of sdp. std::string version; - /** - * the owner/creator of sdp. - */ + // The owner/creator of sdp. std::string owner_username; std::string owner_session_id; std::string owner_session_version; std::string owner_network_type; std::string owner_address_type; std::string owner_address; - /** - * the session name of sdp. - */ + // The session name of sdp. std::string session_name; - /** - * the connection info of sdp. - */ + // The connection info of sdp. std::string connection_network_type; std::string connection_address_type; std::string connection_address; - /** - * the tool attribute of sdp. - */ + // The tool attribute of sdp. std::string tool; - /** - * the video attribute of sdp. - */ + // The video attribute of sdp. std::string video_port; std::string video_protocol; std::string video_transport_format; @@ -363,13 +303,11 @@ public: std::string video_codec; std::string video_sample_rate; std::string video_stream_id; - // fmtp + // The fmtp std::string video_packetization_mode; std::string video_sps; // sequence header: sps. std::string video_pps; // sequence header: pps. - /** - * the audio attribute of sdp. - */ + // The audio attribute of sdp. std::string audio_port; std::string audio_protocol; std::string audio_transport_format; @@ -378,7 +316,7 @@ public: std::string audio_sample_rate; std::string audio_channel; std::string audio_stream_id; - // fmtp + // The fmtp std::string audio_profile_level_id; std::string audio_mode; std::string audio_size_length; @@ -389,34 +327,24 @@ public: SrsRtspSdp(); virtual ~SrsRtspSdp(); public: - /** - * parse a line of token for sdp. - */ + // Parse a line of token for sdp. virtual srs_error_t parse(std::string token); private: - /** - * generally, the fmtp is the sequence header for video or audio. - */ + // generally, the fmtp is the sequence header for video or audio. virtual srs_error_t parse_fmtp_attribute(std::string attr); - /** - * generally, the control is the stream info for video or audio. - */ + // generally, the control is the stream info for video or audio. virtual srs_error_t parse_control_attribute(std::string attr); - /** - * decode the string by base64. - */ + // decode the string by base64. virtual std::string base64_decode(std::string value); }; -/** - * the rtsp transport. - * 12.39 Transport, @see rfc2326-1998-rtsp.pdf, page 115 - * This request header indicates which transport protocol is to be used - * and configures its parameters such as destination address, - * compression, multicast time-to-live and destination port for a single - * stream. It sets those values not already determined by a presentation - * description. - */ +// The rtsp transport. +// 12.39 Transport, @see rfc2326-1998-rtsp.pdf, page 115 +// This request header indicates which transport protocol is to be used +// and configures its parameters such as destination address, +// compression, multicast time-to-live and destination port for a single +// stream. It sets those values not already determined by a presentation +// description. class SrsRtspTransport { public: @@ -431,7 +359,7 @@ public: // Clients that are capable of handling both unicast and // multicast transmission MUST indicate such capability by // including two full transport-specs with separate parameters - // for each. + // For each. std::string cast_type; // The mode parameter indicates the methods to be supported for // this session. Valid values are PLAY and RECORD. If not @@ -449,79 +377,59 @@ public: SrsRtspTransport(); virtual ~SrsRtspTransport(); public: - /** - * parse a line of token for transport. - */ + // Parse a line of token for transport. virtual srs_error_t parse(std::string attr); }; -/** - * the rtsp request message. - * 6 Request, @see rfc2326-1998-rtsp.pdf, page 39 - * A request message from a client to a server or vice versa includes, - * within the first line of that message, the method to be applied to - * the resource, the identifier of the resource, and the protocol - * version in use. - * Request = Request-Line ; Section 6.1 - * *( general-header ; Section 5 - * | request-header ; Section 6.2 - * | entity-header ) ; Section 8.1 - * CRLF - * [ message-body ] ; Section 4.3 - */ +// The rtsp request message. +// 6 Request, @see rfc2326-1998-rtsp.pdf, page 39 +// A request message from a client to a server or vice versa includes, +// within the first line of that message, the method to be applied to +// The resource, the identifier of the resource, and the protocol +// version in use. +// Request = Request-Line ; Section 6.1 +// // ( general-header ; Section 5 +// | request-header ; Section 6.2 +// | entity-header ) ; Section 8.1 +// CRLF +// [ message-body ] ; Section 4.3 class SrsRtspRequest { public: - /** - * 6.1 Request Line - * Request-Line = Method SP Request-URI SP RTSP-Version CRLF - */ + // 6.1 Request Line + // Request-Line = Method SP Request-URI SP RTSP-Version CRLF std::string method; std::string uri; std::string version; - /** - * 12.17 CSeq - * The CSeq field specifies the sequence number for an RTSP requestresponse - * pair. This field MUST be present in all requests and - * responses. For every RTSP request containing the given sequence - * number, there will be a corresponding response having the same - * number. Any retransmitted request must contain the same sequence - * number as the original (i.e. the sequence number is not incremented - * for retransmissions of the same request). - */ + // 12.17 CSeq + // The CSeq field specifies the sequence number for an RTSP requestresponse + // pair. This field MUST be present in all requests and + // responses. For every RTSP request containing the given sequence + // number, there will be a corresponding response having the same + // number. Any retransmitted request must contain the same sequence + // number as the original (i.e. the sequence number is not incremented + // For retransmissions of the same request). long seq; - /** - * 12.16 Content-Type, @see rfc2326-1998-rtsp.pdf, page 99 - * See [H14.18]. Note that the content types suitable for RTSP are - * likely to be restricted in practice to presentation descriptions and - * parameter-value types. - */ + // 12.16 Content-Type, @see rfc2326-1998-rtsp.pdf, page 99 + // See [H14.18]. Note that the content types suitable for RTSP are + // likely to be restricted in practice to presentation descriptions and + // parameter-value types. std::string content_type; - /** - * 12.14 Content-Length, @see rfc2326-1998-rtsp.pdf, page 99 - * This field contains the length of the content of the method (i.e. - * after the double CRLF following the last header). Unlike HTTP, it - * MUST be included in all messages that carry content beyond the header - * portion of the message. If it is missing, a default value of zero is - * assumed. It is interpreted according to [H14.14]. - */ + // 12.14 Content-Length, @see rfc2326-1998-rtsp.pdf, page 99 + // This field contains the length of the content of the method (i.e. + // after the double CRLF following the last header). Unlike HTTP, it + // MUST be included in all messages that carry content beyond the header + // portion of the message. If it is missing, a default value of zero is + // assumed. It is interpreted according to [H14.14]. long content_length; - /** - * the session id. - */ + // The session id. std::string session; - /** - * the sdp in announce, NULL for no sdp. - */ + // The sdp in announce, NULL for no sdp. SrsRtspSdp* sdp; - /** - * the transport in setup, NULL for no transport. - */ + // The transport in setup, NULL for no transport. SrsRtspTransport* transport; - /** - * for setup message, parse the stream id from uri. - */ + // For setup message, parse the stream id from uri. int stream_id; public: SrsRtspRequest(); @@ -533,79 +441,63 @@ public: virtual bool is_record(); }; -/** - * the rtsp response message. - * 7 Response, @see rfc2326-1998-rtsp.pdf, page 43 - * [H6] applies except that HTTP-Version is replaced by RTSP-Version. - * Also, RTSP defines additional status codes and does not define some - * HTTP codes. The valid response codes and the methods they can be used - * with are defined in Table 1. - * After receiving and interpreting a request message, the recipient - * responds with an RTSP response message. - * Response = Status-Line ; Section 7.1 - * *( general-header ; Section 5 - * | response-header ; Section 7.1.2 - * | entity-header ) ; Section 8.1 - * CRLF - * [ message-body ] ; Section 4.3 - */ +// The rtsp response message. +// 7 Response, @see rfc2326-1998-rtsp.pdf, page 43 +// [H6] applies except that HTTP-Version is replaced by RTSP-Version. +// Also, RTSP defines additional status codes and does not define some +// HTTP codes. The valid response codes and the methods they can be used +// with are defined in Table 1. +// After receiving and interpreting a request message, the recipient +// responds with an RTSP response message. +// Response = Status-Line ; Section 7.1 +// // ( general-header ; Section 5 +// | response-header ; Section 7.1.2 +// | entity-header ) ; Section 8.1 +// CRLF +// [ message-body ] ; Section 4.3 class SrsRtspResponse { public: - /** - * 7.1 Status-Line - * The first line of a Response message is the Status-Line, consisting - * of the protocol version followed by a numeric status code, and the - * textual phrase associated with the status code, with each element - * separated by SP characters. No CR or LF is allowed except in the - * final CRLF sequence. - * Status-Line = RTSP-Version SP Status-Code SP Reason-Phrase CRLF - */ + // 7.1 Status-Line + // The first line of a Response message is the Status-Line, consisting + // of the protocol version followed by a numeric status code, and the + // textual phrase associated with the status code, with each element + // separated by SP characters. No CR or LF is allowed except in the + // final CRLF sequence. + // Status-Line = RTSP-Version SP Status-Code SP Reason-Phrase CRLF // @see about the version of rtsp, see SRS_RTSP_VERSION // @see about the status of rtsp, see SRS_CONSTS_RTSP_OK int status; - /** - * 12.17 CSeq, @see rfc2326-1998-rtsp.pdf, page 99 - * The CSeq field specifies the sequence number for an RTSP requestresponse - * pair. This field MUST be present in all requests and - * responses. For every RTSP request containing the given sequence - * number, there will be a corresponding response having the same - * number. Any retransmitted request must contain the same sequence - * number as the original (i.e. the sequence number is not incremented - * for retransmissions of the same request). - */ + // 12.17 CSeq, @see rfc2326-1998-rtsp.pdf, page 99 + // The CSeq field specifies the sequence number for an RTSP requestresponse + // pair. This field MUST be present in all requests and + // responses. For every RTSP request containing the given sequence + // number, there will be a corresponding response having the same + // number. Any retransmitted request must contain the same sequence + // number as the original (i.e. the sequence number is not incremented + // For retransmissions of the same request). long seq; - /** - * the session id. - */ + // The session id. std::string session; public: SrsRtspResponse(int cseq); virtual ~SrsRtspResponse(); public: - /** - * encode message to string. - */ + // Encode message to string. virtual srs_error_t encode(std::stringstream& ss); protected: - /** - * sub classes override this to encode the headers. - */ + // Sub classes override this to encode the headers. virtual srs_error_t encode_header(std::stringstream& ss); }; -/** - * 10.1 OPTIONS, @see rfc2326-1998-rtsp.pdf, page 59 - * The behavior is equivalent to that described in [H9.2]. An OPTIONS - * request may be issued at any time, e.g., if the client is about to - * try a nonstandard request. It does not influence server state. - */ +// 10.1 OPTIONS, @see rfc2326-1998-rtsp.pdf, page 59 +// The behavior is equivalent to that described in [H9.2]. An OPTIONS +// request may be issued at any time, e.g., if the client is about to +// try a nonstandard request. It does not influence server state. class SrsRtspOptionsResponse : public SrsRtspResponse { public: - /** - * join of SrsRtspMethod - */ + // Join of SrsRtspMethod SrsRtspMethod methods; public: SrsRtspOptionsResponse(int cseq); @@ -614,28 +506,26 @@ protected: virtual srs_error_t encode_header(std::stringstream& ss); }; -/** - * 10.4 SETUP, @see rfc2326-1998-rtsp.pdf, page 65 - * The SETUP request for a URI specifies the transport mechanism to be - * used for the streamed media. A client can issue a SETUP request for a - * stream that is already playing to change transport parameters, which - * a server MAY allow. If it does not allow this, it MUST respond with - * error "455 Method Not Valid In This State". For the benefit of any - * intervening firewalls, a client must indicate the transport - * parameters even if it has no influence over these parameters, for - * example, where the server advertises a fixed multicast address. - */ +// 10.4 SETUP, @see rfc2326-1998-rtsp.pdf, page 65 +// The SETUP request for a URI specifies the transport mechanism to be +// used for the streamed media. A client can issue a SETUP request for a +// stream that is already playing to change transport parameters, which +// a server MAY allow. If it does not allow this, it MUST respond with +// error "455 Method Not Valid In This State". For the benefit of any +// intervening firewalls, a client must indicate the transport +// parameters even if it has no influence over these parameters, for +// example, where the server advertises a fixed multicast address. class SrsRtspSetupResponse : public SrsRtspResponse { public: - // the client specified port. + // The client specified port. int client_port_min; int client_port_max; - // client will use the port in: + // The client will use the port in: // [local_port_min, local_port_max) int local_port_min; int local_port_max; - // session. + // The session. std::string session; public: SrsRtspSetupResponse(int cseq); @@ -644,65 +534,45 @@ protected: virtual srs_error_t encode_header(std::stringstream& ss); }; -/** - * the rtsp protocol stack to parse the rtsp packets. - */ +// The rtsp protocol stack to parse the rtsp packets. class SrsRtspStack { private: - /** - * cached bytes buffer. - */ + // The cached bytes buffer. SrsSimpleStream* buf; - /** - * underlayer socket object, send/recv bytes. - */ + // The underlayer socket object, send/recv bytes. ISrsProtocolReadWriter* skt; public: SrsRtspStack(ISrsProtocolReadWriter* s); virtual ~SrsRtspStack(); public: - /** - * recv rtsp message from underlayer io. - * @param preq the output rtsp request message, which user must free it. - * @return an int error code. - * ERROR_RTSP_REQUEST_HEADER_EOF indicates request header EOF. - */ + // Recv rtsp message from underlayer io. + // @param preq the output rtsp request message, which user must free it. + // @return an int error code. + // ERROR_RTSP_REQUEST_HEADER_EOF indicates request header EOF. virtual srs_error_t recv_message(SrsRtspRequest** preq); - /** - * send rtsp message over underlayer io. - * @param res the rtsp response message, which user should never free it. - * @return an int error code. - */ + // Send rtsp message over underlayer io. + // @param res the rtsp response message, which user should never free it. + // @return an int error code. virtual srs_error_t send_message(SrsRtspResponse* res); private: - /** - * recv the rtsp message. - */ + // Recv the rtsp message. virtual srs_error_t do_recv_message(SrsRtspRequest* req); - /** - * read a normal token from io, error when token state is not normal. - */ + // Read a normal token from io, error when token state is not normal. virtual srs_error_t recv_token_normal(std::string& token); - /** - * read a normal token from io, error when token state is not eof. - */ + // Read a normal token from io, error when token state is not eof. virtual srs_error_t recv_token_eof(std::string& token); - /** - * read the token util got eof, for example, to read the response status Reason-Phrase - * @param pconsumed, output the token parsed length. NULL to ignore. - */ + // Read the token util got eof, for example, to read the response status Reason-Phrase + // @param pconsumed, output the token parsed length. NULL to ignore. virtual srs_error_t recv_token_util_eof(std::string& token, int* pconsumed = NULL); - /** - * read a token from io, split by SP, endswith CRLF: - * token1 SP token2 SP ... tokenN CRLF - * @param token, output the read token. - * @param state, output the token parse state. - * @param normal_ch, the char to indicates the normal token. - * the SP use to indicates the normal token, @see SRS_RTSP_SP - * the 0x00 use to ignore normal token flag. @see recv_token_util_eof - * @param pconsumed, output the token parsed length. NULL to ignore. - */ + // Read a token from io, split by SP, endswith CRLF: + // token1 SP token2 SP ... tokenN CRLF + // @param token, output the read token. + // @param state, output the token parse state. + // @param normal_ch, the char to indicates the normal token. + // the SP use to indicates the normal token, @see SRS_RTSP_SP + // the 0x00 use to ignore normal token flag. @see recv_token_util_eof + // @param pconsumed, output the token parsed length. NULL to ignore. virtual srs_error_t recv_token(std::string& token, SrsRtspTokenState& state, char normal_ch = SRS_RTSP_SP, int* pconsumed = NULL); };