Search in sources :

Example 11 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class Ac4Reader method parseHeader.

/**
 * Parses the sample header.
 */
@RequiresNonNull("output")
private void parseHeader() {
    headerScratchBits.setPosition(0);
    SyncFrameInfo frameInfo = Ac4Util.parseAc4SyncframeInfo(headerScratchBits);
    if (format == null || frameInfo.channelCount != format.channelCount || frameInfo.sampleRate != format.sampleRate || !MimeTypes.AUDIO_AC4.equals(format.sampleMimeType)) {
        format = new Format.Builder().setId(formatId).setSampleMimeType(MimeTypes.AUDIO_AC4).setChannelCount(frameInfo.channelCount).setSampleRate(frameInfo.sampleRate).setLanguage(language).build();
        output.format(format);
    }
    sampleSize = frameInfo.frameSize;
    // In this class a sample is an AC-4 sync frame, but Format#sampleRate specifies the number of
    // PCM audio samples per second.
    sampleDurationUs = C.MICROS_PER_SECOND * frameInfo.sampleCount / format.sampleRate;
}
Also used : Format(com.google.android.exoplayer2.Format) SyncFrameInfo(com.google.android.exoplayer2.audio.Ac4Util.SyncFrameInfo) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 12 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class PlayerView method setDrawableArtwork.

@RequiresNonNull("artworkView")
private boolean setDrawableArtwork(@Nullable Drawable drawable) {
    if (drawable != null) {
        int drawableWidth = drawable.getIntrinsicWidth();
        int drawableHeight = drawable.getIntrinsicHeight();
        if (drawableWidth > 0 && drawableHeight > 0) {
            float artworkAspectRatio = (float) drawableWidth / drawableHeight;
            onContentAspectRatioChanged(contentFrame, artworkAspectRatio);
            artworkView.setImageDrawable(drawable);
            artworkView.setVisibility(VISIBLE);
            return true;
        }
    }
    return false;
}
Also used : SuppressLint(android.annotation.SuppressLint) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 13 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class StyledPlayerView method setDrawableArtwork.

@RequiresNonNull("artworkView")
private boolean setDrawableArtwork(@Nullable Drawable drawable) {
    if (drawable != null) {
        int drawableWidth = drawable.getIntrinsicWidth();
        int drawableHeight = drawable.getIntrinsicHeight();
        if (drawableWidth > 0 && drawableHeight > 0) {
            float artworkAspectRatio = (float) drawableWidth / drawableHeight;
            onContentAspectRatioChanged(contentFrame, artworkAspectRatio);
            artworkView.setImageDrawable(drawable);
            artworkView.setVisibility(VISIBLE);
            return true;
        }
    }
    return false;
}
Also used : SuppressLint(android.annotation.SuppressLint) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 14 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class SubtitlePainter method setupBitmapLayout.

@RequiresNonNull("cueBitmap")
private void setupBitmapLayout() {
    Bitmap cueBitmap = this.cueBitmap;
    int parentWidth = parentRight - parentLeft;
    int parentHeight = parentBottom - parentTop;
    float anchorX = parentLeft + (parentWidth * cuePosition);
    float anchorY = parentTop + (parentHeight * cueLine);
    int width = Math.round(parentWidth * cueSize);
    int height = cueBitmapHeight != Cue.DIMEN_UNSET ? Math.round(parentHeight * cueBitmapHeight) : Math.round(width * ((float) cueBitmap.getHeight() / cueBitmap.getWidth()));
    int x = Math.round(cuePositionAnchor == Cue.ANCHOR_TYPE_END ? (anchorX - width) : cuePositionAnchor == Cue.ANCHOR_TYPE_MIDDLE ? (anchorX - (width / 2)) : anchorX);
    int y = Math.round(cueLineAnchor == Cue.ANCHOR_TYPE_END ? (anchorY - height) : cueLineAnchor == Cue.ANCHOR_TYPE_MIDDLE ? (anchorY - (height / 2)) : anchorY);
    bitmapRect = new Rect(x, y, x + width, y + height);
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 15 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class SubtitlePainter method setupTextLayout.

@RequiresNonNull("cueText")
private void setupTextLayout() {
    SpannableStringBuilder cueText = this.cueText instanceof SpannableStringBuilder ? (SpannableStringBuilder) this.cueText : new SpannableStringBuilder(this.cueText);
    int parentWidth = parentRight - parentLeft;
    int parentHeight = parentBottom - parentTop;
    textPaint.setTextSize(defaultTextSizePx);
    int textPaddingX = (int) (defaultTextSizePx * INNER_PADDING_RATIO + 0.5f);
    int availableWidth = parentWidth - textPaddingX * 2;
    if (cueSize != Cue.DIMEN_UNSET) {
        availableWidth = (int) (availableWidth * cueSize);
    }
    if (availableWidth <= 0) {
        Log.w(TAG, "Skipped drawing subtitle cue (insufficient space)");
        return;
    }
    if (cueTextSizePx > 0) {
        // Use an AbsoluteSizeSpan encompassing the whole text to apply the default cueTextSizePx.
        cueText.setSpan(new AbsoluteSizeSpan((int) cueTextSizePx), /* start= */
        0, /* end= */
        cueText.length(), Spanned.SPAN_PRIORITY);
    }
    // Remove embedded font color to not destroy edges, otherwise it overrides edge color.
    SpannableStringBuilder cueTextEdge = new SpannableStringBuilder(cueText);
    if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
        ForegroundColorSpan[] foregroundColorSpans = cueTextEdge.getSpans(0, cueTextEdge.length(), ForegroundColorSpan.class);
        for (ForegroundColorSpan foregroundColorSpan : foregroundColorSpans) {
            cueTextEdge.removeSpan(foregroundColorSpan);
        }
    }
    // (https://github.com/google/ExoPlayer/pull/6724#issuecomment-564650572).
    if (Color.alpha(backgroundColor) > 0) {
        if (edgeType == CaptionStyleCompat.EDGE_TYPE_NONE || edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) {
            cueText.setSpan(new BackgroundColorSpan(backgroundColor), 0, cueText.length(), Spanned.SPAN_PRIORITY);
        } else {
            cueTextEdge.setSpan(new BackgroundColorSpan(backgroundColor), 0, cueTextEdge.length(), Spanned.SPAN_PRIORITY);
        }
    }
    Alignment textAlignment = cueTextAlignment == null ? Alignment.ALIGN_CENTER : cueTextAlignment;
    textLayout = new StaticLayout(cueText, textPaint, availableWidth, textAlignment, spacingMult, spacingAdd, true);
    int textHeight = textLayout.getHeight();
    int textWidth = 0;
    int lineCount = textLayout.getLineCount();
    for (int i = 0; i < lineCount; i++) {
        textWidth = Math.max((int) Math.ceil(textLayout.getLineWidth(i)), textWidth);
    }
    if (cueSize != Cue.DIMEN_UNSET && textWidth < availableWidth) {
        textWidth = availableWidth;
    }
    textWidth += textPaddingX * 2;
    int textLeft;
    int textRight;
    if (cuePosition != Cue.DIMEN_UNSET) {
        int anchorPosition = Math.round(parentWidth * cuePosition) + parentLeft;
        switch(cuePositionAnchor) {
            case Cue.ANCHOR_TYPE_END:
                textLeft = anchorPosition - textWidth;
                break;
            case Cue.ANCHOR_TYPE_MIDDLE:
                textLeft = (anchorPosition * 2 - textWidth) / 2;
                break;
            case Cue.ANCHOR_TYPE_START:
            case Cue.TYPE_UNSET:
            default:
                textLeft = anchorPosition;
        }
        textLeft = Math.max(textLeft, parentLeft);
        textRight = Math.min(textLeft + textWidth, parentRight);
    } else {
        textLeft = (parentWidth - textWidth) / 2 + parentLeft;
        textRight = textLeft + textWidth;
    }
    textWidth = textRight - textLeft;
    if (textWidth <= 0) {
        Log.w(TAG, "Skipped drawing subtitle cue (invalid horizontal positioning)");
        return;
    }
    int textTop;
    if (cueLine != Cue.DIMEN_UNSET) {
        if (cueLineType == Cue.LINE_TYPE_FRACTION) {
            int anchorPosition = Math.round(parentHeight * cueLine) + parentTop;
            textTop = cueLineAnchor == Cue.ANCHOR_TYPE_END ? anchorPosition - textHeight : cueLineAnchor == Cue.ANCHOR_TYPE_MIDDLE ? (anchorPosition * 2 - textHeight) / 2 : anchorPosition;
        } else {
            // cueLineType == Cue.LINE_TYPE_NUMBER
            int firstLineHeight = textLayout.getLineBottom(0) - textLayout.getLineTop(0);
            if (cueLine >= 0) {
                textTop = Math.round(cueLine * firstLineHeight) + parentTop;
            } else {
                textTop = Math.round((cueLine + 1) * firstLineHeight) + parentBottom - textHeight;
            }
        }
        if (textTop + textHeight > parentBottom) {
            textTop = parentBottom - textHeight;
        } else if (textTop < parentTop) {
            textTop = parentTop;
        }
    } else {
        textTop = parentBottom - textHeight - (int) (parentHeight * bottomPaddingFraction);
    }
    // Update the derived drawing variables.
    this.textLayout = new StaticLayout(cueText, textPaint, textWidth, textAlignment, spacingMult, spacingAdd, true);
    this.edgeLayout = new StaticLayout(cueTextEdge, textPaint, textWidth, textAlignment, spacingMult, spacingAdd, true);
    this.textLeft = textLeft;
    this.textTop = textTop;
    this.textPaddingX = textPaddingX;
}
Also used : Alignment(android.text.Layout.Alignment) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StaticLayout(android.text.StaticLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) BackgroundColorSpan(android.text.style.BackgroundColorSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)43 Nullable (androidx.annotation.Nullable)12 Format (com.google.android.exoplayer2.Format)10 SuppressLint (android.annotation.SuppressLint)4 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)3 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 TextPaint (android.text.TextPaint)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)2 Transformer (com.google.android.exoplayer2.transformer.Transformer)2 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)2 UnderlyingAST (org.checkerframework.dataflow.cfg.UnderlyingAST)2 SpecialBlock (org.checkerframework.dataflow.cfg.block.SpecialBlock)2 TypeSystemError (org.checkerframework.javacutil.TypeSystemError)2