60 Commits

Author SHA1 Message Date
claincly
be7bb0eea4 Add GL utility methods to get 4x4 identity and set identity
PiperOrigin-RevId: 483671580
2022-10-31 11:33:30 +00:00
huangdarwin
bb215857e5 HDR: Support RGBA_1010102 in GlUtil as a parameter.
Make it easier to support use of RGBA_101012 rather than RGBA_8888 for EGL
contexts, displays, and surfaces.

This tangentially supports adding HDR tests, by slightly simplifying the color
selection logic we'd have to add in HDR tests.

PiperOrigin-RevId: 482219428
2022-10-24 10:43:40 +00:00
huangdarwin
e39826a8db Effect: Remove unnecessary "this" qualifier
`transformationMatrix` is not ambiguous, as there's no other local
transformationMatrix variable nearby.

PiperOrigin-RevId: 482184602
2022-10-24 10:40:53 +00:00
huangdarwin
cce79a7040 Test: Update MatrixProcessorPixelTest to use input width and height.
Before, they used `width` and `height`, which was inconsistent with other pixel tests, and less descriptive.

Refactoring change only. No functional change intended.

PiperOrigin-RevId: 481970243
2022-10-24 10:36:09 +00:00
huangdarwin
f9724e9fb6 Effect: Remove unused private int ouptutTexId in pixel tests.
PiperOrigin-RevId: 481143798
2022-10-17 16:01:32 +00:00
claincly
a426cb27c0 Remove late frame dropping in FrameProcessor
Currently, a frame is dropped if it's requested release time is in the past.
This mode was added to support previewing. However, in normal ExoPlayer
playback, slightly late frames (<30ms late) are also rendered. On MediaCodec
side, this means calling `releaseOutputBuffer` with a release time in the
past.

PiperOrigin-RevId: 479615291
2022-10-17 15:41:25 +00:00
claincly
26be9ae885 Add a FrameProcessor flag to drop the processed frame
This mode is supported by using `C.TIME_UNSET` (which is a negative value). The
new logic decouples the value of `C.TIME_UNSET` and the frame dropping
behaviour.

PiperOrigin-RevId: 479368880
2022-10-17 15:36:29 +00:00
claincly
139a6e8d31 Add FrameProcessor functionality to release a frame immediately
Currently `FrameProcessor.releaseOutputFrame()` method supports

Release at a specific system time
Drops the frame
This API is not that convenient to use when the caller wants to release a frame, now, regardless of the release time. A use case is to release (present) a frame when no frame is shown for a while, and it's thus better to just release the frame, now.

Currently if MCVR wants a frame to be rendered now, MCVR calls release frame with a set offset like 10us: `releaseOutputFrame(System.nanoTime() + 10_000)`. The 10us offset is to prevent the frame processor dropping the frame, due to thread hopping delays.

To make the API better usable, consider adding a mode for releasing the frame now, like (bold marks the new mode)

- Use C.TIME_UNSET to drop
- **Use -1 to release the frame immediately, or**
- Use an actual release time.

PiperOrigin-RevId: 479044215
2022-10-17 15:31:34 +00:00
huangdarwin
d5c272fde8 Tests: Statically import BitmapTestUtil methods.
Per go/java-practices/imports#static

No functional changes intended.

PiperOrigin-RevId: 477974779
2022-09-30 18:32:50 +00:00
huangdarwin
62b95a7190 Test: Rename to avoid redundant substrings.
Rename test files to avoid substrings that can be implied by the directory name,
like "Transformation" and "Test"

No functional changes. Renaming-only.

PiperOrigin-RevId: 477724724
2022-09-30 18:31:56 +00:00
huangdarwin
16dca1828c HDR: Update gamma comments to linear.
Comment-only change.

PiperOrigin-RevId: 476873286
2022-09-30 18:20:18 +00:00
leonwind
44b9aec0b9 Store LUT bitmap as texture with processor creation.
* Before this CL, the texture was stored during the construction of the LUT processor. This failed since if one creates a list of GlEffects on the application thread, the texture will get stored in the application thread during the effect creation and not on the GL thread, which executes the FrameProcessors.
* This is an issue since the executing thread then can't index from the texture stored on a different thread.

PiperOrigin-RevId: 476388021
2022-09-30 18:16:33 +00:00
leonwind
7eb0ce623b Remove TODOs for merging RGB and MatrixTransformation processors.
PiperOrigin-RevId: 476362571
2022-09-30 18:12:29 +00:00
huangdarwin
87fd51a39b HDR: Assert output C.ColorTransfer for tests.
To confirm that tone mapping did or did not happen.

PiperOrigin-RevId: 476354606
2022-09-30 18:10:25 +00:00
leonwind
dc9fa4f463 Add HSL Adjustments to the effects module.
PiperOrigin-RevId: 476144167
2022-09-30 18:09:26 +00:00
leonwind
3433758c3b Add OETF and EOTF ES2 fragment shaders for non-HDR frames.
* Transform the intermediate color space to linear SDR by applying the SMPTE 170M EOTF and OETF.
* Use linear colors for the color filter pixel tests and update all golden bitmaps.

PiperOrigin-RevId: 476124592
2022-09-30 18:08:30 +00:00
leonwind
f00e43cf81 Use golden bitmaps in contrast pixel tests.
PiperOrigin-RevId: 475805421
2022-09-30 18:04:10 +00:00
leonwind
f55a5146e0 Add LUT functionalities to transformer.
* Adds SDR 3D LUT functionalities with OpenGL 2.0 support.

PiperOrigin-RevId: 474561060
2022-09-30 17:59:58 +00:00
leonwind
ab6562e052 Fix testId and match it to the test name.
PiperOrigin-RevId: 474363545
2022-09-30 17:59:00 +00:00
leonwind
60ea64734b Change ContrastProcessor java doc for consistency.
PiperOrigin-RevId: 474002026
2022-09-30 17:55:20 +00:00
leonwind
7a460fa3bd Add java docs for ContrastProcessor constructor.
* Add docs for the public constructor for consistency with all the
other frame processors.

PiperOrigin-RevId: 473726586
2022-09-30 17:53:26 +00:00
leonwind
10cb5f17e0 Add rgb matrices to java docs for public constructors.
PiperOrigin-RevId: 473699927
2022-09-30 17:52:28 +00:00
claincly
7f42e19f09 Split decoding out of the test
This method is useful for other tests also.

PiperOrigin-RevId: 473574282
2022-09-30 17:51:31 +00:00
leonwind
5c78444bf8 Rename MatrixTransformationProcessor to MatrixTextureProcessor.
PiperOrigin-RevId: 473283967
2022-09-30 17:50:33 +00:00
leonwind
55afa598e7 Add caching for compositeRgbMatrixArray.
* Refactor caching for matrix transformations to reuse it for rgb matrices.

PiperOrigin-RevId: 473042194
2022-09-30 17:45:37 +00:00
claincly
5e2823bb1e Clarify GlTextureProcessor.InputListener contract
PiperOrigin-RevId: 472745311
2022-09-30 17:40:55 +00:00
leonwind
5b556b3c33 Make MatrixTransformationsProcessor constructor to take in Lists.
* Replace ImmutableLists to List interface for constructors

PiperOrigin-RevId: 472433434
2022-09-30 17:30:41 +00:00
leonwind
91e1209e82 Use super class for toGlProcessor in RgbFilter.
PiperOrigin-RevId: 472405147
2022-09-30 17:29:42 +00:00
leonwind
672405afdf Merge RgbProcessor and MatrixTransformation.
PiperOrigin-RevId: 472325145
2022-09-30 17:28:47 +00:00
huangdarwin
1b6482960e HDR: Use factory for MatrixTransformationProcessor.
Separate MatrixTransformationProcessor constructors by color input and output.

PiperOrigin-RevId: 471034768
2022-09-30 17:14:44 +00:00
leonwind
8595042302 Add static Grayscale and Inverted RGB Filter.
PiperOrigin-RevId: 471017440
2022-09-30 17:12:33 +00:00
claincly
91709831ed Fix ExternalTextureManager: repeated queueing input frame in preview
TL;DR: we should check if there are new frames available to queue to the
ExternalTextureProcessor before actually queueing a frame.

The overall flow on the external texture processor:

- `SurfaceTexture.onFrameAvailable` is called on `ExtTexMgr`, and
  - it calls `updateTexImage()`, and sets `frame`
  - it calls `maybeQueueFrameToExtTexProc()`
    - the frame is queued to `ExtTexProc` if `frame` is set

  - From `ExtTexProc.queueInputFrame()`:
    - notifies the `frameProcessorListener` of available frame
    - notifies the `inputListener` of `onReadyToAcceptInputFrame`
      - (`ExtTexMgr` is the listener), it calls `maybeQueueFrameToExtTexProc()`
       again

-- Parallelly --
- `ExtTexProc` calls `inputListener.onInputFrameProcessed`, when the frame is
released
  - (`ExtTexMgr` is the listener), sets `frame` to `null`

*Problem*

This logic relies on `frame` to be cleared at the right time.

In transformer, it's OK b/c `ExtTexProc` release the frame immediately in
`queueInputFrame()` and calls `onInputFrameProcessed` which also reset `frame`

But in previewing, the frame is not released for a while, up to 10 ms.
In this case, `frame` will not reset in this 10 ms, and
`maybeQueueFrameToExtTexProc()` is repeatedly queueing the same input frame.

PiperOrigin-RevId: 470211620
2022-09-30 17:06:21 +00:00
leonwind
a7d3752c66 Delete glPrograms in Contrast and RgbMatrix.
Remove unecessary null checks.

PiperOrigin-RevId: 469999952
2022-09-30 17:03:27 +00:00
huangdarwin
2a05a50403 HDR: Rename GL_COLOR_TRANSFER instances to COLOR_TRANSFER
PiperOrigin-RevId: 469959215
2022-09-30 17:02:27 +00:00
huangdarwin
2ad07e88ee HDR: Add PQ support.
Use the PQ OETF and EOTF to ensure that intermediate fragment shader operations
using PQ are in linear BT.2020 rather than PQ and HLG-1 BT.2020.

Also, swap the OETF and EOTF in shaders, as they were used incorrectly before

Manually tested by verifying transformer demo HLG and PQ videos look the same with and without this CL, including with a BitmapOverlayProcessor enabled to test flows both with one MatrixTransformationProcessor that skips HDR TFs, and with one that doesn't.

PiperOrigin-RevId: 469736067
2022-09-30 17:00:13 +00:00
leonwind
7e5dcf2360 Bind contrastFactor in constructor instead of drawFrame method.
PiperOrigin-RevId: 469438747
2022-09-30 16:58:16 +00:00
Googler
0b1c540ff9 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
2022-09-30 16:51:14 +00:00
Googler
a5d7fdcab5 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
2022-09-30 16:49:21 +00:00
huangdarwin
244d38cf0e HDR: Clamp YUV to RGB conversion.
Manually tested using transformer demo HLG videos. Before this CL, RGB values after the YUV to RGB conversion reached up to 1.025. After this CL, RGB values correctly clamp at 1.0.

PiperOrigin-RevId: 468426092
2022-09-30 16:48:22 +00:00
Googler
0c961a7abd Defensively cancel frame processing tasks on error.
FrameProcessingTaskExecutor should be released on error.
There can be a delay until this happens, so
FrameProcessingTaskExecutor will cancel any pending tasks
and drop new tasks until it is released.

PiperOrigin-RevId: 468171820
2022-09-30 16:46:16 +00:00
leonwind
9f6940eaa4 Fix typo
PiperOrigin-RevId: 468152718
2022-09-30 16:45:20 +00:00
leonwind
045a396167 Compact a RGB Matrix chain into a singular RGB Matrix.
PiperOrigin-RevId: 468013019
2022-09-30 16:44:22 +00:00
huangdarwin
d963dfbd3e HDR: Update limited range and add full range YUV to RGB color transforms.
PiperOrigin-RevId: 467910378
2022-09-30 16:42:26 +00:00
Googler
59be732230 Allow high-priority tasks to be executed before other tasks.
This is needed as a pre-requisite for allowing MCVR to control
FrameProcessor frame release for previewing.

Submitting a high-priority task is conceptually different from
posting at the front of a single queue of tasks, as the high-priority
tasks are executed in FIFO order among themselves. This will ensure
that frame release tasks submitted in close succession are executed
in the order they are submitted but before any lower priority tasks.

PiperOrigin-RevId: 467675137
2022-09-30 16:41:28 +00:00
andrewlewis
73d606acf3 Increase pixel difference threshold
PiperOrigin-RevId: 467610621
2022-09-30 16:37:17 +00:00
leonwind
8760ee48b9 Refactor RgbaMatrix to RgbMatrix.
* Rename all Rgba instances to Rgb.
* Remove alpha value from the RGBA Matrices and apply the 4x4 matrix
only to the R, G, B channels.
* Restore the alpha from the input unchanged.

PiperOrigin-RevId: 467208888
2022-09-30 16:35:25 +00:00
Googler
d7bf1ed2d7 Avoid spinning while queueing input to ExternalTextureProcessor.
This change adds ExternalTextureManager which implements
InputListener to only queue input frames to the
ExternalTextureProcessor when it is ready to accept an input
frame. This replaces the old retry-logic in GlEffectsFrameProcessor.

Before this change, the retrying in GlEffectFrameProcessor wasted
CPU time if input becomes available faster than the
ExternalTextureProcessor can process it.

PiperOrigin-RevId: 467177659
2022-09-30 16:34:28 +00:00
Googler
4c4f7d73b4 Fix ChainingGlTextureProcessorListener field name.
PiperOrigin-RevId: 466735554
2022-09-30 16:31:26 +00:00
Googler
97e6a86d2b Avoid spinning in between intermediate texture processors.
This change adds a new method onReadyToAcceptInputFrame to
GlTextureProcesssor.InputListener and changes maybeQueueInputFrame
to queueInputFrame, removing the boolean return value.
This avoids the re-trying in ChainingGlTextureProcessorListener
by allowing it to only feed frames from the producing to the consuming
GlTextureProcessor when there is capacity.

MediaPipeProcessor still needs re-trying when processing isn't 1:1.

PiperOrigin-RevId: 466626369
2022-09-30 16:28:27 +00:00
Googler
1bdc252d2c Remove times(1) from effect and transformer tests as it is the default.
PiperOrigin-RevId: 466324322
2022-09-30 16:24:11 +00:00