Skip to content

Commit

Permalink
Added CreateDefaultPlaylist option to WebRTC, LLHLS, HLS publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
getroot committed Sep 24, 2024
1 parent 2bb9bbc commit cdc0b62
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 29 deletions.
10 changes: 10 additions & 0 deletions misc/conf_examples/Edge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<Rtx>false</Rtx>
<Ulpfec>false</Ulpfec>
<JitterBuffer>false</JitterBuffer>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist>
</WebRTC>
<LLHLS>
<ChunkDuration>0.5</ChunkDuration>
Expand All @@ -229,7 +230,16 @@
<CrossDomains>
<Url>*</Url>
</CrossDomains>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist> <!-- llhls.m3u8 -->
</LLHLS>
<HLS>
<SegmentCount>4</SegmentCount>
<SegmentDuration>4</SegmentDuration>
<CrossDomains>
<Url>*</Url>
</CrossDomains>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist> <!-- ts:playlist.m3u8 -->
</HLS>
</Publishers>
</Application>
</Applications>
Expand Down
16 changes: 16 additions & 0 deletions misc/conf_examples/Origin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@
<Rtx>false</Rtx>
<Ulpfec>false</Ulpfec>
<JitterBuffer>false</JitterBuffer>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist>
</WebRTC>
<LLHLS>
<OriginMode>true</OriginMode>
Expand All @@ -373,7 +374,22 @@
<CrossDomains>
<Url>*</Url>
</CrossDomains>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist> <!-- llhls.m3u8 -->
</LLHLS>
<HLS>
<SegmentCount>4</SegmentCount>
<SegmentDuration>4</SegmentDuration>
<!-- <DVR>
<Enable>true</Enable>
<EventPlaylistType>false</EventPlaylistType>
<TempStoragePath>/tmp/ome_dvr/</TempStoragePath>
<MaxDuration>600</MaxDuration>
</DVR> -->
<CrossDomains>
<Url>*</Url>
</CrossDomains>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist> <!-- ts:playlist.m3u8 -->
</HLS>
</Publishers>
</Application>
</Applications>
Expand Down
17 changes: 17 additions & 0 deletions misc/conf_examples/Server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
<Rtx>false</Rtx>
<Ulpfec>false</Ulpfec>
<JitterBuffer>false</JitterBuffer>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist>
</WebRTC>
<LLHLS>
<ChunkDuration>0.5</ChunkDuration>
Expand All @@ -545,7 +546,23 @@
<CrossDomains>
<Url>*</Url>
</CrossDomains>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist> <!-- llhls.m3u8 -->
</LLHLS>
<HLS>
<SegmentCount>4</SegmentCount>
<SegmentDuration>4</SegmentDuration>
<!-- <DVR>
<Enable>true</Enable>
<EventPlaylistType>false</EventPlaylistType>
<TempStoragePath>/tmp/ome_dvr/</TempStoragePath>
<MaxDuration>600</MaxDuration>
</DVR> -->
<CrossDomains>
<Url>*</Url>
</CrossDomains>
<CreateDefaultPlaylist>true</CreateDefaultPlaylist> <!-- ts:playlist.m3u8 -->
</HLS>

<!--
<Push>
<StreamMap>
Expand Down
6 changes: 6 additions & 0 deletions src/projects/base/publisher/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ namespace pub
continue;
}

// State::CREATED could be needed for some cases
if (stream->GetState() == Stream::State::ERROR || stream->GetState() == Stream::State::STOPPED)
{
continue;
}

if (media_packet->GetMediaType() == cmn::MediaType::Video)
{
stream->SendVideoFrame(stream_data->_media_packet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace cfg
int _segment_duration = 5;
Dvr _dvr;
DefaultQueryString _default_query_string;
bool _create_default_playlist = true;

public:
PublisherType GetType() const override
Expand All @@ -39,6 +40,8 @@ namespace cfg
CFG_DECLARE_CONST_REF_GETTER_OF(GetSegmentDuration, _segment_duration)
CFG_DECLARE_CONST_REF_GETTER_OF(GetDvr, _dvr)
CFG_DECLARE_CONST_REF_GETTER_OF(GetDefaultQueryString, _default_query_string)
CFG_DECLARE_CONST_REF_GETTER_OF(ShouldCreateDefaultPlaylist, _create_default_playlist)


protected:
void MakeList() override
Expand All @@ -50,6 +53,7 @@ namespace cfg
Register<Optional>("CrossDomains", &_cross_domains);
Register<Optional>("DVR", &_dvr);
Register<Optional>("DefaultQueryString", &_default_query_string);
Register<Optional>("CreateDefaultPlaylist", &_create_default_playlist);
}
};
} // namespace pub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace cfg
bool _server_time_based_segment_numbering = false;
bool _enable_preload_hint = true;
DefaultQueryString _default_query_string;
bool _create_default_playlist = true;

public:
PublisherType GetType() const override
Expand All @@ -59,6 +60,7 @@ namespace cfg
CFG_DECLARE_CONST_REF_GETTER_OF(GetDrm, _drm)
CFG_DECLARE_CONST_REF_GETTER_OF(IsPreloadHintEnabled, _enable_preload_hint)
CFG_DECLARE_CONST_REF_GETTER_OF(GetDefaultQueryString, _default_query_string)
CFG_DECLARE_CONST_REF_GETTER_OF(ShouldCreateDefaultPlaylist, _create_default_playlist)

protected:
void MakeList() override
Expand All @@ -78,6 +80,7 @@ namespace cfg
Register<Optional>("DRM", &_drm);
Register<Optional>("EnablePreloadHint", &_enable_preload_hint);
Register<Optional>("DefaultQueryString", &_default_query_string);
Register<Optional>("CreateDefaultPlaylist", &_create_default_playlist);
}
};
} // namespace pub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace cfg
CFG_DECLARE_CONST_REF_GETTER_OF(IsJitterBufferEnabled, _jitter_buffer)
CFG_DECLARE_CONST_REF_GETTER_OF(GetPlayoutDelay, _playout_delay)
CFG_DECLARE_CONST_REF_GETTER_OF(GetBandwidthEstimationType, _bandwidth_estimation_type)
CFG_DECLARE_CONST_REF_GETTER_OF(ShouldCreateDefaultPlaylist, _create_default_playlist)

protected:
void MakeList() override
Expand All @@ -60,6 +61,7 @@ namespace cfg
Register<Optional>("Rtx", &_rtx);
Register<Optional>("Ulpfec", &_ulpfec);
Register<Optional>("PlayoutDelay", &_playout_delay);
Register<Optional>("CreateDefaultPlaylist", &_create_default_playlist);
Register<Optional>("BandwidthEstimation", &_bwe,
[=]() -> std::shared_ptr<ConfigError> {
return nullptr;
Expand Down Expand Up @@ -92,6 +94,7 @@ namespace cfg

WebRtcBandwidthEstimationType _bandwidth_estimation_type = WebRtcBandwidthEstimationType::REMB;
PlayoutDelay _playout_delay;
bool _create_default_playlist = true;
};
} // namespace pub
} // namespace app
Expand Down
16 changes: 15 additions & 1 deletion src/projects/publishers/hls/hls_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,26 @@ bool HlsStream::Start()

_default_option_rewind = _ts_config.GetDefaultQueryString().GetBoolValue("_HLS_rewind", kDefaultHlsRewind);

CreateDefaultPlaylist();
if (_ts_config.ShouldCreateDefaultPlaylist() == true)
{
CreateDefaultPlaylist();
}
else
{
logti("HLS Stream(%s/%s) - Default playlist creation is disabled", GetApplication()->GetVHostAppName().CStr(), GetName().CStr());
if (GetPlaylists().size() == 0)
{
logtw("HLS Stream(%s/%s) - There is no playlist to create packagers, HLSv3 will not work for this stream.", GetApplication()->GetVHostAppName().CStr(), GetName().CStr());
Stop(); // Release resources
return false;
}
}

// Create Packetizer
if (CreatePackagers() == false)
{
logte("Failed to create packetizers");
Stop(); // Release resources
return false;
}

Expand Down
40 changes: 27 additions & 13 deletions src/projects/publishers/llhls/llhls_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,38 @@ bool LLHlsStream::Start()
return false;
}

// If there is no default playlist, make default playlist
// Default playlist is consist of first compatible video and audio track among all tracks
ov::String default_playlist_name = DEFAULT_PLAYLIST_NAME;
auto default_playlist_name_without_ext = default_playlist_name.Substring(0, default_playlist_name.IndexOfRev('.'));
auto default_playlist = Stream::GetPlaylist(default_playlist_name_without_ext);
if (default_playlist == nullptr)

if (llhls_config.ShouldCreateDefaultPlaylist() == true)
{
auto playlist = std::make_shared<info::Playlist>("llhls_default", default_playlist_name_without_ext);
auto rendition = std::make_shared<info::Rendition>("default", first_video_track ? first_video_track->GetVariantName() : "", first_audio_track ? first_audio_track->GetVariantName() : "");
// If there is no default playlist, make default playlist
// Default playlist is consist of first compatible video and audio track among all tracks
ov::String default_playlist_name = DEFAULT_PLAYLIST_NAME;
auto default_playlist_name_without_ext = default_playlist_name.Substring(0, default_playlist_name.IndexOfRev('.'));
auto default_playlist = Stream::GetPlaylist(default_playlist_name_without_ext);
if (default_playlist == nullptr)
{
auto playlist = std::make_shared<info::Playlist>("llhls_default", default_playlist_name_without_ext);
auto rendition = std::make_shared<info::Rendition>("default", first_video_track ? first_video_track->GetVariantName() : "", first_audio_track ? first_audio_track->GetVariantName() : "");

playlist->AddRendition(rendition);
playlist->AddRendition(rendition);

AddPlaylist(playlist);
AddPlaylist(playlist);

auto master_playlist = CreateMasterPlaylist(playlist);
auto master_playlist = CreateMasterPlaylist(playlist);

std::lock_guard<std::mutex> guard(_master_playlists_lock);
_master_playlists[default_playlist_name] = master_playlist;
std::lock_guard<std::mutex> guard(_master_playlists_lock);
_master_playlists[default_playlist_name] = master_playlist;
}
}
else
{
logti("LLHLS stream [%s/%s] - Default playlist creation is disabled.", GetApplication()->GetVHostAppName().CStr(), GetName().CStr());
if (GetPlaylists().size() == 0)
{
logtw("LLHLS stream [%s/%s] - There is no playlist, LLHLS will not work for this stream", GetApplication()->GetVHostAppName().CStr(), GetName().CStr());
Stop(); // Release all resources
return false;
}
}

// Select the dump setting for this stream.
Expand Down
43 changes: 28 additions & 15 deletions src/projects/publishers/webrtc/rtc_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,39 @@ bool RtcStream::Start()
}
}

// Create Default Playlist for no file name (ws://domain/app/stream)
_default_playlist_name = "webrtc_default";

auto default_playlist = GetPlaylist(_default_playlist_name);
if (default_playlist == nullptr)
if (webrtc_config.ShouldCreateDefaultPlaylist() == true)
{
auto playlist = std::make_shared<info::Playlist>("webrtc_default", _default_playlist_name);
auto rendition = std::make_shared<info::Rendition>("default", _first_video_track ? _first_video_track->GetVariantName() : "", _first_audio_track ? _first_audio_track->GetVariantName() : "");
// Create Default Playlist for no file name (ws://domain/app/stream)
_default_playlist_name = "webrtc_default";

auto default_playlist = GetPlaylist(_default_playlist_name);
if (default_playlist == nullptr)
{
auto playlist = std::make_shared<info::Playlist>("webrtc_default", _default_playlist_name);
auto rendition = std::make_shared<info::Rendition>("default", _first_video_track ? _first_video_track->GetVariantName() : "", _first_audio_track ? _first_audio_track->GetVariantName() : "");

playlist->AddRendition(rendition);
playlist->SetWebRtcAutoAbr(false);
playlist->AddRendition(rendition);
playlist->SetWebRtcAutoAbr(false);

AddPlaylist(playlist);
}
AddPlaylist(playlist);
}

auto rtc_master_playlist = CreateRtcMasterPlaylist(_default_playlist_name);
auto rtc_master_playlist = CreateRtcMasterPlaylist(_default_playlist_name);

// lock
std::lock_guard<std::shared_mutex> lock(_rtc_master_playlist_map_lock);
_rtc_master_playlist_map[_default_playlist_name] = rtc_master_playlist;
// lock
std::lock_guard<std::shared_mutex> lock(_rtc_master_playlist_map_lock);
_rtc_master_playlist_map[_default_playlist_name] = rtc_master_playlist;
}
else
{
logti("RtcStream(%s/%s) - Default playlist creation is disabled", GetApplication()->GetVHostAppName().CStr(), GetName().CStr());
if (GetPlaylists().size() == 0)
{
logtw("RtcStream(%s/%s) - There is no playlist, WebRTC will not work for this stream.", GetApplication()->GetVHostAppName().CStr(), GetName().CStr());
Stop(); // Release resources
return false;
}
}

logti("WebRTC Stream has been created : %s/%u\nRtx(%s) Ulpfec(%s) JitterBuffer(%s) PlayoutDelay(%s min:%d max: %d)",
GetName().CStr(), GetId(),
Expand Down

0 comments on commit cdc0b62

Please sign in to comment.