mirror of
https://github.com/androidx/media.git
synced 2025-05-07 23:50:44 +08:00
Fix AC3Passthrough
- Handle read returning NOTHING_READ for AC-3 streams. - Remove extra checks for the audio track being initialized. - Call isInitialized() instead of checking audioTrack != null.
This commit is contained in:
parent
57068a6406
commit
f1fe109bfa
@ -199,11 +199,9 @@ public final class Ac3PassthroughAudioTrackRenderer extends TrackRenderer {
|
||||
|
||||
int result =
|
||||
source.readData(trackIndex, currentPositionUs, formatHolder, sampleHolder, false);
|
||||
sampleHolder.data.flip();
|
||||
shouldReadInputBuffer = false;
|
||||
|
||||
if (result == SampleSource.FORMAT_READ) {
|
||||
format = formatHolder.format;
|
||||
audioTrack.reconfigure(format.getFrameworkMediaFormatV16(), AudioFormat.ENCODING_AC3, 0);
|
||||
}
|
||||
if (result == SampleSource.END_OF_STREAM) {
|
||||
inputStreamEnded = true;
|
||||
@ -211,6 +209,7 @@ public final class Ac3PassthroughAudioTrackRenderer extends TrackRenderer {
|
||||
if (result != SampleSource.SAMPLE_READ) {
|
||||
return;
|
||||
}
|
||||
shouldReadInputBuffer = false;
|
||||
}
|
||||
|
||||
int handleBufferResult =
|
||||
@ -227,16 +226,12 @@ public final class Ac3PassthroughAudioTrackRenderer extends TrackRenderer {
|
||||
|
||||
@Override
|
||||
protected void onStarted() {
|
||||
if (audioTrack.isInitialized()) {
|
||||
audioTrack.play();
|
||||
}
|
||||
audioTrack.play();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopped() {
|
||||
if (audioTrack.isInitialized()) {
|
||||
audioTrack.pause();
|
||||
}
|
||||
audioTrack.pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -310,8 +310,8 @@ public final class AudioTrack {
|
||||
|
||||
// TODO: Does channelConfig determine channelCount?
|
||||
boolean isAc3 = encoding == AudioFormat.ENCODING_AC3 || encoding == AudioFormat.ENCODING_E_AC3;
|
||||
if (audioTrack != null && this.sampleRate == sampleRate
|
||||
&& this.channelConfig == channelConfig && !this.isAc3 && !isAc3) {
|
||||
if (isInitialized() && this.sampleRate == sampleRate && this.channelConfig == channelConfig
|
||||
&& !this.isAc3 && !isAc3) {
|
||||
// We already have an existing audio track with the correct sample rate and channel config.
|
||||
return;
|
||||
}
|
||||
@ -450,7 +450,7 @@ public final class AudioTrack {
|
||||
|
||||
/** Returns whether the audio track has more data pending that will be played back. */
|
||||
public boolean hasPendingData() {
|
||||
return audioTrack != null && bytesToFrames(submittedBytes) > getPlaybackPositionFrames();
|
||||
return isInitialized() && bytesToFrames(submittedBytes) > getPlaybackPositionFrames();
|
||||
}
|
||||
|
||||
/** Returns whether enough data has been supplied via {@link #handleBuffer} to begin playback. */
|
||||
@ -461,7 +461,7 @@ public final class AudioTrack {
|
||||
/** Sets the playback volume. */
|
||||
public void setVolume(float volume) {
|
||||
this.volume = volume;
|
||||
if (audioTrack != null) {
|
||||
if (isInitialized()) {
|
||||
if (Util.SDK_INT >= 21) {
|
||||
setVolumeV21(audioTrack, volume);
|
||||
} else {
|
||||
@ -482,7 +482,7 @@ public final class AudioTrack {
|
||||
|
||||
/** Pauses playback. */
|
||||
public void pause() {
|
||||
if (audioTrack != null) {
|
||||
if (isInitialized()) {
|
||||
resetSyncParams();
|
||||
audioTrack.pause();
|
||||
}
|
||||
@ -494,7 +494,7 @@ public final class AudioTrack {
|
||||
* after resetting.
|
||||
*/
|
||||
public void reset() {
|
||||
if (audioTrack != null) {
|
||||
if (isInitialized()) {
|
||||
submittedBytes = 0;
|
||||
temporaryBufferSize = 0;
|
||||
lastRawPlaybackHeadPosition = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user