Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions AampCacheHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,19 @@ void AampCacheHandler::StopPlaylistCache( void )
mCondVar.notify_one();
}

bool AampCacheHandler::RetrieveFromPlaylistCache( const std::string &url, AampGrowableBuffer* buffer, std::string& effectiveUrl, AampMediaType mediaType )
bool AampCacheHandler::RetrieveFromPlaylistCache(std::string url, AampGrowableBuffer* buffer, std::string& effectiveUrl, AampMediaType mediaType)
{
bool ret = false;
std::lock_guard<std::mutex> lock(mCacheAccessMutex);
AampCachedData *cachedData = mPlaylistCache.Find(url);
if( cachedData )
if (cachedData)
{
effectiveUrl = cachedData->effectiveUrl;
if( effectiveUrl.empty() )
{
effectiveUrl = url;
}
effectiveUrl = cachedData->effectiveUrl.empty() ? url : cachedData->effectiveUrl;
buffer->Clear();
buffer->AppendBytes( cachedData->buffer->GetPtr(), cachedData->buffer->GetLen() );
buffer->AppendBytes(cachedData->buffer->GetPtr(), cachedData->buffer->GetLen());
// below fails when playing an HLS playlist directly, then seeking or retuning
// assert( mediaType == cachedData->mediaType );
AAMPLOG_TRACE( "%s %s found", GetMediaTypeName(cachedData->mediaType), url.c_str() );
AAMPLOG_TRACE("%s %s found", GetMediaTypeName(cachedData->mediaType), url.c_str());
ret = true;
}
else
Expand Down Expand Up @@ -119,24 +115,17 @@ void AampCacheHandler::InsertToInitFragCache( const std::string &url, const Aamp
mInitFragmentCache.Insert( url, buffer, effectiveUrl, mediaType );
}

bool AampCacheHandler::RetrieveFromInitFragmentCache(const std::string &url, AampGrowableBuffer* buffer, std::string& effectiveUrl)
bool AampCacheHandler::RetrieveFromInitFragmentCache(std::string url, AampGrowableBuffer* buffer, std::string& effectiveUrl)
{
bool ret = false;
std::lock_guard<std::mutex> lock(mCacheAccessMutex);
AampCachedData *cachedData = mInitFragmentCache.Find(url);
if( cachedData )
if (cachedData)
{
std::shared_ptr<AampGrowableBuffer> buf = cachedData->buffer;
if (cachedData->effectiveUrl.empty())
{
effectiveUrl = url;
}
else
{
effectiveUrl = cachedData->effectiveUrl;
}
effectiveUrl = cachedData->effectiveUrl.empty() ? url : cachedData->effectiveUrl;
buffer->Clear();
buffer->AppendBytes( buf->GetPtr(), buf->GetLen() );
buffer->AppendBytes(buf->GetPtr(), buf->GetLen());
AAMPLOG_INFO("%s %s found", GetMediaTypeName(cachedData->mediaType), url.c_str());
ret = true;
}
Expand Down
4 changes: 2 additions & 2 deletions AampCacheHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class AampCacheHandler
* @param[out] effectiveUrl - Final URL
* @return true: found, false: not found
*/
bool RetrieveFromPlaylistCache( const std::string &url, AampGrowableBuffer* buffer, std::string& effectiveUrl, AampMediaType mediaType );
bool RetrieveFromPlaylistCache(std::string url, AampGrowableBuffer* buffer, std::string& effectiveUrl, AampMediaType mediaType);

/**
* @brief Remove playlist from cache
Expand Down Expand Up @@ -493,7 +493,7 @@ class AampCacheHandler
*
* @return true: found, false: not found
*/
bool RetrieveFromInitFragmentCache(const std::string &url, AampGrowableBuffer* buffer, std::string& effectiveUrl);
bool RetrieveFromInitFragmentCache(std::string url, AampGrowableBuffer* buffer, std::string& effectiveUrl);

/**
* @brief set max initialization fragments allowed in cache (per track)
Expand Down
8 changes: 8 additions & 0 deletions StreamAbstractionAAMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,14 @@ class StreamAbstractionAAMP : public AampLicenseFetcher
*/
void SetCurrentAudioTrackIndex(std::string& index) { mAudioTrackIndex = index; }

/**
* @brief Set current text track index
*
* @param[in] string index
* @return void
*/
void SetCurrentTextTrackIndex(std::string& index) { mTextTrackIndex = index; }

/**
* @brief Change muxed audio track index
*
Expand Down
26 changes: 17 additions & 9 deletions fragmentcollector_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3450,19 +3450,26 @@ AAMPStatusType StreamAbstractionAAMP_HLS::Init(TuneType tuneType)
// Generate audio and text track structures
PopulateAudioAndTextTracks();

// Select preferred text track based on user language preferences
TextTrackInfo selectedTextTrack;
if (SelectPreferredTextTrack(selectedTextTrack))
if (aamp->GetPreferredTextTrack().index.empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be tested in an L1 test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth while given its covered by the L3 test ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the existing tests this would be very complex. We should refactor this 1.2k line function and add L1 tests at that stage.

Open to suggestions though ?

{
AAMPLOG_INFO("Selected text track - lang:%s, name:%s, rendition:%s",
selectedTextTrack.language.c_str(),
selectedTextTrack.name.c_str(),
selectedTextTrack.rendition.c_str());
aamp->SetPreferredTextTrack(std::move(selectedTextTrack));
// Select preferred text track based on user language preferences
TextTrackInfo selectedTextTrack;
if (SelectPreferredTextTrack(selectedTextTrack))
{
AAMPLOG_INFO("Selected text track - lang:%s, name:%s, rendition:%s",
selectedTextTrack.language.c_str(),
selectedTextTrack.name.c_str(),
selectedTextTrack.rendition.c_str());
aamp->SetPreferredTextTrack(std::move(selectedTextTrack));
}
else
{
AAMPLOG_WARN("No text track matched user preferences, will use default selection");
}
}
else
{
AAMPLOG_WARN("No text track matched user preferences, will use default selection");
AAMPLOG_INFO("Preferred text track set, so not looking at the list of preferred languages");
}

// Configure Subtitle track for the playback
Expand Down Expand Up @@ -7593,6 +7600,7 @@ void StreamAbstractionAAMP_HLS::SelectSubtitleTrack()
bool StreamAbstractionAAMP_HLS::SelectPreferredTextTrack(TextTrackInfo &selectedTextTrack)
{
std::vector<TextTrackInfo> availableTracks = GetAvailableTextTracks();

if (availableTracks.empty())
{
AAMPLOG_WARN("No text tracks available");
Expand Down
2 changes: 2 additions & 0 deletions priv_aamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12611,6 +12611,8 @@ void PrivateInstanceAAMP::SetPreferredTextLanguages(const char *param)
if (closedCaptionTrackId >= 0)
{
TextTrackInfo track = trackInfo[closedCaptionTrackId];
SetPreferredTextTrack(track); // If we found the track via CheckPreferredTextLanguages() it may not be the current preferred text track
mpStreamAbstractionAAMP->SetCurrentTextTrackIndex(track.index); // Normally set as part of parsing the manifest during tune, but if we don't tune we should keep it consistent
SetClosedCaptionsFromTextTrack(track);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/utests/fakes/FakeAampCacheHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void AampCacheHandler::StopPlaylistCache()
{
}

bool AampCacheHandler::RetrieveFromPlaylistCache(const std::string &url, AampGrowableBuffer* buffer, std::string& effectiveUrl, AampMediaType mediaType)
bool AampCacheHandler::RetrieveFromPlaylistCache(std::string url, AampGrowableBuffer* buffer, std::string& effectiveUrl, AampMediaType mediaType)
{
return false;
}
Expand All @@ -65,7 +65,7 @@ void AampCacheHandler::InsertToInitFragCache( const std::string &url, const Aamp
{
}

bool AampCacheHandler::RetrieveFromInitFragmentCache(const std::string &url, AampGrowableBuffer* buffer, std::string& effectiveUrl)
bool AampCacheHandler::RetrieveFromInitFragmentCache(std::string url, AampGrowableBuffer* buffer, std::string& effectiveUrl)
{
return false;
}
Expand Down
Loading