mirror of
https://github.com/samsonjs/media.git
synced 2026-04-10 12:05:47 +00:00
Set the passthrough buffer size based on encoded format bit rates.
After this change, AC-3 uses about 20 KB and DTS uses 49 KB. For comparison, 'normal' PCM playbacks use by default (depending on the device and input format) about 45 KB. For passthrough, the following buffer sizes were used before this change: - Nexus Player AC-3: 23 KB - Nexus Player DTS: 25 KB - NVIDIA Shield AC-3: 15 KB - NVIDIA Shield DTS: 16 KB (caused underruns in some DTS-HD playbacks) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=112254836
This commit is contained in:
parent
9bb124a011
commit
0900c53564
1 changed files with 17 additions and 6 deletions
|
|
@ -134,6 +134,10 @@ public final class AudioTrack {
|
|||
* A maximum length for the {@link android.media.AudioTrack} buffer, in microseconds.
|
||||
*/
|
||||
private static final long MAX_BUFFER_DURATION_US = 750000;
|
||||
/**
|
||||
* The length for passthrough {@link android.media.AudioTrack} buffers, in microseconds.
|
||||
*/
|
||||
private static final long PASSTHROUGH_BUFFER_DURATION_US = 250000;
|
||||
/**
|
||||
* A multiplication factor to apply to the minimum buffer size requested by the underlying
|
||||
* {@link android.media.AudioTrack}.
|
||||
|
|
@ -199,7 +203,6 @@ public final class AudioTrack {
|
|||
private int encoding;
|
||||
private boolean passthrough;
|
||||
private int pcmFrameSize;
|
||||
private int minBufferSize;
|
||||
private int bufferSize;
|
||||
private long bufferSizeUs;
|
||||
|
||||
|
|
@ -394,15 +397,23 @@ public final class AudioTrack {
|
|||
this.sampleRate = sampleRate;
|
||||
this.channelConfig = channelConfig;
|
||||
pcmFrameSize = 2 * channelCount; // 2 bytes per 16 bit sample * number of channels.
|
||||
minBufferSize = android.media.AudioTrack.getMinBufferSize(sampleRate, channelConfig, encoding);
|
||||
Assertions.checkState(minBufferSize != android.media.AudioTrack.ERROR_BAD_VALUE);
|
||||
|
||||
if (specifiedBufferSize != 0) {
|
||||
bufferSize = specifiedBufferSize;
|
||||
} else if (passthrough) {
|
||||
// TODO: Set the minimum buffer size correctly for encoded output when getMinBufferSize takes
|
||||
// the encoding into account. [Internal: b/25181305]
|
||||
bufferSize = minBufferSize * BUFFER_MULTIPLICATION_FACTOR * 2;
|
||||
// TODO: Set the minimum buffer size using getMinBufferSize when it takes the encoding into
|
||||
// account. [Internal: b/25181305]
|
||||
if (encoding == C.ENCODING_AC3 || encoding == C.ENCODING_E_AC3) {
|
||||
// AC-3 allows bitrates up to 640 kbit/s.
|
||||
bufferSize = (int) (PASSTHROUGH_BUFFER_DURATION_US * 80 * 1024 / C.MICROS_PER_SECOND);
|
||||
} else { // encoding == C.ENCODING_DTS || encoding == C.ENCODING_DTS_HD
|
||||
// DTS allows an 'open' bitrate, but we assume the maximum listed value: 1536 kbit/s.
|
||||
bufferSize = (int) (PASSTHROUGH_BUFFER_DURATION_US * 192 * 1024 / C.MICROS_PER_SECOND);
|
||||
}
|
||||
} else {
|
||||
int minBufferSize =
|
||||
android.media.AudioTrack.getMinBufferSize(sampleRate, channelConfig, encoding);
|
||||
Assertions.checkState(minBufferSize != android.media.AudioTrack.ERROR_BAD_VALUE);
|
||||
int multipliedBufferSize = minBufferSize * BUFFER_MULTIPLICATION_FACTOR;
|
||||
int minAppBufferSize = (int) durationUsToFrames(MIN_BUFFER_DURATION_US) * pcmFrameSize;
|
||||
int maxAppBufferSize = (int) Math.max(minBufferSize,
|
||||
|
|
|
|||
Loading…
Reference in a new issue