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
83408d06
authored
Nov 29, 2021
by
samrobinson
Committed by
tonihei
Dec 02, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Create and write the TransformationResult to on-device text file.
PiperOrigin-RevId: 412856100
parent
99eb3517
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
10 deletions
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/AndroidTestUtil.java
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/AndroidTestUtil.java
View file @
83408d06
...
...
@@ -20,12 +20,14 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import
android.content.Context
;
import
android.net.Uri
;
import
android.os.Build
;
import
androidx.annotation.Nullable
;
import
androidx.test.platform.app.InstrumentationRegistry
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.transformer.Transformer
;
import
com.google.android.exoplayer2.util.Assertions
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.atomic.AtomicReference
;
...
...
@@ -40,9 +42,11 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
/** Information about the result of successfully running a transformer. */
public
static
final
class
TransformationResult
{
public
long
outputSizeBytes
;
public
final
String
testId
;
public
final
long
outputSizeBytes
;
private
TransformationResult
(
long
outputSizeBytes
)
{
private
TransformationResult
(
String
testId
,
long
outputSizeBytes
)
{
this
.
testId
=
testId
;
this
.
outputSizeBytes
=
outputSizeBytes
;
}
}
...
...
@@ -83,13 +87,13 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
.
build
();
Uri
uri
=
Uri
.
parse
(
uriString
);
File
externalCacheFile
=
createExternalCacheFile
(
context
,
/* filePrefix= */
testId
);
File
outputVideoFile
=
createExternalCacheFile
(
context
,
/* fileName= */
testId
+
"-output.mp4"
);
InstrumentationRegistry
.
getInstrumentation
()
.
runOnMainSync
(
()
->
{
try
{
testTransformer
.
startTransformation
(
MediaItem
.
fromUri
(
uri
),
externalCache
File
.
getAbsolutePath
());
MediaItem
.
fromUri
(
uri
),
outputVideo
File
.
getAbsolutePath
());
}
catch
(
IOException
e
)
{
exceptionReference
.
set
(
e
);
}
...
...
@@ -102,16 +106,41 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
if
(
exception
!=
null
)
{
throw
exception
;
}
long
outputSizeBytes
=
externalCacheFile
.
length
();
return
new
TransformationResult
(
outputSizeBytes
);
long
outputSizeBytes
=
outputVideoFile
.
length
();
TransformationResult
result
=
new
TransformationResult
(
testId
,
outputSizeBytes
);
writeTransformationResultToFile
(
context
,
result
);
return
result
;
}
private
static
File
createExternalCacheFile
(
Context
context
,
String
filePrefix
)
private
static
void
writeTransformationResultToFile
(
Context
context
,
TransformationResult
result
)
throws
IOException
{
File
file
=
new
File
(
context
.
getExternalCacheDir
(),
filePrefix
+
"-output.mp4"
);
File
analysisFile
=
createExternalCacheFile
(
context
,
/* fileName= */
result
.
testId
+
"-result.txt"
);
FileWriter
fileWriter
=
new
FileWriter
(
analysisFile
);
String
fileContents
=
"test="
+
result
.
testId
+
", deviceBrand="
+
Build
.
MANUFACTURER
+
", deviceModel="
+
Build
.
MODEL
+
", sdkVersion="
+
Build
.
VERSION
.
SDK_INT
+
", outputSizeBytes="
+
result
.
outputSizeBytes
;
try
{
fileWriter
.
write
(
fileContents
);
}
finally
{
fileWriter
.
close
();
}
}
private
static
File
createExternalCacheFile
(
Context
context
,
String
fileName
)
throws
IOException
{
File
file
=
new
File
(
context
.
getExternalCacheDir
(),
fileName
);
Assertions
.
checkState
(
!
file
.
exists
()
||
file
.
delete
(),
"Could not delete
the previous transformer output file."
);
Assertions
.
checkState
(
file
.
createNewFile
(),
"Could not create
the transformer output file."
);
!
file
.
exists
()
||
file
.
delete
(),
"Could not delete
file: "
+
file
.
getAbsolutePath
()
);
Assertions
.
checkState
(
file
.
createNewFile
(),
"Could not create
file: "
+
file
.
getAbsolutePath
()
);
return
file
;
}
...
...
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