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
01c24e4d
authored
Mar 30, 2022
by
samrobinson
Committed by
Ian Baker
Apr 06, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Move Json helper methods to AndroidTestUtil.
PiperOrigin-RevId: 438253138
parent
3ac7e0e8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
55 deletions
libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java
libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformationTestResult.java
libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerAndroidTestRunner.java
libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java
View file @
01c24e4d
...
...
@@ -18,8 +18,12 @@ package androidx.media3.transformer;
import
static
androidx
.
media3
.
common
.
util
.
Assertions
.
checkState
;
import
android.content.Context
;
import
android.os.Build
;
import
androidx.media3.common.util.Log
;
import
java.io.File
;
import
java.io.IOException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/** Utilities for instrumentation tests. */
public
final
class
AndroidTestUtil
{
...
...
@@ -44,5 +48,33 @@ public final class AndroidTestUtil {
return
file
;
}
/**
* Returns a {@link JSONObject} containing device specific details from {@link Build}, including
* manufacturer, model, SDK version and build fingerprint.
*/
public
static
JSONObject
getDeviceDetailsAsJsonObject
()
throws
JSONException
{
return
new
JSONObject
()
.
put
(
"manufacturer"
,
Build
.
MANUFACTURER
)
.
put
(
"model"
,
Build
.
MODEL
)
.
put
(
"sdkVersion"
,
Build
.
VERSION
.
SDK_INT
)
.
put
(
"fingerprint"
,
Build
.
FINGERPRINT
);
}
/**
* Converts an exception to a {@link JSONObject}.
*
* <p>If the exception is a {@link TransformationException}, {@code errorCode} is included.
*/
public
static
JSONObject
exceptionAsJsonObject
(
Exception
exception
)
throws
JSONException
{
JSONObject
exceptionJson
=
new
JSONObject
();
exceptionJson
.
put
(
"message"
,
exception
.
getMessage
());
exceptionJson
.
put
(
"type"
,
exception
.
getClass
());
if
(
exception
instanceof
TransformationException
)
{
exceptionJson
.
put
(
"errorCode"
,
((
TransformationException
)
exception
).
errorCode
);
}
exceptionJson
.
put
(
"stackTrace"
,
Log
.
getThrowableString
(
exception
));
return
exceptionJson
;
}
private
AndroidTestUtil
()
{}
}
libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformationTestResult.java
View file @
01c24e4d
...
...
@@ -17,6 +17,8 @@ package androidx.media3.transformer;
import
androidx.annotation.Nullable
;
import
androidx.media3.common.C
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/** A test only class for holding the details of a test transformation. */
public
class
TransformationTestResult
{
...
...
@@ -111,11 +113,38 @@ public class TransformationTestResult {
/** The SSIM score of the transformation, {@link #SSIM_UNSET} if unavailable. */
public
final
double
ssim
;
/**
* The {@link Exception} that was thrown during post-tranformation analysis, or {@code null} if
* The {@link Exception} that was thrown during post-tran
s
formation analysis, or {@code null} if
* nothing was thrown.
*/
@Nullable
public
final
Exception
analysisException
;
/** Returns a {@link JSONObject} representing all the values in {@code this}. */
public
JSONObject
asJsonObject
()
throws
JSONException
{
JSONObject
jsonObject
=
new
JSONObject
();
if
(
transformationResult
.
durationMs
!=
C
.
LENGTH_UNSET
)
{
jsonObject
.
put
(
"durationMs"
,
transformationResult
.
durationMs
);
}
if
(
transformationResult
.
fileSizeBytes
!=
C
.
LENGTH_UNSET
)
{
jsonObject
.
put
(
"fileSizeBytes"
,
transformationResult
.
fileSizeBytes
);
}
if
(
transformationResult
.
averageAudioBitrate
!=
C
.
RATE_UNSET_INT
)
{
jsonObject
.
put
(
"averageAudioBitrate"
,
transformationResult
.
averageAudioBitrate
);
}
if
(
transformationResult
.
averageVideoBitrate
!=
C
.
RATE_UNSET_INT
)
{
jsonObject
.
put
(
"averageVideoBitrate"
,
transformationResult
.
averageVideoBitrate
);
}
if
(
elapsedTimeMs
!=
C
.
TIME_UNSET
)
{
jsonObject
.
put
(
"elapsedTimeMs"
,
elapsedTimeMs
);
}
if
(
ssim
!=
TransformationTestResult
.
SSIM_UNSET
)
{
jsonObject
.
put
(
"ssim"
,
ssim
);
}
if
(
analysisException
!=
null
)
{
jsonObject
.
put
(
"analysisException"
,
AndroidTestUtil
.
exceptionAsJsonObject
(
analysisException
));
}
return
jsonObject
;
}
private
TransformationTestResult
(
TransformationResult
transformationResult
,
@Nullable
String
filePath
,
...
...
libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerAndroidTestRunner.java
View file @
01c24e4d
...
...
@@ -20,9 +20,7 @@ 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.media3.common.C
;
import
androidx.media3.common.MediaItem
;
import
androidx.media3.common.util.Log
;
import
androidx.media3.common.util.SystemClock
;
...
...
@@ -179,13 +177,13 @@ public class TransformerAndroidTestRunner {
resultJson
.
put
(
"inputValues"
,
JSONObject
.
wrap
(
inputValues
));
try
{
TransformationTestResult
transformationTestResult
=
runInternal
(
testId
,
uriString
);
resultJson
.
put
(
"transformationResult"
,
getTestResultJson
(
transformationTestResult
));
resultJson
.
put
(
"transformationResult"
,
transformationTestResult
.
asJsonObject
(
));
if
(!
suppressAnalysisExceptions
&&
transformationTestResult
.
analysisException
!=
null
)
{
throw
transformationTestResult
.
analysisException
;
}
return
transformationTestResult
;
}
catch
(
Exception
e
)
{
resultJson
.
put
(
"exception"
,
getExceptionJson
(
e
));
resultJson
.
put
(
"exception"
,
AndroidTestUtil
.
exceptionAsJsonObject
(
e
));
throw
e
;
}
finally
{
writeTestSummaryToFile
(
context
,
testId
,
resultJson
);
...
...
@@ -308,7 +306,7 @@ public class TransformerAndroidTestRunner {
private
static
void
writeTestSummaryToFile
(
Context
context
,
String
testId
,
JSONObject
resultJson
)
throws
IOException
,
JSONException
{
resultJson
.
put
(
"testId"
,
testId
).
put
(
"device"
,
getDeviceJson
());
resultJson
.
put
(
"testId"
,
testId
).
put
(
"device"
,
AndroidTestUtil
.
getDeviceDetailsAsJsonObject
());
String
analysisContents
=
resultJson
.
toString
(
/* indentSpaces= */
2
);
...
...
@@ -321,53 +319,4 @@ public class TransformerAndroidTestRunner {
fileWriter
.
write
(
analysisContents
);
}
}
private
static
JSONObject
getDeviceJson
()
throws
JSONException
{
return
new
JSONObject
()
.
put
(
"manufacturer"
,
Build
.
MANUFACTURER
)
.
put
(
"model"
,
Build
.
MODEL
)
.
put
(
"sdkVersion"
,
Build
.
VERSION
.
SDK_INT
)
.
put
(
"fingerprint"
,
Build
.
FINGERPRINT
);
}
private
static
JSONObject
getTestResultJson
(
TransformationTestResult
testResult
)
throws
JSONException
{
TransformationResult
transformationResult
=
testResult
.
transformationResult
;
JSONObject
transformationResultJson
=
new
JSONObject
();
if
(
transformationResult
.
durationMs
!=
C
.
LENGTH_UNSET
)
{
transformationResultJson
.
put
(
"durationMs"
,
transformationResult
.
durationMs
);
}
if
(
transformationResult
.
fileSizeBytes
!=
C
.
LENGTH_UNSET
)
{
transformationResultJson
.
put
(
"fileSizeBytes"
,
transformationResult
.
fileSizeBytes
);
}
if
(
transformationResult
.
averageAudioBitrate
!=
C
.
RATE_UNSET_INT
)
{
transformationResultJson
.
put
(
"averageAudioBitrate"
,
transformationResult
.
averageAudioBitrate
);
}
if
(
transformationResult
.
averageVideoBitrate
!=
C
.
RATE_UNSET_INT
)
{
transformationResultJson
.
put
(
"averageVideoBitrate"
,
transformationResult
.
averageVideoBitrate
);
}
if
(
testResult
.
elapsedTimeMs
!=
C
.
TIME_UNSET
)
{
transformationResultJson
.
put
(
"elapsedTimeMs"
,
testResult
.
elapsedTimeMs
);
}
if
(
testResult
.
ssim
!=
TransformationTestResult
.
SSIM_UNSET
)
{
transformationResultJson
.
put
(
"ssim"
,
testResult
.
ssim
);
}
if
(
testResult
.
analysisException
!=
null
)
{
transformationResultJson
.
put
(
"analysisException"
,
getExceptionJson
(
testResult
.
analysisException
));
}
return
transformationResultJson
;
}
private
static
JSONObject
getExceptionJson
(
Exception
exception
)
throws
JSONException
{
JSONObject
exceptionJson
=
new
JSONObject
();
exceptionJson
.
put
(
"message"
,
exception
.
getMessage
());
exceptionJson
.
put
(
"type"
,
exception
.
getClass
());
if
(
exception
instanceof
TransformationException
)
{
exceptionJson
.
put
(
"errorCode"
,
((
TransformationException
)
exception
).
errorCode
);
}
exceptionJson
.
put
(
"stackTrace"
,
Log
.
getThrowableString
(
exception
));
return
exceptionJson
;
}
}
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