winlin

merge from 1.0release for bug #264. 2.0.74

@@ -329,6 +329,12 @@ vhost with-hls.srs.com { @@ -329,6 +329,12 @@ vhost with-hls.srs.com {
329 # the hls window in seconds, the number of ts in m3u8. 329 # the hls window in seconds, the number of ts in m3u8.
330 # default: 60 330 # default: 60
331 hls_window 60; 331 hls_window 60;
  332 + # the error strategy. canbe:
  333 + # ignore, when error ignore and disable hls.
  334 + # disconnect, when error disconnect the publish connection.
  335 + # @see https://github.com/winlinvip/simple-rtmp-server/issues/264
  336 + # default: ignore
  337 + hls_on_error ignore;
332 } 338 }
333 } 339 }
334 # the vhost with hls disabled. 340 # the vhost with hls disabled.
@@ -798,6 +798,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -798,6 +798,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
798 srs_trace("vhost %s reload forward success.", vhost.c_str()); 798 srs_trace("vhost %s reload forward success.", vhost.c_str());
799 } 799 }
800 // hls, only one per vhost 800 // hls, only one per vhost
  801 + // @remark, the hls_on_error directly support reload.
801 if (!srs_directive_equals(new_vhost->get("hls"), old_vhost->get("hls"))) { 802 if (!srs_directive_equals(new_vhost->get("hls"), old_vhost->get("hls"))) {
802 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 803 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
803 ISrsReloadHandler* subscribe = *it; 804 ISrsReloadHandler* subscribe = *it;
@@ -1412,7 +1413,7 @@ int SrsConfig::check_config() @@ -1412,7 +1413,7 @@ int SrsConfig::check_config()
1412 } else if (n == "hls") { 1413 } else if (n == "hls") {
1413 for (int j = 0; j < (int)conf->directives.size(); j++) { 1414 for (int j = 0; j < (int)conf->directives.size(); j++) {
1414 string m = conf->at(j)->name.c_str(); 1415 string m = conf->at(j)->name.c_str();
1415 - if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window") { 1416 + if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error") {
1416 ret = ERROR_SYSTEM_CONFIG_INVALID; 1417 ret = ERROR_SYSTEM_CONFIG_INVALID;
1417 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); 1418 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
1418 return ret; 1419 return ret;
@@ -3064,6 +3065,23 @@ double SrsConfig::get_hls_window(string vhost) @@ -3064,6 +3065,23 @@ double SrsConfig::get_hls_window(string vhost)
3064 return ::atof(conf->arg0().c_str()); 3065 return ::atof(conf->arg0().c_str());
3065 } 3066 }
3066 3067
  3068 +string SrsConfig::get_hls_on_error(string vhost)
  3069 +{
  3070 + SrsConfDirective* hls = get_hls(vhost);
  3071 +
  3072 + if (!hls) {
  3073 + return SRS_CONF_DEFAULT_HLS_ON_ERROR;
  3074 + }
  3075 +
  3076 + SrsConfDirective* conf = hls->get("hls_on_error");
  3077 +
  3078 + if (!conf) {
  3079 + return SRS_CONF_DEFAULT_HLS_ON_ERROR;
  3080 + }
  3081 +
  3082 + return conf->arg0();
  3083 +}
  3084 +
3067 SrsConfDirective* SrsConfig::get_dvr(string vhost) 3085 SrsConfDirective* SrsConfig::get_dvr(string vhost)
3068 { 3086 {
3069 SrsConfDirective* conf = get_vhost(vhost); 3087 SrsConfDirective* conf = get_vhost(vhost);
@@ -48,6 +48,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -48,6 +48,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 #define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html" 48 #define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html"
49 #define SRS_CONF_DEFAULT_HLS_FRAGMENT 10 49 #define SRS_CONF_DEFAULT_HLS_FRAGMENT 10
50 #define SRS_CONF_DEFAULT_HLS_WINDOW 60 50 #define SRS_CONF_DEFAULT_HLS_WINDOW 60
  51 +#define SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE "ignore"
  52 +#define SRS_CONF_DEFAULT_HLS_ON_ERROR_DISCONNECT "disconnect"
  53 +#define SRS_CONF_DEFAULT_HLS_ON_ERROR SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE
51 #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html" 54 #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html"
52 #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" 55 #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session"
53 #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" 56 #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment"
@@ -847,6 +850,13 @@ public: @@ -847,6 +850,13 @@ public:
847 * @remark SRS will delete the ts exceed the window. 850 * @remark SRS will delete the ts exceed the window.
848 */ 851 */
849 virtual double get_hls_window(std::string vhost); 852 virtual double get_hls_window(std::string vhost);
  853 + /**
  854 + * get the hls hls_on_error config.
  855 + * the ignore will ignore error and disable hls.
  856 + * the disconnect will disconnect publish connection.
  857 + * @see https://github.com/winlinvip/simple-rtmp-server/issues/264
  858 + */
  859 + virtual std::string get_hls_on_error(std::string vhost);
850 // dvr section 860 // dvr section
851 private: 861 private:
852 /** 862 /**
@@ -1439,7 +1439,7 @@ int SrsHls::on_audio(SrsSharedPtrMessage* __audio) @@ -1439,7 +1439,7 @@ int SrsHls::on_audio(SrsSharedPtrMessage* __audio)
1439 1439
1440 sample->clear(); 1440 sample->clear();
1441 if ((ret = codec->audio_aac_demux(audio->payload, audio->size, sample)) != ERROR_SUCCESS) { 1441 if ((ret = codec->audio_aac_demux(audio->payload, audio->size, sample)) != ERROR_SUCCESS) {
1442 - srs_error("codec demux audio failed. ret=%d", ret); 1442 + srs_error("hls codec demux audio failed. ret=%d", ret);
1443 return ret; 1443 return ret;
1444 } 1444 }
1445 1445
@@ -1484,7 +1484,7 @@ int SrsHls::on_video(SrsSharedPtrMessage* __video) @@ -1484,7 +1484,7 @@ int SrsHls::on_video(SrsSharedPtrMessage* __video)
1484 1484
1485 sample->clear(); 1485 sample->clear();
1486 if ((ret = codec->video_avc_demux(video->payload, video->size, sample)) != ERROR_SUCCESS) { 1486 if ((ret = codec->video_avc_demux(video->payload, video->size, sample)) != ERROR_SUCCESS) {
1487 - srs_error("codec demux video failed. ret=%d", ret); 1487 + srs_error("hls codec demux video failed. ret=%d", ret);
1488 return ret; 1488 return ret;
1489 } 1489 }
1490 1490
@@ -1239,14 +1239,22 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) @@ -1239,14 +1239,22 @@ int SrsSource::on_audio(SrsCommonMessage* __audio)
1239 srs_verbose("initialize shared ptr audio success."); 1239 srs_verbose("initialize shared ptr audio success.");
1240 1240
1241 #ifdef SRS_AUTO_HLS 1241 #ifdef SRS_AUTO_HLS
1242 - if ((ret = hls->on_audio(&msg)) != ERROR_SUCCESS) {  
1243 - srs_warn("hls process audio message failed, ignore and disable hls. ret=%d", ret);  
1244 -  
1245 - // unpublish, ignore ret.  
1246 - hls->on_unpublish();  
1247 -  
1248 - // ignore.  
1249 - ret = ERROR_SUCCESS; 1242 + if ((ret = hls->on_audio(msg.copy())) != ERROR_SUCCESS) {
  1243 + // apply the error strategy for hls.
  1244 + // @see https://github.com/winlinvip/simple-rtmp-server/issues/264
  1245 + std::string hls_error_strategy = _srs_config->get_hls_on_error(_req->vhost);
  1246 + if (hls_error_strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE) {
  1247 + srs_warn("hls process audio message failed, ignore and disable hls. ret=%d", ret);
  1248 +
  1249 + // unpublish, ignore ret.
  1250 + hls->on_unpublish();
  1251 +
  1252 + // ignore.
  1253 + ret = ERROR_SUCCESS;
  1254 + } else {
  1255 + srs_warn("hls disconnect publisher for audio error. ret=%d", ret);
  1256 + return ret;
  1257 + }
1250 } 1258 }
1251 #endif 1259 #endif
1252 1260
@@ -1298,7 +1306,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) @@ -1298,7 +1306,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio)
1298 SrsAvcAacCodec codec; 1306 SrsAvcAacCodec codec;
1299 SrsCodecSample sample; 1307 SrsCodecSample sample;
1300 if ((ret = codec.audio_aac_demux(msg.payload, msg.size, &sample)) != ERROR_SUCCESS) { 1308 if ((ret = codec.audio_aac_demux(msg.payload, msg.size, &sample)) != ERROR_SUCCESS) {
1301 - srs_error("codec demux audio failed. ret=%d", ret); 1309 + srs_error("source codec demux audio failed. ret=%d", ret);
1302 return ret; 1310 return ret;
1303 } 1311 }
1304 1312
@@ -1349,14 +1357,22 @@ int SrsSource::on_video(SrsCommonMessage* __video) @@ -1349,14 +1357,22 @@ int SrsSource::on_video(SrsCommonMessage* __video)
1349 srs_verbose("initialize shared ptr video success."); 1357 srs_verbose("initialize shared ptr video success.");
1350 1358
1351 #ifdef SRS_AUTO_HLS 1359 #ifdef SRS_AUTO_HLS
1352 - if ((ret = hls->on_video(&msg)) != ERROR_SUCCESS) {  
1353 - srs_warn("hls process video message failed, ignore and disable hls. ret=%d", ret);  
1354 -  
1355 - // unpublish, ignore ret.  
1356 - hls->on_unpublish();  
1357 -  
1358 - // ignore.  
1359 - ret = ERROR_SUCCESS; 1360 + if ((ret = hls->on_video(msg.copy())) != ERROR_SUCCESS) {
  1361 + // apply the error strategy for hls.
  1362 + // @see https://github.com/winlinvip/simple-rtmp-server/issues/264
  1363 + std::string hls_error_strategy = _srs_config->get_hls_on_error(_req->vhost);
  1364 + if (hls_error_strategy == SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE) {
  1365 + srs_warn("hls process video message failed, ignore and disable hls. ret=%d", ret);
  1366 +
  1367 + // unpublish, ignore ret.
  1368 + hls->on_unpublish();
  1369 +
  1370 + // ignore.
  1371 + ret = ERROR_SUCCESS;
  1372 + } else {
  1373 + srs_warn("hls disconnect publisher for video error. ret=%d", ret);
  1374 + return ret;
  1375 + }
1360 } 1376 }
1361 #endif 1377 #endif
1362 1378
@@ -1406,7 +1422,7 @@ int SrsSource::on_video(SrsCommonMessage* __video) @@ -1406,7 +1422,7 @@ int SrsSource::on_video(SrsCommonMessage* __video)
1406 SrsAvcAacCodec codec; 1422 SrsAvcAacCodec codec;
1407 SrsCodecSample sample; 1423 SrsCodecSample sample;
1408 if ((ret = codec.video_avc_demux(msg.payload, msg.size, &sample)) != ERROR_SUCCESS) { 1424 if ((ret = codec.video_avc_demux(msg.payload, msg.size, &sample)) != ERROR_SUCCESS) {
1409 - srs_error("codec demux video failed. ret=%d", ret); 1425 + srs_error("source codec demux video failed. ret=%d", ret);
1410 return ret; 1426 return ret;
1411 } 1427 }
1412 1428
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 73 34 +#define VERSION_REVISION 74
35 // server info. 35 // server info.
36 #define RTMP_SIG_SRS_KEY "SRS" 36 #define RTMP_SIG_SRS_KEY "SRS"
37 #define RTMP_SIG_SRS_ROLE "origin/edge server" 37 #define RTMP_SIG_SRS_ROLE "origin/edge server"