Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DTS Express Audio Buffer Underflow Issue. #650

Merged

Conversation

cedricxperi
Copy link
Contributor

Problem Description
DASH DTS Express audio playback results in buffer underrun issues. This can be heard as regular blips in the output.

Solution
DTS Express audio for streaming, uses a frame size (number of audio samples per channel per frame) of 4096. This requires a higher multiple for the buffersize computation.

@cedricxperi
Copy link
Contributor Author

cedricxperi commented Sep 13, 2023

@tianyif This is the same pull request as #450 which you were assigned in June. I re-applied the changes to the latest main branch. Kindly have a look. Thanks.

@@ -232,7 +254,20 @@ protected int getPassthroughBufferSizeInBytes(@C.Encoding int encoding, int bitr
int bufferSizeUs = passthroughBufferDurationUs;
if (encoding == C.ENCODING_AC3) {
bufferSizeUs *= ac3BufferMultiplicationFactor;
} else if ((DtsUtil.getCurrentMimeType().contentEquals(MimeTypes.AUDIO_DTS_EXPRESS) && (bitrate
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add tests for the DTS Express case? DefaultAudioTrackBufferSizeProviderAC3Test can be a good example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* Default multiplication factor to apply to DTS Express passthrough buffer to avoid underruns
* on some devices (e.g., Xiaomi A2 TV).
*/
private static final int DTSE_BUFFER_MULTIPLICATION_FACTOR = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: How do you think of changing the naming to DTSHD_BUFFER_MULTIPLICATION_FACTOR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done.

Copy link
Contributor

@tianyif tianyif left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! I only left some nit comments, and after addressing them I will bring this PR to the internal review stage.

/**
* Sets the multiplication factor to apply to the passthrough buffer for DTS-HD (DTS Express)
* to avoid underruns on some devices (e.g., Xiaomi A2 TV). Default is
* {@value #DTSHD_BUFFER_MULTIPLICATION_FACTOR}.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: {@link #DTSHD_BUFFER_MULTIPLICATION_FACTOR} instead of @value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -232,7 +258,13 @@ protected int getPassthroughBufferSizeInBytes(@C.Encoding int encoding, int bitr
int bufferSizeUs = passthroughBufferDurationUs;
if (encoding == C.ENCODING_AC3) {
bufferSizeUs *= ac3BufferMultiplicationFactor;
} else if (encoding == C.ENCODING_DTS_HD) {
// DTSHD (DTS Express) for streaming uses a frame size (number of audio samples per channel
Copy link
Contributor

Choose a reason for hiding this comment

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

super-nit: DTS-HD (a dash "-" in between)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -232,7 +258,13 @@ protected int getPassthroughBufferSizeInBytes(@C.Encoding int encoding, int bitr
int bufferSizeUs = passthroughBufferDurationUs;
if (encoding == C.ENCODING_AC3) {
bufferSizeUs *= ac3BufferMultiplicationFactor;
} else if (encoding == C.ENCODING_DTS_HD) {
// DTSHD (DTS Express) for streaming uses a frame size (number of audio samples per channel
// per frame of 4096. This requires a higher multiple for the buffersize computation.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: A missing closing ) after the second word "frame"? The corresponding open ( is in the last line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

private static final int DTSHD_BUFFER_MULTIPLICATION_FACTOR = 4;

/**
* A builder to create {@link DefaultAudioTrackBufferSizeProvider} instances.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Since there is no actual required diff at lines 71-74, could you please revert these lines back to the original state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@tianyif
Copy link
Contributor

tianyif commented Sep 18, 2023

I'm going to send this for internal review now. You may see some more commits being added as I make changes in response to review feedback. Please refrain from pushing any more substantive changes as it will complicate the internal review - thanks!

@tianyif
Copy link
Contributor

tianyif commented Oct 11, 2023

@cedricxperi Sorry for the delay on this PR. I was just back from the holiday :)

Quick question for double check: Does this buffer underrun issues apply to all devices or only applies to some of them like Xiaomi A2 TV? I'm asking to see if we have to mention the devices in the comment lines.

@cedricxperi
Copy link
Contributor Author

@cedricxperi Sorry for the delay on this PR. I was just back from the holiday :)

Quick question for double check: Does this buffer underrun issues apply to all devices or only applies to some of them like Xiaomi A2 TV? I'm asking to see if we have to mention the devices in the comment lines.

Hi @tianyif no worries. This will happen for all devices as it is not a processor speed issue. Thanks

@tianyif tianyif force-pushed the dts-lbr-buffer-underflow-fix branch from a4b4ff1 to 492048c Compare October 12, 2023 09:56
@copybara-service copybara-service bot merged commit 2421ba4 into androidx:main Oct 12, 2023
1 check passed
rohitjoins pushed a commit that referenced this pull request Oct 23, 2023
PiperOrigin-RevId: 572864175
(cherry picked from commit 2421ba4)
@androidx androidx locked and limited conversation to collaborators Dec 12, 2023
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.

2 participants