diff --git a/README.md b/README.md
index 866ea3061..9204d415c 100755
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ For example, use ffmpeg to publish:
for((;;)); do \
./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv \
-vcodec copy -acodec copy \
- -f flv -y rtmp://127.0.0.1/live/livestream; \
+ -f flv -y rtmp://127.0.0.1/live?vhost=demo.srs.com/livestream; \
sleep 1; \
done
diff --git a/trunk/conf/srs.19350.conf b/trunk/conf/srs.19350.conf
index d40676478..13d32fbba 100755
--- a/trunk/conf/srs.19350.conf
+++ b/trunk/conf/srs.19350.conf
@@ -3,9 +3,11 @@ chunk_size 65000;
vhost __defaultVhost__ {
enabled on;
gop_cache on;
- hls on;
- hls_path ./objs/nginx/html/forward;
- hls_fragment 5;
- hls_window 30;
+ hls {
+ enabled on;
+ hls_path ./objs/nginx/html/forward;
+ hls_fragment 5;
+ hls_window 30;
+ }
}
diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf
index 25ac12e61..eb0d225d6 100755
--- a/trunk/conf/srs.conf
+++ b/trunk/conf/srs.conf
@@ -17,10 +17,17 @@ max_connections 2000;
# vhost list, the __defaultVhost__ is the default vhost
# for example, user use ip to access the stream: rtmp://192.168.1.2/live/livestream.
# for which cannot identify the required vhost.
-# for default demo.
vhost __defaultVhost__ {
enabled on;
gop_cache on;
+}
+# vhost list, the __defaultVhost__ is the default vhost
+# for example, user use ip to access the stream: rtmp://192.168.1.2/live/livestream.
+# for which cannot identify the required vhost.
+# for default demo.
+vhost demo.srs.com {
+ enabled on;
+ gop_cache on;
queue_length 30;
forward 127.0.0.1:19350;
hls {
@@ -44,7 +51,7 @@ vhost __defaultVhost__ {
engine ld {
enabled on;
vfilter {
- vf 'drawtext=text=SimpleRtmpServer(SRS):x=10:y=10:fontcolor=#cccccc:fontfile=./doc/FreeSerifBold.ttf';
+ vf 'drawtext=text=SimpleRtmpServer(SRS):x=10:y=10:fontsize=30:fontcolor=#cccccc:fontfile=./doc/FreeSerifBold.ttf';
}
vcodec libx264;
vbitrate 300;
@@ -89,6 +96,48 @@ vhost __defaultVhost__ {
}
}
}
+# for the players site, to play or publish.
+# the flash player publisher need to transcode to support hls,
+# we add players_hls vhost to support it.
+vhost players {
+ enabled on;
+ gop_cache on;
+ transcode {
+ enabled on;
+ ffmpeg ./objs/ffmpeg/bin/ffmpeg;
+ engine hls {
+ enabled on;
+ vfilter {
+ vf 'drawtext=text=SRS(SimpleRtmpServer):x=10:y=10:fontcolor=#cccccc:fontfile=./doc/FreeSerifBold.ttf';
+ }
+ vcodec libx264;
+ vbitrate 300;
+ vfps 20;
+ vwidth 768;
+ vheight 320;
+ vthreads 1;
+ vprofile baseline;
+ vpreset superfast;
+ vparams {
+ }
+ acodec libaacplus;
+ abitrate 30;
+ asample_rate 44100;
+ achannels 2;
+ aparams {
+ }
+ output rtmp://127.0.0.1:[port]/[app]?vhost=players_pub/[stream];
+ }
+ }
+}
+vhost players_pub {
+ hls {
+ enabled on;
+ hls_path ./objs/nginx/html;
+ hls_fragment 5;
+ hls_window 30;
+ }
+}
# for development
vhost dev {
enabled on;
diff --git a/trunk/research/players/index.html b/trunk/research/players/index.html
index 916050076..97148ee90 100755
--- a/trunk/research/players/index.html
+++ b/trunk/research/players/index.html
@@ -17,7 +17,8 @@
$(function(){
update_nav();
- window.location.href = "srs_player.html";
+ // direct to the default vhost for players.
+ window.location.href = "srs_player.html?vhost=" + srs_get_player_vhost();
});
@@ -25,7 +26,7 @@
-
SRS
+
SRS
- SRS播放器
diff --git a/trunk/research/players/js/srs.js b/trunk/research/players/js/srs.js
index ceaf46150..9dee1e475 100755
--- a/trunk/research/players/js/srs.js
+++ b/trunk/research/players/js/srs.js
@@ -30,13 +30,28 @@ function update_nav() {
* parse the query string to object.
*/
function parse_query_string(){
+ var obj = {};
+
+ // parse the host(hostname:http_port), pathname(dir/filename)
+ obj.host = window.location.host;
+ obj.hostname = window.location.hostname;
+ obj.http_port = (window.location.port == "")? 80:window.location.port;
+ obj.pathname = window.location.pathname;
+ if (obj.pathname.lastIndexOf("/") <= 0) {
+ obj.dir = "/";
+ obj.filename = "";
+ } else {
+ obj.dir = obj.pathname.substr(0, obj.pathname.lastIndexOf("/"));
+ obj.filename = obj.pathname.substr(obj.pathname.lastIndexOf("/"));
+ }
+
+ // parse the query string.
var query_string = String(window.location.search).replace(" ", "").split("?")[1];
if(query_string == undefined){
- return {};
+ return obj;
}
var queries = query_string.split("&");
- var obj = {};
$(queries).each(function(){
var query = this.split("=");
obj[query[0]] = query[1];
@@ -46,6 +61,7 @@ function parse_query_string(){
}
/**
+@param server the ip of server. default to window.location.hostname
@param vhost the vhost of rtmp. default to window.location.hostname
@param port the port of rtmp. default to 1935
@param app the app of rtmp. default to live.
@@ -54,16 +70,23 @@ function parse_query_string(){
function build_default_rtmp_url() {
var query = parse_query_string();
+ var server = (query.server == undefined)? window.location.hostname:query.server;
var port = (query.port == undefined)? 1935:query.port;
var vhost = (query.vhost == undefined)? window.location.hostname:query.vhost;
var app = (query.app == undefined)? "live":query.app;
var stream = (query.stream == undefined)? "livestream":query.stream;
- return "rtmp://" + vhost + ":" + port + "/" + app + "/" + stream;
+ if (server == vhost || vhost == "") {
+ return "rtmp://" + server + ":" + port + "/" + app + "/" + stream;
+ } else {
+ return "rtmp://" + server + ":" + port + "/" + app + "...vhost..." + vhost + "/" + stream;
+ }
}
/**
+@param server the ip of server. default to window.location.hostname
@param vhost the vhost of hls. default to window.location.hostname
+@param hls_vhost the vhost of hls. override the server if specified.
@param hls_port the port of hls. default to window.location.port
@param app the app of hls. default to live.
@param stream the stream of hls. default to livestream.
@@ -71,7 +94,14 @@ function build_default_rtmp_url() {
function build_default_hls_url() {
var query = parse_query_string();
- var vhost = (query.vhost == undefined)? window.location.hostname:query.vhost;
+ // for http, use hls_vhost to override server if specified.
+ var server = window.location.hostname;
+ if (query.server != undefined) {
+ server = query.server;
+ } else if (query.hls_vhost != undefined) {
+ server = query.hls_vhost;
+ }
+
var port = (query.hls_port == undefined)? window.location.port:query.hls_port;
var app = (query.app == undefined)? "live":query.app;
var stream = (query.stream == undefined)? "livestream":query.stream;
@@ -79,7 +109,45 @@ function build_default_hls_url() {
if (port == "" || port == null || port == undefined) {
port = 80;
}
- return "http://" + vhost + ":" + port + "/" + app + "/" + stream + ".m3u8";
+
+ return "http://" + server + ":" + port + "/" + app + "/" + stream + ".m3u8";
+}
+
+/**
+* parse the rtmp url,
+* for example: rtmp://demo.srs.com:1935/live...vhost...players/livestream
+* @return object {server, port, vhost, app, stream}
+*/
+function srs_parse_rtmp_url(rtmp_url) {
+ // @see: http://stackoverflow.com/questions/10469575/how-to-use-location-object-to-parse-url-without-redirecting-the-page-in-javascri
+ var a = document.createElement("a");
+ a.href = rtmp_url.replace("rtmp://", "http://");
+
+ var vhost = a.hostname;
+ var port = (a.port == "")? "1935":a.port;
+ var app = a.pathname.substr(1, a.pathname.lastIndexOf("/") - 1);
+ var stream = a.pathname.substr(a.pathname.lastIndexOf("/") + 1);
+
+ // parse the vhost in the params of app, that srs supports.
+ app = app.replace("...vhost...", "?vhost=");
+ if (app.indexOf("?") >= 0) {
+ var params = app.substr(app.indexOf("?"));
+ app = app.substr(0, app.indexOf("?"));
+
+ if (params.indexOf("vhost=") > 0) {
+ vhost = params.substr(params.indexOf("vhost=") + "vhost=".length);
+ if (vhost.indexOf("&") > 0) {
+ vhost = vhost.substr(0, vhost.indexOf("&"));
+ }
+ }
+ }
+
+ var ret = {
+ server: a.hostname, port: port,
+ vhost: vhost, app: app, stream: stream
+ };
+
+ return ret;
}
/**
@@ -91,6 +159,13 @@ function srs_get_player_height() { return srs_get_player_width() * 9 / 19; }
// to query the swf anti cache.
function srs_get_version_code() { return "1.1"; }
+// get the default vhost for players.
+function srs_get_player_vhost() { return "players"; }
+// get the stream published to vhost,
+// generally we need to transcode the stream to support HLS and filters.
+// for example, src_vhost is "players", we transcode stream to vhost "players_pub".
+// if not equals to the player vhost, return the orignal vhost.
+function srs_get_player_publish_vhost(src_vhost) { return (src_vhost != srs_get_player_vhost())? src_vhost:(src_vhost + "_pub"); }
/**
* initialize the page.
diff --git a/trunk/research/players/jwplayer6.html b/trunk/research/players/jwplayer6.html
index f21091597..5c1a64bdd 100755
--- a/trunk/research/players/jwplayer6.html
+++ b/trunk/research/players/jwplayer6.html
@@ -62,6 +62,15 @@
_url = $("#txt_hls_url").val();
$("#main_modal").modal({show:true, keyboard:false});
});
+
+ var query = parse_query_string();
+ if (query.hls_autostart == "true") {
+ _url = $("#txt_hls_url").val();
+ $("#main_modal").modal({show:true, keyboard:false});
+ } else if (query.rtmp_autostart == "true") {
+ _url = $("#txt_rtmp_url").val();
+ $("#main_modal").modal({show:true, keyboard:false});
+ }
});
@@ -69,7 +78,7 @@
-
SRS
+
SRS
- SRS播放器
diff --git a/trunk/research/players/osmf.html b/trunk/research/players/osmf.html
index c14af1c17..9d4c69ed2 100755
--- a/trunk/research/players/osmf.html
+++ b/trunk/research/players/osmf.html
@@ -74,7 +74,7 @@
-
SRS
+
SRS
- SRS播放器
diff --git a/trunk/research/players/srs_bwt.html b/trunk/research/players/srs_bwt.html
index 9ae461beb..9fdf98c43 100755
--- a/trunk/research/players/srs_bwt.html
+++ b/trunk/research/players/srs_bwt.html
@@ -23,7 +23,7 @@
-
SRS
+
SRS
- SRS播放器
diff --git a/trunk/research/players/srs_player.html b/trunk/research/players/srs_player.html
index 91fa62d5a..0d84cd71f 100755
--- a/trunk/research/players/srs_player.html
+++ b/trunk/research/players/srs_player.html
@@ -26,6 +26,7 @@