Java Code Examples for com.google.android.exoplayer2.util.Assertions#checkArgument()
The following examples show how to use
com.google.android.exoplayer2.util.Assertions#checkArgument() .
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: UserDataReader.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public void createTracks( ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator) { for (int i = 0; i < outputs.length; i++) { idGenerator.generateNewId(); TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT); Format channelFormat = closedCaptionFormats.get(i); String channelMimeType = channelFormat.sampleMimeType; Assertions.checkArgument( MimeTypes.APPLICATION_CEA608.equals(channelMimeType) || MimeTypes.APPLICATION_CEA708.equals(channelMimeType), "Invalid closed caption mime type provided: " + channelMimeType); output.format( Format.createTextSampleFormat( idGenerator.getFormatId(), channelMimeType, /* codecs= */ null, /* bitrate= */ Format.NO_VALUE, channelFormat.selectionFlags, channelFormat.language, channelFormat.accessibilityChannel, /* drmInitData= */ null, Format.OFFSET_SAMPLE_RELATIVE, channelFormat.initializationData)); outputs[i] = output; } }
Example 2
Source File: ExtractorMediaSource.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { Assertions.checkArgument(id.periodIndex == 0); DataSource dataSource = dataSourceFactory.createDataSource(); if (transferListener != null) { dataSource.addTransferListener(transferListener); } return new ExtractorMediaPeriod( uri, dataSource, extractorsFactory.createExtractors(), minLoadableRetryCount, createEventDispatcher(id), this, allocator, customCacheKey, continueLoadingCheckIntervalBytes); }
Example 3
Source File: ConcatenatingMediaSource.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@GuardedBy("this") private void movePublicMediaSource( int currentIndex, int newIndex, @Nullable Handler handler, @Nullable Runnable onCompletionAction) { Assertions.checkArgument((handler == null) == (onCompletionAction == null)); Handler playbackThreadHandler = this.playbackThreadHandler; mediaSourcesPublic.add(newIndex, mediaSourcesPublic.remove(currentIndex)); if (playbackThreadHandler != null) { HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction); playbackThreadHandler .obtainMessage(MSG_MOVE, new MessageData<>(currentIndex, newIndex, callbackAction)) .sendToTarget(); } else if (onCompletionAction != null && handler != null) { handler.post(onCompletionAction); } }
Example 4
Source File: TrackSampleTable.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public TrackSampleTable( Track track, long[] offsets, int[] sizes, int maximumSize, long[] timestampsUs, int[] flags, long durationUs) { Assertions.checkArgument(sizes.length == timestampsUs.length); Assertions.checkArgument(offsets.length == timestampsUs.length); Assertions.checkArgument(flags.length == timestampsUs.length); this.track = track; this.offsets = offsets; this.sizes = sizes; this.maximumSize = maximumSize; this.timestampsUs = timestampsUs; this.flags = flags; this.durationUs = durationUs; sampleCount = offsets.length; if (flags.length > 0) { flags[flags.length - 1] |= C.BUFFER_FLAG_LAST_SAMPLE; } }
Example 5
Source File: ConcatenatingMediaSource.java From Telegram with GNU General Public License v2.0 | 5 votes |
@GuardedBy("this") private void setPublicShuffleOrder( ShuffleOrder shuffleOrder, @Nullable Handler handler, @Nullable Runnable onCompletionAction) { Assertions.checkArgument((handler == null) == (onCompletionAction == null)); Handler playbackThreadHandler = this.playbackThreadHandler; if (playbackThreadHandler != null) { int size = getSize(); if (shuffleOrder.getLength() != size) { shuffleOrder = shuffleOrder .cloneAndClear() .cloneAndInsert(/* insertionIndex= */ 0, /* insertionCount= */ size); } HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction); playbackThreadHandler .obtainMessage( MSG_SET_SHUFFLE_ORDER, new MessageData<>(/* index= */ 0, shuffleOrder, callbackAction)) .sendToTarget(); } else { this.shuffleOrder = shuffleOrder.getLength() > 0 ? shuffleOrder.cloneAndClear() : shuffleOrder; if (onCompletionAction != null && handler != null) { handler.post(onCompletionAction); } } }
Example 6
Source File: AtomParsers.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Returns the position of the esds box within a parent, or {@link C#POSITION_UNSET} if no esds * box is found */ private static int findEsdsPosition(ParsableByteArray parent, int position, int size) { int childAtomPosition = parent.getPosition(); while (childAtomPosition - position < size) { parent.setPosition(childAtomPosition); int childAtomSize = parent.readInt(); Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive"); int childType = parent.readInt(); if (childType == Atom.TYPE_esds) { return childAtomPosition; } childAtomPosition += childAtomSize; } return C.POSITION_UNSET; }
Example 7
Source File: DefaultOggSeeker.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public long startSeek(long timeUs) { Assertions.checkArgument(state == STATE_IDLE || state == STATE_SEEK); targetGranule = timeUs == 0 ? 0 : streamReader.convertTimeToGranule(timeUs); state = STATE_SEEK; resetSeeking(); return targetGranule; }
Example 8
Source File: AdPlaybackState.java From Telegram with GNU General Public License v2.0 | 5 votes |
private AdGroup(int count, @AdState int[] states, Uri[] uris, long[] durationsUs) { Assertions.checkArgument(states.length == uris.length); this.count = count; this.states = states; this.uris = uris; this.durationsUs = durationsUs; }
Example 9
Source File: AdPlaybackState.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** Returns a new instance with the specified ad durations, in microseconds. */ @CheckResult public AdGroup withAdDurationsUs(long[] durationsUs) { Assertions.checkArgument(count == C.LENGTH_UNSET || durationsUs.length <= this.uris.length); if (durationsUs.length < this.uris.length) { durationsUs = copyDurationsUsWithSpaceForAdCount(durationsUs, uris.length); } return new AdGroup(count, states, uris, durationsUs); }
Example 10
Source File: BaseMediaSource.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public final void prepareSource( SourceInfoRefreshListener listener, @Nullable TransferListener mediaTransferListener) { Looper looper = Looper.myLooper(); Assertions.checkArgument(this.looper == null || this.looper == looper); sourceInfoListeners.add(listener); if (this.looper == null) { this.looper = looper; prepareSourceInternal(mediaTransferListener); } else if (timeline != null) { listener.onSourceInfoRefreshed(/* source= */ this, timeline, manifest); } }
Example 11
Source File: SimpleDecoder.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override public final void queueInputBuffer(I inputBuffer) throws E { synchronized (lock) { maybeThrowException(); Assertions.checkArgument(inputBuffer == dequeuedInputBuffer); queuedInputBuffers.addLast(inputBuffer); maybeNotifyDecodeLoop(); dequeuedInputBuffer = null; } }
Example 12
Source File: FrameworkMediaDrm.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private FrameworkMediaDrm(UUID uuid) throws UnsupportedSchemeException { Assertions.checkNotNull(uuid); Assertions.checkArgument(!C.COMMON_PSSH_UUID.equals(uuid), "Use C.CLEARKEY_UUID instead"); this.uuid = uuid; this.mediaDrm = new MediaDrm(adjustUuid(uuid)); if (C.WIDEVINE_UUID.equals(uuid) && needsForceWidevineL3Workaround()) { forceWidevineL3(mediaDrm); } }
Example 13
Source File: DefaultDrmSessionManager.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * @param uuid The UUID of the drm scheme. * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param callback Performs key and provisioning requests. * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * to {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null. * @param multiSession A boolean that specify whether multiple key session support is enabled. * Default is false. * @param initialDrmRequestRetryCount The number of times to retry for initial provisioning and * key request before reporting error. */ public DefaultDrmSessionManager( UUID uuid, ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback, @Nullable HashMap<String, String> optionalKeyRequestParameters, boolean multiSession, int initialDrmRequestRetryCount) { Assertions.checkNotNull(uuid); Assertions.checkNotNull(mediaDrm); Assertions.checkArgument(!C.COMMON_PSSH_UUID.equals(uuid), "Use C.CLEARKEY_UUID instead"); this.uuid = uuid; this.mediaDrm = mediaDrm; this.callback = callback; this.optionalKeyRequestParameters = optionalKeyRequestParameters; this.eventDispatcher = new EventDispatcher<>(); this.multiSession = multiSession; this.initialDrmRequestRetryCount = initialDrmRequestRetryCount; mode = MODE_PLAYBACK; sessions = new ArrayList<>(); provisioningSessions = new ArrayList<>(); if (multiSession && C.WIDEVINE_UUID.equals(uuid) && Util.SDK_INT >= 19) { // TODO: Enabling session sharing probably doesn't do anything useful here. It would only be // useful if DefaultDrmSession instances were aware of one another's state, which is not // implemented. Or if custom renderers are being used that allow playback to proceed before // keys, which seems unlikely to be true in practice. mediaDrm.setPropertyString("sessionSharing", "enable"); } mediaDrm.setOnEventListener(new MediaDrmEventListener()); }
Example 14
Source File: CompositeMediaSource.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Prepares a child source. * * <p>{@link #onChildSourceInfoRefreshed(Object, MediaSource, Timeline)} will be called when the * child source updates its timeline with the same {@code id} passed to this method. * * <p>Any child sources that aren't explicitly released with {@link #releaseChildSource(Object)} * will be released in {@link #releaseSourceInternal()}. * * @param id A unique id to identify the child source preparation. Null is allowed as an id. * @param mediaSource The child {@link MediaSource}. */ protected final void prepareChildSource(final T id, MediaSource mediaSource) { Assertions.checkArgument(!childSources.containsKey(id)); MediaSourceCaller caller = (source, timeline) -> onChildSourceInfoRefreshed(id, source, timeline); MediaSourceEventListener eventListener = new ForwardingEventListener(id); childSources.put(id, new MediaSourceAndListener(mediaSource, caller, eventListener)); mediaSource.addEventListener(Assertions.checkNotNull(eventHandler), eventListener); mediaSource.prepareSource(caller, mediaTransferListener); if (!isEnabled()) { mediaSource.disable(caller); } }
Example 15
Source File: SubripSubtitle.java From K-Sonic with MIT License | 4 votes |
@Override public long getEventTime(int index) { Assertions.checkArgument(index >= 0); Assertions.checkArgument(index < cueTimesUs.length); return cueTimesUs[index]; }
Example 16
Source File: TrackSelectionUtil.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Returns bitrate values for a set of tracks whose upcoming media chunk iterators and formats are * given. * * <p>If an average bitrate can't be calculated, an estimation is calculated using average bitrate * of another track and the ratio of the bitrate values defined in the formats of the two tracks. * * @param iterators An array of {@link MediaChunkIterator}s providing information about the * sequence of upcoming media chunks for each track. * @param formats The track formats. * @param maxDurationUs Maximum duration of chunks to be included in average bitrate values, in * microseconds. * @param bitrates If not null, stores bitrate values in this array. * @return Average bitrate values for the tracks. If for a track, an average bitrate or an * estimation can't be calculated, {@link Format#NO_VALUE} is set. * @see #getAverageBitrate(MediaChunkIterator, long) */ @VisibleForTesting /* package */ static int[] getBitratesUsingFutureInfo( MediaChunkIterator[] iterators, Format[] formats, long maxDurationUs, @Nullable int[] bitrates) { int trackCount = iterators.length; Assertions.checkArgument(trackCount == formats.length); if (trackCount == 0) { return new int[0]; } if (bitrates == null) { bitrates = new int[trackCount]; } if (maxDurationUs == 0) { Arrays.fill(bitrates, Format.NO_VALUE); return bitrates; } int[] formatBitrates = new int[trackCount]; float[] bitrateRatios = new float[trackCount]; boolean needEstimateBitrate = false; boolean canEstimateBitrate = false; for (int i = 0; i < trackCount; i++) { int bitrate = getAverageBitrate(iterators[i], maxDurationUs); if (bitrate != Format.NO_VALUE) { int formatBitrate = formats[i].bitrate; formatBitrates[i] = formatBitrate; if (formatBitrate != Format.NO_VALUE) { bitrateRatios[i] = ((float) bitrate) / formatBitrate; canEstimateBitrate = true; } } else { needEstimateBitrate = true; formatBitrates[i] = Format.NO_VALUE; } bitrates[i] = bitrate; } if (needEstimateBitrate && canEstimateBitrate) { estimateBitrates(bitrates, formats, formatBitrates, bitrateRatios); } return bitrates; }
Example 17
Source File: DefaultLoadControl.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private static void assertGreaterOrEqual(int value1, int value2, String name1, String name2) { Assertions.checkArgument(value1 >= value2, name1 + " cannot be less than " + name2); }
Example 18
Source File: SubripSubtitle.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public long getEventTime(int index) { Assertions.checkArgument(index >= 0); Assertions.checkArgument(index < cueTimesUs.length); return cueTimesUs[index]; }
Example 19
Source File: HlsSampleStream.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public void bindSampleQueue() { Assertions.checkArgument(sampleQueueIndex == HlsSampleStreamWrapper.SAMPLE_QUEUE_INDEX_PENDING); sampleQueueIndex = sampleStreamWrapper.bindSampleQueueToSampleStream(trackGroupIndex); }
Example 20
Source File: DefaultBandwidthMeter.java From TelePlus-Android with GNU General Public License v2.0 | 3 votes |
/** * Sets an event listener for new bandwidth estimates. * * @param eventHandler A handler for events. * @param eventListener A listener of events. * @return This builder. * @throws IllegalArgumentException If the event handler or listener are null. */ public Builder setEventListener(Handler eventHandler, EventListener eventListener) { Assertions.checkArgument(eventHandler != null && eventListener != null); this.eventHandler = eventHandler; this.eventListener = eventListener; return this; }