Skip to content

Commit 8bdfee3

Browse files
committed
It's WOOOOOOOOORKIIIIIIING
1 parent 3074f62 commit 8bdfee3

File tree

4 files changed

+11
-37
lines changed

4 files changed

+11
-37
lines changed

app/src/main/java/com/example/ijdfpvviewer/H264Extractor.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22-
import java.util.List;
2322

2423
import static com.google.android.exoplayer2.extractor.ts.TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR;
25-
2624
/**
2725
* Extracts data from H264 bitstreams.
2826
*/
2927
public final class H264Extractor implements Extractor {
30-
3128
/** Factory for {@link H264Extractor} instances. */
3229
public static final ExtractorsFactory FACTORY = () -> new Extractor[] {new H264Extractor()};
3330

3431
private static final int MAX_SYNC_FRAME_SIZE = 30 * 1024;
3532
private static final int ID3_TAG = Util.getIntegerCodeForString("ID3");
3633

37-
private final long firstSampleTimestampUs;
34+
private long firstSampleTimestampUs;
35+
private long sampleTime = 200; // todo: try to lower this. it directly infer on speed and latency
3836
private final H264Reader reader;
3937
private final ParsableByteArray sampleData;
4038

@@ -51,7 +49,6 @@ public H264Extractor(long firstSampleTimestampUs) {
5149
}
5250

5351
// Extractor implementation.
54-
5552
@Override
5653
public boolean sniff(ExtractorInput input) throws IOException {
5754
return true;
@@ -90,6 +87,8 @@ public int read(ExtractorInput input, PositionHolder seekPosition) throws IOExce
9087
reader.packetStarted(firstSampleTimestampUs, FLAG_DATA_ALIGNMENT_INDICATOR);
9188
startedPacket = true;
9289
}
90+
firstSampleTimestampUs+=sampleTime;
91+
reader.packetStarted(firstSampleTimestampUs, FLAG_DATA_ALIGNMENT_INDICATOR);
9392
// TODO: Make it possible for the reader to consume the dataSource directly, so that it becomes
9493
// unnecessary to copy the data through packetBuffer.
9594
reader.consume(sampleData);

app/src/main/java/com/example/ijdfpvviewer/InputStreamDataSource.java

+2-29
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public long open(DataSpec dataSpec) throws IOException {
4141
if (dataSpec.length != C.LENGTH_UNSET) {
4242
bytesRemaining = dataSpec.length;
4343
} else {
44-
bytesRemaining = inputStream.available();
45-
if (bytesRemaining == Integer.MAX_VALUE)
46-
bytesRemaining = C.LENGTH_UNSET;
44+
bytesRemaining = C.LENGTH_UNSET;
4745
}
4846
} catch (IOException e) {
4947
throw new IOException(e);
@@ -55,32 +53,7 @@ public long open(DataSpec dataSpec) throws IOException {
5553

5654
@Override
5755
public int read(byte[] buffer, int offset, int readLength) throws IOException {
58-
if (readLength == 0) {
59-
return 0;
60-
} else if (bytesRemaining == 0) {
61-
return C.RESULT_END_OF_INPUT;
62-
}
63-
64-
int bytesRead;
65-
try {
66-
int bytesToRead = bytesRemaining == C.LENGTH_UNSET ? readLength
67-
: (int) Math.min(bytesRemaining, readLength);
68-
bytesRead = inputStream.read(buffer, offset, bytesToRead);
69-
} catch (IOException e) {
70-
throw new IOException(e);
71-
}
72-
73-
if (bytesRead == -1) {
74-
if (bytesRemaining != C.LENGTH_UNSET) {
75-
// End of stream reached having not read sufficient data.
76-
throw new IOException(new EOFException());
77-
}
78-
return C.RESULT_END_OF_INPUT;
79-
}
80-
if (bytesRemaining != C.LENGTH_UNSET) {
81-
bytesRemaining -= bytesRead;
82-
}
83-
return bytesRead;
56+
return inputStream.read(buffer,offset,readLength);
8457
}
8558

8659
@Override

app/src/main/java/com/example/ijdfpvviewer/VideoReaderExoplayer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ public class VideoReaderExoplayer {
2222
private SimpleExoPlayer mPlayer;
2323

2424
VideoReaderExoplayer(InputStream input, SurfaceView videoSurface, Context c){
25-
DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(32*1024, 64*1024, 0, 0).createDefaultLoadControl();
25+
DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(32*1024, 64*1024, 0, 0).build();
2626
mPlayer = new SimpleExoPlayer.Builder(c).setLoadControl(loadControl).build();
2727

2828
mPlayer.setVideoSurfaceView(videoSurface);
2929
mPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
3030

31-
DataSpec dataSpec = new DataSpec(Uri.parse("test"));
31+
DataSpec dataSpec = new DataSpec(Uri.parse(""),0,C.LENGTH_UNSET);
3232

3333
DataSource.Factory dataSourceFactory = () -> (DataSource) new InputStreamDataSource(c, dataSpec, input);
3434

35-
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory,H264Extractor.FACTORY).createMediaSource(MediaItem.fromUri(Uri.parse("test")));
35+
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory,H264Extractor.FACTORY).createMediaSource(MediaItem.fromUri(Uri.parse("")));
3636
mPlayer.setMediaSource(mediaSource);
3737
}
3838

settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include ':app'
2+
rootProject.name = "fpv_viewer_android"

0 commit comments

Comments
 (0)