KEMBAR78
Do not flush eac3(joc) decoder on reuse by dwhea · Pull Request #1346 · androidx/media · GitHub
Skip to content

Conversation

dwhea
Copy link
Contributor

@dwhea dwhea commented May 6, 2024

eac3(joc) decoders do not need to be flushed to be reused for the next compatible track. This change allows for gapless playback on devices with Dolby decoders that require internal re-initialization on flush.

@icbaker icbaker requested a review from microkatz May 7, 2024 16:14
@microkatz
Copy link
Contributor

Hello @dwhea,

Thank you for creating this pull request! Just to confirm, may I ask if you have any data backing up that the eac3(joc) has independent samples (like xHE-AAC codec)?

@mzchan1
Copy link

mzchan1 commented May 16, 2024

Hi @microkatz,

To respond to your query, eac3-joc frames are structured such that each frame represents an independent time slice (e.g. 32ms of audio) that is encoded such that it does not depend on other frames, and is packaged as a single access unit in container formats such as MP4. eac3-joc is encoded via the Enhanced AC-3 bitstream format which is documented here: https://www.etsi.org/deliver/etsi_ts/102300_102399/102366/01.03.01_60/ts_102366v010301p.pdf

The core problem this pull request solves is to avoid issuing a flush event to the eac3/eac3-joc MediaCodec component under the following playback conditions:

  1. Playing back a playlist containing a series of media assets intended to seamlessly transition from the end of one media asset to the beginning of the next media asset without introducing audible gaps or other audio artifacts.
  2. During streaming audio playback (e.g. via DASH) the switching of representations within an adaptation set does not introduce audible gaps or other audio artifacts, even if the asset switches between eac3 and eac3-joc audio formats.

Please let me know if you have any further queries.

Thanks.

@dwhea
Copy link
Contributor Author

dwhea commented May 22, 2024

Thanks @mzchan1 for responding.

@microkatz
Copy link
Contributor

Hi @dwhea,

Sorry for the delay. Would it be possible to open a new PR from an individual-owned fork? We can't push changes to organization-owned forks like this one unless we have collaborator access. If that's not possible then we can still merge this PR but it will result in an 'evil' merge. See more info here: https://github.com/androidx/media/blob/release/CONTRIBUTING.md#push-access-to-pr-branches

@dwhea
Copy link
Contributor Author

dwhea commented Aug 20, 2024

Hi @microkatz , no problem. We're not able to open PR from individual-owned fork, so merging as an "evil merge" is OK for us. This was discussed between us two parties around January 2024 and we came to that decision then.

}

// For eac3 and eac3-joc formats, adaptation is possible without reconfiguration or flushing.
if (discardReasons == 0 && (MimeTypes.AUDIO_E_AC3_JOC.equals(mimeType)
Copy link
Contributor

@microkatz microkatz Aug 21, 2024

Choose a reason for hiding this comment

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

@dwhea
Do Dolby Audio decoders use any initalization data provided by the stream? Just checking if this check needs to occur after the initialization data comparison right below.

Copy link
Contributor Author

@dwhea dwhea Aug 23, 2024

Choose a reason for hiding this comment

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

There's no initialization data for Dolby codecs.

@microkatz
Copy link
Contributor

Hi @microkatz , no problem. We're not able to open PR from individual-owned fork, so merging as an "evil merge" is OK for us. This was discussed between us two parties around January 2024 and we came to that decision then.

If you are not opening a PR from an individual-owned fork then it still easier for us if given collaborator access. In that way we can submit commits to this branch during the review process.

// For eac3 and eac3-joc formats, adaptation is possible without reconfiguration or flushing.
if (discardReasons == 0 && (MimeTypes.AUDIO_E_AC3_JOC.equals(mimeType)
|| MimeTypes.AUDIO_E_AC3.equals(mimeType))) {
return new DecoderReuseEvaluation(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to add a unit test to the MediaCodecInfoTest file that given a call of canReuseCodec for dolby content of the same mimetype that REUSE_RESULT_YES_WITHOUT_RECONFIGURATION is returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we will add those tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I force pushed a commit to DolbyLaboratories@ade6e4f which rebased to Google upstream main branch, and added the requested tests.

I'm not sure how to update this pull request with those changes. Please advise if I need to do anything, or whether you can pull that new commit into this pull request (or create a new pull request).

Copy link
Contributor

@microkatz microkatz Aug 27, 2024

Choose a reason for hiding this comment

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

I believe that you need to make the commits to your topic branch, DolbyLaboratories:dlb/ddp-gapless, and then rebase the topic branch back onto main. With a git --force push command that should update the PR with your requested commits and update the PR's base commit as main head.

Without the collaborator access I'm unable to do this for you.

I also made a comment in the referenced commit as well.
DolbyLaboratories@ade6e4f#r145885998

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks and sorry for long turnaround time. I've rebased and force pushed the update to the DolbyLaboratories:dlb/ddp-gapless branch.

@benlancaster
Copy link

benlancaster commented Sep 5, 2024

I'm somewhat surprised by this change. My team has observed several cases on many devices where E-AC-3 codecs need not only a flush but also a reconfiguration when transitioning between two E-AC-3 tracks of differing bitrates, or E-AC-3 to E-AC-3+JOC.

@microkatz
Copy link
Contributor

@benlancaster

I'm somewhat surprised by this change. My team has observed several cases on many devices where E-AC-3 codecs need not only a flush but also a reconfiguration when transitioning between two E-AC-3 tracks of differing bitrates, or E-AC-3 to E-AC-3+JOC.

Thanks for the query!

Although not expressly noted in the description, if you check out the proposed commit, you'll see that the new conditional check to reuse the decoder(ln: 482) occurs after the checks on sampleMimetype(ln: 414) and sampleRate(ln: 451). Does this help alleviate your concerns?

@google-oss-bot
Copy link
Collaborator

Hey @dwhea. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@dwhea dwhea force-pushed the dlb/ddp-gapless branch 2 times, most recently from 8d58577 to f5f1ce9 Compare March 20, 2025 02:55
@google-oss-bot
Copy link
Collaborator

Since there haven't been any recent updates here, I am going to close this issue.

@dwhea if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@dwhea
Copy link
Contributor Author

dwhea commented Mar 31, 2025

Hello, please update this issue. I did respond to this issue in #1346 (comment) 2 weeks ago but this seems to have been ignored. @microkatz could you please take a look?

@microkatz microkatz reopened this Apr 2, 2025
@dwhea dwhea force-pushed the dlb/ddp-gapless branch 2 times, most recently from bc3f515 to a797ad3 Compare July 8, 2025 02:47
@microkatz
Copy link
Contributor

@dwhea

Thanks for the update for AC-4. One last question to be certain. Would the decoders for these formats need reconfiguration or flushing if the profiles or levels are different from the old to new formats?

eac3(joc) and ac4 decoders (for the same profile and level content) do
not need to be flushed to be reused for the next compatible track or
across adapative bitrate transitions. This change allows for gapless
playback on devices with Dolby decoders that require internal
re-initialization on flush.

This change introduces a codec check in canReuseCodec, in addition to
the existing mimeType check, as within the same mimeType, such as
AC-4, there can be codec changes (such as between AC-4 ac-4.02.01.04
for Atmos Objective Based Immersive and ac-4.02.02.00 for AC-4
Immersive Stereo) that may require decoder reinitialization for
correct decoding.
@dwhea dwhea force-pushed the dlb/ddp-gapless branch from a797ad3 to 9b1f1b1 Compare July 11, 2025 06:59
@dwhea
Copy link
Contributor Author

dwhea commented Jul 11, 2025

@dwhea

Thanks for the update for AC-4. One last question to be certain. Would the decoders for these formats need reconfiguration or flushing if the profiles or levels are different from the old to new formats?

It's possible that the AC-4 decoder needs re-initialization on AC-4 profile or level change. Although this is not always the case, to be conservative, I've updated the PR to check the format codec string, which encapsulates the AC-4 content profile and level information, and require re-initialization whenever this changes.

@copybara-service copybara-service bot merged commit 580f994 into androidx:main Aug 14, 2025
1 check passed
dwhea added a commit to DolbyLaboratories/media that referenced this pull request Aug 19, 2025
eac3(joc) and ac4 decoders (for the same profile and level content) do
not need to be flushed to be reused for the next compatible track or
across adapative bitrate transitions. This change allows for gapless
playback on devices with Dolby decoders that require internal
re-initialization on flush.

This change introduces a codec check in canReuseCodec, in addition to
the existing mimeType check, as within the same mimeType, such as
AC-4, there can be codec changes (such as between AC-4 ac-4.02.01.04
for Atmos Objective Based Immersive and ac-4.02.02.00 for AC-4
Immersive Stereo) that may require decoder reinitialization for
correct decoding.

This is a cherry-pick of 9b1f1b1 from
androidx#1346 and
9b1f1b1
.
nift4 pushed a commit to nift4/media that referenced this pull request Sep 21, 2025
@androidx androidx locked and limited conversation to collaborators Oct 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants