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
755df46a
authored
Jan 13, 2022
by
hschlueter
Committed by
Ian Baker
Jan 14, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Remove Transformer-specific things from MediaCodecAdapter.
PiperOrigin-RevId: 421514944
parent
b09b8dc2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
170 deletions
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapter.java
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecAdapter.java
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/SynchronousMediaCodecAdapter.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/CapturingRenderersFactory.java
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapter.java
View file @
755df46a
...
...
@@ -109,8 +109,7 @@ import java.nio.ByteBuffer;
configuration
.
mediaFormat
,
configuration
.
surface
,
configuration
.
crypto
,
configuration
.
flags
,
configuration
.
createInputSurface
);
configuration
.
flags
);
return
codecAdapter
;
}
catch
(
Exception
e
)
{
if
(
codecAdapter
!=
null
)
{
...
...
@@ -139,7 +138,6 @@ import java.nio.ByteBuffer;
private
final
boolean
enableImmediateCodecStartAfterFlush
;
private
boolean
codecReleased
;
@State
private
int
state
;
@Nullable
private
Surface
inputSurface
;
private
AsynchronousMediaCodecAdapter
(
MediaCodec
codec
,
...
...
@@ -159,15 +157,11 @@ import java.nio.ByteBuffer;
@Nullable
MediaFormat
mediaFormat
,
@Nullable
Surface
surface
,
@Nullable
MediaCrypto
crypto
,
int
flags
,
boolean
createInputSurface
)
{
int
flags
)
{
asynchronousMediaCodecCallback
.
initialize
(
codec
);
TraceUtil
.
beginSection
(
"configureCodec"
);
codec
.
configure
(
mediaFormat
,
surface
,
crypto
,
flags
);
TraceUtil
.
endSection
();
if
(
createInputSurface
)
{
inputSurface
=
codec
.
createInputSurface
();
}
bufferEnqueuer
.
start
();
TraceUtil
.
beginSection
(
"startCodec"
);
codec
.
start
();
...
...
@@ -225,12 +219,6 @@ import java.nio.ByteBuffer;
@Override
@Nullable
public
Surface
getInputSurface
()
{
return
inputSurface
;
}
@Override
@Nullable
public
ByteBuffer
getOutputBuffer
(
int
index
)
{
return
codec
.
getOutputBuffer
(
index
);
}
...
...
@@ -263,9 +251,6 @@ import java.nio.ByteBuffer;
}
state
=
STATE_SHUT_DOWN
;
}
finally
{
if
(
inputSurface
!=
null
)
{
inputSurface
.
release
();
}
if
(!
codecReleased
)
{
codec
.
release
();
codecReleased
=
true
;
...
...
@@ -302,12 +287,6 @@ import java.nio.ByteBuffer;
}
@Override
public
void
signalEndOfInputStream
()
{
maybeBlockOnQueueing
();
codec
.
signalEndOfInputStream
();
}
@Override
@RequiresApi
(
26
)
public
PersistableBundle
getMetrics
()
{
maybeBlockOnQueueing
();
...
...
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecAdapter.java
View file @
755df46a
...
...
@@ -55,13 +55,7 @@ public interface MediaCodecAdapter {
Format
format
,
@Nullable
MediaCrypto
crypto
)
{
return
new
Configuration
(
codecInfo
,
mediaFormat
,
format
,
/* surface= */
null
,
crypto
,
/* flags= */
0
,
/* createInputSurface= */
false
);
codecInfo
,
mediaFormat
,
format
,
/* surface= */
null
,
crypto
,
/* flags= */
0
);
}
/**
...
...
@@ -80,55 +74,7 @@ public interface MediaCodecAdapter {
Format
format
,
@Nullable
Surface
surface
,
@Nullable
MediaCrypto
crypto
)
{
return
new
Configuration
(
codecInfo
,
mediaFormat
,
format
,
surface
,
crypto
,
/* flags= */
0
,
/* createInputSurface= */
false
);
}
/**
* Creates a configuration for audio encoding.
*
* @param codecInfo See {@link #codecInfo}.
* @param mediaFormat See {@link #mediaFormat}.
* @param format See {@link #format}.
* @return The created instance.
*/
public
static
Configuration
createForAudioEncoding
(
MediaCodecInfo
codecInfo
,
MediaFormat
mediaFormat
,
Format
format
)
{
return
new
Configuration
(
codecInfo
,
mediaFormat
,
format
,
/* surface= */
null
,
/* crypto= */
null
,
MediaCodec
.
CONFIGURE_FLAG_ENCODE
,
/* createInputSurface= */
false
);
}
/**
* Creates a configuration for video encoding.
*
* @param codecInfo See {@link #codecInfo}.
* @param mediaFormat See {@link #mediaFormat}.
* @param format See {@link #format}.
* @return The created instance.
*/
@RequiresApi
(
18
)
public
static
Configuration
createForVideoEncoding
(
MediaCodecInfo
codecInfo
,
MediaFormat
mediaFormat
,
Format
format
)
{
return
new
Configuration
(
codecInfo
,
mediaFormat
,
format
,
/* surface= */
null
,
/* crypto= */
null
,
MediaCodec
.
CONFIGURE_FLAG_ENCODE
,
/* createInputSurface= */
true
);
return
new
Configuration
(
codecInfo
,
mediaFormat
,
format
,
surface
,
crypto
,
/* flags= */
0
);
}
/** Information about the {@link MediaCodec} being configured. */
...
...
@@ -145,17 +91,8 @@ public interface MediaCodecAdapter {
@Nullable
public
final
Surface
surface
;
/** For DRM protected playbacks, a {@link MediaCrypto} to use for decryption. */
@Nullable
public
final
MediaCrypto
crypto
;
/**
* Specify CONFIGURE_FLAG_ENCODE to configure the component as an encoder.
*
* @see MediaCodec#configure
*/
/** See {@link MediaCodec#configure}. */
public
final
int
flags
;
/**
* Whether to request a {@link Surface} and use it as to the input to an encoder. This can only
* be set to {@code true} on API 18+.
*/
public
final
boolean
createInputSurface
;
private
Configuration
(
MediaCodecInfo
codecInfo
,
...
...
@@ -163,15 +100,13 @@ public interface MediaCodecAdapter {
Format
format
,
@Nullable
Surface
surface
,
@Nullable
MediaCrypto
crypto
,
int
flags
,
boolean
createInputSurface
)
{
int
flags
)
{
this
.
codecInfo
=
codecInfo
;
this
.
mediaFormat
=
mediaFormat
;
this
.
format
=
format
;
this
.
surface
=
surface
;
this
.
crypto
=
crypto
;
this
.
flags
=
flags
;
this
.
createInputSurface
=
createInputSurface
;
}
}
...
...
@@ -230,14 +165,6 @@ public interface MediaCodecAdapter {
ByteBuffer
getInputBuffer
(
int
index
);
/**
* Returns the input {@link Surface}, or null if the input is not a surface.
*
* @see MediaCodec#createInputSurface()
*/
@Nullable
Surface
getInputSurface
();
/**
* Returns a read-only ByteBuffer for a dequeued output buffer index.
*
* @see MediaCodec#getOutputBuffer(int)
...
...
@@ -330,15 +257,6 @@ public interface MediaCodecAdapter {
boolean
needsReconfiguration
();
/**
* Signals the encoder of end-of-stream on input. The call can only be used when the encoder
* receives its input from a {@link Surface surface}.
*
* @see MediaCodec#signalEndOfInputStream()
*/
@RequiresApi
(
18
)
void
signalEndOfInputStream
();
/**
* Returns metrics data about the current codec instance.
*
* @see MediaCodec#getMetrics()
...
...
library/core/src/main/java/com/google/android/exoplayer2/mediacodec/SynchronousMediaCodecAdapter.java
View file @
755df46a
...
...
@@ -25,7 +25,6 @@ import android.os.Bundle;
import
android.os.Handler
;
import
android.os.PersistableBundle
;
import
android.view.Surface
;
import
androidx.annotation.DoNotInline
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
com.google.android.exoplayer2.C
;
...
...
@@ -46,7 +45,6 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
@Override
public
MediaCodecAdapter
createAdapter
(
Configuration
configuration
)
throws
IOException
{
@Nullable
MediaCodec
codec
=
null
;
@Nullable
Surface
inputSurface
=
null
;
try
{
codec
=
createCodec
(
configuration
);
TraceUtil
.
beginSection
(
"configureCodec"
);
...
...
@@ -56,24 +54,11 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
configuration
.
crypto
,
configuration
.
flags
);
TraceUtil
.
endSection
();
if
(
configuration
.
createInputSurface
)
{
if
(
Util
.
SDK_INT
>=
18
)
{
inputSurface
=
Api18
.
createCodecInputSurface
(
codec
);
}
else
{
throw
new
IllegalStateException
(
"Encoding from a surface is only supported on API 18 and up."
);
}
}
TraceUtil
.
beginSection
(
"startCodec"
);
codec
.
start
();
TraceUtil
.
endSection
();
return
new
SynchronousMediaCodecAdapter
(
codec
,
inputSurface
);
return
new
SynchronousMediaCodecAdapter
(
codec
);
}
catch
(
IOException
|
RuntimeException
e
)
{
if
(
inputSurface
!=
null
)
{
inputSurface
.
release
();
}
if
(
codec
!=
null
)
{
codec
.
release
();
}
...
...
@@ -93,13 +78,11 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
}
private
final
MediaCodec
codec
;
@Nullable
private
final
Surface
inputSurface
;
@Nullable
private
ByteBuffer
[]
inputByteBuffers
;
@Nullable
private
ByteBuffer
[]
outputByteBuffers
;
private
SynchronousMediaCodecAdapter
(
MediaCodec
mediaCodec
,
@Nullable
Surface
inputSurface
)
{
private
SynchronousMediaCodecAdapter
(
MediaCodec
mediaCodec
)
{
this
.
codec
=
mediaCodec
;
this
.
inputSurface
=
inputSurface
;
if
(
Util
.
SDK_INT
<
21
)
{
inputByteBuffers
=
codec
.
getInputBuffers
();
outputByteBuffers
=
codec
.
getOutputBuffers
();
...
...
@@ -146,12 +129,6 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
@Override
@Nullable
public
Surface
getInputSurface
()
{
return
inputSurface
;
}
@Override
@Nullable
public
ByteBuffer
getOutputBuffer
(
int
index
)
{
if
(
Util
.
SDK_INT
>=
21
)
{
return
codec
.
getOutputBuffer
(
index
);
...
...
@@ -193,19 +170,10 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
public
void
release
()
{
inputByteBuffers
=
null
;
outputByteBuffers
=
null
;
if
(
inputSurface
!=
null
)
{
inputSurface
.
release
();
}
codec
.
release
();
}
@Override
@RequiresApi
(
18
)
public
void
signalEndOfInputStream
()
{
Api18
.
signalEndOfInputStream
(
codec
);
}
@Override
@RequiresApi
(
23
)
public
void
setOnFrameRenderedListener
(
OnFrameRenderedListener
listener
,
Handler
handler
)
{
codec
.
setOnFrameRenderedListener
(
...
...
@@ -237,19 +205,4 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
public
PersistableBundle
getMetrics
()
{
return
codec
.
getMetrics
();
}
@RequiresApi
(
18
)
private
static
final
class
Api18
{
private
Api18
()
{}
@DoNotInline
public
static
Surface
createCodecInputSurface
(
MediaCodec
codec
)
{
return
codec
.
createInputSurface
();
}
@DoNotInline
public
static
void
signalEndOfInputStream
(
MediaCodec
codec
)
{
codec
.
signalEndOfInputStream
();
}
}
}
testutils/src/main/java/com/google/android/exoplayer2/testutil/CapturingRenderersFactory.java
View file @
755df46a
...
...
@@ -197,12 +197,6 @@ public class CapturingRenderersFactory implements RenderersFactory, Dumper.Dumpa
@Nullable
@Override
public
Surface
getInputSurface
()
{
return
delegate
.
getInputSurface
();
}
@Nullable
@Override
public
ByteBuffer
getOutputBuffer
(
int
index
)
{
return
delegate
.
getOutputBuffer
(
index
);
}
...
...
@@ -270,12 +264,6 @@ public class CapturingRenderersFactory implements RenderersFactory, Dumper.Dumpa
delegate
.
setVideoScalingMode
(
scalingMode
);
}
@RequiresApi
(
18
)
@Override
public
void
signalEndOfInputStream
()
{
delegate
.
signalEndOfInputStream
();
}
@RequiresApi
(
26
)
@Override
public
PersistableBundle
getMetrics
()
{
...
...
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