473 Commits

Author SHA1 Message Date
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
olly
e959af40f1 Add ContrastProcessor for contrast adjustments.
PiperOrigin-RevId: 462232813
(cherry picked from commit 714edc93be549f93194ad0a1d7e187c32b49d1e8)
2022-07-20 21:38:10 +00:00
samrobinson
8dbf6f9f0d Don't include case statement if it falls through to default.
PiperOrigin-RevId: 461888238
(cherry picked from commit 21016eaadfde74ba0e1e6acacc8f187cb4555974)
2022-07-19 15:25:58 +00:00
huangdarwin
82e1eda417 Only apply a MediaFormat-generated ColorInfo if it's valid.
Otherwise, invalid ColorInfo instances generated using faulty
MediaFormat#getInteger values could cause exceptions.

Confirmed that b/239435670 reproduces without this CL, and does not reproduce
with this CL.

PiperOrigin-RevId: 461862191
(cherry picked from commit 87198fe7f8df62a4b9087bc7f2c3cda237f789b2)
2022-07-19 13:00:02 +00:00
huangdarwin
54cdec4614 HDR: Use FP16 color representation for texture processors.
* Introduced `useHdr` for `GlEffect#toGlTextureProcessor`, so
  `TextureProcessor` implementations can decide how to handle HDR.
* Creating FP16 color textures for HDR input.

Tested via manual testing, adding a no-op GlEffectWrapper to the transformation to
force use of intermediate textures, adding a linear ramp to the fragment shader,
and trying to ascertain that there's a real reduction in posterization when
switching from 4-bit to 8-bit unsigned bytes, and again from 8-bit unsigned bytes
to 16-bit floating point.

PiperOrigin-RevId: 461613117
(cherry picked from commit ba9c9bb96471a9589d391ae498ebb0c194a5b41e)
2022-07-18 14:21:17 +00:00
huangdarwin
add44470cf HDR: Throw when unexpected color transfer encountered.
This may happen when a containers' color transfer incorrectly does not match
the video's color transfer.

An example of a file with such a mismatch is the current Transformer demo HDR10
sample file.

Manually tested by confirming that no errors are emitted for SDR and HLG sample
files, and that errors are emitted for our incorrect HDR10 sample file.

PiperOrigin-RevId: 461583532
(cherry picked from commit 9f7a159bc4c8a82653fdbb6d62e4f79b020cff06)
2022-07-18 11:20:31 +00:00
andrewlewis
04fa2fda2a Make minor fixes to HDR handling
- Update profile selection logic to pick an HDR-compatible profile when doing HDR editing on H.264/AVC videos.
- Handle doing the capabilities check for all MIME types that support HDR (not just H.265/HEVC).
- Fix a bug where we would pass an HDR input color format to the encoder when using tone-mapping.
- Tweak how `EncoderWrapper` works so decisions at made at construction time.

Manually tested cases:
- Transformation of an SDR video.
- Transformation of an HDR video to AVC (which triggers fallback/tone-mapping on a device that doesn't support HDR editing for AVC).
- Transformation of an HDR video with HDR editing.

PiperOrigin-RevId: 461572973
(cherry picked from commit 604ab7fcdaa759025536feb673a3abb93196a829)
2022-07-18 10:09:35 +00:00
samrobinson
ac2a5e56b0 Add additional video files.
These are providing more variety and complexity.

All files are okay to be public.

PiperOrigin-RevId: 460935247
(cherry picked from commit b87fa45fea56a50b5c035c7ca18eaf19697e60bf)
2022-07-14 12:27:05 +00:00
hschlueter
4e92c4260a Use COLOR_Format32bitABGR2101010 for HDR encoder configuration.
Also remove VideoEncoderSettings.colorProfile as there are no
concrete use cases for customizing this and it clashes with picking
the color format automatically based on SDR vs. HDR.

PiperOrigin-RevId: 460746987
(cherry picked from commit 7954eeb3c2fa274d9343cbf51963a3cccf3270c7)
2022-07-13 17:20:33 +00:00
samrobinson
00aea7519b Fix assertion error when using high quality targeting API.
Add test that verifies SSIM with API enabled.

#minor-release

PiperOrigin-RevId: 460692420
(cherry picked from commit f903869eb880508812c0dc2e1a8b01ecf0597f45)
2022-07-13 12:48:02 +00:00
samrobinson
9ae0f6c5c1 Clarify format is supported by encoder.
#cleanup
#minor-release

PiperOrigin-RevId: 460688226
(cherry picked from commit a88426ae58dc2ce31e1c4c0b7838f5e464107dcd)
2022-07-13 12:16:59 +00:00
claincly
4655b7b8f7 Fix a mis-match in encoder priority.
PiperOrigin-RevId: 460500666
(cherry picked from commit e56219f1f6ba4d3d3b7e579ba48c6a661761ee3f)
2022-07-12 17:43:55 +00:00
claincly
414be2ef5b Verified encoding performance, removing TODO.
PiperOrigin-RevId: 460459378
(cherry picked from commit 776c8a5544357bed1c92399f3ab47fc245c0b878)
2022-07-12 14:41:02 +00:00
hschlueter
2ea90e7abd Set ColorInfo in decoder configuration format.
Pass the color info and HDR static metadata when configuring the decoder
using MediaFormatUtil.maybeSetColorInfo.

PiperOrigin-RevId: 460424985
(cherry picked from commit 66e12299881b4edbfa60d1fe717a9b6016fac2a5)
2022-07-12 11:09:46 +00:00
hschlueter
fa08d8e219 HDR: Check whether EXT_YUV_target extension is supported.
This extension is needed for editing HDR input with OpenGL, as the
ExternalTextureProcessor samples raw YUV values from the
external texture for HDR and converts them to RGB itself rather than
relying on the OpenGL driver to do this automatically as for SDR.

PiperOrigin-RevId: 460424154
(cherry picked from commit a5ff4ef17f78b64735d82c6b16f0b69af5a570a3)
2022-07-12 11:04:05 +00:00
hschlueter
04ca9a2d38 Merge MatrixTransformationProcessor and ExternalTextureProcessor.
This saves an intermediate texture copy step for use-cases
where matrix transformations are the first or only effects
in the chain.

PiperOrigin-RevId: 460239403
(cherry picked from commit 7dc54efdb9c751aff14660fca38889ba2007e4d5)
2022-07-11 17:04:11 +00:00
claincly
627f26adef Apply priority/operating rate settings for video encoding.
- Added setter to disable this feature.
- Added accompanying tests.
- Plan to run tests on the same set of settings on H265.

PiperOrigin-RevId: 460238673
(cherry picked from commit 18f4068c06a27ceedce8ee951b3832235a96f75e)
2022-07-11 17:01:33 +00:00