Commit a114a0ed by aquilescanta Committed by kim-vde

Rename SampleDataReader to DataReader and move to common

PiperOrigin-RevId: 297603312
parent 1f718301
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer2.extractor; package com.google.android.exoplayer2.upstream;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import java.io.IOException; import java.io.IOException;
/** Provides sample data to be consumed by a {@link TrackOutput}. */ /** Reads bytes from a data stream. */
public interface SampleDataReader { public interface DataReader {
/** /**
* Reads up to {@code length} bytes of sample data from the input. * Reads up to {@code length} bytes of data from the input.
* *
* @param target A target array into which data should be written. * @param target A target array into which data should be written.
* @param offset The offset into the target array at which to write. * @param offset The offset into the target array at which to write.
......
...@@ -19,11 +19,11 @@ import androidx.annotation.Nullable; ...@@ -19,11 +19,11 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.decoder.CryptoInfo; import com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.extractor.SampleDataReader;
import com.google.android.exoplayer2.extractor.TrackOutput.CryptoData; import com.google.android.exoplayer2.extractor.TrackOutput.CryptoData;
import com.google.android.exoplayer2.source.SampleQueue.SampleExtrasHolder; import com.google.android.exoplayer2.source.SampleQueue.SampleExtrasHolder;
import com.google.android.exoplayer2.upstream.Allocation; import com.google.android.exoplayer2.upstream.Allocation;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.EOFException; import java.io.EOFException;
...@@ -177,7 +177,7 @@ import java.util.Arrays; ...@@ -177,7 +177,7 @@ import java.util.Arrays;
return totalBytesWritten; return totalBytesWritten;
} }
public int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) public int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException { throws IOException, InterruptedException {
length = preAppend(length); length = preAppend(length);
int bytesAppended = int bytesAppended =
......
...@@ -26,9 +26,9 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer; ...@@ -26,9 +26,9 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.drm.DrmInitData; import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.DrmSession; import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.SampleDataReader;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
...@@ -469,7 +469,7 @@ public class SampleQueue implements TrackOutput { ...@@ -469,7 +469,7 @@ public class SampleQueue implements TrackOutput {
} }
@Override @Override
public final int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) public final int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException { throws IOException, InterruptedException {
return sampleDataQueue.sampleData(input, length, allowEndOfInput); return sampleDataQueue.sampleData(input, length, allowEndOfInput);
} }
......
...@@ -24,9 +24,9 @@ import com.google.android.exoplayer2.Format; ...@@ -24,9 +24,9 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.DummyTrackOutput; import com.google.android.exoplayer2.extractor.DummyTrackOutput;
import com.google.android.exoplayer2.extractor.Extractor; import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.SampleDataReader;
import com.google.android.exoplayer2.extractor.SeekMap; import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import java.io.IOException; import java.io.IOException;
...@@ -203,7 +203,7 @@ public final class ChunkExtractorWrapper implements ExtractorOutput { ...@@ -203,7 +203,7 @@ public final class ChunkExtractorWrapper implements ExtractorOutput {
} }
@Override @Override
public int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) public int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException { throws IOException, InterruptedException {
return castNonNull(trackOutput).sampleData(input, length, allowEndOfInput); return castNonNull(trackOutput).sampleData(input, length, allowEndOfInput);
} }
......
...@@ -25,7 +25,6 @@ import com.google.android.exoplayer2.Format; ...@@ -25,7 +25,6 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.SampleDataReader;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer; import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
...@@ -35,6 +34,7 @@ import com.google.android.exoplayer2.source.SampleQueue; ...@@ -35,6 +34,7 @@ import com.google.android.exoplayer2.source.SampleQueue;
import com.google.android.exoplayer2.source.chunk.Chunk; import com.google.android.exoplayer2.source.chunk.Chunk;
import com.google.android.exoplayer2.source.dash.manifest.DashManifest; import com.google.android.exoplayer2.source.dash.manifest.DashManifest;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
...@@ -295,7 +295,7 @@ public final class PlayerEmsgHandler implements Handler.Callback { ...@@ -295,7 +295,7 @@ public final class PlayerEmsgHandler implements Handler.Callback {
} }
@Override @Override
public int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) public int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException { throws IOException, InterruptedException {
return sampleQueue.sampleData(input, length, allowEndOfInput); return sampleQueue.sampleData(input, length, allowEndOfInput);
} }
......
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.extractor; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.extractor;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
...@@ -42,7 +43,7 @@ public final class DummyTrackOutput implements TrackOutput { ...@@ -42,7 +43,7 @@ public final class DummyTrackOutput implements TrackOutput {
} }
@Override @Override
public int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) public int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException { throws IOException, InterruptedException {
int bytesToSkipByReading = Math.min(readBuffer.length, length); int bytesToSkipByReading = Math.min(readBuffer.length, length);
int bytesSkipped = input.read(readBuffer, /* offset= */ 0, bytesToSkipByReading); int bytesSkipped = input.read(readBuffer, /* offset= */ 0, bytesToSkipByReading);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.extractor; package com.google.android.exoplayer2.extractor;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.upstream.DataReader;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -63,7 +64,7 @@ import java.io.InputStream; ...@@ -63,7 +64,7 @@ import java.io.InputStream;
* (regardless of {@code allowEndOfInput}). * (regardless of {@code allowEndOfInput}).
* </ul> * </ul>
*/ */
public interface ExtractorInput extends SampleDataReader { public interface ExtractorInput extends DataReader {
/** /**
* Reads up to {@code length} bytes from the input and resets the peek position. * Reads up to {@code length} bytes from the input and resets the peek position.
......
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.extractor; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.extractor;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
...@@ -103,7 +104,7 @@ public interface TrackOutput { ...@@ -103,7 +104,7 @@ public interface TrackOutput {
/** /**
* Called to write sample data to the output. * Called to write sample data to the output.
* *
* @param input An {@link ExtractorInput} from which to read the sample data. * @param input A {@link DataReader} from which to read the sample data.
* @param length The maximum length to read from the input. * @param length The maximum length to read from the input.
* @param allowEndOfInput True if encountering the end of the input having read no data is * @param allowEndOfInput True if encountering the end of the input having read no data is
* allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it * allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it
...@@ -112,7 +113,7 @@ public interface TrackOutput { ...@@ -112,7 +113,7 @@ public interface TrackOutput {
* @throws IOException If an error occurred reading from the input. * @throws IOException If an error occurred reading from the input.
* @throws InterruptedException If the thread was interrupted. * @throws InterruptedException If the thread was interrupted.
*/ */
int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException; throws IOException, InterruptedException;
/** /**
...@@ -127,15 +128,14 @@ public interface TrackOutput { ...@@ -127,15 +128,14 @@ public interface TrackOutput {
* Called when metadata associated with a sample has been extracted from the stream. * Called when metadata associated with a sample has been extracted from the stream.
* *
* <p>The corresponding sample data will have already been passed to the output via calls to * <p>The corresponding sample data will have already been passed to the output via calls to
* {@link #sampleData(SampleDataReader, int, boolean)} or {@link #sampleData(ParsableByteArray, * {@link #sampleData(DataReader, int, boolean)} or {@link #sampleData(ParsableByteArray, int)}.
* int)}.
* *
* @param timeUs The media timestamp associated with the sample, in microseconds. * @param timeUs The media timestamp associated with the sample, in microseconds.
* @param flags Flags associated with the sample. See {@code C.BUFFER_FLAG_*}. * @param flags Flags associated with the sample. See {@code C.BUFFER_FLAG_*}.
* @param size The size of the sample data, in bytes. * @param size The size of the sample data, in bytes.
* @param offset The number of bytes that have been passed to {@link #sampleData(SampleDataReader, * @param offset The number of bytes that have been passed to {@link #sampleData(DataReader, int,
* int, boolean)} or {@link #sampleData(ParsableByteArray, int)} since the last byte belonging * boolean)} or {@link #sampleData(ParsableByteArray, int)} since the last byte belonging to
* to the sample whose metadata is being passed. * the sample whose metadata is being passed.
* @param encryptionData The encryption data required to decrypt the sample. May be null. * @param encryptionData The encryption data required to decrypt the sample. May be null.
*/ */
void sampleMetadata( void sampleMetadata(
......
...@@ -30,7 +30,6 @@ import com.google.android.exoplayer2.drm.DrmSessionManager; ...@@ -30,7 +30,6 @@ import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.DummyTrackOutput; import com.google.android.exoplayer2.extractor.DummyTrackOutput;
import com.google.android.exoplayer2.extractor.Extractor; import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.SampleDataReader;
import com.google.android.exoplayer2.extractor.SeekMap; import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
...@@ -48,6 +47,7 @@ import com.google.android.exoplayer2.source.chunk.Chunk; ...@@ -48,6 +47,7 @@ import com.google.android.exoplayer2.source.chunk.Chunk;
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator; import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.Loader; import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.Loader.LoadErrorAction; import com.google.android.exoplayer2.upstream.Loader.LoadErrorAction;
...@@ -1459,7 +1459,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -1459,7 +1459,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
@Override @Override
public int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) public int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException { throws IOException, InterruptedException {
ensureBufferCapacity(bufferPosition + length); ensureBufferCapacity(bufferPosition + length);
int numBytesRead = input.read(buffer, bufferPosition, length); int numBytesRead = input.read(buffer, bufferPosition, length);
......
...@@ -20,9 +20,9 @@ import static com.google.common.truth.Truth.assertThat; ...@@ -20,9 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.SampleDataReader;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.testutil.Dumper.Dumpable; import com.google.android.exoplayer2.testutil.Dumper.Dumpable;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.EOFException; import java.io.EOFException;
...@@ -65,7 +65,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable { ...@@ -65,7 +65,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
} }
@Override @Override
public int sampleData(SampleDataReader input, int length, boolean allowEndOfInput) public int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException { throws IOException, InterruptedException {
byte[] newData = new byte[length]; byte[] newData = new byte[length];
int bytesAppended = input.read(newData, 0, length); int bytesAppended = input.read(newData, 0, length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment