Skip to content

Commit

Permalink
for ossrs#179, refine dvr code to more simple.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 21, 2015
1 parent 3d225e1 commit 95b4bae
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 337 deletions.
29 changes: 21 additions & 8 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ vhost dvr.srs.com {
# whether enabled dvr features
# default: off
enabled on;
# the dvr plan. canbe:
# session reap flv when session end(unpublish).
# segment reap flv when flv duration exceed the specified dvr_duration.
# api reap flv when api required.
# default: session
dvr_plan session;
# the dvr output path.
# we supports some variables to generate the filename.
# [vhost], the vhost of stream.
Expand Down Expand Up @@ -314,22 +320,28 @@ vhost dvr.srs.com {
# dvr_path /data/ossrs.net/live/2015/01/livestream-03-10.57.30.776.flv;
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DVR#custom-path
# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_DVR#custom-path
# segment,session apply it.
# api apply before api specified the path.
# default: ./objs/nginx/html
dvr_path ./objs/nginx/html;
# the dvr plan. canbe:
# session reap flv when session end(unpublish).
# segment reap flv when flv duration exceed the specified dvr_duration.
# default: session
dvr_plan session;
# the param for plan(segment), in seconds.
# the duration for dvr file, reap if exeed, in seconds.
# segment apply it.
# session,api ignore.
# default: 30
dvr_duration 30;
# the param for plan(segment),
# whether wait keyframe to reap segment,
# if off, reap segment when duration exceed the dvr_duration,
# if on, reap segment when duration exceed and got keyframe.
# segment apply it.
# session,api ignore.
# default: on
dvr_wait_keyframe on;
# whether dvr auto start when publish.
# if off, dvr wait for api to start it.
# api apply it.
# segment,session ignore.
# default: on
dvr_autostart on;
# about the stream monotonically increasing:
# 1. video timestamp is monotonically increasing,
# 2. audio timestamp is monotonically increasing,
Expand All @@ -340,10 +352,11 @@ vhost dvr.srs.com {
# 1. full, to ensure stream start at zero, and ensure stream monotonically increasing.
# 2. zero, only ensure sttream start at zero, ignore timestamp jitter.
# 3. off, disable the time jitter algorithm, like atc.
# apply for all dvr plan.
# default: full
time_jitter full;

# on_dvr
# on_dvr, never config in here, should config in http_hooks.
# for the dvr http callback, @see http_hooks.on_dvr of vhost hooks.callback.srs.com
# @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DVR#http-callback
# @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_DVR#http-callback
Expand Down
18 changes: 18 additions & 0 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ int SrsConfig::check_config()
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "dvr_path" && m != "dvr_plan"
&& m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter"
&& m != "dvr_autostart"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret);
Expand Down Expand Up @@ -3377,6 +3378,23 @@ bool SrsConfig::get_dvr_wait_keyframe(string vhost)
return false;
}

bool SrsConfig::get_dvr_autostart(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);

if (!dvr) {
return true;
}

SrsConfDirective* conf = dvr->get("dvr_autostart");

if (!conf || conf->arg0() != "off") {
return true;
}

return false;
}

int SrsConfig::get_dvr_time_jitter(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
Expand Down
9 changes: 7 additions & 2 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html"
#define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session"
#define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment"
#define SRS_CONF_DEFAULT_DVR_PLAN_API "api"
#define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION
#define SRS_CONF_DEFAULT_DVR_DURATION 30
#define SRS_CONF_DEFAULT_TIME_JITTER "full"
Expand Down Expand Up @@ -921,14 +922,18 @@ class SrsConfig
*/
virtual std::string get_dvr_plan(std::string vhost);
/**
* get the duration of dvr flv, for segment plan.
* get the duration of dvr flv.
*/
virtual int get_dvr_duration(std::string vhost);
/**
* whether wait keyframe to reap segment, for segment plan.
* whether wait keyframe to reap segment.
*/
virtual bool get_dvr_wait_keyframe(std::string vhost);
/**
* whether autostart for dvr. wait api to start dvr if false.
*/
virtual bool get_dvr_autostart(std::string vhost);
/**
* get the time_jitter algorithm for dvr.
*/
virtual int get_dvr_time_jitter(std::string vhost);
Expand Down
Loading

0 comments on commit 95b4bae

Please sign in to comment.