32 Commits

Author SHA1 Message Date
leonwind
8da65d01d2 Merge RgbProcessor and MatrixTransformation.
PiperOrigin-RevId: 472325145
(cherry picked from commit 672405afdff53ee746a4bcd237170de3b9feb1f7)
2022-09-05 21:51:11 +00:00
huangdarwin
6c51aa949d HDR: Use factory for MatrixTransformationProcessor.
Separate MatrixTransformationProcessor constructors by color input and output.

PiperOrigin-RevId: 471034768
(cherry picked from commit 1b6482960e9240a7697c6a13fdde198e3bf375a1)
2022-08-30 17:50:21 +00:00
leonwind
fb43ce2005 Add static Grayscale and Inverted RGB Filter.
PiperOrigin-RevId: 471017440
(cherry picked from commit 859504230240eacd3255cdf6be987412a4ff6c69)
2022-08-30 16:47:02 +00:00
claincly
7fc1e4a674 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
(cherry picked from commit 91709831ede920a38fc7dc3510973a434f390611)
2022-08-26 11:03:54 +00:00
leonwind
bf299da11c Delete glPrograms in Contrast and RgbMatrix.
Remove unecessary null checks.

PiperOrigin-RevId: 469999952
(cherry picked from commit a7d3752c6655d6572101b4b4c8b88c885fcf80de)
2022-08-25 15:49:13 +00:00
huangdarwin
893bf0db7c HDR: Rename GL_COLOR_TRANSFER instances to COLOR_TRANSFER
PiperOrigin-RevId: 469959215
(cherry picked from commit 2a05a5040379ae93c5b0c2b0aecd2345da84461d)
2022-08-25 11:43:40 +00:00
huangdarwin
7e7f07f8ab 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
(cherry picked from commit 2ad07e88ee39ed5f662df91dc7034bd0ce478abe)
2022-08-24 15:44:22 +00:00
leonwind
5ace28044d Bind contrastFactor in constructor instead of drawFrame method.
PiperOrigin-RevId: 469438747
(cherry picked from commit 7e5dcf2360190e05d000d0fe4a18f2bca252fabe)
2022-08-23 13:16:17 +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
068a9d1099 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
(cherry picked from commit 244d38cf0e5640b6c07abaeebcaffce2d3913345)
2022-08-18 11:31:03 +00:00
Googler
823df91ca0 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
(cherry picked from commit 0c961a7abdc6ea7ef1b3f33dfd44d01459d2344a)
2022-08-17 12:25:53 +00:00
leonwind
06e95f9f59 Fix typo
PiperOrigin-RevId: 468152718
(cherry picked from commit 9f6940eaa4d60ac48d1e7be92d81e81a8793ce75)
2022-08-17 10:15:21 +00:00
leonwind
ec9948e9f2 Compact a RGB Matrix chain into a singular RGB Matrix.
PiperOrigin-RevId: 468013019
(cherry picked from commit 045a396167e9cfc7faf35a94d1f63971bec3d290)
2022-08-16 20:39:42 +00:00
huangdarwin
d91f60b6e6 HDR: Update limited range and add full range YUV to RGB color transforms.
PiperOrigin-RevId: 467910378
(cherry picked from commit d963dfbd3e478f01077e45ad84bae6d1ea666038)
2022-08-16 13:33:32 +00:00
Googler
f6dde78204 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
(cherry picked from commit 59be732230fe9bfdc27c27d6a6866abacbdda3fe)
2022-08-15 15:27:21 +00:00
andrewlewis
a2815141e6 Increase pixel difference threshold
PiperOrigin-RevId: 467610621
(cherry picked from commit 73d606acf3dd371232f874b20a1534952f8d560d)
2022-08-15 07:59:28 +00:00
leonwind
1076f3f7d7 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
(cherry picked from commit 8760ee48b910a4a34e6cc5008b660513203b05e8)
2022-08-12 14:51:25 +00:00
Googler
19dfbeae5b 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
(cherry picked from commit d7bf1ed2d7f5cd1e3893000d9d917ae69b814848)
2022-08-12 11:10:47 +00:00
Googler
65d73e142f Fix ChainingGlTextureProcessorListener field name.
PiperOrigin-RevId: 466735554
(cherry picked from commit 4c4f7d73b49b522599b8ac166085c0add801c074)
2022-08-10 18:01:01 +00:00
Googler
6b4d174cde 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
(cherry picked from commit 97e6a86d2b1f72de9f95658f90ea40d1e1e4fac2)
2022-08-10 09:56:24 +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
Googler
cdd47ff703 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
(cherry picked from commit 7dc05edbab233dcd631a4a78ad65f1c30a1e9734)
2022-08-09 10:05:14 +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
leonwind
1bbb5df410 Switch @param to @code tags in RgbAdjustment.
PiperOrigin-RevId: 465591877
(cherry picked from commit fe0cf0528318abf1a9a7a8f75bcce402235f961a)
2022-08-05 17:20:54 +00:00
leonwind
d34ed7a5e1 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
(cherry picked from commit a76dbfd363e2d167b13d2bcd978979bcfd69b071)
2022-08-05 12:56:26 +00:00
leonwind
46f267700f Remove clamp function in contrast fragment shader.
* OpenGL automatically clamps the output colors to the [0, 1] interval.

PiperOrigin-RevId: 465071999
(cherry picked from commit 2347db5d7484b161f6389846e6cde5b0ac1ed7a6)
2022-08-03 16:14:30 +00:00
hschlueter
110c442758 Fix saving previous debugSurfaceView in FinalMatrixTPWrapper.
PiperOrigin-RevId: 465067306
(cherry picked from commit a28a508d2dd10ac2858c334a1a0fe0ff1350e98c)
2022-08-03 15:52:24 +00:00
hschlueter
89edfbc12b Clean up FrameProcessor TODOs.
PiperOrigin-RevId: 465044342
(cherry picked from commit c5d1940fbab430ede4b158300bbb381c032498bf)
2022-08-03 13:53:53 +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
hschlueter
93bb191cb1 Create effect module.
PiperOrigin-RevId: 464767396
(cherry picked from commit 4d09ca66986a3c862b09f42a06a5bb031dce46f8)
2022-08-02 12:36:47 +00:00