Refine typo in app.

pull/1651/head
winlin 6 years ago
parent aac8a13f42
commit 45009785fb

@ -40,9 +40,7 @@ class SrsMpdWriter;
class SrsMp4M2tsInitEncoder;
class SrsMp4M2tsSegmentEncoder;
/**
* The init mp4 for FMP4.
*/
// The init mp4 for FMP4.
class SrsInitMp4 : public SrsFragment
{
private:
@ -56,9 +54,7 @@ public:
virtual srs_error_t write(SrsFormat* format, bool video, int tid);
};
/**
* The FMP4(Fragmented MP4) for DASH streaming.
*/
// The FMP4(Fragmented MP4) for DASH streaming.
class SrsFragmentedMp4 : public SrsFragment
{
private:
@ -76,9 +72,7 @@ public:
virtual srs_error_t reap(uint64_t& dts);
};
/**
* The writer to write MPD for DASH.
*/
// The writer to write MPD for DASH.
class SrsMpdWriter
{
private:
@ -113,9 +107,7 @@ public:
virtual srs_error_t get_fragment(bool video, std::string& home, std::string& filename, int64_t& sn, srs_utime_t& basetime);
};
/**
* The controller for DASH, control the MPD and FMP4 generating system.
*/
// The controller for DASH, control the MPD and FMP4 generating system.
class SrsDashController
{
private:
@ -149,9 +141,7 @@ private:
virtual srs_error_t refresh_init_mp4(SrsSharedPtrMessage* msg, SrsFormat* format);
};
/**
* The MPEG-DASH encoder, transmux RTMP to DASH.
*/
// The MPEG-DASH encoder, transmux RTMP to DASH.
class SrsDash
{
private:

@ -49,9 +49,7 @@ class SrsFormat;
#include <srs_app_reload.hpp>
#include <srs_app_async_call.hpp>
/**
* The segmenter for DVR, to write a segment file in flv/mp4.
*/
// The segmenter for DVR, to write a segment file in flv/mp4.
class SrsDvrSegmenter : public ISrsReloadHandler
{
protected:
@ -110,9 +108,7 @@ public:
virtual srs_error_t on_reload_vhost_dvr(std::string vhost);
};
/**
* The FLV segmenter to use FLV encoder to write file.
*/
// The FLV segmenter to use FLV encoder to write file.
class SrsDvrFlvSegmenter : public SrsDvrSegmenter
{
private:
@ -140,9 +136,7 @@ protected:
virtual srs_error_t close_encoder();
};
/**
* The MP4 segmenter to use MP4 encoder to write file.
*/
// The MP4 segmenter to use MP4 encoder to write file.
class SrsDvrMp4Segmenter : public SrsDvrSegmenter
{
private:
@ -161,9 +155,7 @@ protected:
virtual srs_error_t close_encoder();
};
/**
* the dvr async call.
*/
// the dvr async call.
class SrsDvrAsyncCallOnDvr : public ISrsAsyncCallTask
{
private:
@ -178,9 +170,7 @@ public:
virtual std::string to_string();
};
/**
* The DVR plan, when and how to reap segment.
*/
// The DVR plan, when and how to reap segment.
class SrsDvrPlan : public ISrsReloadHandler
{
public:
@ -208,9 +198,7 @@ public:
static srs_error_t create_plan(std::string vhost, SrsDvrPlan** pplan);
};
/**
* The DVR session plan: reap flv when session complete(unpublish)
*/
// The DVR session plan: reap flv when session complete(unpublish)
class SrsDvrSessionPlan : public SrsDvrPlan
{
public:
@ -221,9 +209,7 @@ public:
virtual void on_unpublish();
};
/**
* The DVR segment plan: reap flv when duration exceed.
*/
// The DVR segment plan: reap flv when duration exceed.
class SrsDvrSegmentPlan : public SrsDvrPlan
{
private:
@ -246,9 +232,7 @@ public:
virtual srs_error_t on_reload_vhost_dvr(std::string vhost);
};
/**
* DVR(Digital Video Recorder) to record RTMP stream to flv/mp4 file.
*/
// DVR(Digital Video Recorder) to record RTMP stream to flv/mp4 file.
class SrsDvr : public ISrsReloadHandler
{
private:
@ -264,36 +248,24 @@ public:
SrsDvr();
virtual ~SrsDvr();
public:
/**
* initialize dvr, create dvr plan.
* when system initialize(encoder publish at first time, or reload),
* initialize the dvr will reinitialize the plan, the whole dvr framework.
*/
// initialize dvr, create dvr plan.
// when system initialize(encoder publish at first time, or reload),
// initialize the dvr will reinitialize the plan, the whole dvr framework.
virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r);
/**
* publish stream event,
* when encoder start to publish RTMP stream.
* @param fetch_sequence_header whether fetch sequence from source.
*/
// publish stream event,
// when encoder start to publish RTMP stream.
// @param fetch_sequence_header whether fetch sequence from source.
virtual srs_error_t on_publish();
/**
* the unpublish event.,
* when encoder stop(unpublish) to publish RTMP stream.
*/
// the unpublish event.,
// when encoder stop(unpublish) to publish RTMP stream.
virtual void on_unpublish();
/**
* get some information from metadata, it's optinal.
*/
// get some information from metadata, it's optinal.
virtual srs_error_t on_meta_data(SrsSharedPtrMessage* metadata);
/**
* mux the audio packets to dvr.
* @param shared_audio, directly ptr, copy it if need to save it.
*/
// mux the audio packets to dvr.
// @param shared_audio, directly ptr, copy it if need to save it.
virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* foramt);
/**
* mux the video packets to dvr.
* @param shared_video, directly ptr, copy it if need to save it.
*/
// mux the video packets to dvr.
// @param shared_video, directly ptr, copy it if need to save it.
virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format);
// interface ISrsReloadHandler
public:

@ -47,34 +47,28 @@ class SrsTcpClient;
class SrsSimpleRtmpClient;
class SrsPacket;
/**
* the state of edge, auto machine
*/
// The state of edge, auto machine
enum SrsEdgeState
{
SrsEdgeStateInit = 0,
// for play edge
// For play edge
SrsEdgeStatePlay = 100,
// play stream from origin, ingest stream
SrsEdgeStateIngestConnected = 101,
// for publish edge
// For publish edge
SrsEdgeStatePublish = 200,
};
/**
* the state of edge from user, manual machine
*/
// The state of edge from user, manual machine
enum SrsEdgeUserState
{
SrsEdgeUserStateInit = 0,
SrsEdgeUserStateReloading = 100,
};
/**
* the upstream of edge, can be rtmp or http.
*/
// The upstream of edge, can be rtmp or http.
class SrsEdgeUpstream
{
public:
@ -93,7 +87,7 @@ public:
class SrsEdgeRtmpUpstream : public SrsEdgeUpstream
{
private:
// for RTMP 302, if not empty,
// For RTMP 302, if not empty,
// use this <ip[:port]> as upstream.
std::string redirect;
SrsSimpleRtmpClient* sdk;
@ -111,9 +105,7 @@ public:
virtual void kbps_sample(const char* label, int64_t age);
};
/**
* edge used to ingest stream from origin.
*/
// The edge used to ingest stream from origin.
class SrsEdgeIngester : public ISrsCoroutineHandler
{
private:
@ -123,7 +115,7 @@ private:
SrsCoroutine* trd;
SrsLbRoundRobin* lb;
SrsEdgeUpstream* upstream;
// for RTMP 302 redirect.
// For RTMP 302 redirect.
std::string redirect;
public:
SrsEdgeIngester();
@ -143,9 +135,7 @@ private:
virtual srs_error_t process_publish_message(SrsCommonMessage* msg);
};
/**
* edge used to forward stream to origin.
*/
// The edge used to forward stream to origin.
class SrsEdgeForwarder : public ISrsCoroutineHandler
{
private:
@ -155,16 +145,12 @@ private:
SrsCoroutine* trd;
SrsSimpleRtmpClient* sdk;
SrsLbRoundRobin* lb;
/**
* we must ensure one thread one fd principle,
* that is, a fd must be write/read by the one thread.
* the publish service thread will proxy(msg), and the edge forward thread
* will cycle(), so we use queue for cycle to send the msg of proxy.
*/
// we must ensure one thread one fd principle,
// that is, a fd must be write/read by the one thread.
// The publish service thread will proxy(msg), and the edge forward thread
// will cycle(), so we use queue for cycle to send the msg of proxy.
SrsMessageQueue* queue;
/**
* error code of send, for edge proxy thread to query.
*/
// error code of send, for edge proxy thread to query.
int send_error_code;
public:
SrsEdgeForwarder();
@ -184,10 +170,7 @@ public:
virtual srs_error_t proxy(SrsCommonMessage* msg);
};
/**
* play edge control service.
* downloading edge speed-up.
*/
// The play edge control service.
class SrsPlayEdge
{
private:
@ -197,32 +180,21 @@ public:
SrsPlayEdge();
virtual ~SrsPlayEdge();
public:
/**
* always use the req of source,
* for we assume all client to edge is invalid,
* if auth open, edge must valid it from origin, then service it.
*/
// Always use the req of source,
// For we assume all client to edge is invalid,
// if auth open, edge must valid it from origin, then service it.
virtual srs_error_t initialize(SrsSource* source, SrsRequest* req);
/**
* when client play stream on edge.
*/
// When client play stream on edge.
virtual srs_error_t on_client_play();
/**
* when all client stopped play, disconnect to origin.
*/
// When all client stopped play, disconnect to origin.
virtual void on_all_client_stop();
virtual std::string get_curr_origin();
public:
/**
* when ingester start to play stream.
*/
// When ingester start to play stream.
virtual srs_error_t on_ingest_play();
};
/**
* publish edge control service.
* uploading edge speed-up.
*/
// The publish edge control service.
class SrsPublishEdge
{
private:
@ -236,17 +208,11 @@ public:
public:
virtual srs_error_t initialize(SrsSource* source, SrsRequest* req);
virtual bool can_publish();
/**
* when client publish stream on edge.
*/
// When client publish stream on edge.
virtual srs_error_t on_client_publish();
/**
* proxy publish stream to edge
*/
// Proxy publish stream to edge
virtual srs_error_t on_proxy_publish(SrsCommonMessage* msg);
/**
* proxy unpublish stream to edge.
*/
// Proxy unpublish stream to edge.
virtual void on_proxy_unpublish();
};

@ -36,10 +36,8 @@ class SrsRequest;
class SrsPithyPrint;
class SrsFFMPEG;
/**
* the encoder for a stream,
* may use multiple ffmpegs to transcode the specified stream.
*/
// The encoder for a stream, may use multiple
// ffmpegs to transcode the specified stream.
class SrsEncoder : public ISrsCoroutineHandler
{
private:

@ -35,10 +35,7 @@ class SrsConfDirective;
class SrsPithyPrint;
class SrsProcess;
/**
* a transcode engine: ffmepg,
* used to transcode a stream to another.
*/
// A transcode engine: ffmepg, used to transcode a stream to another.
class SrsFFMPEG
{
private:

@ -43,14 +43,11 @@ class SrsOriginHub;
class SrsKbps;
class SrsSimpleRtmpClient;
/**
* forward the stream to other servers.
*/
// TODO: FIXME: refine the error log, comments it.
// Forward the stream to other servers.
class SrsForwarder : public ISrsCoroutineHandler
{
private:
// the ep to forward, server[:port].
// The ep to forward, server[:port].
std::string ep_forward;
SrsRequest* req;
private:
@ -60,10 +57,8 @@ private:
SrsSimpleRtmpClient* sdk;
SrsRtmpJitter* jitter;
SrsMessageQueue* queue;
/**
* cache the sequence header for retry when slave is failed.
* @see https://github.com/ossrs/srs/issues/150
*/
// Cache the sequence header for retry when slave is failed.
// @see https://github.com/ossrs/srs/issues/150
SrsSharedPtrMessage* sh_audio;
SrsSharedPtrMessage* sh_video;
public:
@ -75,20 +70,14 @@ public:
public:
virtual srs_error_t on_publish();
virtual void on_unpublish();
/**
* forward the audio packet.
* @param shared_metadata, directly ptr, copy it if need to save it.
*/
// Forward the audio packet.
// @param shared_metadata, directly ptr, copy it if need to save it.
virtual srs_error_t on_meta_data(SrsSharedPtrMessage* shared_metadata);
/**
* forward the audio packet.
* @param shared_audio, directly ptr, copy it if need to save it.
*/
// Forward the audio packet.
// @param shared_audio, directly ptr, copy it if need to save it.
virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio);
/**
* forward the video packet.
* @param shared_video, directly ptr, copy it if need to save it.
*/
// Forward the video packet.
// @param shared_video, directly ptr, copy it if need to save it.
virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video);
// interface ISrsReusableThread2Handler.
public:

@ -29,10 +29,8 @@
#include <string>
#include <vector>
/**
* Represent a fragment, such as HLS segment, DVR segment or DASH segment.
* It's a media file, for example FLV or MP4, with duration.
*/
// Represent a fragment, such as HLS segment, DVR segment or DASH segment.
// It's a media file, for example FLV or MP4, with duration.
class SrsFragment
{
private:
@ -75,9 +73,7 @@ public:
virtual srs_error_t rename();
};
/**
* The fragment window manage a series of fragment.
*/
// The fragment window manage a series of fragment.
class SrsFragmentWindow
{
private:

@ -35,6 +35,7 @@ class SrsSharedPtrMessage;
class SrsHdsFragment;
class SrsSource;
// Mux RTMP to Adobe HDS streaming.
class SrsHds
{
public:

@ -28,68 +28,63 @@
#include <map>
/**
* the handler for the tick.
*/
// The handler for the tick.
class ISrsHourGlass
{
public:
ISrsHourGlass();
virtual ~ISrsHourGlass();
public:
/**
* notify the handler, the type and tick.
*/
// When time is ticked, this function is called.
virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick) = 0;
};
/**
* the hourglass used to do some specieal task,
* while these task is cycle when some interval, for example,
* there are N=3 tasks to do:
* 1. heartbeat every 3s.
* 2. print message every 5s.
* 3. notify backend every 7s.
* the hourglass will call back when ticks:
* 1. notify(type=1, time=3)
* 2. notify(type=2, time=5)
* 3. notify(type=1, time=6)
* 4. notify(type=3, time=7)
* 5. notify(type=1, time=9)
* 6. notify(type=2, time=10)
* this is used for server and bocar server and other manager.
*
* Usage:
* SrsHourGlass* hg = new SrsHourGlass(handler, 1 * SRS_UTIME_MILLISECONDS);
* hg->tick(1, 3 * SRS_UTIME_MILLISECONDS);
* hg->tick(2, 5 * SRS_UTIME_MILLISECONDS);
* hg->tick(3, 7 * SRS_UTIME_MILLISECONDS);
* // create a thread to cycle, which will call handerl when ticked.
* while (true) {
* hg->cycle();
* }
*/
// he hourglass used to do some specieal task,
// while these task is cycle when some interval, for example,
// there are N=3 tasks to do:
// 1. heartbeat every 3s.
// 2. print message every 5s.
// 3. notify backend every 7s.
// The hourglass will call back when ticks:
// 1. notify(type=1, time=3)
// 2. notify(type=2, time=5)
// 3. notify(type=1, time=6)
// 4. notify(type=3, time=7)
// 5. notify(type=1, time=9)
// 6. notify(type=2, time=10)
// This is used for server and bocar server and other manager.
//
// Usage:
// SrsHourGlass* hg = new SrsHourGlass(handler, 1 * SRS_UTIME_MILLISECONDS);
// hg->tick(1, 3 * SRS_UTIME_MILLISECONDS);
// hg->tick(2, 5 * SRS_UTIME_MILLISECONDS);
// hg->tick(3, 7 * SRS_UTIME_MILLISECONDS);
// // create a thread to cycle, which will call handerl when ticked.
// while (true) {
// hg->cycle();
// }
class SrsHourGlass
{
private:
ISrsHourGlass* handler;
srs_utime_t _resolution;
// key: the type of tick.
// value: the interval of tick.
// The ticks:
// key: the type of tick.
// value: the interval of tick.
std::map<int, srs_utime_t> ticks;
// the total elapsed time,
// The total elapsed time,
// for each cycle, we increase it with a resolution.
srs_utime_t total_elapse;
public:
SrsHourGlass(ISrsHourGlass* h, srs_utime_t resolution);
virtual ~SrsHourGlass();
public:
// add a pair of tick(type, interval).
// Add a pair of tick(type, interval).
// @param type the type of tick.
// @param interval the interval in srs_utime_t of tick.
virtual srs_error_t tick(int type, srs_utime_t interval);
public:
// cycle the hourglass, which will sleep resolution every time.
// Cycle the hourglass, which will sleep resolution every time.
// and call handler when ticked.
virtual srs_error_t cycle();
};

@ -37,7 +37,7 @@ class SrsServer;
#include <srs_http_stack.hpp>
#include <srs_app_reload.hpp>
// for http root.
// For http root.
class SrsGoApiRoot : public ISrsHttpHandler
{
public:

@ -55,9 +55,7 @@ class SrsHttpMessage;
class SrsHttpStreamServer;
class SrsHttpStaticServer;
/**
* The http connection which request the static or stream content.
*/
// The http connection which request the static or stream content.
class SrsHttpConn : public SrsConnection
{
protected:
@ -73,26 +71,22 @@ public:
protected:
virtual srs_error_t do_cycle();
protected:
// when got http message,
// When got http message,
// for the static service or api, discard any body.
// for the stream caster, for instance, http flv streaming, may discard the flv header or not.
virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg) = 0;
private:
virtual srs_error_t process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
/**
* when the connection disconnect, call this method.
* e.g. log msg of connection and report to other system.
* @param request: request which is converted by the last http message.
*/
// When the connection disconnect, call this method.
// e.g. log msg of connection and report to other system.
// @param request: request which is converted by the last http message.
virtual srs_error_t on_disconnect(SrsRequest* req);
// interface ISrsReloadHandler
public:
virtual srs_error_t on_reload_http_stream_crossdomain();
};
/**
* drop body of request, only process the response.
*/
// Drop body of request, only process the response.
class SrsResponseOnlyHttpConn : public SrsHttpConn
{
public:
@ -109,9 +103,7 @@ public:
virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg);
};
/**
* the http server, use http stream or static server to serve requests.
*/
// The http server, use http stream or static server to serve requests.
class SrsHttpServer : public ISrsHttpServeMux
{
private:
@ -123,10 +115,9 @@ public:
virtual ~SrsHttpServer();
public:
virtual srs_error_t initialize();
// ISrsHttpServeMux
// interface ISrsHttpServeMux
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
// http flv/ts/mp3/aac stream
public:
virtual srs_error_t http_mount(SrsSource* s, SrsRequest* r);
virtual void http_unmount(SrsSource* s, SrsRequest* r);

@ -34,11 +34,10 @@ class SrsRequest;
class SrsHttpParser;
class SrsHttpClient;
/**
* the http hooks, http callback api,
* for some event, such as on_connect, call
* a http api(hooks).
*/
// the http hooks, http callback api,
// for some event, such as on_connect, call
// a http api(hooks).
// TODO: Refine to global variable.
class SrsHttpHooks
{
private:
@ -46,76 +45,56 @@ private:
public:
virtual ~SrsHttpHooks();
public:
/**
* on_connect hook, when client connect to srs.
* @param url the api server url, to valid the client.
* ignore if empty.
*/
// The on_connect hook, when client connect to srs.
// @param url the api server url, to valid the client.
// ignore if empty.
static srs_error_t on_connect(std::string url, SrsRequest* req);
/**
* on_close hook, when client disconnect to srs, where client is valid by on_connect.
* @param url the api server url, to process the event.
* ignore if empty.
*/
// The on_close hook, when client disconnect to srs, where client is valid by on_connect.
// @param url the api server url, to process the event.
// ignore if empty.
static void on_close(std::string url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes);
/**
* on_publish hook, when client(encoder) start to publish stream
* @param url the api server url, to valid the client.
* ignore if empty.
*/
// The on_publish hook, when client(encoder) start to publish stream
// @param url the api server url, to valid the client.
// ignore if empty.
static srs_error_t on_publish(std::string url, SrsRequest* req);
/**
* on_unpublish hook, when client(encoder) stop publish stream.
* @param url the api server url, to process the event.
* ignore if empty.
*/
// The on_unpublish hook, when client(encoder) stop publish stream.
// @param url the api server url, to process the event.
// ignore if empty.
static void on_unpublish(std::string url, SrsRequest* req);
/**
* on_play hook, when client start to play stream.
* @param url the api server url, to valid the client.
* ignore if empty.
*/
// The on_play hook, when client start to play stream.
// @param url the api server url, to valid the client.
// ignore if empty.
static srs_error_t on_play(std::string url, SrsRequest* req);
/**
* on_stop hook, when client stop to play the stream.
* @param url the api server url, to process the event.
* ignore if empty.
*/
// The on_stop hook, when client stop to play the stream.
// @param url the api server url, to process the event.
// ignore if empty.
static void on_stop(std::string url, SrsRequest* req);
/**
* on_dvr hook, when reap a dvr file.
* @param url the api server url, to process the event.
* ignore if empty.
* @param file the file path, can be relative or absolute path.
* @param cid the source connection cid, for the on_dvr is async call.
*/
// The on_dvr hook, when reap a dvr file.
// @param url the api server url, to process the event.
// ignore if empty.
// @param file the file path, can be relative or absolute path.
// @param cid the source connection cid, for the on_dvr is async call.
static srs_error_t on_dvr(int cid, std::string url, SrsRequest* req, std::string file);
/**
* when hls reap segment, callback.
* @param url the api server url, to process the event.
* ignore if empty.
* @param file the ts file path, can be relative or absolute path.
* @param ts_url the ts url, which used for m3u8.
* @param m3u8 the m3u8 file path, can be relative or absolute path.
* @param m3u8_url the m3u8 url, which is used for the http mount path.
* @param sn the seq_no, the sequence number of ts in hls/m3u8.
* @param duration the segment duration in srs_utime_t.
* @param cid the source connection cid, for the on_dvr is async call.
*/
// When hls reap segment, callback.
// @param url the api server url, to process the event.
// ignore if empty.
// @param file the ts file path, can be relative or absolute path.
// @param ts_url the ts url, which used for m3u8.
// @param m3u8 the m3u8 file path, can be relative or absolute path.
// @param m3u8_url the m3u8 url, which is used for the http mount path.
// @param sn the seq_no, the sequence number of ts in hls/m3u8.
// @param duration the segment duration in srs_utime_t.
// @param cid the source connection cid, for the on_dvr is async call.
static srs_error_t on_hls(int cid, std::string url, SrsRequest* req, std::string file, std::string ts_url,
std::string m3u8, std::string m3u8_url, int sn, srs_utime_t duration);
/**
* when hls reap segment, callback.
* @param url the api server url, to process the event.
* ignore if empty.
* @param ts_url the ts uri, used to replace the variable [ts_url] in url.
* @param nb_notify the max bytes to read from notify server.
* @param cid the source connection cid, for the on_dvr is async call.
*/
// When hls reap segment, callback.
// @param url the api server url, to process the event.
// ignore if empty.
// @param ts_url the ts uri, used to replace the variable [ts_url] in url.
// @param nb_notify the max bytes to read from notify server.
// @param cid the source connection cid, for the on_dvr is async call.
static srs_error_t on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify);
/**
* Discover co-workers for origin cluster.
*/
// Discover co-workers for origin cluster.
static srs_error_t discover_co_workers(std::string url, std::string& host, int& port);
private:
static srs_error_t do_post(SrsHttpClient* hc, std::string url, std::string req, int& code, std::string& res);

@ -28,12 +28,10 @@
#include <srs_app_http_conn.hpp>
/**
* the flv vod stream supports flv?start=offset-bytes.
* for example, http://server/file.flv?start=10240
* server will write flv header and sequence header,
* then seek(10240) and response flv tag data.
*/
// The flv vod stream supports flv?start=offset-bytes.
// For example, http://server/file.flv?start=10240
// server will write flv header and sequence header,
// then seek(10240) and response flv tag data.
class SrsVodStream : public SrsHttpFileServer
{
public:
@ -44,10 +42,8 @@ protected:
virtual srs_error_t serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int start, int end);
};
/**
* the http static server instance,
* serve http static file and flv/mp4 vod stream.
*/
// The http static server instance,
// serve http static file and flv/mp4 vod stream.
class SrsHttpStaticServer : virtual public ISrsReloadHandler
{
private:

@ -33,9 +33,7 @@ class SrsMp3Transmuxer;
class SrsFlvTransmuxer;
class SrsTsTransmuxer;
/**
* A cache for HTTP Live Streaming encoder, to make android(weixin) happy.
*/
// A cache for HTTP Live Streaming encoder, to make android(weixin) happy.
class SrsBufferCache : public ISrsCoroutineHandler
{
private:
@ -57,43 +55,31 @@ public:
virtual srs_error_t cycle();
};
/**
* The encoder to transmux RTMP stream.
*/
// The encoder to transmux RTMP stream.
class ISrsBufferEncoder
{
public:
ISrsBufferEncoder();
virtual ~ISrsBufferEncoder();
public:
/**
* initialize the encoder with file writer(to http response) and stream cache.
* @param w the writer to write to http response.
* @param c the stream cache for audio stream fast startup.
*/
// Initialize the encoder with file writer(to http response) and stream cache.
// @param w the writer to write to http response.
// @param c the stream cache for audio stream fast startup.
virtual srs_error_t initialize(SrsFileWriter* w, SrsBufferCache* c) = 0;
/**
* write rtmp video/audio/metadata.
*/
// Write rtmp video/audio/metadata.
virtual srs_error_t write_audio(int64_t timestamp, char* data, int size) = 0;
virtual srs_error_t write_video(int64_t timestamp, char* data, int size) = 0;
virtual srs_error_t write_metadata(int64_t timestamp, char* data, int size) = 0;
public:
/**
* for some stream, for example, mp3 and aac, the audio stream,
* we use large gop cache in encoder, for the gop cache of SrsSource is ignore audio.
* @return true to use gop cache of encoder; otherwise, use SrsSource.
*/
// For some stream, for example, mp3 and aac, the audio stream,
// we use large gop cache in encoder, for the gop cache of SrsSource is ignore audio.
// @return true to use gop cache of encoder; otherwise, use SrsSource.
virtual bool has_cache() = 0;
/**
* dumps the cache of encoder to consumer.
*/
// Dumps the cache of encoder to consumer.
virtual srs_error_t dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorithm jitter) = 0;
};
/**
* Transmux RTMP to HTTP Live Streaming.
*/
// Transmux RTMP to HTTP Live Streaming.
class SrsFlvStreamEncoder : public ISrsBufferEncoder
{
protected:
@ -112,26 +98,20 @@ public:
};
#ifdef SRS_PERF_FAST_FLV_ENCODER
/**
* A Fast HTTP FLV Live Streaming, to write multiple tags by writev.
* @see https://github.com/ossrs/srs/issues/405
*/
// A Fast HTTP FLV Live Streaming, to write multiple tags by writev.
// @see https://github.com/ossrs/srs/issues/405
class SrsFastFlvStreamEncoder : public SrsFlvStreamEncoder
{
public:
SrsFastFlvStreamEncoder();
virtual ~SrsFastFlvStreamEncoder();
public:
/**
* write the tags in a time.
*/
// Write the tags in a time.
virtual srs_error_t write_tags(SrsSharedPtrMessage** msgs, int count);
};
#endif
/**
* Transmux RTMP to HTTP TS Streaming.
*/
// Transmux RTMP to HTTP TS Streaming.
class SrsTsStreamEncoder : public ISrsBufferEncoder
{
private:
@ -149,9 +129,7 @@ public:
virtual srs_error_t dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorithm jitter);
};
/**
* Transmux RTMP with AAC stream to HTTP AAC Streaming.
*/
// Transmux RTMP with AAC stream to HTTP AAC Streaming.
class SrsAacStreamEncoder : public ISrsBufferEncoder
{
private:
@ -170,9 +148,7 @@ public:
virtual srs_error_t dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorithm jitter);
};
/**
* Transmux RTMP with MP3 stream to HTTP MP3 Streaming.
*/
// Transmux RTMP with MP3 stream to HTTP MP3 Streaming.
class SrsMp3StreamEncoder : public ISrsBufferEncoder
{
private:
@ -191,9 +167,7 @@ public:
virtual srs_error_t dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorithm jitter);
};
/**
* write stream to http response direclty.
*/
// Write stream to http response direclty.
class SrsBufferWriter : public SrsFileWriter
{
private:
@ -212,9 +186,7 @@ public:
virtual srs_error_t writev(const iovec* iov, int iovcnt, ssize_t* pnwrite);
};
/**
* HTTP Live Streaming, to transmux RTMP to HTTP FLV or other format.
*/
// HTTP Live Streaming, to transmux RTMP to HTTP FLV or other format.
class SrsLiveStream : public ISrsHttpHandler
{
private:
@ -234,9 +206,7 @@ private:
virtual srs_error_t streaming_send_messages(ISrsBufferEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs);
};
/**
* The Live Entry, to handle HTTP Live Streaming.
*/
// The Live Entry, to handle HTTP Live Streaming.
struct SrsLiveEntry
{
private:
@ -248,8 +218,8 @@ public:
SrsRequest* req;
SrsSource* source;
public:
// for template, the mount contains variables.
// for concrete stream, the mount is url to access.
// For template, the mount contains variables.
// For concrete stream, the mount is url to access.
std::string mount;
SrsLiveStream* stream;
@ -263,9 +233,7 @@ public:
bool is_aac();
};
/**
* The HTTP Live Streaming Server, to serve FLV/TS/MP3/AAC stream.
*/
// The HTTP Live Streaming Server, to serve FLV/TS/MP3/AAC stream.
// TODO: Support multiple stream.
class SrsHttpStreamServer : virtual public ISrsReloadHandler
, virtual public ISrsHttpMatchHijacker
@ -274,17 +242,17 @@ private:
SrsServer* server;
public:
SrsHttpServeMux mux;
// the http live streaming template, to create streams.
// The http live streaming template, to create streams.
std::map<std::string, SrsLiveEntry*> tflvs;
// the http live streaming streams, crote by template.
// The http live streaming streams, crote by template.
std::map<std::string, SrsLiveEntry*> sflvs;
public:
SrsHttpStreamServer(SrsServer* svr);
virtual ~SrsHttpStreamServer();
public:
virtual srs_error_t initialize();
// http flv/ts/mp3/aac stream
public:
// HTTP flv/ts/mp3/aac stream
virtual srs_error_t http_mount(SrsSource* s, SrsRequest* r);
virtual void http_unmount(SrsSource* s, SrsRequest* r);
// interface ISrsReloadHandler.

@ -33,51 +33,39 @@
struct sockaddr;
/**
* the udp packet handler.
*/
// The udp packet handler.
class ISrsUdpHandler
{
public:
ISrsUdpHandler();
virtual ~ISrsUdpHandler();
public:
/**
* when fd changed, for instance, reload the listen port,
* notify the handler and user can do something.
*/
// When fd changed, for instance, reload the listen port,
// notify the handler and user can do something.
virtual srs_error_t on_stfd_change(srs_netfd_t fd);
public:
/**
* when udp listener got a udp packet, notice server to process it.
* @param type, the client type, used to create concrete connection,
* for instance RTMP connection to serve client.
* @param from, the udp packet from address.
* @param buf, the udp packet bytes, user should copy if need to use.
* @param nb_buf, the size of udp packet bytes.
* @remark user should never use the buf, for it's a shared memory bytes.
*/
// When udp listener got a udp packet, notice server to process it.
// @param type, the client type, used to create concrete connection,
// for instance RTMP connection to serve client.
// @param from, the udp packet from address.
// @param buf, the udp packet bytes, user should copy if need to use.
// @param nb_buf, the size of udp packet bytes.
// @remark user should never use the buf, for it's a shared memory bytes.
virtual srs_error_t on_udp_packet(const sockaddr* from, const int fromlen, char* buf, int nb_buf) = 0;
};
/**
* the tcp connection handler.
*/
// The tcp connection handler.
class ISrsTcpHandler
{
public:
ISrsTcpHandler();
virtual ~ISrsTcpHandler();
public:
/**
* when got tcp client.
*/
// When got tcp client.
virtual srs_error_t on_tcp_client(srs_netfd_t stfd) = 0;
};
/**
* bind udp port, start thread to recv packet and handler it.
*/
// Bind udp port, start thread to recv packet and handler it.
class SrsUdpListener : public ISrsCoroutineHandler
{
private:
@ -104,9 +92,7 @@ public:
virtual srs_error_t cycle();
};
/**
* bind and listen tcp port, use handler to process the client.
*/
// Bind and listen tcp port, use handler to process the client.
class SrsTcpListener : public ISrsCoroutineHandler
{
private:

@ -32,24 +32,21 @@
#include <srs_app_reload.hpp>
#include <srs_service_log.hpp>
/**
* we use memory/disk cache and donot flush when write log.
* it's ok to use it without config, which will log to console, and default trace level.
* when you want to use different level, override this classs, set the protected _level.
*/
// Use memory/disk cache and donot flush when write log.
// it's ok to use it without config, which will log to console, and default trace level.
// when you want to use different level, override this classs, set the protected _level.
class SrsFastLog : public ISrsLog, public ISrsReloadHandler
{
// for utest to override
protected:
// defined in SrsLogLevel.
private:
// Defined in SrsLogLevel.
SrsLogLevel level;
private:
char* log_data;
// log to file if specified srs_log_file
// Log to file if specified srs_log_file
int fd;
// whether log to file tank
// Whether log to file tank
bool log_to_file_tank;
// whether use utc time.
// Whether use utc time.
bool utc;
public:
SrsFastLog();

@ -48,15 +48,13 @@ class SrsSimpleRtmpClient;
#include <srs_kernel_ts.hpp>
#include <srs_app_listener.hpp>
/**
* the queue for mpegts over udp to send packets.
* for the aac in mpegts contains many flv packets in a pes packet,
* we must recalc the timestamp.
*/
// The queue for mpegts over udp to send packets.
// For the aac in mpegts contains many flv packets in a pes packet,
// we must recalc the timestamp.
class SrsMpegtsQueue
{
private:
// key: dts, value: msg.
// The key: dts, value: msg.
std::map<int64_t, SrsSharedPtrMessage*> msgs;
int nb_audios;
int nb_videos;
@ -68,11 +66,8 @@ public:
virtual SrsSharedPtrMessage* dequeue();
};
/**
* the mpegts over udp stream caster.
*/
class SrsMpegtsOverUdp : virtual public ISrsTsHandler
, virtual public ISrsUdpHandler
// The mpegts over udp stream caster.
class SrsMpegtsOverUdp : virtual public ISrsTsHandler, virtual public ISrsUdpHandler
{
private:
SrsTsContext* context;

@ -35,11 +35,9 @@ class SrsRequest;
class SrsPithyPrint;
class SrsProcess;
/**
* the ng-exec is the exec feature introduced by nginx-rtmp,
* @see https://github.com/arut/nginx-rtmp-module/wiki/Directives#exec_push
* @see https://github.com/ossrs/srs/issues/367
*/
// The ng-exec is the exec feature introduced by nginx-rtmp,
// @see https://github.com/arut/nginx-rtmp-module/wiki/Directives#exec_push
// @see https://github.com/ossrs/srs/issues/367
class SrsNgExec : public ISrsCoroutineHandler
{
private:

@ -28,9 +28,7 @@
#include <srs_app_reload.hpp>
/**
* the stage info to calc the age.
*/
// The stage info to calc the age.
class SrsStageInfo : public ISrsReloadHandler
{
public:
@ -50,26 +48,24 @@ public:
virtual srs_error_t on_reload_pithy_print();
};
/**
* the stage is used for a collection of object to do print,
* the print time in a stage is constant and not changed,
* that is, we always got one message to print every specified time.
*
* for example, stage #1 for all play clients, print time is 3s,
* if there is 1client, it will print every 3s.
* if there is 10clients, random select one to print every 3s.
* Usage:
* SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_play();
* SrsAutoFree(SrsPithyPrint, pprint);
* while (true) {
* pprint->elapse();
* if (pprint->can_print()) {
* // print pithy message.
* // user can get the elapse time by: pprint->age()
* }
* // read and write RTMP messages.
* }
*/
// The stage is used for a collection of object to do print,
// the print time in a stage is constant and not changed,
// that is, we always got one message to print every specified time.
//
// For example, stage #1 for all play clients, print time is 3s,
// if there is 1client, it will print every 3s.
// if there is 10clients, random select one to print every 3s.
// Usage:
// SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_play();
// SrsAutoFree(SrsPithyPrint, pprint);
// while (true) {
// pprint->elapse();
// if (pprint->can_print()) {
// // print pithy message.
// // user can get the elapse time by: pprint->age()
// }
// // read and write RTMP messages.
// }
class SrsPithyPrint
{
private:
@ -93,26 +89,16 @@ public:
static SrsPithyPrint* create_http_stream_cache();
virtual ~SrsPithyPrint();
private:
/**
* enter the specified stage, return the client id.
*/
// Enter the specified stage, return the client id.
virtual int enter_stage();
/**
* leave the specified stage, release the client id.
*/
// Leave the specified stage, release the client id.
virtual void leave_stage();
public:
/**
* auto calc the elapse time
*/
// Auto calc the elapse time
virtual void elapse();
/**
* whether current client can print.
*/
// Whether current client can print.
virtual bool can_print();
/**
* get the elapsed time in srs_utime_t.
*/
// Get the elapsed time in srs_utime_t.
virtual srs_utime_t age();
};

@ -29,26 +29,24 @@
#include <string>
#include <vector>
/**
* to start and stop a process, cycle to restart the process when terminated.
* the usage:
* // the binary is the process to fork.
* binary = "./objs/ffmpeg/bin/ffmpeg";
* // where argv is a array contains each params.
* argv = ["./objs/ffmpeg/bin/ffmpeg", "-i", "in.flv", "1", ">", "/dev/null", "2", ">", "/dev/null"];
*
* process = new SrsProcess();
* if ((ret = process->initialize(binary, argv)) != ERROR_SUCCESS) { return ret; }
* if ((ret = process->start()) != ERROR_SUCCESS) { return ret; }
* if ((ret = process->cycle()) != ERROR_SUCCESS) { return ret; }
* process->fast_stop();
* process->stop();
*/
// Start and stop a process. Call cycle to restart the process when terminated.
// The usage:
// // the binary is the process to fork.
// binary = "./objs/ffmpeg/bin/ffmpeg";
// // where argv is a array contains each params.
// argv = ["./objs/ffmpeg/bin/ffmpeg", "-i", "in.flv", "1", ">", "/dev/null", "2", ">", "/dev/null"];
//
// process = new SrsProcess();
// if ((ret = process->initialize(binary, argv)) != ERROR_SUCCESS) { return ret; }
// if ((ret = process->start()) != ERROR_SUCCESS) { return ret; }
// if ((ret = process->cycle()) != ERROR_SUCCESS) { return ret; }
// process->fast_stop();
// process->stop();
class SrsProcess
{
private:
bool is_started;
// whether SIGTERM send but need to wait or SIGKILL.
// Whether SIGTERM send but need to wait or SIGKILL.
bool fast_stopped;
pid_t pid;
private:
@ -56,56 +54,42 @@ private:
std::string stdout_file;
std::string stderr_file;
std::vector<std::string> params;
// the cli to fork process.
// The cli to fork process.
std::string cli;
std::string actual_cli;
public:
SrsProcess();
virtual ~SrsProcess();
public:
/**
* get pid of process.
*/
// Get pid of process.
virtual int get_pid();
/**
* whether process is already started.
*/
// whether process is already started.
virtual bool started();
/**
* initialize the process with binary and argv.
* @param binary the binary path to exec.
* @param argv the argv for binary path, the argv[0] generally is the binary.
* @remark the argv[0] must be the binary.
*/
// Initialize the process with binary and argv.
// @param binary the binary path to exec.
// @param argv the argv for binary path, the argv[0] generally is the binary.
// @remark the argv[0] must be the binary.
virtual srs_error_t initialize(std::string binary, std::vector<std::string> argv);
public:
/**
* start the process, ignore when already started.
*/
// Start the process, ignore when already started.
virtual srs_error_t start();
/**
* cycle check the process, update the state of process.
* @remark when process terminated(not started), user can restart it again by start().
*/
// cycle check the process, update the state of process.
// @remark when process terminated(not started), user can restart it again by start().
virtual srs_error_t cycle();
/**
* send SIGTERM then SIGKILL to ensure the process stopped.
* the stop will wait [0, SRS_PROCESS_QUIT_TIMEOUT_MS] depends on the
* process quit timeout.
* @remark use fast_stop before stop one by one, when got lots of process to quit.
*/
// Send SIGTERM then SIGKILL to ensure the process stopped.
// the stop will wait [0, SRS_PROCESS_QUIT_TIMEOUT_MS] depends on the
// process quit timeout.
// @remark use fast_stop before stop one by one, when got lots of process to quit.
virtual void stop();
public:
/**
* the fast stop is to send a SIGTERM.
* for example, the ingesters owner lots of FFMPEG, it will take a long time
* to stop one by one, instead the ingesters can fast_stop all FFMPEG, then
* wait one by one to stop, it's more faster.
* @remark user must use stop() to ensure the ffmpeg to stopped.
* @remark we got N processes to stop, compare the time we spend,
* when use stop without fast_stop, we spend maybe [0, SRS_PROCESS_QUIT_TIMEOUT_MS * N]
* but use fast_stop then stop, the time is almost [0, SRS_PROCESS_QUIT_TIMEOUT_MS].
*/
// The fast stop is to send a SIGTERM.
// for example, the ingesters owner lots of FFMPEG, it will take a long time
// to stop one by one, instead the ingesters can fast_stop all FFMPEG, then
// wait one by one to stop, it's more faster.
// @remark user must use stop() to ensure the ffmpeg to stopped.
// @remark we got N processes to stop, compare the time we spend,
// when use stop without fast_stop, we spend maybe [0, SRS_PROCESS_QUIT_TIMEOUT_MS * N]
// but use fast_stop then stop, the time is almost [0, SRS_PROCESS_QUIT_TIMEOUT_MS].
virtual void fast_stop();
};

@ -42,54 +42,38 @@ class SrsConsumer;
class SrsHttpConn;
class SrsResponseOnlyHttpConn;
/**
* The message consumer which consume a message.
*/
// The message consumer which consume a message.
class ISrsMessageConsumer
{
public:
ISrsMessageConsumer();
virtual ~ISrsMessageConsumer();
public:
/**
* Consume the received message.
* @remark user must free this message.
*/
// Consume the received message.
// @remark user must free this message.
virtual srs_error_t consume(SrsCommonMessage* msg) = 0;
};
/**
* The message pumper to pump messages to processer.
*/
// The message pumper to pump messages to processer.
class ISrsMessagePumper : public ISrsMessageConsumer
{
public:
ISrsMessagePumper();
virtual ~ISrsMessagePumper();
public:
/**
* Whether the pumper is interrupted.
* For example, when pumpter is busy, it's interrupted,
* please wait for a while then try to feed the pumper.
*/
// Whether the pumper is interrupted.
// For example, when pumpter is busy, it's interrupted,
// please wait for a while then try to feed the pumper.
virtual bool interrupted() = 0;
/**
* Interrupt the pumper for a error.
*/
// Interrupt the pumper for a error.
virtual void interrupt(srs_error_t error) = 0;
/**
* When start the pumper.
*/
// When start the pumper.
virtual void on_start() = 0;
/**
* When stop the pumper.
*/
// When stop the pumper.
virtual void on_stop() = 0;
};
/**
* the recv thread, use message handler to handle each received message.
*/
// The recv thread, use message handler to handle each received message.
class SrsRecvThread : public ISrsCoroutineHandler
{
protected:
@ -117,19 +101,17 @@ private:
virtual srs_error_t do_cycle();
};
/**
* the recv thread used to replace the timeout recv,
* which hurt performance for the epoll_ctrl is frequently used.
* @see: SrsRtmpConn::playing
* @see: https://github.com/ossrs/srs/issues/217
*/
// The recv thread used to replace the timeout recv,
// which hurt performance for the epoll_ctrl is frequently used.
// @see: SrsRtmpConn::playing
// @see: https://github.com/ossrs/srs/issues/217
class SrsQueueRecvThread : public ISrsMessagePumper
{
private:
std::vector<SrsCommonMessage*> queue;
SrsRecvThread trd;
SrsRtmpServer* rtmp;
// the recv thread error code.
// The recv thread error code.
srs_error_t recv_error;
SrsConsumer* _consumer;
public:
@ -153,10 +135,8 @@ public:
virtual void on_stop();
};
/**
* the publish recv thread got message and callback the source method to process message.
* @see: https://github.com/ossrs/srs/issues/237
*/
// The publish recv thread got message and callback the source method to process message.
// @see: https://github.com/ossrs/srs/issues/237
class SrsPublishRecvThread : virtual public ISrsMessagePumper, virtual public ISrsReloadHandler
#ifdef SRS_PERF_MERGED_READ
, virtual public IMergeReadHandler
@ -166,27 +146,27 @@ private:
SrsRecvThread trd;
SrsRtmpServer* rtmp;
SrsRequest* req;
// the msgs already got.
// The msgs already got.
int64_t _nb_msgs;
// The video frames we got.
uint64_t video_frames;
// for mr(merged read),
// For mr(merged read),
// @see https://github.com/ossrs/srs/issues/241
bool mr;
int mr_fd;
srs_utime_t mr_sleep;
// for realtime
// For realtime
// @see https://github.com/ossrs/srs/issues/257
bool realtime;
// the recv thread error code.
// The recv thread error code.
srs_error_t recv_error;
SrsRtmpConn* _conn;
// the params for conn callback.
// The params for conn callback.
SrsSource* _source;
// the error timeout cond
// The error timeout cond
// @see https://github.com/ossrs/srs/issues/244
srs_cond_t error;
// merged context id.
// The merged context id.
int cid;
int ncid;
public:
@ -194,9 +174,7 @@ public:
int mr_sock_fd, srs_utime_t tm, SrsRtmpConn* conn, SrsSource* source, int parent_cid);
virtual ~SrsPublishRecvThread();
public:
/**
* wait for error for some timeout.
*/
// Wait for error for some timeout.
virtual srs_error_t wait(srs_utime_t tm);
virtual int64_t nb_msgs();
virtual uint64_t nb_video_frames();
@ -226,12 +204,10 @@ private:
virtual void set_socket_buffer(srs_utime_t sleep_v);
};
/**
* The HTTP receive thread, try to read messages util EOF.
* For example, the HTTP FLV serving thread will use the receive thread to break
* when client closed the request, to avoid FD leak.
* @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427
*/
// The HTTP receive thread, try to read messages util EOF.
// For example, the HTTP FLV serving thread will use the receive thread to break
// when client closed the request, to avoid FD leak.
// @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427
class SrsHttpRecvThread : public ISrsCoroutineHandler
{
private:

@ -36,11 +36,9 @@ public:
SrsRefer();
virtual ~SrsRefer();
public:
/**
* to check the refer.
* @param page_url the client page url.
* @param refer the refer in config.
*/
// Check the refer.
// @param page_url the client page url.
// @param refer the refer in config.
virtual srs_error_t check(std::string page_url, SrsConfDirective* refer);
private:
virtual srs_error_t check_single_refer(std::string page_url, std::string refer);

@ -28,13 +28,11 @@
#include <string>
/**
* the handler for config reload.
* when reload callback, the config is updated yet.
*
* features not support reload,
* @see: https://github.com/ossrs/srs/wiki/v1_CN_Reload#notsupportedfeatures
*/
// The handler for config reload.
// When reload callback, the config is updated yet.
//
// Features not support reload,
// @see: https://github.com/ossrs/srs/wiki/v1_CN_Reload#notsupportedfeatures
class ISrsReloadHandler
{
public:

@ -58,9 +58,7 @@ class SrsPacket;
class ISrsKafkaCluster;
#endif
/**
* The simple rtmp client for SRS.
*/
// The simple rtmp client for SRS.
class SrsSimpleRtmpClient : public SrsBasicRtmpClient
{
public:
@ -70,9 +68,7 @@ protected:
virtual srs_error_t connect_app();
};
/**
* Some information of client.
*/
// Some information of client.
class SrsClientInfo
{
public:
@ -89,12 +85,10 @@ public:
virtual ~SrsClientInfo();
};
/**
* the client provides the main logic control for RTMP clients.
*/
// The client provides the main logic control for RTMP clients.
class SrsRtmpConn : virtual public SrsConnection, virtual public ISrsReloadHandler
{
// for the thread to directly access any field of connection.
// For the thread to directly access any field of connection.
friend class SrsPublishRecvThread;
private:
SrsServer* server;
@ -102,27 +96,27 @@ private:
SrsRefer* refer;
SrsBandwidth* bandwidth;
SrsSecurity* security;
// the wakable handler, maybe NULL.
// The wakable handler, maybe NULL.
// TODO: FIXME: Should refine the state for receiving thread.
ISrsWakable* wakable;
// elapse duration in srs_utime_t
// for live play duration, for instance, rtmpdump to record.
// The elapsed duration in srs_utime_t
// For live play duration, for instance, rtmpdump to record.
// @see https://github.com/ossrs/srs/issues/47
srs_utime_t duration;
// the MR(merged-write) sleep time in srs_utime_t.
// The MR(merged-write) sleep time in srs_utime_t.
srs_utime_t mw_sleep;
// the MR(merged-write) only enabled for play.
// The MR(merged-write) only enabled for play.
int mw_enabled;
// for realtime
// For realtime
// @see https://github.com/ossrs/srs/issues/257
bool realtime;
// the minimal interval in srs_utime_t for delivery stream.
// The minimal interval in srs_utime_t for delivery stream.
srs_utime_t send_min_interval;
// publish 1st packet timeout in srs_utime_t
// The publish 1st packet timeout in srs_utime_t
srs_utime_t publish_1stpkt_timeout;
// publish normal packet timeout in srs_utime_t
// The publish normal packet timeout in srs_utime_t
srs_utime_t publish_normal_timeout;
// whether enable the tcp_nodelay.
// Whether enable the tcp_nodelay.
bool tcp_nodelay;
// About the rtmp client.
SrsClientInfo* info;
@ -144,9 +138,9 @@ public:
public:
virtual void remark(int64_t* in, int64_t* out);
private:
// when valid and connected to vhost/app, service the client.
// When valid and connected to vhost/app, service the client.
virtual srs_error_t service_cycle();
// stream(play/publish) service cycle, identify client first.
// The stream(play/publish) service cycle, identify client first.
virtual srs_error_t stream_service_cycle();
virtual srs_error_t check_vhost(bool try_default_vhost);
virtual srs_error_t playing(SrsSource* source);
@ -164,10 +158,8 @@ private:
virtual srs_error_t check_edge_token_traverse_auth();
virtual srs_error_t do_token_traverse_auth(SrsRtmpClient* client);
private:
/**
* when the connection disconnect, call this method.
* e.g. log msg of connection and report to other system.
*/
// When the connection disconnect, call this method.
// e.g. log msg of connection and report to other system.
virtual srs_error_t on_disconnect();
private:
virtual srs_error_t http_hooks_on_connect();

@ -52,9 +52,7 @@ class SrsSimpleStream;
class SrsPithyPrint;
class SrsSimpleRtmpClient;
/**
* a rtp connection which transport a stream.
*/
// A rtp connection which transport a stream.
class SrsRtpConn: public ISrsUdpHandler
{
private:
@ -75,9 +73,7 @@ public:
virtual srs_error_t on_udp_packet(const sockaddr* from, const int fromlen, char* buf, int nb_buf);
};
/**
* audio is group by frames.
*/
// The audio cache, audio is grouped by frames.
struct SrsRtspAudioCache
{
int64_t dts;
@ -88,9 +84,7 @@ struct SrsRtspAudioCache
virtual ~SrsRtspAudioCache();
};
/**
* the time jitter correct for rtsp.
*/
// The time jitter correct for rtsp.
class SrsRtspJitter
{
private:
@ -105,9 +99,7 @@ public:
virtual srs_error_t correct(int64_t& ts);
};
/**
* the rtsp connection serve the fd.
*/
// The rtsp connection serve the fd.
class SrsRtspConn : public ISrsCoroutineHandler
{
private:
@ -176,16 +168,14 @@ private:
virtual void close();
};
/**
* the caster for rtsp.
*/
// The caster for rtsp.
class SrsRtspCaster : public ISrsTcpHandler
{
private:
std::string output;
int local_port_min;
int local_port_max;
// key: port, value: whether used.
// The key: port, value: whether used.
std::map<int, bool> used_ports;
private:
std::vector<SrsRtspConn*> clients;
@ -193,19 +183,15 @@ public:
SrsRtspCaster(SrsConfDirective* c);
virtual ~SrsRtspCaster();
public:
/**
* alloc a rtp port from local ports pool.
* @param pport output the rtp port.
*/
// Alloc a rtp port from local ports pool.
// @param pport output the rtp port.
virtual srs_error_t alloc_port(int* pport);
/**
* free the alloced rtp port.
*/
// Free the alloced rtp port.
virtual void free_port(int lpmin, int lpmax);
// interface ISrsTcpHandler
public:
virtual srs_error_t on_tcp_client(srs_netfd_t stfd);
// internal methods.
// internal methods.
public:
virtual void remove(SrsRtspConn* conn);
};

@ -32,33 +32,25 @@
class SrsConfDirective;
/**
* the security apply on vhost.
* @see https://github.com/ossrs/srs/issues/211
*/
// The security apply on vhost.
// @see https://github.com/ossrs/srs/issues/211
class SrsSecurity
{
public:
SrsSecurity();
virtual ~SrsSecurity();
public:
/**
* security check the client apply by vhost security strategy
* @param type the client type, publish or play.
* @param ip the ip address of client.
* @param req the request object of client.
*/
// Security check the client apply by vhost security strategy
// @param type the client type, publish or play.
// @param ip the ip address of client.
// @param req the request object of client.
virtual srs_error_t check(SrsRtmpConnType type, std::string ip, SrsRequest* req);
private:
/**
* security check the allow,
* @return, if allowed, ERROR_SYSTEM_SECURITY_ALLOW.
*/
// Security check the allow,
// @return, if allowed, ERROR_SYSTEM_SECURITY_ALLOW.
virtual int allow_check(SrsConfDirective* rules, SrsRtmpConnType type, std::string ip);
/**
* security check the deny,
* @return, if denied, ERROR_SYSTEM_SECURITY_DENY.
*/
// Security check the deny,
// @return, if denied, ERROR_SYSTEM_SECURITY_DENY.
virtual int deny_check(SrsConfDirective* rules, SrsRtmpConnType type, std::string ip);
};

@ -31,49 +31,43 @@
#include <srs_service_st.hpp>
#include <srs_protocol_io.hpp>
/**
* Each ST-coroutine must implements this interface,
* to do the cycle job and handle some events.
*
* Thread do a job then terminated normally, it's a SrsOneCycleThread:
* class SrsOneCycleThread : public ISrsCoroutineHandler {
* public: SrsCoroutine trd;
* public: virtual srs_error_t cycle() {
* // Do something, then return this cycle and thread terminated normally.
* }
* };
*
* Thread has its inside loop, such as the RTMP receive thread:
* class SrsReceiveThread : public ISrsCoroutineHandler {
* public: SrsCoroutine* trd;
* public: virtual srs_error_t cycle() {
* while (true) {
* // Check whether thread interrupted.
* if ((err = trd->pull()) != srs_success) {
* return err;
* }
* // Do something, such as st_read() packets, it'll be wakeup
* // when user stop or interrupt the thread.
* }
* }
* };
*/
// Each ST-coroutine must implements this interface,
// to do the cycle job and handle some events.
//
// Thread do a job then terminated normally, it's a SrsOneCycleThread:
// class SrsOneCycleThread : public ISrsCoroutineHandler {
// public: SrsCoroutine trd;
// public: virtual srs_error_t cycle() {
// // Do something, then return this cycle and thread terminated normally.
// }
// };
//
// Thread has its inside loop, such as the RTMP receive thread:
// class SrsReceiveThread : public ISrsCoroutineHandler {
// public: SrsCoroutine* trd;
// public: virtual srs_error_t cycle() {
// while (true) {
// // Check whether thread interrupted.
// if ((err = trd->pull()) != srs_success) {
// return err;
// }
// // Do something, such as st_read() packets, it'll be wakeup
// // when user stop or interrupt the thread.
// }
// }
// };
class ISrsCoroutineHandler
{
public:
ISrsCoroutineHandler();
virtual ~ISrsCoroutineHandler();
public:
/**
* Do the work. The ST-coroutine will terminated normally if it returned.
* @remark If the cycle has its own loop, it must check the thread pull.
*/
// Do the work. The ST-coroutine will terminated normally if it returned.
// @remark If the cycle has its own loop, it must check the thread pull.
virtual srs_error_t cycle() = 0;
};
/**
* The corotine object.
*/
// The corotine object.
class SrsCoroutine
{
public:
@ -89,10 +83,8 @@ public:
virtual int cid() = 0;
};
/**
* An empty coroutine, user can default to this object before create any real coroutine.
* @see https://github.com/ossrs/srs/pull/908
*/
// An empty coroutine, user can default to this object before create any real coroutine.
// @see https://github.com/ossrs/srs/pull/908
class SrsDummyCoroutine : public SrsCoroutine
{
public:
@ -110,20 +102,18 @@ public:
typedef void* (*_ST_THREAD_CREATE_PFN)(void *(*start)(void *arg), void *arg, int joinable, int stack_size);
extern _ST_THREAD_CREATE_PFN _pfn_st_thread_create;
/**
* A ST-coroutine is a lightweight thread, just like the goroutine.
* But the goroutine maybe run on different thread, while ST-coroutine only
* run in single thread, because it use setjmp and longjmp, so it may cause
* problem in multiple threads. For SRS, we only use single thread module,
* like NGINX to get very high performance, with asynchronous and non-blocking
* sockets.
* @reamrk For multiple processes, please use go-oryx to fork many SRS processes.
* Please read https://github.com/ossrs/go-oryx
* @remark For debugging of ST-coroutine, read _st_iterate_threads_flag of ST/README
* https://github.com/ossrs/state-threads/blob/st-1.9/README#L115
* @remark We always create joinable thread, so we must join it or memory leak,
* Please read https://github.com/ossrs/srs/issues/78
*/
// A ST-coroutine is a lightweight thread, just like the goroutine.
// But the goroutine maybe run on different thread, while ST-coroutine only
// run in single thread, because it use setjmp and longjmp, so it may cause
// problem in multiple threads. For SRS, we only use single thread module,
// like NGINX to get very high performance, with asynchronous and non-blocking
// sockets.
// @reamrk For multiple processes, please use go-oryx to fork many SRS processes.
// Please read https://github.com/ossrs/go-oryx
// @remark For debugging of ST-coroutine, read _st_iterate_threads_flag of ST/README
// https://github.com/ossrs/state-threads/blob/st-1.9/README#L115
// @remark We always create joinable thread, so we must join it or memory leak,
// Please read https://github.com/ossrs/srs/issues/78
class SrsSTCoroutine : public SrsCoroutine
{
private:
@ -145,35 +135,25 @@ public:
SrsSTCoroutine(const std::string& n, ISrsCoroutineHandler* h, int cid = 0);
virtual ~SrsSTCoroutine();
public:
/**
* Start the thread.
* @remark Should never start it when stopped or terminated.
*/
// Start the thread.
// @remark Should never start it when stopped or terminated.
virtual srs_error_t start();
/**
* Interrupt the thread then wait to terminated.
* @remark If user want to notify thread to quit async, for example if there are
* many threads to stop like the encoder, use the interrupt to notify all threads
* to terminate then use stop to wait for each to terminate.
*/
// Interrupt the thread then wait to terminated.
// @remark If user want to notify thread to quit async, for example if there are
// many threads to stop like the encoder, use the interrupt to notify all threads
// to terminate then use stop to wait for each to terminate.
virtual void stop();
/**
* Interrupt the thread and notify it to terminate, it will be wakeup if it's blocked
* in some IO operations, such as st_read or st_write, then it will found should quit,
* finally the thread should terminated normally, user can use the stop to join it.
*/
// Interrupt the thread and notify it to terminate, it will be wakeup if it's blocked
// in some IO operations, such as st_read or st_write, then it will found should quit,
// finally the thread should terminated normally, user can use the stop to join it.
virtual void interrupt();
/**
* Check whether thread is terminated normally or error(stopped or termianted with error),
* and the thread should be running if it return ERROR_SUCCESS.
* @remark Return specified error when thread terminated normally with error.
* @remark Return ERROR_THREAD_TERMINATED when thread terminated normally without error.
* @remark Return ERROR_THREAD_INTERRUPED when thread is interrupted.
*/
// Check whether thread is terminated normally or error(stopped or termianted with error),
// and the thread should be running if it return ERROR_SUCCESS.
// @remark Return specified error when thread terminated normally with error.
// @remark Return ERROR_THREAD_TERMINATED when thread terminated normally without error.
// @remark Return ERROR_THREAD_INTERRUPED when thread is interrupted.
virtual srs_error_t pull();
/**
* Get the context id of thread.
*/
// Get the context id of thread.
virtual int cid();
private:
virtual srs_error_t cycle();

Loading…
Cancel
Save