Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLS: restore HLS information when republish stream.(#3088) #3126

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

chundonglinlin
Copy link
Member

Feature

HLS continuous mode: In this mode HLS sequence number is started from where it stopped last time. Old fragments are kept. Default is on.

Configuration

vhost __defaultVhost__ {
    hls {
        enabled         on;
        hls_path        ./objs/nginx/html;
        hls_fragment    10;
        hls_window      60;
        hls_continuous  on;
    }
}

@winlinvip winlinvip force-pushed the develop branch 2 times, most recently from 55dce2c to bc381a0 Compare December 31, 2022 04:40
@winlinvip winlinvip force-pushed the develop branch 3 times, most recently from 4ae67f1 to badf33c Compare January 10, 2023 14:08
@winlinvip winlinvip force-pushed the develop branch 2 times, most recently from 500d8fc to 498ce72 Compare January 11, 2023 02:57
@winlinvip winlinvip force-pushed the develop branch 3 times, most recently from c056094 to 2ac9eb8 Compare March 23, 2023 06:02
@duiniuluantanqin duiniuluantanqin linked an issue Apr 11, 2023 that may be closed by this pull request
@winlinvip
Copy link
Member

winlinvip commented Aug 14, 2023

Due to the HLS state recovery, it is necessary to parse the m3u8 files on the disk, which also involves the recovery of various states of HLS. From a broader perspective, it is not suitable for SRS to do, which is very similar to DVR.

Of course, SRS has also implemented DVR FLV and MP4, because sometimes it is necessary to have various basic functions and capabilities for convenience. Unfortunately, it is not possible to implement a more complete capability in SRS, because SRS is a C++ server, and it is difficult to customize the business.

The best solution is to use Go with SRS in the SRS Stack, just like the recording we implemented in the SRS Stack, which includes recording to local disk, DVR to cloud storage, and even a VoD cloud on-demand system.

In summary: HLS status recovery can be implemented in SRS, but only basic recovery capabilities are implemented to keep it simple, and full coverage testing is required. Complete HLS recovery capabilities are implemented in the SRS Stack.

TRANS_BY_GPT4

@@ -17,5 +17,6 @@ vhost __defaultVhost__ {
hls_path ./objs/nginx/html;
hls_fragment 10;
hls_window 60;
hls_continuous on;
Copy link
Member

@winlinvip winlinvip Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to: hls_recover would be better, corresponding to the panic-recover concept in Go.

TRANS_BY_GPT4

@@ -383,6 +383,167 @@ srs_error_t SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
return err;
}

srs_error_t SrsHlsMuxer::restore_stream()
Copy link
Member

@winlinvip winlinvip Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of this exception recovery, because it is a very commonly used path, must be verified and ensured for correctness through utest, otherwise it is very easy to make mistakes.

From the perspective of utest, it would be best to split this function into two functions, making it easier to mock fr, that is, to read the m3u8 content from memory instead of from the actual file. It's somewhat like this:

srs_error_t SrsHlsMuxer::restore_stream() {
    SrsFileReader fr;
    if ((err = fr.open(m3u8)) != srs_success) {
        return srs_error_wrap(err, "open file");
    }

    return do_restore_stream(&fr);

In this way, a mock can be used in utest to avoid reading the actual file.

VOID TEST() {
    MOCKFileReader fr;
    SrsHlsMuxer muxer;
    muxer.do_restore_stream(&fr);

The above is just an example, you can refer to the Config section, which also requires mocking file reading.

TRANS_BY_GPT4

int nb_fbuf = fr.filesize();
char* fbuf = new char[nb_fbuf];
SrsAutoFreeA(char, fbuf);
if ((err = fr.read(fbuf, nb_fbuf, NULL)) != srs_success) {
Copy link
Member

@winlinvip winlinvip Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to remember there is an auxiliary function like srs read all, which can read all the content of a certain Reader until EOF.

It's a bit like the ioutil.ReadAll(io.Reader) function in Go.

TRANS_BY_GPT4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HLS: Should restore the sequence number when restart
3 participants