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
392ec6f3
authored
Feb 02, 2022
by
claincly
Committed by
Ian Baker
Feb 04, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Split the implementation of Encoder/Decoder Factory
PiperOrigin-RevId: 425838647
parent
3bb0210d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
193 additions
and
2 deletions
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Codec.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/CodecFactoryUtil.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultCodecFactory.java → library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Codec.java
View file @
392ec6f3
...
@@ -47,7 +47,7 @@ public final class Codec {
...
@@ -47,7 +47,7 @@ public final class Codec {
public
interface
DecoderFactory
{
public
interface
DecoderFactory
{
/** A default {@code DecoderFactory} implementation. */
/** A default {@code DecoderFactory} implementation. */
DecoderFactory
DEFAULT
=
new
Default
CodecFactory
(
/* videoEncoderSelector= */
null
);
DecoderFactory
DEFAULT
=
new
Default
DecoderFactory
(
);
/**
/**
* Returns a {@link Codec} for audio decoding.
* Returns a {@link Codec} for audio decoding.
...
@@ -76,7 +76,7 @@ public final class Codec {
...
@@ -76,7 +76,7 @@ public final class Codec {
public
interface
EncoderFactory
{
public
interface
EncoderFactory
{
/** A default {@code EncoderFactory} implementation. */
/** A default {@code EncoderFactory} implementation. */
EncoderFactory
DEFAULT
=
new
Default
CodecFactory
(
EncoderSelector
.
DEFAULT
);
EncoderFactory
DEFAULT
=
new
Default
EncoderFactory
(
);
/**
/**
* Returns a {@link Codec} for audio encoding.
* Returns a {@link Codec} for audio encoding.
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/CodecFactoryUtil.java
0 → 100644
View file @
392ec6f3
/*
* Copyright 2021 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
.
transformer
;
import
android.media.MediaCodec
;
import
android.media.MediaFormat
;
import
android.view.Surface
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.util.TraceUtil
;
import
java.io.IOException
;
import
org.checkerframework.checker.nullness.qual.RequiresNonNull
;
/** Utility methods for {@link Codec}'s factory methods. */
/* package */
final
class
CodecFactoryUtil
{
/** Creates a {@link Codec}. */
@RequiresNonNull
(
"#1.sampleMimeType"
)
public
static
Codec
createCodec
(
Format
format
,
MediaFormat
mediaFormat
,
@Nullable
String
mediaCodecName
,
boolean
isVideo
,
boolean
isDecoder
,
@Nullable
Surface
outputSurface
)
throws
TransformationException
{
@Nullable
MediaCodec
mediaCodec
=
null
;
@Nullable
Surface
inputSurface
=
null
;
try
{
mediaCodec
=
mediaCodecName
!=
null
?
MediaCodec
.
createByCodecName
(
mediaCodecName
)
:
isDecoder
?
MediaCodec
.
createDecoderByType
(
format
.
sampleMimeType
)
:
MediaCodec
.
createEncoderByType
(
format
.
sampleMimeType
);
configureCodec
(
mediaCodec
,
mediaFormat
,
isDecoder
,
outputSurface
);
if
(
isVideo
&&
!
isDecoder
)
{
inputSurface
=
mediaCodec
.
createInputSurface
();
}
startCodec
(
mediaCodec
);
}
catch
(
Exception
e
)
{
if
(
inputSurface
!=
null
)
{
inputSurface
.
release
();
}
if
(
mediaCodec
!=
null
)
{
mediaCodecName
=
mediaCodec
.
getName
();
mediaCodec
.
release
();
}
throw
createTransformationException
(
e
,
format
,
isVideo
,
isDecoder
,
mediaCodecName
);
}
return
new
Codec
(
mediaCodec
,
format
,
inputSurface
);
}
/** Creates a {@link TransformationException}. */
public
static
TransformationException
createTransformationException
(
Exception
cause
,
Format
format
,
boolean
isVideo
,
boolean
isDecoder
,
@Nullable
String
mediaCodecName
)
{
String
componentName
=
(
isVideo
?
"Video"
:
"Audio"
)
+
(
isDecoder
?
"Decoder"
:
"Encoder"
);
if
(
cause
instanceof
IOException
||
cause
instanceof
MediaCodec
.
CodecException
)
{
return
TransformationException
.
createForCodec
(
cause
,
componentName
,
format
,
mediaCodecName
,
isDecoder
?
TransformationException
.
ERROR_CODE_DECODER_INIT_FAILED
:
TransformationException
.
ERROR_CODE_ENCODER_INIT_FAILED
);
}
if
(
cause
instanceof
IllegalArgumentException
)
{
return
TransformationException
.
createForCodec
(
cause
,
componentName
,
format
,
mediaCodecName
,
isDecoder
?
TransformationException
.
ERROR_CODE_DECODING_FORMAT_UNSUPPORTED
:
TransformationException
.
ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED
);
}
return
TransformationException
.
createForUnexpected
(
cause
);
}
private
static
void
configureCodec
(
MediaCodec
codec
,
MediaFormat
mediaFormat
,
boolean
isDecoder
,
@Nullable
Surface
outputSurface
)
{
TraceUtil
.
beginSection
(
"configureCodec"
);
codec
.
configure
(
mediaFormat
,
outputSurface
,
/* crypto= */
null
,
isDecoder
?
0
:
MediaCodec
.
CONFIGURE_FLAG_ENCODE
);
TraceUtil
.
endSection
();
}
private
static
void
startCodec
(
MediaCodec
codec
)
{
TraceUtil
.
beginSection
(
"startCodec"
);
codec
.
start
();
TraceUtil
.
endSection
();
}
private
CodecFactoryUtil
()
{}
}
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java
0 → 100644
View file @
392ec6f3
/*
* Copyright 2022 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
.
transformer
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
CodecFactoryUtil
.
createCodec
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
SDK_INT
;
import
android.media.MediaFormat
;
import
android.view.Surface
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.util.MediaFormatUtil
;
/** A default implementation of {@link Codec.DecoderFactory}. */
/* package */
final
class
DefaultDecoderFactory
implements
Codec
.
DecoderFactory
{
@Override
public
Codec
createForAudioDecoding
(
Format
format
)
throws
TransformationException
{
MediaFormat
mediaFormat
=
MediaFormat
.
createAudioFormat
(
checkNotNull
(
format
.
sampleMimeType
),
format
.
sampleRate
,
format
.
channelCount
);
MediaFormatUtil
.
maybeSetInteger
(
mediaFormat
,
MediaFormat
.
KEY_MAX_INPUT_SIZE
,
format
.
maxInputSize
);
MediaFormatUtil
.
setCsdBuffers
(
mediaFormat
,
format
.
initializationData
);
return
createCodec
(
format
,
mediaFormat
,
/* mediaCodecName= */
null
,
/* isVideo= */
false
,
/* isDecoder= */
true
,
/* outputSurface= */
null
);
}
@Override
public
Codec
createForVideoDecoding
(
Format
format
,
Surface
outputSurface
)
throws
TransformationException
{
MediaFormat
mediaFormat
=
MediaFormat
.
createVideoFormat
(
checkNotNull
(
format
.
sampleMimeType
),
format
.
width
,
format
.
height
);
MediaFormatUtil
.
maybeSetInteger
(
mediaFormat
,
MediaFormat
.
KEY_ROTATION
,
format
.
rotationDegrees
);
MediaFormatUtil
.
maybeSetInteger
(
mediaFormat
,
MediaFormat
.
KEY_MAX_INPUT_SIZE
,
format
.
maxInputSize
);
MediaFormatUtil
.
setCsdBuffers
(
mediaFormat
,
format
.
initializationData
);
if
(
SDK_INT
>=
29
)
{
// On API levels over 29, Transformer decodes as many frames as possible in one render
// cycle. This key ensures no frame dropping when the decoder's output surface is full.
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_ALLOW_FRAME_DROP
,
0
);
}
return
createCodec
(
format
,
mediaFormat
,
/* mediaCodecName= */
null
,
/* isVideo= */
true
,
/* isDecoder= */
true
,
outputSurface
);
}
}
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Default
Codec
Factory.java
→
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Default
Encoder
Factory.java
View file @
392ec6f3
This diff is collapsed.
Click to expand it.
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