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
ee14b1fa
authored
Dec 17, 2018
by
tonihei
Committed by
Oliver Woodman
Dec 18, 2018
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add test for SsMediaPeriod.getStreamKeys
PiperOrigin-RevId: 225811310
parent
8202cb2d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
215 additions
and
30 deletions
library/smoothstreaming/src/test/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaPeriodTest.java
library/smoothstreaming/src/test/java/com/google/android/exoplayer2/source/smoothstreaming/SsTestUtils.java
library/smoothstreaming/src/test/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/SsManifestTest.java
library/smoothstreaming/src/test/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaPeriodTest.java
0 → 100644
View file @
ee14b1fa
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
;
import
static
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
.
SsTestUtils
.
createSsManifest
;
import
static
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
.
SsTestUtils
.
createStreamElement
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.source.CompositeSequenceableLoaderFactory
;
import
com.google.android.exoplayer2.source.MediaSource.MediaPeriodId
;
import
com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher
;
import
com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest
;
import
com.google.android.exoplayer2.testutil.MediaPeriodAsserts
;
import
com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory
;
import
com.google.android.exoplayer2.testutil.RobolectricUtil
;
import
com.google.android.exoplayer2.upstream.Allocator
;
import
com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy
;
import
com.google.android.exoplayer2.upstream.LoaderErrorThrower
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.annotation.Config
;
/** Unit tests for {@link SsMediaPeriod}. */
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
shadows
=
{
RobolectricUtil
.
CustomLooper
.
class
,
RobolectricUtil
.
CustomMessageQueue
.
class
})
public
class
SsMediaPeriodTest
{
@Test
public
void
getSteamKeys_isCompatibleWithSsManifestFilter
()
{
SsManifest
testManifest
=
createSsManifest
(
createStreamElement
(
/* name= */
"video"
,
C
.
TRACK_TYPE_VIDEO
,
createVideoFormat
(
/* bitrate= */
200000
),
createVideoFormat
(
/* bitrate= */
400000
),
createVideoFormat
(
/* bitrate= */
800000
)),
createStreamElement
(
/* name= */
"audio"
,
C
.
TRACK_TYPE_AUDIO
,
createAudioFormat
(
/* bitrate= */
48000
),
createAudioFormat
(
/* bitrate= */
96000
)),
createStreamElement
(
/* name= */
"text"
,
C
.
TRACK_TYPE_TEXT
,
createTextFormat
(
/* language= */
"eng"
)));
FilterableManifestMediaPeriodFactory
<
SsManifest
>
mediaPeriodFactory
=
manifest
->
new
SsMediaPeriod
(
manifest
,
mock
(
SsChunkSource
.
Factory
.
class
),
mock
(
TransferListener
.
class
),
mock
(
CompositeSequenceableLoaderFactory
.
class
),
mock
(
LoadErrorHandlingPolicy
.
class
),
new
EventDispatcher
()
.
withParameters
(
/* windowIndex= */
0
,
/* mediaPeriodId= */
new
MediaPeriodId
(
/* periodUid= */
new
Object
()),
/* mediaTimeOffsetMs= */
0
),
mock
(
LoaderErrorThrower
.
class
),
mock
(
Allocator
.
class
));
MediaPeriodAsserts
.
assertGetStreamKeysAndManifestFilterIntegration
(
mediaPeriodFactory
,
testManifest
);
}
private
static
Format
createVideoFormat
(
int
bitrate
)
{
return
Format
.
createContainerFormat
(
/* id= */
null
,
/* label= */
null
,
MimeTypes
.
VIDEO_MP4
,
MimeTypes
.
VIDEO_H264
,
/* codecs= */
null
,
bitrate
,
/* selectionFlags= */
0
,
/* language= */
null
);
}
private
static
Format
createAudioFormat
(
int
bitrate
)
{
return
Format
.
createContainerFormat
(
/* id= */
null
,
/* label= */
null
,
MimeTypes
.
AUDIO_MP4
,
MimeTypes
.
AUDIO_AAC
,
/* codecs= */
null
,
bitrate
,
/* selectionFlags= */
0
,
/* language= */
null
);
}
private
static
Format
createTextFormat
(
String
language
)
{
return
Format
.
createContainerFormat
(
/* id= */
null
,
/* label= */
null
,
MimeTypes
.
APPLICATION_MP4
,
MimeTypes
.
TEXT_VTT
,
/* codecs= */
null
,
/* bitrate= */
Format
.
NO_VALUE
,
/* selectionFlags= */
0
,
language
);
}
}
library/smoothstreaming/src/test/java/com/google/android/exoplayer2/source/smoothstreaming/SsTestUtils.java
0 → 100644
View file @
ee14b1fa
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
;
import
android.util.Base64
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest
;
import
com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.ProtectionElement
;
import
com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
/** Util methods for SmoothStreaming tests. */
public
class
SsTestUtils
{
private
static
final
int
TEST_MAJOR_VERSION
=
1
;
private
static
final
int
TEST_MINOR_VERSION
=
2
;
private
static
final
int
TEST_TIMESCALE
=
1000
;
private
static
final
int
TEST_DURATION
=
5000
;
private
static
final
int
TEST_DVR_WINDOW_LENGTH
=
0
;
private
static
final
int
TEST_LOOKAHEAD_COUNT
=
0
;
private
static
final
boolean
TEST_IS_LIVE
=
false
;
private
static
final
String
TEST_BASE_URI
=
"baseUri"
;
private
static
final
String
TEST_CHUNK_TEMPLATE
=
"chunkTemplate"
;
private
static
final
String
TEST_SUB_TYPE
=
"subType"
;
private
static
final
int
TEST_MAX_WIDTH
=
1024
;
private
static
final
int
TEST_MAX_HEIGHT
=
768
;
private
static
final
String
TEST_LANGUAGE
=
"eng"
;
private
static
final
ProtectionElement
TEST_PROTECTION_ELEMENT
=
new
ProtectionElement
(
C
.
WIDEVINE_UUID
,
(
"<KID>"
+
Base64
.
encodeToString
(
new
byte
[]
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
},
Base64
.
DEFAULT
)
+
"</KID>"
)
.
getBytes
(
StandardCharsets
.
UTF_16LE
));
private
SsTestUtils
()
{}
/** Creates test manifest with the given stream elements. */
public
static
SsManifest
createSsManifest
(
StreamElement
...
streamElements
)
{
return
new
SsManifest
(
TEST_MAJOR_VERSION
,
TEST_MINOR_VERSION
,
TEST_TIMESCALE
,
TEST_DURATION
,
TEST_DVR_WINDOW_LENGTH
,
TEST_LOOKAHEAD_COUNT
,
TEST_IS_LIVE
,
TEST_PROTECTION_ELEMENT
,
streamElements
);
}
/** Creates test video stream element with the given name, track type and formats. */
public
static
StreamElement
createStreamElement
(
String
name
,
int
trackType
,
Format
...
formats
)
{
return
new
StreamElement
(
TEST_BASE_URI
,
TEST_CHUNK_TEMPLATE
,
trackType
,
TEST_SUB_TYPE
,
TEST_TIMESCALE
,
name
,
TEST_MAX_WIDTH
,
TEST_MAX_HEIGHT
,
TEST_MAX_WIDTH
,
TEST_MAX_HEIGHT
,
TEST_LANGUAGE
,
formats
,
/* chunkStartTimes= */
Collections
.
emptyList
(),
/* lastChunkDuration= */
0
);
}
}
library/smoothstreaming/src/test/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/SsManifestTest.java
View file @
ee14b1fa
...
@@ -15,12 +15,13 @@
...
@@ -15,12 +15,13 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
.
manifest
;
package
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
.
manifest
;
import
static
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
.
SsTestUtils
.
createSsManifest
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.source.smoothstreaming.
manifest.SsManifest.ProtectionElement
;
import
com.google.android.exoplayer2.source.smoothstreaming.
SsTestUtils
;
import
com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement
;
import
com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
java.util.Arrays
;
import
java.util.Arrays
;
...
@@ -35,14 +36,12 @@ import org.robolectric.RobolectricTestRunner;
...
@@ -35,14 +36,12 @@ import org.robolectric.RobolectricTestRunner;
@RunWith
(
RobolectricTestRunner
.
class
)
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
SsManifestTest
{
public
class
SsManifestTest
{
private
static
final
ProtectionElement
DUMMY_PROTECTION_ELEMENT
=
new
ProtectionElement
(
C
.
WIDEVINE_UUID
,
new
byte
[]
{
0
,
1
,
2
});
@Test
@Test
public
void
testCopy
()
throws
Exception
{
public
void
testCopy
()
throws
Exception
{
Format
[][]
formats
=
newFormats
(
2
,
3
);
Format
[][]
formats
=
newFormats
(
2
,
3
);
SsManifest
sourceManifest
=
SsManifest
sourceManifest
=
newSsManifest
(
newStreamElement
(
"1"
,
formats
[
0
]),
newStreamElement
(
"2"
,
formats
[
1
]));
createSsManifest
(
createStreamElement
(
"1"
,
formats
[
0
]),
createStreamElement
(
"2"
,
formats
[
1
]));
List
<
StreamKey
>
keys
=
List
<
StreamKey
>
keys
=
Arrays
.
asList
(
new
StreamKey
(
0
,
0
),
new
StreamKey
(
0
,
2
),
new
StreamKey
(
1
,
0
));
Arrays
.
asList
(
new
StreamKey
(
0
,
0
),
new
StreamKey
(
0
,
2
),
new
StreamKey
(
1
,
0
));
...
@@ -52,9 +51,9 @@ public class SsManifestTest {
...
@@ -52,9 +51,9 @@ public class SsManifestTest {
SsManifest
copyManifest
=
sourceManifest
.
copy
(
keys
);
SsManifest
copyManifest
=
sourceManifest
.
copy
(
keys
);
SsManifest
expectedManifest
=
SsManifest
expectedManifest
=
new
SsManifest
(
create
SsManifest
(
new
StreamElement
(
"1"
,
formats
[
0
][
0
],
formats
[
0
][
2
]),
create
StreamElement
(
"1"
,
formats
[
0
][
0
],
formats
[
0
][
2
]),
new
StreamElement
(
"2"
,
formats
[
1
][
0
]));
create
StreamElement
(
"2"
,
formats
[
1
][
0
]));
assertManifestEquals
(
expectedManifest
,
copyManifest
);
assertManifestEquals
(
expectedManifest
,
copyManifest
);
}
}
...
@@ -62,13 +61,14 @@ public class SsManifestTest {
...
@@ -62,13 +61,14 @@ public class SsManifestTest {
public
void
testCopyRemoveStreamElement
()
throws
Exception
{
public
void
testCopyRemoveStreamElement
()
throws
Exception
{
Format
[][]
formats
=
newFormats
(
2
,
3
);
Format
[][]
formats
=
newFormats
(
2
,
3
);
SsManifest
sourceManifest
=
SsManifest
sourceManifest
=
newSsManifest
(
newStreamElement
(
"1"
,
formats
[
0
]),
newStreamElement
(
"2"
,
formats
[
1
]));
createSsManifest
(
createStreamElement
(
"1"
,
formats
[
0
]),
createStreamElement
(
"2"
,
formats
[
1
]));
List
<
StreamKey
>
keys
=
Collections
.
singletonList
(
new
StreamKey
(
1
,
0
));
List
<
StreamKey
>
keys
=
Collections
.
singletonList
(
new
StreamKey
(
1
,
0
));
SsManifest
copyManifest
=
sourceManifest
.
copy
(
keys
);
SsManifest
copyManifest
=
sourceManifest
.
copy
(
keys
);
SsManifest
expectedManifest
=
newSsManifest
(
new
StreamElement
(
"2"
,
formats
[
1
][
0
]));
SsManifest
expectedManifest
=
createSsManifest
(
create
StreamElement
(
"2"
,
formats
[
1
][
0
]));
assertManifestEquals
(
expectedManifest
,
copyManifest
);
assertManifestEquals
(
expectedManifest
,
copyManifest
);
}
}
...
@@ -109,26 +109,8 @@ public class SsManifestTest {
...
@@ -109,26 +109,8 @@ public class SsManifestTest {
return
formats
;
return
formats
;
}
}
private
static
SsManifest
newSsManifest
(
StreamElement
...
streamElements
)
{
private
static
StreamElement
createStreamElement
(
String
name
,
Format
...
formats
)
{
return
new
SsManifest
(
1
,
2
,
1000
,
5000
,
0
,
0
,
false
,
DUMMY_PROTECTION_ELEMENT
,
streamElements
);
return
SsTestUtils
.
createStreamElement
(
name
,
C
.
TRACK_TYPE_VIDEO
,
formats
);
}
private
static
StreamElement
newStreamElement
(
String
name
,
Format
...
formats
)
{
return
new
StreamElement
(
"baseUri"
,
"chunkTemplate"
,
C
.
TRACK_TYPE_VIDEO
,
"subType"
,
1000
,
name
,
1024
,
768
,
1024
,
768
,
null
,
formats
,
Collections
.
emptyList
(),
0
);
}
}
private
static
Format
newFormat
(
String
id
)
{
private
static
Format
newFormat
(
String
id
)
{
...
...
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