mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
WebM extractor tests: Fix up byte/int conversions.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117131005
This commit is contained in:
parent
9d732d8c27
commit
c8d81abd52
3 changed files with 25 additions and 17 deletions
|
|
@ -136,9 +136,9 @@ import java.util.List;
|
||||||
public StreamBuilder addSimpleBlockEncryptedMedia(int trackNumber, int clusterTimecode,
|
public StreamBuilder addSimpleBlockEncryptedMedia(int trackNumber, int clusterTimecode,
|
||||||
int blockTimecode, boolean keyframe, boolean invisible, boolean validSignalByte,
|
int blockTimecode, boolean keyframe, boolean invisible, boolean validSignalByte,
|
||||||
byte[] data) {
|
byte[] data) {
|
||||||
byte flags = (byte) ((keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00));
|
int flags = (keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00);
|
||||||
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags,
|
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags, true,
|
||||||
true, validSignalByte, 1, data);
|
validSignalByte, 1, data);
|
||||||
mediaSegments.add(createCluster(clusterTimecode, simpleBlockElement));
|
mediaSegments.add(createCluster(clusterTimecode, simpleBlockElement));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -146,9 +146,9 @@ import java.util.List;
|
||||||
|
|
||||||
public StreamBuilder addSimpleBlockMedia(int trackNumber, int clusterTimecode,
|
public StreamBuilder addSimpleBlockMedia(int trackNumber, int clusterTimecode,
|
||||||
int blockTimecode, boolean keyframe, boolean invisible, byte[] data) {
|
int blockTimecode, boolean keyframe, boolean invisible, byte[] data) {
|
||||||
byte flags = (byte) ((keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00));
|
int flags = (keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00);
|
||||||
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags,
|
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags, false,
|
||||||
false, true, 1, data);
|
true, 1, data);
|
||||||
mediaSegments.add(createCluster(clusterTimecode, simpleBlockElement));
|
mediaSegments.add(createCluster(clusterTimecode, simpleBlockElement));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -344,13 +344,13 @@ import java.util.List;
|
||||||
byte[] simpleBlockBytes;
|
byte[] simpleBlockBytes;
|
||||||
if (lacingFrameCount > 1) {
|
if (lacingFrameCount > 1) {
|
||||||
flags |= 0x04; // Fixed-size lacing
|
flags |= 0x04; // Fixed-size lacing
|
||||||
simpleBlockBytes = TestUtil.createByteArray(
|
simpleBlockBytes = TestUtil.joinByteArrays(
|
||||||
0x40, trackNumberBytes[3], // Track number size=2
|
new byte[] {0x40, trackNumberBytes[3], timeBytes[2], timeBytes[3]},
|
||||||
timeBytes[2], timeBytes[3], flags, lacingFrameCount - 1); // Timecode, flags and lacing.
|
TestUtil.createByteArray(flags, lacingFrameCount - 1));
|
||||||
} else {
|
} else {
|
||||||
simpleBlockBytes = TestUtil.createByteArray(
|
simpleBlockBytes = TestUtil.joinByteArrays(
|
||||||
0x40, trackNumberBytes[3], // Track number size=2
|
new byte[] {0x40, trackNumberBytes[3], timeBytes[2], timeBytes[3]},
|
||||||
timeBytes[2], timeBytes[3], flags); // Timecode and flags
|
TestUtil.createByteArray(flags));
|
||||||
}
|
}
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
simpleBlockBytes = TestUtil.joinByteArrays(
|
simpleBlockBytes = TestUtil.joinByteArrays(
|
||||||
|
|
@ -412,10 +412,10 @@ import java.util.List;
|
||||||
|
|
||||||
private static byte[] getIntegerBytes(int value) {
|
private static byte[] getIntegerBytes(int value) {
|
||||||
return TestUtil.createByteArray(
|
return TestUtil.createByteArray(
|
||||||
(value & 0xFF000000) >> 24,
|
(value >> 24) & 0xFF,
|
||||||
(value & 0x00FF0000) >> 16,
|
(value >> 16) & 0xFF,
|
||||||
(value & 0x0000FF00) >> 8,
|
(value >> 8) & 0xFF,
|
||||||
(value & 0x000000FF));
|
(value) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] getLongBytes(long value) {
|
private static byte[] getLongBytes(long value) {
|
||||||
|
|
|
||||||
|
|
@ -676,7 +676,7 @@ public final class WebmExtractorTest extends InstrumentationTestCase {
|
||||||
.addOpusTrack(AUDIO_TRACK_NUMBER, TEST_CHANNEL_COUNT, TEST_SAMPLE_RATE, TEST_CODEC_DELAY,
|
.addOpusTrack(AUDIO_TRACK_NUMBER, TEST_CHANNEL_COUNT, TEST_SAMPLE_RATE, TEST_CODEC_DELAY,
|
||||||
TEST_SEEK_PRE_ROLL, TEST_OPUS_CODEC_PRIVATE, TEST_DEFAULT_DURATION_NS)
|
TEST_SEEK_PRE_ROLL, TEST_OPUS_CODEC_PRIVATE, TEST_DEFAULT_DURATION_NS)
|
||||||
.addSimpleBlockMediaWithFixedSizeLacing(2 /* trackNumber */, 0 /* clusterTimecode */,
|
.addSimpleBlockMediaWithFixedSizeLacing(2 /* trackNumber */, 0 /* clusterTimecode */,
|
||||||
0 /* blockTimecode */, 20, media)
|
0 /* blockTimecode */, 20 /* lacingFrameCount */, media)
|
||||||
.build(1);
|
.build(1);
|
||||||
|
|
||||||
TestUtil.consumeTestData(extractor, data);
|
TestUtil.consumeTestData(extractor, data);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import com.google.android.exoplayer.extractor.Extractor;
|
||||||
import com.google.android.exoplayer.extractor.ExtractorInput;
|
import com.google.android.exoplayer.extractor.ExtractorInput;
|
||||||
import com.google.android.exoplayer.extractor.PositionHolder;
|
import com.google.android.exoplayer.extractor.PositionHolder;
|
||||||
import com.google.android.exoplayer.upstream.DataSpec;
|
import com.google.android.exoplayer.upstream.DataSpec;
|
||||||
|
import com.google.android.exoplayer.util.Assertions;
|
||||||
import com.google.android.exoplayer.util.Util;
|
import com.google.android.exoplayer.util.Util;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
|
|
@ -89,9 +90,16 @@ public class TestUtil {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an array of integers in the range [0, 255] into an equivalent byte array.
|
||||||
|
*
|
||||||
|
* @param intArray An array of integers, all of which must be in the range [0, 255].
|
||||||
|
* @return The equivalent byte array.
|
||||||
|
*/
|
||||||
public static byte[] createByteArray(int... intArray) {
|
public static byte[] createByteArray(int... intArray) {
|
||||||
byte[] byteArray = new byte[intArray.length];
|
byte[] byteArray = new byte[intArray.length];
|
||||||
for (int i = 0; i < byteArray.length; i++) {
|
for (int i = 0; i < byteArray.length; i++) {
|
||||||
|
Assertions.checkState(0x00 <= intArray[i] && intArray[i] <= 0xFF);
|
||||||
byteArray[i] = (byte) intArray[i];
|
byteArray[i] = (byte) intArray[i];
|
||||||
}
|
}
|
||||||
return byteArray;
|
return byteArray;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue