@@ -63,6 +63,11 @@ public class DefaultAudioTrackBufferSizeProvider
63
63
*/
64
64
private static final int AC3_BUFFER_MULTIPLICATION_FACTOR = 2 ;
65
65
66
+ /**
67
+ * Default multiplication factor to apply to DTS Express passthrough buffer to avoid underruns.
68
+ */
69
+ private static final int DTSHD_BUFFER_MULTIPLICATION_FACTOR = 4 ;
70
+
66
71
/** A builder to create {@link DefaultAudioTrackBufferSizeProvider} instances. */
67
72
public static class Builder {
68
73
@@ -72,6 +77,7 @@ public static class Builder {
72
77
private int passthroughBufferDurationUs ;
73
78
private int offloadBufferDurationUs ;
74
79
private int ac3BufferMultiplicationFactor ;
80
+ private int dtshdBufferMultiplicationFactor ;
75
81
76
82
/** Creates a new builder. */
77
83
public Builder () {
@@ -81,6 +87,7 @@ public Builder() {
81
87
passthroughBufferDurationUs = PASSTHROUGH_BUFFER_DURATION_US ;
82
88
offloadBufferDurationUs = OFFLOAD_BUFFER_DURATION_US ;
83
89
ac3BufferMultiplicationFactor = AC3_BUFFER_MULTIPLICATION_FACTOR ;
90
+ dtshdBufferMultiplicationFactor = DTSHD_BUFFER_MULTIPLICATION_FACTOR ;
84
91
}
85
92
86
93
/**
@@ -143,6 +150,16 @@ public Builder setAc3BufferMultiplicationFactor(int ac3BufferMultiplicationFacto
143
150
return this ;
144
151
}
145
152
153
+ /**
154
+ * Sets the multiplication factor to apply to the passthrough buffer for DTS-HD (DTS Express) to
155
+ * avoid underruns. Default is {@link #DTSHD_BUFFER_MULTIPLICATION_FACTOR}.
156
+ */
157
+ @ CanIgnoreReturnValue
158
+ public Builder setDtshdBufferMultiplicationFactor (int dtshdBufferMultiplicationFactor ) {
159
+ this .dtshdBufferMultiplicationFactor = dtshdBufferMultiplicationFactor ;
160
+ return this ;
161
+ }
162
+
146
163
/** Build the {@link DefaultAudioTrackBufferSizeProvider}. */
147
164
public DefaultAudioTrackBufferSizeProvider build () {
148
165
return new DefaultAudioTrackBufferSizeProvider (this );
@@ -170,13 +187,20 @@ public DefaultAudioTrackBufferSizeProvider build() {
170
187
*/
171
188
public final int ac3BufferMultiplicationFactor ;
172
189
190
+ /**
191
+ * The multiplication factor to apply to DTS-HD (DTS Express) passthrough buffer to avoid
192
+ * underruns.
193
+ */
194
+ public final int dtshdBufferMultiplicationFactor ;
195
+
173
196
protected DefaultAudioTrackBufferSizeProvider (Builder builder ) {
174
197
minPcmBufferDurationUs = builder .minPcmBufferDurationUs ;
175
198
maxPcmBufferDurationUs = builder .maxPcmBufferDurationUs ;
176
199
pcmBufferMultiplicationFactor = builder .pcmBufferMultiplicationFactor ;
177
200
passthroughBufferDurationUs = builder .passthroughBufferDurationUs ;
178
201
offloadBufferDurationUs = builder .offloadBufferDurationUs ;
179
202
ac3BufferMultiplicationFactor = builder .ac3BufferMultiplicationFactor ;
203
+ dtshdBufferMultiplicationFactor = builder .dtshdBufferMultiplicationFactor ;
180
204
}
181
205
182
206
@ Override
@@ -232,7 +256,13 @@ protected int getPassthroughBufferSizeInBytes(@C.Encoding int encoding, int bitr
232
256
int bufferSizeUs = passthroughBufferDurationUs ;
233
257
if (encoding == C .ENCODING_AC3 ) {
234
258
bufferSizeUs *= ac3BufferMultiplicationFactor ;
259
+ } else if (encoding == C .ENCODING_DTS_HD ) {
260
+ // DTS-HD (DTS Express) for streaming uses a frame size (number of audio samples per channel
261
+ // per frame) of 4096. This requires a higher multiple for the buffersize computation.
262
+ // Otherwise, there will be buffer underflow during DASH playback.
263
+ bufferSizeUs *= dtshdBufferMultiplicationFactor ;
235
264
}
265
+
236
266
int byteRate =
237
267
bitrate != Format .NO_VALUE
238
268
? divide (bitrate , 8 , RoundingMode .CEILING )
0 commit comments