Skip to content

Commit

Permalink
fix(hls): deadlock caused by missing flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkness4 committed Feb 3, 2024
1 parent bc6728b commit e63e053
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions hls/hls_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func (hls *Downloader) fillQueue(ctx context.Context, urlChan chan<- string) err

newIdx := 0
// Find the last fragment url to resume download
if lastFragmentName != "" && !lastFragmentTime.Equal(timeZero) {
if lastFragmentName != "" &&
((useTimeBasedSorting && !lastFragmentTime.Equal(timeZero)) || !useTimeBasedSorting) {
for i, u := range urls {
parsed, err := url.Parse(u)
if err != nil {
Expand All @@ -170,7 +171,7 @@ func (hls *Downloader) fillQueue(ctx context.Context, urlChan chan<- string) err
}

if lastFragmentName >= fragmentName &&
(useTimeBasedSorting && lastFragmentTime.Compare(fragmentTime) >= 0 || !useTimeBasedSorting) {
((useTimeBasedSorting && lastFragmentTime.Compare(fragmentTime) >= 0) || !useTimeBasedSorting) {
newIdx = i + 1
}
}
Expand All @@ -197,14 +198,16 @@ func (hls *Downloader) fillQueue(ctx context.Context, urlChan chan<- string) err
Msg("failed to parse fragment URL, skipping")
continue
}
tsI, err := strconv.ParseInt(parsed.Query().Get("time"), 10, 64)
if err != nil {
hls.log.Err(err).
Str("url", u).
Msg("failed to parse fragment URL, time is invalid, considering time now")
lastFragmentTime = time.Now()
} else {
lastFragmentTime = time.Unix(tsI, 0)
if useTimeBasedSorting {
tsI, err := strconv.ParseInt(parsed.Query().Get("time"), 10, 64)
if err != nil {
hls.log.Err(err).
Str("url", u).
Msg("failed to parse fragment URL, time is invalid, considering time now")
useTimeBasedSorting = false
} else {
lastFragmentTime = time.Unix(tsI, 0)
}
}
urlChan <- u
}
Expand Down

0 comments on commit e63e053

Please sign in to comment.