mirror of
https://github.com/samsonjs/media.git
synced 2026-06-29 05:39:31 +00:00
Code Review Changes
(cherry picked from commit 135e103faa1bd829df0542a7062e67ebcfc8638f)
This commit is contained in:
parent
ed2c814837
commit
3886f5f0b6
9 changed files with 39 additions and 25 deletions
|
|
@ -56,6 +56,8 @@ public final class MimeTypes {
|
|||
public static final String VIDEO_OGG = BASE_TYPE_VIDEO + "/ogg";
|
||||
public static final String VIDEO_AVI = BASE_TYPE_VIDEO + "/x-msvideo";
|
||||
public static final String VIDEO_MJPEG = BASE_TYPE_VIDEO + "/mjpeg";
|
||||
public static final String VIDEO_MP42 = BASE_TYPE_VIDEO + "/mp42";
|
||||
public static final String VIDEO_MP43 = BASE_TYPE_VIDEO + "/mp43";
|
||||
public static final String VIDEO_UNKNOWN = BASE_TYPE_VIDEO + "/x-unknown";
|
||||
|
||||
// audio/ MIME types
|
||||
|
|
|
|||
|
|
@ -19,11 +19,6 @@ android {
|
|||
testCoverageEnabled = true
|
||||
}
|
||||
}
|
||||
testOptions{
|
||||
unitTests.all {
|
||||
jvmArgs '-noverify'
|
||||
}
|
||||
}
|
||||
sourceSets.test.assets.srcDir '../../testdata/src/test/assets/'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ import java.util.Arrays;
|
|||
* Consists of Video chunk offsets and indexes for all streams
|
||||
*/
|
||||
public class AviSeekMap implements SeekMap {
|
||||
final int videoId;
|
||||
final long videoUsPerChunk;
|
||||
final long duration;
|
||||
private final int videoId;
|
||||
private final long videoUsPerChunk;
|
||||
private final long duration;
|
||||
//These are ints / 2
|
||||
final int[] keyFrameOffsetsDiv2;
|
||||
private final int[] keyFrameOffsetsDiv2;
|
||||
//Seek chunk indexes by streamId
|
||||
final int[][] seekIndexes;
|
||||
private final int[][] seekIndexes;
|
||||
/**
|
||||
* Usually the same as moviOffset, but sometimes 0 (muxer bug)
|
||||
*/
|
||||
|
|
@ -118,4 +118,19 @@ public class AviSeekMap implements SeekMap {
|
|||
}
|
||||
return indexes;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
public long getKeyFrameOffsets(int streamId) {
|
||||
return keyFrameOffsetsDiv2[streamId] * 2L;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
public int[] getSeekIndexes(int streamId) {
|
||||
return seekIndexes[streamId];
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
public long getVideoUsPerChunk() {
|
||||
return videoUsPerChunk;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public class ChunkHandler {
|
|||
*/
|
||||
public static final int[] ALL_KEY_FRAMES = new int[0];
|
||||
|
||||
public static int TYPE_VIDEO = ('d' << 16) | ('c' << 24);
|
||||
public static int TYPE_AUDIO = ('w' << 16) | ('b' << 24);
|
||||
public static final int TYPE_VIDEO = ('d' << 16) | ('c' << 24);
|
||||
public static final int TYPE_AUDIO = ('w' << 16) | ('b' << 24);
|
||||
|
||||
@NonNull
|
||||
ChunkClock clock;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ListBox extends Box {
|
|||
|
||||
final List<Box> children;
|
||||
|
||||
ListBox(int size, int listType, List<Box> children) {
|
||||
public ListBox(int size, int listType, List<Box> children) {
|
||||
super(LIST, size);
|
||||
this.listType = listType;
|
||||
this.children = children;
|
||||
|
|
|
|||
|
|
@ -32,12 +32,11 @@ public class VideoFormat {
|
|||
static {
|
||||
//Although other types are technically supported, AVI is almost exclusively MP4V and MJPEG
|
||||
final String mimeType = MimeTypes.VIDEO_MP4V;
|
||||
//final String mimeType = MimeTypes.VIDEO_H263;
|
||||
|
||||
//I've never seen an Android devices that actually supports MP42
|
||||
STREAM_MAP.put('M' | ('P' << 8) | ('4' << 16) | ('2' << 24), MimeTypes.BASE_TYPE_VIDEO+"/mp42");
|
||||
STREAM_MAP.put('M' | ('P' << 8) | ('4' << 16) | ('2' << 24), MimeTypes.VIDEO_MP42);
|
||||
//Samsung seems to support the rare MP43.
|
||||
STREAM_MAP.put('M' | ('P' << 8) | ('4' << 16) | ('3' << 24), MimeTypes.BASE_TYPE_VIDEO+"/mp43");
|
||||
STREAM_MAP.put('M' | ('P' << 8) | ('4' << 16) | ('3' << 24), MimeTypes.VIDEO_MP43);
|
||||
STREAM_MAP.put('H' | ('2' << 8) | ('6' << 16) | ('4' << 24), MimeTypes.VIDEO_H264);
|
||||
STREAM_MAP.put('a' | ('v' << 8) | ('c' << 16) | ('1' << 24), MimeTypes.VIDEO_H264);
|
||||
STREAM_MAP.put('A' | ('V' << 8) | ('C' << 16) | ('1' << 24), MimeTypes.VIDEO_H264);
|
||||
|
|
|
|||
|
|
@ -176,10 +176,10 @@ public class AviExtractorTest {
|
|||
Assert.assertEquals(2 * framesPerKeyFrame, videoTrack.keyFrames[2]);
|
||||
|
||||
Assert.assertEquals(2 * keyFrameRate * DataHelper.AUDIO_PER_VIDEO,
|
||||
aviSeekMap.seekIndexes[DataHelper.AUDIO_ID][2]);
|
||||
aviSeekMap.getSeekIndexes(DataHelper.AUDIO_ID)[2]);
|
||||
Assert.assertEquals(4L + 2 * keyFrameRate * DataHelper.VIDEO_SIZE +
|
||||
2 * keyFrameRate * DataHelper.AUDIO_SIZE * DataHelper.AUDIO_PER_VIDEO,
|
||||
aviSeekMap.keyFrameOffsetsDiv2[2] * 2L);
|
||||
aviSeekMap.getKeyFrameOffsets(2));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -471,9 +471,10 @@ public class AviExtractorTest {
|
|||
final AviSeekMap aviSeekMap = DataHelper.getAviSeekMap();
|
||||
aviExtractor.aviSeekMap = aviSeekMap;
|
||||
final ChunkHandler chunkHandler = aviExtractor.getVideoTrack();
|
||||
final long position = DataHelper.MOVI_OFFSET + aviSeekMap.keyFrameOffsetsDiv2[1] * 2L;
|
||||
final long position = DataHelper.MOVI_OFFSET + aviSeekMap.getKeyFrameOffsets(DataHelper.AUDIO_ID);
|
||||
aviExtractor.seek(position, 0L);
|
||||
Assert.assertEquals(aviSeekMap.seekIndexes[chunkHandler.getId()][1], chunkHandler.getClock().getIndex());
|
||||
Assert.assertEquals(aviSeekMap.getSeekIndexes(chunkHandler.getId())[1],
|
||||
chunkHandler.getClock().getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ public class AviSeekMapTest {
|
|||
@Test
|
||||
public void getFrames_givenExactSeekPointMatch() {
|
||||
final AviSeekMap aviSeekMap = DataHelper.getAviSeekMap();
|
||||
final long position = aviSeekMap.keyFrameOffsetsDiv2[1] * 2L + aviSeekMap.seekOffset;
|
||||
final long position = aviSeekMap.getKeyFrameOffsets(DataHelper.AUDIO_ID) + aviSeekMap.seekOffset;
|
||||
final int secs = 4;
|
||||
final ChunkHandler[] chunkHandlers = new ChunkHandler[]{DataHelper.getVideoChunkHandler(secs),
|
||||
DataHelper.getAudioChunkHandler(secs)};
|
||||
|
||||
int[] indexes = aviSeekMap.getIndexes(position);
|
||||
for (int i=0;i<chunkHandlers.length;i++) {
|
||||
Assert.assertEquals(aviSeekMap.seekIndexes[i][1], indexes[i]);
|
||||
Assert.assertEquals(aviSeekMap.getSeekIndexes(i)[1], indexes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,12 +51,13 @@ public class AviSeekMapTest {
|
|||
public void getSeekPoints_givenNonKeyFrameUs() {
|
||||
final AviSeekMap aviSeekMap = DataHelper.getAviSeekMap();
|
||||
//Time before the 1st keyFrame
|
||||
final long us = aviSeekMap.seekIndexes[0][1] * aviSeekMap.videoUsPerChunk - 100L;
|
||||
final long videoUsPerChunk = aviSeekMap.getVideoUsPerChunk();
|
||||
final long us = aviSeekMap.getSeekIndexes(DataHelper.VIDEO_ID)[1] * videoUsPerChunk - 100L;
|
||||
|
||||
final SeekMap.SeekPoints seekPoints = aviSeekMap.getSeekPoints(us);
|
||||
Assert.assertEquals(aviSeekMap.seekIndexes[0][0] * aviSeekMap.videoUsPerChunk,
|
||||
Assert.assertEquals(aviSeekMap.getSeekIndexes(DataHelper.VIDEO_ID)[0] * videoUsPerChunk,
|
||||
seekPoints.first.timeUs);
|
||||
Assert.assertEquals(aviSeekMap.seekIndexes[0][1] * aviSeekMap.videoUsPerChunk,
|
||||
Assert.assertEquals(aviSeekMap.getSeekIndexes(DataHelper.VIDEO_ID)[1] * videoUsPerChunk,
|
||||
seekPoints.second.timeUs);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public class DataHelper {
|
|||
static final int AUDIO_PER_VIDEO = 4;
|
||||
static final int VIDEO_SIZE = 4096;
|
||||
static final int AUDIO_SIZE = 256;
|
||||
static final int VIDEO_ID = 0;
|
||||
static final int AUDIO_ID = 1;
|
||||
static final int MOVI_OFFSET = 4096;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue