mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #293, support http live flv/aac/mp3 stream with fast cache. 2.0.100.
This commit is contained in:
parent
29a8932b49
commit
b7b268dfbf
9 changed files with 87 additions and 8 deletions
|
@ -515,6 +515,7 @@ Supported operating systems and hardware:
|
||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
|
* v2.0, 2015-01-19, fix [#293](https://github.com/winlinvip/simple-rtmp-server/issues/293), support http live flv/aac/mp3 stream with fast cache. 2.0.100.
|
||||||
* v2.0, 2015-01-18, fix [#293](https://github.com/winlinvip/simple-rtmp-server/issues/293), support rtmp remux to http flv live stream. 2.0.99.
|
* v2.0, 2015-01-18, fix [#293](https://github.com/winlinvip/simple-rtmp-server/issues/293), support rtmp remux to http flv live stream. 2.0.99.
|
||||||
* v2.0, 2015-01-17, fix [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http server refer to go http-framework. 2.0.98
|
* v2.0, 2015-01-17, fix [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http server refer to go http-framework. 2.0.98
|
||||||
* v2.0, 2015-01-17, for [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http api refer to go http-framework. 2.0.97
|
* v2.0, 2015-01-17, for [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http api refer to go http-framework. 2.0.97
|
||||||
|
|
|
@ -371,12 +371,21 @@ vhost http.flv.srs.com {
|
||||||
# whether enable the http flv live streaming service for vhost.
|
# whether enable the http flv live streaming service for vhost.
|
||||||
# default: off
|
# default: off
|
||||||
enabled on;
|
enabled on;
|
||||||
|
# the fast cache for audio stream(mp3/aac),
|
||||||
|
# to cache more audio and send to client in a time to make android(weixin) happy.
|
||||||
|
# @remark the flv stream ignore it
|
||||||
|
# default: 30
|
||||||
|
fast_cache 30;
|
||||||
# the stream mout for rtmp to remux to flv live streaming.
|
# the stream mout for rtmp to remux to flv live streaming.
|
||||||
# for example, if mount to [vhost]/[app]/[stream].flv, user access by http://[vhost]/[app]/[stream].flv
|
# for example, if mount to [vhost]/[app]/[stream].flv, user access by http://[vhost]/[app]/[stream].flv
|
||||||
# the variables:
|
# the variables:
|
||||||
# [vhost] current vhost for http flv live stream.
|
# [vhost] current vhost for http flv live stream.
|
||||||
# [app] current app for http flv live stream.
|
# [app] current app for http flv live stream.
|
||||||
# [stream] current stream for http flv live stream.
|
# [stream] current stream for http flv live stream.
|
||||||
|
# the extension:
|
||||||
|
# .flv mount http live flv stream, use default gop cache.
|
||||||
|
# .mp3 mount http live mp3 stream, ignore video and audio mp3 codec required.
|
||||||
|
# .aac mount http live aac stream, ignore video and audio aac codec required.
|
||||||
# default: [vhost]/[app]/[stream].flv
|
# default: [vhost]/[app]/[stream].flv
|
||||||
mount [vhost]/[app]/[stream].flv;
|
mount [vhost]/[app]/[stream].flv;
|
||||||
}
|
}
|
||||||
|
|
18
trunk/conf/http.aac.live.conf
Normal file
18
trunk/conf/http.aac.live.conf
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# the config for srs to remux rtmp to aac live stream.
|
||||||
|
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHttpFlvStream
|
||||||
|
# @see full.conf for detail config.
|
||||||
|
|
||||||
|
listen 1935;
|
||||||
|
max_connections 1000;
|
||||||
|
http_stream {
|
||||||
|
enabled on;
|
||||||
|
listen 8080;
|
||||||
|
dir ./objs/nginx/html;
|
||||||
|
}
|
||||||
|
vhost __defaultVhost__ {
|
||||||
|
http_flv {
|
||||||
|
enabled on;
|
||||||
|
fast_cache 30;
|
||||||
|
mount [vhost]/[app]/[stream].aac;
|
||||||
|
}
|
||||||
|
}
|
18
trunk/conf/http.mp3.live.conf
Normal file
18
trunk/conf/http.mp3.live.conf
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# the config for srs to remux rtmp to mp3 live stream.
|
||||||
|
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHttpFlvStream
|
||||||
|
# @see full.conf for detail config.
|
||||||
|
|
||||||
|
listen 1935;
|
||||||
|
max_connections 1000;
|
||||||
|
http_stream {
|
||||||
|
enabled on;
|
||||||
|
listen 8080;
|
||||||
|
dir ./objs/nginx/html;
|
||||||
|
}
|
||||||
|
vhost __defaultVhost__ {
|
||||||
|
http_flv {
|
||||||
|
enabled on;
|
||||||
|
fast_cache 30;
|
||||||
|
mount [vhost]/[app]/[stream].mp3;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1426,7 +1426,7 @@ int SrsConfig::check_config()
|
||||||
} else if (n == "http_flv") {
|
} else if (n == "http_flv") {
|
||||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||||
string m = conf->at(j)->name.c_str();
|
string m = conf->at(j)->name.c_str();
|
||||||
if (m != "enabled" && m != "mount") {
|
if (m != "enabled" && m != "mount" && m != "fast_cache") {
|
||||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||||
srs_error("unsupported vhost http_flv directive %s, ret=%d", m.c_str(), ret);
|
srs_error("unsupported vhost http_flv directive %s, ret=%d", m.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -3469,6 +3469,30 @@ bool SrsConfig::get_vhost_http_flv_enabled(string vhost)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double SrsConfig::get_vhost_http_flv_fast_cache(string vhost)
|
||||||
|
{
|
||||||
|
SrsConfDirective* conf = get_vhost(vhost);
|
||||||
|
if (!conf) {
|
||||||
|
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf = conf->get("http_flv");
|
||||||
|
if (!conf) {
|
||||||
|
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf = conf->get("fast_cache");
|
||||||
|
if (!conf) {
|
||||||
|
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conf->arg0().empty()) {
|
||||||
|
return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ::atof(conf->arg0().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
string SrsConfig::get_vhost_http_flv_mount(string vhost)
|
string SrsConfig::get_vhost_http_flv_mount(string vhost)
|
||||||
{
|
{
|
||||||
SrsConfDirective* conf = get_vhost(vhost);
|
SrsConfDirective* conf = get_vhost(vhost);
|
||||||
|
|
|
@ -68,6 +68,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/"
|
#define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/"
|
||||||
#define SRS_CONF_DEFAULT_HTTP_FLV_MOUNT "[vhost]/[app]/[stream].flv"
|
#define SRS_CONF_DEFAULT_HTTP_FLV_MOUNT "[vhost]/[app]/[stream].flv"
|
||||||
#define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH
|
#define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH
|
||||||
|
#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 30
|
||||||
|
|
||||||
#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080
|
#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080
|
||||||
#define SRS_CONF_DEFAULT_HTTP_API_PORT 1985
|
#define SRS_CONF_DEFAULT_HTTP_API_PORT 1985
|
||||||
|
@ -971,6 +972,10 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool get_vhost_http_flv_enabled(std::string vhost);
|
virtual bool get_vhost_http_flv_enabled(std::string vhost);
|
||||||
/**
|
/**
|
||||||
|
* get the fast cache duration for http audio live stream.
|
||||||
|
*/
|
||||||
|
virtual double get_vhost_http_flv_fast_cache(std::string vhost);
|
||||||
|
/**
|
||||||
* get the http flv live stream mount point for vhost.
|
* get the http flv live stream mount point for vhost.
|
||||||
* used to generate the flv stream mount path.
|
* used to generate the flv stream mount path.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -140,8 +140,9 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStreamCache::SrsStreamCache(SrsSource* s)
|
SrsStreamCache::SrsStreamCache(SrsSource* s, SrsRequest* r)
|
||||||
{
|
{
|
||||||
|
req = r->copy();
|
||||||
source = s;
|
source = s;
|
||||||
queue = new SrsMessageQueue(true);
|
queue = new SrsMessageQueue(true);
|
||||||
pthread = new SrsThread("http-stream", this, 0, false);
|
pthread = new SrsThread("http-stream", this, 0, false);
|
||||||
|
@ -153,6 +154,7 @@ SrsStreamCache::~SrsStreamCache()
|
||||||
srs_freep(pthread);
|
srs_freep(pthread);
|
||||||
|
|
||||||
srs_freep(queue);
|
srs_freep(queue);
|
||||||
|
srs_freep(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsStreamCache::start()
|
int SrsStreamCache::start()
|
||||||
|
@ -168,7 +170,8 @@ int SrsStreamCache::dump_cache(SrsConsumer* consumer)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_trace("http: dump cache %d msgs, duration=%dms", queue->size(), queue->duration());
|
srs_trace("http: dump cache %d msgs, duration=%dms, cache=%.2fs",
|
||||||
|
queue->size(), queue->duration(), _srs_config->get_vhost_http_flv_fast_cache(req->vhost));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -187,8 +190,8 @@ int SrsStreamCache::cycle()
|
||||||
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
||||||
// TODO: FIMXE: add pithy print.
|
// TODO: FIMXE: add pithy print.
|
||||||
|
|
||||||
// TODO: FIXME: config it.
|
// TODO: FIXME: support reload.
|
||||||
queue->set_queue_size(60);
|
queue->set_queue_size(_srs_config->get_vhost_http_flv_fast_cache(req->vhost));
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// get messages from consumer.
|
// get messages from consumer.
|
||||||
|
@ -616,7 +619,7 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r)
|
||||||
// remove the default vhost mount
|
// remove the default vhost mount
|
||||||
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
|
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
|
||||||
|
|
||||||
entry->cache = new SrsStreamCache(s);
|
entry->cache = new SrsStreamCache(s, r);
|
||||||
entry->stream = new SrsLiveStream(s, r, entry->cache);
|
entry->stream = new SrsLiveStream(s, r, entry->cache);
|
||||||
|
|
||||||
// start http stream cache thread
|
// start http stream cache thread
|
||||||
|
|
|
@ -77,9 +77,10 @@ class SrsStreamCache : public ISrsThreadHandler
|
||||||
private:
|
private:
|
||||||
SrsMessageQueue* queue;
|
SrsMessageQueue* queue;
|
||||||
SrsSource* source;
|
SrsSource* source;
|
||||||
|
SrsRequest* req;
|
||||||
SrsThread* pthread;
|
SrsThread* pthread;
|
||||||
public:
|
public:
|
||||||
SrsStreamCache(SrsSource* s);
|
SrsStreamCache(SrsSource* s, SrsRequest* r);
|
||||||
virtual ~SrsStreamCache();
|
virtual ~SrsStreamCache();
|
||||||
public:
|
public:
|
||||||
virtual int start();
|
virtual int start();
|
||||||
|
|
|
@ -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 2
|
#define VERSION_MAJOR 2
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 99
|
#define VERSION_REVISION 100
|
||||||
|
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "SRS"
|
#define RTMP_SIG_SRS_KEY "SRS"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue