Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.media.AudioTrack;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.AuxEffectInfo;
import androidx.media3.common.C;
Expand Down Expand Up @@ -646,18 +645,16 @@ default void setOutputStreamOffsetUs(long outputStreamOffsetUs) {}
void disableTunneling();

/**
* Sets audio offload mode, if possible. Enabling offload is only possible if the sink is based on
* a platform {@link AudioTrack}, and requires platform API version 29 onwards.
* Sets audio offload mode, if possible. If the sink is based on a platform {@link AudioTrack},
* enabling offload requires platform API version 29 onwards.
*/
@RequiresApi(29)
default void setOffloadMode(@OffloadMode int offloadMode) {}

/**
* Sets offload delay padding on the {@link AudioTrack}, if possible. Setting the offload delay
* padding is only possible if the sink is based on a platform {@link AudioTrack} in offload mode.
* Also requires platform API version 29 onwards.
* Sets offload delay padding on the {@link AudioTrack}, if possible. If the sink is based on a
* platform {@link AudioTrack}, setting the offload delay padding requires platform API version 29
* onwards and the {@link AudioTrack} must be in offload mode.
*/
@RequiresApi(29)
default void setOffloadDelayPadding(int delayInFrames, int paddingInFrames) {}

/** Sets the {@link AudioOutputProvider} to use as the output path. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,9 +1260,7 @@ public boolean isEnded() {
@Override
public boolean hasPendingData() {
return isAudioOutputInitialized()
&& (SDK_INT < 29
|| !audioOutput.isOffloadedPlayback()
|| !handledOffloadOnPresentationEnded)
&& (!audioOutput.isOffloadedPlayback() || !handledOffloadOnPresentationEnded)
&& hasAudioOutputPendingData(getWrittenFrames());
}

Expand Down Expand Up @@ -1399,14 +1397,11 @@ public void disableTunneling() {
}
}

@RequiresApi(29)
@Override
public void setOffloadMode(@OffloadMode int offloadMode) {
checkState(SDK_INT >= 29);
this.offloadMode = offloadMode;
}

@RequiresApi(29)
@Override
public void setOffloadDelayPadding(int delayInFrames, int paddingInFrames) {
if (audioOutput != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import android.media.AudioDeviceInfo;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.AuxEffectInfo;
import androidx.media3.common.Format;
Expand Down Expand Up @@ -182,13 +181,11 @@ public void disableTunneling() {
}

@Override
@RequiresApi(29)
public void setOffloadMode(@OffloadMode int offloadMode) {
sink.setOffloadMode(offloadMode);
}

@Override
@RequiresApi(29)
public void setOffloadDelayPadding(int delayInFrames, int paddingInFrames) {
sink.setOffloadDelayPadding(delayInFrames, paddingInFrames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,13 @@ protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaF
}
}
try {
if (SDK_INT >= 29) {
if (isBypassEnabled()
&& getConfiguration().offloadModePreferred != AudioSink.OFFLOAD_MODE_DISABLED) {
// TODO(b/280050553): Investigate potential issue where bypass is enabled for passthrough
// but offload is not supported
audioSink.setOffloadMode(getConfiguration().offloadModePreferred);
} else {
audioSink.setOffloadMode(AudioSink.OFFLOAD_MODE_DISABLED);
}
if (isBypassEnabled()
&& getConfiguration().offloadModePreferred != AudioSink.OFFLOAD_MODE_DISABLED) {
// TODO(b/280050553): Investigate potential issue where bypass is enabled for passthrough
// but offload is not supported
audioSink.setOffloadMode(getConfiguration().offloadModePreferred);
} else {
audioSink.setOffloadMode(AudioSink.OFFLOAD_MODE_DISABLED);
}
audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
} catch (AudioSink.ConfigurationException e) {
Expand Down Expand Up @@ -979,8 +977,7 @@ public void handleMessage(@MessageType int messageType, @Nullable Object message

@Override
protected void handleInputBufferSupplementalData(DecoderInputBuffer buffer) {
if (SDK_INT >= 29
&& buffer.format != null
if (buffer.format != null
&& Objects.equals(buffer.format.sampleMimeType, MimeTypes.AUDIO_OPUS)
&& isBypassEnabled()) {
ByteBuffer data = checkNotNull(buffer.supplementalData);
Expand Down