-
Notifications
You must be signed in to change notification settings - Fork 314
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
Changes from 1 commit
25acaa1
7edfe58
24d03b0
0f200ba
215f663
49f45c4
834b61d
492048c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
import android.media.AudioTrack; | ||
import androidx.media3.common.C; | ||
import androidx.media3.common.Format; | ||
import androidx.media3.common.MimeTypes; | ||
import androidx.media3.common.util.UnstableApi; | ||
import androidx.media3.exoplayer.audio.DefaultAudioSink.OutputMode; | ||
import androidx.media3.extractor.AacUtil; | ||
|
@@ -67,8 +66,11 @@ public class DefaultAudioTrackBufferSizeProvider | |
* 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; | ||
/** A builder to create {@link DefaultAudioTrackBufferSizeProvider} instances. */ | ||
private static final int DTSHD_BUFFER_MULTIPLICATION_FACTOR = 4; | ||
|
||
/** | ||
* A builder to create {@link DefaultAudioTrackBufferSizeProvider} instances. | ||
*/ | ||
|
||
public static class Builder { | ||
|
||
|
@@ -78,7 +80,7 @@ public static class Builder { | |
private int passthroughBufferDurationUs; | ||
private int offloadBufferDurationUs; | ||
private int ac3BufferMultiplicationFactor; | ||
private int dtseBufferMultiplicationFactor; | ||
private int dtshdBufferMultiplicationFactor; | ||
|
||
/** Creates a new builder. */ | ||
public Builder() { | ||
|
@@ -88,7 +90,7 @@ public Builder() { | |
passthroughBufferDurationUs = PASSTHROUGH_BUFFER_DURATION_US; | ||
offloadBufferDurationUs = OFFLOAD_BUFFER_DURATION_US; | ||
ac3BufferMultiplicationFactor = AC3_BUFFER_MULTIPLICATION_FACTOR; | ||
dtseBufferMultiplicationFactor = DTSE_BUFFER_MULTIPLICATION_FACTOR; | ||
dtshdBufferMultiplicationFactor = DTSHD_BUFFER_MULTIPLICATION_FACTOR; | ||
} | ||
|
||
/** | ||
|
@@ -152,13 +154,13 @@ public Builder setAc3BufferMultiplicationFactor(int ac3BufferMultiplicationFacto | |
} | ||
|
||
/** | ||
* Sets the multiplication factor to apply to the passthrough buffer for DTS Express to avoid | ||
* underruns on some devices (e.g., Xiaomi A2 TV). Default is | ||
* {@value #DTSE_BUFFER_MULTIPLICATION_FACTOR}. | ||
* 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}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
*/ | ||
@CanIgnoreReturnValue | ||
public Builder setDtseBufferMultiplicationFactor(int dtseBufferMultiplicationFactor) { | ||
this.dtseBufferMultiplicationFactor = dtseBufferMultiplicationFactor; | ||
public Builder setDtshdBufferMultiplicationFactor(int dtshdBufferMultiplicationFactor) { | ||
this.dtshdBufferMultiplicationFactor = dtshdBufferMultiplicationFactor; | ||
return this; | ||
} | ||
|
||
|
@@ -189,18 +191,18 @@ public DefaultAudioTrackBufferSizeProvider build() { | |
*/ | ||
public final int ac3BufferMultiplicationFactor; | ||
/** | ||
* The multiplication factor to apply to DTS Express passthrough buffer to avoid underruns on some | ||
* devices (e.g., Xiaomi A2 TV). | ||
* The multiplication factor to apply to DTS-HD (DTS Express) passthrough buffer to avoid | ||
* underruns on some devices (e.g., Xiaomi A2 TV). | ||
*/ | ||
public final int dtseBufferMultiplicationFactor; | ||
public final int dtshdBufferMultiplicationFactor; | ||
protected DefaultAudioTrackBufferSizeProvider(Builder builder) { | ||
minPcmBufferDurationUs = builder.minPcmBufferDurationUs; | ||
maxPcmBufferDurationUs = builder.maxPcmBufferDurationUs; | ||
pcmBufferMultiplicationFactor = builder.pcmBufferMultiplicationFactor; | ||
passthroughBufferDurationUs = builder.passthroughBufferDurationUs; | ||
offloadBufferDurationUs = builder.offloadBufferDurationUs; | ||
ac3BufferMultiplicationFactor = builder.ac3BufferMultiplicationFactor; | ||
dtseBufferMultiplicationFactor = builder.dtseBufferMultiplicationFactor; | ||
dtshdBufferMultiplicationFactor = builder.dtshdBufferMultiplicationFactor; | ||
} | ||
|
||
@Override | ||
|
@@ -257,10 +259,10 @@ protected int getPassthroughBufferSizeInBytes(@C.Encoding int encoding, int bitr | |
if (encoding == C.ENCODING_AC3) { | ||
bufferSizeUs *= ac3BufferMultiplicationFactor; | ||
} else if (encoding == C.ENCODING_DTS_HD) { | ||
// 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. Otherwise, there | ||
// will be buffer underflow during DASH playback. | ||
bufferSizeUs *= dtseBufferMultiplicationFactor; | ||
// DTSHD (DTS Express) for streaming uses a frame size (number of audio samples per channel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super-nit: DTS-HD (a dash "-" in between)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
// per frame of 4096. This requires a higher multiple for the buffersize computation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: A missing closing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
// Otherwise, there will be buffer underflow during DASH playback. | ||
bufferSizeUs *= dtshdBufferMultiplicationFactor; | ||
} | ||
|
||
int byteRate = | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done