Skip to content

Commit

Permalink
For #299, add dash files.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 11, 2017
1 parent 7fd221e commit 5e419c6
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 120 deletions.
10 changes: 10 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,16 @@ vhost exec.srs.com {
}
}

# The vhost for MPEG-DASH.
vhost dash.srs.com {
dash {
# Whether DASH is enabled.
# Transmux RTMP to DASH if on.
# default: off
enabled on;
}
}

# the vhost with hls specified.
vhost hls.srs.com {
hls {
Expand Down
73 changes: 56 additions & 17 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,18 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
srs_trace("vhost %s reload forward success.", vhost.c_str());
}

// To reload DASH.
if (!srs_directive_equals(new_vhost->get("dash"), old_vhost->get("dash"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_dash(vhost)) != ERROR_SUCCESS) {
srs_error("Reload vhost %s dash failed, ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("Reload vhost %s dash ok.", vhost.c_str());
}

// hls, only one per vhost
// @remark, the hls_on_error directly support reload.
if (!srs_directive_equals(new_vhost->get("hls"), old_vhost->get("hls"))) {
Expand Down Expand Up @@ -3808,7 +3820,7 @@ int SrsConfig::check_config()
&& n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
&& n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck"
&& n != "play" && n != "publish" && n != "cluster"
&& n != "security" && n != "http_remux"
&& n != "security" && n != "http_remux" && n != "dash"
&& n != "http_static" && n != "hds" && n != "exec"
&& n != "in_ack_size" && n != "out_ack_size"
) {
Expand All @@ -3819,7 +3831,7 @@ int SrsConfig::check_config()
// for each sub directives of vhost.
if (n == "dvr") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "dvr_apply" && m != "dvr_path" && m != "dvr_plan"
&& m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter"
) {
Expand All @@ -3830,7 +3842,7 @@ int SrsConfig::check_config()
}
} else if (n == "refer") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "all" && m != "publish" && m != "play") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost refer directive %s, ret=%d", m.c_str(), ret);
Expand All @@ -3839,7 +3851,7 @@ int SrsConfig::check_config()
}
} else if (n == "exec") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "publish") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost exec directive %s, ret=%d", m.c_str(), ret);
Expand All @@ -3848,7 +3860,7 @@ int SrsConfig::check_config()
}
} else if (n == "play") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "time_jitter" && m != "mix_correct" && m != "atc" && m != "atc_auto" && m != "mw_latency"
&& m != "gop_cache" && m != "queue_length" && m != "send_min_interval" && m != "reduce_sequence_header"
) {
Expand All @@ -3859,7 +3871,7 @@ int SrsConfig::check_config()
}
} else if (n == "cluster") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost cluster directive %s, ret=%d", m.c_str(), ret);
Expand All @@ -3868,7 +3880,7 @@ int SrsConfig::check_config()
}
} else if (n == "publish") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "mr" && m != "mr_latency" && m != "firstpkt_timeout" && m != "normal_timeout" && m != "parse_sps") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost publish directive %s, ret=%d", m.c_str(), ret);
Expand All @@ -3877,7 +3889,7 @@ int SrsConfig::check_config()
}
} else if (n == "ingest") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "input" && m != "ffmpeg" && m != "engine") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret);
Expand All @@ -3886,7 +3898,7 @@ int SrsConfig::check_config()
}
} else if (n == "http_static") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "mount" && m != "dir") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost http directive %s, ret=%d", m.c_str(), ret);
Expand All @@ -3895,16 +3907,25 @@ int SrsConfig::check_config()
}
} else if (n == "http_remux") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "mount" && m != "fast_cache") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost http_remux directive %s, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "dash") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "enabled") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("Illegal directive %s in vhost.dash, ret=%d", m.c_str(), ret);
return ret;
}
}
} else if (n == "hls") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error"
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
&& m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
Expand All @@ -3922,7 +3943,7 @@ int SrsConfig::check_config()
}
} else if (n == "http_hooks") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
&& m != "on_unpublish" && m != "on_play" && m != "on_stop"
&& m != "on_dvr" && m != "on_hls" && m != "on_hls_notify"
Expand All @@ -3934,7 +3955,7 @@ int SrsConfig::check_config()
}
} else if (n == "forward") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "destination") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret);
Expand Down Expand Up @@ -3979,7 +4000,7 @@ int SrsConfig::check_config()
}
} else if (n == "bandcheck") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
string m = conf->at(j)->name;
if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost bandcheck directive %s, ret=%d", m.c_str(), ret);
Expand Down Expand Up @@ -5944,15 +5965,33 @@ string SrsConfig::get_ffmpeg_log_dir()
return conf->arg0();
}

SrsConfDirective* SrsConfig::get_hls(string vhost)
SrsConfDirective* SrsConfig::get_dash(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
return conf? conf->get("dash") : NULL;
}

bool SrsConfig::get_dash_enabled(string vhost)
{
static bool DEFAULT = false;

SrsConfDirective* conf = get_dash(vhost);
if (!conf) {
return NULL;
return DEFAULT;
}

return conf->get("hls");
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

return SRS_CONF_PERFER_FALSE(conf->arg0());
}

SrsConfDirective* SrsConfig::get_hls(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
return conf? conf->get("hls") : NULL;
}

bool SrsConfig::get_hls_enabled(string vhost)
Expand Down
6 changes: 6 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,12 @@ class SrsConfig
* @remark, /dev/null to disable it.
*/
virtual std::string get_ffmpeg_log_dir();
// The MPEG-DASH section.
private:
virtual SrsConfDirective* get_dash(std::string vhost);
public:
// Whether DASH is enabled.
virtual bool get_dash_enabled(std::string vhost);
// hls section
private:
/**
Expand Down
76 changes: 76 additions & 0 deletions trunk/src/app/srs_app_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,80 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <srs_app_dash.hpp>

#include <srs_kernel_error.hpp>
#include <srs_app_source.hpp>
#include <srs_app_config.hpp>
#include <srs_rtmp_stack.hpp>

SrsMpegDash::SrsMpegDash()
{
hub = NULL;
req = NULL;

enabled = false;
}

SrsMpegDash::~SrsMpegDash()
{
}

int SrsMpegDash::initialize(SrsOriginHub* h, SrsRequest* r)
{
int ret = ERROR_SUCCESS;

hub = h;
req = r;

return ret;
}

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

// Prevent duplicated publish.
if (enabled) {
return ret;
}

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

enabled = true;

return ret;
}

int SrsMpegDash::on_audio(SrsSharedPtrMessage* shared_audio)
{
int ret = ERROR_SUCCESS;

if (!enabled) {
return ret;
}

return ret;
}

int SrsMpegDash::on_video(SrsSharedPtrMessage* shared_video, bool is_sequence_header)
{
int ret = ERROR_SUCCESS;

if (!enabled) {
return ret;
}

return ret;
}

void SrsMpegDash::on_unpublish()
{
// Prevent duplicated unpublish.
if (!enabled) {
return;
}

enabled = false;
}

30 changes: 30 additions & 0 deletions trunk/src/app/srs_app_dash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_core.hpp>

class SrsRequest;
class SrsOriginHub;
class SrsSharedPtrMessage;

/**
* The MPEG-DASH encoder, transmux RTMP to DASH.
*/
class SrsMpegDash
{
private:
bool enabled;
private:
SrsRequest* req;
SrsOriginHub* hub;
public:
SrsMpegDash();
virtual ~SrsMpegDash();
public:
// Initalize the encoder.
virtual int initialize(SrsOriginHub* h, SrsRequest* r);
// When stream start publishing.
virtual int on_publish();
// When got an shared audio message.
virtual int on_audio(SrsSharedPtrMessage* shared_audio);
// When got an shared video message.
virtual int on_video(SrsSharedPtrMessage* shared_video, bool is_sequence_header);
// When stream stop publishing.
virtual void on_unpublish();
};

#endif
26 changes: 16 additions & 10 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ int SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r)
return ret;
}

int SrsDvr::on_publish(bool fetch_sequence_header)
int SrsDvr::on_publish()
{
int ret = ERROR_SUCCESS;

Expand All @@ -1032,10 +1032,6 @@ int SrsDvr::on_publish(bool fetch_sequence_header)
return ret;
}

if (fetch_sequence_header && (ret = hub->on_dvr_request_sh()) != ERROR_SUCCESS) {
return ret;
}

return ret;
}

Expand Down Expand Up @@ -1088,11 +1084,21 @@ int SrsDvr::on_reload_vhost_dvr_apply(string vhost)
bool v = srs_config_apply_filter(conf, req);

// the apply changed, republish the dvr.
if (v != actived) {
actived = v;

on_unpublish();
return on_publish(true);
if (v == actived) {
return ret;
}
actived = v;

on_unpublish();
if (!actived) {
return ret;
}

if ((ret = on_publish()) != ERROR_SUCCESS) {
return ret;
}
if ((ret = hub->on_dvr_request_sh()) != ERROR_SUCCESS) {
return ret;
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_dvr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class SrsDvr : public ISrsReloadHandler
* when encoder start to publish RTMP stream.
* @param fetch_sequence_header whether fetch sequence from source.
*/
virtual int on_publish(bool fetch_sequence_header);
virtual int on_publish();
/**
* the unpublish event.,
* when encoder stop(unpublish) to publish RTMP stream.
Expand Down
Loading

0 comments on commit 5e419c6

Please sign in to comment.