Skip to content

Commit

Permalink
for ossrs#179, add dvr plan append.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 21, 2015
1 parent 95b4bae commit 7077b74
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ vhost dvr.srs.com {
# the dvr plan. canbe:
# session reap flv when session end(unpublish).
# segment reap flv when flv duration exceed the specified dvr_duration.
# append always append to flv file, never reap it.
# api reap flv when api required.
# default: session
dvr_plan session;
Expand Down
1 change: 1 addition & 0 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_APPEND "append"
#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
Expand Down
43 changes: 40 additions & 3 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool SrsFlvSegment::is_overflow(int64_t max_duration)
return duration >= max_duration;
}

int SrsFlvSegment::open()
int SrsFlvSegment::open(bool use_tmp_file)
{
int ret = ERROR_SUCCESS;

Expand All @@ -113,7 +113,7 @@ int SrsFlvSegment::open()
}

// generate the tmp flv path.
if (!fresh_flv_file) {
if (!fresh_flv_file || !use_tmp_file) {
// when path exists, always append to it.
// so we must use the target flv path as output flv.
tmp_flv_file = path;
Expand Down Expand Up @@ -546,8 +546,11 @@ SrsDvrPlan* SrsDvrPlan::create_plan(string vhost)
return new SrsDvrSegmentPlan();
} else if (plan == SRS_CONF_DEFAULT_DVR_PLAN_SESSION) {
return new SrsDvrSessionPlan();
} else if (plan == SRS_CONF_DEFAULT_DVR_PLAN_APPEND) {
return new SrsDvrAppendPlan();
} else {
return new SrsDvrSessionPlan();
srs_error("invalid dvr plan=%s, vhost=%s", plan.c_str(), vhost.c_str());
srs_assert(false);
}
}

Expand Down Expand Up @@ -601,6 +604,40 @@ void SrsDvrSessionPlan::on_unpublish()
dvr_enabled = false;
}

SrsDvrAppendPlan::SrsDvrAppendPlan()
{
}

SrsDvrAppendPlan::~SrsDvrAppendPlan()
{
}

int SrsDvrAppendPlan::on_publish()
{
int ret = ERROR_SUCCESS;

// support multiple publish.
if (dvr_enabled) {
return ret;
}

if (!_srs_config->get_dvr_enabled(req->vhost)) {
return ret;
}

if ((ret = segment->open(false)) != ERROR_SUCCESS) {
return ret;
}

dvr_enabled = true;

return ret;
}

void SrsDvrAppendPlan::on_unpublish()
{
}

SrsDvrSegmentPlan::SrsDvrSegmentPlan()
{
segment_duration = -1;
Expand Down
16 changes: 15 additions & 1 deletion trunk/src/app/srs_app_dvr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ class SrsFlvSegment : public ISrsReloadHandler
/**
* open new segment file, timestamp start at 0 for fresh flv file.
* @remark ignore when already open.
* @param use_tmp_file whether use tmp file if possible.
*/
virtual int open();
virtual int open(bool use_tmp_file = true);
/**
* close current segment.
* @remark ignore when already closed.
Expand Down Expand Up @@ -207,6 +208,19 @@ class SrsDvrSessionPlan : public SrsDvrPlan
virtual void on_unpublish();
};

/**
* always append to flv file, never reap it.
*/
class SrsDvrAppendPlan : public SrsDvrPlan
{
public:
SrsDvrAppendPlan();
virtual ~SrsDvrAppendPlan();
public:
virtual int on_publish();
virtual void on_unpublish();
};

/**
* segment plan: reap flv when duration exceed.
*/
Expand Down

0 comments on commit 7077b74

Please sign in to comment.