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
@mapengfei53 mapengfei53 force-pushed the bugfix/delay-cleanup branch from 5126fad to 34ad906 Compare April 22, 2022 02:21
@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

@mapengfei53 mapengfei53 force-pushed the bugfix/delay-cleanup branch from 32b58dd to 03c3a1f Compare April 22, 2022 05:05
@winlinvip winlinvip force-pushed the develop branch 11 times, most recently from 9c7a9d0 to 38c3d9f Compare September 2, 2022 14:22
@winlinvip winlinvip force-pushed the develop branch 2 times, most recently from 991fdb5 to 02d47c5 Compare November 23, 2022 03:57
@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
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 29, 2023
@winlinvip winlinvip force-pushed the develop branch 2 times, most recently from 0bb9637 to 2e211f6 Compare August 12, 2024 10:42
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