ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.7k stars 5.28k forks source link

SrsLiveSource cleanup is different to SrsSrtSource #4093

Closed lizhongjie9999 closed 1 week ago

lizhongjie9999 commented 1 week ago

Release v6.0-d5

The original code:

void SrsLiveSource::on_consumer_destroy(SrsLiveConsumer* consumer)
{
    ...
    if (consumers.empty()) {
        play_edge->on_all_client_stop();

        // For edge server, the stream die when the last player quit, because the edge stream is created by player
        // activities, so it should die when all players quit.
        if (_srs_config->get_vhost_is_edge(req->vhost)) {
            stream_die_at_ = srs_get_system_time();
        }

        // When no players, the publisher is idle now.
        publisher_idle_at_ = srs_get_system_time();
    }
}

Code that should be changed, Similar to SrsSrtSource::on_consumer_destroy():

void SrsLiveSource::on_consumer_destroy(SrsLiveConsumer* consumer)
{
    ...
    if (consumers.empty()) {
        play_edge->on_all_client_stop();

        // For edge server, the stream die when the last player quit, because the edge stream is created by player
        // activities, so it should die when all players quit.
        if (_srs_config->get_vhost_is_edge(req->vhost)) {
            stream_die_at_ = srs_get_system_time();
        } else if (_can_publish) {  // should die when no publishers and consumers.
            stream_die_at_ = srs_get_system_time();
        }

        // When no players, the publisher is idle now.
        publisher_idle_at_ = srs_get_system_time();
    }
}
winlinvip commented 1 week ago

LiveSource is designed for scheduled cleanup, which differs from the cleanup method used by SrtSource. In the future, it will be modified for consistency.

TRANS_BY_GPT4

winlinvip commented 1 week ago

LiveSource use a timer to cleanup, because we need to dispose HLS files while disposing source. So SRTSource should follow the same rule to LiveSource.

lizhongjie9999 commented 1 week ago

Call the SrsLiveSource::on_consumer_destroy(), both the consumer and publisher are gone, stream_dieat needs to be set, or the timer will not clean up the SrsLiveSource