Back to Exoplayer

OggFileAudioBufferSink (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/testutil/OggFileAudioBufferSink.html

latest7.6 KB
Original Source

Package com.google.android.exoplayer2.testutil

Class OggFileAudioBufferSink


public final classOggFileAudioBufferSinkextends[ForwardingAudioSink](../audio/ForwardingAudioSink.html "class in com.google.android.exoplayer2.audio")

A sink for audio buffers that writes output audio as .ogg files with a given path prefix. When new audio data is handled after flushing the audio packetizer, a counter is incremented and its value is appended to the output file name.

Note: if writing to external storage it's necessary to grant the WRITE_EXTERNAL_STORAGE permission.

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 | Modifier and Type | Field | Description | | --- | --- | --- | | static int | SAMPLE_RATE | Opus streams are always 48000 Hz. |

- 

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 | | --- | --- | | OggFileAudioBufferSink​(AudioSink audioSink, String outputFileNamePrefix) | Creates an instance. |

Method Summary

All Methods Instance Methods Concrete Methods | Modifier and Type | Method | Description | | --- | --- | --- | | void | flush() | Flushes the sink, after which it is ready to receive buffers from a new playback position. | | boolean | handleBuffer​(ByteBuffer buffer, long presentationTimeUs, int encodedAccessUnitCount) | Attempts to process data from a ByteBuffer, starting from its current position and ending at its limit (exclusive). | | void | reset() | Resets the sink, releasing any resources that it currently holds. |

- 

Methods inherited from class com.google.android.exoplayer2.audio.ForwardingAudioSink

configure, disableTunneling, enableTunnelingV21, experimentalFlushWithoutAudioTrackRelease, getAudioAttributes, getCurrentPositionUs, getFormatSupport, getPlaybackParameters, getSkipSilenceEnabled, handleDiscontinuity, hasPendingData, isEnded, pause, play, playToEndOfStream, setAudioAttributes, setAudioSessionId, setAuxEffectInfo, setListener, setOutputStreamOffsetUs, setPlaybackParameters, setPlayerId, setPreferredDevice, setSkipSilenceEnabled, setVolume, supportsFormat

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

- 

Methods inherited from interface com.google.android.exoplayer2.audio.AudioSink

release

Field Detail

- 

SAMPLE_RATE

public static final int SAMPLE_RATE

Opus streams are always 48000 Hz. See Also:Constant Field Values

Constructor Detail

- 

OggFileAudioBufferSink

public OggFileAudioBufferSink​([AudioSink](../audio/AudioSink.html "interface in com.google.android.exoplayer2.audio")audioSink,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")outputFileNamePrefix)

Creates an instance. Parameters:audioSink - The base audioSink calls are forwarded to.outputFileNamePrefix - The prefix for output files.

Method Detail

- 

flush

public void flush()

Description copied from interface: AudioSink

Flushes 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:flush in interface AudioSinkOverrides:flush in class ForwardingAudioSink

- 

reset

public void reset()

Description copied from interface: AudioSink

Resets the sink, releasing any resources that it currently holds. Specified by:reset in interface AudioSinkOverrides:reset in class ForwardingAudioSink

- 

handleBuffer

public boolean handleBuffer​([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")buffer,
                            long presentationTimeUs,
                            int encodedAccessUnitCount)
                     throws[AudioSink.InitializationException](../audio/AudioSink.InitializationException.html "class in com.google.android.exoplayer2.audio"),[AudioSink.WriteException](../audio/AudioSink.WriteException.html "class in com.google.android.exoplayer2.audio")

Description copied from interface: AudioSink

Attempts to process data from a ByteBuffer, starting from its current position and ending at its limit (exclusive). The position of the ByteBuffer is advanced by the number of bytes that were handled. AudioSink.Listener.onPositionDiscontinuity() will be called if presentationTimeUs is 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 ByteBuffer must be provided to subsequent calls until it has been fully consumed, except in the case of an intervening call to AudioSink.flush() (or to AudioSink.configure(Format, int, int[]) that causes the sink to be flushed).

Specified by:handleBuffer in interface AudioSinkOverrides:handleBuffer in class ForwardingAudioSinkParameters: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.