From a17d36de12b7adb79b1e979803042efe505f876e Mon Sep 17 00:00:00 2001 From: Dustin Date: Fri, 28 Jan 2022 17:42:04 -0700 Subject: [PATCH] Minor cleanup --- .../video/BitmapFactoryVideoRenderer.java | 12 ++-- .../extractor/avi/AviExtractor.java | 71 ++++++++----------- 2 files changed, 36 insertions(+), 47 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/BitmapFactoryVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/BitmapFactoryVideoRenderer.java index 41a17b7b9e..e7b15d2fd3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/BitmapFactoryVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/BitmapFactoryVideoRenderer.java @@ -148,7 +148,10 @@ public class BitmapFactoryVideoRenderer extends BaseRenderer { return null; } - private void renderBitmap(final Bitmap bitmap, @NonNull final Surface surface) { + private void renderBitmap(final Bitmap bitmap, @Nullable final Surface surface) { + if (surface == null) { + return; + } //Log.d(TAG, "Drawing: " + bitmap.getWidth() + "x" + bitmap.getHeight()); final Canvas canvas = surface.lockCanvas(null); @@ -243,13 +246,8 @@ public class BitmapFactoryVideoRenderer extends BaseRenderer { if (sleep()) { continue main; } - if (!running) { - break main; - } } - @Nullable - final Surface surface = BitmapFactoryVideoRenderer.this.surface; - if (surface != null) { + if (running) { renderBitmap(bitmap, surface); } } else if (result == C.RESULT_FORMAT_READ) { diff --git a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AviExtractor.java b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AviExtractor.java index 614719112e..a48025afb5 100644 --- a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AviExtractor.java +++ b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AviExtractor.java @@ -57,6 +57,34 @@ public class AviExtractor implements Extractor { } } + static int checkAlign(final ExtractorInput input, PositionHolder seekPosition) { + final long position = input.getPosition(); + if ((position & 1) ==1) { + seekPosition.position = position + 1; + return RESULT_SEEK; + } + return RESULT_CONTINUE; + } + + static ByteBuffer allocate(int bytes) { + final byte[] buffer = new byte[bytes]; + final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); + byteBuffer.order(ByteOrder.LITTLE_ENDIAN); + return byteBuffer; + } + + @VisibleForTesting + static int getStreamId(int chunkId) { + final int upperChar = chunkId & 0xff; + if (Character.isDigit(upperChar)) { + final int lowerChar = (chunkId >> 8) & 0xff; + if (Character.isDigit(upperChar)) { + return (lowerChar & 0xf) + ((upperChar & 0xf) * 10); + } + } + return -1; + } + static final String TAG = "AviExtractor"; @VisibleForTesting static final int PEEK_BYTES = 28; @@ -87,8 +115,6 @@ public class AviExtractor implements Extractor { static final int JUNK = 'J' | ('U' << 8) | ('N' << 16) | ('K' << 24); static final int REC_ = 'r' | ('e' << 8) | ('c' << 16) | (' ' << 24); - static final long SEEK_GAP = 2_000_000L; //Time between seek points in micro seconds - @VisibleForTesting int state; @VisibleForTesting @@ -112,7 +138,6 @@ public class AviExtractor implements Extractor { /** * - * @param input * @param bytes Must be at least 20 */ @Nullable @@ -143,7 +168,7 @@ public class AviExtractor implements Extractor { } @Override - public boolean sniff(ExtractorInput input) throws IOException { + public boolean sniff(@NonNull ExtractorInput input) throws IOException { final ByteBuffer byteBuffer = getAviBuffer(input, PEEK_BYTES); if (byteBuffer == null) { return false; @@ -155,29 +180,7 @@ public class AviExtractor implements Extractor { return false; } final int avih = byteBuffer.getInt(); - if (avih != AviHeaderBox.AVIH) { - return false; - } - return true; - } - - static ByteBuffer allocate(int bytes) { - final byte[] buffer = new byte[bytes]; - final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); - byteBuffer.order(ByteOrder.LITTLE_ENDIAN); - return byteBuffer; - } - - @VisibleForTesting - static int getStreamId(int chunkId) { - final int upperChar = chunkId & 0xff; - if (Character.isDigit(upperChar)) { - final int lowerChar = (chunkId >> 8) & 0xff; - if (Character.isDigit(upperChar)) { - return (lowerChar & 0xf) + ((upperChar & 0xf) * 10); - } - } - return -1; + return avih == AviHeaderBox.AVIH; } @VisibleForTesting @@ -206,7 +209,7 @@ public class AviExtractor implements Extractor { } @Override - public void init(ExtractorOutput output) { + public void init(@NonNull ExtractorOutput output) { this.state = STATE_READ_TRACKS; this.output = output; } @@ -379,9 +382,6 @@ public class AviExtractor implements Extractor { /** * Reads the index and sets the keyFrames and creates the SeekMap - * @param input - * @param remaining - * @throws IOException */ void readIdx1(ExtractorInput input, int remaining) throws IOException { final AviTrack videoTrack = getVideoTrack(); @@ -478,15 +478,6 @@ public class AviExtractor implements Extractor { return null; } - int checkAlign(final ExtractorInput input, PositionHolder seekPosition) { - final long position = input.getPosition(); - if ((position & 1) ==1) { - seekPosition.position = position +1; - return RESULT_SEEK; - } - return RESULT_CONTINUE; - } - int readSamples(ExtractorInput input, PositionHolder seekPosition) throws IOException { if (chunkHandler != null) { if (chunkHandler.resume(input)) {