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;
}
@Override
public
void
release
()
{
if
(
isStarted
)
{
isStarted
=
false
;
try
{
mediaMuxer
.
stop
();
}
catch
(
IllegalStateException
e
)
{
if
(
SDK_INT
<
30
)
{
// Set the muxer state to stopped even if mediaMuxer.stop() failed so that
// mediaMuxer.release() doesn't attempt to stop the muxer and therefore doesn't throw the
// same exception without releasing its resources. This is already implemented in
// MediaMuxer
// from API level 30.
try
{
Field
muxerStoppedStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"MUXER_STATE_STOPPED"
);
muxerStoppedStateField
.
setAccessible
(
true
);
int
muxerStoppedState
=
castNonNull
((
Integer
)
muxerStoppedStateField
.
get
(
mediaMuxer
));
Field
muxerStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"mState"
);
muxerStateField
.
setAccessible
(
true
);
muxerStateField
.
set
(
mediaMuxer
,
muxerStoppedState
);
}
catch
(
Exception
reflectionException
)
{
// Do nothing.
}
public
void
release
(
boolean
forCancellation
)
{
if
(!
isStarted
)
{
mediaMuxer
.
release
();
return
;
}
isStarted
=
false
;
try
{
mediaMuxer
.
stop
();
}
catch
(
IllegalStateException
e
)
{
if
(
SDK_INT
<
30
)
{
// Set the muxer state to stopped even if mediaMuxer.stop() failed so that
// mediaMuxer.release() doesn't attempt to stop the muxer and therefore doesn't throw the
// same exception without releasing its resources. This is already implemented in MediaMuxer
// from API level 30.
try
{
Field
muxerStoppedStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"MUXER_STATE_STOPPED"
);
muxerStoppedStateField
.
setAccessible
(
true
);
int
muxerStoppedState
=
castNonNull
((
Integer
)
muxerStoppedStateField
.
get
(
mediaMuxer
));
Field
muxerStateField
=
MediaMuxer
.
class
.
getDeclaredField
(
"mState"
);
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
;
}
}
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;
void
writeSampleData
(
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;
}
/**
*
Stops the muxer
.
*
Releases any resources associated with muxing
.
*
* <p>The muxer cannot be used anymore once it is stopped.
*/
public
void
stop
()
{
if
(
isReady
)
{
isReady
=
false
;
}
}
/**
* Releases the muxer.
* <p>The muxer cannot be used anymore once this method has been called.
*
* <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
;
muxer
.
release
();
muxer
.
release
(
forCancellation
);
}
/** 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 {
* @throws IllegalStateException If this method is called from the wrong thread.
*/
public
void
cancel
()
{
// It doesn't matter that stopping the muxer throws, because the transformation is cancelled
// anyway.
releaseResources
(
/* swallowStopMuxerException= */
true
);
releaseResources
(
/* forCancellation= */
true
);
}
/**
* 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 the muxer is in the wrong state
when stopping it and {@code
*
swallowStopMuxerException} is
false.
* @throws IllegalStateException If the muxer is in the wrong state
and {@code forCancellation} is
* false.
*/
private
void
releaseResources
(
boolean
swallowStopMuxerExcep
tion
)
{
private
void
releaseResources
(
boolean
forCancella
tion
)
{
verifyApplicationThread
();
if
(
player
!=
null
)
{
player
.
release
();
player
=
null
;
}
if
(
muxerWrapper
!=
null
)
{
try
{
muxerWrapper
.
stop
();
}
catch
(
IllegalStateException
e
)
{
if
(!
swallowStopMuxerException
)
{
throw
e
;
}
}
finally
{
muxerWrapper
.
release
();
muxerWrapper
=
null
;
}
muxerWrapper
.
release
(
forCancellation
);
muxerWrapper
=
null
;
}
progressState
=
PROGRESS_STATE_NO_TRANSFORMATION
;
}
...
...
@@ -654,7 +645,7 @@ public final class Transformer {
private
void
handleTransformationEnded
(
@Nullable
Exception
exception
)
{
try
{
releaseResources
(
/*
swallowStopMuxerExcep
tion= */
false
);
releaseResources
(
/*
forCancella
tion= */
false
);
}
catch
(
IllegalStateException
e
)
{
if
(
exception
==
null
)
{
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 {
}
@Override
public
void
release
()
{
public
void
release
(
boolean
forCancellation
)
{
dumpables
.
add
(
dumper
->
dumper
.
add
(
"released"
,
true
));
frameworkMuxer
.
release
();
frameworkMuxer
.
release
(
forCancellation
);
}
// 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