Skip to content

VPAAMP 293 : Audio loss occurs when switching audio tracks in multiview streams - #1775

Closed
Abhi-jith-S wants to merge 6 commits into
support/2.9.0_8.3_2.9.5vfrom
feature/VPAAMP-293_flex_release
Closed

VPAAMP 293 : Audio loss occurs when switching audio tracks in multiview streams#1775
Abhi-jith-S wants to merge 6 commits into
support/2.9.0_8.3_2.9.5vfrom
feature/VPAAMP-293_flex_release

Conversation

@Abhi-jith-S

@Abhi-jith-S Abhi-jith-S commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Reason for change : To overwrite track-id for audio tracks incase of mismatch. Since the audio track mismatch caused audio loss while tile switching in mutliview streams

Test Procedure : Refer ticket

Signed-off-by: Abhi-jith-S <abhijithssa7@gmail.com>
Signed-off-by: Abhi-jith-S <abhijithssa7@gmail.com>
Signed-off-by: Abhi-jith-S <abhijithssa7@gmail.com>
Signed-off-by: Abhi-jith-S <abhijithssa7@gmail.com>
Signed-off-by: Abhi-jith-S <abhijithssa7@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Addresses audio loss during audio-track switches in multiview MP4 streams by detecting track-id mismatches and rewriting the fragment track-id to match the currently selected audio track.

Changes:

  • Extends track-id inspection/overwrite logic to include non-init audio fragments in MediaStreamContext::CacheFragment.
  • Enhances ISO-BMFF parsing to extract track-id from tfhd when trak isn’t present (typical for media fragments).
  • Adds TfhdBox support for reading/overwriting TFHD track-id in-place during box construction.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
MediaStreamContext.cpp Runs track-id parsing for audio media fragments and overwrites mismatched audio track-id.
isobmff/isobmffbuffer.cpp Adds TFHD-based fallback for track-id extraction in fragmented MP4.
isobmff/isobmffbox.h Extends TfhdBox API/state to track and rewrite TFHD track-id.
isobmff/isobmffbox.cpp Implements TFHD track-id capture + optional overwrite during TFHD construction.
Comments suppressed due to low confidence (2)

MediaStreamContext.cpp:233

  • This INFO log now runs for every audio fragment (not just init), which can be very noisy; it also uses %d for a uint32_t track_id. Consider lowering to DEBUG and using correct format specifiers, and avoid setting mIsTrackIdMismatch for the overWriteTrackId (encrypted-header) use-case.
					bool trackIdUpdated = false;
					AAMPLOG_INFO("Audio track_id read from  fragment: %d and track id stored in AAMP instance: %d", track_id, aamp->mCurrentAudioTrackId);
					if(aamp->mCurrentAudioTrackId != -1 && track_id != aamp->mCurrentAudioTrackId)
					{
							buffer.parseBuffer(false, aamp->mCurrentAudioTrackId);
							trackIdUpdated = true;
							aamp->mIsTrackIdMismatch = true;
							AAMPLOG_DEBUG("TrackId mismatch detected for audio, current track_id: %d, next period track_id: %d", aamp->mCurrentAudioTrackId, track_id);
					}

MediaStreamContext.cpp:167

  • This condition now includes eMEDIATYPE_AUDIO, so the subsequent track-id extraction runs for non-init audio fragments as well. In that path, IsoBmffBuffer::getTrack_id() can fail (it returns bool) but its return value is currently ignored, leaving track_id as 0 and potentially corrupting mCurrentAudioTrackId / overwrite behavior. Please guard the track-id logic when getTrack_id() returns false.
			if ((actualType == eMEDIATYPE_INIT_VIDEO || actualType == eMEDIATYPE_INIT_AUDIO || actualType == eMEDIATYPE_AUDIO || actualType == eMEDIATYPE_INIT_SUBTITLE) && ret) // Only if init fragment successful or available from cache

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread MediaStreamContext.cpp Outdated
Comment thread isobmff/isobmffbuffer.cpp
Comment on lines +409 to +421
else if (IS_TYPE(box->getType(), Box::TFHD))
{
try {
TfhdBox *tfhdBox = dynamic_cast<TfhdBox *>(box);
if(tfhdBox)
{
tfhdTrackId = tfhdBox->getTrackId();
tfhdTrackFound = true;
}
} catch (std::bad_cast& bc){
//do nothing
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping the try-catch block same as trak box construction

Comment thread isobmff/isobmffbox.cpp
Comment on lines +1159 to +1171
TfhdBox* TfhdBox::constructTfhdBox(uint32_t sz, uint8_t *ptr, int newTrackId)
{
auto start = ptr;
uint8_t version = READ_VERSION(ptr); // 8
uint32_t flags = READ_FLAGS(ptr); //24

uint8_t* trackId_loc{ptr};
uint32_t trackId = READ_U32(ptr);
if(-1 != newTrackId)
{
WRITE_U32(trackId_loc, static_cast<uint32_t>(newTrackId));
trackId = static_cast<uint32_t>(newTrackId);
}
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

-Removed unused headers
-Removed unused tfhd track-id set function
-Kept tfhd box const. consistent with existing trak box const.

Signed-off-by: Abhi-jith-S <abhijithssa7@gmail.com>
@Abhi-jith-S

Copy link
Copy Markdown
Contributor Author

Closing the PR as we are waiting for approval of fix

@Abhi-jith-S Abhi-jith-S closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants