Class CapturingAudioSink
- java.lang.Object
-
- com.google.android.exoplayer2.audio.ForwardingAudioSink
-
- com.google.android.exoplayer2.testutil.CapturingAudioSink
-
- All Implemented Interfaces:
AudioSink,Dumper.Dumpable
public final class CapturingAudioSink extends ForwardingAudioSink implements Dumper.Dumpable
AForwardingAudioSinkthat captures configuration, discontinuity and buffer events.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.audio.AudioSink
AudioSink.ConfigurationException, AudioSink.InitializationException, AudioSink.Listener, AudioSink.SinkFormatSupport, AudioSink.UnexpectedDiscontinuityException, AudioSink.WriteException
-
-
Field Summary
-
Fields inherited from interface com.google.android.exoplayer2.audio.AudioSink
CURRENT_POSITION_NOT_SET, SINK_FORMAT_SUPPORTED_DIRECTLY, SINK_FORMAT_SUPPORTED_WITH_TRANSCODING, SINK_FORMAT_UNSUPPORTED
-
-
Constructor Summary
Constructors Constructor Description CapturingAudioSink(AudioSink sink)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(Format inputFormat, int specifiedBufferSize, int[] outputChannels)Configures (or reconfigures) the sink.voiddump(Dumper dumper)Dumps the fields of the object using thedumper.voidflush()Flushes the sink, after which it is ready to receive buffers from a new playback position.booleanhandleBuffer(ByteBuffer buffer, long presentationTimeUs, int encodedAccessUnitCount)Attempts to process data from aByteBuffer, starting from its current position and ending at its limit (exclusive).voidhandleDiscontinuity()Signals to the sink that the next buffer may be discontinuous with the previous buffer.voidreset()Resets the sink, releasing any resources that it currently holds.-
Methods inherited from class com.google.android.exoplayer2.audio.ForwardingAudioSink
disableTunneling, enableTunnelingV21, experimentalFlushWithoutAudioTrackRelease, getAudioAttributes, getCurrentPositionUs, getFormatSupport, getPlaybackParameters, getSkipSilenceEnabled, hasPendingData, isEnded, pause, play, playToEndOfStream, setAudioAttributes, setAudioSessionId, setAuxEffectInfo, setListener, setPlaybackParameters, setPlayerId, setSkipSilenceEnabled, setVolume, supportsFormat
-
-
-
-
Constructor Detail
-
CapturingAudioSink
public CapturingAudioSink(AudioSink sink)
-
-
Method Detail
-
configure
public void configure(Format inputFormat, int specifiedBufferSize, @Nullable int[] outputChannels) throws AudioSink.ConfigurationException
Description copied from interface:AudioSinkConfigures (or reconfigures) the sink.- Specified by:
configurein interfaceAudioSink- Overrides:
configurein classForwardingAudioSink- Parameters:
inputFormat- The format of audio data provided in the input buffers.specifiedBufferSize- A specific size for the playback buffer in bytes, or 0 to infer a suitable buffer size.outputChannels- A mapping from input to output channels that is applied to this sink's input as a preprocessing step, if handling PCM input. Specifynullto leave the input unchanged. Otherwise, the element at indexispecifies index of the input channel to map to output channeliwhen preprocessing input buffers. After the map is applied the audio data will haveoutputChannels.lengthchannels.- Throws:
AudioSink.ConfigurationException- If an error occurs configuring the sink.
-
handleDiscontinuity
public void handleDiscontinuity()
Description copied from interface:AudioSinkSignals to the sink that the next buffer may be discontinuous with the previous buffer.- Specified by:
handleDiscontinuityin interfaceAudioSink- Overrides:
handleDiscontinuityin classForwardingAudioSink
-
handleBuffer
public boolean handleBuffer(ByteBuffer buffer, long presentationTimeUs, int encodedAccessUnitCount) throws AudioSink.InitializationException, AudioSink.WriteException
Description copied from interface:AudioSinkAttempts to process data from aByteBuffer, starting from its current position and ending at its limit (exclusive). The position of theByteBufferis advanced by the number of bytes that were handled.AudioSink.Listener.onPositionDiscontinuity()will be called ifpresentationTimeUsis discontinuous with the last buffer handled since the last reset.Returns whether the data was handled in full. If the data was not handled in full then the same
ByteBuffermust be provided to subsequent calls until it has been fully consumed, except in the case of an intervening call toAudioSink.flush()(or toAudioSink.configure(Format, int, int[])that causes the sink to be flushed).- Specified by:
handleBufferin interfaceAudioSink- Overrides:
handleBufferin classForwardingAudioSink- Parameters:
buffer- The buffer containing audio data.presentationTimeUs- The presentation timestamp of the buffer in microseconds.encodedAccessUnitCount- The number of encoded access units in the buffer, or 1 if the buffer contains PCM audio. This allows batching multiple encoded access units in one buffer.- Returns:
- Whether the buffer was handled fully.
- Throws:
AudioSink.InitializationException- If an error occurs initializing the sink.AudioSink.WriteException- If an error occurs writing the audio data.
-
flush
public void flush()
Description copied from interface:AudioSinkFlushes the sink, after which it is ready to receive buffers from a new playback position.The audio session may remain active until
AudioSink.reset()is called.- Specified by:
flushin interfaceAudioSink- Overrides:
flushin classForwardingAudioSink
-
reset
public void reset()
Description copied from interface:AudioSinkResets the sink, releasing any resources that it currently holds.- Specified by:
resetin interfaceAudioSink- Overrides:
resetin classForwardingAudioSink
-
dump
public void dump(Dumper dumper)
Description copied from interface:Dumper.DumpableDumps the fields of the object using thedumper.- Specified by:
dumpin interfaceDumper.Dumpable- Parameters:
dumper- TheDumperto be used to dump fields.
-
-