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
8c07f1e1
authored
Apr 20, 2022
by
samrobinson
Committed by
Ian Baker
Apr 26, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Align MediaCodec and Decoder AudioRenderer onDisabled logic.
PiperOrigin-RevId: 443156130
parent
e996d48b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
66 deletions
library/core/src/main/java/com/google/android/exoplayer2/audio/DecoderAudioRenderer.java
library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java
library/core/src/main/java/com/google/android/exoplayer2/audio/DecoderAudioRenderer.java
View file @
8c07f1e1
...
...
@@ -137,7 +137,7 @@ public abstract class DecoderAudioRenderer<
private
@ReinitializationState
int
decoderReinitializationState
;
private
boolean
decoderReceivedBuffers
;
private
boolean
audio
Trac
kNeedsConfigure
;
private
boolean
audio
Sin
kNeedsConfigure
;
private
long
currentPositionUs
;
private
boolean
allowFirstBufferPositionDiscontinuity
;
...
...
@@ -202,7 +202,7 @@ public abstract class DecoderAudioRenderer<
audioSink
.
setListener
(
new
AudioSinkListener
());
flagsOnlyBuffer
=
DecoderInputBuffer
.
newNoDataInstance
();
decoderReinitializationState
=
REINITIALIZATION_STATE_NONE
;
audio
Trac
kNeedsConfigure
=
true
;
audio
Sin
kNeedsConfigure
=
true
;
}
/**
...
...
@@ -397,7 +397,7 @@ public abstract class DecoderAudioRenderer<
releaseDecoder
();
maybeInitDecoder
();
// The audio track may need to be recreated once the new output format is known.
audio
Trac
kNeedsConfigure
=
true
;
audio
Sin
kNeedsConfigure
=
true
;
}
else
{
outputBuffer
.
release
();
outputBuffer
=
null
;
...
...
@@ -411,7 +411,7 @@ public abstract class DecoderAudioRenderer<
return
false
;
}
if
(
audio
Trac
kNeedsConfigure
)
{
if
(
audio
Sin
kNeedsConfigure
)
{
Format
outputFormat
=
getOutputFormat
(
decoder
)
.
buildUpon
()
...
...
@@ -419,7 +419,7 @@ public abstract class DecoderAudioRenderer<
.
setEncoderPadding
(
encoderPadding
)
.
build
();
audioSink
.
configure
(
outputFormat
,
/* specifiedBufferSize= */
0
,
/* outputChannels= */
null
);
audio
Trac
kNeedsConfigure
=
false
;
audio
Sin
kNeedsConfigure
=
false
;
}
if
(
audioSink
.
handleBuffer
(
...
...
@@ -581,7 +581,7 @@ public abstract class DecoderAudioRenderer<
@Override
protected
void
onDisabled
()
{
inputFormat
=
null
;
audio
Trac
kNeedsConfigure
=
true
;
audio
Sin
kNeedsConfigure
=
true
;
try
{
setSourceDrmSession
(
null
);
releaseDecoder
();
...
...
@@ -734,7 +734,7 @@ public abstract class DecoderAudioRenderer<
// There aren't any final output buffers, so release the decoder immediately.
releaseDecoder
();
maybeInitDecoder
();
audio
Trac
kNeedsConfigure
=
true
;
audio
Sin
kNeedsConfigure
=
true
;
}
}
eventDispatcher
.
inputFormatChanged
(
inputFormat
,
evaluation
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java
View file @
8c07f1e1
...
...
@@ -103,7 +103,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
private
long
currentPositionUs
;
private
boolean
allowFirstBufferPositionDiscontinuity
;
private
boolean
allowPositionDiscontinuity
;
private
boolean
audioSinkNeeds
Reset
;
private
boolean
audioSinkNeeds
Configure
;
private
boolean
experimentalKeepAudioTrackOnSeek
;
...
...
@@ -254,6 +254,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
this
.
audioSink
=
audioSink
;
eventDispatcher
=
new
EventDispatcher
(
eventHandler
,
eventListener
);
audioSink
.
setListener
(
new
AudioSinkListener
());
audioSinkNeedsConfigure
=
true
;
}
@Override
...
...
@@ -500,50 +501,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override
protected
void
onOutputFormatChanged
(
Format
format
,
@Nullable
MediaFormat
mediaFormat
)
throws
ExoPlaybackException
{
Format
audioSinkInputFormat
;
@Nullable
int
[]
channelMap
=
null
;
if
(
decryptOnlyCodecFormat
!=
null
)
{
// Direct playback with a codec for decryption.
audioSinkInputFormat
=
decryptOnlyCodecFormat
;
}
else
if
(
getCodec
()
==
null
)
{
// Direct playback with codec bypass.
audioSinkInputFormat
=
format
;
}
else
{
@C
.
PcmEncoding
int
pcmEncoding
;
if
(
MimeTypes
.
AUDIO_RAW
.
equals
(
format
.
sampleMimeType
))
{
// For PCM streams, the encoder passes through int samples despite set to float mode.
pcmEncoding
=
format
.
pcmEncoding
;
}
else
if
(
Util
.
SDK_INT
>=
24
&&
mediaFormat
.
containsKey
(
MediaFormat
.
KEY_PCM_ENCODING
))
{
pcmEncoding
=
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_PCM_ENCODING
);
}
else
if
(
mediaFormat
.
containsKey
(
VIVO_BITS_PER_SAMPLE_KEY
))
{
pcmEncoding
=
Util
.
getPcmEncoding
(
mediaFormat
.
getInteger
(
VIVO_BITS_PER_SAMPLE_KEY
));
}
else
{
// If the format is anything other than PCM then we assume that the audio decoder will
// output 16-bit PCM.
pcmEncoding
=
C
.
ENCODING_PCM_16BIT
;
}
audioSinkInputFormat
=
new
Format
.
Builder
()
.
setSampleMimeType
(
MimeTypes
.
AUDIO_RAW
)
.
setPcmEncoding
(
pcmEncoding
)
.
setEncoderDelay
(
format
.
encoderDelay
)
.
setEncoderPadding
(
format
.
encoderPadding
)
.
setChannelCount
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_CHANNEL_COUNT
))
.
setSampleRate
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_SAMPLE_RATE
))
.
build
();
if
(
codecNeedsDiscardChannelsWorkaround
&&
audioSinkInputFormat
.
channelCount
==
6
&&
format
.
channelCount
<
6
)
{
channelMap
=
new
int
[
format
.
channelCount
];
for
(
int
i
=
0
;
i
<
format
.
channelCount
;
i
++)
{
channelMap
[
i
]
=
i
;
}
}
}
try
{
audioSink
.
configure
(
audioSinkInputFormat
,
/* specifiedBufferSize= */
0
,
channelMap
);
}
catch
(
AudioSink
.
ConfigurationException
e
)
{
throw
createRendererException
(
e
,
e
.
format
,
PlaybackException
.
ERROR_CODE_AUDIO_TRACK_INIT_FAILED
);
}
audioSinkNeedsConfigure
=
true
;
}
/** See {@link AudioSink.Listener#onPositionDiscontinuity()}. */
...
...
@@ -595,9 +553,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override
protected
void
onDisabled
()
{
audioSinkNeeds
Reset
=
true
;
audioSinkNeeds
Configure
=
true
;
try
{
audioSink
.
flush
();
audioSink
.
reset
();
}
finally
{
try
{
super
.
onDisabled
();
...
...
@@ -608,18 +566,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
}
@Override
protected
void
onReset
()
{
try
{
super
.
onReset
();
}
finally
{
if
(
audioSinkNeedsReset
)
{
audioSinkNeedsReset
=
false
;
audioSink
.
reset
();
}
}
}
@Override
public
boolean
isEnded
()
{
return
super
.
isEnded
()
&&
audioSink
.
isEnded
();
}
...
...
@@ -689,6 +635,8 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
return
true
;
}
maybeConfigureAudioSink
(
format
,
getCodecOutputMediaFormat
());
if
(
isDecodeOnlyBuffer
)
{
if
(
codec
!=
null
)
{
codec
.
releaseOutputBuffer
(
bufferIndex
,
false
);
...
...
@@ -871,6 +819,58 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
}
}
private
void
maybeConfigureAudioSink
(
Format
format
,
@Nullable
MediaFormat
mediaFormat
)
throws
ExoPlaybackException
{
if
(!
audioSinkNeedsConfigure
)
{
return
;
}
Format
audioSinkInputFormat
;
@Nullable
int
[]
channelMap
=
null
;
if
(
decryptOnlyCodecFormat
!=
null
)
{
// Direct playback with a codec for decryption.
audioSinkInputFormat
=
decryptOnlyCodecFormat
;
}
else
if
(
getCodec
()
==
null
)
{
// Direct playback with codec bypass.
audioSinkInputFormat
=
format
;
}
else
{
@C
.
PcmEncoding
int
pcmEncoding
;
if
(
MimeTypes
.
AUDIO_RAW
.
equals
(
format
.
sampleMimeType
))
{
// For PCM streams, the encoder passes through int samples despite set to float mode.
pcmEncoding
=
format
.
pcmEncoding
;
}
else
if
(
Util
.
SDK_INT
>=
24
&&
mediaFormat
.
containsKey
(
MediaFormat
.
KEY_PCM_ENCODING
))
{
pcmEncoding
=
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_PCM_ENCODING
);
}
else
if
(
mediaFormat
.
containsKey
(
VIVO_BITS_PER_SAMPLE_KEY
))
{
pcmEncoding
=
Util
.
getPcmEncoding
(
mediaFormat
.
getInteger
(
VIVO_BITS_PER_SAMPLE_KEY
));
}
else
{
// If the format is anything other than PCM then we assume that the audio decoder will
// output 16-bit PCM.
pcmEncoding
=
C
.
ENCODING_PCM_16BIT
;
}
audioSinkInputFormat
=
new
Format
.
Builder
()
.
setSampleMimeType
(
MimeTypes
.
AUDIO_RAW
)
.
setPcmEncoding
(
pcmEncoding
)
.
setEncoderDelay
(
format
.
encoderDelay
)
.
setEncoderPadding
(
format
.
encoderPadding
)
.
setChannelCount
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_CHANNEL_COUNT
))
.
setSampleRate
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_SAMPLE_RATE
))
.
build
();
if
(
codecNeedsDiscardChannelsWorkaround
&&
audioSinkInputFormat
.
channelCount
==
6
&&
format
.
channelCount
<
6
)
{
channelMap
=
new
int
[
format
.
channelCount
];
for
(
int
i
=
0
;
i
<
format
.
channelCount
;
i
++)
{
channelMap
[
i
]
=
i
;
}
}
}
try
{
audioSink
.
configure
(
audioSinkInputFormat
,
/* specifiedBufferSize= */
0
,
channelMap
);
audioSinkNeedsConfigure
=
false
;
}
catch
(
AudioSink
.
ConfigurationException
e
)
{
throw
createRendererException
(
e
,
e
.
format
,
PlaybackException
.
ERROR_CODE_AUDIO_TRACK_INIT_FAILED
);
}
}
/**
* Returns whether the device's decoders are known to not support setting the codec operating
* rate.
...
...
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