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
19bf020d
authored
Nov 18, 2022
by
kimvde
Committed by
microkatz
Nov 21, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Build TransformationResult only when transformation succeeded
PiperOrigin-RevId: 489442518
parent
d9d71686
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
16 deletions
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java
View file @
19bf020d
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
com
.
google
.
android
.
exoplayer2
.
transformer
;
package
com
.
google
.
android
.
exoplayer2
.
transformer
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
TransformerInternal
.
END_TRANSFORMATION_REASON_CANCELLED
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkState
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkState
;
import
static
java
.
lang
.
annotation
.
ElementType
.
TYPE_USE
;
import
static
java
.
lang
.
annotation
.
ElementType
.
TYPE_USE
;
...
@@ -777,7 +778,7 @@ public final class Transformer {
...
@@ -777,7 +778,7 @@ public final class Transformer {
return
;
return
;
}
}
try
{
try
{
transformerInternal
.
release
(
/* forCancellation= */
true
);
transformerInternal
.
release
(
END_TRANSFORMATION_REASON_CANCELLED
);
}
catch
(
TransformationException
impossible
)
{
}
catch
(
TransformationException
impossible
)
{
throw
new
IllegalStateException
(
impossible
);
throw
new
IllegalStateException
(
impossible
);
}
}
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java
View file @
19bf020d
...
@@ -22,10 +22,12 @@ import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STA
...
@@ -22,10 +22,12 @@ import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STA
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
Transformer
.
PROGRESS_STATE_WAITING_FOR_AVAILABILITY
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
Transformer
.
PROGRESS_STATE_WAITING_FOR_AVAILABILITY
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
java
.
lang
.
Math
.
min
;
import
static
java
.
lang
.
Math
.
min
;
import
static
java
.
lang
.
annotation
.
ElementType
.
TYPE_USE
;
import
android.content.Context
;
import
android.content.Context
;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.os.ParcelFileDescriptor
;
import
android.os.ParcelFileDescriptor
;
import
androidx.annotation.IntDef
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.Format
;
...
@@ -44,6 +46,10 @@ import com.google.android.exoplayer2.util.HandlerWrapper;
...
@@ -44,6 +46,10 @@ import com.google.android.exoplayer2.util.HandlerWrapper;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
...
@@ -57,6 +63,28 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...
@@ -57,6 +63,28 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
void
onTransformationError
(
TransformationException
exception
);
void
onTransformationError
(
TransformationException
exception
);
}
}
/**
* Represents a reason for ending a transformation. May be one of {@link
* #END_TRANSFORMATION_REASON_COMPLETED}, {@link #END_TRANSFORMATION_REASON_CANCELLED} or {@link
* #END_TRANSFORMATION_REASON_ERROR}.
*/
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Target
(
TYPE_USE
)
@IntDef
({
END_TRANSFORMATION_REASON_COMPLETED
,
END_TRANSFORMATION_REASON_CANCELLED
,
END_TRANSFORMATION_REASON_ERROR
})
public
@interface
EndTransformationReason
{}
/** The transformation completed successfully. */
public
static
final
int
END_TRANSFORMATION_REASON_COMPLETED
=
0
;
/** The transformation was cancelled. */
public
static
final
int
END_TRANSFORMATION_REASON_CANCELLED
=
1
;
/** An error occurred during the transformation. */
public
static
final
int
END_TRANSFORMATION_REASON_ERROR
=
2
;
private
final
Context
context
;
private
final
Context
context
;
private
final
TransformationRequest
transformationRequest
;
private
final
TransformationRequest
transformationRequest
;
private
final
ImmutableList
<
AudioProcessor
>
audioProcessors
;
private
final
ImmutableList
<
AudioProcessor
>
audioProcessors
;
...
@@ -145,12 +173,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...
@@ -145,12 +173,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/**
/**
* Releases the resources.
* Releases the resources.
*
*
* @param
forCancellation Whether the reason for releasing the resources is the transformation
* @param
endTransformationReason The {@linkplain EndTransformationReason reason} for ending the
*
cancell
ation.
*
transform
ation.
* @throws TransformationException If the muxer is in the wrong state and {@code
forCancellation}
* @throws TransformationException If the muxer is in the wrong state and {@code
*
is false
.
*
endTransformationReason} is not {@link #END_TRANSFORMATION_REASON_CANCELLED}
.
*/
*/
public
void
release
(
boolean
forCancellation
)
throws
TransformationException
{
public
void
release
(
@EndTransformationReason
int
endTransformationReason
)
throws
TransformationException
{
if
(
released
)
{
if
(
released
)
{
return
;
return
;
}
}
...
@@ -161,16 +190,20 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...
@@ -161,16 +190,20 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
clock
.
createHandler
(
exoPlayerAssetLoader
.
getPlaybackLooper
(),
/* callback= */
null
);
clock
.
createHandler
(
exoPlayerAssetLoader
.
getPlaybackLooper
(),
/* callback= */
null
);
playbackHandler
.
post
(
playbackHandler
.
post
(
()
->
{
()
->
{
transformationResult
=
if
(
endTransformationReason
==
END_TRANSFORMATION_REASON_COMPLETED
)
{
new
TransformationResult
.
Builder
()
transformationResult
=
.
setDurationMs
(
checkNotNull
(
muxerWrapper
).
getDurationMs
())
new
TransformationResult
.
Builder
()
.
setAverageAudioBitrate
(
muxerWrapper
.
getTrackAverageBitrate
(
C
.
TRACK_TYPE_AUDIO
))
.
setDurationMs
(
checkNotNull
(
muxerWrapper
).
getDurationMs
())
.
setAverageVideoBitrate
(
muxerWrapper
.
getTrackAverageBitrate
(
C
.
TRACK_TYPE_VIDEO
))
.
setAverageAudioBitrate
(
muxerWrapper
.
getTrackAverageBitrate
(
C
.
TRACK_TYPE_AUDIO
))
.
setVideoFrameCount
(
muxerWrapper
.
getTrackSampleCount
(
C
.
TRACK_TYPE_VIDEO
))
.
setAverageVideoBitrate
(
muxerWrapper
.
getTrackAverageBitrate
(
C
.
TRACK_TYPE_VIDEO
))
.
setFileSizeBytes
(
muxerWrapper
.
getCurrentOutputSizeBytes
())
.
setVideoFrameCount
(
muxerWrapper
.
getTrackSampleCount
(
C
.
TRACK_TYPE_VIDEO
))
.
build
();
.
setFileSizeBytes
(
muxerWrapper
.
getCurrentOutputSizeBytes
())
.
build
();
}
try
{
try
{
muxerWrapper
.
release
(
forCancellation
);
muxerWrapper
.
release
(
/* forCancellation= */
endTransformationReason
==
END_TRANSFORMATION_REASON_CANCELLED
);
}
catch
(
Muxer
.
MuxerException
e
)
{
}
catch
(
Muxer
.
MuxerException
e
)
{
releaseMuxerException
=
releaseMuxerException
=
TransformationException
.
createForMuxer
(
TransformationException
.
createForMuxer
(
...
@@ -392,7 +425,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...
@@ -392,7 +425,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
()
->
{
()
->
{
@Nullable
TransformationException
releaseException
=
null
;
@Nullable
TransformationException
releaseException
=
null
;
try
{
try
{
release
(
/* forCancellation= */
false
);
release
(
transformationException
==
null
?
END_TRANSFORMATION_REASON_COMPLETED
:
END_TRANSFORMATION_REASON_ERROR
);
}
catch
(
TransformationException
e
)
{
}
catch
(
TransformationException
e
)
{
releaseException
=
e
;
releaseException
=
e
;
}
catch
(
RuntimeException
e
)
{
}
catch
(
RuntimeException
e
)
{
...
...
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