@@ -44,31 +44,49 @@ ov::String LLHlsStream::GetStreamId() const
4444 return ov::String::FormatString (" llhls/%s" , GetUri ().CStr ());
4545}
4646
47+ bool LLHlsStream::CreateOriginSessionPool ()
48+ {
49+ if (_origin_mode == false )
50+ {
51+ return false ;
52+ }
53+
54+ size_t max_pool_size = _worker_count == 0 ? 1 : _worker_count;
55+
56+ // Create sessions up to _worker_count
57+ for (size_t i = 0 ; i < max_pool_size; i++)
58+ {
59+ auto session = LLHlsSession::Create (static_cast <session_id_t >(i),
60+ _origin_mode,
61+ " " ,
62+ GetApplication (),
63+ pub::Stream::GetSharedPtr (),
64+ 0 );
65+ logtd (" LLHlsStream(%s/%s) - Pre-created origin mode session in pool, session id: %zu" , GetApplication ()->GetVHostAppName ().CStr (), GetName ().CStr (), i);
66+ AddSession (session);
67+ }
68+
69+ return true ;
70+ }
71+
4772std::shared_ptr<LLHlsSession> LLHlsStream::GetSessionFromPool ()
4873{
4974 // Max session pool size if _worker_count
50- size_t max_pool_size = _worker_count;
75+ size_t max_pool_size = _worker_count == 0 ? 1 : _worker_count ;
5176
5277 // Get random index
5378 size_t index = ov::Random::GenerateUInt32 () % max_pool_size;
5479
5580 auto session = GetSession (static_cast <session_id_t >(index));
5681 if (session == nullptr )
5782 {
58- // create
59- session = LLHlsSession::Create (static_cast <session_id_t >(index),
60- _origin_mode,
61- " " ,
62- GetApplication (),
63- pub::Stream::GetSharedPtr (),
64- 0 );
65- logtd (" LLHlsStream(%s/%s) - Created origin mode session from pool, session id: %zu" , GetApplication ()->GetVHostAppName ().CStr (), GetName ().CStr (), index);
66- AddSession (session);
83+ return nullptr ;
6784 }
6885
6986 return std::static_pointer_cast<LLHlsSession>(session);
7087}
7188
89+
7290std::shared_ptr<const pub::Stream::DefaultPlaylistInfo> LLHlsStream::GetDefaultPlaylistInfo () const
7391{
7492 static auto info = []() -> std::shared_ptr<const pub::Stream::DefaultPlaylistInfo> {
@@ -96,6 +114,15 @@ bool LLHlsStream::Start()
96114 return false ;
97115 }
98116
117+ if (_origin_mode == true )
118+ {
119+ if (CreateOriginSessionPool () == false )
120+ {
121+ logte (" LLHlsStream(%s/%s) - Failed to create origin session pool" , GetApplication ()->GetVHostAppName ().CStr (), GetName ().CStr ());
122+ return false ;
123+ }
124+ }
125+
99126 auto config = GetApplication ()->GetConfig ();
100127
101128 auto llhls_config = config.GetPublishers ().GetLLHlsPublisher ();
0 commit comments