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
0770d55c
authored
Mar 08, 2022
by
samrobinson
Committed by
Ian Baker
Mar 09, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Nit cleanup of SsimHelper.
PiperOrigin-RevId: 433174767
parent
20282151
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
17 deletions
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/SsimHelper.java
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/SsimHelper.java
View file @
0770d55c
...
@@ -93,7 +93,7 @@ public final class SsimHelper {
...
@@ -93,7 +93,7 @@ public final class SsimHelper {
public
static
double
calculate
(
Context
context
,
String
expectedVideoPath
,
String
actualVideoPath
)
public
static
double
calculate
(
Context
context
,
String
expectedVideoPath
,
String
actualVideoPath
)
throws
IOException
,
InterruptedException
{
throws
IOException
,
InterruptedException
{
return
new
SsimHelper
(
context
,
expectedVideoPath
,
actualVideoPath
,
DEFAULT_COMPARISON_INTERVAL
)
return
new
SsimHelper
(
context
,
expectedVideoPath
,
actualVideoPath
,
DEFAULT_COMPARISON_INTERVAL
)
.
startCalculation
();
.
calculateSsim
();
}
}
private
SsimHelper
(
private
SsimHelper
(
...
@@ -108,12 +108,10 @@ public final class SsimHelper {
...
@@ -108,12 +108,10 @@ public final class SsimHelper {
this
.
height
=
new
AtomicInteger
(
Format
.
NO_VALUE
);
this
.
height
=
new
AtomicInteger
(
Format
.
NO_VALUE
);
}
}
void
ensureDecoderWrappersAreCreated
()
throws
IOException
{
/** Calculates the SSIM score between the two videos. */
if
(
expectedDecodingWrapper
!=
null
||
actualDecodingWrapper
!=
null
)
{
private
double
calculateSsim
()
throws
InterruptedException
,
IOException
{
return
;
// The test thread has no looper, so a handler is created on which the
}
// ImageReader.OnImageAvailableListener is called.
// This constructor is executed on the test thread, which does not have a looper attached.
// Creates a handler on which the ImageReader.onImageAvailableListener is called.
Handler
mainThreadHandler
=
Util
.
createHandlerForCurrentOrMainLooper
();
Handler
mainThreadHandler
=
Util
.
createHandlerForCurrentOrMainLooper
();
ImageReader
.
OnImageAvailableListener
onImageAvailableListener
=
this
::
onImageAvailableListener
;
ImageReader
.
OnImageAvailableListener
onImageAvailableListener
=
this
::
onImageAvailableListener
;
expectedDecodingWrapper
=
expectedDecodingWrapper
=
...
@@ -130,13 +128,7 @@ public final class SsimHelper {
...
@@ -130,13 +128,7 @@ public final class SsimHelper {
onImageAvailableListener
,
onImageAvailableListener
,
mainThreadHandler
,
mainThreadHandler
,
comparisonInterval
);
comparisonInterval
);
}
/** Returns the SSIM score between the two videos. */
private
double
startCalculation
()
throws
InterruptedException
,
IOException
{
ensureDecoderWrappersAreCreated
();
checkStateNotNull
(
expectedDecodingWrapper
);
checkStateNotNull
(
actualDecodingWrapper
);
try
{
try
{
while
(!
expectedDecodingWrapper
.
hasEnded
()
&&
!
actualDecodingWrapper
.
hasEnded
())
{
while
(!
expectedDecodingWrapper
.
hasEnded
()
&&
!
actualDecodingWrapper
.
hasEnded
())
{
if
(!
expectedDecodingWrapper
.
runUntilComparisonFrameOrEnded
()
if
(!
expectedDecodingWrapper
.
runUntilComparisonFrameOrEnded
()
...
@@ -161,13 +153,14 @@ public final class SsimHelper {
...
@@ -161,13 +153,14 @@ public final class SsimHelper {
expectedLumaBuffer
.
set
(
EMPTY_BUFFER
);
expectedLumaBuffer
.
set
(
EMPTY_BUFFER
);
actualLumaBuffer
.
set
(
EMPTY_BUFFER
);
actualLumaBuffer
.
set
(
EMPTY_BUFFER
);
}
}
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
throw
e
;
}
finally
{
}
finally
{
expectedDecodingWrapper
.
close
();
expectedDecodingWrapper
.
close
();
actualDecodingWrapper
.
close
();
actualDecodingWrapper
.
close
();
}
}
if
(
comparedImagesCount
==
0
)
{
throw
new
IOException
(
"Input had no frames."
);
}
return
accumulatedSsim
/
comparedImagesCount
;
return
accumulatedSsim
/
comparedImagesCount
;
}
}
...
@@ -303,7 +296,7 @@ public final class SsimHelper {
...
@@ -303,7 +296,7 @@ public final class SsimHelper {
* @return {@code true} when a comparison frame is encountered, or {@code false} if decoding
* @return {@code true} when a comparison frame is encountered, or {@code false} if decoding
* {@link #hasEnded() had ended}.
* {@link #hasEnded() had ended}.
*/
*/
public
boolean
runUntilComparisonFrameOrEnded
()
throws
InterruptedException
{
public
boolean
runUntilComparisonFrameOrEnded
()
{
while
(!
hasEnded
()
&&
!
isCurrentFrameComparisonFrame
)
{
while
(!
hasEnded
()
&&
!
isCurrentFrameComparisonFrame
)
{
while
(
dequeueOneFrameFromDecoder
())
{}
while
(
dequeueOneFrameFromDecoder
())
{}
while
(
queueOneFrameToEncoder
())
{}
while
(
queueOneFrameToEncoder
())
{}
...
...
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