Skip to content

Commit 252f91d

Browse files
committed
Merge remote-tracking branch 'origin/feature/refacto' into feature/22
# Conflicts: # app/build.gradle # app/src/main/java/com/fpvout/digiview/InputStreamDataSource.java # app/src/main/java/com/fpvout/digiview/MainActivity.java # app/src/main/java/com/fpvout/digiview/UsbMaskConnection.java # app/src/main/java/com/fpvout/digiview/VideoReaderExoplayer.java # app/src/main/java/usb/AndroidUSBInputStream.java
2 parents e31693c + 8aed123 commit 252f91d

13 files changed

+304
-390
lines changed

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
keyAlias digiviewKeyAlias
1313
}
1414
catch (ex) {
15-
println("You should define mStoreFile, mStorePassword, mKeyPassword and mKeyAlias in ~/.gradle/gradle.properties.")
15+
println("You should define mStoreFile, mStorePassword, mKeyPassword and mKeyAlias in ~/.gradle/gradle.properties : "+ ex.message)
1616
}
1717
}
1818
}
@@ -65,18 +65,18 @@ android {
6565

6666
dependencies {
6767

68-
implementation 'androidx.appcompat:appcompat:1.2.0'
68+
implementation 'androidx.appcompat:appcompat:1.3.0'
6969
implementation 'com.google.android.material:material:1.3.0'
7070
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
71-
implementation 'com.google.android.exoplayer:exoplayer:2.13.3'
71+
implementation 'com.google.android.exoplayer:exoplayer:2.14.0'
7272
implementation 'org.mp4parser:isoparser:1.9.39'
7373
implementation 'org.mp4parser:muxer:1.9.39'
7474
compile 'org.slf4j:slf4j-nop:1.7.25'
7575
implementation 'org.jcodec:jcodec:0.2.5'
7676
implementation 'io.sentry:sentry-android:4.3.0'
7777
implementation 'androidx.preference:preference:1.1.1'
7878

79-
testImplementation 'junit:junit:4.+'
79+
testImplementation 'junit:junit:4.13.2'
8080
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
8181
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
8282
}

app/src/main/java/com/fpvout/digiview/H264Extractor.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package com.fpvout.digiview;
22

33
import com.google.android.exoplayer2.C;
4-
import com.google.android.exoplayer2.Format;
54
import com.google.android.exoplayer2.extractor.Extractor;
65
import com.google.android.exoplayer2.extractor.ExtractorInput;
76
import com.google.android.exoplayer2.extractor.ExtractorOutput;
8-
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
97
import com.google.android.exoplayer2.extractor.PositionHolder;
108
import com.google.android.exoplayer2.extractor.SeekMap;
119
import com.google.android.exoplayer2.extractor.ts.H264Reader;
10+
import com.google.android.exoplayer2.extractor.ts.SeiReader;
1211
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader;
12+
import com.google.android.exoplayer2.util.NonNullApi;
1313
import com.google.android.exoplayer2.util.ParsableByteArray;
14-
import com.google.android.exoplayer2.extractor.ts.SeiReader;
1514

1615
import java.io.IOException;
1716
import java.util.ArrayList;
@@ -21,9 +20,6 @@
2120
* Extracts data from H264 bitstreams.
2221
*/
2322
public final class H264Extractor implements Extractor {
24-
/** Factory for {@link H264Extractor} instances. */
25-
public static final ExtractorsFactory FACTORY = () -> new Extractor[] {new H264Extractor()};
26-
2723
private static int MAX_SYNC_FRAME_SIZE = 131072;
2824

2925
private long firstSampleTimestampUs;
@@ -33,33 +29,27 @@ public final class H264Extractor implements Extractor {
3329

3430
private boolean startedPacket;
3531

36-
public H264Extractor() {
37-
this(0);
38-
}
39-
4032
public H264Extractor(int mMaxSyncFrameSize, int mSampleTime) {
4133
this(0, mMaxSyncFrameSize, mSampleTime);
4234
}
4335

44-
public H264Extractor(long firstSampleTimestampUs) {
45-
this(firstSampleTimestampUs, MAX_SYNC_FRAME_SIZE, (int) sampleTime);
46-
}
47-
4836
public H264Extractor(long firstSampleTimestampUs, int mMaxSyncFrameSize, int mSampleTime) {
4937
MAX_SYNC_FRAME_SIZE = mMaxSyncFrameSize;
5038
sampleTime = mSampleTime;
5139
this.firstSampleTimestampUs = firstSampleTimestampUs;
52-
reader = new H264Reader(new SeiReader(new ArrayList<Format>()),false,true);
40+
reader = new H264Reader(new SeiReader(new ArrayList<>()), false, true);
5341
sampleData = new ParsableByteArray(MAX_SYNC_FRAME_SIZE);
5442
}
5543

5644
// Extractor implementation.
5745
@Override
58-
public boolean sniff(ExtractorInput input) throws IOException {
46+
@NonNullApi
47+
public boolean sniff(ExtractorInput input) {
5948
return true;
6049
}
6150

6251
@Override
52+
@NonNullApi
6353
public void init(ExtractorOutput output) {
6454
reader.createTracks(output, new TsPayloadReader.TrackIdGenerator(0, 1));
6555
output.endTracks();
@@ -78,6 +68,7 @@ public void release() {
7868
}
7969

8070
@Override
71+
@NonNullApi
8172
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
8273
int bytesRead = input.read(sampleData.getData(), 0, MAX_SYNC_FRAME_SIZE);
8374
if (bytesRead == C.RESULT_END_OF_INPUT) {

app/src/main/java/com/fpvout/digiview/InputStreamBufferedDataSource.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.fpvout.digiview;
22

3-
import android.content.Context;
43
import android.net.Uri;
54

5+
import androidx.annotation.NonNull;
6+
67
import com.google.android.exoplayer2.C;
78
import com.google.android.exoplayer2.upstream.DataSource;
89
import com.google.android.exoplayer2.upstream.DataSpec;
@@ -19,31 +20,29 @@ public class InputStreamBufferedDataSource implements DataSource {
1920
private static final String ERROR_THREAD_NOT_INITIALIZED = "Read thread not initialized, call first 'startReadThread()'";
2021
private static final long READ_TIMEOUT = 200;
2122

22-
private Context context;
23-
private DataSpec dataSpec;
23+
private final DataSpec dataSpec;
2424
private InputStream inputStream;
25-
private long bytesRemaining;
2625
private boolean opened;
2726

2827
private CircularByteBuffer readBuffer;
2928
private Thread receiveThread;
3029
private boolean working;
3130

3231

33-
public InputStreamBufferedDataSource(Context context, DataSpec dataSpec, InputStream inputStream) {
34-
this.context = context;
32+
public InputStreamBufferedDataSource(DataSpec dataSpec, InputStream inputStream) {
3533
this.dataSpec = dataSpec;
3634
this.inputStream = inputStream;
3735
startReadThread();
3836
}
3937

4038
@Override
41-
public void addTransferListener(TransferListener transferListener) {
39+
public void addTransferListener(@NonNull TransferListener transferListener) {
4240

4341
}
4442

4543
@Override
4644
public long open(DataSpec dataSpec) throws IOException {
45+
long bytesRemaining;
4746
try {
4847
long skipped = inputStream.skip(dataSpec.position);
4948
if (skipped < dataSpec.position)
@@ -63,16 +62,14 @@ public long open(DataSpec dataSpec) throws IOException {
6362
}
6463

6564
@Override
66-
public int read(byte[] buffer, int offset, int readLength) throws IOException {
65+
public int read(@NonNull byte[] buffer, int offset, int readLength) throws IOException {
6766
if (readBuffer == null)
6867
throw new IOException(ERROR_THREAD_NOT_INITIALIZED);
6968

7069
long deadLine = System.currentTimeMillis() + READ_TIMEOUT;
7170
int readBytes = 0;
7271
while (System.currentTimeMillis() < deadLine && readBytes <= 0)
7372
readBytes = readBuffer.read(buffer, offset, readLength);
74-
if (readBytes <= 0)
75-
return readBytes;
7673
return readBytes;
7774
}
7875

app/src/main/java/com/fpvout/digiview/InputStreamDataSource.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.fpvout.digiview;
22

3-
import android.content.Context;
43
import android.net.Uri;
54

65
import com.fpvout.digiview.dvr.DVR;
6+
import androidx.annotation.NonNull;
7+
78
import com.google.android.exoplayer2.C;
89
import com.google.android.exoplayer2.upstream.DataSource;
910
import com.google.android.exoplayer2.upstream.DataSpec;
@@ -14,25 +15,23 @@
1415
import java.io.InputStream;
1516

1617
public class InputStreamDataSource implements DataSource {
17-
private Context context;
18-
private DataSpec dataSpec;
18+
private final DataSpec dataSpec;
1919
private InputStream inputStream;
20-
private long bytesRemaining;
2120
private boolean opened;
2221

23-
public InputStreamDataSource(Context context, DataSpec dataSpec, InputStream inputStream) {
24-
this.context = context;
22+
public InputStreamDataSource(DataSpec dataSpec, InputStream inputStream) {
2523
this.dataSpec = dataSpec;
2624
this.inputStream = inputStream;
2725
}
2826

2927
@Override
30-
public void addTransferListener(TransferListener transferListener) {
28+
public void addTransferListener(@NonNull TransferListener transferListener) {
3129

3230
}
3331

3432
@Override
3533
public long open(DataSpec dataSpec) throws IOException {
34+
long bytesRemaining;
3635
try {
3736
long skipped = inputStream.skip(dataSpec.position);
3837
if (skipped < dataSpec.position)
@@ -52,7 +51,7 @@ public long open(DataSpec dataSpec) throws IOException {
5251
}
5352

5453
@Override
55-
public int read(byte[] buffer, int offset, int readLength) throws IOException {
54+
public int read(@NonNull byte[] buffer, int offset, int readLength) throws IOException {
5655
return inputStream.read(buffer, offset, readLength);
5756
}
5857

0 commit comments

Comments
 (0)