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 =
|
int result =
|
||||||
source.readData(trackIndex, currentPositionUs, formatHolder, sampleHolder, false);
|
source.readData(trackIndex, currentPositionUs, formatHolder, sampleHolder, false);
|
||||||
sampleHolder.data.flip();
|
|
||||||
shouldReadInputBuffer = false;
|
|
||||||
|
|
||||||
if (result == SampleSource.FORMAT_READ) {
|
if (result == SampleSource.FORMAT_READ) {
|
||||||
format = formatHolder.format;
|
format = formatHolder.format;
|
||||||
|
audioTrack.reconfigure(format.getFrameworkMediaFormatV16(), AudioFormat.ENCODING_AC3, 0);
|
||||||
}
|
}
|
||||||
if (result == SampleSource.END_OF_STREAM) {
|
if (result == SampleSource.END_OF_STREAM) {
|
||||||
inputStreamEnded = true;
|
inputStreamEnded = true;
|
||||||
@ -211,6 +209,7 @@ public final class Ac3PassthroughAudioTrackRenderer extends TrackRenderer {
|
|||||||
if (result != SampleSource.SAMPLE_READ) {
|
if (result != SampleSource.SAMPLE_READ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
shouldReadInputBuffer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handleBufferResult =
|
int handleBufferResult =
|
||||||
@ -227,16 +226,12 @@ public final class Ac3PassthroughAudioTrackRenderer extends TrackRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStarted() {
|
protected void onStarted() {
|
||||||
if (audioTrack.isInitialized()) {
|
audioTrack.play();
|
||||||
audioTrack.play();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStopped() {
|
protected void onStopped() {
|
||||||
if (audioTrack.isInitialized()) {
|
audioTrack.pause();
|
||||||
audioTrack.pause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -310,8 +310,8 @@ public final class AudioTrack {
|
|||||||
|
|
||||||
// TODO: Does channelConfig determine channelCount?
|
// TODO: Does channelConfig determine channelCount?
|
||||||
boolean isAc3 = encoding == AudioFormat.ENCODING_AC3 || encoding == AudioFormat.ENCODING_E_AC3;
|
boolean isAc3 = encoding == AudioFormat.ENCODING_AC3 || encoding == AudioFormat.ENCODING_E_AC3;
|
||||||
if (audioTrack != null && this.sampleRate == sampleRate
|
if (isInitialized() && this.sampleRate == sampleRate && this.channelConfig == channelConfig
|
||||||
&& this.channelConfig == channelConfig && !this.isAc3 && !isAc3) {
|
&& !this.isAc3 && !isAc3) {
|
||||||
// We already have an existing audio track with the correct sample rate and channel config.
|
// We already have an existing audio track with the correct sample rate and channel config.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -450,7 +450,7 @@ public final class AudioTrack {
|
|||||||
|
|
||||||
/** Returns whether the audio track has more data pending that will be played back. */
|
/** Returns whether the audio track has more data pending that will be played back. */
|
||||||
public boolean hasPendingData() {
|
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. */
|
/** 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. */
|
/** Sets the playback volume. */
|
||||||
public void setVolume(float volume) {
|
public void setVolume(float volume) {
|
||||||
this.volume = volume;
|
this.volume = volume;
|
||||||
if (audioTrack != null) {
|
if (isInitialized()) {
|
||||||
if (Util.SDK_INT >= 21) {
|
if (Util.SDK_INT >= 21) {
|
||||||
setVolumeV21(audioTrack, volume);
|
setVolumeV21(audioTrack, volume);
|
||||||
} else {
|
} else {
|
||||||
@ -482,7 +482,7 @@ public final class AudioTrack {
|
|||||||
|
|
||||||
/** Pauses playback. */
|
/** Pauses playback. */
|
||||||
public void pause() {
|
public void pause() {
|
||||||
if (audioTrack != null) {
|
if (isInitialized()) {
|
||||||
resetSyncParams();
|
resetSyncParams();
|
||||||
audioTrack.pause();
|
audioTrack.pause();
|
||||||
}
|
}
|
||||||
@ -494,7 +494,7 @@ public final class AudioTrack {
|
|||||||
* after resetting.
|
* after resetting.
|
||||||
*/
|
*/
|
||||||
public void reset() {
|
public void reset() {
|
||||||
if (audioTrack != null) {
|
if (isInitialized()) {
|
||||||
submittedBytes = 0;
|
submittedBytes = 0;
|
||||||
temporaryBufferSize = 0;
|
temporaryBufferSize = 0;
|
||||||
lastRawPlaybackHeadPosition = 0;
|
lastRawPlaybackHeadPosition = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user