Skip to content

Commit

Permalink
Fixed issue where wallclock was not applied to some playlists when mu…
Browse files Browse the repository at this point in the history
…ltiple playlists existed
  • Loading branch information
dimiden committed Feb 17, 2025
1 parent 428852c commit ba7c700
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/projects/publishers/hls/hls_media_playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void HlsMediaPlaylist::SetEndList()

bool HlsMediaPlaylist::OnSegmentCreated(const std::shared_ptr<mpegts::Segment> &segment)
{
OV_ASSERT(_wallclock_offset_ms > 0, "Wallclock offset is not set");
OV_ASSERT(_wallclock_offset_ms != INT64_MIN, "Wallclock offset is not set");

std::lock_guard<std::shared_mutex> lock(_segments_mutex);

Expand Down
3 changes: 2 additions & 1 deletion src/projects/publishers/hls/hls_media_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HlsMediaPlaylist

void AddMediaTrackInfo(const std::shared_ptr<MediaTrack> &track);

int64_t GetWallclockOffset() const { return _wallclock_offset_ms; }
void SetWallclockOffset(int64_t offset_ms) { _wallclock_offset_ms = offset_ms; }

bool OnSegmentCreated(const std::shared_ptr<mpegts::Segment> &segment);
Expand Down Expand Up @@ -63,7 +64,7 @@ class HlsMediaPlaylist
// Segment number : Segment
std::map<uint64_t, std::shared_ptr<mpegts::Segment>> _segments;
mutable std::shared_mutex _segments_mutex;
int64_t _wallclock_offset_ms = 0;
int64_t _wallclock_offset_ms = INT64_MIN;

bool _end_list = false;
};
6 changes: 3 additions & 3 deletions src/projects/publishers/hls/hls_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,14 @@ void HlsStream::OnSegmentCreated(const ov::String &packager_id, const std::share

segment->SetUrl(GetSegmentName(packager_id, segment->GetNumber()));

if (_is_first_segment)
if (playlist->GetWallclockOffset() == INT64_MIN)
{
_is_first_segment = false;

auto first_segment_timestamp_ms = (segment->GetFirstTimestamp() / mpegts::TIMEBASE_DBL) * 1000.0;

auto wallclock_offset_ms = static_cast<int64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(GetInputStreamPublishedTime().time_since_epoch()).count() - first_segment_timestamp_ms);

OV_ASSERT(wallclock_offset_ms != INT64_MIN, "Failed to calculate wallclock offset");

playlist->SetWallclockOffset(wallclock_offset_ms);
}

Expand Down
4 changes: 1 addition & 3 deletions src/projects/publishers/hls/hls_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,4 @@ class HlsStream final : public pub::Stream, public mpegts::PackagerSink
// Append #EXT-X-ENDLIST all chunklists, and no more update segment and chunklist
bool _concluded = false;
mutable std::shared_mutex _concluded_lock;

bool _is_first_segment = true;
};
};

0 comments on commit ba7c700

Please sign in to comment.