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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations