439 Commits

Author SHA1 Message Date
samrobinson
c7cd3b9c91 Add support for skipping windows in MssimCalculator.
By skipping every other row and column, SSIM calculation time reduces by 10-30%.

PiperOrigin-RevId: 474286702
(cherry picked from commit 314b312af18c568c5353b661b31ebc60a0736678)
2022-09-14 14:35:12 +00:00
samrobinson
eeba63ab3e Add MssimCalculatorTest to verify SSIM calculations.
As part of this change, MssimCalculator is moved from androidTest/ to main/

PiperOrigin-RevId: 473771344
(cherry picked from commit 8ce42f0670504a89c5c3e546f8be3d849be36195)
2022-09-12 16:45:36 +00:00
samrobinson
8085fe22f5 Rollback of 3d5ddf0c42
*** Original commit ***

Handle int instead of byte in SSIM.

The value of pixels are converted to integers at the point of use,
move this logic to the initialisation step.

This is a prerequisite step for testing SSIM calculation, which
will lead on to some SSIM improvements being verifiable.

Tested manually and SSIM values match for the same video
before and after this change.

***

PiperOrigin-RevId: 473259446
(cherry picked from commit d188babd2daea5b737ef43604aa00baf157a2df5)
2022-09-09 15:33:08 +00:00
samrobinson
88584c311d Handle int instead of byte in SSIM.
The value of pixels are converted to integers at the point of use,
move this logic to the initialisation step.

This is a prerequisite step for testing SSIM calculation, which
will lead on to some SSIM improvements being verifiable.

Tested manually and SSIM values match for the same video
before and after this change.

PiperOrigin-RevId: 473231779
(cherry picked from commit 3d5ddf0c42f1d2b91d4ef33c75f59656c6e566bc)
2022-09-09 13:07:14 +00:00
huangdarwin
60737f66a6 Decoder: Reduce max pending frame count limit down to 5.
PiperOrigin-RevId: 473212543
(cherry picked from commit 4133bb6070fd1bb000958000d2d4b953cbfc0576)
2022-09-09 10:56:03 +00:00
huangdarwin
0a13578989 HDR: Add fallback MH tests.
Test that HDR editing succeeds on devices supporting HDR editing, tone maps on
devices supporting tone mapping, and throws exceptions on all other devices.

Also, only restrict HDR editing and tone mapping support to API 31+ only when
transcoding, not for all transformations.

PiperOrigin-RevId: 472958965
(cherry picked from commit 0d8fd3d4fc1da31c05fa82bb5e815332a6c7fa12)
2022-09-08 12:03:40 +00:00
claincly
1ded03ce13 Remove conditional check for no-longer flaky API version
PiperOrigin-RevId: 472949850
(cherry picked from commit 8b7638bed352ced64e176b068a6524141a3fbf5c)
2022-09-08 11:02:51 +00:00
claincly
17cc7b59b8 Remove redundant constant definition
PiperOrigin-RevId: 472522846
(cherry picked from commit c401fb9771454e48b2b7eddba281ddda0ca5e398)
2022-09-06 19:06:17 +00:00
claincly
18188ebe01 Include CamcorderProfile resolution in encoder capability test
PiperOrigin-RevId: 472459423
(cherry picked from commit 3f6a59f0f776e160aa88e69af69aa5749f594f2a)
2022-09-06 15:05:46 +00:00
huangdarwin
c4fa1978b8 Minor javadoc and scoping cleanup.
No functional changes.

PiperOrigin-RevId: 472245797
(cherry picked from commit fa1f09fc51ea7a54052562e6a40e48e55fed4a67)
2022-09-05 11:06:21 +00:00
huangdarwin
eac4829406 Rename shouldPassthrough to shouldTranscode
shouldPassthrough's internal checks seem to be check whether we should *not*
pass through, which seemed a bit like a confusing double-negative to me.

shouldTranscode is slightly more clear, by instead returning true when we do
want to transcode.

No functional changes intended.

PiperOrigin-RevId: 471753771
(cherry picked from commit 7085c2fa6e90834b7ace3b22b16d9f14f5e9eb66)
2022-09-02 09:49:26 +00:00
Googler
15f8e361b6 Skip transcoding if HDR video does not need encoding.
3b0d2c1586 made `shouldPassthrough` always return false for `enableHdrVideoEditing`:

>We force using `FrameEditor` (no passthrough) to avoid the need to select another edit operation, and use the new shaders. The `EGLContext` and `EGLSurface` also need to be set up differently for this path.

However, this was introduced before the `videoNeedsEncoding` setting was introduced in 3f615040c0. That setting should apply to HDR videos as much as SDR videos.

PiperOrigin-RevId: 471569853
(cherry picked from commit bc88f8be54b5c666d9ad591c04ac9faa4457454a)
2022-09-01 17:37:30 +00:00
ibaker
30e55ad772 Remove media3-only line from exoplayer2 build.gradle file
#minor-release

PiperOrigin-RevId: 470999044
(cherry picked from commit 932f0d2248d1779940c7d5e7cbb9c214222321c0)
2022-08-30 15:27:12 +00:00
andrewlewis
19fad593e5 Update color info mismatch test
This should now expect transformation to succeed.

PiperOrigin-RevId: 470950411
(cherry picked from commit daf1e5e2eb536d6f4fa6ccb2b7234d474bfcd248)
2022-08-30 11:02:46 +00:00
andrewlewis
f3adc5a5d2 Log instead of throwing for transfer mismatch
PiperOrigin-RevId: 470354448
(cherry picked from commit dbe66775518a02c138e138a990939729bd9a3b23)
2022-08-26 23:08:53 +00:00
Googler
373ac4c7bd Change onOutputFrameAvailable timestamp from nanos to micros.
Upstream timestamps from the decoder are also in microseconds,
so using microseconds here is consistent with that.

PiperOrigin-RevId: 468659099
(cherry picked from commit 0b1c540ff96b4f4f4ff7cff16a2e51674a42a0c2)
2022-08-19 09:47:28 +00:00
Googler
166838ae70 Allow frame release to be controlled outside FrameProcessor.
Adds a method to FrameProcessor.Listener to be called when an
output frame is available and a method releaseOutputFrame in
FrameProcessor allowing the caller to trigger release of the
oldest available output frame at a given timestamp. Late frames
or frames with unset release times are dropped in the
FinalMatrixTransformationProcessorWrapper.

More than one output frame can become available before they are
released if the penultimate GlTextureProcessor is capable of producing
multiple output frames. Processing continues while waiting for
releaseOutputFrame to be called. Frame release tasks are prioritized
over other tasks.

PiperOrigin-RevId: 468473072
(cherry picked from commit a5d7fdcab52ea6c12fa35efc348b69eccb53f715)
2022-08-18 16:10:48 +00:00
huangdarwin
da10c96229 HDR: Clarify tone mapping fallback.
createSupportedTransformationRequest is more accurate than
createFallbackTransformationRequest, as a TransformationRequest will be returned
regardless of whether any fallback is applied.

PiperOrigin-RevId: 466641277
(cherry picked from commit c5a5364673749cb737be3df92c9521fc15207658)
2022-08-10 11:25:56 +00:00
huangdarwin
f83753d4e0 HDR: Update experimental_setEnableHdrEditing javadoc.
Previously, this feature interpreted SDR signals as HDR when called. Now, only HDR
streams are interpreted as HDR, so the javadoc should be updated. Not yet removing
this method, as there are still some loose ends to finish up (ex. PQ support, e2e
tests).

PiperOrigin-RevId: 466425738
(cherry picked from commit 05fcda510a1dc8ab0a44487f3ddfff7fc2b617e7)
2022-08-09 18:56:08 +00:00
Googler
ccef3950ca Remove times(1) from effect and transformer tests as it is the default.
PiperOrigin-RevId: 466324322
(cherry picked from commit 1bdc252d2cfac5499306584fd68a2b1f33f05cc4)
2022-08-09 12:08:39 +00:00
huangdarwin
00749d9d26 HDR: Rename ColorInfo#isHdr to isTransferHdr.
While HDR is most closely tied to the color transfer (ex.
COLOR_TRANSFER_SDR is the only one explicitly mentioning dynamic
range), technically color spaces may be associated with HDR as well,
like BT.2020 commonly being used for HDR rather than BT.709 for SDR.

Therefore, it's more specific to mention just that the transfer is HDR.

PiperOrigin-RevId: 466316960
(cherry picked from commit 35161c748956d96e8e83cee007143615ef6f9d07)
2022-08-09 11:28:31 +00:00
huangdarwin
37274c91de HDR: Input ColorInfo to the FrameProcessor.
This allows the GlEffectsFrameProcessor to later handle HLG and PQ
differently, or limited and full color range differently.

No functional change intended in this CL.

PiperOrigin-RevId: 466070764
(cherry picked from commit 536d42c865fd692c1d1799082077906287a2c3f0)
2022-08-08 16:55:22 +00:00
andrewlewis
5385cc0422 Remove unused log tag constant
PiperOrigin-RevId: 466025324
(cherry picked from commit 2315a39f5240a422e915c4953d159db9eb439b27)
2022-08-08 13:20:34 +00:00
andrewlewis
08bbb79c21 Throw if tone-mapping is requested but not enabled
In the case where this check fails, the downstream frame processor chain won't be able to handle the incoming (SDR) data anyway as we've already set it up for HDR.

PiperOrigin-RevId: 465584814
(cherry picked from commit 2bd1a93d27fbc1615c55edb200917f5d5a1891b4)
2022-08-05 16:49:26 +00:00
andrewlewis
99202c5568 Clarify SSIM request method name
`requestCalculateSsim` more clearly represents the intention of the caller.

Also rephrase the javadoc to simplify it and make it more precise.

PiperOrigin-RevId: 465575578
(cherry picked from commit 2eb59fa1af823ff66fcf384f567a92e55c35b683)
2022-08-05 16:02:07 +00:00
andrewlewis
5dd796e14d Fix frame processor reference
PiperOrigin-RevId: 465562260
(cherry picked from commit 16a325217abf0b52eb103b86164000c1e93cb1b3)
2022-08-05 14:49:23 +00:00
huangdarwin
7eab760b18 HDR: Add comment to clarify lack of support HDR10 for AVC
PiperOrigin-RevId: 465360186
(cherry picked from commit 348662283a60c88e6c5a0deef9307da75161b241)
2022-08-04 18:18:18 +00:00
andrewlewis
f8aaed1ac7 Avoid encoder default color info when tone-mapping
The encoder color info [defaults](https://cs.android.com/android/platform/superproject/+/master:frameworks/av/media/libstagefright/foundation/ColorUtils.cpp;l=377;drc=891c19ccfa4953b5e5f7b87118e007b994d8074c) to a value that depends on the input resolution, but when tone-mapping is enabled we should always get BT.709 color space. Hard-code this constant for now to avoid behavior depending on the resolution. A future change should use the decoder output media format to populate the color info.

PiperOrigin-RevId: 465070378
(cherry picked from commit 3c4ee51e10fe0a2ea495f00a3fcd98d6cb83b561)
2022-08-03 16:06:45 +00:00
hschlueter
8b9203a3ea Move effects functionality out of transformer to effects module.
PiperOrigin-RevId: 465038852
(cherry picked from commit 22725ddfa8f5c39c83b792a176339700364b724e)
2022-08-03 13:19:15 +00:00
leonwind
2c4e946f71 Implement RGBA color matrices processor
* Transform frame colors using a defined RGBA Matrix to apply filters.

PiperOrigin-RevId: 464523581
(cherry picked from commit d15f2ed388e59e1b378440470347ee6f7f00ed94)
2022-08-01 13:47:21 +00:00
leonwind
1ef01adc74 Migrate Contrast asset to emulator generated one.
PiperOrigin-RevId: 464519030
(cherry picked from commit ae1915ea1acea1181198b71ae654830c7512337b)
2022-08-01 13:14:49 +00:00
huangdarwin
c34e41950b HDR: Have @C.ColorTransfer check consider NO_VALUE as SDR.
Format.NO_VALUE is a placeholder value for an invalid @C.ColorTransfer, used
for example when the decoder doesn't support this transfer function.

When encountering this invalid value, interpret this as COLOR_TRANSFER_SDR.

Confirmed locally that an exception is thrown when transcoding on p4head, and no exception is thrown when transcoding with this CL.

PiperOrigin-RevId: 464135080
(cherry picked from commit 687a50e9b313e5db37a0b32f5f40559252ab6031)
2022-07-29 19:33:44 +00:00
hschlueter
de4c2e08e1 Move FrameProcessor and related interfaces to common.
This will allow effects preview in ExoPlayer to use the
Effect and FrameProcessor interface (and the interfaces
they depend on) without depending on transformer or the
future effects module.

PiperOrigin-RevId: 464060047
(cherry picked from commit 480c129c54777780f298d7e5dbd9fa23a371f660)
2022-07-29 12:54:30 +00:00
huangdarwin
071f0a5a0d Transformer: Improve misc javadocs and exception logs.
PiperOrigin-RevId: 463971447
(cherry picked from commit 534740fd46f5ec9465215eaaa03a764eebab4ac4)
2022-07-29 01:16:26 +00:00
huangdarwin
db1cad911c HDR: Centralize getting Colorinfo from MediaFormat
* Sets KEY_HDR_STATIC_INFO from MediaFormat in the DefaultCodec.
* Adds checks in mediaparser to ensure color space, range, and transfer are valid
  values.

PiperOrigin-RevId: 463921325
(cherry picked from commit 65a2a3a0a073c6dd8b47a044609f4be1abdd19c9)
2022-07-28 21:07:43 +00:00
hschlueter
427a7a1ff9 Generalize frame processing error codes.
TransformationException error codes were previously tied to OpenGL
but other FrameProcessor implementations are possible. So this CL
renames the error codes.
Also, remove GL_INIT_FAILED error code, as FrameProcessor
implemenations may initialize resources on a background thread
after the factory method returns, so it's not obvious how to
distinguish between initialization failures and processing failures.

PiperOrigin-RevId: 463704902
(cherry picked from commit 0f96d8615d28cf50f3efa0c34fb31e01fa0d491c)
2022-07-27 23:21:31 +00:00
hschlueter
6e390771a0 Add Effect marker interface.
This allows non-GL effects to be passed to custom FrameProcessor
implementations.

PiperOrigin-RevId: 463696384
(cherry picked from commit 580e44fc47ec5b62da5a133d12048a20d716e94f)
2022-07-27 22:40:20 +00:00
hschlueter
49a6511696 Remove redundant interface from FinalMatrixTPWrapper.
PiperOrigin-RevId: 463646211
(cherry picked from commit b28fb139988f54d1446df7426d508de34695299f)
2022-07-27 19:08:58 +00:00
hschlueter
309fd907b1 Make FrameInfo and SurfaceInfo public.
Both are used in the public FrameProcessor interface, so they
should be public too.

PiperOrigin-RevId: 463454859
(cherry picked from commit b1b9ba825f83030c5d5b0617796176f21526dc2e)
2022-07-26 23:34:30 +00:00
samrobinson
8aa4281dfa Add 8 new videos, representing lower resolutions.
Downsampled from 3840x2160 resolution videos using ffmpeg:

`ffmpeg -i <inputFilename> -filter:v scale=<width>:<height> -c:a copy <outputFilename>`

PiperOrigin-RevId: 463454628
(cherry picked from commit 56e50b63ec30ed514f8b2fc62f54251dd4df61dc)
2022-07-26 23:33:10 +00:00
samrobinson
6ccf46d40e Add H265 as a parameter to SsimMapperTest.
PiperOrigin-RevId: 463452893
(cherry picked from commit 60d6654b8d2932dcadb49f77d726f05b377f828e)
2022-07-26 23:24:03 +00:00
leonwind
6cf0737e00 Rename ContrastProcessorPixelTest and make contexts final
PiperOrigin-RevId: 463450395
(cherry picked from commit 302a742c944b002379759ed05f121aaeab8af396)
2022-07-26 23:10:33 +00:00
samrobinson
b68412a1f7 Add an SsimMapperTest, which binary searches for 95% ssim.
This is possible because SSIM increases monotonically with bitrate.

PiperOrigin-RevId: 463434373
(cherry picked from commit 4a0b07b4f7e577d02b6d36f49da2c9f5d0b2e485)
2022-07-26 21:56:33 +00:00
huangdarwin
df741a8baa Rename findEncoderWithClosestFormatSupport.
Just a misc nit, since I found the name a bit confusing, and figured
findEncoderWithClosestSupportedFormat might be more descriptive.

PiperOrigin-RevId: 463433646
(cherry picked from commit a7a17dc2bb8bd76988ae32867ff1b8109fcccdb5)
2022-07-26 21:53:18 +00:00
hschlueter
dfe60dad87 Allow FrameProcessor.Factory to be set on Transformer.Builder.
Extract a FrameProcessor.Factory interface from GlEffectsFrameProcessor
and allow it to  be customized using a setter on Transformer.Builder.

PiperOrigin-RevId: 463433438
(cherry picked from commit 22822d8e194cedb89bd01fac89a131f145c5042b)
2022-07-26 21:52:30 +00:00
hschlueter
4001e699a1 Replace Size with Pair in effects.
Size requires API 21. Using Pair instead will allow effects to be
used from API 18 during previewing once they are moved out of
transformer.

PiperOrigin-RevId: 463206474
(cherry picked from commit 4adf19939839baa3eaf018fef0d1b58049fd3b91)
2022-07-25 23:39:59 +00:00
hschlueter
bb7db5a13c Only recreate output EGLSurface when Surface changed.
PiperOrigin-RevId: 463193768
(cherry picked from commit 5db7778ca322676a6e6445c473184dc1055d4c22)
2022-07-25 22:38:28 +00:00
hschlueter
9eeb4bc272 Allow stream offset passed to GlEffectsFrameProcessor to change.
This is needed for applying effects to a playlist.

The effects are applied based on the presentation time of the
frame in its corresponding media item and the offset is added
back before encoding.

Each time the offset changes, end of input stream is signalled
to the texture processors. This is needed because the texture
processors can expect monotonically increasing timestamp within
the same input stream but when the offset changes, the timstamps
jump back to 0.

PiperOrigin-RevId: 462714966
(cherry picked from commit 30e5bc9837e2423cd2bb426c5797211e0f6ad76b)
2022-07-22 22:18:55 +00:00
ibaker
878279425b Annotate methods that always return this with @CanIgnoreReturnValue
It's always safe to ignore the result of these methods, because the
caller already has a reference to the returned value.

PiperOrigin-RevId: 462388947
(cherry picked from commit 2deb435625c7569cb0bd250848adaa846884dc50)
2022-07-21 15:24:07 +00:00
huangdarwin
06d3c07a1c HDR: Implement HLG EOTF and OETF.
This allows us to use BT.2020 RGB linear for intermediate shaders, which also
allows us to re-enable PeriodicVignetteProcessor, which should work properly in
linear color-spaces.

Manually tested by adding a GlEffectsWrapper, and confirming that HLG HDR editing still looks correct.

PiperOrigin-RevId: 462265821
(cherry picked from commit 2f977eeec93be5cc71fda57f80362c1bc639c041)
2022-07-21 00:24:41 +00:00