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: Added delay cleanup old expired ts files #3001

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

Conversation

mapengfei53
Copy link
Contributor

Some player start to play from the first ts file, which might be cleanup.
It's better to delay cleanup the ts files. issues #2999


for (int i = (int)expired_fragments.size() - 1; i >= 0; i--) {
SrsFragment* fragment = expired_fragments[i];
duration += fragment->duration();
Copy link
Member

@winlinvip winlinvip Apr 15, 2022

Choose a reason for hiding this comment

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

Here, duration is used as the time for scheduled cleaning, which is difficult to understand, and there are too many if-else statements, making it very challenging for future maintenance.

A better solution is to send the task of deleting slice files to an asynchronous worker, which will handle recording the time and performing the cleaning.

It's something like this:

void SrsFragmentWindow::clear_expired(bool delete_files, srs_utime_t delay_time)
{
  for (it = expired_fragments.begin(); it != expired_fragments.end(); ++it) {
    SrsFragment* fragment = *it;
    if (!delete_files) {
      continue;
    }
    
    if (delay_time) {
      err = cleanup_worker->unlink_file(filename);
    } else {
      err = fragment->unlink_file();
    }
    if (err != srs_success) {
      srs_warn("Unlink ts failed, %s", srs_error_desc(err).c_str());
      srs_freep(err);
    }

You can use a global cleanup_worker, which is relatively simple.

TRANS_BY_GPT3

Copy link
Contributor Author

@mapengfei53 mapengfei53 Apr 22, 2022

Choose a reason for hiding this comment

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

I added an asynchronous clock to handle expired ts files. If you have time, please take a look. Thank you.

TRANS_BY_GPT3

@winlinvip winlinvip self-assigned this Apr 15, 2022
@winlinvip winlinvip changed the title Added delay cleanup old expired ts files HLS: Added delay cleanup old expired ts files Apr 15, 2022
@winlinvip winlinvip linked an issue Apr 15, 2022 that may be closed by this pull request
@winlinvip winlinvip added Enhancement Improvement or enhancement. Feature It's a new feature. labels Apr 15, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2022

Codecov Report

Merging #3001 (54852b5) into develop (2b2379d) will decrease coverage by 0.04%.
The diff coverage is 3.77%.

❗ Current head 54852b5 differs from pull request most recent head 895acf2. Consider uploading reports for the commit 895acf2 to get more accurate results

@@             Coverage Diff             @@
##           develop    #3001      +/-   ##
===========================================
- Coverage    56.10%   56.06%   -0.05%     
===========================================
  Files          153      153              
  Lines        57561    57609      +48     
===========================================
+ Hits         32294    32296       +2     
- Misses       25267    25313      +46     

| Impacted Files | Coverage Δ | |'

Translated to English while maintaining the markdown structure:

'| Impacted Files | Coverage Δ | |
|---|---|---|
| trunk/src/app/srs_app_config.cpp | 65.38% <0.00%> (-0.18%) | ⬇️ |
| trunk/src/app/srs_app_config.hpp | 100.00% <ø> (ø) | |'

Translated to English while maintaining the markdown structure:

'| trunk/src/app/srs_app_config.hpp | 100.00% <ø> (ø) | |
| trunk/src/app/srs_app_fragment.cpp | 11.90% <0.00%> (-0.30%) | ⬇️ |
| trunk/src/app/srs_app_hls.cpp | 0.00% <0.00%> (ø) | |'

Translated to English while maintaining the markdown structure:

'| trunk/src/app/srs_app_hls.cpp | 0.00% <0.00%> (ø) | |
| trunk/src/app/srs_app_hybrid.cpp | 11.26% <5.88%> (-1.70%) | ⬇️ |


Continue to review full report at Codecov.

Legend - Click here to learn more
| Δ = absolute <relative> (impact), ø = not affected, ? = missing data |

Translated to English while maintaining the markdown structure:

| Δ = absolute <relative> (impact), ø = not affected, ? = missing data |

Powered by Codecov. Last update 2b2379d...895acf2. Read the comment docs.

TRANS_BY_GPT3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement or enhancement. Feature It's a new feature. TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HLS: Support delay cleanup for TS files.
3 participants