Skip to content

Commit

Permalink
Merge pull request #1329 from CastagnaIT/fix_hls_audio
Browse files Browse the repository at this point in the history
[backport] Fallback to ADTS sample reader when TS initialization fails
  • Loading branch information
glennguy authored Jul 18, 2023
2 parents a5c2511 + 5790b88 commit 3d7d9d8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool CInputStreamAdaptive::OpenStream(int streamid)
bool needRefetch = false; //Make sure that Kodi fetches changes
stream->m_isEnabled = true;

const adaptive::AdaptiveTree::Representation* rep(stream->m_adStream.getRepresentation());
adaptive::AdaptiveTree::Representation* rep = stream->m_adStream.getRepresentation();

// If we select a dummy (=inside video) stream, open the video part
// Dummy streams will be never enabled, they will only enable / activate audio track.
Expand Down Expand Up @@ -337,12 +337,27 @@ bool CInputStreamAdaptive::OpenStream(int streamid)
stream->SetReader(std::make_unique<CTSSampleReader>(
stream->GetAdByteStream(), stream->m_info.GetStreamType(), streamid, mask));

if (!stream->GetReader()->Initialize())
if (stream->GetReader()->Initialize())
{
m_session->OnSegmentChanged(&stream->m_adStream);
}
else if (stream->m_adStream.get_type() == adaptive::AdaptiveTree::AUDIO)
{
// If TSSampleReader fail, try fallback to ADTS
//! @todo: we should have an appropriate file type check
//! e.g. with HLS we determine the container type from file extension
//! in the url address, but .ts file could have ADTS
LOG::LogF(LOGWARNING, "Cannot initialize TS sample reader, fallback to ADTS sample reader");
rep->containerType_ = adaptive::AdaptiveTree::CONTAINERTYPE_ADTS;

stream->GetAdByteStream()->Seek(0); // Seek because bytes are consumed from previous reader
stream->SetReader(std::make_unique<CADTSSampleReader>(stream->GetAdByteStream(), streamid));
}
else
{
stream->Disable();
return false;
}
m_session->OnSegmentChanged(&stream->m_adStream);
}
else if (rep->containerType_ == adaptive::AdaptiveTree::CONTAINERTYPE_ADTS)
{
Expand Down

0 comments on commit 3d7d9d8

Please sign in to comment.