Skip to content

Commit

Permalink
fix ossrs#293, support http live flv/aac/mp3 stream with fast cache. …
Browse files Browse the repository at this point in the history
…2.0.100.
  • Loading branch information
winlinvip committed Jan 19, 2015
1 parent 29a8932 commit b7b268d
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ Supported operating systems and hardware:

## 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-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
Expand Down
9 changes: 9 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,21 @@ vhost http.flv.srs.com {
# whether enable the http flv live streaming service for vhost.
# default: off
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.
# for example, if mount to [vhost]/[app]/[stream].flv, user access by http://[vhost]/[app]/[stream].flv
# the variables:
# [vhost] current vhost for http flv live stream.
# [app] current app 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
mount [vhost]/[app]/[stream].flv;
}
Expand Down
18 changes: 18 additions & 0 deletions trunk/conf/http.aac.live.conf
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions trunk/conf/http.mp3.live.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
26 changes: 25 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ int SrsConfig::check_config()
} else if (n == "http_flv") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
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;
srs_error("unsupported vhost http_flv directive %s, ret=%d", m.c_str(), ret);
return ret;
Expand Down Expand Up @@ -3469,6 +3469,30 @@ bool SrsConfig::get_vhost_http_flv_enabled(string vhost)
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)
{
SrsConfDirective* conf = get_vhost(vhost);
Expand Down
5 changes: 5 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_FLV_MOUNT "[vhost]/[app]/[stream].flv"
#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_API_PORT 1985
Expand Down Expand Up @@ -971,6 +972,10 @@ class SrsConfig
*/
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.
* used to generate the flv stream mount path.
*/
Expand Down
13 changes: 8 additions & 5 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
return ret;
}

SrsStreamCache::SrsStreamCache(SrsSource* s)
SrsStreamCache::SrsStreamCache(SrsSource* s, SrsRequest* r)
{
req = r->copy();
source = s;
queue = new SrsMessageQueue(true);
pthread = new SrsThread("http-stream", this, 0, false);
Expand All @@ -153,6 +154,7 @@ SrsStreamCache::~SrsStreamCache()
srs_freep(pthread);

srs_freep(queue);
srs_freep(req);
}

int SrsStreamCache::start()
Expand All @@ -168,7 +170,8 @@ int SrsStreamCache::dump_cache(SrsConsumer* consumer)
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;
}
Expand All @@ -187,8 +190,8 @@ int SrsStreamCache::cycle()
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
// TODO: FIMXE: add pithy print.

// TODO: FIXME: config it.
queue->set_queue_size(60);
// TODO: FIXME: support reload.
queue->set_queue_size(_srs_config->get_vhost_http_flv_fast_cache(req->vhost));

while (true) {
// get messages from consumer.
Expand Down Expand Up @@ -616,7 +619,7 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r)
// remove the default vhost mount
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);

// start http stream cache thread
Expand Down
3 changes: 2 additions & 1 deletion trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class SrsStreamCache : public ISrsThreadHandler
private:
SrsMessageQueue* queue;
SrsSource* source;
SrsRequest* req;
SrsThread* pthread;
public:
SrsStreamCache(SrsSource* s);
SrsStreamCache(SrsSource* s, SrsRequest* r);
virtual ~SrsStreamCache();
public:
virtual int start();
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 99
#define VERSION_REVISION 100

// server info.
#define RTMP_SIG_SRS_KEY "SRS"
Expand Down

0 comments on commit b7b268d

Please sign in to comment.