Java Code Examples for com.google.android.exoplayer2.util.Assertions#checkState()
The following examples show how to use
com.google.android.exoplayer2.util.Assertions#checkState() .
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: BaseTrackSelection.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * @param group The {@link TrackGroup}. Must not be null. * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be * null or empty. May be in any order. */ public BaseTrackSelection(TrackGroup group, int... tracks) { Assertions.checkState(tracks.length > 0); this.group = Assertions.checkNotNull(group); this.length = tracks.length; // Set the formats, sorted in order of decreasing bandwidth. formats = new Format[length]; for (int i = 0; i < tracks.length; i++) { formats[i] = group.getFormat(tracks[i]); } Arrays.sort(formats, new DecreasingBandwidthComparator()); // Set the format indices in the same order. this.tracks = new int[length]; for (int i = 0; i < length; i++) { this.tracks[i] = group.indexOf(formats[i]); } blacklistUntilTimes = new long[length]; }
Example 2
Source File: ChunkExtractorWrapper.java From K-Sonic with MIT License | 5 votes |
@Override public TrackOutput track(int id, int type) { BindingTrackOutput bindingTrackOutput = bindingTrackOutputs.get(id); if (bindingTrackOutput == null) { // Assert that if we're seeing a new track we have not seen endTracks. Assertions.checkState(sampleFormats == null); bindingTrackOutput = new BindingTrackOutput(id, type, manifestFormat); bindingTrackOutput.bind(trackOutputProvider); bindingTrackOutputs.put(id, bindingTrackOutput); } return bindingTrackOutput; }
Example 3
Source File: SimpleCache.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@NonNull @Override public synchronized NavigableSet<CacheSpan> getCachedSpans(String key) { Assertions.checkState(!released); CachedContent cachedContent = index.get(key); return cachedContent == null || cachedContent.isEmpty() ? new TreeSet<CacheSpan>() : new TreeSet<CacheSpan>(cachedContent.getSpans()); }
Example 4
Source File: DownloadManager.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Nullable @CheckResult private Task syncQueuedDownload(@Nullable Task activeTask, Download download) { if (activeTask != null) { // We have a task, which must be a download task. If the download state is queued we need to // cancel it and start a new one, since a new request has been merged into the download. Assertions.checkState(!activeTask.isRemove); activeTask.cancel(/* released= */ false); return activeTask; } if (!canDownloadsRun() || activeDownloadTaskCount >= maxParallelDownloads) { return null; } // We can start a download task. download = putDownloadWithState(download, STATE_DOWNLOADING); Downloader downloader = downloaderFactory.createDownloader(download.request); activeTask = new Task( download.request, downloader, download.progress, /* isRemove= */ false, minRetryCount, /* internalHandler= */ this); activeTasks.put(download.request.id, activeTask); if (activeDownloadTaskCount++ == 0) { sendEmptyMessageDelayed(MSG_UPDATE_PROGRESS, UPDATE_PROGRESS_INTERVAL_MS); } activeTask.start(); return activeTask; }
Example 5
Source File: DrmInitData.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Returns an instance containing the {@link #schemeDatas} from both this and {@code other}. The * {@link #schemeType} of the instances being merged must either match, or at least one scheme * type must be {@code null}. * * @param drmInitData The instance to merge. * @return The merged result. */ public DrmInitData merge(DrmInitData drmInitData) { Assertions.checkState( schemeType == null || drmInitData.schemeType == null || TextUtils.equals(schemeType, drmInitData.schemeType)); String mergedSchemeType = schemeType != null ? this.schemeType : drmInitData.schemeType; SchemeData[] mergedSchemeDatas = Util.nullSafeArrayConcatenation(schemeDatas, drmInitData.schemeDatas); return new DrmInitData(mergedSchemeType, mergedSchemeDatas); }
Example 6
Source File: CachedContentIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public void load( HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey) { Assertions.checkState(!changed); if (!readFile(content, idToKey)) { content.clear(); idToKey.clear(); atomicFile.delete(); } }
Example 7
Source File: Sonic.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void adjustRate(float rate, int originalOutputFrameCount) { if (outputFrameCount == originalOutputFrameCount) { return; } int newSampleRate = (int) (inputSampleRateHz / rate); int oldSampleRate = inputSampleRateHz; // Set these values to help with the integer math. while (newSampleRate > (1 << 14) || oldSampleRate > (1 << 14)) { newSampleRate /= 2; oldSampleRate /= 2; } moveNewSamplesToPitchBuffer(originalOutputFrameCount); // Leave at least one pitch sample in the buffer. for (int position = 0; position < pitchFrameCount - 1; position++) { while ((oldRatePosition + 1) * newSampleRate > newRatePosition * oldSampleRate) { outputBuffer = ensureSpaceForAdditionalFrames( outputBuffer, outputFrameCount, /* additionalFrameCount= */ 1); for (int i = 0; i < channelCount; i++) { outputBuffer[outputFrameCount * channelCount + i] = interpolate(pitchBuffer, position * channelCount + i, oldSampleRate, newSampleRate); } newRatePosition++; outputFrameCount++; } oldRatePosition++; if (oldRatePosition == oldSampleRate) { oldRatePosition = 0; Assertions.checkState(newRatePosition == newSampleRate); newRatePosition = 0; } } removePitchFrames(pitchFrameCount - 1); }
Example 8
Source File: CeaDecoder.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public SubtitleInputBuffer dequeueInputBuffer() throws SubtitleDecoderException { Assertions.checkState(dequeuedInputBuffer == null); if (availableInputBuffers.isEmpty()) { return null; } dequeuedInputBuffer = availableInputBuffers.pollFirst(); return dequeuedInputBuffer; }
Example 9
Source File: CachedContent.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Copies the given span with an updated last access time. Passed span becomes invalid after this * call. * * @param cacheSpan Span to be copied and updated. * @return a span with the updated last access time. * @throws CacheException If renaming of the underlying span file failed. */ public SimpleCacheSpan touch(SimpleCacheSpan cacheSpan) throws CacheException { // Remove the old span from the in-memory representation. Assertions.checkState(cachedSpans.remove(cacheSpan)); // Obtain a new span with updated last access timestamp. SimpleCacheSpan newCacheSpan = cacheSpan.copyWithUpdatedLastAccessTime(id); // Rename the cache file if (!cacheSpan.file.renameTo(newCacheSpan.file)) { throw new CacheException("Renaming of " + cacheSpan.file + " to " + newCacheSpan.file + " failed."); } // Add the updated span back into the in-memory representation. cachedSpans.add(newCacheSpan); return newCacheSpan; }
Example 10
Source File: SampleChooserActivity.java From ExoPlayer-Offline with Apache License 2.0 | 4 votes |
private Sample readEntry(JsonReader reader, boolean insidePlaylist) throws IOException { String sampleName = null; String uri = null; String extension = null; UUID drmUuid = null; String drmLicenseUrl = null; String[] drmKeyRequestProperties = null; boolean preferExtensionDecoders = false; ArrayList<UriSample> playlistSamples = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); switch (name) { case "name": sampleName = reader.nextString(); break; case "uri": uri = reader.nextString(); break; case "extension": extension = reader.nextString(); break; case "drm_scheme": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: drm_scheme"); drmUuid = getDrmUuid(reader.nextString()); break; case "drm_license_url": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: drm_license_url"); drmLicenseUrl = reader.nextString(); break; case "drm_key_request_properties": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: drm_key_request_properties"); ArrayList<String> drmKeyRequestPropertiesList = new ArrayList<>(); reader.beginObject(); while (reader.hasNext()) { drmKeyRequestPropertiesList.add(reader.nextName()); drmKeyRequestPropertiesList.add(reader.nextString()); } reader.endObject(); drmKeyRequestProperties = drmKeyRequestPropertiesList.toArray(new String[0]); break; case "prefer_extension_decoders": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: prefer_extension_decoders"); preferExtensionDecoders = reader.nextBoolean(); break; case "playlist": Assertions.checkState(!insidePlaylist, "Invalid nesting of playlists"); playlistSamples = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { playlistSamples.add((UriSample) readEntry(reader, true)); } reader.endArray(); break; default: throw new ParserException("Unsupported attribute name: " + name); } } reader.endObject(); if (playlistSamples != null) { UriSample[] playlistSamplesArray = playlistSamples.toArray( new UriSample[playlistSamples.size()]); return new PlaylistSample(sampleName, drmUuid, drmLicenseUrl, drmKeyRequestProperties, preferExtensionDecoders, playlistSamplesArray); } else { return new UriSample(sampleName, drmUuid, drmLicenseUrl, drmKeyRequestProperties, preferExtensionDecoders, uri, extension); } }
Example 11
Source File: SonicAudioProcessor.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void queueEndOfStream() { Assertions.checkState(sonic != null); sonic.queueEndOfStream(); inputEnded = true; }
Example 12
Source File: SimpleDecoderVideoRenderer.java From MediaSDK with Apache License 2.0 | 4 votes |
@Override public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException { if (outputStreamEnded) { return; } if (inputFormat == null) { // We don't have a format yet, so try and read one. FormatHolder formatHolder = getFormatHolder(); flagsOnlyBuffer.clear(); int result = readSource(formatHolder, flagsOnlyBuffer, true); if (result == C.RESULT_FORMAT_READ) { onInputFormatChanged(formatHolder); } else if (result == C.RESULT_BUFFER_READ) { // End of stream read having not read a format. Assertions.checkState(flagsOnlyBuffer.isEndOfStream()); inputStreamEnded = true; outputStreamEnded = true; return; } else { // We still don't have a format and can't make progress without one. return; } } // If we don't have a decoder yet, we need to instantiate one. maybeInitDecoder(); if (decoder != null) { try { // Rendering loop. TraceUtil.beginSection("drainAndFeed"); while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {} while (feedInputBuffer()) {} TraceUtil.endSection(); } catch (VideoDecoderException e) { throw createRendererException(e, inputFormat); } decoderCounters.ensureUpdated(); } }
Example 13
Source File: BufferSizeAdaptationBuilder.java From Telegram with GNU General Public License v2.0 | 3 votes |
/** * Sets track selection parameters used during the start-up phase before the selection can be made * purely on based on buffer size. During the start-up phase the selection is based on the current * bandwidth estimate. * * @param bandwidthFraction The fraction of the available bandwidth that the selection should * consider available for use. Setting to a value less than 1 is recommended to account for * inaccuracies in the bandwidth estimator. * @param minBufferForQualityIncreaseMs The minimum duration of buffered media required for the * selected track to switch to one of higher quality. * @return This builder, for convenience. * @throws IllegalStateException If {@link #buildPlayerComponents()} has already been called. */ public BufferSizeAdaptationBuilder setStartUpTrackSelectionParameters( float bandwidthFraction, int minBufferForQualityIncreaseMs) { Assertions.checkState(!buildCalled); this.startUpBandwidthFraction = bandwidthFraction; this.startUpMinBufferForQualityIncreaseMs = minBufferForQualityIncreaseMs; return this; }
Example 14
Source File: NoSampleRenderer.java From TelePlus-Android with GNU General Public License v2.0 | 3 votes |
/** * Replaces the {@link SampleStream} that will be associated with this renderer. * <p> * This method may be called when the renderer is in the following states: * {@link #STATE_DISABLED}. * * @param configuration The renderer configuration. * @param formats The enabled formats. Should be empty. * @param stream The {@link SampleStream} from which the renderer should consume. * @param positionUs The player's current position. * @param joining Whether this renderer is being enabled to join an ongoing playback. * @param offsetUs The offset that should be subtracted from {@code positionUs} * to get the playback position with respect to the media. * @throws ExoPlaybackException If an error occurs. */ @Override public final void enable(RendererConfiguration configuration, Format[] formats, SampleStream stream, long positionUs, boolean joining, long offsetUs) throws ExoPlaybackException { Assertions.checkState(state == STATE_DISABLED); this.configuration = configuration; state = STATE_ENABLED; onEnabled(joining); replaceStream(formats, stream, offsetUs); onPositionReset(positionUs, joining); }
Example 15
Source File: ExoPlaybackException.java From TelePlus-Android with GNU General Public License v2.0 | 2 votes |
/** * Retrieves the underlying error when {@link #type} is {@link #TYPE_RENDERER}. * * @throws IllegalStateException If {@link #type} is not {@link #TYPE_RENDERER}. */ public Exception getRendererException() { Assertions.checkState(type == TYPE_RENDERER); return (Exception) getCause(); }
Example 16
Source File: PlayerMessage.java From Telegram with GNU General Public License v2.0 | 2 votes |
/** * Sets a position in the current window at which the message will be delivered. * * @param positionMs The position in the current window at which the message will be sent, in * milliseconds. * @return This message. * @throws IllegalStateException If {@link #send()} has already been called. */ public PlayerMessage setPosition(long positionMs) { Assertions.checkState(!isSent); this.positionMs = positionMs; return this; }
Example 17
Source File: PlayerMessage.java From Telegram-FOSS with GNU General Public License v2.0 | 2 votes |
/** * Sets the handler the message is delivered on. * * @param handler A {@link Handler}. * @return This message. * @throws IllegalStateException If {@link #send()} has already been called. */ public PlayerMessage setHandler(Handler handler) { Assertions.checkState(!isSent); this.handler = handler; return this; }
Example 18
Source File: SsMediaSource.java From Telegram with GNU General Public License v2.0 | 2 votes |
/** * Sets the manifest parser to parse loaded manifest data when loading a manifest URI. * * @param manifestParser A parser for loaded manifest data. * @return This factory, for convenience. * @throws IllegalStateException If one of the {@code create} methods has already been called. */ public Factory setManifestParser(ParsingLoadable.Parser<? extends SsManifest> manifestParser) { Assertions.checkState(!isCreateCalled); this.manifestParser = Assertions.checkNotNull(manifestParser); return this; }
Example 19
Source File: ExoPlayer.java From MediaSDK with Apache License 2.0 | 2 votes |
/** * Sets the {@link LoadControl} that will be used by the player. * * @param loadControl A {@link LoadControl}. * @return This builder. * @throws IllegalStateException If {@link #build()} has already been called. */ public Builder setLoadControl(LoadControl loadControl) { Assertions.checkState(!buildCalled); this.loadControl = loadControl; return this; }
Example 20
Source File: SsMediaSource.java From Telegram with GNU General Public License v2.0 | 2 votes |
/** * Sets a list of {@link StreamKey stream keys} by which the manifest is filtered. * * @param streamKeys A list of {@link StreamKey stream keys}. * @return This factory, for convenience. * @throws IllegalStateException If one of the {@code create} methods has already been called. */ public Factory setStreamKeys(List<StreamKey> streamKeys) { Assertions.checkState(!isCreateCalled); this.streamKeys = streamKeys; return this; }