mirror of
https://github.com/androidx/media.git
synced 2025-05-13 02:29:52 +08:00
Add extra documentation to AudioGraphInput.
PiperOrigin-RevId: 603663084
This commit is contained in:
parent
30b60f6c60
commit
2b52c2d74f
@ -46,10 +46,14 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a single stream of raw audio samples.
|
* Processes a single sequential stream of PCM audio samples.
|
||||||
*
|
*
|
||||||
* <p>Handles changes to the {@link Format} and {@link Effects} on {@linkplain #onMediaItemChanged
|
* <p>Supports changes to the input {@link Format} and {@link Effects} on {@linkplain
|
||||||
* item boundaries}.
|
* #onMediaItemChanged item boundaries}.
|
||||||
|
*
|
||||||
|
* <p>Class has thread-safe support for input and processing happening on different threads. In that
|
||||||
|
* case, one is the upstream SampleConsumer "input" thread, and the other is the main internal
|
||||||
|
* "processing" thread.
|
||||||
*/
|
*/
|
||||||
/* package */ final class AudioGraphInput implements GraphInput {
|
/* package */ final class AudioGraphInput implements GraphInput {
|
||||||
private static final int MAX_INPUT_BUFFER_COUNT = 10;
|
private static final int MAX_INPUT_BUFFER_COUNT = 10;
|
||||||
@ -67,6 +71,14 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
private boolean receivedEndOfStreamFromInput;
|
private boolean receivedEndOfStreamFromInput;
|
||||||
private boolean queueEndOfStreamAfterSilence;
|
private boolean queueEndOfStreamAfterSilence;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param requestedOutputAudioFormat The requested {@linkplain AudioFormat properties} of the
|
||||||
|
* output audio. {@linkplain Format#NO_VALUE Unset} fields are ignored.
|
||||||
|
* @param editedMediaItem The initial {@link EditedMediaItem}.
|
||||||
|
* @param inputFormat The initial {@link Format} of audio input data.
|
||||||
|
*/
|
||||||
public AudioGraphInput(
|
public AudioGraphInput(
|
||||||
AudioFormat requestedOutputAudioFormat, EditedMediaItem editedMediaItem, Format inputFormat)
|
AudioFormat requestedOutputAudioFormat, EditedMediaItem editedMediaItem, Format inputFormat)
|
||||||
throws UnhandledAudioFormatException {
|
throws UnhandledAudioFormatException {
|
||||||
@ -92,12 +104,16 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
outputAudioFormat = audioProcessingPipeline.getOutputAudioFormat();
|
outputAudioFormat = audioProcessingPipeline.getOutputAudioFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the {@link AudioFormat} of {@linkplain #getOutput() output buffers}. */
|
||||||
public AudioFormat getOutputAudioFormat() {
|
public AudioFormat getOutputAudioFormat() {
|
||||||
return outputAudioFormat;
|
return outputAudioFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ByteBuffer} of output.
|
* Returns a {@link ByteBuffer} of output, in the {@linkplain #getOutputAudioFormat() output audio
|
||||||
|
* format}.
|
||||||
|
*
|
||||||
|
* <p>Should only be called by the processing thread.
|
||||||
*
|
*
|
||||||
* @throws UnhandledAudioFormatException If the configuration of underlying components fails as a
|
* @throws UnhandledAudioFormatException If the configuration of underlying components fails as a
|
||||||
* result of upstream changes.
|
* result of upstream changes.
|
||||||
@ -116,6 +132,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
return EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>Should only be called by the input thread.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onMediaItemChanged(
|
public void onMediaItemChanged(
|
||||||
EditedMediaItem editedMediaItem,
|
EditedMediaItem editedMediaItem,
|
||||||
@ -135,6 +156,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
new MediaItemChange(editedMediaItem, durationUs, decodedFormat, isLast));
|
new MediaItemChange(editedMediaItem, durationUs, decodedFormat, isLast));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>Should only be called by the input thread.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public DecoderInputBuffer getInputBuffer() {
|
public DecoderInputBuffer getInputBuffer() {
|
||||||
@ -144,6 +170,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
return availableInputBuffers.peek();
|
return availableInputBuffers.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>Should only be called by the input thread.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean queueInputBuffer() {
|
public boolean queueInputBuffer() {
|
||||||
checkState(pendingMediaItemChange.get() == null);
|
checkState(pendingMediaItemChange.get() == null);
|
||||||
@ -152,13 +183,21 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Releases any underlying resources. */
|
/**
|
||||||
|
* Releases any underlying resources.
|
||||||
|
*
|
||||||
|
* <p>Should only be called by the processing thread.
|
||||||
|
*/
|
||||||
public void release() {
|
public void release() {
|
||||||
// TODO(b/303029174): Impl flush(), reset() & decide if a separate release() is still needed.
|
// TODO(b/303029174): Impl flush(), reset() & decide if a separate release() is still needed.
|
||||||
audioProcessingPipeline.reset();
|
audioProcessingPipeline.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether the input has ended and all queued data has been output. */
|
/**
|
||||||
|
* Returns whether the input has ended and all queued data has been output.
|
||||||
|
*
|
||||||
|
* <p>Should only be called on the processing thread.
|
||||||
|
*/
|
||||||
public boolean isEnded() {
|
public boolean isEnded() {
|
||||||
if (hasDataToOutput()) {
|
if (hasDataToOutput()) {
|
||||||
return false;
|
return false;
|
||||||
@ -323,6 +362,16 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
processedFirstMediaItemChange = true;
|
processedFirstMediaItemChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new configured {@link AudioProcessingPipeline}.
|
||||||
|
*
|
||||||
|
* <p>Additional {@link AudioProcessor} instances may be added to the returned pipeline that:
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>Handle {@linkplain EditedMediaItem#flattenForSlowMotion slow motion flattening}.
|
||||||
|
* <li>Modify the audio stream to match the {@code requiredOutputAudioFormat}.
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
private static AudioProcessingPipeline configureProcessing(
|
private static AudioProcessingPipeline configureProcessing(
|
||||||
EditedMediaItem editedMediaItem,
|
EditedMediaItem editedMediaItem,
|
||||||
@Nullable Format inputFormat,
|
@Nullable Format inputFormat,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user