@@ -8151,10 +8151,19 @@ void PrivateInstanceAAMP::Stop( bool isDestructing )
81518151 {
81528152 std::lock_guard<std::mutex> guard (mMutexPlaystart );
81538153 waitforplaystart.notify_all ();
8154+ AAMPLOG_WARN (" HariPriya Stop: notified PreCache thread, isDestructing=%d" , isDestructing);
81548155 }
81558156 if (mPreCachePlaylistThreadId .joinable ())
81568157 {
8158+ auto joinStartTime = NOW_STEADY_TS_MS;
8159+ AAMPLOG_WARN (" HariPriya Stop: About to join PreCache thread, isDestructing=%d" , isDestructing);
81578160 mPreCachePlaylistThreadId .join ();
8161+ auto joinDuration = NOW_STEADY_TS_MS - joinStartTime;
8162+ AAMPLOG_WARN (" HariPriya Stop: PreCache thread joined after %lld ms, isDestructing=%d" , joinDuration, isDestructing);
8163+ }
8164+ else
8165+ {
8166+ AAMPLOG_INFO (" HariPriya Stop: PreCache thread not joinable, isDestructing=%d" , isDestructing);
81588167 }
81598168
81608169 if (mAampCacheHandler )
@@ -10271,14 +10280,17 @@ void PrivateInstanceAAMP::PreCachePlaylistDownloadTask()
1027110280{
1027210281 // This is the thread function to download all the HLS Playlist in a
1027310282 // differed manner
10283+ AAMPLOG_WARN (" PreCachePlaylistDownloadTask: Thread started" );
1027410284 int maxWindowForDownload = mPreCacheDnldTimeWindow * 60 ; // convert to seconds
1027510285 int szPlaylistCount = (int )mPreCacheDnldList .size ();
1027610286 if (szPlaylistCount)
1027710287 {
1027810288 // First wait for Tune to complete to start this functionality
1027910289 {
1028010290 std::unique_lock<std::mutex> lock (mMutexPlaystart );
10291+ AAMPLOG_WARN (" PreCachePlaylistDownloadTask: Waiting for playstart notification" );
1028110292 waitforplaystart.wait (lock);
10293+ AAMPLOG_WARN (" PreCachePlaylistDownloadTask: Received playstart notification, proceeding" );
1028210294 }
1028310295 // May be Stop is called to release all resources .
1028410296 // Before download , check the state
@@ -10312,7 +10324,25 @@ void PrivateInstanceAAMP::PreCachePlaylistDownloadTask()
1031210324 bool ret = false ;
1031310325 // Using StreamLock to avoid StreamAbstractionAAMP deletion when external player commands or stop call received
1031410326 AcquireStreamLock ();
10327+ auto getFileStartTime = NOW_STEADY_TS_MS;
10328+ AAMPLOG_WARN (" HariPriya PreCachePlaylistDownloadTask: About to call GetFile (network I/O), state=%d" , GetState ());
10329+
10330+ // DEBUG: Simulate slow network to reproduce GC deadlock issue
10331+ // Set AAMP_SIMULATE_SLOW_PRECACHE_MS env var to inject delay (e.g., export AAMP_SIMULATE_SLOW_PRECACHE_MS=5000)
10332+ const char * delayEnv = getenv (" AAMP_SIMULATE_SLOW_PRECACHE_MS" );
10333+ if (delayEnv)
10334+ {
10335+ int delayMs = atoi (delayEnv);
10336+ if (delayMs > 0 )
10337+ {
10338+ AAMPLOG_WARN (" HariPriya PreCachePlaylistDownloadTask: DEBUG - Simulating slow network with %d ms delay" , delayMs);
10339+ std::this_thread::sleep_for (std::chrono::milliseconds (delayMs));
10340+ }
10341+ }
10342+
1031510343 ret = GetFile (newelem.url , newelem.type , &playlistStore, playlistEffectiveUrl, &http_code, &downloadTime, NULL , eCURLINSTANCE_PLAYLISTPRECACHE, true );
10344+ auto getFileDuration = NOW_STEADY_TS_MS - getFileStartTime;
10345+ AAMPLOG_WARN (" HariPriya PreCachePlaylistDownloadTask: GetFile returned after %lld ms, ret=%d, state=%d" , getFileDuration, ret, GetState ());
1031610346 ReleaseStreamLock ();
1031710347 if (ret != false )
1031810348 {
@@ -10337,11 +10367,12 @@ void PrivateInstanceAAMP::PreCachePlaylistDownloadTask()
1033710367 }
1033810368 }
1033910369 }while (idx < mPreCacheDnldList .size () && state != eSTATE_STOPPING && state != eSTATE_IDLE && state != eSTATE_ERROR);
10370+ AAMPLOG_WARN (" HariPriya PreCachePlaylistDownloadTask: Exiting loop, state=%d, idx=%d, size=%zu" , state, idx, mPreCacheDnldList .size ());
1034010371 mPreCacheDnldList .clear ();
1034110372 CurlTerm (eCURLINSTANCE_PLAYLISTPRECACHE);
1034210373 }
1034310374 }
10344- AAMPLOG_WARN (" End of PreCachePlaylistDownloadTask " );
10375+ AAMPLOG_WARN (" PreCachePlaylistDownloadTask: Thread exiting, state=%d " , GetState () );
1034510376}
1034610377
1034710378/* *
0 commit comments