Java Code Examples for com.google.android.exoplayer2.util.Util#EMPTY_BYTE_ARRAY

The following examples show how to use com.google.android.exoplayer2.util.Util#EMPTY_BYTE_ARRAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadRequest.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param id See {@link #id}.
 * @param type See {@link #type}.
 * @param uri See {@link #uri}.
 * @param streamKeys See {@link #streamKeys}.
 * @param customCacheKey See {@link #customCacheKey}.
 * @param data See {@link #data}.
 */
public DownloadRequest(
    String id,
    String type,
    Uri uri,
    List<StreamKey> streamKeys,
    @Nullable String customCacheKey,
    @Nullable byte[] data) {
  if (TYPE_DASH.equals(type) || TYPE_HLS.equals(type) || TYPE_SS.equals(type)) {
    Assertions.checkArgument(
        customCacheKey == null, "customCacheKey must be null for type: " + type);
  }
  this.id = id;
  this.type = type;
  this.uri = uri;
  ArrayList<StreamKey> mutableKeys = new ArrayList<>(streamKeys);
  Collections.sort(mutableKeys);
  this.streamKeys = Collections.unmodifiableList(mutableKeys);
  this.customCacheKey = customCacheKey;
  this.data = data != null ? Arrays.copyOf(data, data.length) : Util.EMPTY_BYTE_ARRAY;
}
 
Example 2
Source File: DownloadRequest.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param id See {@link #id}.
 * @param type See {@link #type}.
 * @param uri See {@link #uri}.
 * @param streamKeys See {@link #streamKeys}.
 * @param customCacheKey See {@link #customCacheKey}.
 * @param data See {@link #data}.
 */
public DownloadRequest(
    String id,
    String type,
    Uri uri,
    List<StreamKey> streamKeys,
    @Nullable String customCacheKey,
    @Nullable byte[] data) {
  if (TYPE_DASH.equals(type) || TYPE_HLS.equals(type) || TYPE_SS.equals(type)) {
    Assertions.checkArgument(
        customCacheKey == null, "customCacheKey must be null for type: " + type);
  }
  this.id = id;
  this.type = type;
  this.uri = uri;
  ArrayList<StreamKey> mutableKeys = new ArrayList<>(streamKeys);
  Collections.sort(mutableKeys);
  this.streamKeys = Collections.unmodifiableList(mutableKeys);
  this.customCacheKey = customCacheKey;
  this.data = data != null ? Arrays.copyOf(data, data.length) : Util.EMPTY_BYTE_ARRAY;
}
 
Example 3
Source File: SilenceSkippingAudioProcessor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onReset() {
  enabled = false;
  paddingSize = 0;
  maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
  paddingBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 4
Source File: CachedContentIndex.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserializes a {@link DefaultContentMetadata} from the given input stream.
 *
 * @param input Input stream to read from.
 * @return a {@link DefaultContentMetadata} instance.
 * @throws IOException If an error occurs during reading from the input.
 */
private static DefaultContentMetadata readContentMetadata(DataInputStream input)
    throws IOException {
  int size = input.readInt();
  HashMap<String, byte[]> metadata = new HashMap<>();
  for (int i = 0; i < size; i++) {
    String name = input.readUTF();
    int valueSize = input.readInt();
    if (valueSize < 0) {
      throw new IOException("Invalid value size: " + valueSize);
    }
    // Grow the array incrementally to avoid OutOfMemoryError in the case that a corrupt (and very
    // large) valueSize was read. In such cases the implementation below is expected to throw
    // IOException from one of the readFully calls, due to the end of the input being reached.
    int bytesRead = 0;
    int nextBytesToRead = Math.min(valueSize, INCREMENTAL_METADATA_READ_LENGTH);
    byte[] value = Util.EMPTY_BYTE_ARRAY;
    while (bytesRead != valueSize) {
      value = Arrays.copyOf(value, bytesRead + nextBytesToRead);
      input.readFully(value, bytesRead, nextBytesToRead);
      bytesRead += nextBytesToRead;
      nextBytesToRead = Math.min(valueSize - bytesRead, INCREMENTAL_METADATA_READ_LENGTH);
    }
    metadata.put(name, value);
  }
  return new DefaultContentMetadata(metadata);
}
 
Example 5
Source File: SilenceSkippingAudioProcessor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onReset() {
  enabled = false;
  paddingSize = 0;
  maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
  paddingBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 6
Source File: CachedContentIndex.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes a {@link DefaultContentMetadata} from the given input stream.
 *
 * @param input Input stream to read from.
 * @return a {@link DefaultContentMetadata} instance.
 * @throws IOException If an error occurs during reading from the input.
 */
private static DefaultContentMetadata readContentMetadata(DataInputStream input)
    throws IOException {
  int size = input.readInt();
  HashMap<String, byte[]> metadata = new HashMap<>();
  for (int i = 0; i < size; i++) {
    String name = input.readUTF();
    int valueSize = input.readInt();
    if (valueSize < 0) {
      throw new IOException("Invalid value size: " + valueSize);
    }
    // Grow the array incrementally to avoid OutOfMemoryError in the case that a corrupt (and very
    // large) valueSize was read. In such cases the implementation below is expected to throw
    // IOException from one of the readFully calls, due to the end of the input being reached.
    int bytesRead = 0;
    int nextBytesToRead = Math.min(valueSize, INCREMENTAL_METADATA_READ_LENGTH);
    byte[] value = Util.EMPTY_BYTE_ARRAY;
    while (bytesRead != valueSize) {
      value = Arrays.copyOf(value, bytesRead + nextBytesToRead);
      input.readFully(value, bytesRead, nextBytesToRead);
      bytesRead += nextBytesToRead;
      nextBytesToRead = Math.min(valueSize - bytesRead, INCREMENTAL_METADATA_READ_LENGTH);
    }
    metadata.put(name, value);
  }
  return new DefaultContentMetadata(metadata);
}
 
Example 7
Source File: CachedContentIndex.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserializes a {@link DefaultContentMetadata} from the given input stream.
 *
 * @param input Input stream to read from.
 * @return a {@link DefaultContentMetadata} instance.
 * @throws IOException If an error occurs during reading from the input.
 */
private static DefaultContentMetadata readContentMetadata(DataInputStream input)
    throws IOException {
  int size = input.readInt();
  HashMap<String, byte[]> metadata = new HashMap<>();
  for (int i = 0; i < size; i++) {
    String name = input.readUTF();
    int valueSize = input.readInt();
    if (valueSize < 0) {
      throw new IOException("Invalid value size: " + valueSize);
    }
    // Grow the array incrementally to avoid OutOfMemoryError in the case that a corrupt (and very
    // large) valueSize was read. In such cases the implementation below is expected to throw
    // IOException from one of the readFully calls, due to the end of the input being reached.
    int bytesRead = 0;
    int nextBytesToRead = Math.min(valueSize, INCREMENTAL_METADATA_READ_LENGTH);
    byte[] value = Util.EMPTY_BYTE_ARRAY;
    while (bytesRead != valueSize) {
      value = Arrays.copyOf(value, bytesRead + nextBytesToRead);
      input.readFully(value, bytesRead, nextBytesToRead);
      bytesRead += nextBytesToRead;
      nextBytesToRead = Math.min(valueSize - bytesRead, INCREMENTAL_METADATA_READ_LENGTH);
    }
    metadata.put(name, value);
  }
  return new DefaultContentMetadata(metadata);
}
 
Example 8
Source File: SilenceSkippingAudioProcessor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
protected void onReset() {
  enabled = false;
  paddingSize = 0;
  maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
  paddingBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 9
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * @param extractorFactory An {@link HlsExtractorFactory} from which to obtain the extractors for
 *     media chunks.
 * @param playlistTracker The {@link HlsPlaylistTracker} from which to obtain media playlists.
 * @param playlistUrls The {@link Uri}s of the media playlists that can be adapted between by this
 *     chunk source.
 * @param playlistFormats The {@link Format Formats} corresponding to the media playlists.
 * @param dataSourceFactory An {@link HlsDataSourceFactory} to create {@link DataSource}s for the
 *     chunks.
 * @param mediaTransferListener The transfer listener which should be informed of any media data
 *     transfers. May be null if no listener is available.
 * @param timestampAdjusterProvider A provider of {@link TimestampAdjuster} instances. If multiple
 *     {@link HlsChunkSource}s are used for a single playback, they should all share the same
 *     provider.
 * @param muxedCaptionFormats List of muxed caption {@link Format}s. Null if no closed caption
 *     information is available in the master playlist.
 */
public HlsChunkSource(
    HlsExtractorFactory extractorFactory,
    HlsPlaylistTracker playlistTracker,
    Uri[] playlistUrls,
    Format[] playlistFormats,
    HlsDataSourceFactory dataSourceFactory,
    @Nullable TransferListener mediaTransferListener,
    TimestampAdjusterProvider timestampAdjusterProvider,
    @Nullable List<Format> muxedCaptionFormats) {
  this.extractorFactory = extractorFactory;
  this.playlistTracker = playlistTracker;
  this.playlistUrls = playlistUrls;
  this.playlistFormats = playlistFormats;
  this.timestampAdjusterProvider = timestampAdjusterProvider;
  this.muxedCaptionFormats = muxedCaptionFormats;
  keyCache = new FullSegmentEncryptionKeyCache(KEY_CACHE_SIZE);
  scratchSpace = Util.EMPTY_BYTE_ARRAY;
  liveEdgeInPeriodTimeUs = C.TIME_UNSET;
  mediaDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_MEDIA);
  if (mediaTransferListener != null) {
    mediaDataSource.addTransferListener(mediaTransferListener);
  }
  encryptionDataSource = dataSourceFactory.createDataSource(C.DATA_TYPE_DRM);
  trackGroup = new TrackGroup(playlistFormats);
  int[] initialTrackSelection = new int[playlistUrls.length];
  for (int i = 0; i < playlistUrls.length; i++) {
    initialTrackSelection[i] = i;
  }
  trackSelection = new InitializationTrackSelection(trackGroup, initialTrackSelection);
}
 
Example 10
Source File: TrimmingAudioProcessor.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
protected void onReset() {
  endBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 11
Source File: SilenceSkippingAudioProcessor.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/** Creates a new silence trimming audio processor. */
public SilenceSkippingAudioProcessor() {
  maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
  paddingBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 12
Source File: SilenceSkippingAudioProcessor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new silence trimming audio processor. */
public SilenceSkippingAudioProcessor() {
  maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
  paddingBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 13
Source File: TrimmingAudioProcessor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onReset() {
  endBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 14
Source File: TrimmingAudioProcessor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new audio processor for trimming samples from the start/end of data. */
public TrimmingAudioProcessor() {
  endBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 15
Source File: TrimmingAudioProcessor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new audio processor for trimming samples from the start/end of data. */
public TrimmingAudioProcessor() {
  endBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 16
Source File: SilenceSkippingAudioProcessor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new silence trimming audio processor. */
public SilenceSkippingAudioProcessor() {
  maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
  paddingBuffer = Util.EMPTY_BYTE_ARRAY;
}
 
Example 17
Source File: DummyExoMediaDrm.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] getPropertyByteArray(String propertyName) {
  return Util.EMPTY_BYTE_ARRAY;
}
 
Example 18
Source File: Id3Decoder.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Copies the specified range of an array, or returns a zero length array if the range is invalid.
 *
 * @param data The array from which to copy.
 * @param from The start of the range to copy (inclusive).
 * @param to The end of the range to copy (exclusive).
 * @return The copied data, or a zero length array if the range is invalid.
 */
private static byte[] copyOfRangeIfValid(byte[] data, int from, int to) {
  if (to <= from) {
    // Invalid or zero length range.
    return Util.EMPTY_BYTE_ARRAY;
  }
  return Arrays.copyOfRange(data, from, to);
}
 
Example 19
Source File: Id3Decoder.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Copies the specified range of an array, or returns a zero length array if the range is invalid.
 *
 * @param data The array from which to copy.
 * @param from The start of the range to copy (inclusive).
 * @param to The end of the range to copy (exclusive).
 * @return The copied data, or a zero length array if the range is invalid.
 */
private static byte[] copyOfRangeIfValid(byte[] data, int from, int to) {
  if (to <= from) {
    // Invalid or zero length range.
    return Util.EMPTY_BYTE_ARRAY;
  }
  return Arrays.copyOfRange(data, from, to);
}
 
Example 20
Source File: Id3Decoder.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Copies the specified range of an array, or returns a zero length array if the range is invalid.
 *
 * @param data The array from which to copy.
 * @param from The start of the range to copy (inclusive).
 * @param to The end of the range to copy (exclusive).
 * @return The copied data, or a zero length array if the range is invalid.
 */
private static byte[] copyOfRangeIfValid(byte[] data, int from, int to) {
  if (to <= from) {
    // Invalid or zero length range.
    return Util.EMPTY_BYTE_ARRAY;
  }
  return Arrays.copyOfRange(data, from, to);
}