Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3daa74dc
authored
Jan 22, 2022
by
Dustin
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Tests for AudioFormat, VideoFormat and UnboundedIntArray
parent
c4cf876d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
4 deletions
library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AudioFormat.java
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/AudioFormatTest.java
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/DataHelper.java
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/VideoFormatTest.java
testdata/src/test/assets/extractordumps/avi/aac_stream_format.dump
testdata/src/test/assets/extractordumps/avi/h264_stream_format.dump
library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AudioFormat.java
View file @
3daa74dc
...
@@ -6,8 +6,8 @@ import java.nio.ByteBuffer;
...
@@ -6,8 +6,8 @@ import java.nio.ByteBuffer;
public
class
AudioFormat
{
public
class
AudioFormat
{
public
static
final
short
WAVE_FORMAT_PCM
=
1
;
public
static
final
short
WAVE_FORMAT_PCM
=
1
;
static
final
short
WAVE_FORMAT_AAC
=
0xff
;
private
static
final
short
WAVE_FORMAT_MPEGLAYER3
=
0x55
;
private
static
final
short
WAVE_FORMAT_MPEGLAYER3
=
0x55
;
private
static
final
short
WAVE_FORMAT_AAC
=
0xff
;
private
static
final
short
WAVE_FORMAT_DVM
=
0x2000
;
//AC3
private
static
final
short
WAVE_FORMAT_DVM
=
0x2000
;
//AC3
private
static
final
short
WAVE_FORMAT_DTS2
=
0x2001
;
//DTS
private
static
final
short
WAVE_FORMAT_DTS2
=
0x2001
;
//DTS
private
static
final
SparseArray
<
String
>
FORMAT_MAP
=
new
SparseArray
<>();
private
static
final
SparseArray
<
String
>
FORMAT_MAP
=
new
SparseArray
<>();
...
@@ -40,9 +40,10 @@ public class AudioFormat {
...
@@ -40,9 +40,10 @@ public class AudioFormat {
return
byteBuffer
.
getInt
(
4
);
return
byteBuffer
.
getInt
(
4
);
}
}
// 8 - nAvgBytesPerSec(uint)
// 8 - nAvgBytesPerSec(uint)
public
int
getBlockAlign
()
{
// 12 - nBlockAlign
return
byteBuffer
.
getShort
(
12
);
// public int getBlockAlign() {
}
// return byteBuffer.getShort(12);
// }
public
short
getBitsPerSample
()
{
public
short
getBitsPerSample
()
{
return
byteBuffer
.
getShort
(
14
);
return
byteBuffer
.
getShort
(
14
);
}
}
...
...
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/AudioFormatTest.java
0 → 100644
View file @
3daa74dc
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
avi
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
java.io.IOException
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
@RunWith
(
AndroidJUnit4
.
class
)
public
class
AudioFormatTest
{
final
byte
[]
CODEC_PRIVATE
=
{
0x11
,
(
byte
)
0x90
};
@Test
public
void
getters_givenAacStreamFormat
()
throws
IOException
{
final
StreamFormatBox
streamFormatBox
=
DataHelper
.
getAudioStreamFormat
();
final
AudioFormat
audioFormat
=
streamFormatBox
.
getAudioFormat
();
Assert
.
assertEquals
(
MimeTypes
.
AUDIO_AAC
,
audioFormat
.
getMimeType
());
Assert
.
assertEquals
(
2
,
audioFormat
.
getChannels
());
Assert
.
assertEquals
(
AudioFormat
.
WAVE_FORMAT_AAC
,
audioFormat
.
getFormatTag
());
Assert
.
assertEquals
(
48000
,
audioFormat
.
getSamplesPerSecond
());
Assert
.
assertEquals
(
0
,
audioFormat
.
getBitsPerSample
());
//Not meaningful for AAC
Assert
.
assertArrayEquals
(
CODEC_PRIVATE
,
audioFormat
.
getCodecData
());
}
}
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/DataHelper.java
View file @
3daa74dc
...
@@ -29,4 +29,18 @@ public class DataHelper {
...
@@ -29,4 +29,18 @@ public class DataHelper {
byteBuffer
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
byteBuffer
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
return
new
StreamHeaderBox
(
StreamHeaderBox
.
STRH
,
buffer
.
length
,
byteBuffer
);
return
new
StreamHeaderBox
(
StreamHeaderBox
.
STRH
,
buffer
.
length
,
byteBuffer
);
}
}
public
static
StreamFormatBox
getAudioStreamFormat
()
throws
IOException
{
final
byte
[]
buffer
=
getBytes
(
"aac_stream_format.dump"
);
final
ByteBuffer
byteBuffer
=
ByteBuffer
.
wrap
(
buffer
);
byteBuffer
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
return
new
StreamFormatBox
(
StreamFormatBox
.
STRF
,
buffer
.
length
,
byteBuffer
);
}
public
static
StreamFormatBox
getVideoStreamFormat
()
throws
IOException
{
final
byte
[]
buffer
=
getBytes
(
"h264_stream_format.dump"
);
final
ByteBuffer
byteBuffer
=
ByteBuffer
.
wrap
(
buffer
);
byteBuffer
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
return
new
StreamFormatBox
(
StreamFormatBox
.
STRF
,
buffer
.
length
,
byteBuffer
);
}
}
}
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java
0 → 100644
View file @
3daa74dc
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
avi
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
UnboundedIntArrayTest
{
@Test
public
void
add_givenInt
()
{
final
UnboundedIntArray
unboundedIntArray
=
new
UnboundedIntArray
();
unboundedIntArray
.
add
(
4
);
Assert
.
assertEquals
(
1
,
unboundedIntArray
.
getSize
());
Assert
.
assertEquals
(
unboundedIntArray
.
array
[
0
],
4
);
}
@Test
public
void
indexOf_givenOrderSet
()
{
final
UnboundedIntArray
unboundedIntArray
=
new
UnboundedIntArray
();
unboundedIntArray
.
add
(
2
);
unboundedIntArray
.
add
(
4
);
unboundedIntArray
.
add
(
5
);
unboundedIntArray
.
add
(
8
);
Assert
.
assertEquals
(
2
,
unboundedIntArray
.
indexOf
(
5
));
Assert
.
assertTrue
(
unboundedIntArray
.
indexOf
(
6
)
<
0
);
}
@Test
public
void
grow_givenSizeOfOne
()
{
final
UnboundedIntArray
unboundedIntArray
=
new
UnboundedIntArray
(
1
);
unboundedIntArray
.
add
(
0
);
Assert
.
assertEquals
(
1
,
unboundedIntArray
.
getSize
());
unboundedIntArray
.
add
(
1
);
Assert
.
assertTrue
(
unboundedIntArray
.
getSize
()
>
1
);
}
@Test
public
void
pack_givenSizeOfOne
()
{
final
UnboundedIntArray
unboundedIntArray
=
new
UnboundedIntArray
(
8
);
unboundedIntArray
.
add
(
1
);
unboundedIntArray
.
add
(
2
);
Assert
.
assertEquals
(
8
,
unboundedIntArray
.
array
.
length
);
unboundedIntArray
.
pack
();
Assert
.
assertEquals
(
2
,
unboundedIntArray
.
array
.
length
);
}
@Test
public
void
illegalArgument_givenNegativeSize
()
{
try
{
new
UnboundedIntArray
(-
1
);
Assert
.
fail
();
}
catch
(
IllegalArgumentException
e
)
{
//Intentionally blank
}
}
}
library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/VideoFormatTest.java
0 → 100644
View file @
3daa74dc
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
avi
;
import
java.io.IOException
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
VideoFormatTest
{
@Test
public
void
getters_givenVideoStreamFormat
()
throws
IOException
{
final
StreamFormatBox
streamFormatBox
=
DataHelper
.
getVideoStreamFormat
();
final
VideoFormat
videoFormat
=
streamFormatBox
.
getVideoFormat
();
Assert
.
assertEquals
(
712
,
videoFormat
.
getWidth
());
Assert
.
assertEquals
(
464
,
videoFormat
.
getHeight
());
}
}
testdata/src/test/assets/extractordumps/avi/aac_stream_format.dump
0 → 100644
View file @
3daa74dc
No preview for this file type
testdata/src/test/assets/extractordumps/avi/h264_stream_format.dump
0 → 100644
View file @
3daa74dc
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment