Minor cleanup

This commit is contained in:
Dustin 2022-01-28 17:42:04 -07:00
parent 1ff78292d1
commit a17d36de12
2 changed files with 36 additions and 47 deletions

View File

@ -148,7 +148,10 @@ public class BitmapFactoryVideoRenderer extends BaseRenderer {
return null; 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()); //Log.d(TAG, "Drawing: " + bitmap.getWidth() + "x" + bitmap.getHeight());
final Canvas canvas = surface.lockCanvas(null); final Canvas canvas = surface.lockCanvas(null);
@ -243,13 +246,8 @@ public class BitmapFactoryVideoRenderer extends BaseRenderer {
if (sleep()) { if (sleep()) {
continue main; continue main;
} }
if (!running) {
break main;
} }
} if (running) {
@Nullable
final Surface surface = BitmapFactoryVideoRenderer.this.surface;
if (surface != null) {
renderBitmap(bitmap, surface); renderBitmap(bitmap, surface);
} }
} else if (result == C.RESULT_FORMAT_READ) { } else if (result == C.RESULT_FORMAT_READ) {

View File

@ -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"; static final String TAG = "AviExtractor";
@VisibleForTesting @VisibleForTesting
static final int PEEK_BYTES = 28; 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 JUNK = 'J' | ('U' << 8) | ('N' << 16) | ('K' << 24);
static final int REC_ = 'r' | ('e' << 8) | ('c' << 16) | (' ' << 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 @VisibleForTesting
int state; int state;
@VisibleForTesting @VisibleForTesting
@ -112,7 +138,6 @@ public class AviExtractor implements Extractor {
/** /**
* *
* @param input
* @param bytes Must be at least 20 * @param bytes Must be at least 20
*/ */
@Nullable @Nullable
@ -143,7 +168,7 @@ public class AviExtractor implements Extractor {
} }
@Override @Override
public boolean sniff(ExtractorInput input) throws IOException { public boolean sniff(@NonNull ExtractorInput input) throws IOException {
final ByteBuffer byteBuffer = getAviBuffer(input, PEEK_BYTES); final ByteBuffer byteBuffer = getAviBuffer(input, PEEK_BYTES);
if (byteBuffer == null) { if (byteBuffer == null) {
return false; return false;
@ -155,29 +180,7 @@ public class AviExtractor implements Extractor {
return false; return false;
} }
final int avih = byteBuffer.getInt(); final int avih = byteBuffer.getInt();
if (avih != AviHeaderBox.AVIH) { return 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;
} }
@VisibleForTesting @VisibleForTesting
@ -206,7 +209,7 @@ public class AviExtractor implements Extractor {
} }
@Override @Override
public void init(ExtractorOutput output) { public void init(@NonNull ExtractorOutput output) {
this.state = STATE_READ_TRACKS; this.state = STATE_READ_TRACKS;
this.output = output; this.output = output;
} }
@ -379,9 +382,6 @@ public class AviExtractor implements Extractor {
/** /**
* Reads the index and sets the keyFrames and creates the SeekMap * 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 { void readIdx1(ExtractorInput input, int remaining) throws IOException {
final AviTrack videoTrack = getVideoTrack(); final AviTrack videoTrack = getVideoTrack();
@ -478,15 +478,6 @@ public class AviExtractor implements Extractor {
return null; 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 { int readSamples(ExtractorInput input, PositionHolder seekPosition) throws IOException {
if (chunkHandler != null) { if (chunkHandler != null) {
if (chunkHandler.resume(input)) { if (chunkHandler.resume(input)) {