1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for #742, refine source, meta and origin hub. 3.0.16

This commit is contained in:
winlin 2017-01-19 12:38:55 +08:00
parent 6209945a07
commit 4cff49afd2
10 changed files with 1000 additions and 728 deletions

View file

@ -184,6 +184,7 @@ Please select your language:
### V3 changes ### V3 changes
* v3.0, 2017-01-19, for [#742][bug #742] refine source, meta and origin hub. 3.0.16
* v3.0, 2017-01-17, for [#742][bug #742] refine source, timeout, live cycle. 3.0.15 * v3.0, 2017-01-17, for [#742][bug #742] refine source, timeout, live cycle. 3.0.15
* v3.0, 2017-01-11, fix [#735][bug #735] config transform refer_publish invalid. 3.0.14 * v3.0, 2017-01-11, fix [#735][bug #735] config transform refer_publish invalid. 3.0.14
* v3.0, 2017-01-06, for [#730][bug #730] support config in/out ack size. 3.0.13 * v3.0, 2017-01-06, for [#730][bug #730] support config in/out ack size. 3.0.13
@ -872,13 +873,13 @@ Remark:
| Input | SRS(Simple RTMP Server) | Output | | Input | SRS(Simple RTMP Server) | Output |
+----------------------+-------------------------+----------------+ +----------------------+-------------------------+----------------+
| Encoder(1) | +-> RTMP/HDS --------+-> Flash player | | Encoder(1) | +-> RTMP/HDS --------+-> Flash player |
| (FMLE,FFMPEG, -rtmp-+->-+-> HLS/HTTP ---------+-> M3u8 player | | (FMLE,FFMPEG, -rtmp-+->-+-> HLS/HTTP ---------+-> M3U8 player |
| Flash,XSPLIT, | +-> FLV/MP3/Aac/Ts ---+-> HTTP player | | Flash,XSPLIT, | +-> FLV/MP3/Aac/Ts ---+-> HTTP player |
| ......) | +-> Fowarder ---------+-> RTMP server | | ......) | +-> Fowarder ---------+-> RTMP server |
| | +-> Transcoder -------+-> RTMP server | | | +-> Transcoder -------+-> RTMP server |
| | +-> EXEC(5) ----------+-> External app | | | +-> EXEC(5) ----------+-> External app |
| | +-> DVR --------------+-> Flv file | | | +-> DVR --------------+-> FLV file |
| | +-> BandwidthTest ----+-> flash | | | +-> BandwidthTest ----+-> Flash |
+----------------------+ | | +----------------------+ | |
| MediaSource(2) | | | | MediaSource(2) | | |
| (RTSP,FILE, | | | | (RTSP,FILE, | | |

View file

@ -970,7 +970,7 @@ int SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg)
SrsDvr::SrsDvr() SrsDvr::SrsDvr()
{ {
source = NULL; hub = NULL;
plan = NULL; plan = NULL;
req = NULL; req = NULL;
actived = false; actived = false;
@ -985,12 +985,12 @@ SrsDvr::~SrsDvr()
srs_freep(plan); srs_freep(plan);
} }
int SrsDvr::initialize(SrsSource* s, SrsRequest* r) int SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
req = r; req = r;
source = s; hub = h;
SrsConfDirective* conf = _srs_config->get_dvr_apply(r->vhost); SrsConfDirective* conf = _srs_config->get_dvr_apply(r->vhost);
actived = srs_config_apply_filter(conf, r); actived = srs_config_apply_filter(conf, r);
@ -1018,7 +1018,7 @@ int SrsDvr::on_publish(bool fetch_sequence_header)
return ret; return ret;
} }
if (fetch_sequence_header && (ret = source->on_dvr_request_sh()) != ERROR_SUCCESS) { if (fetch_sequence_header && (ret = hub->on_dvr_request_sh()) != ERROR_SUCCESS) {
return ret; return ret;
} }

View file

@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef SRS_AUTO_DVR #ifdef SRS_AUTO_DVR
class SrsSource; class SrsSource;
class SrsOriginHub;
class SrsRequest; class SrsRequest;
class SrsBuffer; class SrsBuffer;
class SrsRtmpJitter; class SrsRtmpJitter;
@ -300,7 +301,7 @@ private:
class SrsDvr : public ISrsReloadHandler class SrsDvr : public ISrsReloadHandler
{ {
private: private:
SrsSource* source; SrsOriginHub* hub;
SrsDvrPlan* plan; SrsDvrPlan* plan;
SrsRequest* req; SrsRequest* req;
private: private:
@ -317,7 +318,7 @@ public:
* when system initialize(encoder publish at first time, or reload), * when system initialize(encoder publish at first time, or reload),
* initialize the dvr will reinitialize the plan, the whole dvr framework. * initialize the dvr will reinitialize the plan, the whole dvr framework.
*/ */
virtual int initialize(SrsSource* s, SrsRequest* r); virtual int initialize(SrsOriginHub* h, SrsRequest* r);
/** /**
* publish stream event, * publish stream event,
* when encoder start to publish RTMP stream. * when encoder start to publish RTMP stream.

View file

@ -50,9 +50,9 @@ using namespace std;
// when error, forwarder sleep for a while and retry. // when error, forwarder sleep for a while and retry.
#define SRS_FORWARDER_CIMS (3000) #define SRS_FORWARDER_CIMS (3000)
SrsForwarder::SrsForwarder(SrsSource* s) SrsForwarder::SrsForwarder(SrsOriginHub* h)
{ {
source = s; hub = h;
req = NULL; req = NULL;
sh_video = sh_audio = NULL; sh_video = sh_audio = NULL;
@ -250,7 +250,7 @@ int SrsForwarder::cycle()
return ret; return ret;
} }
if ((ret = source->on_forwarder_start(this)) != ERROR_SUCCESS) { if ((ret = hub->on_forwarder_start(this)) != ERROR_SUCCESS) {
srs_error("callback the source to feed the sequence header failed. ret=%d", ret); srs_error("callback the source to feed the sequence header failed. ret=%d", ret);
return ret; return ret;
} }

View file

@ -42,6 +42,7 @@ class SrsRtmpJitter;
class SrsRtmpClient; class SrsRtmpClient;
class SrsRequest; class SrsRequest;
class SrsSource; class SrsSource;
class SrsOriginHub;
class SrsKbps; class SrsKbps;
class SrsSimpleRtmpClient; class SrsSimpleRtmpClient;
@ -58,7 +59,7 @@ private:
private: private:
SrsReusableThread2* pthread; SrsReusableThread2* pthread;
private: private:
SrsSource* source; SrsOriginHub* hub;
SrsSimpleRtmpClient* sdk; SrsSimpleRtmpClient* sdk;
SrsRtmpJitter* jitter; SrsRtmpJitter* jitter;
SrsMessageQueue* queue; SrsMessageQueue* queue;
@ -69,7 +70,7 @@ private:
SrsSharedPtrMessage* sh_audio; SrsSharedPtrMessage* sh_audio;
SrsSharedPtrMessage* sh_video; SrsSharedPtrMessage* sh_video;
public: public:
SrsForwarder(SrsSource* _source); SrsForwarder(SrsOriginHub* h);
virtual ~SrsForwarder(); virtual ~SrsForwarder();
public: public:
virtual int initialize(SrsRequest* r, std::string ep); virtual int initialize(SrsRequest* r, std::string ep);

View file

@ -1125,7 +1125,7 @@ int SrsHlsCache::reap_segment(string log_desc, SrsHlsMuxer* muxer, int64_t segme
SrsHls::SrsHls() SrsHls::SrsHls()
{ {
req = NULL; req = NULL;
source = NULL; hub = NULL;
hls_enabled = false; hls_enabled = false;
hls_can_dispose = false; hls_can_dispose = false;
@ -1197,11 +1197,11 @@ int SrsHls::cycle()
return ret; return ret;
} }
int SrsHls::initialize(SrsSource* s, SrsRequest* r) int SrsHls::initialize(SrsOriginHub* h, SrsRequest* r)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
source = s; hub = h;
req = r; req = r;
if ((ret = muxer->initialize()) != ERROR_SUCCESS) { if ((ret = muxer->initialize()) != ERROR_SUCCESS) {
@ -1244,7 +1244,7 @@ int SrsHls::on_publish(bool fetch_sequence_header)
// notice the source to get the cached sequence header. // notice the source to get the cached sequence header.
// when reload to start hls, hls will never get the sequence header in stream, // when reload to start hls, hls will never get the sequence header in stream,
// use the SrsSource.on_hls_start to push the sequence header to HLS. // use the SrsSource.on_hls_start to push the sequence header to HLS.
if ((ret = source->on_hls_start()) != ERROR_SUCCESS) { if ((ret = hub->on_hls_start()) != ERROR_SUCCESS) {
srs_error("callback source hls start failed. ret=%d", ret); srs_error("callback source hls start failed. ret=%d", ret);
return ret; return ret;
} }

View file

@ -45,6 +45,7 @@ class SrsAvcAacCodec;
class SrsRequest; class SrsRequest;
class SrsPithyPrint; class SrsPithyPrint;
class SrsSource; class SrsSource;
class SrsOriginHub;
class SrsFileWriter; class SrsFileWriter;
class SrsSimpleStream; class SrsSimpleStream;
class SrsTsAacJitter; class SrsTsAacJitter;
@ -362,7 +363,7 @@ private:
bool hls_can_dispose; bool hls_can_dispose;
int64_t last_update_time; int64_t last_update_time;
private: private:
SrsSource* source; SrsOriginHub* hub;
SrsAvcAacCodec* codec; SrsAvcAacCodec* codec;
SrsCodecSample* sample; SrsCodecSample* sample;
SrsRtmpJitter* jitter; SrsRtmpJitter* jitter;
@ -391,7 +392,7 @@ public:
/** /**
* initialize the hls by handler and source. * initialize the hls by handler and source.
*/ */
virtual int initialize(SrsSource* s, SrsRequest* r); virtual int initialize(SrsOriginHub* h, SrsRequest* r);
/** /**
* publish stream event, continue to write the m3u8, * publish stream event, continue to write the m3u8,
* for the muxer object not destroyed. * for the muxer object not destroyed.

File diff suppressed because it is too large Load diff

View file

@ -53,6 +53,7 @@ class SrsEdgeProxyContext;
class SrsMessageArray; class SrsMessageArray;
class SrsNgExec; class SrsNgExec;
class SrsConnection; class SrsConnection;
class SrsMessageHeader;
#ifdef SRS_AUTO_HLS #ifdef SRS_AUTO_HLS
class SrsHls; class SrsHls;
#endif #endif
@ -410,11 +411,129 @@ public:
virtual SrsSharedPtrMessage* pop(); 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.
*/
class SrsOriginHub : public ISrsReloadHandler
{
private:
SrsSource* source;
SrsRequest* req;
private:
// hls handler.
#ifdef SRS_AUTO_HLS
SrsHls* hls;
#endif
// dvr handler.
#ifdef SRS_AUTO_DVR
SrsDvr* dvr;
#endif
// transcoding handler.
#ifdef SRS_AUTO_TRANSCODE
SrsEncoder* encoder;
#endif
#ifdef SRS_AUTO_HDS
// adobe hds(http dynamic streaming).
SrsHds *hds;
#endif
// nginx-rtmp exec feature.
SrsNgExec* ng_exec;
// to forward stream to other servers
std::vector<SrsForwarder*> forwarders;
public:
SrsOriginHub(SrsSource* s);
virtual ~SrsOriginHub();
public:
// Initialize the hub with source and request.
// @param r The request object, managed by source.
virtual int initialize(SrsRequest* r);
// Dispose the hub, release utilities resource,
// for example, delete all HLS pieces.
virtual void dispose();
// Cycle the hub, process some regular events,
// for example, dispose hls in cycle.
virtual int cycle();
public:
// When got a original metadata.
virtual int on_original_metadata(SrsOnMetaDataPacket* metadata);
// When got a parsed metadata.
virtual int on_meta_data(SrsSharedPtrMessage* shared_metadata);
// When got a parsed audio packet.
virtual int on_audio(SrsSharedPtrMessage* shared_audio);
// When got a parsed video packet.
virtual int on_video(SrsSharedPtrMessage* shared_video, bool is_sequence_header);
public:
// When start publish stream.
virtual int on_publish();
// When stop publish stream.
virtual void on_unpublish();
// for the tools callback
public:
// for the SrsForwarder to callback to request the sequence headers.
virtual int on_forwarder_start(SrsForwarder* forwarder);
// for the SrsHls to callback to request the sequence headers.
virtual int on_hls_start();
// for the SrsDvr to callback to request the sequence headers.
virtual int on_dvr_request_sh();
// interface ISrsReloadHandler
public:
virtual int on_reload_vhost_forward(std::string vhost);
virtual int on_reload_vhost_hls(std::string vhost);
virtual int on_reload_vhost_hds(std::string vhost);
virtual int on_reload_vhost_dvr(std::string vhost);
virtual int on_reload_vhost_transcode(std::string vhost);
virtual int on_reload_vhost_exec(std::string vhost);
private:
virtual int create_forwarders();
virtual void destroy_forwarders();
};
/**
* Each stream have optional meta(sps/pps in sequence header and metadata).
* This class cache and update the meta.
*/
class SrsMetaCache
{
private:
SrsSharedPtrMessage* cache_metadata;
// the cached video sequence header.
SrsSharedPtrMessage* cache_sh_video;
// the cached audio sequence header.
SrsSharedPtrMessage* cache_sh_audio;
public:
SrsMetaCache();
virtual ~SrsMetaCache();
public:
// Dispose the metadata cache.
virtual void dispose();
public:
// Get the cached metadata.
virtual SrsSharedPtrMessage* data();
// Get the cached vsh(video sequence header).
virtual SrsSharedPtrMessage* vsh();
// Get the cached ash(audio sequence header).
virtual SrsSharedPtrMessage* ash();
// Dumps cached metadata to consumer.
// @param dm Whether dumps the metadata.
// @param ds Whether dumps the sequence header.
virtual int dumps(SrsConsumer* consumer, bool atc, SrsRtmpJitterAlgorithm ag, bool dm, bool ds);
public:
// Update the cached metadata by packet.
virtual int update_data(SrsMessageHeader* header, SrsOnMetaDataPacket* metadata, bool& updated);
// Update the cached audio sequence header.
virtual void update_ash(SrsSharedPtrMessage* msg);
// Update the cached video sequence header.
virtual void update_vsh(SrsSharedPtrMessage* msg);
};
/** /**
* live streaming source. * live streaming source.
*/ */
class SrsSource : public ISrsReloadHandler class SrsSource : public ISrsReloadHandler
{ {
friend class SrsOriginHub;
private: private:
static std::map<std::string, SrsSource*> pool; static std::map<std::string, SrsSource*> pool;
public: public:
@ -475,35 +594,19 @@ private:
bool 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; int64_t last_packet_time;
// hls handler. // for aggregate message
#ifdef SRS_AUTO_HLS SrsBuffer* aggregate_stream;
SrsHls* hls; // the event handler.
#endif ISrsSourceHandler* handler;
// dvr handler.
#ifdef SRS_AUTO_DVR
SrsDvr* dvr;
#endif
// transcoding handler.
#ifdef SRS_AUTO_TRANSCODE
SrsEncoder* encoder;
#endif
#ifdef SRS_AUTO_HDS
// adobe hds(http dynamic streaming).
SrsHds *hds;
#endif
// nginx-rtmp exec feature.
SrsNgExec* ng_exec;
// edge control service // edge control service
SrsPlayEdge* play_edge; SrsPlayEdge* play_edge;
SrsPublishEdge* publish_edge; SrsPublishEdge* publish_edge;
// gop cache for client fast startup. // gop cache for client fast startup.
SrsGopCache* gop_cache; SrsGopCache* gop_cache;
// to forward stream to other servers // The hub for origin server.
std::vector<SrsForwarder*> forwarders; SrsOriginHub* hub;
// for aggregate message // The metadata cache.
SrsBuffer* aggregate_stream; SrsMetaCache* meta;
// the event handler.
ISrsSourceHandler* handler;
private: private:
/** /**
* can publish, true when is not streaming * can publish, true when is not streaming
@ -512,12 +615,6 @@ private:
// last die time, when all consumers quit and no publisher, // 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.
int64_t die_at; int64_t die_at;
private:
SrsSharedPtrMessage* cache_metadata;
// the cached video sequence header.
SrsSharedPtrMessage* cache_sh_video;
// the cached audio sequence header.
SrsSharedPtrMessage* cache_sh_audio;
public: public:
SrsSource(); SrsSource();
virtual ~SrsSource(); virtual ~SrsSource();
@ -535,20 +632,8 @@ public:
// interface ISrsReloadHandler // interface ISrsReloadHandler
public: public:
virtual int on_reload_vhost_play(std::string vhost); virtual int on_reload_vhost_play(std::string vhost);
virtual int on_reload_vhost_forward(std::string vhost);
virtual int on_reload_vhost_hls(std::string vhost);
virtual int on_reload_vhost_hds(std::string vhost);
virtual int on_reload_vhost_dvr(std::string vhost);
virtual int on_reload_vhost_transcode(std::string vhost);
virtual int on_reload_vhost_exec(std::string vhost);
// for the tools callback // for the tools callback
public: public:
// for the SrsForwarder to callback to request the sequence headers.
virtual int on_forwarder_start(SrsForwarder* forwarder);
// for the SrsHls to callback to request the sequence headers.
virtual int on_hls_start();
// for the SrsDvr to callback to request the sequence headers.
virtual int on_dvr_request_sh();
// source id changed. // source id changed.
virtual int on_source_id_changed(int id); virtual int on_source_id_changed(int id);
// get current source id. // get current source id.
@ -599,9 +684,6 @@ public:
virtual int on_edge_proxy_publish(SrsCommonMessage* msg); virtual int on_edge_proxy_publish(SrsCommonMessage* msg);
// for edge, proxy stop publish // for edge, proxy stop publish
virtual void on_edge_proxy_unpublish(); virtual void on_edge_proxy_unpublish();
private:
virtual int create_forwarders();
virtual void destroy_forwarders();
public: public:
virtual std::string get_curr_origin(); virtual std::string get_curr_origin();
}; };

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 15 #define VERSION_REVISION 16
// generated by configure, only macros. // generated by configure, only macros.
#include <srs_auto_headers.hpp> #include <srs_auto_headers.hpp>