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