Skip to content

Commit 10297fa

Browse files
committed
fix #257, support 0.1s+ latency. 2.0.70
1 parent 68ade0a commit 10297fa

19 files changed

+179
-30
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ Supported operating systems and hardware:
453453
[CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_SrsLibrtmp#publish-audio-raw-stream),
454454
[EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_SrsLibrtmp#publish-audio-raw-stream)
455455
) by srs-librtmp.
456+
1. Support 0.1s+ latency, read [#257](https://github.com/winlinvip/simple-rtmp-server/issues/257).
456457
1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech).
457458
1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92).
458459
1. [no-plan] Support multiple processes, for both origin and edge
@@ -486,6 +487,7 @@ Supported operating systems and hardware:
486487
* 2013-10-17, Created.<br/>
487488

488489
## History
490+
* v2.0, 2014-12-12, fix [#257](https://github.com/winlinvip/simple-rtmp-server/issues/257), support 0.1s+ latency. 2.0.70
489491
* v2.0, 2014-12-08, update wiki for mr([EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_LowLatency#merged-read), [CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_LowLatency#merged-read)) and mw([EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_LowLatency#merged-write), [CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_LowLatency#merged-write)).
490492
* v2.0, 2014-12-07, fix [#251](https://github.com/winlinvip/simple-rtmp-server/issues/251), 10k+ clients, use queue cond wait and fast vector. 2.0.67
491493
* v2.0, 2014-12-05, fix [#251](https://github.com/winlinvip/simple-rtmp-server/issues/251), 9k+ clients, use fast cache for msgs queue. 2.0.57

trunk/conf/full.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ vhost __defaultVhost__ {
145145
# the MR(merged-read) setting for publisher.
146146
# the MW(merged-write) settings for player.
147147
vhost mrw.srs.com {
148+
# whether enable min delay mode for vhost.
149+
# for min latence mode:
150+
# 1. disable the mr for vhost.
151+
# 2. use timeout for cond wait for consumer queue.
152+
# @see https://github.com/winlinvip/simple-rtmp-server/issues/257
153+
# default: on
154+
min_latency off;
148155
# about MR, read https://github.com/winlinvip/simple-rtmp-server/issues/241
149156
mr {
150157
# whether enable the MR(merged-read)
@@ -440,6 +447,12 @@ vhost debug.srs.com {
440447

441448
# the vhost for min delay, donot cache any stream.
442449
vhost min.delay.com {
450+
# @see vhost mrw.srs.com for detail.
451+
min_latency on;
452+
mr {
453+
enabled off;
454+
}
455+
mw_latency 100;
443456
# whether cache the last gop.
444457
# if on, cache the last gop and dispatch to client,
445458
# to enabled fast startup for client, client play immediately.

trunk/conf/realtime.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# the config for srs to delivery realtime RTMP stream
2-
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_SampleRealtime
2+
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_SampleRealtime
33
# @see full.conf for detail config.
44

55
listen 1935;
66
max_connections 1000;
77
vhost __defaultVhost__ {
88
gop_cache off;
99
queue_length 10;
10+
min_latency on;
1011
mr {
1112
enabled off;
1213
}

trunk/research/players/js/srs.player.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function SrsPlayer(container, width, height, private_object) {
2222
this.height = height;
2323
this.id = SrsPlayer.__id++;
2424
this.stream_url = null;
25-
this.buffer_time = 0.8; // default to 0.8
25+
this.buffer_time = 0.3; // default to 0.3
2626
this.volume = 1.0; // default to 100%
2727
this.callbackObj = null;
2828

trunk/research/players/srs_player.html

100644100755
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
srs_player = new SrsPlayer("player_id", srs_get_player_width(), srs_get_player_height());
9898
srs_player.on_player_ready = function() {
99-
select_buffer_time("#btn_bt_0_8", 0.8);
99+
select_buffer_time("#btn_bt_0_1", 0.1);
100100
this.play(url);
101101
};
102102
srs_player.on_player_metadata = function(metadata) {
@@ -231,6 +231,15 @@
231231
}
232232

233233
if (true) {
234+
$("#btn_bt_0_1").click(function(){
235+
select_buffer_time("#btn_bt_0_1", 0.1);
236+
});
237+
$("#btn_bt_0_2").click(function(){
238+
select_buffer_time("#btn_bt_0_2", 0.2);
239+
});
240+
$("#btn_bt_0_3").click(function(){
241+
select_buffer_time("#btn_bt_0_3", 0.3);
242+
});
234243
$("#btn_bt_0_5").click(function(){
235244
select_buffer_time("#btn_bt_0_5", 0.5);
236245
});
@@ -504,6 +513,9 @@ <h3><a href="https://github.com/winlinvip/simple-rtmp-server">SrsPlayer</a></h3>
504513
<div class="btn-group dropup">
505514
<button class="btn dropdown-toggle" data-toggle="dropdown">缓冲区<span class="caret"></span></button>
506515
<ul class="dropdown-menu">
516+
<li><a id="btn_bt_0_1" href="#">0.1秒(实时)</a></li>
517+
<li><a id="btn_bt_0_2" href="#">0.2秒(实时)</a></li>
518+
<li><a id="btn_bt_0_3" href="#">0.3秒(实时)</a></li>
507519
<li><a id="btn_bt_0_5" href="#">0.5秒(实时)</a></li>
508520
<li><a id="btn_bt_0_8" href="#">0.8秒(会议)</a></li>
509521
<li><a id="btn_bt_1" href="#">1秒(低延迟)</a></li>

trunk/src/app/srs_app_config.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,17 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
852852
}
853853
srs_trace("vhost %s reload mw success.", vhost.c_str());
854854
}
855+
// min_latency, only one per vhost
856+
if (!srs_directive_equals(new_vhost->get("min_latency"), old_vhost->get("min_latency"))) {
857+
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
858+
ISrsReloadHandler* subscribe = *it;
859+
if ((ret = subscribe->on_reload_vhost_realtime(vhost)) != ERROR_SUCCESS) {
860+
srs_error("vhost %s notify subscribes min_latency failed. ret=%d", vhost.c_str(), ret);
861+
return ret;
862+
}
863+
}
864+
srs_trace("vhost %s reload min_latency success.", vhost.c_str());
865+
}
855866
// http, only one per vhost.
856867
if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) {
857868
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
@@ -1350,7 +1361,7 @@ int SrsConfig::check_config()
13501361
&& n != "time_jitter"
13511362
&& n != "atc" && n != "atc_auto"
13521363
&& n != "debug_srs_upnode"
1353-
&& n != "mr" && n != "mw_latency"
1364+
&& n != "mr" && n != "mw_latency" && n != "min_latency"
13541365
) {
13551366
ret = ERROR_SYSTEM_CONFIG_INVALID;
13561367
srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret);
@@ -2125,7 +2136,6 @@ int SrsConfig::get_chunk_size(string vhost)
21252136

21262137
bool SrsConfig::get_mr_enabled(string vhost)
21272138
{
2128-
21292139
SrsConfDirective* conf = get_vhost(vhost);
21302140

21312141
if (!conf) {
@@ -2147,7 +2157,6 @@ bool SrsConfig::get_mr_enabled(string vhost)
21472157

21482158
int SrsConfig::get_mr_sleep_ms(string vhost)
21492159
{
2150-
21512160
SrsConfDirective* conf = get_vhost(vhost);
21522161

21532162
if (!conf) {
@@ -2169,7 +2178,6 @@ int SrsConfig::get_mr_sleep_ms(string vhost)
21692178

21702179
int SrsConfig::get_mw_sleep_ms(string vhost)
21712180
{
2172-
21732181
SrsConfDirective* conf = get_vhost(vhost);
21742182

21752183
if (!conf) {
@@ -2184,6 +2192,22 @@ int SrsConfig::get_mw_sleep_ms(string vhost)
21842192
return ::atoi(conf->arg0().c_str());
21852193
}
21862194

2195+
bool SrsConfig::get_realtime_enabled(string vhost)
2196+
{
2197+
SrsConfDirective* conf = get_vhost(vhost);
2198+
2199+
if (!conf) {
2200+
return SRS_PERF_MIN_LATENCY_ENABLED;
2201+
}
2202+
2203+
conf = conf->get("min_latency");
2204+
if (!conf || conf->arg0() != "off") {
2205+
return SRS_PERF_MIN_LATENCY_ENABLED;
2206+
}
2207+
2208+
return false;
2209+
}
2210+
21872211
int SrsConfig::get_global_chunk_size()
21882212
{
21892213
SrsConfDirective* conf = root->get("chunk_size");

trunk/src/app/srs_app_config.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ class SrsConfig
545545
*/
546546
// TODO: FIXME: add utest for mw config.
547547
virtual int get_mw_sleep_ms(std::string vhost);
548+
/**
549+
* whether min latency mode enabled.
550+
* @param vhost, the vhost to get the min_latency.
551+
*/
552+
// TODO: FIXME: add utest for min_latency.
553+
virtual bool get_realtime_enabled(std::string vhost);
548554
private:
549555
/**
550556
* get the global chunk size.

trunk/src/app/srs_app_recv_thread.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ SrsPublishRecvThread::SrsPublishRecvThread(
251251
mr = _srs_config->get_mr_enabled(req->vhost);
252252
mr_sleep = _srs_config->get_mr_sleep_ms(req->vhost);
253253

254+
realtime = _srs_config->get_realtime_enabled(req->vhost);
255+
254256
_srs_config->subscribe(this);
255257
}
256258

@@ -340,6 +342,10 @@ int SrsPublishRecvThread::handle(SrsCommonMessage* msg)
340342
int ret = ERROR_SUCCESS;
341343

342344
_nb_msgs++;
345+
346+
// log to show the time of recv thread.
347+
srs_verbose("recv thread now=%"PRId64"us, got msg time=%"PRId64"ms, size=%d",
348+
srs_update_system_time_ms(), msg->header.timestamp, msg->size);
343349

344350
// the rtmp connection will handle this message
345351
ret = _conn->handle_publish_message(_source, msg, _is_fmle, _is_edge);
@@ -363,7 +369,7 @@ void SrsPublishRecvThread::on_recv_error(int ret)
363369
#ifdef SRS_PERF_MERGED_READ
364370
void SrsPublishRecvThread::on_read(ssize_t nread)
365371
{
366-
if (!mr) {
372+
if (!mr || realtime) {
367373
return;
368374
}
369375

@@ -386,6 +392,10 @@ void SrsPublishRecvThread::on_read(ssize_t nread)
386392
int SrsPublishRecvThread::on_reload_vhost_mr(string vhost)
387393
{
388394
int ret = ERROR_SUCCESS;
395+
396+
if (req->vhost != vhost) {
397+
return ret;
398+
}
389399

390400
// the mr settings,
391401
// @see https://github.com/winlinvip/simple-rtmp-server/issues/241
@@ -419,6 +429,21 @@ int SrsPublishRecvThread::on_reload_vhost_mr(string vhost)
419429
return ret;
420430
}
421431

432+
int SrsPublishRecvThread::on_reload_vhost_realtime(string vhost)
433+
{
434+
int ret = ERROR_SUCCESS;
435+
436+
if (req->vhost != vhost) {
437+
return ret;
438+
}
439+
440+
bool realtime_enabled = _srs_config->get_realtime_enabled(req->vhost);
441+
srs_trace("realtime changed %d=>%d", realtime, realtime_enabled);
442+
realtime = realtime_enabled;
443+
444+
return ret;
445+
}
446+
422447
void SrsPublishRecvThread::set_socket_buffer(int sleep_ms)
423448
{
424449
// the bytes:
@@ -446,8 +471,9 @@ void SrsPublishRecvThread::set_socket_buffer(int sleep_ms)
446471
}
447472
getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &nb_rbuf, &sock_buf_size);
448473

449-
srs_trace("mr change sleep %d=>%d, erbuf=%d, rbuf %d=>%d, sbytes=%d",
450-
mr_sleep, sleep_ms, socket_buffer_size, onb_rbuf, nb_rbuf, SRS_MR_SMALL_BYTES);
474+
srs_trace("mr change sleep %d=>%d, erbuf=%d, rbuf %d=>%d, sbytes=%d, realtime=%d",
475+
mr_sleep, sleep_ms, socket_buffer_size, onb_rbuf, nb_rbuf,
476+
SRS_MR_SMALL_BYTES, realtime);
451477

452478
rtmp->set_recv_buffer(nb_rbuf);
453479
}

trunk/src/app/srs_app_recv_thread.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class SrsPublishRecvThread : virtual public ISrsMessageHandler
153153
bool mr;
154154
int mr_fd;
155155
int mr_sleep;
156+
// for realtime
157+
// @see https://github.com/winlinvip/simple-rtmp-server/issues/257
158+
bool realtime;
156159
// the recv thread error code.
157160
int recv_error_code;
158161
SrsRtmpConn* _conn;
@@ -193,6 +196,7 @@ class SrsPublishRecvThread : virtual public ISrsMessageHandler
193196
// interface ISrsReloadHandler
194197
public:
195198
virtual int on_reload_vhost_mr(std::string vhost);
199+
virtual int on_reload_vhost_realtime(std::string vhost);
196200
private:
197201
virtual void set_socket_buffer(int sleep_ms);
198202
};

trunk/src/app/srs_app_reload.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ int ISrsReloadHandler::on_reload_vhost_mw(string /*vhost*/)
150150
return ERROR_SUCCESS;
151151
}
152152

153+
int ISrsReloadHandler::on_reload_vhost_realtime(string /*vhost*/)
154+
{
155+
return ERROR_SUCCESS;
156+
}
157+
153158
int ISrsReloadHandler::on_reload_vhost_chunk_size(string /*vhost*/)
154159
{
155160
return ERROR_SUCCESS;

trunk/src/app/srs_app_reload.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class ISrsReloadHandler
6767
virtual int on_reload_vhost_dvr(std::string vhost);
6868
virtual int on_reload_vhost_mr(std::string vhost);
6969
virtual int on_reload_vhost_mw(std::string vhost);
70+
virtual int on_reload_vhost_realtime(std::string vhost);
7071
virtual int on_reload_vhost_chunk_size(std::string vhost);
7172
virtual int on_reload_vhost_transcode(std::string vhost);
7273
virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id);

0 commit comments

Comments
 (0)