Search in sources :

Example 31 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class DashManifestParser method buildRepresentation.

protected Representation buildRepresentation(RepresentationInfo representationInfo, String contentId, ArrayList<SchemeData> extraDrmSchemeDatas, ArrayList<SchemeValuePair> extraInbandEventStreams) {
    Format format = representationInfo.format;
    ArrayList<SchemeData> drmSchemeDatas = representationInfo.drmSchemeDatas;
    drmSchemeDatas.addAll(extraDrmSchemeDatas);
    if (!drmSchemeDatas.isEmpty()) {
        format = format.copyWithDrmInitData(new DrmInitData(drmSchemeDatas));
    }
    ArrayList<SchemeValuePair> inbandEventStremas = representationInfo.inbandEventStreams;
    inbandEventStremas.addAll(extraInbandEventStreams);
    return Representation.newInstance(contentId, Representation.REVISION_ID_DEFAULT, format, representationInfo.baseUrl, representationInfo.segmentBase, inbandEventStremas);
}
Also used : Format(com.google.android.exoplayer2.Format) DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData)

Example 32 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class TtmlDecoder method parseTimeExpression.

/**
   * Parses a time expression, returning the parsed timestamp.
   * <p>
   * For the format of a time expression, see:
   * <a href="http://www.w3.org/TR/ttaf1-dfxp/#timing-value-timeExpression">timeExpression</a>
   *
   * @param time A string that includes the time expression.
   * @param frameAndTickRate The effective frame and tick rates of the stream.
   * @return The parsed timestamp in microseconds.
   * @throws SubtitleDecoderException If the given string does not contain a valid time expression.
   */
private static long parseTimeExpression(String time, FrameAndTickRate frameAndTickRate) throws SubtitleDecoderException {
    Matcher matcher = CLOCK_TIME.matcher(time);
    if (matcher.matches()) {
        String hours = matcher.group(1);
        double durationSeconds = Long.parseLong(hours) * 3600;
        String minutes = matcher.group(2);
        durationSeconds += Long.parseLong(minutes) * 60;
        String seconds = matcher.group(3);
        durationSeconds += Long.parseLong(seconds);
        String fraction = matcher.group(4);
        durationSeconds += (fraction != null) ? Double.parseDouble(fraction) : 0;
        String frames = matcher.group(5);
        durationSeconds += (frames != null) ? Long.parseLong(frames) / frameAndTickRate.effectiveFrameRate : 0;
        String subframes = matcher.group(6);
        durationSeconds += (subframes != null) ? ((double) Long.parseLong(subframes)) / frameAndTickRate.subFrameRate / frameAndTickRate.effectiveFrameRate : 0;
        return (long) (durationSeconds * C.MICROS_PER_SECOND);
    }
    matcher = OFFSET_TIME.matcher(time);
    if (matcher.matches()) {
        String timeValue = matcher.group(1);
        double offsetSeconds = Double.parseDouble(timeValue);
        String unit = matcher.group(2);
        switch(unit) {
            case "h":
                offsetSeconds *= 3600;
                break;
            case "m":
                offsetSeconds *= 60;
                break;
            case "s":
                // Do nothing.
                break;
            case "ms":
                offsetSeconds /= 1000;
                break;
            case "f":
                offsetSeconds /= frameAndTickRate.effectiveFrameRate;
                break;
            case "t":
                offsetSeconds /= frameAndTickRate.tickRate;
                break;
        }
        return (long) (offsetSeconds * C.MICROS_PER_SECOND);
    }
    throw new SubtitleDecoderException("Malformed time expression: " + time);
}
Also used : Matcher(java.util.regex.Matcher) SubtitleDecoderException(com.google.android.exoplayer2.text.SubtitleDecoderException)

Example 33 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class DashMediaPeriod method buildTrackGroups.

// Internal methods.
private static Pair<TrackGroupArray, EmbeddedTrackInfo[]> buildTrackGroups(List<AdaptationSet> adaptationSets) {
    int adaptationSetCount = adaptationSets.size();
    int embeddedTrackCount = getEmbeddedTrackCount(adaptationSets);
    TrackGroup[] trackGroupArray = new TrackGroup[adaptationSetCount + embeddedTrackCount];
    EmbeddedTrackInfo[] embeddedTrackInfos = new EmbeddedTrackInfo[embeddedTrackCount];
    int embeddedTrackIndex = 0;
    for (int i = 0; i < adaptationSetCount; i++) {
        AdaptationSet adaptationSet = adaptationSets.get(i);
        List<Representation> representations = adaptationSet.representations;
        Format[] formats = new Format[representations.size()];
        for (int j = 0; j < formats.length; j++) {
            formats[j] = representations.get(j).format;
        }
        trackGroupArray[i] = new TrackGroup(formats);
        if (hasEventMessageTrack(adaptationSet)) {
            Format format = Format.createSampleFormat(adaptationSet.id + ":emsg", MimeTypes.APPLICATION_EMSG, null, Format.NO_VALUE, null);
            trackGroupArray[adaptationSetCount + embeddedTrackIndex] = new TrackGroup(format);
            embeddedTrackInfos[embeddedTrackIndex++] = new EmbeddedTrackInfo(i, C.TRACK_TYPE_METADATA);
        }
        if (hasCea608Track(adaptationSet)) {
            Format format = Format.createTextSampleFormat(adaptationSet.id + ":cea608", MimeTypes.APPLICATION_CEA608, null, Format.NO_VALUE, 0, null, null);
            trackGroupArray[adaptationSetCount + embeddedTrackIndex] = new TrackGroup(format);
            embeddedTrackInfos[embeddedTrackIndex++] = new EmbeddedTrackInfo(i, C.TRACK_TYPE_TEXT);
        }
    }
    return Pair.create(new TrackGroupArray(trackGroupArray), embeddedTrackInfos);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation)

Example 34 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class AdaptiveTrackSelection method evaluateQueueSize.

@Override
public int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue) {
    if (queue.isEmpty()) {
        return 0;
    }
    int queueSize = queue.size();
    long bufferedDurationUs = queue.get(queueSize - 1).endTimeUs - playbackPositionUs;
    if (bufferedDurationUs < minDurationToRetainAfterDiscardUs) {
        return queueSize;
    }
    int idealSelectedIndex = determineIdealSelectedIndex(SystemClock.elapsedRealtime());
    Format idealFormat = getFormat(idealSelectedIndex);
    // track.
    for (int i = 0; i < queueSize; i++) {
        MediaChunk chunk = queue.get(i);
        Format format = chunk.trackFormat;
        long durationBeforeThisChunkUs = chunk.startTimeUs - playbackPositionUs;
        if (durationBeforeThisChunkUs >= minDurationToRetainAfterDiscardUs && format.bitrate < idealFormat.bitrate && format.height != Format.NO_VALUE && format.height < 720 && format.width != Format.NO_VALUE && format.width < 1280 && format.height < idealFormat.height) {
            return i;
        }
    }
    return queueSize;
}
Also used : Format(com.google.android.exoplayer2.Format) MediaChunk(com.google.android.exoplayer2.source.chunk.MediaChunk)

Example 35 with Format

use of com.google.android.exoplayer2.Format in project react-native-video by react-native-community.

the class ReactExoplayerView method videoLoaded.

private void videoLoaded() {
    if (loadVideoStarted) {
        loadVideoStarted = false;
        Format videoFormat = player.getVideoFormat();
        int width = videoFormat != null ? videoFormat.width : 0;
        int height = videoFormat != null ? videoFormat.height : 0;
        eventEmitter.load(player.getDuration(), player.getCurrentPosition(), width, height);
    }
}
Also used : Format(com.google.android.exoplayer2.Format) SuppressLint(android.annotation.SuppressLint)

Aggregations

Format (com.google.android.exoplayer2.Format)44 Point (android.graphics.Point)8 ArrayList (java.util.ArrayList)8 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)7 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 SuppressLint (android.annotation.SuppressLint)4 MediaFormat (android.media.MediaFormat)4 ParserException (com.google.android.exoplayer2.ParserException)4 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)4 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)4 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)3 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)3 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)3 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)2 MediaCodecInfo (com.google.android.exoplayer2.mediacodec.MediaCodecInfo)2 Metadata (com.google.android.exoplayer2.metadata.Metadata)2 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)2 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)2 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)2 SingleSegmentBase (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase)2