diff --git a/trunk/src/app/srs_app_async_call.hpp b/trunk/src/app/srs_app_async_call.hpp index 61afcc1ac..183533457 100644 --- a/trunk/src/app/srs_app_async_call.hpp +++ b/trunk/src/app/srs_app_async_call.hpp @@ -31,38 +31,29 @@ #include -/** - * the async call for http hooks, - * for the http hooks will switch st-thread, - * so we must use isolate thread to avoid the thread corrupt, - * for example, when dvr call http hooks, the video receive thread got - * a video and pass it to the dvr again. - * futhurmore, the aync call never block the main worker thread. - */ +// The async call for http hooks, for the http hooks will switch st-thread, +// so we must use isolate thread to avoid the thread corrupt, +// for example, when dvr call http hooks, the video receive thread got +// a video and pass it to the dvr again. +// Futhurmore, the aync call never block the main worker thread. class ISrsAsyncCallTask { public: ISrsAsyncCallTask(); virtual ~ISrsAsyncCallTask(); public: - /** - * execute the task async. - * this method is the actual execute method of task, - * for example, to notify callback server. - */ + // Execute the task async. + // This method is the actual execute method of task, + // for example, to notify callback server. virtual srs_error_t call() = 0; - /** - * convert task to string to describe it. - * used for logger. - */ + // Convert task to string to describe it. + // It's used for logger. virtual std::string to_string() = 0; }; -/** - * the async callback for dvr, callback and other async worker. - * when worker call with the task, the worker will do it in isolate thread. - * that is, the task is execute/call in async mode. - */ +// The async callback for dvr, callback and other async worker. +// When worker call with the task, the worker will do it in isolate thread. +// That is, the task is execute/call in async mode. class SrsAsyncCallWorker : public ISrsCoroutineHandler { private: diff --git a/trunk/src/app/srs_app_bandwidth.hpp b/trunk/src/app/srs_app_bandwidth.hpp index 0afdf9e07..af7b232ab 100644 --- a/trunk/src/app/srs_app_bandwidth.hpp +++ b/trunk/src/app/srs_app_bandwidth.hpp @@ -36,85 +36,69 @@ class SrsRtmpServer; class SrsKbpsLimit; class ISrsProtocolStatistic; -/** - * bandwidth check/test sample. - */ +// The bandwidth check/test sample. class SrsBandwidthSample { public: - /** - * the plan, how long to do the test, in ms, - * if exceed the duration, abort the test. - */ + // The plan, how long to do the test, in ms, + // if exceed the duration, abort the test. int duration_ms; - /** - * the plan, interval for each check/test packet, in ms - */ + // The plan, interval for each check/test packet, in ms int interval_ms; public: - /** - * the actual test duration, in ms. - */ + // The actual test duration, in ms. int actual_duration_ms; - /** - * the actual test bytes - */ + // The actual test bytes int bytes; - /** - * the actual test kbps - */ + // The actual test kbps int kbps; public: SrsBandwidthSample(); virtual ~SrsBandwidthSample(); public: - /** - * update the bytes and actual duration, then calc the kbps. - * @param _bytes update the sample bytes. - * @param _duration update the actual duration, in ms. - */ + // Update the bytes and actual duration, then calc the kbps. + // @param _bytes update the sample bytes. + // @param _duration update the actual duration, in ms. virtual void calc_kbps(int _bytes, int _duration); }; -/** - * bandwidth test agent which provides the interfaces for bandwidth check. - * 1. if vhost disabled bandwidth check, ignore. - * 2. otherwise, check the key, error if verify failed. - * 3. check the interval limit, error if bandwidth in the interval window. - * 4. check the bandwidth under the max kbps. - * 5. send the bandwidth data to client. - * bandwidth workflow: - * +------------+ +----------+ - * | Client | | Server | - * +-----+------+ +-----+----+ - * | | - * | connect vhost------> | if vhost enable bandwidth, - * | <-----result(success) | do bandwidth check. - * | | - * | <----call(start play) | onSrsBandCheckStartPlayBytes - * | result(playing)-----> | onSrsBandCheckStartingPlayBytes - * | <-------data(playing) | onSrsBandCheckStartingPlayBytes - * | <-----call(stop play) | onSrsBandCheckStopPlayBytes - * | result(stopped)-----> | onSrsBandCheckStoppedPlayBytes - * | | - * | <-call(start publish) | onSrsBandCheckStartPublishBytes - * | result(publishing)--> | onSrsBandCheckStartingPublishBytes - * | data(publishing)(3)-> | onSrsBandCheckStartingPublishBytes - * | <--call(stop publish) | onSrsBandCheckStopPublishBytes - * | result(stopped)(1)--> | onSrsBandCheckStoppedPublishBytes - * | | - * | <--------------report | - * | final(2)------------> | finalClientPacket - * | | - * - * 1. when flash client, server never wait the stop publish response, - * for the flash client queue is fullfill with other packets. - * 2. when flash client, server never wait the final packet, - * for the flash client directly close when got report packet. - * 3. for linux client, it will send the publish data then send a stop publish, - * for the linux client donot know when to stop the publish. - * when server got publishing and stop publish, stop publish. - */ +// The bandwidth test agent which provides the interfaces for bandwidth check. +// 1. if vhost disabled bandwidth check, ignore. +// 2. otherwise, check the key, error if verify failed. +// 3. check the interval limit, error if bandwidth in the interval window. +// 4. check the bandwidth under the max kbps. +// 5. send the bandwidth data to client. +// bandwidth workflow: +// +------------+ +----------+ +// | Client | | Server | +// +-----+------+ +-----+----+ +// | | +// | connect vhost------> | if vhost enable bandwidth, +// | <-----result(success) | do bandwidth check. +// | | +// | <----call(start play) | onSrsBandCheckStartPlayBytes +// | result(playing)-----> | onSrsBandCheckStartingPlayBytes +// | <-------data(playing) | onSrsBandCheckStartingPlayBytes +// | <-----call(stop play) | onSrsBandCheckStopPlayBytes +// | result(stopped)-----> | onSrsBandCheckStoppedPlayBytes +// | | +// | <-call(start publish) | onSrsBandCheckStartPublishBytes +// | result(publishing)--> | onSrsBandCheckStartingPublishBytes +// | data(publishing)(3)-> | onSrsBandCheckStartingPublishBytes +// | <--call(stop publish) | onSrsBandCheckStopPublishBytes +// | result(stopped)(1)--> | onSrsBandCheckStoppedPublishBytes +// | | +// | <--------------report | +// | final(2)------------> | finalClientPacket +// | | +// +// 1. when flash client, server never wait the stop publish response, +// for the flash client queue is fullfill with other packets. +// 2. when flash client, server never wait the final packet, +// for the flash client directly close when got report packet. +// 3. for linux client, it will send the publish data then send a stop publish, +// for the linux client donot know when to stop the publish. +// when server got publishing and stop publish, stop publish. class SrsBandwidth { private: @@ -124,81 +108,61 @@ public: SrsBandwidth(); virtual ~SrsBandwidth(); public: - /** - * do the bandwidth check. - * @param rtmp, server RTMP protocol object, send/recv RTMP packet to/from client. - * @param io_stat, the underlayer io statistic, provides send/recv bytes count. - * @param req, client request object, specifies the request info from client. - * @param local_ip, the ip of server which client connected at - */ + // Do the bandwidth check. + // @param rtmp, server RTMP protocol object, send/recv RTMP packet to/from client. + // @param io_stat, the underlayer io statistic, provides send/recv bytes count. + // @param req, client request object, specifies the request info from client. + // @param local_ip, the ip of server which client connected at virtual srs_error_t bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io_stat, SrsRequest* req, std::string local_ip); private: - /** - * used to process band width check from client. - * @param limit, the bandwidth limit object, to slowdown if exceed the kbps. - */ + // Used to process band width check from client. + // @param limit, the bandwidth limit object, to slowdown if exceed the kbps. virtual srs_error_t do_bandwidth_check(SrsKbpsLimit* limit); // play check/test, downloading bandwidth kbps. private: - /** - * start play/download bandwidth check/test, - * send start-play command to client, client must response starting-play - * to start the test. - */ + // Start play/download bandwidth check/test, + // send start-play command to client, client must response starting-play + // to start the test. virtual srs_error_t play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); - /** - * do play/download bandwidth check/test, - * server send call messages to client in specified time, - * calc the time and bytes sent, then we got the kbps. - */ + // Do play/download bandwidth check/test, + // server send call messages to client in specified time, + // calc the time and bytes sent, then we got the kbps. virtual srs_error_t play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); - /** - * stop play/download bandwidth check/test, - * send stop-play command to client, client must response stopped-play - * to stop the test. - */ + // stop play/download bandwidth check/test, + // send stop-play command to client, client must response stopped-play + // to stop the test. virtual srs_error_t play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); // publish check/test, publishing bandwidth kbps. private: - /** - * start publish/upload bandwidth check/test, - * send start-publish command to client, client must response starting-publish - * to start the test. - */ + // Start publish/upload bandwidth check/test, + // send start-publish command to client, client must response starting-publish + // to start the test. virtual srs_error_t publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); - /** - * do publish/upload bandwidth check/test, - * client send call messages to client in specified time, - * server calc the time and bytes received, then we got the kbps. - * @remark, for linux client, it will send a stop publish client, server will stop publishing. - * then enter the publish-stop stage with client. - * @remark, for flash client, it will send many many call messages, that is, - * the send queue is fullfill with call messages, so we should never expect the - * response message in the publish-stop stage. - */ + // Do publish/upload bandwidth check/test, + // client send call messages to client in specified time, + // server calc the time and bytes received, then we got the kbps. + // @remark, for linux client, it will send a stop publish client, server will stop publishing. + // then enter the publish-stop stage with client. + // @remark, for flash client, it will send many many call messages, that is, + // the send queue is fullfill with call messages, so we should never expect the + // response message in the publish-stop stage. virtual srs_error_t publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); - /** - * stop publish/upload bandwidth check/test, - * send stop-publish command to client, - * for linux client, always expect a stopped-publish response from client, - * for flash client, the sent queue is fullfill with publishing call messages, - * so server never expect the stopped-publish from it. - */ + // Stop publish/upload bandwidth check/test, + // send stop-publish command to client, + // for linux client, always expect a stopped-publish response from client, + // for flash client, the sent queue is fullfill with publishing call messages, + // so server never expect the stopped-publish from it. virtual srs_error_t publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); private: - /** - * report and final packet - * report a finish packet, with the bytes/time/kbps bandwidth check/test result, - * for linux client, server always expect a final packet from client, - * for flash client, the sent queue is fullfill with publishing call messages, - * so server never expect the final packet from it. - */ + // Report and final packet + // report a finish packet, with the bytes/time/kbps bandwidth check/test result, + // for linux client, server always expect a final packet from client, + // for flash client, the sent queue is fullfill with publishing call messages, + // so server never expect the final packet from it. virtual srs_error_t do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, srs_utime_t start_time, srs_utime_t& end_time); }; -/** - * the kbps limit, if exceed the kbps, slow down. - */ +// The kbps limit, if exceed the kbps, slow down. class SrsKbpsLimit { private: @@ -208,17 +172,11 @@ public: SrsKbpsLimit(SrsKbps* kbps, int limit_kbps); virtual ~SrsKbpsLimit(); public: - /** - * get the system limit kbps. - */ + // Get the system limit kbps. virtual int limit_kbps(); - /** - * limit the recv bandwidth. - */ + // Limit the recv bandwidth. virtual void recv_limit(); - /** - * limit the send bandwidth. - */ + // Limit the send bandwidth. virtual void send_limit(); }; diff --git a/trunk/src/app/srs_app_caster_flv.hpp b/trunk/src/app/srs_app_caster_flv.hpp index 3e3d44f7c..8305d86c5 100644 --- a/trunk/src/app/srs_app_caster_flv.hpp +++ b/trunk/src/app/srs_app_caster_flv.hpp @@ -46,9 +46,7 @@ class SrsSimpleRtmpClient; #include #include -/** - * the stream caster for flv stream over HTTP POST. - */ +// The stream caster for flv stream over HTTP POST. class SrsAppCasterFlv : virtual public ISrsTcpHandler , virtual public IConnectionManager, virtual public ISrsHttpHandler { @@ -62,20 +60,18 @@ public: virtual ~SrsAppCasterFlv(); public: virtual srs_error_t initialize(); -// ISrsTcpHandler +// interface ISrsTcpHandler public: virtual srs_error_t on_tcp_client(srs_netfd_t stfd); -// IConnectionManager +// interface IConnectionManager public: virtual void remove(ISrsConnection* c); -// ISrsHttpHandler +// interface ISrsHttpHandler public: virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); }; -/** - * the dynamic http connection, never drop the body. - */ +// The dynamic http connection, never drop the body. class SrsDynamicHttpConn : public SrsHttpConn { private: @@ -93,10 +89,7 @@ private: virtual srs_error_t do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec); }; -/** - * the http wrapper for file reader, - * to read http post stream like a file. - */ +// The http wrapper for file reader, to read http post stream like a file. class SrsHttpFileReader : public SrsFileReader { private: @@ -105,9 +98,7 @@ public: SrsHttpFileReader(ISrsHttpResponseReader* h); virtual ~SrsHttpFileReader(); public: - /** - * open file reader, can open then close then open... - */ + // Open file reader, can open then close then open... virtual srs_error_t open(std::string file); virtual void close(); public: diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index be985a00a..6d52eb18e 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -49,47 +49,37 @@ class SrsConfDirective; namespace _srs_internal { - /** - * the buffer of config content. - */ + // The buffer of config content. class SrsConfigBuffer { protected: - // last available position. + // The last available position. char* last; - // end of buffer. + // The end of buffer. char* end; - // start of buffer. + // The start of buffer. char* start; public: - // current consumed position. + // Current consumed position. char* pos; - // current parsed line. + // Current parsed line. int line; public: SrsConfigBuffer(); virtual ~SrsConfigBuffer(); public: - /** - * fullfill the buffer with content of file specified by filename. - */ + // Fullfill the buffer with content of file specified by filename. virtual srs_error_t fullfill(const char* filename); - /** - * whether buffer is empty. - */ + // Whether buffer is empty. virtual bool empty(); }; }; -/** - * deep compare directive. - */ +// Deep compare directive. extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, std::string except); -/** - * helper utilities, used for compare the consts values. - */ +// The helper utilities, used for compare the consts values. extern bool srs_config_hls_is_on_error_ignore(std::string strategy); extern bool srs_config_hls_is_on_error_continue(std::string strategy); extern bool srs_config_ingest_is_file(std::string type); @@ -99,415 +89,277 @@ extern bool srs_config_dvr_is_plan_session(std::string plan); extern bool srs_stream_caster_is_udp(std::string caster); extern bool srs_stream_caster_is_rtsp(std::string caster); extern bool srs_stream_caster_is_flv(std::string caster); -// whether the dvr_apply active the stream specified by req. +// Whether the dvr_apply active the stream specified by req. extern bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req); -/** - * convert bool in str to on/off - */ +// Convert bool in str to on/off extern std::string srs_config_bool2switch(const std::string& sbool); -/** - * parse loaded vhost directives to compatible mode. - * for exmaple, SRS1/2 use the follow refer style: - * refer a.domain.com b.domain.com; - * while SRS3 use the following: - * refer { - * enabled on; - * all a.domain.com b.domain.com; - * } - * so we must transform the vhost directive anytime load the config. - * @param root the root directive to transform, in and out parameter. - */ +// Parse loaded vhost directives to compatible mode. +// For exmaple, SRS1/2 use the follow refer style: +// refer a.domain.com b.domain.com; +// while SRS3 use the following: +// refer { +// enabled on; +// all a.domain.com b.domain.com; +// } +// so we must transform the vhost directive anytime load the config. +// @param root the root directive to transform, in and out parameter. extern srs_error_t srs_config_transform_vhost(SrsConfDirective* root); // @global config object. extern SrsConfig* _srs_config; -/** - * the config directive. - * the config file is a group of directives, - * all directive has name, args and child-directives. - * for example, the following config text: - vhost vhost.ossrs.net { - enabled on; - ingest livestream { - enabled on; - ffmpeg /bin/ffmpeg; - } - } - * will be parsed to: - * SrsConfDirective: name="vhost", arg0="vhost.ossrs.net", child-directives=[ - * SrsConfDirective: name="enabled", arg0="on", child-directives=[] - * SrsConfDirective: name="ingest", arg0="livestream", child-directives=[ - * SrsConfDirective: name="enabled", arg0="on", child-directives=[] - * SrsConfDirective: name="ffmpeg", arg0="/bin/ffmpeg", child-directives=[] - * ] - * ] - * @remark, allow empty directive, for example: "dir0 {}" - * @remark, don't allow empty name, for example: ";" or "{dir0 arg0;} - */ +// The config directive. +// The config file is a group of directives, +// all directive has name, args and child-directives. +// For example, the following config text: +// vhost vhost.ossrs.net { +// enabled on; +// ingest livestream { +// enabled on; +// ffmpeg /bin/ffmpeg; +// } +// } +// will be parsed to: +// SrsConfDirective: name="vhost", arg0="vhost.ossrs.net", child-directives=[ +// SrsConfDirective: name="enabled", arg0="on", child-directives=[] +// SrsConfDirective: name="ingest", arg0="livestream", child-directives=[ +// SrsConfDirective: name="enabled", arg0="on", child-directives=[] +// SrsConfDirective: name="ffmpeg", arg0="/bin/ffmpeg", child-directives=[] +// ] +// ] +// @remark, allow empty directive, for example: "dir0 {}" +// @remark, don't allow empty name, for example: ";" or "{dir0 arg0;} class SrsConfDirective { public: - /** - * the line of config file in which the directive from - */ + // The line of config file in which the directive from int conf_line; - /** - * the name of directive, for example, the following config text: - * enabled on; - * will be parsed to a directive, its name is "enalbed" - */ + // The name of directive, for example, the following config text: + // enabled on; + // will be parsed to a directive, its name is "enalbed" std::string name; - /** - * the args of directive, for example, the following config text: - * listen 1935 1936; - * will be parsed to a directive, its args is ["1935", "1936"]. - */ + // The args of directive, for example, the following config text: + // listen 1935 1936; + // will be parsed to a directive, its args is ["1935", "1936"]. std::vector args; - /** - * the child directives, for example, the following config text: - * vhost vhost.ossrs.net { - * enabled on; - * } - * will be parsed to a directive, its directives is a vector contains - * a directive, which is: - * name:"enalbed", args:["on"], directives:[] - * - * @remark, the directives can contains directives. - */ + // The child directives, for example, the following config text: + // vhost vhost.ossrs.net { + // enabled on; + // } + // will be parsed to a directive, its directives is a vector contains + // a directive, which is: + // name:"enalbed", args:["on"], directives:[] + // + // @remark, the directives can contains directives. std::vector directives; public: SrsConfDirective(); virtual ~SrsConfDirective(); public: - /** - * deep copy the directive, for SrsConfig to use it to support reload in upyun cluster, - * for when reload the upyun dynamic config, the root will be changed, - * so need to copy it to an old root directive, and use the copy result to do reload. - */ + // Deep copy the directive, for SrsConfig to use it to support reload in upyun cluster, + // For when reload the upyun dynamic config, the root will be changed, + // so need to copy it to an old root directive, and use the copy result to do reload. virtual SrsConfDirective* copy(); // @param except the name of sub directive. virtual SrsConfDirective* copy(std::string except); // args public: - /** - * get the args0,1,2, if user want to get more args, - * directly use the args.at(index). - */ + // Get the args0,1,2, if user want to get more args, + // directly use the args.at(index). virtual std::string arg0(); virtual std::string arg1(); virtual std::string arg2(); virtual std::string arg3(); // directives public: - /** - * get the directive by index. - * @remark, assert the index& args, int& line_start); }; -/** - * the config service provider. - * for the config supports reload, so never keep the reference cross st-thread, - * that is, never save the SrsConfDirective* get by any api of config, - * for it maybe free in the reload st-thread cycle. - * you can keep it before st-thread switch, or simply never keep it. - */ +// The config service provider. +// For the config supports reload, so never keep the reference cross st-thread, +// that is, never save the SrsConfDirective* get by any api of config, +// For it maybe free in the reload st-thread cycle. +// You could keep it before st-thread switch, or simply never keep it. class SrsConfig { // user command private: - /** - * whether srs is run in dolphin mode. - * @see https://github.com/ossrs/srs-dolphin - */ + // Whether srs is run in dolphin mode. + // @see https://github.com/ossrs/srs-dolphin bool dolphin; std::string dolphin_rtmp_port; std::string dolphin_http_port; - /** - * whether show help and exit. - */ + // Whether show help and exit. bool show_help; - /** - * whether test config file and exit. - */ + // Whether test config file and exit. bool test_conf; - /** - * whether show SRS version and exit. - */ + // Whether show SRS version and exit. bool show_version; - /** - * whether show SRS signature and exit. - */ + // Whether show SRS signature and exit. bool show_signature; // global env variables. private: - /** - * the user parameters, the argc and argv. - * the argv is " ".join(argv), where argv is from main(argc, argv). - */ + // The user parameters, the argc and argv. + // The argv is " ".join(argv), where argv is from main(argc, argv). std::string _argv; - /** - * current working directory. - */ + // current working directory. std::string _cwd; - // config section + // Config section private: - /** - * the last parsed config file. - * if reload, reload the config file. - */ + // The last parsed config file. + // If reload, reload the config file. std::string config_file; protected: - /** - * the directive root. - */ + // The directive root. SrsConfDirective* root; -// reload section +// Reload section private: - /** - * the reload subscribers, when reload, callback all handlers. - */ + // The reload subscribers, when reload, callback all handlers. std::vector subscribes; public: SrsConfig(); virtual ~SrsConfig(); // dolphin public: - /** - * whether srs is in dolphin mode. - */ + // Whether srs is in dolphin mode. virtual bool is_dolphin(); private: virtual void set_config_directive(SrsConfDirective* parent, std::string dir, std::string value); -// reload +// Reload public: - /** - * for reload handler to register itself, - * when config service do the reload, callback the handler. - */ + // For reload handler to register itself, + // when config service do the reload, callback the handler. virtual void subscribe(ISrsReloadHandler* handler); - /** - * for reload handler to unregister itself. - */ + // For reload handler to unregister itself. virtual void unsubscribe(ISrsReloadHandler* handler); - /** - * reload the config file. - * @remark, user can test the config before reload it. - */ + // Reload the config file. + // @remark, user can test the config before reload it. virtual srs_error_t reload(); private: - /** - * reload the vhost section of config. - */ + // Reload the vhost section of config. virtual srs_error_t reload_vhost(SrsConfDirective* old_root); protected: - /** - * reload from the config. - * @remark, use protected for the utest to override with mock. - */ + // Reload from the config. + // @remark, use protected for the utest to override with mock. virtual srs_error_t reload_conf(SrsConfig* conf); private: - /** - * reload the http_api section of config. - */ + // Reload the http_api section of config. virtual srs_error_t reload_http_api(SrsConfDirective* old_root); - /** - * reload the http_stream section of config. - */ + // Reload the http_stream section of config. // TODO: FIXME: rename to http_server. virtual srs_error_t reload_http_stream(SrsConfDirective* old_root); - /** - * reload the transcode section of vhost of config. - */ + // Reload the transcode section of vhost of config. virtual srs_error_t reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); - /** - * reload the ingest section of vhost of config. - */ + // Reload the ingest section of vhost of config. virtual srs_error_t reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); - // parse options and file +// Parse options and file public: - /** - * parse the cli, the main(argc,argv) function. - */ + // Parse the cli, the main(argc,argv) function. virtual srs_error_t parse_options(int argc, char** argv); - /** - * initialize the cwd for server, - * because we may change the workdir. - */ + // initialize the cwd for server, + // because we may change the workdir. virtual srs_error_t initialize_cwd(); - /** - * persistence current config to file. - */ + // Marshal current config to file. virtual srs_error_t persistence(); private: virtual srs_error_t do_persistence(SrsFileWriter* fw); public: - /** - * dumps the global sections to json. - */ + // Dumps the global sections to json. virtual srs_error_t global_to_json(SrsJsonObject* obj); - /** - * dumps the minimal sections to json. - */ + // Dumps the minimal sections to json. virtual srs_error_t minimal_to_json(SrsJsonObject* obj); - /** - * dumps the vhost section to json. - */ + // Dumps the vhost section to json. virtual srs_error_t vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj); - /** - * dumps the http_api sections to json for raw api info. - */ + // Dumps the http_api sections to json for raw api info. virtual srs_error_t raw_to_json(SrsJsonObject* obj); - /** - * raw set the global listen. - */ + // RAW set the global listen. virtual srs_error_t raw_set_listen(const std::vector& eps, bool& applied); - /** - * raw set the global pid. - */ + // RAW set the global pid. virtual srs_error_t raw_set_pid(std::string pid, bool& applied); - /** - * raw set the global chunk size. - */ + // RAW set the global chunk size. virtual srs_error_t raw_set_chunk_size(std::string chunk_size, bool& applied); - /** - * raw set the global ffmpeg log dir. - */ + // RAW set the global ffmpeg log dir. virtual srs_error_t raw_set_ff_log_dir(std::string ff_log_dir, bool& applied); - /** - * raw set the global log tank. - */ + // RAW set the global log tank. virtual srs_error_t raw_set_srs_log_tank(std::string srs_log_tank, bool& applied); - /** - * raw set the global log level. - */ + // RAW set the global log level. virtual srs_error_t raw_set_srs_log_level(std::string srs_log_level, bool& applied); - /** - * raw set the global log file path for file tank. - */ + // RAW set the global log file path for file tank. virtual srs_error_t raw_set_srs_log_file(std::string srs_log_file, bool& applied); - /** - * raw set the global max connections of srs. - */ + // RAW set the global max connections of srs. virtual srs_error_t raw_set_max_connections(std::string max_connections, bool& applied); - /** - * raw set the global whether use utc time. - */ + // RAW set the global whether use utc time. virtual srs_error_t raw_set_utc_time(std::string utc_time, bool& applied); - /** - * raw set the global pithy print interval in ms. - */ + // RAW set the global pithy print interval in ms. virtual srs_error_t raw_set_pithy_print_ms(std::string pithy_print_ms, bool& applied); - /** - * raw create the new vhost. - */ + // RAW create the new vhost. virtual srs_error_t raw_create_vhost(std::string vhost, bool& applied); - /** - * raw update the disabled vhost name. - */ + // RAW update the disabled vhost name. virtual srs_error_t raw_update_vhost(std::string vhost, std::string name, bool& applied); - /** - * raw delete the disabled vhost. - */ + // RAW delete the disabled vhost. virtual srs_error_t raw_delete_vhost(std::string vhost, bool& applied); - /** - * raw disable the enabled vhost. - */ + // RAW disable the enabled vhost. virtual srs_error_t raw_disable_vhost(std::string vhost, bool& applied); - /** - * raw enable the disabled vhost. - */ + // RAW enable the disabled vhost. virtual srs_error_t raw_enable_vhost(std::string vhost, bool& applied); - /** - * raw enable the dvr of stream of vhost. - */ + // RAW enable the dvr of stream of vhost. virtual srs_error_t raw_enable_dvr(std::string vhost, std::string stream, bool& applied); - /** - * raw disable the dvr of stream of vhost. - */ + // RAW disable the dvr of stream of vhost. virtual srs_error_t raw_disable_dvr(std::string vhost, std::string stream, bool& applied); private: virtual srs_error_t do_reload_listen(); @@ -522,627 +374,393 @@ private: virtual srs_error_t do_reload_vhost_removed(std::string vhost); virtual srs_error_t do_reload_vhost_dvr_apply(std::string vhost); public: - /** - * get the config file path. - */ + // Get the config file path. virtual std::string config(); private: - /** - * parse each argv. - */ + // Parse each argv. virtual srs_error_t parse_argv(int& i, char** argv); - /** - * print help and exit. - */ + // Print help and exit. virtual void print_help(char** argv); public: - /** - * parse the config file, which is specified by cli. - */ + // Parse the config file, which is specified by cli. virtual srs_error_t parse_file(const char* filename); - /** - * check the parsed config. - */ + // Check the parsed config. virtual srs_error_t check_config(); protected: virtual srs_error_t check_normal_config(); virtual srs_error_t check_number_connections(); protected: - /** - * parse config from the buffer. - * @param buffer, the config buffer, user must delete it. - * @remark, use protected for the utest to override with mock. - */ + // Parse config from the buffer. + // @param buffer, the config buffer, user must delete it. + // @remark, use protected for the utest to override with mock. virtual srs_error_t parse_buffer(_srs_internal::SrsConfigBuffer* buffer); // global env public: - /** - * get the current work directory. - */ + // Get the current work directory. virtual std::string cwd(); - /** - * get the cli, the main(argc,argv), program start command. - */ + // Get the cli, the main(argc,argv), program start command. virtual std::string argv(); // global section public: - /** - * get the directive root, corresponding to the config file. - * the root directive, no name and args, contains directives. - * all directive parsed can retrieve from root. - */ + // Get the directive root, corresponding to the config file. + // The root directive, no name and args, contains directives. + // All directive parsed can retrieve from root. virtual SrsConfDirective* get_root(); - /** - * get the deamon config. - * if true, SRS will run in deamon mode, fork and fork to reap the - * grand-child process to init process. - */ + // Get the deamon config. + // If true, SRS will run in deamon mode, fork and fork to reap the + // grand-child process to init process. virtual bool get_deamon(); - /** - * get the max connections limit of system. - * if exceed the max connection, SRS will disconnect the connection. - * @remark, linux will limit the connections of each process, - * for example, when you need SRS to service 10000+ connections, - * user must use "ulimit -HSn 10000" and config the max connections - * of SRS. - */ + // Get the max connections limit of system. + // If exceed the max connection, SRS will disconnect the connection. + // @remark, linux will limit the connections of each process, + // for example, when you need SRS to service 10000+ connections, + // user must use "ulimit -HSn 10000" and config the max connections + // of SRS. virtual int get_max_connections(); - /** - * get the listen port of SRS. - * user can specifies multiple listen ports, - * each args of directive is a listen port. - */ + // Get the listen port of SRS. + // user can specifies multiple listen ports, + // each args of directive is a listen port. virtual std::vector get_listens(); - /** - * get the pid file path. - * the pid file is used to save the pid of SRS, - * use file lock to prevent multiple SRS starting. - * @remark, if user need to run multiple SRS instance, - * for example, to start multiple SRS for multiple CPUs, - * user can use different pid file for each process. - */ + // Get the pid file path. + // The pid file is used to save the pid of SRS, + // use file lock to prevent multiple SRS starting. + // @remark, if user need to run multiple SRS instance, + // for example, to start multiple SRS for multiple CPUs, + // user can use different pid file for each process. virtual std::string get_pid_file(); - /** - * get pithy print pulse in srs_utime_t, - * for example, all rtmp connections only print one message - * every this interval in ms. - */ + // Get pithy print pulse in srs_utime_t, + // For example, all rtmp connections only print one message + // every this interval in ms. virtual srs_utime_t get_pithy_print(); - /** - * whether use utc-time to format the time. - */ + // Whether use utc-time to format the time. virtual bool get_utc_time(); - /** - * get the configed work dir. - * ignore if empty string. - */ + // Get the configed work dir. + // ignore if empty string. virtual std::string get_work_dir(); - // whether use asprocess mode. + // Whether use asprocess mode. virtual bool get_asprocess(); // stream_caster section public: - /** - * get all stream_caster in config file. - */ + // Get all stream_caster in config file. virtual std::vector get_stream_casters(); - /** - * get whether the specified stream_caster is enabled. - */ + // Get whether the specified stream_caster is enabled. virtual bool get_stream_caster_enabled(SrsConfDirective* conf); - /** - * get the engine of stream_caster, the caster config. - */ + // Get the engine of stream_caster, the caster config. virtual std::string get_stream_caster_engine(SrsConfDirective* conf); - /** - * get the output rtmp url of stream_caster, the output config. - */ + // Get the output rtmp url of stream_caster, the output config. virtual std::string get_stream_caster_output(SrsConfDirective* conf); - /** - * get the listen port of stream caster. - */ + // Get the listen port of stream caster. virtual int get_stream_caster_listen(SrsConfDirective* conf); - /** - * get the min udp port for rtp of stream caster rtsp. - */ + // Get the min udp port for rtp of stream caster rtsp. virtual int get_stream_caster_rtp_port_min(SrsConfDirective* conf); - /** - * get the max udp port for rtp of stream caster rtsp. - */ + // Get the max udp port for rtp of stream caster rtsp. virtual int get_stream_caster_rtp_port_max(SrsConfDirective* conf); // kafka section. public: - /** - * whether the kafka enabled. - */ + // Whether the kafka enabled. virtual bool get_kafka_enabled(); - /** - * get the broker list, each is format in . - */ + // Get the broker list, each is format in . virtual SrsConfDirective* get_kafka_brokers(); - /** - * get the kafka topic to use for srs. - */ + // Get the kafka topic to use for srs. virtual std::string get_kafka_topic(); // vhost specified section public: - /** - * get the vhost directive by vhost name. - * @param vhost, the name of vhost to get. - * @param try_default_vhost whether try default when get specified vhost failed. - */ + // Get the vhost directive by vhost name. + // @param vhost, the name of vhost to get. + // @param try_default_vhost whether try default when get specified vhost failed. virtual SrsConfDirective* get_vhost(std::string vhost, bool try_default_vhost = true); - /** - * get all vhosts in config file. - */ + // Get all vhosts in config file. virtual void get_vhosts(std::vector& vhosts); - /** - * whether vhost is enabled - * @param vhost, the vhost name. - * @return true when vhost is ok; otherwise, false. - */ + // Whether vhost is enabled + // @param vhost, the vhost name. + // @return true when vhost is ok; otherwise, false. virtual bool get_vhost_enabled(std::string vhost); - /** - * whether vhost is enabled - * @param vhost, the vhost directive. - * @return true when vhost is ok; otherwise, false. - */ + // Whether vhost is enabled + // @param vhost, the vhost directive. + // @return true when vhost is ok; otherwise, false. virtual bool get_vhost_enabled(SrsConfDirective* conf); - /** - * whether gop_cache is enabled of vhost. - * gop_cache used to cache last gop, for client to fast startup. - * @return true when gop_cache is ok; otherwise, false. - * @remark, default true. - */ + // Whether gop_cache is enabled of vhost. + // gop_cache used to cache last gop, for client to fast startup. + // @return true when gop_cache is ok; otherwise, false. + // @remark, default true. virtual bool get_gop_cache(std::string vhost); - /** - * whether debug_srs_upnode is enabled of vhost. - * debug_srs_upnode is very important feature for tracable log, - * but some server, for instance, flussonic donot support it. - * @see https://github.com/ossrs/srs/issues/160 - * @return true when debug_srs_upnode is ok; otherwise, false. - * @remark, default true. - */ + // Whether debug_srs_upnode is enabled of vhost. + // debug_srs_upnode is very important feature for tracable log, + // but some server, for instance, flussonic donot support it. + // @see https://github.com/ossrs/srs/issues/160 + // @return true when debug_srs_upnode is ok; otherwise, false. + // @remark, default true. virtual bool get_debug_srs_upnode(std::string vhost); - /** - * whether atc is enabled of vhost. - * atc always use encoder timestamp, SRS never adjust the time. - * @return true when atc is ok; otherwise, false. - * @remark, default false. - */ + // Whether atc is enabled of vhost. + // atc always use encoder timestamp, SRS never adjust the time. + // @return true when atc is ok; otherwise, false. + // @remark, default false. virtual bool get_atc(std::string vhost); - /** - * whether atc_auto is enabled of vhost. - * atc_auto used to auto enable atc, when metadata specified the bravo_atc. - * @return true when atc_auto is ok; otherwise, false. - * @remark, default true. - */ + // Whether atc_auto is enabled of vhost. + // atc_auto used to auto enable atc, when metadata specified the bravo_atc. + // @return true when atc_auto is ok; otherwise, false. + // @remark, default true. virtual bool get_atc_auto(std::string vhost); - /** - * get the time_jitter algorithm. - * @return the time_jitter algorithm, defined in SrsRtmpJitterAlgorithm. - * @remark, default full. - */ + // Get the time_jitter algorithm. + // @return the time_jitter algorithm, defined in SrsRtmpJitterAlgorithm. + // @remark, default full. virtual int get_time_jitter(std::string vhost); - /** - * whether use mix correct algorithm to ensure the timestamp - * monotonically increase. - */ + // Whether use mix correct algorithm to ensure the timestamp + // monotonically increase. virtual bool get_mix_correct(std::string vhost); - /** - * get the cache queue length, in srs_utime_t. - * when exceed the queue length, drop packet util I frame. - * @remark, default 10s. - */ + // Get the cache queue length, in srs_utime_t. + // when exceed the queue length, drop packet util I frame. + // @remark, default 10s. virtual srs_utime_t get_queue_length(std::string vhost); - /** - * whether the refer hotlink-denial enabled. - */ + // Whether the refer hotlink-denial enabled. virtual bool get_refer_enabled(std::string vhost); - /** - * get the refer hotlink-denial for all type. - * @return the refer, NULL for not configed. - */ + // Get the refer hotlink-denial for all type. + // @return the refer, NULL for not configed. virtual SrsConfDirective* get_refer_all(std::string vhost); - /** - * get the refer hotlink-denial for play. - * @return the refer, NULL for not configed. - */ + // Get the refer hotlink-denial for play. + // @return the refer, NULL for not configed. virtual SrsConfDirective* get_refer_play(std::string vhost); - /** - * get the refer hotlink-denial for publish. - * @return the refer, NULL for not configed. - */ + // Get the refer hotlink-denial for publish. + // @return the refer, NULL for not configed. virtual SrsConfDirective* get_refer_publish(std::string vhost); // Get the input default ack size, which is generally set by message from peer. virtual int get_in_ack_size(std::string vhost); // Get the output default ack size, to notify the peer to send acknowledge to server. virtual int get_out_ack_size(std::string vhost); - /** - * get the chunk size of vhost. - * @param vhost, the vhost to get the chunk size. use global if not specified. - * empty string to get the global. - * @remark, default 60000. - */ + // Get the chunk size of vhost. + // @param vhost, the vhost to get the chunk size. use global if not specified. + // empty string to get the global. + // @remark, default 60000. virtual int get_chunk_size(std::string vhost); - /** - * whether parse the sps when publish stream to SRS. - */ + // Whether parse the sps when publish stream to SRS. virtual bool get_parse_sps(std::string vhost); - /** - * whether mr is enabled for vhost. - * @param vhost, the vhost to get the mr. - */ + // Whether mr is enabled for vhost. + // @param vhost, the vhost to get the mr. virtual bool get_mr_enabled(std::string vhost); - /** - * get the mr sleep time in srs_utime_t for vhost. - * @param vhost, the vhost to get the mr sleep time. - */ + // Get the mr sleep time in srs_utime_t for vhost. + // @param vhost, the vhost to get the mr sleep time. // TODO: FIXME: add utest for mr config. virtual srs_utime_t get_mr_sleep(std::string vhost); - /** - * get the mw sleep time in srs_utime_t for vhost. - * @param vhost, the vhost to get the mw sleep time. - */ + // Get the mw sleep time in srs_utime_t for vhost. + // @param vhost, the vhost to get the mw sleep time. // TODO: FIXME: add utest for mw config. virtual srs_utime_t get_mw_sleep(std::string vhost); - /** - * whether min latency mode enabled. - * @param vhost, the vhost to get the min_latency. - */ + // Whether min latency mode enabled. + // @param vhost, the vhost to get the min_latency. // TODO: FIXME: add utest for min_latency. virtual bool get_realtime_enabled(std::string vhost); - /** - * whether enable tcp nodelay for all clients of vhost. - */ + // Whether enable tcp nodelay for all clients of vhost. virtual bool get_tcp_nodelay(std::string vhost); - /** - * the minimal send interval in srs_utime_t. - */ + // The minimal send interval in srs_utime_t. virtual srs_utime_t get_send_min_interval(std::string vhost); - /** - * whether reduce the sequence header. - */ + // Whether reduce the sequence header. virtual bool get_reduce_sequence_header(std::string vhost); - /** - * the 1st packet timeout in srs_utime_t for encoder. - */ + // The 1st packet timeout in srs_utime_t for encoder. virtual srs_utime_t get_publish_1stpkt_timeout(std::string vhost); - /** - * the normal packet timeout in srs_utime_t for encoder. - */ + // The normal packet timeout in srs_utime_t for encoder. virtual srs_utime_t get_publish_normal_timeout(std::string vhost); private: - /** - * get the global chunk size. - */ + // Get the global chunk size. virtual int get_global_chunk_size(); // forward section public: - /** - * whether the forwarder enabled. - */ + // Whether the forwarder enabled. virtual bool get_forward_enabled(std::string vhost); - /** - * get the forward directive of vhost. - */ + // Get the forward directive of vhost. virtual SrsConfDirective* get_forwards(std::string vhost); // http_hooks section private: - /** - * get the http_hooks directive of vhost. - */ + // Get the http_hooks directive of vhost. virtual SrsConfDirective* get_vhost_http_hooks(std::string vhost); public: - /** - * whether vhost http-hooks enabled. - * @remark, if not enabled, donot callback all http hooks. - */ + // Whether vhost http-hooks enabled. + // @remark, if not enabled, donot callback all http hooks. virtual bool get_vhost_http_hooks_enabled(std::string vhost); - /** - * get the on_connect callbacks of vhost. - * @return the on_connect callback directive, the args is the url to callback. - */ + // Get the on_connect callbacks of vhost. + // @return the on_connect callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_connect(std::string vhost); - /** - * get the on_close callbacks of vhost. - * @return the on_close callback directive, the args is the url to callback. - */ + // Get the on_close callbacks of vhost. + // @return the on_close callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_close(std::string vhost); - /** - * get the on_publish callbacks of vhost. - * @return the on_publish callback directive, the args is the url to callback. - */ + // Get the on_publish callbacks of vhost. + // @return the on_publish callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_publish(std::string vhost); - /** - * get the on_unpublish callbacks of vhost. - * @return the on_unpublish callback directive, the args is the url to callback. - */ + // Get the on_unpublish callbacks of vhost. + // @return the on_unpublish callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); - /** - * get the on_play callbacks of vhost. - * @return the on_play callback directive, the args is the url to callback. - */ + // Get the on_play callbacks of vhost. + // @return the on_play callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_play(std::string vhost); - /** - * get the on_stop callbacks of vhost. - * @return the on_stop callback directive, the args is the url to callback. - */ + // Get the on_stop callbacks of vhost. + // @return the on_stop callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); - /** - * get the on_dvr callbacks of vhost. - * @return the on_dvr callback directive, the args is the url to callback. - */ + // Get the on_dvr callbacks of vhost. + // @return the on_dvr callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_dvr(std::string vhost); - /** - * get the on_hls callbacks of vhost. - * @return the on_hls callback directive, the args is the url to callback. - */ + // Get the on_hls callbacks of vhost. + // @return the on_hls callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_hls(std::string vhost); - /** - * get the on_hls_notify callbacks of vhost. - * @return the on_hls_notify callback directive, the args is the url to callback. - */ + // Get the on_hls_notify callbacks of vhost. + // @return the on_hls_notify callback directive, the args is the url to callback. virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost); // bwct(bandwidth check tool) section public: - /** - * whether bw check enabled for vhost. - * if enabled, serve all clients with bandwidth check services. - * oterwise, serve all cleints with stream. - */ + // Whether bw check enabled for vhost. + // If enabled, serve all clients with bandwidth check services. + // oterwise, serve all cleints with stream. virtual bool get_bw_check_enabled(std::string vhost); - /** - * the key of server, if client key mot match, reject. - */ + // The key of server, if client key mot match, reject. virtual std::string get_bw_check_key(std::string vhost); - /** - * the check interval, in srs_utime_t. - * if the client request check in very short time(in the interval), - * SRS will reject client. - * @remark this is used to prevent the bandwidth check attack. - */ + // The check interval, in srs_utime_t. + // If the client request check in very short time(in the interval), + // SRS will reject client. + // @remark this is used to prevent the bandwidth check attack. virtual srs_utime_t get_bw_check_interval(std::string vhost); - /** - * the max kbps that user can test, - * if exceed the kbps, server will slowdown the send-recv. - * @remark this is used to protect the service bandwidth. - */ + // The max kbps that user can test, + // If exceed the kbps, server will slowdown the send-recv. + // @remark this is used to protect the service bandwidth. virtual int get_bw_check_limit_kbps(std::string vhost); // vhost cluster section public: - /** - * whether vhost is edge mode. - * for edge, publish client will be proxyed to upnode, - * for edge, play client will share a connection to get stream from upnode. - */ + // Whether vhost is edge mode. + // For edge, publish client will be proxyed to upnode, + // For edge, play client will share a connection to get stream from upnode. virtual bool get_vhost_is_edge(std::string vhost); - /** - * whether vhost is edge mode. - * for edge, publish client will be proxyed to upnode, - * for edge, play client will share a connection to get stream from upnode. - */ + // Whether vhost is edge mode. + // For edge, publish client will be proxyed to upnode, + // For edge, play client will share a connection to get stream from upnode. virtual bool get_vhost_is_edge(SrsConfDirective* conf); - /** - * get the origin config of edge, - * specifies the origin ip address, port. - */ + // Get the origin config of edge, + // specifies the origin ip address, port. virtual SrsConfDirective* get_vhost_edge_origin(std::string vhost); - /** - * whether edge token tranverse is enabled, - * if true, edge will send connect origin to verfy the token of client. - * for example, we verify all clients on the origin FMS by server-side as, - * all clients connected to edge must be tranverse to origin to verify. - */ + // Whether edge token tranverse is enabled, + // If true, edge will send connect origin to verfy the token of client. + // For example, we verify all clients on the origin FMS by server-side as, + // all clients connected to edge must be tranverse to origin to verify. virtual bool get_vhost_edge_token_traverse(std::string vhost); - /** - * get the transformed vhost for edge, - * @see https://github.com/ossrs/srs/issues/372 - */ + // Get the transformed vhost for edge, + // @see https://github.com/ossrs/srs/issues/372 virtual std::string get_vhost_edge_transform_vhost(std::string vhost); - /** - * Whether enable the origin cluster. - * @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster - */ + // Whether enable the origin cluster. + // @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster virtual bool get_vhost_origin_cluster(std::string vhost); - /** - * Get the co-workers of origin cluster. - * @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster - */ + // Get the co-workers of origin cluster. + // @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster virtual std::vector get_vhost_coworkers(std::string vhost); // vhost security section public: - /** - * whether the secrity of vhost enabled. - */ + // Whether the secrity of vhost enabled. virtual bool get_security_enabled(std::string vhost); - /** - * get the security rules. - */ + // Get the security rules. virtual SrsConfDirective* get_security_rules(std::string vhost); // vhost transcode section public: - /** - * get the transcode directive of vhost in specified scope. - * @param vhost, the vhost name to get the transcode directive. - * @param scope, the scope, empty to get all. for example, user can transcode - * the app scope stream, by config with app: - * transcode live {...} - * when the scope is "live", this directive is matched. - * the scope can be: empty for all, app, app/stream. - * @remark, please see the samples of full.conf, the app.transcode.srs.com - * and stream.transcode.srs.com. - */ + // Get the transcode directive of vhost in specified scope. + // @param vhost, the vhost name to get the transcode directive. + // @param scope, the scope, empty to get all. for example, user can transcode + // the app scope stream, by config with app: + // transcode live {...} + // when the scope is "live", this directive is matched. + // the scope can be: empty for all, app, app/stream. + // @remark, please see the samples of full.conf, the app.transcode.srs.com + // and stream.transcode.srs.com. virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); - /** - * whether the transcode directive is enabled. - */ + // Whether the transcode directive is enabled. virtual bool get_transcode_enabled(SrsConfDirective* conf); - /** - * get the ffmpeg tool path of transcode. - */ + // Get the ffmpeg tool path of transcode. virtual std::string get_transcode_ffmpeg(SrsConfDirective* conf); - /** - * get the engines of transcode. - */ + // Get the engines of transcode. virtual std::vector get_transcode_engines(SrsConfDirective* conf); - /** - * whether the engine is enabled. - */ + // Whether the engine is enabled. virtual bool get_engine_enabled(SrsConfDirective* conf); - /** - * get the perfile of engine - */ + // Get the perfile of engine virtual std::vector get_engine_perfile(SrsConfDirective* conf); - /** - * get the iformat of engine - */ + // Get the iformat of engine virtual std::string get_engine_iformat(SrsConfDirective* conf); - /** - * get the vfilter of engine, - * the video filter set before the vcodec of FFMPEG. - */ + // Get the vfilter of engine, + // The video filter set before the vcodec of FFMPEG. virtual std::vector get_engine_vfilter(SrsConfDirective* conf); - /** - * get the vcodec of engine, - * the codec of video, can be vn, copy or libx264 - */ + // Get the vcodec of engine, + // The codec of video, can be vn, copy or libx264 virtual std::string get_engine_vcodec(SrsConfDirective* conf); - /** - * get the vbitrate of engine, - * the bitrate in kbps of video, for example, 800kbps - */ + // Get the vbitrate of engine, + // The bitrate in kbps of video, for example, 800kbps virtual int get_engine_vbitrate(SrsConfDirective* conf); - /** - * get the vfps of engine. - * the video fps, for example, 25fps - */ + // Get the vfps of engine. + // The video fps, for example, 25fps virtual double get_engine_vfps(SrsConfDirective* conf); - /** - * get the vwidth of engine, - * the video width, for example, 1024 - */ + // Get the vwidth of engine, + // The video width, for example, 1024 virtual int get_engine_vwidth(SrsConfDirective* conf); - /** - * get the vheight of engine, - * the video height, for example, 576 - */ + // Get the vheight of engine, + // The video height, for example, 576 virtual int get_engine_vheight(SrsConfDirective* conf); - /** - * get the vthreads of engine, - * the video transcode libx264 threads, for instance, 8 - */ + // Get the vthreads of engine, + // The video transcode libx264 threads, for instance, 8 virtual int get_engine_vthreads(SrsConfDirective* conf); - /** - * get the vprofile of engine, - * the libx264 profile, can be high,main,baseline - */ + // Get the vprofile of engine, + // The libx264 profile, can be high,main,baseline virtual std::string get_engine_vprofile(SrsConfDirective* conf); - /** - * get the vpreset of engine, - * the libx264 preset, can be ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo - */ + // Get the vpreset of engine, + // The libx264 preset, can be ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo virtual std::string get_engine_vpreset(SrsConfDirective* conf); - /** - * get the additional video params. - */ + // Get the additional video params. virtual std::vector get_engine_vparams(SrsConfDirective* conf); - /** - * get the acodec of engine, - * the audio codec can be an, copy or libfdk_aac - */ + // Get the acodec of engine, + // The audio codec can be an, copy or libfdk_aac virtual std::string get_engine_acodec(SrsConfDirective* conf); - /** - * get the abitrate of engine, - * the audio bitrate in kbps, for instance, 64kbps. - */ + // Get the abitrate of engine, + // The audio bitrate in kbps, for instance, 64kbps. virtual int get_engine_abitrate(SrsConfDirective* conf); - /** - * get the asample_rate of engine, - * the audio sample_rate, for instance, 44100HZ - */ + // Get the asample_rate of engine, + // The audio sample_rate, for instance, 44100HZ virtual int get_engine_asample_rate(SrsConfDirective* conf); - /** - * get the achannels of engine, - * the audio channel, for instance, 1 for mono, 2 for stereo. - */ + // Get the achannels of engine, + // The audio channel, for instance, 1 for mono, 2 for stereo. virtual int get_engine_achannels(SrsConfDirective* conf); - /** - * get the aparams of engine, - * the audio additional params. - */ + // Get the aparams of engine, + // The audio additional params. virtual std::vector get_engine_aparams(SrsConfDirective* conf); - /** - * get the oformat of engine - */ + // Get the oformat of engine virtual std::string get_engine_oformat(SrsConfDirective* conf); - /** - * get the output of engine, for example, rtmp://localhost/live/livestream, - * @remark, we will use some variable, for instance, [vhost] to substitude with vhost. - */ + // Get the output of engine, for example, rtmp://localhost/live/livestream, + // @remark, we will use some variable, for instance, [vhost] to substitude with vhost. virtual std::string get_engine_output(SrsConfDirective* conf); // vhost exec secion private: - /** - * get the exec directive of vhost. - */ + // Get the exec directive of vhost. virtual SrsConfDirective* get_exec(std::string vhost); public: - /** - * whether the exec is enabled of vhost. - */ + // Whether the exec is enabled of vhost. virtual bool get_exec_enabled(std::string vhost); - /** - * get all exec publish directives of vhost. - */ + // Get all exec publish directives of vhost. virtual std::vector get_exec_publishs(std::string vhost); // vhost ingest section public: - /** - * get the ingest directives of vhost. - */ + // Get the ingest directives of vhost. virtual std::vector get_ingesters(std::string vhost); - /** - * get specified ingest. - */ + // Get specified ingest. virtual SrsConfDirective* get_ingest_by_id(std::string vhost, std::string ingest_id); - /** - * whether ingest is enalbed. - */ + // Whether ingest is enalbed. virtual bool get_ingest_enabled(SrsConfDirective* conf); - /** - * get the ingest ffmpeg tool - */ + // Get the ingest ffmpeg tool virtual std::string get_ingest_ffmpeg(SrsConfDirective* conf); - /** - * get the ingest input type, file or stream. - */ + // Get the ingest input type, file or stream. virtual std::string get_ingest_input_type(SrsConfDirective* conf); - /** - * get the ingest input url. - */ + // Get the ingest input url. virtual std::string get_ingest_input_url(SrsConfDirective* conf); // log section public: - /** - * whether log to file. - */ + // Whether log to file. virtual bool get_log_tank_file(); - /** - * get the log level. - */ + // Get the log level. virtual std::string get_log_level(); - /** - * get the log file path. - */ + // Get the log file path. virtual std::string get_log_file(); - /** - * whether ffmpeg log enabled - */ + // Whether ffmpeg log enabled virtual bool get_ffmpeg_log_enabled(); - /** - * the ffmpeg log dir. - * @remark, /dev/null to disable it. - */ + // The ffmpeg log dir. + // @remark, /dev/null to disable it. virtual std::string get_ffmpeg_log_dir(); // The MPEG-DASH section. private: @@ -1162,299 +780,171 @@ public: virtual std::string get_dash_mpd_file(std::string vhost); // hls section private: - /** - * get the hls directive of vhost. - */ + // Get the hls directive of vhost. virtual SrsConfDirective* get_hls(std::string vhost); public: - /** - * whether HLS is enabled. - */ + // Whether HLS is enabled. virtual bool get_hls_enabled(std::string vhost); - /** - * get the HLS m3u8 list ts segment entry prefix info. - */ + // Get the HLS m3u8 list ts segment entry prefix info. virtual std::string get_hls_entry_prefix(std::string vhost); - /** - * get the HLS ts/m3u8 file store path. - */ + // Get the HLS ts/m3u8 file store path. virtual std::string get_hls_path(std::string vhost); - /** - * get the HLS m3u8 file path template. - */ + // Get the HLS m3u8 file path template. virtual std::string get_hls_m3u8_file(std::string vhost); - /** - * get the HLS ts file path template. - */ + // Get the HLS ts file path template. virtual std::string get_hls_ts_file(std::string vhost); - /** - * whether enable the floor(timestamp/hls_fragment) for variable timestamp. - */ + // Whether enable the floor(timestamp/hls_fragment) for variable timestamp. virtual bool get_hls_ts_floor(std::string vhost); - /** - * get the hls fragment time, in srs_utime_t. - */ + // Get the hls fragment time, in srs_utime_t. virtual srs_utime_t get_hls_fragment(std::string vhost); - /** - * get the hls td(target duration) ratio. - */ + // Get the hls td(target duration) ratio. virtual double get_hls_td_ratio(std::string vhost); - /** - * get the hls aof(audio overflow) ratio. - */ + // Get the hls aof(audio overflow) ratio. virtual double get_hls_aof_ratio(std::string vhost); - /** - * get the hls window time, in srs_utime_t. - * a window is a set of ts, the ts collection in m3u8. - * @remark SRS will delete the ts exceed the window. - */ + // Get the hls window time, in srs_utime_t. + // a window is a set of ts, the ts collection in m3u8. + // @remark SRS will delete the ts exceed the window. virtual srs_utime_t get_hls_window(std::string vhost); - /** - * get the hls hls_on_error config. - * the ignore will ignore error and disable hls. - * the disconnect will disconnect publish connection. - * @see https://github.com/ossrs/srs/issues/264 - */ + // Get the hls hls_on_error config. + // The ignore will ignore error and disable hls. + // The disconnect will disconnect publish connection. + // @see https://github.com/ossrs/srs/issues/264 virtual std::string get_hls_on_error(std::string vhost); - /** - * get the HLS default audio codec. - */ + // Get the HLS default audio codec. virtual std::string get_hls_acodec(std::string vhost); - /** - * get the HLS default video codec. - */ + // Get the HLS default video codec. virtual std::string get_hls_vcodec(std::string vhost); - /** - * whether cleanup the old ts files. - */ + // Whether cleanup the old ts files. virtual bool get_hls_cleanup(std::string vhost); - /** - * the timeout in srs_utime_t to dispose the hls. - */ + // The timeout in srs_utime_t to dispose the hls. virtual srs_utime_t get_hls_dispose(std::string vhost); - /** - * whether reap the ts when got keyframe. - */ + // Whether reap the ts when got keyframe. virtual bool get_hls_wait_keyframe(std::string vhost); - /** - * encrypt ts or not - */ + // encrypt ts or not virtual bool get_hls_keys(std::string vhost); - /** - * how many fragments can one key encrypted. - */ + // how many fragments can one key encrypted. virtual int get_hls_fragments_per_key(std::string vhost); - /** - * get the HLS key file path template. - */ + // Get the HLS key file path template. virtual std::string get_hls_key_file(std::string vhost); - /** - * get the HLS key file store path. - */ + // Get the HLS key file store path. virtual std::string get_hls_key_file_path(std::string vhost); - /** - * get the HLS key file url which will be put in m3u8 - */ + // Get the HLS key file url which will be put in m3u8 virtual std::string get_hls_key_url(std::string vhost); - /** - * get the size of bytes to read from cdn network, for the on_hls_notify callback, - * that is, to read max bytes of the bytes from the callback, or timeout or error. - */ + // Get the size of bytes to read from cdn network, for the on_hls_notify callback, + // that is, to read max bytes of the bytes from the callback, or timeout or error. virtual int get_vhost_hls_nb_notify(std::string vhost); // hds section private: - /** - * get the hds directive of vhost. - */ + // Get the hds directive of vhost. virtual SrsConfDirective* get_hds(const std::string &vhost); public: - /** - * whether HDS is enabled. - */ + // Whether HDS is enabled. virtual bool get_hds_enabled(const std::string &vhost); - /** - * get the HDS file store path. - */ + // Get the HDS file store path. virtual std::string get_hds_path(const std::string &vhost); - /** - * get the hds fragment time, in srs_utime_t. - */ + // Get the hds fragment time, in srs_utime_t. virtual srs_utime_t get_hds_fragment(const std::string &vhost); - /** - * get the hds window time, in srs_utime_t. - * a window is a set of hds fragments. - */ + // Get the hds window time, in srs_utime_t. + // a window is a set of hds fragments. virtual srs_utime_t get_hds_window(const std::string &vhost); // dvr section private: - /** - * get the dvr directive. - */ + // Get the dvr directive. virtual SrsConfDirective* get_dvr(std::string vhost); public: - /** - * whether dvr is enabled. - */ + // Whether dvr is enabled. virtual bool get_dvr_enabled(std::string vhost); - /** - * get the filter of dvr to apply to. - * @remark user can use srs_config_apply_filter(conf, req):bool to check it. - */ + // Get the filter of dvr to apply to. + // @remark user can use srs_config_apply_filter(conf, req):bool to check it. virtual SrsConfDirective* get_dvr_apply(std::string vhost); - /** - * get the dvr path, the flv file to save in. - */ + // Get the dvr path, the flv file to save in. virtual std::string get_dvr_path(std::string vhost); - /** - * get the plan of dvr, how to reap the flv file. - */ + // Get the plan of dvr, how to reap the flv file. virtual std::string get_dvr_plan(std::string vhost); - /** - * get the duration of dvr flv. - */ + // Get the duration of dvr flv. virtual srs_utime_t get_dvr_duration(std::string vhost); - /** - * whether wait keyframe to reap segment. - */ + // Whether wait keyframe to reap segment. virtual bool get_dvr_wait_keyframe(std::string vhost); - /** - * get the time_jitter algorithm for dvr. - */ + // Get the time_jitter algorithm for dvr. virtual int get_dvr_time_jitter(std::string vhost); // http api section private: - /** - * whether http api enabled - */ + // Whether http api enabled virtual bool get_http_api_enabled(SrsConfDirective* conf); public: - /** - * whether http api enabled. - */ + // Whether http api enabled. virtual bool get_http_api_enabled(); - /** - * get the http api listen port. - */ + // Get the http api listen port. virtual std::string get_http_api_listen(); - /** - * whether enable crossdomain for http api. - */ + // Whether enable crossdomain for http api. virtual bool get_http_api_crossdomain(); - /** - * whether enable the HTTP RAW API. - */ + // Whether enable the HTTP RAW API. virtual bool get_raw_api(); - /** - * whether allow rpc reload. - */ + // Whether allow rpc reload. virtual bool get_raw_api_allow_reload(); - /** - * whether allow rpc query. - */ + // Whether allow rpc query. virtual bool get_raw_api_allow_query(); - /** - * whether allow rpc update. - */ + // Whether allow rpc update. virtual bool get_raw_api_allow_update(); // http stream section private: - /** - * whether http stream enabled. - */ + // Whether http stream enabled. virtual bool get_http_stream_enabled(SrsConfDirective* conf); public: - /** - * whether http stream enabled. - */ + // Whether http stream enabled. // TODO: FIXME: rename to http_static. virtual bool get_http_stream_enabled(); - /** - * get the http stream listen port. - */ + // Get the http stream listen port. virtual std::string get_http_stream_listen(); - /** - * get the http stream root dir. - */ + // Get the http stream root dir. virtual std::string get_http_stream_dir(); - /** - * whether enable crossdomain for http static and stream server. - */ + // Whether enable crossdomain for http static and stream server. virtual bool get_http_stream_crossdomain(); public: - /** - * get whether vhost enabled http stream - */ + // Get whether vhost enabled http stream virtual bool get_vhost_http_enabled(std::string vhost); - /** - * get the http mount point for vhost. - * for example, http://vhost/live/livestream - */ + // Get the http mount point for vhost. + // For example, http://vhost/live/livestream virtual std::string get_vhost_http_mount(std::string vhost); - /** - * get the http dir for vhost. - * the path on disk for mount root of http vhost. - */ + // Get the http dir for vhost. + // The path on disk for mount root of http vhost. virtual std::string get_vhost_http_dir(std::string vhost); // flv live streaming section public: - /** - * get whether vhost enabled http flv live stream - */ + // Get whether vhost enabled http flv live stream virtual bool get_vhost_http_remux_enabled(std::string vhost); - /** - * get the fast cache duration for http audio live stream. - */ + // Get the fast cache duration for http audio live stream. virtual srs_utime_t get_vhost_http_remux_fast_cache(std::string vhost); - /** - * get the http flv live stream mount point for vhost. - * used to generate the flv stream mount path. - */ + // Get the http flv live stream mount point for vhost. + // used to generate the flv stream mount path. virtual std::string get_vhost_http_remux_mount(std::string vhost); // http heartbeart section private: - /** - * get the heartbeat directive. - */ + // Get the heartbeat directive. virtual SrsConfDirective* get_heartbeart(); public: - /** - * whether heartbeat enabled. - */ + // Whether heartbeat enabled. virtual bool get_heartbeat_enabled(); - /** - * get the heartbeat interval, in srs_utime_t. - */ + // Get the heartbeat interval, in srs_utime_t. virtual srs_utime_t get_heartbeat_interval(); - /** - * get the heartbeat report url. - */ + // Get the heartbeat report url. virtual std::string get_heartbeat_url(); - /** - * get the device id of heartbeat, to report to server. - */ + // Get the device id of heartbeat, to report to server. virtual std::string get_heartbeat_device_id(); - /** - * whether report with summaries of http api: /api/v1/summaries. - */ + // Whether report with summaries of http api: /api/v1/summaries. virtual bool get_heartbeat_summaries(); // stats section private: - /** - * get the stats directive. - */ + // Get the stats directive. virtual SrsConfDirective* get_stats(); public: - /** - * get the network device index, used to retrieve the ip of device, - * for heartbeat to report to server, or to get the local ip. - * for example, 0 means the eth0 maybe. - */ + // Get the network device index, used to retrieve the ip of device, + // For heartbeat to report to server, or to get the local ip. + // For example, 0 means the eth0 maybe. virtual int get_stats_network(); - /** - * get the disk stat device name list. - * the device name configed in args of directive. - * @return the disk device name to stat. NULL if not configed. - */ + // Get the disk stat device name list. + // The device name configed in args of directive. + // @return the disk device name to stat. NULL if not configed. virtual SrsConfDirective* get_stats_disk_device(); }; diff --git a/trunk/src/app/srs_app_conn.hpp b/trunk/src/app/srs_app_conn.hpp index 7a723dfbf..bd5922688 100644 --- a/trunk/src/app/srs_app_conn.hpp +++ b/trunk/src/app/srs_app_conn.hpp @@ -36,48 +36,32 @@ class SrsWallClock; -/** - * the basic connection of SRS, - * all connections accept from listener must extends from this base class, - * server will add the connection to manager, and delete it when remove. - */ +// The basic connection of SRS, +// all connections accept from listener must extends from this base class, +// server will add the connection to manager, and delete it when remove. class SrsConnection : virtual public ISrsConnection, virtual public ISrsCoroutineHandler , virtual public ISrsKbpsDelta, virtual public ISrsReloadHandler { protected: - /** - * each connection start a green thread, - * when thread stop, the connection will be delete by server. - */ + // Each connection start a green thread, + // when thread stop, the connection will be delete by server. SrsCoroutine* trd; - /** - * the manager object to manage the connection. - */ + // The manager object to manage the connection. IConnectionManager* manager; - /** - * the underlayer st fd handler. - */ + // The underlayer st fd handler. srs_netfd_t stfd; - /** - * the ip of client. - */ + // The ip of client. std::string ip; - /** - * the underlayer socket. - */ + // The underlayer socket. SrsStSocket* skt; - /** - * connection total kbps. - * not only the rtmp or http connection, all type of connection are - * need to statistic the kbps of io. - * the SrsStatistic will use it indirectly to statistic the bytes delta of current connection. - */ + // The connection total kbps. + // not only the rtmp or http connection, all type of connection are + // need to statistic the kbps of io. + // The SrsStatistic will use it indirectly to statistic the bytes delta of current connection. SrsKbps* kbps; SrsWallClock* clk; - /** - * the create time in milliseconds. - * for current connection to log self create time and calculate the living time. - */ + // The create time in milliseconds. + // for current connection to log self create time and calculate the living time. int64_t create_time; public: SrsConnection(IConnectionManager* cm, srs_netfd_t c, std::string cip); @@ -86,19 +70,15 @@ public: public: virtual void remark(int64_t* in, int64_t* out); public: - /** - * to dipose the connection. - */ + // To dipose the connection. virtual void dispose(); - /** - * start the client green thread. - * when server get a client from listener, - * 1. server will create an concrete connection(for instance, RTMP connection), - * 2. then add connection to its connection manager, - * 3. start the client thread by invoke this start() - * when client cycle thread stop, invoke the on_thread_stop(), which will use server - * to remove the client by server->remove(this). - */ + // Start the client green thread. + // when server get a client from listener, + // 1. server will create an concrete connection(for instance, RTMP connection), + // 2. then add connection to its connection manager, + // 3. start the client thread by invoke this start() + // when client cycle thread stop, invoke the on_thread_stop(), which will use server + // To remove the client by server->remove(this). virtual srs_error_t start(); // Set socket option TCP_NODELAY. virtual srs_error_t set_tcp_nodelay(bool v); @@ -106,25 +86,17 @@ public: virtual srs_error_t set_socket_buffer(srs_utime_t buffer_v); // interface ISrsOneCycleThreadHandler public: - /** - * the thread cycle function, - * when serve connection completed, terminate the loop which will terminate the thread, - * thread will invoke the on_thread_stop() when it terminated. - */ + // The thread cycle function, + // when serve connection completed, terminate the loop which will terminate the thread, + // thread will invoke the on_thread_stop() when it terminated. virtual srs_error_t cycle(); public: - /** - * get the srs id which identify the client. - */ + // Get the srs id which identify the client. virtual int srs_id(); - /** - * set connection to expired. - */ + // Set connection to expired. virtual void expire(); protected: - /** - * for concrete connection to do the cycle. - */ + // For concrete connection to do the cycle. virtual srs_error_t do_cycle() = 0; }; diff --git a/trunk/src/app/srs_app_coworkers.hpp b/trunk/src/app/srs_app_coworkers.hpp index 60c460159..b7be73dca 100644 --- a/trunk/src/app/srs_app_coworkers.hpp +++ b/trunk/src/app/srs_app_coworkers.hpp @@ -33,6 +33,7 @@ class SrsJsonAny; class SrsRequest; class SrsSource; +// For origin cluster. class SrsCoWorkers { private: diff --git a/trunk/src/app/srs_app_heartbeat.hpp b/trunk/src/app/srs_app_heartbeat.hpp index e08275ca2..32d7b97dc 100644 --- a/trunk/src/app/srs_app_heartbeat.hpp +++ b/trunk/src/app/srs_app_heartbeat.hpp @@ -26,10 +26,7 @@ #include -/** - * the http heartbeat to api-server to notice api - * that the information of SRS. - */ +// The http heartbeat to api-server to notice api that the information of SRS. class SrsHttpHeartbeat { public: diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index d51ad7efb..cb95ac738 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -50,12 +50,10 @@ class SrsTsMessageCache; class SrsHlsSegment; class SrsTsContext; -/** - * the wrapper of m3u8 segment from specification: - * - * 3.3.2. EXTINF - * The EXTINF tag specifies the duration of a media segment. - */ +// The wrapper of m3u8 segment from specification: +// +// 3.3.2. EXTINF +// The EXTINF tag specifies the duration of a media segment. class SrsHlsSegment : public SrsFragment { public: @@ -63,7 +61,7 @@ public: int sequence_no; // ts uri in m3u8. std::string uri; - // the underlayer file writer. + // The underlayer file writer. SrsFileWriter* writer; // The TS context writer to write TS to file. SrsTsContextWriter* tscw; @@ -78,9 +76,7 @@ public: void config_cipher(unsigned char* key,unsigned char* iv); }; -/** - * the hls async call: on_hls - */ +// The hls async call: on_hls class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask { private: @@ -101,9 +97,7 @@ public: virtual std::string to_string(); }; -/** - * the hls async call: on_hls_notify - */ +// The hls async call: on_hls_notify class SrsDvrAsyncCallOnHlsNotify : public ISrsAsyncCallTask { private: @@ -118,14 +112,12 @@ public: virtual std::string to_string(); }; -/** - * muxer the HLS stream(m3u8 and ts files). - * generally, the m3u8 muxer only provides methods to open/close segments, - * to flush video/audio, without any mechenisms. - * - * that is, user must use HlsCache, which will control the methods of muxer, - * and provides HLS mechenisms. - */ +// Mux the HLS stream(m3u8 and ts files). +// Generally, the m3u8 muxer only provides methods to open/close segments, +// to flush video/audio, without any mechenisms. +// +// That is, user must use HlsCache, which will control the methods of muxer, +// and provides HLS mechenisms. class SrsHlsMuxer { private: @@ -143,26 +135,26 @@ private: srs_utime_t hls_window; SrsAsyncCallWorker* async; private: - // whether use floor algorithm for timestamp. + // Whether use floor algorithm for timestamp. bool hls_ts_floor; - // the deviation in piece to adjust the fragment to be more + // The deviation in piece to adjust the fragment to be more // bigger or smaller. int deviation_ts; - // the previous reap floor timestamp, + // The previous reap floor timestamp, // used to detect the dup or jmp or ts. int64_t accept_floor_ts; int64_t previous_floor_ts; private: - // encrypted or not + // Whether encrypted or not bool hls_keys; int hls_fragments_per_key; - // key file name + // The key file name std::string hls_key_file; - // key file path + // The key file path std::string hls_key_file_path; - // key file url + // The key file url std::string hls_key_url; - // key and iv. + // The key and iv. unsigned char key[16]; unsigned char iv[16]; SrsFileWriter *writer; @@ -176,10 +168,8 @@ private: SrsFragmentWindow* segments; // The current writing segment. SrsHlsSegment* current; - /** - * the ts context, to keep cc continous between ts. - * @see https://github.com/ossrs/srs/issues/375 - */ + // The ts context, to keep cc continous between ts. + // @see https://github.com/ossrs/srs/issues/375 SrsTsContext* context; public: SrsHlsMuxer(); @@ -192,48 +182,32 @@ public: virtual srs_utime_t duration(); virtual int deviation(); public: - /** - * initialize the hls muxer. - */ + // Initialize the hls muxer. virtual srs_error_t initialize(); - /** - * when publish, update the config for muxer. - */ + // When publish, update the config for muxer. virtual srs_error_t update_config(SrsRequest* r, std::string entry_prefix, std::string path, std::string m3u8_file, std::string ts_file, srs_utime_t fragment, srs_utime_t window, bool ts_floor, double aof_ratio, bool cleanup, bool wait_keyframe, bool keys, int fragments_per_key, std::string key_file, std::string key_file_path, std::string key_url); - /** - * open a new segment(a new ts file) - */ + // Open a new segment(a new ts file) virtual srs_error_t segment_open(); virtual srs_error_t on_sequence_header(); - /** - * whether segment overflow, - * that is whether the current segment duration>=(the segment in config) - */ + // Whether segment overflow, + // that is whether the current segment duration>=(the segment in config) virtual bool is_segment_overflow(); - /** - * whether wait keyframe to reap the ts. - */ + // Whether wait keyframe to reap the ts. virtual bool wait_keyframe(); - /** - * whether segment absolutely overflow, for pure audio to reap segment, - * that is whether the current segment duration>=2*(the segment in config) - * @see https://github.com/ossrs/srs/issues/151#issuecomment-71155184 - */ + // Whether segment absolutely overflow, for pure audio to reap segment, + // that is whether the current segment duration>=2*(the segment in config) + // @see https://github.com/ossrs/srs/issues/151#issuecomment-71155184 virtual bool is_segment_absolutely_overflow(); public: - /** - * whether current hls muxer is pure audio mode. - */ + // Whether current hls muxer is pure audio mode. virtual bool pure_audio(); virtual srs_error_t flush_audio(SrsTsMessageCache* cache); virtual srs_error_t flush_video(SrsTsMessageCache* cache); - /** - * Close segment(ts). - */ + // Close segment(ts). virtual srs_error_t segment_close(); private: virtual srs_error_t do_segment_close(); @@ -242,23 +216,21 @@ private: virtual srs_error_t _refresh_m3u8(std::string m3u8_file); }; -/** - * hls stream cache, - * use to cache hls stream and flush to hls muxer. - * - * when write stream to ts file: - * video frame will directly flush to M3u8Muxer, - * audio frame need to cache, because it's small and flv tbn problem. - * - * whatever, the Hls cache used to cache video/audio, - * and flush video/audio to m3u8 muxer if needed. - * - * about the flv tbn problem: - * flv tbn is 1/1000, ts tbn is 1/90000, - * when timestamp convert to flv tbn, it will loose precise, - * so we must gather audio frame together, and recalc the timestamp @see SrsTsAacJitter, - * we use a aac jitter to correct the audio pts. - */ +// The hls stream cache, +// use to cache hls stream and flush to hls muxer. +// +// When write stream to ts file: +// video frame will directly flush to M3u8Muxer, +// audio frame need to cache, because it's small and flv tbn problem. +// +// Whatever, the Hls cache used to cache video/audio, +// and flush video/audio to m3u8 muxer if needed. +// +// About the flv tbn problem: +// flv tbn is 1/1000, ts tbn is 1/90000, +// when timestamp convert to flv tbn, it will loose precise, +// so we must gather audio frame together, and recalc the timestamp @see SrsTsAacJitter, +// we use a aac jitter to correct the audio pts. class SrsHlsController { private: @@ -278,40 +250,28 @@ public: virtual srs_utime_t duration(); virtual int deviation(); public: - /** - * when publish or unpublish stream. - */ + // When publish or unpublish stream. virtual srs_error_t on_publish(SrsRequest* req); virtual srs_error_t on_unpublish(); - /** - * when get sequence header, - * must write a #EXT-X-DISCONTINUITY to m3u8. - * @see: hls-m3u8-draft-pantos-http-live-streaming-12.txt - * @see: 3.4.11. EXT-X-DISCONTINUITY - */ + // When get sequence header, + // must write a #EXT-X-DISCONTINUITY to m3u8. + // @see: hls-m3u8-draft-pantos-http-live-streaming-12.txt + // @see: 3.4.11. EXT-X-DISCONTINUITY virtual srs_error_t on_sequence_header(); - /** - * write audio to cache, if need to flush, flush to muxer. - */ + // write audio to cache, if need to flush, flush to muxer. virtual srs_error_t write_audio(SrsAudioFrame* frame, int64_t pts); - /** - * write video to muxer. - */ + // write video to muxer. virtual srs_error_t write_video(SrsVideoFrame* frame, int64_t dts); private: - /** - * reopen the muxer for a new hls segment, - * close current segment, open a new segment, - * then write the key frame to the new segment. - * so, user must reap_segment then flush_video to hls muxer. - */ + // Reopen the muxer for a new hls segment, + // close current segment, open a new segment, + // then write the key frame to the new segment. + // so, user must reap_segment then flush_video to hls muxer. virtual srs_error_t reap_segment(); }; -/** - * Transmux RTMP stream to HLS(m3u8 and ts). - * TODO: FIXME: add utest for hls. - */ +// Transmux RTMP stream to HLS(m3u8 and ts). +// TODO: FIXME: add utest for hls. class SrsHls { private: @@ -338,31 +298,21 @@ public: virtual void dispose(); virtual srs_error_t cycle(); public: - /** - * initialize the hls by handler and source. - */ + // Initialize the hls by handler and source. virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r); - /** - * publish stream event, continue to write the m3u8, - * for the muxer object not destroyed. - * @param fetch_sequence_header whether fetch sequence from source. - */ + // Publish stream event, continue to write the m3u8, + // for the muxer object not destroyed. + // @param fetch_sequence_header whether fetch sequence from source. virtual srs_error_t on_publish(); - /** - * the unpublish event, only close the muxer, donot destroy the - * muxer, for when we continue to publish, the m3u8 will continue. - */ + // The unpublish event, only close the muxer, donot destroy the + // muxer, for when we continue to publish, the m3u8 will continue. virtual void on_unpublish(); - /** - * mux the audio packets to ts. - * @param shared_audio, directly ptr, copy it if need to save it. - */ + // Mux the audio packets to ts. + // @param shared_audio, directly ptr, copy it if need to save it. virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format); - /** - * mux the video packets to ts. - * @param shared_video, directly ptr, copy it if need to save it. - * @param is_sps_pps whether the video is h.264 sps/pps. - */ + // Mux the video packets to ts. + // @param shared_video, directly ptr, copy it if need to save it. + // @param is_sps_pps whether the video is h.264 sps/pps. // TODO: FIXME: Remove param is_sps_pps. virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format); private: diff --git a/trunk/src/app/srs_app_ingest.hpp b/trunk/src/app/srs_app_ingest.hpp index 9e16f6906..79659439f 100644 --- a/trunk/src/app/srs_app_ingest.hpp +++ b/trunk/src/app/srs_app_ingest.hpp @@ -35,9 +35,7 @@ class SrsFFMPEG; class SrsConfDirective; class SrsPithyPrint; -/** - * ingester ffmpeg object. - */ +// Ingester ffmpeg object. class SrsIngesterFFMPEG { private: @@ -50,9 +48,9 @@ public: virtual ~SrsIngesterFFMPEG(); public: virtual srs_error_t initialize(SrsFFMPEG* ff, std::string v, std::string i); - // the ingest uri, [vhost]/[ingest id] + // The ingest uri, [vhost]/[ingest id] virtual std::string uri(); - // the alive in srs_utime_t. + // The alive in srs_utime_t. virtual srs_utime_t alive(); virtual bool equals(std::string v, std::string i); virtual bool equals(std::string v); @@ -64,11 +62,9 @@ public: virtual void fast_stop(); }; -/** - * ingest file/stream/device, - * encode with FFMPEG(optional), - * push to SRS(or any RTMP server) over RTMP. - */ +// Ingest file/stream/device, +// encode with FFMPEG(optional), +// push to SRS(or any RTMP server) over RTMP. class SrsIngester : public ISrsCoroutineHandler, public ISrsReloadHandler { private: @@ -76,8 +72,7 @@ private: private: SrsCoroutine* trd; SrsPithyPrint* pprint; - // whether the ingesters are expired, - // for example, the listen port changed, + // Whether the ingesters are expired, for example, the listen port changed, // all ingesters must be restart. bool expired; public: diff --git a/trunk/src/app/srs_app_kafka.hpp b/trunk/src/app/srs_app_kafka.hpp index 37101cb8f..38e0ca20e 100644 --- a/trunk/src/app/srs_app_kafka.hpp +++ b/trunk/src/app/srs_app_kafka.hpp @@ -42,14 +42,10 @@ class SrsKafkaProducer; #ifdef SRS_AUTO_KAFKA -/** - * the partition messages cache. - */ +// The partition messages cache. typedef std::vector SrsKafkaPartitionCache; -/** - * the kafka partition info. - */ +// The kafka partition info. struct SrsKafkaPartition { private: @@ -75,9 +71,7 @@ private: virtual void disconnect(); }; -/** - * the following is all types of kafka messages. - */ +// The following is all types of kafka messages. class SrsKafkaMessage : public ISrsAsyncCallTask { private: @@ -93,19 +87,17 @@ public: virtual std::string to_string(); }; -/** - * a message cache for kafka. - */ +// A message cache for kafka. class SrsKafkaCache { public: - // the total partitions, + // The total partitions, // for the key to map to the parition by key%nb_partitions. int nb_partitions; private: - // total messages for all partitions. + // Total messages for all partitions. int count; - // key is the partition id, value is the message set to write to this partition. + // The key is the partition id, value is the message set to write to this partition. // @remark, when refresh metadata, the partition will increase, // so maybe some message will dispatch to new partition. std::map< int32_t, SrsKafkaPartitionCache*> cache; @@ -115,37 +107,27 @@ public: public: virtual void append(int key, SrsJsonObject* obj); virtual int size(); - /** - * fetch out a available partition cache. - * @return true when got a key and pc; otherwise, false. - */ + // Fetch out a available partition cache. + // @return true when got a key and pc; otherwise, false. virtual bool fetch(int* pkey, SrsKafkaPartitionCache** ppc); - /** - * flush the specified partition cache. - */ + // Flush the specified partition cache. virtual srs_error_t flush(SrsKafkaPartition* partition, int key, SrsKafkaPartitionCache* pc); }; -/** - * the kafka cluster interface. - */ +// The kafka cluster interface. class ISrsKafkaCluster { public: ISrsKafkaCluster(); virtual ~ISrsKafkaCluster(); public: - /** - * when got any client connect to SRS, notify kafka. - * @param key the partition map key, the client id or hash(ip). - * @param type the type of client. - * @param ip the peer ip of client. - */ + // When got any client connect to SRS, notify kafka. + // @param key the partition map key, the client id or hash(ip). + // @param type the type of client. + // @param ip the peer ip of client. virtual srs_error_t on_client(int key, SrsListenerType type, std::string ip) = 0; - /** - * when client close or disconnect for error. - * @param key the partition map key, the client id or hash(ip). - */ + // When client close or disconnect for error. + // @param key the partition map key, the client id or hash(ip). virtual srs_error_t on_close(int key) = 0; }; @@ -155,9 +137,7 @@ extern ISrsKafkaCluster* _srs_kafka; extern srs_error_t srs_initialize_kafka(); extern void srs_dispose_kafka(); -/** - * the kafka producer used to save log to kafka cluster. - */ +// The kafka producer used to save log to kafka cluster. class SrsKafkaProducer : virtual public ISrsCoroutineHandler, virtual public ISrsKafkaCluster { private: @@ -183,12 +163,10 @@ public: virtual void stop(); // internal: for worker to call task to send object. public: - /** - * send json object to kafka cluster. - * the producer will aggregate message and send in kafka message set. - * @param key the key to map to the partition, user can use cid or hash. - * @param obj the json object; user must never free it again. - */ + // Send json object to kafka cluster. + // The producer will aggregate message and send in kafka message set. + // @param key the key to map to the partition, user can use cid or hash. + // @param obj the json object; user must never free it again. virtual srs_error_t send(int key, SrsJsonObject* obj); // interface ISrsKafkaCluster public: @@ -201,7 +179,7 @@ private: virtual void clear_metadata(); virtual srs_error_t do_cycle(); virtual srs_error_t request_metadata(); - // set the metadata to invalid and refresh it. + // Set the metadata to invalid and refresh it. virtual void refresh_metadata(); virtual srs_error_t flush(); }; diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 9f0b437d1..437e99db4 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -55,7 +55,7 @@ class SrsKafkaProducer; #endif class SrsCoroutineManager; -// listener type for server to identify the connection, +// The listener type for server to identify the connection, // that is, use different type to process the connection. enum SrsListenerType { @@ -73,9 +73,7 @@ enum SrsListenerType SrsListenerFlv = 5, }; -/** - * the common tcp listener, for RTMP/HTTP server. - */ +// A common tcp listener, for RTMP/HTTP server. class SrsListener { protected: @@ -92,9 +90,7 @@ public: virtual srs_error_t listen(std::string i, int p) = 0; }; -/** - * tcp listener. - */ +// A buffered TCP listener. class SrsBufferListener : virtual public SrsListener, virtual public ISrsTcpHandler { private: @@ -104,14 +100,12 @@ public: virtual ~SrsBufferListener(); public: virtual srs_error_t listen(std::string ip, int port); -// ISrsTcpHandler +// interface ISrsTcpHandler public: virtual srs_error_t on_tcp_client(srs_netfd_t stfd); }; -/** - * the tcp listener, for rtsp server. - */ +// A TCP listener, for rtsp server. class SrsRtspListener : virtual public SrsListener, virtual public ISrsTcpHandler { private: @@ -122,14 +116,12 @@ public: virtual ~SrsRtspListener(); public: virtual srs_error_t listen(std::string i, int p); -// ISrsTcpHandler +// interface ISrsTcpHandler public: virtual srs_error_t on_tcp_client(srs_netfd_t stfd); }; -/** - * the tcp listener, for flv stream server. - */ +// A TCP listener, for flv stream server. class SrsHttpFlvListener : virtual public SrsListener, virtual public ISrsTcpHandler { private: @@ -140,14 +132,12 @@ public: virtual ~SrsHttpFlvListener(); public: virtual srs_error_t listen(std::string i, int p); -// ISrsTcpHandler +// interface ISrsTcpHandler public: virtual srs_error_t on_tcp_client(srs_netfd_t stfd); }; -/** - * the udp listener, for udp server. - */ +// A UDP listener, for udp server. class SrsUdpStreamListener : public SrsListener { protected: @@ -160,9 +150,7 @@ public: virtual srs_error_t listen(std::string i, int p); }; -/** - * the udp listener, for udp stream caster server. - */ +// A UDP listener, for udp stream caster server. class SrsUdpCasterListener : public SrsUdpStreamListener { public: @@ -170,15 +158,13 @@ public: virtual ~SrsUdpCasterListener(); }; -/** - * convert signal to io, - * @see: st-1.9/docs/notes.html - */ +// Convert signal to io, +// @see: st-1.9/docs/notes.html class SrsSignalManager : public ISrsCoroutineHandler { private: - /* Per-process pipe which is used as a signal queue. */ - /* Up to PIPE_BUF/sizeof(int) signals can be queued up. */ + // Per-process pipe which is used as a signal queue. + // Up to PIPE_BUF/sizeof(int) signals can be queued up. int sig_pipe[2]; srs_netfd_t signal_read_stfd; private: @@ -194,43 +180,30 @@ public: public: virtual srs_error_t cycle(); private: - // global singleton instance + // Global singleton instance static SrsSignalManager* instance; - /* Signal catching function. */ - /* Converts signal event to I/O event. */ + // Signal catching function. + // Converts signal event to I/O event. static void sig_catcher(int signo); }; -/** - * the handler to the handle cycle in SRS RTMP server. - */ +// A handler to the handle cycle in SRS RTMP server. class ISrsServerCycle { public: ISrsServerCycle(); virtual ~ISrsServerCycle(); public: - /** - * initialize the cycle handler. - */ + // Initialize the cycle handler. virtual srs_error_t initialize() = 0; - /** - * do on_cycle while server doing cycle. - */ + // Do on_cycle while server doing cycle. virtual srs_error_t on_cycle() = 0; - /** - * callback the handler when got client. - */ + // Callback the handler when got client. virtual srs_error_t on_accept_client(int max, int cur) = 0; }; -/** - * SRS RTMP server, initialize and listen, - * start connection service thread, destroy client. - */ -class SrsServer : virtual public ISrsReloadHandler - , virtual public ISrsSourceHandler - , virtual public IConnectionManager +// SRS RTMP server, initialize and listen, start connection service thread, destroy client. +class SrsServer : virtual public ISrsReloadHandler, virtual public ISrsSourceHandler, virtual public IConnectionManager { private: // TODO: FIXME: rename to http_api @@ -240,59 +213,41 @@ private: SrsIngester* ingester; SrsCoroutineManager* conn_manager; private: - /** - * the pid file fd, lock the file write when server is running. - * @remark the init.d script should cleanup the pid file, when stop service, - * for the server never delete the file; when system startup, the pid in pid file - * maybe valid but the process is not SRS, the init.d script will never start server. - */ + // The pid file fd, lock the file write when server is running. + // @remark the init.d script should cleanup the pid file, when stop service, + // for the server never delete the file; when system startup, the pid in pid file + // maybe valid but the process is not SRS, the init.d script will never start server. int pid_fd; - /** - * all connections, connection manager - */ + // All connections, connection manager std::vector conns; - /** - * all listners, listener manager. - */ + // All listners, listener manager. std::vector listeners; - /** - * signal manager which convert gignal to io message. - */ + // Signal manager which convert gignal to io message. SrsSignalManager* signal_manager; - /** - * handle in server cycle. - */ + // Handle in server cycle. ISrsServerCycle* handler; - /** - * user send the signal, convert to variable. - */ + // User send the signal, convert to variable. bool signal_reload; bool signal_persistence_config; bool signal_gmc_stop; bool signal_gracefully_quit; - // parent pid for asprocess. + // Parent pid for asprocess. int ppid; public: SrsServer(); virtual ~SrsServer(); private: - /** - * the destroy is for gmc to analysis the memory leak, - * if not destroy global/static data, the gmc will warning memory leak. - * in service, server never destroy, directly exit when restart. - */ + // The destroy is for gmc to analysis the memory leak, + // if not destroy global/static data, the gmc will warning memory leak. + // In service, server never destroy, directly exit when restart. virtual void destroy(); - /** - * when SIGTERM, SRS should do cleanup, for example, - * to stop all ingesters, cleanup HLS and dvr. - */ + // When SIGTERM, SRS should do cleanup, for example, + // to stop all ingesters, cleanup HLS and dvr. virtual void dispose(); // server startup workflow, @see run_master() public: - /** - * initialize server with callback handler ch. - * @remark user must free the handler. - */ + // Initialize server with callback handler ch. + // @remark user must free the handler. virtual srs_error_t initialize(ISrsServerCycle* ch); virtual srs_error_t initialize_st(); virtual srs_error_t initialize_signal(); @@ -304,62 +259,48 @@ public: virtual srs_error_t cycle(); // server utilities. public: - /** - * callback for signal manager got a signal. - * the signal manager convert signal to io message, - * whatever, we will got the signo like the orignal signal(int signo) handler. - * @param signo the signal number from user, where: - * SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit. - * SRS_SIGNAL_REOPEN_LOG, the SIGUSR1, reopen the log file. - * SRS_SIGNAL_RELOAD, the SIGHUP, reload the config. - * SRS_SIGNAL_PERSISTENCE_CONFIG, application level signal, persistence config to file. - * @remark, for SIGINT: - * no gmc, directly exit. - * for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc. - * @remark, maybe the HTTP RAW API will trigger the on_signal() also. - */ + // The callback for signal manager got a signal. + // The signal manager convert signal to io message, + // whatever, we will got the signo like the orignal signal(int signo) handler. + // @param signo the signal number from user, where: + // SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit. + // SRS_SIGNAL_REOPEN_LOG, the SIGUSR1, reopen the log file. + // SRS_SIGNAL_RELOAD, the SIGHUP, reload the config. + // SRS_SIGNAL_PERSISTENCE_CONFIG, application level signal, persistence config to file. + // @remark, for SIGINT: + // no gmc, directly exit. + // for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc. + // @remark, maybe the HTTP RAW API will trigger the on_signal() also. virtual void on_signal(int signo); private: - /** - * the server thread main cycle, - * update the global static data, for instance, the current time, - * the cpu/mem/network statistic. - */ + // The server thread main cycle, + // update the global static data, for instance, the current time, + // the cpu/mem/network statistic. virtual srs_error_t do_cycle(); - /** - * listen at specified protocol. - */ + // listen at specified protocol. virtual srs_error_t listen_rtmp(); virtual srs_error_t listen_http_api(); virtual srs_error_t listen_http_stream(); virtual srs_error_t listen_stream_caster(); - /** - * close the listeners for specified type, - * remove the listen object from manager. - */ + // Close the listeners for specified type, + // Remove the listen object from manager. virtual void close_listeners(SrsListenerType type); - /** - * resample the server kbs. - */ + // Resample the server kbs. virtual void resample_kbps(); - // internal only +// For internal only public: - /** - * when listener got a fd, notice server to accept it. - * @param type, the client type, used to create concrete connection, - * for instance RTMP connection to serve client. - * @param stfd, the client fd in st boxed, the underlayer fd. - */ + // When listener got a fd, notice server to accept it. + // @param type, the client type, used to create concrete connection, + // for instance RTMP connection to serve client. + // @param stfd, the client fd in st boxed, the underlayer fd. virtual srs_error_t accept_client(SrsListenerType type, srs_netfd_t stfd); private: virtual srs_error_t fd2conn(SrsListenerType type, srs_netfd_t stfd, SrsConnection** pconn); - // IConnectionManager +// interface IConnectionManager public: - /** - * callback for connection to remove itself. - * when connection thread cycle terminated, callback this to delete connection. - * @see SrsConnection.on_thread_stop(). - */ + // A callback for connection to remove itself. + // When connection thread cycle terminated, callback this to delete connection. + // @see SrsConnection.on_thread_stop(). virtual void remove(ISrsConnection* c); // interface ISrsReloadHandler. public: diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index a4c50d96d..bed9850bf 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -61,12 +61,10 @@ class SrsBuffer; class SrsHds; #endif -/** - * the time jitter algorithm: - * 1. full, to ensure stream start at zero, and ensure stream monotonically increasing. - * 2. zero, only ensure sttream start at zero, ignore timestamp jitter. - * 3. off, disable the time jitter algorithm, like atc. - */ +// The time jitter algorithm: +// 1. full, to ensure stream start at zero, and ensure stream monotonically increasing. +// 2. zero, only ensure sttream start at zero, ignore timestamp jitter. +// 3. off, disable the time jitter algorithm, like atc. enum SrsRtmpJitterAlgorithm { SrsRtmpJitterAlgorithmFULL = 0x01, @@ -75,10 +73,7 @@ enum SrsRtmpJitterAlgorithm }; int _srs_time_jitter_string2int(std::string time_jitter); -/** - * time jitter detect and correct, - * to ensure the rtmp stream is monotonically. - */ +// Time jitter detect and correct, to ensure the rtmp stream is monotonically. class SrsRtmpJitter { private: @@ -88,23 +83,16 @@ public: SrsRtmpJitter(); virtual ~SrsRtmpJitter(); public: - /** - * detect the time jitter and correct it. - * @param ag the algorithm to use for time jitter. - */ + // detect the time jitter and correct it. + // @param ag the algorithm to use for time jitter. virtual srs_error_t correct(SrsSharedPtrMessage* msg, SrsRtmpJitterAlgorithm ag); - /** - * get current client time, the last packet time. - */ + // Get current client time, the last packet time. virtual int64_t get_time(); }; #ifdef SRS_PERF_QUEUE_FAST_VECTOR -/** - * to alloc and increase fixed space, - * fast remove and insert for msgs sender. - * @see https://github.com/ossrs/srs/issues/251 - */ +// To alloc and increase fixed space, fast remove and insert for msgs sender. +// @see https://github.com/ossrs/srs/issues/251 class SrsFastVector { private: @@ -127,10 +115,8 @@ public: }; #endif -/** - * the message queue for the consumer(client), forwarder. - * we limit the size in seconds, drop old messages(the whole gop) if full. - */ +// The message queue for the consumer(client), forwarder. +// We limit the size in seconds, drop old messages(the whole gop) if full. class SrsMessageQueue { private: @@ -151,85 +137,63 @@ public: SrsMessageQueue(bool ignore_shrink = false); virtual ~SrsMessageQueue(); public: - /** - * get the size of queue. - */ + // Get the size of queue. virtual int size(); - /** - * get the duration of queue. - */ + // Get the duration of queue. virtual srs_utime_t duration(); - /** - * set the queue size - * @param queue_size the queue size in srs_utime_t. - */ + // Set the queue size + // @param queue_size the queue size in srs_utime_t. virtual void set_queue_size(srs_utime_t queue_size); public: - /** - * enqueue the message, the timestamp always monotonically. - * @param msg, the msg to enqueue, user never free it whatever the return code. - * @param is_overflow, whether overflow and shrinked. NULL to ignore. - */ + // Enqueue the message, the timestamp always monotonically. + // @param msg, the msg to enqueue, user never free it whatever the return code. + // @param is_overflow, whether overflow and shrinked. NULL to ignore. virtual srs_error_t enqueue(SrsSharedPtrMessage* msg, bool* is_overflow = NULL); - /** - * get packets in consumer queue. - * @pmsgs SrsSharedPtrMessage*[], used to store the msgs, user must alloc it. - * @count the count in array, output param. - * @max_count the max count to dequeue, must be positive. - */ + // Get packets in consumer queue. + // @pmsgs SrsSharedPtrMessage*[], used to store the msgs, user must alloc it. + // @count the count in array, output param. + // @max_count the max count to dequeue, must be positive. virtual srs_error_t dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, int& count); - /** - * dumps packets to consumer, use specified args. - * @remark the atc/tba/tbv/ag are same to SrsConsumer.enqueue(). - */ + // Dumps packets to consumer, use specified args. + // @remark the atc/tba/tbv/ag are same to SrsConsumer.enqueue(). virtual srs_error_t dump_packets(SrsConsumer* consumer, bool atc, SrsRtmpJitterAlgorithm ag); private: - /** - * remove a gop from the front. - * if no iframe found, clear it. - */ + // Remove a gop from the front. + // if no iframe found, clear it. virtual void shrink(); public: - /** - * clear all messages in queue. - */ + // clear all messages in queue. virtual void clear(); }; -/** - * the wakable used for some object - * which is waiting on cond. - */ +// The wakable used for some object +// which is waiting on cond. class ISrsWakable { public: ISrsWakable(); virtual ~ISrsWakable(); public: - /** - * when the consumer(for player) got msg from recv thread, - * it must be processed for maybe it's a close msg, so the cond - * wait must be wakeup. - */ + // when the consumer(for player) got msg from recv thread, + // it must be processed for maybe it's a close msg, so the cond + // wait must be wakeup. virtual void wakeup() = 0; }; -/** - * the consumer for SrsSource, that is a play client. - */ +// The consumer for SrsSource, that is a play client. class SrsConsumer : public ISrsWakable { private: SrsRtmpJitter* jitter; SrsSource* source; SrsMessageQueue* queue; - // the owner connection for debug, maybe NULL. + // The owner connection for debug, maybe NULL. SrsConnection* conn; bool paused; // when source id changed, notice all consumers bool should_update_source_id; #ifdef SRS_PERF_QUEUE_COND_WAIT - // the cond wait for mw. + // The cond wait for mw. // @see https://github.com/ossrs/srs/issues/251 srs_cond_t mw_wait; bool mw_waiting; @@ -240,159 +204,109 @@ public: SrsConsumer(SrsSource* s, SrsConnection* c); virtual ~SrsConsumer(); public: - /** - * set the size of queue. - */ + // Set the size of queue. virtual void set_queue_size(srs_utime_t queue_size); - /** - * when source id changed, notice client to print. - */ + // when source id changed, notice client to print. virtual void update_source_id(); public: - /** - * get current client time, the last packet time. - */ + // Get current client time, the last packet time. virtual int64_t get_time(); - /** - * enqueue an shared ptr message. - * @param shared_msg, directly ptr, copy it if need to save it. - * @param whether atc, donot use jitter correct if true. - * @param ag the algorithm of time jitter. - */ + // Enqueue an shared ptr message. + // @param shared_msg, directly ptr, copy it if need to save it. + // @param whether atc, donot use jitter correct if true. + // @param ag the algorithm of time jitter. virtual srs_error_t enqueue(SrsSharedPtrMessage* shared_msg, bool atc, SrsRtmpJitterAlgorithm ag); - /** - * get packets in consumer queue. - * @param msgs the msgs array to dump packets to send. - * @param count the count in array, intput and output param. - * @remark user can specifies the count to get specified msgs; 0 to get all if possible. - */ + // Get packets in consumer queue. + // @param msgs the msgs array to dump packets to send. + // @param count the count in array, intput and output param. + // @remark user can specifies the count to get specified msgs; 0 to get all if possible. virtual srs_error_t dump_packets(SrsMessageArray* msgs, int& count); #ifdef SRS_PERF_QUEUE_COND_WAIT - /** - * wait for messages incomming, atleast nb_msgs and in duration. - * @param nb_msgs the messages count to wait. - * @param msgs_duration the messages duration to wait. - */ + // wait for messages incomming, atleast nb_msgs and in duration. + // @param nb_msgs the messages count to wait. + // @param msgs_duration the messages duration to wait. virtual void wait(int nb_msgs, srs_utime_t msgs_duration); #endif - /** - * when client send the pause message. - */ + // when client send the pause message. virtual srs_error_t on_play_client_pause(bool is_pause); // ISrsWakable public: - /** - * when the consumer(for player) got msg from recv thread, - * it must be processed for maybe it's a close msg, so the cond - * wait must be wakeup. - */ + // when the consumer(for player) got msg from recv thread, + // it must be processed for maybe it's a close msg, so the cond + // wait must be wakeup. virtual void wakeup(); }; -/** - * cache a gop of video/audio data, - * delivery at the connect of flash player, - * to enable it to fast startup. - */ +// cache a gop of video/audio data, +// delivery at the connect of flash player, +// To enable it to fast startup. class SrsGopCache { private: - /** - * if disabled the gop cache, - * the client will wait for the next keyframe for h264, - * and will be black-screen. - */ + // if disabled the gop cache, + // The client will wait for the next keyframe for h264, + // and will be black-screen. bool enable_gop_cache; - /** - * the video frame count, avoid cache for pure audio stream. - */ + // The video frame count, avoid cache for pure audio stream. int cached_video_count; - /** - * when user disabled video when publishing, and gop cache enalbed, - * we will cache the audio/video for we already got video, but we never - * know when to clear the gop cache, for there is no video in future, - * so we must guess whether user disabled the video. - * when we got some audios after laster video, for instance, 600 audio packets, - * about 3s(26ms per packet) 115 audio packets, clear gop cache. - * - * @remark, it is ok for performance, for when we clear the gop cache, - * gop cache is disabled for pure audio stream. - * @see: https://github.com/ossrs/srs/issues/124 - */ + // when user disabled video when publishing, and gop cache enalbed, + // We will cache the audio/video for we already got video, but we never + // know when to clear the gop cache, for there is no video in future, + // so we must guess whether user disabled the video. + // when we got some audios after laster video, for instance, 600 audio packets, + // about 3s(26ms per packet) 115 audio packets, clear gop cache. + // + // @remark, it is ok for performance, for when we clear the gop cache, + // gop cache is disabled for pure audio stream. + // @see: https://github.com/ossrs/srs/issues/124 int audio_after_last_video_count; - /** - * cached gop. - */ + // cached gop. std::vector gop_cache; public: SrsGopCache(); virtual ~SrsGopCache(); public: - /** - * cleanup when system quit. - */ + // cleanup when system quit. virtual void dispose(); - /** - * to enable or disable the gop cache. - */ + // To enable or disable the gop cache. virtual void set(bool v); virtual bool enabled(); - /** - * only for h264 codec - * 1. cache the gop when got h264 video packet. - * 2. clear gop when got keyframe. - * @param shared_msg, directly ptr, copy it if need to save it. - */ + // only for h264 codec + // 1. cache the gop when got h264 video packet. + // 2. clear gop when got keyframe. + // @param shared_msg, directly ptr, copy it if need to save it. virtual srs_error_t cache(SrsSharedPtrMessage* shared_msg); - /** - * clear the gop cache. - */ + // clear the gop cache. virtual void clear(); - /** - * dump the cached gop to consumer. - */ + // dump the cached gop to consumer. virtual srs_error_t dump(SrsConsumer* consumer, bool atc, SrsRtmpJitterAlgorithm jitter_algorithm); - /** - * used for atc to get the time of gop cache, - * the atc will adjust the sequence header timestamp to gop cache. - */ + // used for atc to get the time of gop cache, + // The atc will adjust the sequence header timestamp to gop cache. virtual bool empty(); - /** - * get the start time of gop cache, in srs_utime_t. - * @return 0 if no packets. - */ + // Get the start time of gop cache, in srs_utime_t. + // @return 0 if no packets. virtual srs_utime_t start_time(); - /** - * whether current stream is pure audio, - * when no video in gop cache, the stream is pure audio right now. - */ + // whether current stream is pure audio, + // when no video in gop cache, the stream is pure audio right now. virtual bool pure_audio(); }; -/** - * the handler to handle the event of srs source. - * for example, the http flv streaming module handle the event and - * mount http when rtmp start publishing. - */ +// The handler to handle the event of srs source. +// For example, the http flv streaming module handle the event and +// mount http when rtmp start publishing. class ISrsSourceHandler { public: ISrsSourceHandler(); virtual ~ISrsSourceHandler(); public: - /** - * when stream start publish, mount stream. - */ + // when stream start publish, mount stream. virtual srs_error_t on_publish(SrsSource* s, SrsRequest* r) = 0; - /** - * when stream stop publish, unmount stream. - */ + // when stream stop publish, unmount stream. virtual void on_unpublish(SrsSource* s, SrsRequest* r) = 0; }; -/** - * the mix queue to correct the timestamp for mix_correct algorithm. - */ +// The mix queue to correct the timestamp for mix_correct algorithm. class SrsMixQueue { private: @@ -408,11 +322,9 @@ public: virtual SrsSharedPtrMessage* pop(); }; -/** - * The hub for origin is a collection of utilities for origin only, - * for example, DVR, HLS, Forward and Transcode are only available for origin, - * they are meanless for edge server. - */ +// The hub for origin is a collection of utilities for origin only, +// For example, DVR, HLS, Forward and Transcode are only available for origin, +// they are meanless for edge server. class SrsOriginHub : public ISrsReloadHandler { private: @@ -437,7 +349,7 @@ private: #endif // nginx-rtmp exec feature. SrsNgExec* ng_exec; - // to forward stream to other servers + // To forward stream to other servers std::vector forwarders; public: SrsOriginHub(); @@ -447,10 +359,10 @@ public: // @param r The request object, managed by source. virtual srs_error_t initialize(SrsSource* s, SrsRequest* r); // Dispose the hub, release utilities resource, - // for example, delete all HLS pieces. + // For example, delete all HLS pieces. virtual void dispose(); // Cycle the hub, process some regular events, - // for example, dispose hls in cycle. + // For example, dispose hls in cycle. virtual srs_error_t cycle(); public: // When got a parsed metadata. @@ -466,9 +378,9 @@ public: virtual void on_unpublish(); // Internal callback. public: - // for the SrsForwarder to callback to request the sequence headers. + // For the SrsForwarder to callback to request the sequence headers. virtual srs_error_t on_forwarder_start(SrsForwarder* forwarder); - // for the SrsDvr to callback to request the sequence headers. + // For the SrsDvr to callback to request the sequence headers. virtual srs_error_t on_dvr_request_sh(); // interface ISrsReloadHandler public: @@ -484,10 +396,8 @@ private: virtual void destroy_forwarders(); }; -/** - * Each stream have optional meta(sps/pps in sequence header and metadata). - * This class cache and update the meta. - */ +// Each stream have optional meta(sps/pps in sequence header and metadata). +// This class cache and update the meta. class SrsMetaCache { private: @@ -528,46 +438,35 @@ public: virtual srs_error_t update_vsh(SrsSharedPtrMessage* msg); }; -/** - * live streaming source. - */ +// live streaming source. class SrsSource : public ISrsReloadHandler { friend class SrsOriginHub; private: static std::map pool; public: - /** - * create source when fetch from cache failed. - * @param r the client request. - * @param h the event handler for source. - * @param pps the matched source, if success never be NULL. - */ + // create source when fetch from cache failed. + // @param r the client request. + // @param h the event handler for source. + // @param pps the matched source, if success never be NULL. static srs_error_t fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, SrsSource** pps); private: - /** - * get the exists source, NULL when not exists. - * update the request and return the exists source. - */ + // Get the exists source, NULL when not exists. + // update the request and return the exists source. static SrsSource* fetch(SrsRequest* r); public: - /** - * dispose and cycle all sources. - */ + // dispose and cycle all sources. static void dispose_all(); static srs_error_t cycle_all(); private: static srs_error_t do_cycle_all(); public: - /** - * when system exit, destroy the sources, - * for gmc to analysis mem leaks. - */ + // when system exit, destroy the sources, + // For gmc to analysis mem leaks. static void destroy(); private: - // source id, - // for publish, it's the publish client id. - // for edge, it's the edge ingest id. + // For publish, it's the publish client id. + // For edge, it's the edge ingest id. // when source id changed, for example, the edge reconnect, // invoke the on_source_id_changed() to let all clients know. int _source_id; @@ -575,31 +474,29 @@ private: int _pre_source_id; // deep copy of client request. SrsRequest* req; - // to delivery stream to clients. + // To delivery stream to clients. std::vector consumers; - // the time jitter algorithm for vhost. + // The time jitter algorithm for vhost. SrsRtmpJitterAlgorithm jitter_algorithm; - // for play, whether use interlaced/mixed algorithm to correct timestamp. + // For play, whether use interlaced/mixed algorithm to correct timestamp. bool mix_correct; - // the mix queue to implements the mix correct algorithm. + // The mix queue to implements the mix correct algorithm. SrsMixQueue* mix_queue; - /** - * for play, whether enabled atc. - * atc whether atc(use absolute time and donot adjust time), - * directly use msg time and donot adjust if atc is true, - * otherwise, adjust msg time to start from 0 to make flash happy. - */ + // For play, whether enabled atc. + // The atc(use absolute time and donot adjust time), + // directly use msg time and donot adjust if atc is true, + // otherwise, adjust msg time to start from 0 to make flash happy. bool atc; // whether stream is monotonically increase. bool is_monotonically_increase; - // the time of the packet we just got. + // The time of the packet we just got. int64_t last_packet_time; - // the event handler. + // The event handler. ISrsSourceHandler* handler; - // edge control service + // The edge control service SrsPlayEdge* play_edge; SrsPublishEdge* publish_edge; - // gop cache for client fast startup. + // The gop cache for client fast startup. SrsGopCache* gop_cache; // The hub for origin server. SrsOriginHub* hub; @@ -609,7 +506,7 @@ private: // Whether source is avaiable for publishing. bool _can_publish; // The last die time, when all consumers quit and no publisher, - // we will remove the source when source die. + // We will remove the source when source die. srs_utime_t die_at; public: SrsSource(); @@ -617,26 +514,23 @@ public: public: virtual void dispose(); virtual srs_error_t cycle(); - // remove source when expired. + // Remove source when expired. virtual bool expired(); -// initialize, get and setter. public: - // initialize the hls with handlers. + // Initialize the hls with handlers. virtual srs_error_t initialize(SrsRequest* r, ISrsSourceHandler* h); // interface ISrsReloadHandler public: virtual srs_error_t on_reload_vhost_play(std::string vhost); -// for the tools callback public: - // source id changed. + // The source id changed. virtual srs_error_t on_source_id_changed(int id); - // get current source id. + // Get current source id. virtual int source_id(); virtual int pre_source_id(); // Whether source is inactive, which means there is no publishing stream source. // @remark For edge, it's inactive util stream has been pulled from origin. virtual bool inactive(); -// logic data methods public: virtual bool can_publish(bool is_edge); virtual srs_error_t on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); @@ -650,33 +544,27 @@ private: virtual srs_error_t on_video_imp(SrsSharedPtrMessage* video); public: virtual srs_error_t on_aggregate(SrsCommonMessage* msg); - /** - * publish stream event notify. - * @param _req the request from client, the source will deep copy it, - * for when reload the request of client maybe invalid. - */ + // Publish stream event notify. + // @param _req the request from client, the source will deep copy it, + // for when reload the request of client maybe invalid. virtual srs_error_t on_publish(); virtual void on_unpublish(); -// consumer methods public: - /** - * create consumer and dumps packets in cache. - * @param consumer, output the create consumer. - * @param ds, whether dumps the sequence header. - * @param dm, whether dumps the metadata. - * @param dg, whether dumps the gop cache. - */ + // Create consumer and dumps packets in cache. + // @param consumer, output the create consumer. + // @param ds, whether dumps the sequence header. + // @param dm, whether dumps the metadata. + // @param dg, whether dumps the gop cache. virtual srs_error_t create_consumer(SrsConnection* conn, SrsConsumer*& consumer, bool ds = true, bool dm = true, bool dg = true); virtual void on_consumer_destroy(SrsConsumer* consumer); virtual void set_cache(bool enabled); virtual SrsRtmpJitterAlgorithm jitter(); -// internal public: - // for edge, when publish edge stream, check the state + // For edge, when publish edge stream, check the state virtual srs_error_t on_edge_start_publish(); - // for edge, proxy the publish + // For edge, proxy the publish virtual srs_error_t on_edge_proxy_publish(SrsCommonMessage* msg); - // for edge, proxy stop publish + // For edge, proxy stop publish virtual void on_edge_proxy_unpublish(); public: virtual std::string get_curr_origin(); diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index c9d5661c0..c9e475ace 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -48,9 +48,7 @@ public: int nb_streams; int nb_clients; public: - /** - * vhost total kbps. - */ + // The vhost total kbps. SrsKbps* kbps; SrsWallClock* clk; public: @@ -73,19 +71,17 @@ public: int nb_clients; uint64_t nb_frames; public: - /** - * stream total kbps. - */ + // The stream total kbps. SrsKbps* kbps; SrsWallClock* clk; public: bool has_video; SrsVideoCodecId vcodec; - // profile_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45. + // The profile_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45. SrsAvcProfile avc_profile; - // level_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45. + // The level_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45. SrsAvcLevel avc_level; - // the width and height in codec info. + // The width and height in codec info. int width; int height; public: @@ -93,12 +89,10 @@ public: SrsAudioCodecId acodec; SrsAudioSampleRate asample_rate; SrsAudioChannels asound_type; - /** - * audio specified - * audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33, - * 1.5.1.1 Audio object type definition, page 23, - * in ISO_IEC_14496-3-AAC-2001.pdf. - */ + // The audio specified + // audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33, + // 1.5.1.1 Audio object type definition, page 23, + // in ISO_IEC_14496-3-AAC-2001.pdf. SrsAacObjectType aac_object; public: SrsStatisticStream(); @@ -106,13 +100,9 @@ public: public: virtual srs_error_t dumps(SrsJsonObject* obj); public: - /** - * publish the stream. - */ + // Publish the stream. virtual void publish(int cid); - /** - * close the stream. - */ + // Close the stream. virtual void close(); }; @@ -136,24 +126,24 @@ class SrsStatistic { private: static SrsStatistic *_instance; - // the id to identify the sever. + // The id to identify the sever. int64_t _server_id; private: - // key: vhost id, value: vhost object. + // The key: vhost id, value: vhost object. std::map vhosts; - // key: vhost url, value: vhost Object. + // The key: vhost url, value: vhost Object. // @remark a fast index for vhosts. std::map rvhosts; private: - // key: stream id, value: stream Object. + // The key: stream id, value: stream Object. std::map streams; - // key: stream url, value: stream Object. + // The key: stream url, value: stream Object. // @remark a fast index for streams. std::map rstreams; private: - // key: client id, value: stream object. + // The key: client id, value: stream object. std::map clients; - // server total kbps. + // The server total kbps. SrsKbps* kbps; SrsWallClock* clk; private: @@ -167,77 +157,51 @@ public: virtual SrsStatisticStream* find_stream(int sid); virtual SrsStatisticClient* find_client(int cid); public: - /** - * when got video info for stream. - */ + // When got video info for stream. virtual srs_error_t on_video_info(SrsRequest* req, SrsVideoCodecId vcodec, SrsAvcProfile avc_profile, SrsAvcLevel avc_level, int width, int height); - /** - * when got audio info for stream. - */ + // When got audio info for stream. virtual srs_error_t on_audio_info(SrsRequest* req, SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioChannels asound_type, SrsAacObjectType aac_object); - /** - * When got videos, update the frames. - * We only stat the total number of video frames. - */ + // When got videos, update the frames. + // We only stat the total number of video frames. virtual srs_error_t on_video_frames(SrsRequest* req, int nb_frames); - /** - * when publish stream. - * @param req the request object of publish connection. - * @param cid the cid of publish connection. - */ + // When publish stream. + // @param req the request object of publish connection. + // @param cid the cid of publish connection. virtual void on_stream_publish(SrsRequest* req, int cid); - /** - * when close stream. - */ + // When close stream. virtual void on_stream_close(SrsRequest* req); public: - /** - * when got a client to publish/play stream, - * @param id, the client srs id. - * @param req, the client request object. - * @param conn, the physical absract connection object. - * @param type, the type of connection. - */ + // When got a client to publish/play stream, + // @param id, the client srs id. + // @param req, the client request object. + // @param conn, the physical absract connection object. + // @param type, the type of connection. virtual srs_error_t on_client(int id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type); - /** - * client disconnect - * @remark the on_disconnect always call, while the on_client is call when - * only got the request object, so the client specified by id maybe not - * exists in stat. - */ + // Client disconnect + // @remark the on_disconnect always call, while the on_client is call when + // only got the request object, so the client specified by id maybe not + // exists in stat. virtual void on_disconnect(int id); - /** - * sample the kbps, add delta bytes of conn. - * use kbps_sample() to get all result of kbps stat. - */ + // Sample the kbps, add delta bytes of conn. + // Use kbps_sample() to get all result of kbps stat. // TODO: FIXME: the add delta must use ISrsKbpsDelta interface instead. virtual void kbps_add_delta(SrsConnection* conn); - /** - * calc the result for all kbps. - * @return the server kbps. - */ + // Calc the result for all kbps. + // @return the server kbps. virtual SrsKbps* kbps_sample(); public: - /** - * get the server id, used to identify the server. - * for example, when restart, the server id must changed. - */ + // Get the server id, used to identify the server. + // For example, when restart, the server id must changed. virtual int64_t server_id(); - /** - * dumps the vhosts to amf0 array. - */ + // Dumps the vhosts to amf0 array. virtual srs_error_t dumps_vhosts(SrsJsonArray* arr); - /** - * dumps the streams to amf0 array. - */ + // Dumps the streams to amf0 array. virtual srs_error_t dumps_streams(SrsJsonArray* arr); - /** - * dumps the clients to amf0 array - * @param start the start index, from 0. - * @param count the max count of clients to dump. - */ + // Dumps the clients to amf0 array + // @param start the start index, from 0. + // @param count the max count of clients to dump. virtual srs_error_t dumps_clients(SrsJsonArray* arr, int start, int count); private: virtual SrsStatisticVhost* create_vhost(SrsRequest* req); diff --git a/trunk/src/app/srs_app_thread.hpp b/trunk/src/app/srs_app_thread.hpp index 4c55cc4c4..f02deb8d2 100644 --- a/trunk/src/app/srs_app_thread.hpp +++ b/trunk/src/app/srs_app_thread.hpp @@ -31,12 +31,10 @@ #include #include -/** - * The coroutine manager use a thread to delete a connection, which will stop the service - * thread, for example, when the RTMP connection thread cycle terminated, it will notify - * the manager(the server) to remove the connection from list of server and push it to - * the manager thread to delete it, finally the thread of connection will stop. - */ +// The coroutine manager use a thread to delete a connection, which will stop the service +// thread, for example, when the RTMP connection thread cycle terminated, it will notify +// the manager(the server) to remove the connection from list of server and push it to +// the manager thread to delete it, finally the thread of connection will stop. class SrsCoroutineManager : virtual public ISrsCoroutineHandler, virtual public IConnectionManager { private: @@ -48,10 +46,10 @@ public: virtual ~SrsCoroutineManager(); public: srs_error_t start(); -// ISrsCoroutineHandler +// interface ISrsCoroutineHandler public: virtual srs_error_t cycle(); -// IConnectionManager +// interface IConnectionManager public: virtual void remove(ISrsConnection* c); private: diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 82cdfb45e..2cf3ee54c 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -41,51 +41,43 @@ class SrsKbps; class SrsBuffer; class SrsJsonObject; -/** - * convert level in string to log level in int. - * @return the log level defined in SrsLogLevel. - */ +// Convert level in string to log level in int. +// @return the log level defined in SrsLogLevel. extern SrsLogLevel srs_get_log_level(std::string level); -/** - * build the path according to vhost/app/stream, where replace variables: - * [vhost], the vhost of stream. - * [app], the app of stream. - * [stream], the stream name of stream. - * @return the replaced path. - */ +// Build the path according to vhost/app/stream, where replace variables: +// [vhost], the vhost of stream. +// [app], the app of stream. +// [stream], the stream name of stream. +// @return the replaced path. extern std::string srs_path_build_stream(std::string template_path, std::string vhost, std::string app, std::string stream); -/** - * build the path according to timestamp, where replace variables: - * [2006], replace this const to current year. - * [01], replace this const to current month. - * [02], replace this const to current date. - * [15], replace this const to current hour. - * [04], repleace this const to current minute. - * [05], repleace this const to current second. - * [999], repleace this const to current millisecond. - * [timestamp],replace this const to current UNIX timestamp in ms. - * @return the replaced path. - */ +// Build the path according to timestamp, where replace variables: +// [2006], replace this const to current year. +// [01], replace this const to current month. +// [02], replace this const to current date. +// [15], replace this const to current hour. +// [04], repleace this const to current minute. +// [05], repleace this const to current second. +// [999], repleace this const to current millisecond. +// [timestamp],replace this const to current UNIX timestamp in ms. +// @return the replaced path. extern std::string srs_path_build_timestamp(std::string template_path); -/** - * kill the pid by SIGINT, then wait to quit, - * kill the pid by SIGKILL again when exceed the timeout. - * @param pid the pid to kill. ignore for -1. set to -1 when killed. - * @return an int error code. - */ +// Kill the pid by SIGINT, then wait to quit, +// Kill the pid by SIGKILL again when exceed the timeout. +// @param pid the pid to kill. ignore for -1. set to -1 when killed. +// @return an int error code. extern srs_error_t srs_kill_forced(int& pid); -// current process resouce usage. +// Current process resouce usage. // @see: man getrusage class SrsRusage { public: - // whether the data is ok. + // Whether the data is ok. bool ok; - // the time in ms when sample. + // The time in ms when sample. int64_t sample_time; public: @@ -95,21 +87,21 @@ public: SrsRusage(); }; -// get system rusage, use cache to avoid performance problem. +// Get system rusage, use cache to avoid performance problem. extern SrsRusage* srs_get_system_rusage(); -// the deamon st-thread will update it. +// The deamon st-thread will update it. extern void srs_update_system_rusage(); -// to stat the process info. +// To stat the process info. // @see: man 5 proc, /proc/[pid]/stat class SrsProcSelfStat { public: - // whether the data is ok. + // Whether the data is ok. bool ok; - // the time in ms when sample. + // The time in ms when sample. int64_t sample_time; - // the percent of usage. 0.153 is 15.3%. + // The percent of usage. 0.153 is 15.3%. float percent; // data of /proc/[pid]/stat @@ -256,49 +248,47 @@ public: SrsProcSelfStat(); }; -// to stat the cpu time. +// To stat the cpu time. // @see: man 5 proc, /proc/stat -/** - * about the cpu time, @see: http://stackoverflow.com/questions/16011677/calculating-cpu-usage-using-proc-files - * for example, for ossrs.net, a single cpu machine: - * [winlin@SRS ~]$ cat /proc/uptime && cat /proc/stat - * 5275153.01 4699624.99 - * cpu 43506750 973 8545744 466133337 4149365 190852 804666 0 0 - * where the uptime is 5275153.01s - * generally, USER_HZ sysconf(_SC_CLK_TCK)=100, which means the unit of /proc/stat is "1/100ths seconds" - * that is, USER_HZ=1/100 seconds - * cpu total = 43506750+973+8545744+466133337+4149365+190852+804666+0+0 (USER_HZ) - * = 523331687 (USER_HZ) - * = 523331687 * 1/100 (seconds) - * = 5233316.87 seconds - * the cpu total seconds almost the uptime, the delta is more precise. - * - * we run the command about 26minutes: - * [winlin@SRS ~]$ cat /proc/uptime && cat /proc/stat - * 5276739.83 4701090.76 - * cpu 43514105 973 8548948 466278556 4150480 190899 804937 0 0 - * where the uptime is 5276739.83s - * cpu total = 43514105+973+8548948+466278556+4150480+190899+804937+0+0 (USER_HZ) - * = 523488898 (USER_HZ) - * = 523488898 * 1/100 (seconds) - * = 5234888.98 seconds - * where: - * uptime delta = 1586.82s - * cpu total delta = 1572.11s - * the deviation is more smaller. - */ +// about the cpu time, @see: http://stackoverflow.com/questions/16011677/calculating-cpu-usage-using-proc-files +// for example, for ossrs.net, a single cpu machine: +// [winlin@SRS ~]$ cat /proc/uptime && cat /proc/stat +// 5275153.01 4699624.99 +// cpu 43506750 973 8545744 466133337 4149365 190852 804666 0 0 +// Where the uptime is 5275153.01s +// generally, USER_HZ sysconf(_SC_CLK_TCK)=100, which means the unit of /proc/stat is "1/100ths seconds" +// that is, USER_HZ=1/100 seconds +// cpu total = 43506750+973+8545744+466133337+4149365+190852+804666+0+0 (USER_HZ) +// = 523331687 (USER_HZ) +// = 523331687 * 1/100 (seconds) +// = 5233316.87 seconds +// The cpu total seconds almost the uptime, the delta is more precise. +// +// we run the command about 26minutes: +// [winlin@SRS ~]$ cat /proc/uptime && cat /proc/stat +// 5276739.83 4701090.76 +// cpu 43514105 973 8548948 466278556 4150480 190899 804937 0 0 +// Where the uptime is 5276739.83s +// cpu total = 43514105+973+8548948+466278556+4150480+190899+804937+0+0 (USER_HZ) +// = 523488898 (USER_HZ) +// = 523488898 * 1/100 (seconds) +// = 5234888.98 seconds +// where: +// uptime delta = 1586.82s +// cpu total delta = 1572.11s +// The deviation is more smaller. class SrsProcSystemStat { public: - // whether the data is ok. + // Whether the data is ok. bool ok; - // the time in ms when sample. + // The time in ms when sample. int64_t sample_time; - // the percent of usage. 0.153 is 15.3%. - // the percent is in [0, 1], where 1 is 100%. + // The percent of usage. 0.153 is 15.3%. + // The percent is in [0, 1], where 1 is 100%. // for multiple core cpu, max also is 100%. float percent; - // the total cpu time units + // The total cpu time units // @remark, zero for the previous total() is zero. // the usaged_cpu_delta = total_delta * percent // previous cpu total = this->total() - total_delta @@ -310,7 +300,7 @@ public: // (1/100ths of a second on most architectures, use // sysconf(_SC_CLK_TCK) to obtain the right value) // - // the system spent in user mode, + // The system spent in user mode, unsigned long long user; // user mode with low priority (nice), unsigned long long nice; @@ -341,18 +331,18 @@ public: public: SrsProcSystemStat(); - // get total cpu units. + // Get total cpu units. int64_t total(); }; -// get system cpu stat, use cache to avoid performance problem. +// Get system cpu stat, use cache to avoid performance problem. extern SrsProcSelfStat* srs_get_self_proc_stat(); -// get system cpu stat, use cache to avoid performance problem. +// Get system cpu stat, use cache to avoid performance problem. extern SrsProcSystemStat* srs_get_system_proc_stat(); -// the deamon st-thread will update it. +// The deamon st-thread will update it. extern void srs_update_proc_stat(); -// stat disk iops +// Stat disk iops // @see: http://stackoverflow.com/questions/4458183/how-the-util-of-iostat-is-computed // for total disk io, @see: cat /proc/vmstat |grep pgpg // for device disk io, @see: cat /proc/diskstats @@ -364,9 +354,9 @@ extern void srs_update_proc_stat(); class SrsDiskStat { public: - // whether the data is ok. + // Whether the data is ok. bool ok; - // the time in ms when sample. + // The time in ms when sample. int64_t sample_time; // input(read) KBytes per seconds @@ -382,10 +372,10 @@ public: public: // @see: cat /proc/vmstat - // the in(read) page count, pgpgin*1024 is the read bytes. + // The in(read) page count, pgpgin*1024 is the read bytes. // Total number of kilobytes the system paged in from disk per second. unsigned long pgpgin; - // the out(write) page count, pgpgout*1024 is the write bytes. + // The out(write) page count, pgpgout*1024 is the write bytes. // Total number of kilobytes the system paged out to disk per second. unsigned long pgpgout; @@ -415,7 +405,7 @@ public: // Write I/O operations unsigned int wr_ios; // Number of writes merged Reads and writes which are adjacent - // to each other may be merged for efficiency. Thus two 4K + // To each other may be merged for efficiency. Thus two 4K // reads may become one 8K read before it is ultimately // handed to the disk, and so it will be counted (and queued) // as only one I/O. This field lets you know how often this was done. @@ -446,7 +436,7 @@ public: // progress (field 9) times the number of milliseconds spent // doing I/O since the last update of this field. This can // provide an easy measure of both I/O completion time and - // the backlog that may be accumulating. + // The backlog that may be accumulating. // Average queue length unsigned int aveq; @@ -454,21 +444,21 @@ public: SrsDiskStat(); }; -// get disk stat, use cache to avoid performance problem. +// Get disk stat, use cache to avoid performance problem. extern SrsDiskStat* srs_get_disk_stat(); -// the deamon st-thread will update it. +// The deamon st-thread will update it. extern void srs_update_disk_stat(); -// stat system memory info +// Stat system memory info // @see: cat /proc/meminfo class SrsMemInfo { public: - // whether the data is ok. + // Whether the data is ok. bool ok; - // the time in ms when sample. + // The time in ms when sample. int64_t sample_time; - // the percent of usage. 0.153 is 15.3%. + // The percent of usage. 0.153 is 15.3%. float percent_ram; float percent_swap; @@ -495,9 +485,9 @@ public: SrsMemInfo(); }; -// get system meminfo, use cache to avoid performance problem. +// Get system meminfo, use cache to avoid performance problem. extern SrsMemInfo* srs_get_meminfo(); -// the deamon st-thread will update it. +// The deamon st-thread will update it. extern void srs_update_meminfo(); // system cpu hardware info. @@ -506,7 +496,7 @@ extern void srs_update_meminfo(); class SrsCpuInfo { public: - // whether the data is ok. + // Whether the data is ok. bool ok; // data of /proc/cpuinfo @@ -520,14 +510,14 @@ public: SrsCpuInfo(); }; -// get system cpu info, use cache to avoid performance problem. +// Get system cpu info, use cache to avoid performance problem. extern SrsCpuInfo* srs_get_cpuinfo(); -// platform(os, srs) uptime/load summary +// The platform(os, srs) uptime/load summary class SrsPlatformInfo { public: - // whether the data is ok. + // Whether the data is ok. bool ok; // srs startup time, in ms. @@ -551,22 +541,21 @@ public: SrsPlatformInfo(); }; -// get platform info, use cache to avoid performance problem. +// Get platform info, use cache to avoid performance problem. extern SrsPlatformInfo* srs_get_platform_info(); -// the deamon st-thread will update it. +// The deamon st-thread will update it. extern void srs_update_platform_info(); -// network device summary for each network device, -// for example, eth0, eth1, ethN +// The network device summary for each network device, for example, eth0, eth1, ethN class SrsNetworkDevices { public: - // whether the network device is ok. + // Whether the network device is ok. bool ok; // 6-chars interfaces name char name[7]; - // the sample time in ms. + // The sample time in ms. int64_t sample_time; public: @@ -594,20 +583,20 @@ public: SrsNetworkDevices(); }; -// get network devices info, use cache to avoid performance problem. +// Get network devices info, use cache to avoid performance problem. extern SrsNetworkDevices* srs_get_network_devices(); extern int srs_get_network_devices_count(); -// the deamon st-thread will update it. +// The deamon st-thread will update it. extern void srs_update_network_devices(); -// system connections, and srs rtmp network summary +// The system connections, and srs rtmp network summary class SrsNetworkRtmpServer { public: - // whether the network device is ok. + // Whether the network device is ok. bool ok; - // the sample time in ms. + // The sample time in ms. int64_t sample_time; public: @@ -638,32 +627,32 @@ public: SrsNetworkRtmpServer(); }; -// get network devices info, use cache to avoid performance problem. +// Get network devices info, use cache to avoid performance problem. extern SrsNetworkRtmpServer* srs_get_network_rtmp_server(); -// the deamon st-thread will update it. +// The deamon st-thread will update it. extern void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps); -// get local or peer ip. -// where local ip is the server ip which client connected. +// Get local or peer ip. +// Where local ip is the server ip which client connected. extern std::string srs_get_local_ip(int fd); -// get the local id port. +// Get the local id port. extern int srs_get_local_port(int fd); -// where peer ip is the client public ip which connected to server. +// Where peer ip is the client public ip which connected to server. extern std::string srs_get_peer_ip(int fd); -// whether string is digit number +// Whether string is digit number // is_digit("1234567890") === true // is_digit("0123456789") === false // is_digit("1234567890a") === false // is_digit("a1234567890") === false extern bool srs_is_digit_number(const std::string& str); -// whether string is boolean +// Whether string is boolean // is_bool("true") == true // is_bool("false") == true // otherwise, false. extern bool srs_is_boolean(const std::string& str); -// dump summaries for /api/v1/summaries. +// Dump summaries for /api/v1/summaries. extern void srs_api_dump_summaries(SrsJsonObject* obj); #endif