Skip to content

Commit a4be45f

Browse files
committed
Add unpublishing state to avoid dispose during on_hls.
1 parent 4df280a commit a4be45f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

trunk/src/app/srs_app_hls.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ SrsHls::SrsHls()
11361136

11371137
enabled = false;
11381138
disposable = false;
1139+
unpublishing_ = false;
11391140
last_update_time = 0;
11401141
hls_dts_directly = false;
11411142

@@ -1174,14 +1175,17 @@ void SrsHls::dispose()
11741175
srs_error_t SrsHls::cycle()
11751176
{
11761177
srs_error_t err = srs_success;
1177-
1178+
11781179
if (last_update_time <= 0) {
11791180
last_update_time = srs_get_system_time();
11801181
}
11811182

11821183
if (!req) {
11831184
return err;
11841185
}
1186+
1187+
// When unpublishing, we must wait for it done.
1188+
if (unpublishing_) return err;
11851189

11861190
srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost);
11871191
if (hls_dispose <= 0) {
@@ -1191,12 +1195,12 @@ srs_error_t SrsHls::cycle()
11911195
return err;
11921196
}
11931197
last_update_time = srs_get_system_time();
1194-
1198+
11951199
if (!disposable) {
11961200
return err;
11971201
}
11981202
disposable = false;
1199-
1203+
12001204
srs_trace("hls cycle to dispose hls %s, timeout=%dms", req->get_stream_url().c_str(), hls_dispose);
12011205
dispose();
12021206

@@ -1243,6 +1247,8 @@ srs_error_t SrsHls::on_publish()
12431247

12441248
// if enabled, open the muxer.
12451249
enabled = true;
1250+
// Reset the unpublishing state.
1251+
unpublishing_ = false;
12461252

12471253
// ok, the hls can be dispose, or need to be dispose.
12481254
disposable = true;
@@ -1258,13 +1264,18 @@ void SrsHls::on_unpublish()
12581264
if (!enabled) {
12591265
return;
12601266
}
1267+
1268+
// During unpublishing, there maybe callback that switch to other coroutines.
1269+
if (unpublishing_) return;
1270+
unpublishing_ = true;
12611271

12621272
if ((err = controller->on_unpublish()) != srs_success) {
12631273
srs_warn("hls: ignore unpublish failed %s", srs_error_desc(err).c_str());
12641274
srs_freep(err);
12651275
}
12661276

12671277
enabled = false;
1278+
unpublishing_ = false;
12681279
}
12691280

12701281
srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)

trunk/src/app/srs_app_hls.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ class SrsHls
277277
SrsRequest* req;
278278
bool enabled;
279279
bool disposable;
280+
bool unpublishing_;
280281
srs_utime_t last_update_time;
281282
private:
282283
// If the diff=dts-previous_audio_dts is about 23,

0 commit comments

Comments
 (0)