1
0
Fork 0
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:
winlin 2015-01-19 13:17:46 +08:00
parent 29a8932b49
commit b7b268dfbf
9 changed files with 87 additions and 8 deletions

View file

@ -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;
@ -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);

View file

@ -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
@ -971,6 +972,10 @@ public:
*/
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.
*/

View file

@ -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);
@ -153,6 +154,7 @@ SrsStreamCache::~SrsStreamCache()
srs_freep(pthread);
srs_freep(queue);
srs_freep(req);
}
int SrsStreamCache::start()
@ -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;
}
@ -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.
@ -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

View file

@ -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();

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 2
#define VERSION_MINOR 0
#define VERSION_REVISION 99
#define VERSION_REVISION 100
// server info.
#define RTMP_SIG_SRS_KEY "SRS"