1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-14 12:21:55 +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.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-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
@ -872,13 +873,13 @@ Remark:
| Input | SRS(Simple RTMP Server) | Output |
+----------------------+-------------------------+----------------+
| 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 |
| ......) | +-> Fowarder ---------+-> RTMP server |
| | +-> Transcoder -------+-> RTMP server |
| | +-> EXEC(5) ----------+-> External app |
| | +-> DVR --------------+-> Flv file |
| | +-> BandwidthTest ----+-> flash |
| | +-> DVR --------------+-> FLV file |
| | +-> BandwidthTest ----+-> Flash |
+----------------------+ | |
| MediaSource(2) | | |
| (RTSP,FILE, | | |

View file

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

View file

@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef SRS_AUTO_DVR
class SrsSource;
class SrsOriginHub;
class SrsRequest;
class SrsBuffer;
class SrsRtmpJitter;
@ -300,7 +301,7 @@ private:
class SrsDvr : public ISrsReloadHandler
{
private:
SrsSource* source;
SrsOriginHub* hub;
SrsDvrPlan* plan;
SrsRequest* req;
private:
@ -317,7 +318,7 @@ public:
* when system initialize(encoder publish at first time, or reload),
* 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,
* 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.
#define SRS_FORWARDER_CIMS (3000)
SrsForwarder::SrsForwarder(SrsSource* s)
SrsForwarder::SrsForwarder(SrsOriginHub* h)
{
source = s;
hub = h;
req = NULL;
sh_video = sh_audio = NULL;
@ -250,7 +250,7 @@ int SrsForwarder::cycle()
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);
return ret;
}

View file

@ -42,6 +42,7 @@ class SrsRtmpJitter;
class SrsRtmpClient;
class SrsRequest;
class SrsSource;
class SrsOriginHub;
class SrsKbps;
class SrsSimpleRtmpClient;
@ -58,7 +59,7 @@ private:
private:
SrsReusableThread2* pthread;
private:
SrsSource* source;
SrsOriginHub* hub;
SrsSimpleRtmpClient* sdk;
SrsRtmpJitter* jitter;
SrsMessageQueue* queue;
@ -69,7 +70,7 @@ private:
SrsSharedPtrMessage* sh_audio;
SrsSharedPtrMessage* sh_video;
public:
SrsForwarder(SrsSource* _source);
SrsForwarder(SrsOriginHub* h);
virtual ~SrsForwarder();
public:
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()
{
req = NULL;
source = NULL;
hub = NULL;
hls_enabled = false;
hls_can_dispose = false;
@ -1197,11 +1197,11 @@ int SrsHls::cycle()
return ret;
}
int SrsHls::initialize(SrsSource* s, SrsRequest* r)
int SrsHls::initialize(SrsOriginHub* h, SrsRequest* r)
{
int ret = ERROR_SUCCESS;
source = s;
hub = h;
req = r;
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.
// 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.
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);
return ret;
}

View file

@ -45,6 +45,7 @@ class SrsAvcAacCodec;
class SrsRequest;
class SrsPithyPrint;
class SrsSource;
class SrsOriginHub;
class SrsFileWriter;
class SrsSimpleStream;
class SrsTsAacJitter;
@ -362,7 +363,7 @@ private:
bool hls_can_dispose;
int64_t last_update_time;
private:
SrsSource* source;
SrsOriginHub* hub;
SrsAvcAacCodec* codec;
SrsCodecSample* sample;
SrsRtmpJitter* jitter;
@ -391,7 +392,7 @@ public:
/**
* 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,
* 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 SrsNgExec;
class SrsConnection;
class SrsMessageHeader;
#ifdef SRS_AUTO_HLS
class SrsHls;
#endif
@ -410,11 +411,129 @@ 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.
*/
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.
*/
class SrsSource : public ISrsReloadHandler
{
friend class SrsOriginHub;
private:
static std::map<std::string, SrsSource*> pool;
public:
@ -475,35 +594,19 @@ private:
bool is_monotonically_increase;
// the time of the packet we just got.
int64_t last_packet_time;
// 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;
// for aggregate message
SrsBuffer* aggregate_stream;
// the event handler.
ISrsSourceHandler* handler;
// edge control service
SrsPlayEdge* play_edge;
SrsPublishEdge* publish_edge;
// gop cache for client fast startup.
SrsGopCache* gop_cache;
// to forward stream to other servers
std::vector<SrsForwarder*> forwarders;
// for aggregate message
SrsBuffer* aggregate_stream;
// the event handler.
ISrsSourceHandler* handler;
// The hub for origin server.
SrsOriginHub* hub;
// The metadata cache.
SrsMetaCache* meta;
private:
/**
* can publish, true when is not streaming
@ -512,12 +615,6 @@ private:
// last die time, when all consumers quit and no publisher,
// we will remove the source when source die.
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:
SrsSource();
virtual ~SrsSource();
@ -535,20 +632,8 @@ public:
// interface ISrsReloadHandler
public:
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
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.
virtual int on_source_id_changed(int id);
// get current source id.
@ -599,9 +684,6 @@ public:
virtual int on_edge_proxy_publish(SrsCommonMessage* msg);
// for edge, proxy stop publish
virtual void on_edge_proxy_unpublish();
private:
virtual int create_forwarders();
virtual void destroy_forwarders();
public:
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
#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_REVISION 15
#define VERSION_REVISION 16
// generated by configure, only macros.
#include <srs_auto_headers.hpp>