533 Commits

Author SHA1 Message Date
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
huangdarwin
35161c7489 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
2022-09-30 16:23:12 +00:00
Googler
7dc05edbab Split GlTextureProcessor.Listener into input/output/error listener.
This simplifies ChainingGlTextureProcessor as it now only connects a
consuming and a producing GlTextureProcessor rather than a previous,
current, and next GlTextureProcessor.

Also use default no-op implementations of the listeners in
SingleFrameGlTextureProcessor and MediaPipeProcessor to avoid
null-checks.

PiperOrigin-RevId: 466301642
2022-09-30 16:22:08 +00:00
huangdarwin
536d42c865 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
2022-09-30 16:21:05 +00:00
leonwind
fe0cf05283 Switch @param to @code tags in RgbAdjustment.
PiperOrigin-RevId: 465591877
2022-08-05 17:20:54 +00:00
leonwind
a76dbfd363 Add RgbAdjustment class to build RgbaMatrices
* Add RgbaMatrix interface implementation.
* Add Builder class for easy adjustments.
* Adjust existing RgbaMatrixPixelTests to use new RgbAdjustment class.

PiperOrigin-RevId: 465545429
2022-08-05 12:56:26 +00:00
leonwind
2347db5d74 Remove clamp function in contrast fragment shader.
* OpenGL automatically clamps the output colors to the [0, 1] interval.

PiperOrigin-RevId: 465071999
2022-08-03 16:14:30 +00:00
hschlueter
a28a508d2d Fix saving previous debugSurfaceView in FinalMatrixTPWrapper.
PiperOrigin-RevId: 465067306
2022-08-03 15:52:24 +00:00
hschlueter
c5d1940fba Clean up FrameProcessor TODOs.
PiperOrigin-RevId: 465044342
2022-08-03 13:53:53 +00:00
hschlueter
22725ddfa8 Move effects functionality out of transformer to effects module.
PiperOrigin-RevId: 465038852
2022-08-03 13:19:15 +00:00
hschlueter
4d09ca6698 Create effect module.
PiperOrigin-RevId: 464767396
2022-08-02 12:36:47 +00:00