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
78260e20
authored
Jul 22, 2020
by
samrobinson
Committed by
Oliver Woodman
Jul 24, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Replacing static arrays with switch statements in MediaCodecUtil.
PiperOrigin-RevId: 322537851
parent
433734dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
322 additions
and
159 deletions
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecUtil.java
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecUtil.java
View file @
78260e20
...
@@ -21,7 +21,6 @@ import android.media.MediaCodecInfo.CodecProfileLevel;
...
@@ -21,7 +21,6 @@ import android.media.MediaCodecInfo.CodecProfileLevel;
import
android.media.MediaCodecList
;
import
android.media.MediaCodecList
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.Pair
;
import
android.util.Pair
;
import
android.util.SparseIntArray
;
import
androidx.annotation.CheckResult
;
import
androidx.annotation.CheckResult
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.annotation.RequiresApi
;
...
@@ -35,7 +34,6 @@ import java.util.ArrayList;
...
@@ -35,7 +34,6 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
org.checkerframework.checker.nullness.qual.EnsuresNonNull
;
import
org.checkerframework.checker.nullness.qual.EnsuresNonNull
;
...
@@ -67,26 +65,16 @@ public final class MediaCodecUtil {
...
@@ -67,26 +65,16 @@ public final class MediaCodecUtil {
// Codecs to constant mappings.
// Codecs to constant mappings.
// AVC.
// AVC.
private
static
final
SparseIntArray
AVC_PROFILE_NUMBER_TO_CONST
;
private
static
final
SparseIntArray
AVC_LEVEL_NUMBER_TO_CONST
;
private
static
final
String
CODEC_ID_AVC1
=
"avc1"
;
private
static
final
String
CODEC_ID_AVC1
=
"avc1"
;
private
static
final
String
CODEC_ID_AVC2
=
"avc2"
;
private
static
final
String
CODEC_ID_AVC2
=
"avc2"
;
// VP9
// VP9
private
static
final
SparseIntArray
VP9_PROFILE_NUMBER_TO_CONST
;
private
static
final
SparseIntArray
VP9_LEVEL_NUMBER_TO_CONST
;
private
static
final
String
CODEC_ID_VP09
=
"vp09"
;
private
static
final
String
CODEC_ID_VP09
=
"vp09"
;
// HEVC.
// HEVC.
private
static
final
Map
<
String
,
Integer
>
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
;
private
static
final
String
CODEC_ID_HEV1
=
"hev1"
;
private
static
final
String
CODEC_ID_HEV1
=
"hev1"
;
private
static
final
String
CODEC_ID_HVC1
=
"hvc1"
;
private
static
final
String
CODEC_ID_HVC1
=
"hvc1"
;
// Dolby Vision.
private
static
final
Map
<
String
,
Integer
>
DOLBY_VISION_STRING_TO_PROFILE
;
private
static
final
Map
<
String
,
Integer
>
DOLBY_VISION_STRING_TO_LEVEL
;
// AV1.
// AV1.
private
static
final
SparseIntArray
AV1_LEVEL_NUMBER_TO_CONST
;
private
static
final
String
CODEC_ID_AV01
=
"av01"
;
private
static
final
String
CODEC_ID_AV01
=
"av01"
;
// MP4A AAC.
// MP4A AAC.
private
static
final
SparseIntArray
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
;
private
static
final
String
CODEC_ID_MP4A
=
"mp4a"
;
private
static
final
String
CODEC_ID_MP4A
=
"mp4a"
;
// Lazily initialized.
// Lazily initialized.
...
@@ -689,13 +677,13 @@ public final class MediaCodecUtil {
...
@@ -689,13 +677,13 @@ public final class MediaCodecUtil {
return
null
;
return
null
;
}
}
@Nullable
String
profileString
=
matcher
.
group
(
1
);
@Nullable
String
profileString
=
matcher
.
group
(
1
);
@Nullable
Integer
profile
=
DOLBY_VISION_STRING_TO_PROFILE
.
get
(
profileString
);
@Nullable
Integer
profile
=
dolbyVisionStringToProfile
(
profileString
);
if
(
profile
==
null
)
{
if
(
profile
==
null
)
{
Log
.
w
(
TAG
,
"Unknown Dolby Vision profile string: "
+
profileString
);
Log
.
w
(
TAG
,
"Unknown Dolby Vision profile string: "
+
profileString
);
return
null
;
return
null
;
}
}
String
levelString
=
parts
[
2
];
String
levelString
=
parts
[
2
];
@Nullable
Integer
level
=
DOLBY_VISION_STRING_TO_LEVEL
.
get
(
levelString
);
@Nullable
Integer
level
=
dolbyVisionStringToLevel
(
levelString
);
if
(
level
==
null
)
{
if
(
level
==
null
)
{
Log
.
w
(
TAG
,
"Unknown Dolby Vision level string: "
+
levelString
);
Log
.
w
(
TAG
,
"Unknown Dolby Vision level string: "
+
levelString
);
return
null
;
return
null
;
...
@@ -727,7 +715,7 @@ public final class MediaCodecUtil {
...
@@ -727,7 +715,7 @@ public final class MediaCodecUtil {
return
null
;
return
null
;
}
}
@Nullable
String
levelString
=
parts
[
3
];
@Nullable
String
levelString
=
parts
[
3
];
@Nullable
Integer
level
=
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
get
(
levelString
);
@Nullable
Integer
level
=
hevcCodecStringToProfileLevel
(
levelString
);
if
(
level
==
null
)
{
if
(
level
==
null
)
{
Log
.
w
(
TAG
,
"Unknown HEVC level string: "
+
levelString
);
Log
.
w
(
TAG
,
"Unknown HEVC level string: "
+
levelString
);
return
null
;
return
null
;
...
@@ -763,12 +751,12 @@ public final class MediaCodecUtil {
...
@@ -763,12 +751,12 @@ public final class MediaCodecUtil {
return
null
;
return
null
;
}
}
int
profile
=
AVC_PROFILE_NUMBER_TO_CONST
.
get
(
profileInteger
,
-
1
);
int
profile
=
avcProfileNumberToConst
(
profileInteger
);
if
(
profile
==
-
1
)
{
if
(
profile
==
-
1
)
{
Log
.
w
(
TAG
,
"Unknown AVC profile: "
+
profileInteger
);
Log
.
w
(
TAG
,
"Unknown AVC profile: "
+
profileInteger
);
return
null
;
return
null
;
}
}
int
level
=
AVC_LEVEL_NUMBER_TO_CONST
.
get
(
levelInteger
,
-
1
);
int
level
=
avcLevelNumberToConst
(
levelInteger
);
if
(
level
==
-
1
)
{
if
(
level
==
-
1
)
{
Log
.
w
(
TAG
,
"Unknown AVC level: "
+
levelInteger
);
Log
.
w
(
TAG
,
"Unknown AVC level: "
+
levelInteger
);
return
null
;
return
null
;
...
@@ -792,12 +780,12 @@ public final class MediaCodecUtil {
...
@@ -792,12 +780,12 @@ public final class MediaCodecUtil {
return
null
;
return
null
;
}
}
int
profile
=
VP9_PROFILE_NUMBER_TO_CONST
.
get
(
profileInteger
,
-
1
);
int
profile
=
vp9ProfileNumberToConst
(
profileInteger
);
if
(
profile
==
-
1
)
{
if
(
profile
==
-
1
)
{
Log
.
w
(
TAG
,
"Unknown VP9 profile: "
+
profileInteger
);
Log
.
w
(
TAG
,
"Unknown VP9 profile: "
+
profileInteger
);
return
null
;
return
null
;
}
}
int
level
=
VP9_LEVEL_NUMBER_TO_CONST
.
get
(
levelInteger
,
-
1
);
int
level
=
vp9LevelNumberToConst
(
levelInteger
);
if
(
level
==
-
1
)
{
if
(
level
==
-
1
)
{
Log
.
w
(
TAG
,
"Unknown VP9 level: "
+
levelInteger
);
Log
.
w
(
TAG
,
"Unknown VP9 level: "
+
levelInteger
);
return
null
;
return
null
;
...
@@ -844,7 +832,7 @@ public final class MediaCodecUtil {
...
@@ -844,7 +832,7 @@ public final class MediaCodecUtil {
profile
=
CodecProfileLevel
.
AV1ProfileMain10
;
profile
=
CodecProfileLevel
.
AV1ProfileMain10
;
}
}
int
level
=
AV1_LEVEL_NUMBER_TO_CONST
.
get
(
levelInteger
,
-
1
);
int
level
=
av1LevelNumberToConst
(
levelInteger
);
if
(
level
==
-
1
)
{
if
(
level
==
-
1
)
{
Log
.
w
(
TAG
,
"Unknown AV1 level: "
+
levelInteger
);
Log
.
w
(
TAG
,
"Unknown AV1 level: "
+
levelInteger
);
return
null
;
return
null
;
...
@@ -905,7 +893,7 @@ public final class MediaCodecUtil {
...
@@ -905,7 +893,7 @@ public final class MediaCodecUtil {
if
(
MimeTypes
.
AUDIO_AAC
.
equals
(
mimeType
))
{
if
(
MimeTypes
.
AUDIO_AAC
.
equals
(
mimeType
))
{
// For MPEG-4 audio this is followed by an audio object type indication as a decimal number.
// For MPEG-4 audio this is followed by an audio object type indication as a decimal number.
int
audioObjectTypeIndication
=
Integer
.
parseInt
(
parts
[
2
]);
int
audioObjectTypeIndication
=
Integer
.
parseInt
(
parts
[
2
]);
int
profile
=
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
get
(
audioObjectTypeIndication
,
-
1
);
int
profile
=
mp4aAudioObjectTypeToProfile
(
audioObjectTypeIndication
);
if
(
profile
!=
-
1
)
{
if
(
profile
!=
-
1
)
{
// Level is set to zero in AAC decoder CodecProfileLevels.
// Level is set to zero in AAC decoder CodecProfileLevels.
return
new
Pair
<>(
profile
,
0
);
return
new
Pair
<>(
profile
,
0
);
...
@@ -1075,150 +1063,325 @@ public final class MediaCodecUtil {
...
@@ -1075,150 +1063,325 @@ public final class MediaCodecUtil {
&&
secure
==
other
.
secure
&&
secure
==
other
.
secure
&&
tunneling
==
other
.
tunneling
;
&&
tunneling
==
other
.
tunneling
;
}
}
}
private
static
int
avcProfileNumberToConst
(
int
profileNumber
)
{
switch
(
profileNumber
)
{
case
66
:
return
CodecProfileLevel
.
AVCProfileBaseline
;
case
77
:
return
CodecProfileLevel
.
AVCProfileMain
;
case
88
:
return
CodecProfileLevel
.
AVCProfileExtended
;
case
100
:
return
CodecProfileLevel
.
AVCProfileHigh
;
case
110
:
return
CodecProfileLevel
.
AVCProfileHigh10
;
case
122
:
return
CodecProfileLevel
.
AVCProfileHigh422
;
case
244
:
return
CodecProfileLevel
.
AVCProfileHigh444
;
default
:
return
-
1
;
}
}
}
static
{
private
static
int
avcLevelNumberToConst
(
int
levelNumber
)
{
AVC_PROFILE_NUMBER_TO_CONST
=
new
SparseIntArray
();
AVC_PROFILE_NUMBER_TO_CONST
.
put
(
66
,
CodecProfileLevel
.
AVCProfileBaseline
);
AVC_PROFILE_NUMBER_TO_CONST
.
put
(
77
,
CodecProfileLevel
.
AVCProfileMain
);
AVC_PROFILE_NUMBER_TO_CONST
.
put
(
88
,
CodecProfileLevel
.
AVCProfileExtended
);
AVC_PROFILE_NUMBER_TO_CONST
.
put
(
100
,
CodecProfileLevel
.
AVCProfileHigh
);
AVC_PROFILE_NUMBER_TO_CONST
.
put
(
110
,
CodecProfileLevel
.
AVCProfileHigh10
);
AVC_PROFILE_NUMBER_TO_CONST
.
put
(
122
,
CodecProfileLevel
.
AVCProfileHigh422
);
AVC_PROFILE_NUMBER_TO_CONST
.
put
(
244
,
CodecProfileLevel
.
AVCProfileHigh444
);
AVC_LEVEL_NUMBER_TO_CONST
=
new
SparseIntArray
();
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
10
,
CodecProfileLevel
.
AVCLevel1
);
// TODO: Find int for CodecProfileLevel.AVCLevel1b.
// TODO: Find int for CodecProfileLevel.AVCLevel1b.
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
11
,
CodecProfileLevel
.
AVCLevel11
);
switch
(
levelNumber
)
{
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
12
,
CodecProfileLevel
.
AVCLevel12
);
case
10
:
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
13
,
CodecProfileLevel
.
AVCLevel13
);
return
CodecProfileLevel
.
AVCLevel1
;
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
20
,
CodecProfileLevel
.
AVCLevel2
);
case
11
:
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
21
,
CodecProfileLevel
.
AVCLevel21
);
return
CodecProfileLevel
.
AVCLevel11
;
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
22
,
CodecProfileLevel
.
AVCLevel22
);
case
12
:
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
30
,
CodecProfileLevel
.
AVCLevel3
);
return
CodecProfileLevel
.
AVCLevel12
;
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
31
,
CodecProfileLevel
.
AVCLevel31
);
case
13
:
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
32
,
CodecProfileLevel
.
AVCLevel32
);
return
CodecProfileLevel
.
AVCLevel13
;
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
40
,
CodecProfileLevel
.
AVCLevel4
);
case
20
:
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
41
,
CodecProfileLevel
.
AVCLevel41
);
return
CodecProfileLevel
.
AVCLevel2
;
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
42
,
CodecProfileLevel
.
AVCLevel42
);
case
21
:
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
50
,
CodecProfileLevel
.
AVCLevel5
);
return
CodecProfileLevel
.
AVCLevel21
;
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
51
,
CodecProfileLevel
.
AVCLevel51
);
case
22
:
AVC_LEVEL_NUMBER_TO_CONST
.
put
(
52
,
CodecProfileLevel
.
AVCLevel52
);
return
CodecProfileLevel
.
AVCLevel22
;
case
30
:
VP9_PROFILE_NUMBER_TO_CONST
=
new
SparseIntArray
();
return
CodecProfileLevel
.
AVCLevel3
;
VP9_PROFILE_NUMBER_TO_CONST
.
put
(
0
,
CodecProfileLevel
.
VP9Profile0
);
case
31
:
VP9_PROFILE_NUMBER_TO_CONST
.
put
(
1
,
CodecProfileLevel
.
VP9Profile1
);
return
CodecProfileLevel
.
AVCLevel31
;
VP9_PROFILE_NUMBER_TO_CONST
.
put
(
2
,
CodecProfileLevel
.
VP9Profile2
);
case
32
:
VP9_PROFILE_NUMBER_TO_CONST
.
put
(
3
,
CodecProfileLevel
.
VP9Profile3
);
return
CodecProfileLevel
.
AVCLevel32
;
VP9_LEVEL_NUMBER_TO_CONST
=
new
SparseIntArray
();
case
40
:
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
10
,
CodecProfileLevel
.
VP9Level1
);
return
CodecProfileLevel
.
AVCLevel4
;
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
11
,
CodecProfileLevel
.
VP9Level11
);
case
41
:
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
20
,
CodecProfileLevel
.
VP9Level2
);
return
CodecProfileLevel
.
AVCLevel41
;
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
21
,
CodecProfileLevel
.
VP9Level21
);
case
42
:
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
30
,
CodecProfileLevel
.
VP9Level3
);
return
CodecProfileLevel
.
AVCLevel42
;
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
31
,
CodecProfileLevel
.
VP9Level31
);
case
50
:
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
40
,
CodecProfileLevel
.
VP9Level4
);
return
CodecProfileLevel
.
AVCLevel5
;
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
41
,
CodecProfileLevel
.
VP9Level41
);
case
51
:
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
50
,
CodecProfileLevel
.
VP9Level5
);
return
CodecProfileLevel
.
AVCLevel51
;
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
51
,
CodecProfileLevel
.
VP9Level51
);
case
52
:
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
60
,
CodecProfileLevel
.
VP9Level6
);
return
CodecProfileLevel
.
AVCLevel52
;
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
61
,
CodecProfileLevel
.
VP9Level61
);
default
:
VP9_LEVEL_NUMBER_TO_CONST
.
put
(
62
,
CodecProfileLevel
.
VP9Level62
);
return
-
1
;
}
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
=
new
HashMap
<>();
}
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L30"
,
CodecProfileLevel
.
HEVCMainTierLevel1
);
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L60"
,
CodecProfileLevel
.
HEVCMainTierLevel2
);
private
static
int
vp9ProfileNumberToConst
(
int
profileNumber
)
{
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L63"
,
CodecProfileLevel
.
HEVCMainTierLevel21
);
switch
(
profileNumber
)
{
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L90"
,
CodecProfileLevel
.
HEVCMainTierLevel3
);
case
0
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L93"
,
CodecProfileLevel
.
HEVCMainTierLevel31
);
return
CodecProfileLevel
.
VP9Profile0
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L120"
,
CodecProfileLevel
.
HEVCMainTierLevel4
);
case
1
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L123"
,
CodecProfileLevel
.
HEVCMainTierLevel41
);
return
CodecProfileLevel
.
VP9Profile1
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L150"
,
CodecProfileLevel
.
HEVCMainTierLevel5
);
case
2
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L153"
,
CodecProfileLevel
.
HEVCMainTierLevel51
);
return
CodecProfileLevel
.
VP9Profile2
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L156"
,
CodecProfileLevel
.
HEVCMainTierLevel52
);
case
3
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L180"
,
CodecProfileLevel
.
HEVCMainTierLevel6
);
return
CodecProfileLevel
.
VP9Profile3
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L183"
,
CodecProfileLevel
.
HEVCMainTierLevel61
);
default
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"L186"
,
CodecProfileLevel
.
HEVCMainTierLevel62
);
return
-
1
;
}
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H30"
,
CodecProfileLevel
.
HEVCHighTierLevel1
);
}
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H60"
,
CodecProfileLevel
.
HEVCHighTierLevel2
);
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H63"
,
CodecProfileLevel
.
HEVCHighTierLevel21
);
private
static
int
vp9LevelNumberToConst
(
int
levelNumber
)
{
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H90"
,
CodecProfileLevel
.
HEVCHighTierLevel3
);
switch
(
levelNumber
)
{
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H93"
,
CodecProfileLevel
.
HEVCHighTierLevel31
);
case
10
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H120"
,
CodecProfileLevel
.
HEVCHighTierLevel4
);
return
CodecProfileLevel
.
VP9Level1
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H123"
,
CodecProfileLevel
.
HEVCHighTierLevel41
);
case
11
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H150"
,
CodecProfileLevel
.
HEVCHighTierLevel5
);
return
CodecProfileLevel
.
VP9Level11
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H153"
,
CodecProfileLevel
.
HEVCHighTierLevel51
);
case
20
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H156"
,
CodecProfileLevel
.
HEVCHighTierLevel52
);
return
CodecProfileLevel
.
VP9Level2
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H180"
,
CodecProfileLevel
.
HEVCHighTierLevel6
);
case
21
:
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H183"
,
CodecProfileLevel
.
HEVCHighTierLevel61
);
return
CodecProfileLevel
.
VP9Level21
;
HEVC_CODEC_STRING_TO_PROFILE_LEVEL
.
put
(
"H186"
,
CodecProfileLevel
.
HEVCHighTierLevel62
);
case
30
:
return
CodecProfileLevel
.
VP9Level3
;
DOLBY_VISION_STRING_TO_PROFILE
=
new
HashMap
<>();
case
31
:
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"00"
,
CodecProfileLevel
.
DolbyVisionProfileDvavPer
);
return
CodecProfileLevel
.
VP9Level31
;
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"01"
,
CodecProfileLevel
.
DolbyVisionProfileDvavPen
);
case
40
:
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"02"
,
CodecProfileLevel
.
DolbyVisionProfileDvheDer
);
return
CodecProfileLevel
.
VP9Level4
;
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"03"
,
CodecProfileLevel
.
DolbyVisionProfileDvheDen
);
case
41
:
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"04"
,
CodecProfileLevel
.
DolbyVisionProfileDvheDtr
);
return
CodecProfileLevel
.
VP9Level41
;
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"05"
,
CodecProfileLevel
.
DolbyVisionProfileDvheStn
);
case
50
:
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"06"
,
CodecProfileLevel
.
DolbyVisionProfileDvheDth
);
return
CodecProfileLevel
.
VP9Level5
;
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"07"
,
CodecProfileLevel
.
DolbyVisionProfileDvheDtb
);
case
51
:
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"08"
,
CodecProfileLevel
.
DolbyVisionProfileDvheSt
);
return
CodecProfileLevel
.
VP9Level51
;
DOLBY_VISION_STRING_TO_PROFILE
.
put
(
"09"
,
CodecProfileLevel
.
DolbyVisionProfileDvavSe
);
case
60
:
return
CodecProfileLevel
.
VP9Level6
;
DOLBY_VISION_STRING_TO_LEVEL
=
new
HashMap
<>();
case
61
:
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"01"
,
CodecProfileLevel
.
DolbyVisionLevelHd24
);
return
CodecProfileLevel
.
VP9Level61
;
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"02"
,
CodecProfileLevel
.
DolbyVisionLevelHd30
);
case
62
:
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"03"
,
CodecProfileLevel
.
DolbyVisionLevelFhd24
);
return
CodecProfileLevel
.
VP9Level62
;
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"04"
,
CodecProfileLevel
.
DolbyVisionLevelFhd30
);
default
:
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"05"
,
CodecProfileLevel
.
DolbyVisionLevelFhd60
);
return
-
1
;
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"06"
,
CodecProfileLevel
.
DolbyVisionLevelUhd24
);
}
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"07"
,
CodecProfileLevel
.
DolbyVisionLevelUhd30
);
}
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"08"
,
CodecProfileLevel
.
DolbyVisionLevelUhd48
);
DOLBY_VISION_STRING_TO_LEVEL
.
put
(
"09"
,
CodecProfileLevel
.
DolbyVisionLevelUhd60
);
@Nullable
private
static
Integer
hevcCodecStringToProfileLevel
(
@Nullable
String
codecString
)
{
if
(
codecString
==
null
)
{
return
null
;
}
switch
(
codecString
)
{
case
"L30"
:
return
CodecProfileLevel
.
HEVCMainTierLevel1
;
case
"L60"
:
return
CodecProfileLevel
.
HEVCMainTierLevel2
;
case
"L63"
:
return
CodecProfileLevel
.
HEVCMainTierLevel21
;
case
"L90"
:
return
CodecProfileLevel
.
HEVCMainTierLevel3
;
case
"L93"
:
return
CodecProfileLevel
.
HEVCMainTierLevel31
;
case
"L120"
:
return
CodecProfileLevel
.
HEVCMainTierLevel4
;
case
"L123"
:
return
CodecProfileLevel
.
HEVCMainTierLevel41
;
case
"L150"
:
return
CodecProfileLevel
.
HEVCMainTierLevel5
;
case
"L153"
:
return
CodecProfileLevel
.
HEVCMainTierLevel51
;
case
"L156"
:
return
CodecProfileLevel
.
HEVCMainTierLevel52
;
case
"L180"
:
return
CodecProfileLevel
.
HEVCMainTierLevel6
;
case
"L183"
:
return
CodecProfileLevel
.
HEVCMainTierLevel61
;
case
"L186"
:
return
CodecProfileLevel
.
HEVCMainTierLevel62
;
case
"H30"
:
return
CodecProfileLevel
.
HEVCHighTierLevel1
;
case
"H60"
:
return
CodecProfileLevel
.
HEVCHighTierLevel2
;
case
"H63"
:
return
CodecProfileLevel
.
HEVCHighTierLevel21
;
case
"H90"
:
return
CodecProfileLevel
.
HEVCHighTierLevel3
;
case
"H93"
:
return
CodecProfileLevel
.
HEVCHighTierLevel31
;
case
"H120"
:
return
CodecProfileLevel
.
HEVCHighTierLevel4
;
case
"H123"
:
return
CodecProfileLevel
.
HEVCHighTierLevel41
;
case
"H150"
:
return
CodecProfileLevel
.
HEVCHighTierLevel5
;
case
"H153"
:
return
CodecProfileLevel
.
HEVCHighTierLevel51
;
case
"H156"
:
return
CodecProfileLevel
.
HEVCHighTierLevel52
;
case
"H180"
:
return
CodecProfileLevel
.
HEVCHighTierLevel6
;
case
"H183"
:
return
CodecProfileLevel
.
HEVCHighTierLevel61
;
case
"H186"
:
return
CodecProfileLevel
.
HEVCHighTierLevel62
;
default
:
return
null
;
}
}
@Nullable
private
static
Integer
dolbyVisionStringToProfile
(
@Nullable
String
profileString
)
{
if
(
profileString
==
null
)
{
return
null
;
}
switch
(
profileString
)
{
case
"00"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvavPer
;
case
"01"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvavPen
;
case
"02"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvheDer
;
case
"03"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvheDen
;
case
"04"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvheDtr
;
case
"05"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvheStn
;
case
"06"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvheDth
;
case
"07"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvheDtb
;
case
"08"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvheSt
;
case
"09"
:
return
CodecProfileLevel
.
DolbyVisionProfileDvavSe
;
default
:
return
null
;
}
}
@Nullable
private
static
Integer
dolbyVisionStringToLevel
(
@Nullable
String
levelString
)
{
if
(
levelString
==
null
)
{
return
null
;
}
switch
(
levelString
)
{
case
"01"
:
return
CodecProfileLevel
.
DolbyVisionLevelHd24
;
case
"02"
:
return
CodecProfileLevel
.
DolbyVisionLevelHd30
;
case
"03"
:
return
CodecProfileLevel
.
DolbyVisionLevelFhd24
;
case
"04"
:
return
CodecProfileLevel
.
DolbyVisionLevelFhd30
;
case
"05"
:
return
CodecProfileLevel
.
DolbyVisionLevelFhd60
;
case
"06"
:
return
CodecProfileLevel
.
DolbyVisionLevelUhd24
;
case
"07"
:
return
CodecProfileLevel
.
DolbyVisionLevelUhd30
;
case
"08"
:
return
CodecProfileLevel
.
DolbyVisionLevelUhd48
;
case
"09"
:
return
CodecProfileLevel
.
DolbyVisionLevelUhd60
;
default
:
return
null
;
}
}
private
static
int
av1LevelNumberToConst
(
int
levelNumber
)
{
// See https://aomediacodec.github.io/av1-spec/av1-spec.pdf Annex A: Profiles and levels for
// See https://aomediacodec.github.io/av1-spec/av1-spec.pdf Annex A: Profiles and levels for
// more information on mapping AV1 codec strings to levels.
// more information on mapping AV1 codec strings to levels.
AV1_LEVEL_NUMBER_TO_CONST
=
new
SparseIntArray
();
switch
(
levelNumber
)
{
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
0
,
CodecProfileLevel
.
AV1Level2
);
case
0
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
1
,
CodecProfileLevel
.
AV1Level21
);
return
CodecProfileLevel
.
AV1Level2
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
2
,
CodecProfileLevel
.
AV1Level22
);
case
1
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
3
,
CodecProfileLevel
.
AV1Level23
);
return
CodecProfileLevel
.
AV1Level21
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
4
,
CodecProfileLevel
.
AV1Level3
);
case
2
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
5
,
CodecProfileLevel
.
AV1Level31
);
return
CodecProfileLevel
.
AV1Level22
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
6
,
CodecProfileLevel
.
AV1Level32
);
case
3
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
7
,
CodecProfileLevel
.
AV1Level33
);
return
CodecProfileLevel
.
AV1Level23
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
8
,
CodecProfileLevel
.
AV1Level4
);
case
4
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
9
,
CodecProfileLevel
.
AV1Level41
);
return
CodecProfileLevel
.
AV1Level3
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
10
,
CodecProfileLevel
.
AV1Level42
);
case
5
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
11
,
CodecProfileLevel
.
AV1Level43
);
return
CodecProfileLevel
.
AV1Level31
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
12
,
CodecProfileLevel
.
AV1Level5
);
case
6
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
13
,
CodecProfileLevel
.
AV1Level51
);
return
CodecProfileLevel
.
AV1Level32
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
14
,
CodecProfileLevel
.
AV1Level52
);
case
7
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
15
,
CodecProfileLevel
.
AV1Level53
);
return
CodecProfileLevel
.
AV1Level33
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
16
,
CodecProfileLevel
.
AV1Level6
);
case
8
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
17
,
CodecProfileLevel
.
AV1Level61
);
return
CodecProfileLevel
.
AV1Level4
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
18
,
CodecProfileLevel
.
AV1Level62
);
case
9
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
19
,
CodecProfileLevel
.
AV1Level63
);
return
CodecProfileLevel
.
AV1Level41
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
20
,
CodecProfileLevel
.
AV1Level7
);
case
10
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
21
,
CodecProfileLevel
.
AV1Level71
);
return
CodecProfileLevel
.
AV1Level42
;
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
22
,
CodecProfileLevel
.
AV1Level72
);
case
11
:
AV1_LEVEL_NUMBER_TO_CONST
.
put
(
23
,
CodecProfileLevel
.
AV1Level73
);
return
CodecProfileLevel
.
AV1Level43
;
case
12
:
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
=
new
SparseIntArray
();
return
CodecProfileLevel
.
AV1Level5
;
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
1
,
CodecProfileLevel
.
AACObjectMain
);
case
13
:
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
2
,
CodecProfileLevel
.
AACObjectLC
);
return
CodecProfileLevel
.
AV1Level51
;
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
3
,
CodecProfileLevel
.
AACObjectSSR
);
case
14
:
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
4
,
CodecProfileLevel
.
AACObjectLTP
);
return
CodecProfileLevel
.
AV1Level52
;
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
5
,
CodecProfileLevel
.
AACObjectHE
);
case
15
:
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
6
,
CodecProfileLevel
.
AACObjectScalable
);
return
CodecProfileLevel
.
AV1Level53
;
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
17
,
CodecProfileLevel
.
AACObjectERLC
);
case
16
:
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
20
,
CodecProfileLevel
.
AACObjectERScalable
);
return
CodecProfileLevel
.
AV1Level6
;
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
23
,
CodecProfileLevel
.
AACObjectLD
);
case
17
:
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
29
,
CodecProfileLevel
.
AACObjectHE_PS
);
return
CodecProfileLevel
.
AV1Level61
;
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
39
,
CodecProfileLevel
.
AACObjectELD
);
case
18
:
MP4A_AUDIO_OBJECT_TYPE_TO_PROFILE
.
put
(
42
,
CodecProfileLevel
.
AACObjectXHE
);
return
CodecProfileLevel
.
AV1Level62
;
case
19
:
return
CodecProfileLevel
.
AV1Level63
;
case
20
:
return
CodecProfileLevel
.
AV1Level7
;
case
21
:
return
CodecProfileLevel
.
AV1Level71
;
case
22
:
return
CodecProfileLevel
.
AV1Level72
;
case
23
:
return
CodecProfileLevel
.
AV1Level73
;
default
:
return
-
1
;
}
}
private
static
int
mp4aAudioObjectTypeToProfile
(
int
profileNumber
)
{
switch
(
profileNumber
)
{
case
1
:
return
CodecProfileLevel
.
AACObjectMain
;
case
2
:
return
CodecProfileLevel
.
AACObjectLC
;
case
3
:
return
CodecProfileLevel
.
AACObjectSSR
;
case
4
:
return
CodecProfileLevel
.
AACObjectLTP
;
case
5
:
return
CodecProfileLevel
.
AACObjectHE
;
case
6
:
return
CodecProfileLevel
.
AACObjectScalable
;
case
17
:
return
CodecProfileLevel
.
AACObjectERLC
;
case
20
:
return
CodecProfileLevel
.
AACObjectERScalable
;
case
23
:
return
CodecProfileLevel
.
AACObjectLD
;
case
29
:
return
CodecProfileLevel
.
AACObjectHE_PS
;
case
39
:
return
CodecProfileLevel
.
AACObjectELD
;
case
42
:
return
CodecProfileLevel
.
AACObjectXHE
;
default
:
return
-
1
;
}
}
}
}
}
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