mirror of
https://github.com/samsonjs/media.git
synced 2026-04-22 14:05:55 +00:00
Set LogSessionId on AudioTrack.
This requires forwarding the PlayerId to the AudioSink. PiperOrigin-RevId: 410509605
This commit is contained in:
parent
45a5a7584d
commit
14ab4f8058
7 changed files with 45 additions and 0 deletions
|
|
@ -24,6 +24,7 @@ import com.google.android.exoplayer2.Format;
|
|||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
|
@ -281,6 +282,13 @@ public interface AudioSink {
|
|||
*/
|
||||
void setListener(Listener listener);
|
||||
|
||||
/**
|
||||
* Sets the {@link PlayerId} of the player using this audio sink.
|
||||
*
|
||||
* @param playerId The {@link PlayerId}, or null to clear a previously set id.
|
||||
*/
|
||||
default void setPlayerId(@Nullable PlayerId playerId) {}
|
||||
|
||||
/**
|
||||
* Returns whether the sink supports a given {@link Format}.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -530,6 +530,7 @@ public abstract class DecoderAudioRenderer<
|
|||
} else {
|
||||
audioSink.disableTunneling();
|
||||
}
|
||||
audioSink.setPlayerId(getPlayerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import android.media.AudioFormat;
|
|||
import android.media.AudioManager;
|
||||
import android.media.AudioTrack;
|
||||
import android.media.PlaybackParams;
|
||||
import android.media.metrics.LogSessionId;
|
||||
import android.os.ConditionVariable;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
|
|
@ -33,6 +34,7 @@ import androidx.annotation.RequiresApi;
|
|||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||
import com.google.android.exoplayer2.audio.AudioProcessor.UnhandledAudioFormatException;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
|
|
@ -323,6 +325,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
initializationExceptionPendingExceptionHolder;
|
||||
private final PendingExceptionHolder<WriteException> writeExceptionPendingExceptionHolder;
|
||||
|
||||
@Nullable private PlayerId playerId;
|
||||
@Nullable private Listener listener;
|
||||
@Nullable private Configuration pendingConfiguration;
|
||||
@MonotonicNonNull private Configuration configuration;
|
||||
|
|
@ -477,6 +480,11 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerId(@Nullable PlayerId playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFormat(Format format) {
|
||||
return getFormatSupport(format) != SINK_FORMAT_UNSUPPORTED;
|
||||
|
|
@ -665,6 +673,9 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
configuration.inputFormat.encoderDelay, configuration.inputFormat.encoderPadding);
|
||||
}
|
||||
}
|
||||
if (Util.SDK_INT >= 31 && playerId != null) {
|
||||
Api31.setLogSessionIdOnAudioTrack(audioTrack, playerId);
|
||||
}
|
||||
audioSessionId = audioTrack.getAudioSessionId();
|
||||
audioTrackPositionTracker.setAudioTrack(
|
||||
audioTrack,
|
||||
|
|
@ -2094,6 +2105,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
audioSessionId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // Using deprecated AudioTrack constructor.
|
||||
private AudioTrack createAudioTrackV9(AudioAttributes audioAttributes, int audioSessionId) {
|
||||
int streamType = Util.getStreamTypeForAudioUsage(audioAttributes.usage);
|
||||
if (audioSessionId == C.AUDIO_SESSION_ID_UNSET) {
|
||||
|
|
@ -2216,4 +2228,16 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
pendingException = null;
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(31)
|
||||
private static final class Api31 {
|
||||
private Api31() {}
|
||||
|
||||
public static void setLogSessionIdOnAudioTrack(AudioTrack audioTrack, PlayerId playerId) {
|
||||
LogSessionId logSessionId = playerId.getLogSessionId();
|
||||
if (!logSessionId.equals(LogSessionId.LOG_SESSION_ID_NONE)) {
|
||||
audioTrack.setLogSessionId(logSessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
|
|||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/** An overridable {@link AudioSink} implementation forwarding all methods to another sink. */
|
||||
|
|
@ -34,6 +35,11 @@ public class ForwardingAudioSink implements AudioSink {
|
|||
sink.setListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerId(@Nullable PlayerId playerId) {
|
||||
sink.setPlayerId(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFormat(Format format) {
|
||||
return sink.supportsFormat(format);
|
||||
|
|
|
|||
|
|
@ -500,6 +500,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
|||
} else {
|
||||
audioSink.disableTunneling();
|
||||
}
|
||||
audioSink.setPlayerId(getPlayerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.RendererConfiguration;
|
||||
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||
import com.google.android.exoplayer2.decoder.CryptoConfig;
|
||||
import com.google.android.exoplayer2.decoder.DecoderException;
|
||||
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
||||
|
|
@ -84,6 +85,7 @@ public class DecoderAudioRendererTest {
|
|||
return FORMAT;
|
||||
}
|
||||
};
|
||||
audioRenderer.init(/* index= */ 0, PlayerId.UNSET);
|
||||
}
|
||||
|
||||
@Config(sdk = 19)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import com.google.android.exoplayer2.ExoPlaybackException;
|
|||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.RendererConfiguration;
|
||||
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
|
||||
|
|
@ -110,6 +111,7 @@ public class MediaCodecAudioRendererTest {
|
|||
eventHandler,
|
||||
audioRendererEventListener,
|
||||
audioSink);
|
||||
mediaCodecAudioRenderer.init(/* index= */ 0, PlayerId.UNSET);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -264,6 +266,7 @@ public class MediaCodecAudioRendererTest {
|
|||
oneByteSample(/* timeUs= */ 0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
|
||||
fakeSampleStream.writeData(/* startPositionUs= */ 0);
|
||||
|
||||
exceptionThrowingRenderer.init(/* index= */ 0, PlayerId.UNSET);
|
||||
exceptionThrowingRenderer.enable(
|
||||
RendererConfiguration.DEFAULT,
|
||||
new Format[] {AUDIO_AAC, changedFormat},
|
||||
|
|
|
|||
Loading…
Reference in a new issue