529 Commits

Author SHA1 Message Date
andrewlewis
179eafb247 Log instead of throwing for transfer mismatch
PiperOrigin-RevId: 470354448
(cherry picked from commit f1a3a40eb1d8a640fed0d7735088a30d00038234)
2022-08-26 23:08:53 +00:00
Googler
60d3e8e26b 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 4e7f9c575d9ff003f1cc4d4a9f464c6df6b4077a)
2022-08-19 09:47:28 +00:00
Googler
884e37633e 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 2c063546a1ac8607eb4632acb88506b9a0d46b9e)
2022-08-18 16:10:48 +00:00
huangdarwin
3e4ca2c981 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 70972bbab0c884bcc2ef1dfef2177967499c36b6)
2022-08-10 11:25:56 +00:00
huangdarwin
dee5c56475 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 2d2926b8c0b4cded25616558ed74cb30cc2932fd)
2022-08-09 18:56:08 +00:00
Googler
f18e0f8287 Remove times(1) from effect and transformer tests as it is the default.
PiperOrigin-RevId: 466324322
(cherry picked from commit 95a7dcaedaf617802054e37acdb3d46d4923ccac)
2022-08-09 12:08:39 +00:00
huangdarwin
c0bef3dbf7 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 7075f78eb26daef44275a6fde5362d5139e6df37)
2022-08-09 11:28:31 +00:00
huangdarwin
2503c0ee95 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 e444eaa5b76074bbf77a6cab6dfe288665a20204)
2022-08-08 16:55:22 +00:00
andrewlewis
dfc04d8ddf Remove unused log tag constant
PiperOrigin-RevId: 466025324
(cherry picked from commit 273cf0866aad78018da3674ba1cbe11187d16afd)
2022-08-08 13:20:34 +00:00
andrewlewis
01a4188d68 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 0e99d28a79ddca5ba9517ffba73d2c36fc2679a7)
2022-08-05 16:49:26 +00:00
andrewlewis
1db2c74fb3 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 d90d7d30789ec819d905fd98291f66ab7031f47b)
2022-08-05 16:02:07 +00:00
andrewlewis
a0efd08b39 Fix frame processor reference
PiperOrigin-RevId: 465562260
(cherry picked from commit aafa31e996f30daebec12f5e9e61aab1dbd0ba81)
2022-08-05 14:49:23 +00:00
huangdarwin
acf40801cf HDR: Add comment to clarify lack of support HDR10 for AVC
PiperOrigin-RevId: 465360186
(cherry picked from commit e63d594f490da6461bc5087d0526c5ca5215958d)
2022-08-04 18:18:18 +00:00
andrewlewis
dce7c45cf0 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 40a28d5aeeb5f3c22e884690128182b68a9929f6)
2022-08-03 16:06:45 +00:00
Googler
89a2685052 Move effects functionality out of transformer to effects module.
PiperOrigin-RevId: 465038852
(cherry picked from commit 707b0618384db17f6d9d4947a445c0eed1c9c630)
2022-08-03 13:19:15 +00:00
leonwind
5668c8a6a9 Implement RGBA color matrices processor
* Transform frame colors using a defined RGBA Matrix to apply filters.

PiperOrigin-RevId: 464523581
(cherry picked from commit 23f34f8d08855645b342a75b0adfc6c0d600c0ab)
2022-08-01 13:47:21 +00:00
leonwind
d354cd597b Migrate Contrast asset to emulator generated one.
PiperOrigin-RevId: 464519030
(cherry picked from commit ea213545e0ed3ae2ae7168a0c4ac791d95b594aa)
2022-08-01 13:14:49 +00:00
huangdarwin
153535a300 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 1a22bcf1e59c1f8e1f8d1fb9d9208a916c92bdb2)
2022-07-29 19:33:44 +00:00
Googler
63db89793a 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 06d41c2775137158f831a1b2f19f137efb1e08b0)
2022-07-29 12:54:30 +00:00
huangdarwin
c09dccc8b0 Transformer: Improve misc javadocs and exception logs.
PiperOrigin-RevId: 463971447
(cherry picked from commit 810f451ec6ac83311f5ae902aba12428877bd809)
2022-07-29 01:16:26 +00:00
huangdarwin
6a3d7f6079 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 44c42fef2aaa65ba78c52883e3fcec94c8d7ad2d)
2022-07-28 21:07:43 +00:00
Googler
44de468f63 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 bac323d346c1d3118a0b904caf9926ecb96b912d)
2022-07-27 23:21:31 +00:00
Googler
5c7dcf42a0 Add Effect marker interface.
This allows non-GL effects to be passed to custom FrameProcessor
implementations.

PiperOrigin-RevId: 463696384
(cherry picked from commit 66dde42989dbc8fedeee59897a05644d86240cf6)
2022-07-27 22:40:20 +00:00
Googler
3fa0ce7faf Remove redundant interface from FinalMatrixTPWrapper.
PiperOrigin-RevId: 463646211
(cherry picked from commit 77f41d6fd4640e392fd04372d417050c3dc011da)
2022-07-27 19:08:58 +00:00
Googler
e674df7f12 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 40e96d1534d34312611d8c603b1b7c92e3250938)
2022-07-26 23:34:30 +00:00
samrobinson
6e8e648ae3 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 5f1ee86eb4655459ed0a8a706aeb44b8eeb9a46a)
2022-07-26 23:33:10 +00:00
samrobinson
127ad8c1ad Add H265 as a parameter to SsimMapperTest.
PiperOrigin-RevId: 463452893
(cherry picked from commit e1b6ed325244d906ac1aadd83517ac58dbc1e80d)
2022-07-26 23:24:03 +00:00
leonwind
65e040afb7 Rename ContrastProcessorPixelTest and make contexts final
PiperOrigin-RevId: 463450395
(cherry picked from commit 03ff5246e79b51e08b22b353138852813bd0dbd9)
2022-07-26 23:10:33 +00:00
samrobinson
de5bd046fd 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 63cddc901028434a9a565a0a8c605b46f223e724)
2022-07-26 21:56:33 +00:00
huangdarwin
abe4b23967 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 324fc5d7e88d9e4fdb1ecc7e70106d641f8236ec)
2022-07-26 21:53:18 +00:00
Googler
d8a47769b0 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 ecbe9a502cf62c92005a2ff045ab17988ea2838f)
2022-07-26 21:52:30 +00:00
Googler
3483131a88 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 b994f8bfa06c82fbfe96044b986cd7b8d243acdd)
2022-07-25 23:39:59 +00:00
Googler
5ebc3dbe3b Only recreate output EGLSurface when Surface changed.
PiperOrigin-RevId: 463193768
(cherry picked from commit 4ac177c3379d673335d64df7f47890e04bfbfd7a)
2022-07-25 22:38:28 +00:00
hschlueter
b9f6df79cb 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 46ab06b816d93c2a034c182552fa4483a6d82cba)
2022-07-22 23:18:55 +01:00
ibaker
57dbf22bfd 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 21cab6124de7b65f1af016cfc260555fa0b6e738)
2022-07-21 16:24:07 +01:00
huangdarwin
83bebd3339 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 1ecf1eb7bfdd469fe855edf6126b2822b52ff07f)
2022-07-21 00:24:41 +00:00
olly
8a848db2fb Add ContrastProcessor for contrast adjustments.
PiperOrigin-RevId: 462232813
(cherry picked from commit 7ef41c73218ec70ee9a5c372369d308273fddd8b)
2022-07-20 21:38:10 +00:00
samrobinson
d63f167dae Don't include case statement if it falls through to default.
PiperOrigin-RevId: 461888238
(cherry picked from commit 42f2e1440b91529fccc104908d662eff5552b743)
2022-07-19 15:25:58 +00:00
huangdarwin
865311d569 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 5533ad1713bd0dc64a6fba485dbbfeb35e177523)
2022-07-19 13:00:02 +00:00
huangdarwin
76093e25db 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 f67c1a73f443f411771676b761ceb03e7a0d48e4)
2022-07-18 14:21:17 +00:00
huangdarwin
7d14750948 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 fd046bd2f63888f8a47c37a426c10212a56be6e0)
2022-07-18 11:20:31 +00:00
andrewlewis
0e15689175 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 0db07c6791620d06db9f524bf0f47e90df635756)
2022-07-18 10:09:35 +00:00
samrobinson
95c84e55bc 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 d4653c335e2bafa79cc590101bf32481e04b1bcd)
2022-07-14 12:27:05 +00:00
hschlueter
79e75cc672 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 db78a87fdcb095fa6520f3c1bd8b5b419d33de50)
2022-07-13 17:20:33 +00:00
samrobinson
bb56c0129d 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 6ec18c8a208842eeb178f97e0680770b2e2a8b29)
2022-07-13 12:48:02 +00:00
samrobinson
66d86d6050 Clarify format is supported by encoder.
#cleanup
#minor-release

PiperOrigin-RevId: 460688226
(cherry picked from commit e0b46ece4e10cd0a9400669f8b30c3555205085d)
2022-07-13 12:16:59 +00:00
claincly
82bc3b19e6 Fix a mis-match in encoder priority.
PiperOrigin-RevId: 460500666
(cherry picked from commit fa55078641a15af90113be71a72526748663e3dc)
2022-07-12 17:43:55 +00:00
claincly
88658df3f6 Verified encoding performance, removing TODO.
PiperOrigin-RevId: 460459378
(cherry picked from commit 4068833541e8be4e94f60bf88d62b0f6a829f9f0)
2022-07-12 14:41:02 +00:00
hschlueter
06ecfb9123 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 46cd92ac1d80b2e651aa0ac2403e6d52d9c1d767)
2022-07-12 11:09:46 +00:00
hschlueter
b34aad7033 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 413016f7efea9dbb1194558374d9b9a8777a0d8c)
2022-07-12 11:04:05 +00:00