mirror of
https://github.com/samsonjs/media.git
synced 2026-03-27 09:45:47 +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,
|
||||
int blockTimecode, boolean keyframe, boolean invisible, boolean validSignalByte,
|
||||
byte[] data) {
|
||||
byte flags = (byte) ((keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00));
|
||||
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags,
|
||||
true, validSignalByte, 1, data);
|
||||
int flags = (keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00);
|
||||
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags, true,
|
||||
validSignalByte, 1, data);
|
||||
mediaSegments.add(createCluster(clusterTimecode, simpleBlockElement));
|
||||
return this;
|
||||
}
|
||||
|
|
@ -146,9 +146,9 @@ import java.util.List;
|
|||
|
||||
public StreamBuilder addSimpleBlockMedia(int trackNumber, int clusterTimecode,
|
||||
int blockTimecode, boolean keyframe, boolean invisible, byte[] data) {
|
||||
byte flags = (byte) ((keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00));
|
||||
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags,
|
||||
false, true, 1, data);
|
||||
int flags = (keyframe ? 0x80 : 0x00) | (invisible ? 0x08 : 0x00);
|
||||
EbmlElement simpleBlockElement = createSimpleBlock(trackNumber, blockTimecode, flags, false,
|
||||
true, 1, data);
|
||||
mediaSegments.add(createCluster(clusterTimecode, simpleBlockElement));
|
||||
return this;
|
||||
}
|
||||
|
|
@ -344,13 +344,13 @@ import java.util.List;
|
|||
byte[] simpleBlockBytes;
|
||||
if (lacingFrameCount > 1) {
|
||||
flags |= 0x04; // Fixed-size lacing
|
||||
simpleBlockBytes = TestUtil.createByteArray(
|
||||
0x40, trackNumberBytes[3], // Track number size=2
|
||||
timeBytes[2], timeBytes[3], flags, lacingFrameCount - 1); // Timecode, flags and lacing.
|
||||
simpleBlockBytes = TestUtil.joinByteArrays(
|
||||
new byte[] {0x40, trackNumberBytes[3], timeBytes[2], timeBytes[3]},
|
||||
TestUtil.createByteArray(flags, lacingFrameCount - 1));
|
||||
} else {
|
||||
simpleBlockBytes = TestUtil.createByteArray(
|
||||
0x40, trackNumberBytes[3], // Track number size=2
|
||||
timeBytes[2], timeBytes[3], flags); // Timecode and flags
|
||||
simpleBlockBytes = TestUtil.joinByteArrays(
|
||||
new byte[] {0x40, trackNumberBytes[3], timeBytes[2], timeBytes[3]},
|
||||
TestUtil.createByteArray(flags));
|
||||
}
|
||||
if (encrypted) {
|
||||
simpleBlockBytes = TestUtil.joinByteArrays(
|
||||
|
|
@ -412,10 +412,10 @@ import java.util.List;
|
|||
|
||||
private static byte[] getIntegerBytes(int value) {
|
||||
return TestUtil.createByteArray(
|
||||
(value & 0xFF000000) >> 24,
|
||||
(value & 0x00FF0000) >> 16,
|
||||
(value & 0x0000FF00) >> 8,
|
||||
(value & 0x000000FF));
|
||||
(value >> 24) & 0xFF,
|
||||
(value >> 16) & 0xFF,
|
||||
(value >> 8) & 0xFF,
|
||||
(value) & 0xFF);
|
||||
}
|
||||
|
||||
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,
|
||||
TEST_SEEK_PRE_ROLL, TEST_OPUS_CODEC_PRIVATE, TEST_DEFAULT_DURATION_NS)
|
||||
.addSimpleBlockMediaWithFixedSizeLacing(2 /* trackNumber */, 0 /* clusterTimecode */,
|
||||
0 /* blockTimecode */, 20, media)
|
||||
0 /* blockTimecode */, 20 /* lacingFrameCount */, media)
|
||||
.build(1);
|
||||
|
||||
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.PositionHolder;
|
||||
import com.google.android.exoplayer.upstream.DataSpec;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
|
|
@ -89,9 +90,16 @@ public class TestUtil {
|
|||
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) {
|
||||
byte[] byteArray = new byte[intArray.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
Assertions.checkState(0x00 <= intArray[i] && intArray[i] <= 0xFF);
|
||||
byteArray[i] = (byte) intArray[i];
|
||||
}
|
||||
return byteArray;
|
||||
|
|
|
|||
Loading…
Reference in a new issue