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
15472a51
authored
Feb 01, 2021
by
kimvde
Committed by
Oliver Woodman
Feb 01, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Merge MuxerWrapper stop() and release() methods
#minor-release PiperOrigin-RevId: 354938190
parent
03b9fa30
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
59 deletions
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameworkMuxer.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Muxer.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/MuxerWrapper.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/TestMuxer.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameworkMuxer.java
View file @
15472a51
...
@@ -138,33 +138,39 @@ import java.nio.ByteBuffer;
...
@@ -138,33 +138,39 @@ import java.nio.ByteBuffer;
}
}
@Override
@Override
public
void
release
()
{
public
void
release
(
boolean
forCancellation
)
{
if
(
isStarted
)
{
if
(!
isStarted
)
{
isStarted
=
false
;
mediaMuxer
.
release
();
try
{
return
;
mediaMuxer
.
stop
();
}
}
catch
(
IllegalStateException
e
)
{
if
(
SDK_INT
<
30
)
{
isStarted
=
false
;
// Set the muxer state to stopped even if mediaMuxer.stop() failed so that
try
{
// mediaMuxer.release() doesn't attempt to stop the muxer and therefore doesn't throw the
mediaMuxer
.
stop
();
// same exception without releasing its resources. This is already implemented in
}
catch
(
IllegalStateException
e
)
{
// MediaMuxer
if
(
SDK_INT
<
30
)
{
// from API level 30.
// Set the muxer state to stopped even if mediaMuxer.stop() failed so that
try
{
// mediaMuxer.release() doesn't attempt to stop the muxer and therefore doesn't throw the
Field
muxerStoppedStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"MUXER_STATE_STOPPED"
);
// same exception without releasing its resources. This is already implemented in MediaMuxer
muxerStoppedStateField
.
setAccessible
(
true
);
// from API level 30.
int
muxerStoppedState
=
castNonNull
((
Integer
)
muxerStoppedStateField
.
get
(
mediaMuxer
));
try
{
Field
muxerStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"mState"
);
Field
muxerStoppedStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"MUXER_STATE_STOPPED"
);
muxerStateField
.
setAccessible
(
true
);
muxerStoppedStateField
.
setAccessible
(
true
);
muxerStateField
.
set
(
mediaMuxer
,
muxerStoppedState
);
int
muxerStoppedState
=
castNonNull
((
Integer
)
muxerStoppedStateField
.
get
(
mediaMuxer
));
}
catch
(
Exception
reflectionException
)
{
Field
muxerStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"mState"
);
// Do nothing.
muxerStateField
.
setAccessible
(
true
);
}
muxerStateField
.
set
(
mediaMuxer
,
muxerStoppedState
);
}
catch
(
Exception
reflectionException
)
{
// Do nothing.
}
}
}
// It doesn't matter that stopping the muxer throws if the transformation is being cancelled.
if
(!
forCancellation
)
{
throw
e
;
throw
e
;
}
}
}
finally
{
mediaMuxer
.
release
();
}
}
mediaMuxer
.
release
();
}
}
/**
/**
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Muxer.java
View file @
15472a51
...
@@ -84,6 +84,11 @@ import java.nio.ByteBuffer;
...
@@ -84,6 +84,11 @@ import java.nio.ByteBuffer;
void
writeSampleData
(
void
writeSampleData
(
int
trackIndex
,
ByteBuffer
data
,
boolean
isKeyFrame
,
long
presentationTimeUs
);
int
trackIndex
,
ByteBuffer
data
,
boolean
isKeyFrame
,
long
presentationTimeUs
);
/** Releases any resources associated with muxing. */
/**
void
release
();
* Releases any resources associated with muxing.
*
* @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation.
*/
void
release
(
boolean
forCancellation
);
}
}
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/MuxerWrapper.java
View file @
15472a51
...
@@ -159,24 +159,16 @@ import java.nio.ByteBuffer;
...
@@ -159,24 +159,16 @@ import java.nio.ByteBuffer;
}
}
/**
/**
*
Stops the muxer
.
*
Releases any resources associated with muxing
.
*
*
* <p>The muxer cannot be used anymore once it is stopped.
* <p>The muxer cannot be used anymore once this method has been called.
*/
public
void
stop
()
{
if
(
isReady
)
{
isReady
=
false
;
}
}
/**
* Releases the muxer.
*
*
* <p>The muxer cannot be used anymore once it is released.
* @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation.
*/
*/
public
void
release
()
{
public
void
release
(
boolean
forCancellation
)
{
isReady
=
false
;
isReady
=
false
;
muxer
.
release
();
muxer
.
release
(
forCancellation
);
}
}
/** Returns the number of {@link #registerTrack() registered} tracks. */
/** Returns the number of {@link #registerTrack() registered} tracks. */
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java
View file @
15472a51
...
@@ -525,36 +525,27 @@ public final class Transformer {
...
@@ -525,36 +525,27 @@ public final class Transformer {
* @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If this method is called from the wrong thread.
*/
*/
public
void
cancel
()
{
public
void
cancel
()
{
// It doesn't matter that stopping the muxer throws, because the transformation is cancelled
releaseResources
(
/* forCancellation= */
true
);
// anyway.
releaseResources
(
/* swallowStopMuxerException= */
true
);
}
}
/**
/**
* Releases the resources.
* Releases the resources.
*
*
* @param swallowStopMuxerException Whether to swallow exceptions thrown by stopping the muxer.
* @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation.
* @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If the muxer is in the wrong state
when stopping it and {@code
* @throws IllegalStateException If the muxer is in the wrong state
and {@code forCancellation} is
*
swallowStopMuxerException} is
false.
* false.
*/
*/
private
void
releaseResources
(
boolean
swallowStopMuxerExcep
tion
)
{
private
void
releaseResources
(
boolean
forCancella
tion
)
{
verifyApplicationThread
();
verifyApplicationThread
();
if
(
player
!=
null
)
{
if
(
player
!=
null
)
{
player
.
release
();
player
.
release
();
player
=
null
;
player
=
null
;
}
}
if
(
muxerWrapper
!=
null
)
{
if
(
muxerWrapper
!=
null
)
{
try
{
muxerWrapper
.
release
(
forCancellation
);
muxerWrapper
.
stop
();
muxerWrapper
=
null
;
}
catch
(
IllegalStateException
e
)
{
if
(!
swallowStopMuxerException
)
{
throw
e
;
}
}
finally
{
muxerWrapper
.
release
();
muxerWrapper
=
null
;
}
}
}
progressState
=
PROGRESS_STATE_NO_TRANSFORMATION
;
progressState
=
PROGRESS_STATE_NO_TRANSFORMATION
;
}
}
...
@@ -654,7 +645,7 @@ public final class Transformer {
...
@@ -654,7 +645,7 @@ public final class Transformer {
private
void
handleTransformationEnded
(
@Nullable
Exception
exception
)
{
private
void
handleTransformationEnded
(
@Nullable
Exception
exception
)
{
try
{
try
{
releaseResources
(
/*
swallowStopMuxerExcep
tion= */
false
);
releaseResources
(
/*
forCancella
tion= */
false
);
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
if
(
exception
==
null
)
{
if
(
exception
==
null
)
{
exception
=
e
;
exception
=
e
;
...
...
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/TestMuxer.java
View file @
15472a51
...
@@ -62,9 +62,9 @@ public final class TestMuxer implements Muxer, Dumper.Dumpable {
...
@@ -62,9 +62,9 @@ public final class TestMuxer implements Muxer, Dumper.Dumpable {
}
}
@Override
@Override
public
void
release
()
{
public
void
release
(
boolean
forCancellation
)
{
dumpables
.
add
(
dumper
->
dumper
.
add
(
"released"
,
true
));
dumpables
.
add
(
dumper
->
dumper
.
add
(
"released"
,
true
));
frameworkMuxer
.
release
();
frameworkMuxer
.
release
(
forCancellation
);
}
}
// Dumper.Dumpable implementation.
// Dumper.Dumpable implementation.
...
...
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