winlin

for #324, support hstrs(http stream trigger rtmp source) origin mode. 2.0.139.

... ... @@ -21,7 +21,9 @@ Download from ossrs.net:
RTSP/MPEGTS-over-UDP.
1. Popular internet delivery: RTMP/HDS for flash, HLS for mobile(IOS/IPad/MAC/Android), HTTP
flv/ts/mp3/aac streaming for user prefered.
1. Enhanced DVR: segment/session/append plan, customer path and HTTP callback.
1. Enhanced DVR and hstrs: segment/session/append plan, customer path and HTTP callback.
the hstrs(http stream trigger rtmp source) enable the http-flv stream standby util encoder
start publish, similar to rtmp, which will trigger edge to fetch from origin.
1. Multiple feature: transcode, forward, ingest, http hooks, dvr, hls, rtsp, http streaming,
http api, refer, log, bandwith test and srs-librtmp.
1. Best maintainess: simple arch over state-threads(coroutine), single thread, single process
... ... @@ -558,6 +560,7 @@ Supported operating systems and hardware:
### SRS 2.0 history
* v2.0, 2015-03-14, for [#324](https://github.com/winlinvip/simple-rtmp-server/issues/324), support hstrs(http stream trigger rtmp source) origin mode. 2.0.139.
* v2.0, 2015-03-12, fix [#328](https://github.com/winlinvip/simple-rtmp-server/issues/328), support adobe hds. 2.0.138.
* v2.0, 2015-03-10, fix [#155](https://github.com/winlinvip/simple-rtmp-server/issues/155), support osx(darwin) for mac pro. 2.0.137.
* v2.0, 2015-03-08, fix [#316](https://github.com/winlinvip/simple-rtmp-server/issues/316), http api provides stream/vhost/srs/server bytes, codec and count. 2.0.136.
... ...
... ... @@ -40,6 +40,8 @@ using namespace std;
#include <srs_kernel_file.hpp>
#include <srs_core_autofree.hpp>
#include <srs_rtmp_buffer.hpp>
#include <srs_rtmp_sdk.hpp>
#include <srs_rtmp_utility.hpp>
#define SRS_DEFAULT_HTTP_PORT 80
... ... @@ -1286,6 +1288,32 @@ string SrsHttpMessage::get_request_header(string name)
return "";
}
SrsRequest* SrsHttpMessage::to_request(string vhost)
{
SrsRequest* req = new SrsRequest();
req->app = _uri->get_path();
ssize_t pos = string::npos;
if ((pos = req->app.rfind("/")) != string::npos) {
req->stream = req->app.substr(pos + 1);
req->app = req->app.substr(0, pos);
}
if ((pos = req->stream.rfind(".")) != string::npos) {
req->stream = req->stream.substr(0, pos);
}
req->tcUrl = "rtmp://" + vhost + req->app;
req->pageUrl = get_request_header("Referer");
req->objectEncoding = 0;
srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->port,
req->param);
req->strip();
return req;
}
SrsHttpParser::SrsHttpParser()
{
buffer = new SrsFastBuffer();
... ...
... ... @@ -565,6 +565,12 @@ public:
virtual std::string request_header_key_at(int index);
virtual std::string request_header_value_at(int index);
virtual std::string get_request_header(std::string name);
public:
/**
* convert the http message to a request.
* @remark user must free the return request.
*/
virtual SrsRequest* to_request(std::string vhost);
};
/**
... ...
... ... @@ -48,6 +48,8 @@ using namespace std;
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_source.hpp>
#include <srs_app_server.hpp>
SrsVodStream::SrsVodStream(string root_dir)
: SrsHttpFileServer(root_dir)
... ... @@ -796,8 +798,10 @@ SrsHlsEntry::SrsHlsEntry()
{
}
SrsHttpServer::SrsHttpServer()
SrsHttpServer::SrsHttpServer(SrsServer* svr)
{
server = svr;
mux.hijack(this);
}
... ... @@ -1110,11 +1114,76 @@ int SrsHttpServer::hijack(SrsHttpMessage* request, ISrsHttpHandler** ph)
if (ext.empty()) {
return ret;
}
if (ext != ".flv" && ext != ".ts" && ext != ".mp3" && ext != ".aac") {
// find the actually request vhost.
SrsConfDirective* vhost = _srs_config->get_vhost(request->host());
if (!vhost || !_srs_config->get_vhost_enabled(vhost)) {
return ret;
}
// TODO: FIXME: implements it.
// find the entry template for the stream.
SrsLiveEntry* entry = NULL;
if (true) {
// no http streaming on vhost, ignore.
std::map<std::string, SrsLiveEntry*>::iterator it = tflvs.find(vhost->arg0());
if (it == tflvs.end()) {
return ret;
}
// hstrs not enabled, ignore.
entry = it->second;
if (!entry->hstrs) {
return ret;
}
// check entry and request extension.
if (entry->is_flv()) {
if (ext != ".flv") {
return ret;
}
} else if (entry->is_ts()) {
if (ext != ".ts") {
return ret;
}
} else if (entry->is_mp3()) {
if (ext != ".mp3") {
return ret;
}
} else if (entry->is_aac()) {
if (ext != ".aac") {
return ret;
}
} else {
return ret;
}
}
// hijack for entry.
SrsRequest* r = request->to_request(vhost->arg0());
SrsAutoFree(SrsRequest, r);
SrsSource* s = SrsSource::fetch(r);
if (!s) {
if ((ret = SrsSource::create(r, server, server, &s)) != ERROR_SUCCESS) {
return ret;
}
}
srs_assert(s != NULL);
// create http streaming handler.
if ((ret = http_mount(s, r)) != ERROR_SUCCESS) {
return ret;
}
// use the handler if exists.
if (ph) {
std::string sid = r->get_stream_url();
if (sflvs.find(sid) != sflvs.end()) {
entry = sflvs[sid];
*ph = entry->stream;
srs_trace("hstrs sid=%s", sid.c_str());
}
}
return ret;
}
... ...
... ... @@ -330,6 +330,8 @@ struct SrsHlsEntry
class SrsHttpServer : virtual public ISrsReloadHandler
, virtual public ISrsHttpMatchHijacker
{
private:
SrsServer* server;
public:
SrsHttpServeMux mux;
// the http live streaming template, to create streams.
... ... @@ -341,7 +343,7 @@ public:
// the hls live streaming streams, crote by template.
std::map<std::string, SrsHlsEntry*> shls;
public:
SrsHttpServer();
SrsHttpServer(SrsServer* svr);
virtual ~SrsHttpServer();
public:
virtual int initialize();
... ...
... ... @@ -296,12 +296,14 @@ int SrsRtmpConn::service_cycle()
// do token traverse before serve it.
// @see https://github.com/winlinvip/simple-rtmp-server/pull/239
bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);
bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost);
if (vhost_is_edge && edge_traverse) {
if ((ret = check_edge_token_traverse_auth()) != ERROR_SUCCESS) {
srs_warn("token auth failed, ret=%d", ret);
return ret;
if (true) {
bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);
bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost);
if (vhost_is_edge && edge_traverse) {
if ((ret = check_edge_token_traverse_auth()) != ERROR_SUCCESS) {
srs_warn("token auth failed, ret=%d", ret);
return ret;
}
}
}
... ...
... ... @@ -401,7 +401,7 @@ SrsServer::SrsServer()
http_api_mux = new SrsHttpServeMux();
#endif
#ifdef SRS_AUTO_HTTP_SERVER
http_stream_mux = new SrsHttpServer();
http_stream_mux = new SrsHttpServer(this);
#endif
#ifdef SRS_AUTO_HTTP_PARSER
http_heartbeat = NULL;
... ...
... ... @@ -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 138
#define VERSION_REVISION 139
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
... ...