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
3ae4c1b0
authored
Jun 15, 2021
by
Oliver Woodman
Committed by
Ian Baker
Jul 16, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Merge pull request #6500 from DolbyLaboratories:dev-v2-isDirectPlaybackSupported
PiperOrigin-RevId: 378895355
parent
9a876f73
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
RELEASENOTES.md
library/core/src/main/java/com/google/android/exoplayer2/audio/AudioCapabilities.java
RELEASENOTES.md
View file @
3ae4c1b0
...
...
@@ -5,6 +5,11 @@
*
Video:
*
Fix
`IncorrectContextUseViolation`
strict mode warning on Android 11
(
[
#8246
](
https://github.com/google/ExoPlayer/pull/8246
)
).
*
Audio:
*
Use
`AudioTrack.isDirectPlaybackSupported`
to check for encoded audio
passthrough capability from API 29 onwards, instead of using the HDMI
audio plug intent
(
[
#6500
](
https://github.com/google/ExoPlayer/pull/6500
)
).
*
UI:
*
Add
`PendingIntent.FLAG_IMMUTABLE`
flag when creating a broadcast intent
in
`PlayerNotificationManager`
. This is required to avoid an error on
...
...
library/core/src/main/java/com/google/android/exoplayer2/audio/AudioCapabilities.java
View file @
3ae4c1b0
...
...
@@ -21,23 +21,30 @@ import android.content.Intent;
import
android.content.IntentFilter
;
import
android.media.AudioFormat
;
import
android.media.AudioManager
;
import
android.media.AudioTrack
;
import
android.net.Uri
;
import
android.provider.Settings.Global
;
import
androidx.annotation.DoNotInline
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.primitives.Ints
;
import
java.util.Arrays
;
/** Represents the set of audio formats that a device is capable of playing. */
public
final
class
AudioCapabilities
{
private
static
final
int
DEFAULT_MAX_CHANNEL_COUNT
=
8
;
private
static
final
int
DEFAULT_SAMPLE_RATE_HZ
=
48_000
;
/** The minimum audio capabilities supported by all devices. */
public
static
final
AudioCapabilities
DEFAULT_AUDIO_CAPABILITIES
=
new
AudioCapabilities
(
new
int
[]
{
AudioFormat
.
ENCODING_PCM_16BIT
},
DEFAULT_MAX_CHANNEL_COUNT
);
/** Audio capabilities when the device specifies external surround sound. */
@SuppressWarnings
(
"InlinedApi"
)
private
static
final
AudioCapabilities
EXTERNAL_SURROUND_SOUND_CAPABILITIES
=
new
AudioCapabilities
(
new
int
[]
{
...
...
@@ -45,6 +52,19 @@ public final class AudioCapabilities {
},
DEFAULT_MAX_CHANNEL_COUNT
);
/** Array of all surround sound encodings that a device may be capable of playing. */
@SuppressWarnings
(
"InlinedApi"
)
private
static
final
int
[]
ALL_SURROUND_ENCODINGS
=
new
int
[]
{
AudioFormat
.
ENCODING_AC3
,
AudioFormat
.
ENCODING_E_AC3
,
AudioFormat
.
ENCODING_E_AC3_JOC
,
AudioFormat
.
ENCODING_AC4
,
AudioFormat
.
ENCODING_DOLBY_TRUEHD
,
AudioFormat
.
ENCODING_DTS
,
AudioFormat
.
ENCODING_DTS_HD
,
};
/** Global settings key for devices that can specify external surround sound. */
private
static
final
String
EXTERNAL_SURROUND_SOUND_KEY
=
"external_surround_sound_enabled"
;
...
...
@@ -68,6 +88,10 @@ public final class AudioCapabilities {
&&
Global
.
getInt
(
context
.
getContentResolver
(),
EXTERNAL_SURROUND_SOUND_KEY
,
0
)
==
1
)
{
return
EXTERNAL_SURROUND_SOUND_CAPABILITIES
;
}
if
(
Util
.
SDK_INT
>=
29
)
{
return
new
AudioCapabilities
(
AudioTrackWrapperV29
.
getDirectPlaybackSupportedEncodingsV29
(),
DEFAULT_MAX_CHANNEL_COUNT
);
}
if
(
intent
==
null
||
intent
.
getIntExtra
(
AudioManager
.
EXTRA_AUDIO_PLUG_STATE
,
0
)
==
0
)
{
return
DEFAULT_AUDIO_CAPABILITIES
;
}
...
...
@@ -158,4 +182,29 @@ public final class AudioCapabilities {
return
Util
.
SDK_INT
>=
17
&&
(
"Amazon"
.
equals
(
Util
.
MANUFACTURER
)
||
"Xiaomi"
.
equals
(
Util
.
MANUFACTURER
));
}
@RequiresApi
(
29
)
private
static
final
class
AudioTrackWrapperV29
{
@DoNotInline
public
static
int
[]
getDirectPlaybackSupportedEncodingsV29
()
{
ImmutableList
.
Builder
<
Integer
>
supportedEncodingsListBuilder
=
ImmutableList
.
builder
();
for
(
int
encoding
:
ALL_SURROUND_ENCODINGS
)
{
if
(
AudioTrack
.
isDirectPlaybackSupported
(
new
AudioFormat
.
Builder
()
.
setChannelMask
(
AudioFormat
.
CHANNEL_OUT_STEREO
)
.
setEncoding
(
encoding
)
.
setSampleRate
(
DEFAULT_SAMPLE_RATE_HZ
)
.
build
(),
new
android
.
media
.
AudioAttributes
.
Builder
()
.
setUsage
(
android
.
media
.
AudioAttributes
.
USAGE_MEDIA
)
.
setContentType
(
android
.
media
.
AudioAttributes
.
CONTENT_TYPE_MOVIE
)
.
setFlags
(
0
)
.
build
()))
{
supportedEncodingsListBuilder
.
add
(
encoding
);
}
}
supportedEncodingsListBuilder
.
add
(
AudioFormat
.
ENCODING_PCM_16BIT
);
return
Ints
.
toArray
(
supportedEncodingsListBuilder
.
build
());
}
}
}
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