235 Commits

Author SHA1 Message Date
tofunmi
1308e22813 fix nits and enhance DefaultVideoFrameProcessorImageFrameOutputTest
resolving comments from 71e92f7512.

PiperOrigin-RevId: 510457401
2023-02-27 18:01:00 +00:00
tofunmi
71e92f7512 Add multi-image input FrameProcessor tests
PiperOrigin-RevId: 510441777
2023-02-27 17:58:25 +00:00
tofunmi
a1f7960eab InternalTextureManager: delete texture after use
PiperOrigin-RevId: 510377977
2023-02-17 11:57:15 +00:00
claincly
cec603393d Fix a missed rename.
PiperOrigin-RevId: 510100709
2023-02-17 11:48:39 +00:00
huangdarwin
cf768329e6 Effect: Rename FrameProcessor
Rename FrameProcessor to VideoFrameProcessor, and GlEffectsFrameProcessor to
DefaultVideoFrameProcessor.

Most changes are semi-mechanical, semi-manual find-replace, preserving case:
* "FrameProc" -> "VideoFrameProc" (ex. FrameProcessor -> VideoFrameProcessor, and
   FrameProcessingException -> VideoFrameProcessingException)
* "GlEffectsVideoFrameProc" -> "DefaultVideoFrameProc"

PiperOrigin-RevId: 509887384
2023-02-17 11:41:06 +00:00
andrewlewis
41a03dd8a6 Fix some minor nits
PiperOrigin-RevId: 509879029
2023-02-17 11:40:13 +00:00
tofunmi
7e33bdfc94 Change FrameProcessor.create() inputTrackType parameter to a boolean
PiperOrigin-RevId: 509808913
2023-02-15 18:17:52 +00:00
tofunmi
83b7946130 Move inputExternalSurfaceTexture to the ExternalTextureManager
Now that the GLEffectFrameProcessor handles external (video) and internal (image) input, components used only for external input needs should be moved to the ExternalTextureManager for code clarity

PiperOrigin-RevId: 509787494
2023-02-15 12:15:00 +00:00
huangdarwin
b7d68fb62e Effect: Add leading zero to decimals in floats.
PiperOrigin-RevId: 509518734
2023-02-15 12:09:53 +00:00
tofunmi
74a307fc71 Fix InternalTextureManager so that all frames are sent downstream
PiperOrigin-RevId: 509478455
2023-02-14 11:23:29 +00:00
claincly
3aca3ad170 Use ColorInfo.Builder in transformer and common.
Because the ColorInfo constructor is deprecated.

PiperOrigin-RevId: 509468663
2023-02-14 10:28:33 +00:00
huangdarwin
3e2c6797bb Effect: Implement brightness convenience class.
It can be confusing how to use RgbMatrix for app devs not comfortable with image
manipulation, so add a helper class that simply translates rgb values the same
constant brightness value, to update the brightness values.

PiperOrigin-RevId: 509287229
2023-02-13 19:34:34 +00:00
andrewlewis
5c30165c28 Update overlay test bitmap based on emulator output
PiperOrigin-RevId: 509210836
2023-02-13 14:35:38 +00:00
tofunmi
574424f626 Update frame & texture processors to handle SDR image input
GLEffectsFrameProcessor, MatrixShaderProgram and FinalMatrixShaderProgramWrapper are currently setup to handle the input frames coming from an external input (i.e. a video decoder). Image input is loaded into Bitmap objects at the start of the pipeline, so they are not produced externally. The changes provide a way for the frame processing pipeline to handle this "internal" (i.e. non-external) input.

PiperOrigin-RevId: 508645244
2023-02-10 14:32:07 +00:00
huangdarwin
0c0c972ea0 Effect: Create GlEffect.isNoOp to simplify Transformer.
This will also allow us to skip transcodes in the future for other effects, like
cropping, color effects, etc.

PiperOrigin-RevId: 507765618
2023-02-08 14:07:41 +00:00
claincly
cccb2f07b7 Remove debug print.
Checked there's no other occurrence.

PiperOrigin-RevId: 507534909
2023-02-08 14:05:03 +00:00
huangdarwin
ca4d2be1fa Effect: Rename TextureProcessor to ShaderProgram.
Also, replace instances of "texture processor" to "shader program", with capitalization retained.

PiperOrigin-RevId: 507515655
2023-02-08 14:04:09 +00:00
tofunmi
4e3c6c6167 Update sample pipelines and frame processors to handle image input.
PiperOrigin-RevId: 506965394
2023-02-08 13:58:50 +00:00
tofunmi
f67569d2dd Update FrameProcessor.create() to accept an input track type.
Based on [this conversation thread](https://chat.google.com/room/AAAA--f88ao/76Rem_cRCK8), I've opted to update the existing FrameProcessor.create() rather than deprecate it, as it is unlikely to be in use by apps outside google3.

PiperOrigin-RevId: 506920930
2023-02-08 13:57:02 +00:00
huangdarwin
f2cfb14be4 HDR: Fix debug surface by setting correct output color.
Set the correct output color on the debug SurfaceViewWrapper, so that SDR contents
can have an output transfer of either GAMMA_2_2 (Gamma 2.2) or SDR (SMPTE 170M).

This fixes an issue where in-app tone-mapping would output gamma 2.2, and the
SDR value incorrectly hardcoded here would lead to an error in the OpenGL, which
does not support SMPTE 170M.

PiperOrigin-RevId: 506684602
2023-02-08 13:44:31 +00:00
claincly
0f4fcc1110 Report flushing completed after all pending frames are decoded.
With the current ExtTexMgr,

it can happen that

- `x` frames are registered, but haven't arrived yet
- flush
  - need to drop `x` frames when they arrive on SurfaceTexture
  - status is reset to 0 pending, 0 available, drop `x` when frames arrive
- register one frame
  - status is set to 1 pending, 0 available, drop `x` when frames arrive
- flush
  - now the number of frame to drop is reset to `pending - available = 1`
  - but it should be `x+1`

This CL solves the issue by reporting (by running the afterFlushTask) flush completes only after all the pending frames before calling flush are accounted for.

PiperOrigin-RevId: 506310671
2023-02-02 15:36:02 +00:00
claincly
4a1cf3d839 Support flushing in FrameProcessor
Flushing resets all the texture processors within the `FrameProcessor`. This
includes:

- At the back, the FinalMatrixTextureProcessorWrapper, and its MatrixTextureProcessor
- At the front, the ExternalTextureManager
- All the texture processors in between
- All the ChainingGlTextureProcessorListeners in between texture processors
- All the internal states in the aforementioned components

The flush process follows the order, from `GlEffectsFrameProcessor.flush()`

1. Flush the `FrameProcessingTaskExecutor`, so that after it returns, all tasks queued before calling `flush()` completes
2. Post to `FrameProcessingTaskExecutor`, to flush the `FinalMatrixTextureProcessorWrapper`
3. Flushing the `FinalMatrixTextureProcessorWrapper` will propagate flushing through, via the `ChainingGlTextureProcessorListener`

Startblock:
   has LGTM from christosts
   and then
   add reviewer andrewlewis
PiperOrigin-RevId: 506296469
2023-02-02 15:33:05 +00:00
tofunmi
eb6c1a5254 Add sRGB eotf to overlay fragment shader.
The eotf is needed so that overlay (image) colors are correctly interpreted and mixed the linear video colors.

Also replaces the 100winners.png with "homemade" image file.

Added GlEffectsFrameProcessor test to justify that the color looks correct at the end of frame processing.

PiperOrigin-RevId: 506290309
2023-02-02 15:32:08 +00:00
claincly
f69a2f5131 Render PQ to DebugSurface in transformer.
For HLG input in transformer, FinalWrapper is configured to only output HLG to
encoder. But since DebugPreview is configured to take PQ for HDR content, the
color will not look correct.

This CL allows overriding the MatrixTP output transfer function, so
that FinalWrapper can output

- HLG to encoder
- PQ to debug preview

PiperOrigin-RevId: 506022840
2023-02-01 10:43:43 +00:00
huangdarwin
089510bc64 Effect: Allow SingleFrameGlTextureProcessor to throw errors.
Implementations outside media3 should be able to throw FrameProcessingException if they come across an error during configure().

PiperOrigin-RevId: 506020149
2023-02-01 10:42:49 +00:00
huangdarwin
0b1a904c07 HDR: Add device checks and mh for GL tone mapping PixelTests.
Add checks to GL tone-mapping pixel tests, to ensure the device's decoder, API
version, and OpenGL implementation support GL tone-mapping before attempting it.

These tests should be run on mobile harness, to detect per-device failures, and
so are moved to transforemr/mh. Per b/263395272, these tests should ultimately
be in an effect/mh directory.

PiperOrigin-RevId: 505749974
2023-02-01 10:37:09 +00:00
kimvde
43aace03cf Make setResolution package private
- Usages in 1P apps have been removed.
- setResolution should be removed when refactoring fallback.

PiperOrigin-RevId: 505043425
2023-02-01 10:20:19 +00:00
huangdarwin
697f84161d Test: Rename pixel tests for golden.
producesExpectedOutput -> matchesGoldenFile

PiperOrigin-RevId: 504863604
2023-02-01 10:18:29 +00:00
huangdarwin
76eb2d4f59 Effect: Move FrameProcessorTestRunner to test-utils.
This is necessary in order to move HDR to SDR tone-mapping tests to transformer/mh.

PiperOrigin-RevId: 504858508
2023-02-01 10:17:36 +00:00
huangdarwin
2360f1f5a3 Effect: Reword GlEffectsFrameProcessor javadoc.
PiperOrigin-RevId: 504847212
2023-02-01 10:16:34 +00:00
tofunmi
1a416b17b5 Update max overlays in one OverlayTextureProcessor
Tested adding 3, 15,16 different overlays in a single OverlayTextureProcessor. The program errored out when 16 overlays were added.

PiperOrigin-RevId: 504810157
2023-02-01 10:14:38 +00:00
huangdarwin
a5d43b2194 Effect: Clarify that padding is added in ScaleToFitTransformation.
PiperOrigin-RevId: 504796380
2023-02-01 10:13:45 +00:00
huangdarwin
86b629fff8 Effect: Decouple GlEffectsFrameProcessorTestRunner from GLEffects.
This is necessary in order to move HDR to SDR tone-mapping tests to transformer/mh,
and to move the test runner to androidx.media3.test-utils, which should not have to
include androidx.media3.effects.

PiperOrigin-RevId: 504607929
2023-02-01 10:10:57 +00:00
huangdarwin
ea629bec83 Test: Rename FrameProcessor Pixel Tests.
Rename tests using the action state expectation pattern.

PiperOrigin-RevId: 504546583
2023-01-25 18:45:31 +00:00
huangdarwin
b359502a13 Effect: Clarify OpenGL configuration.
This information may be needed for applications to create their own OpenGL contexts
and textures passed into or interacting with Effects.

PiperOrigin-RevId: 504342258
2023-01-25 18:43:44 +00:00
huangdarwin
301683a831 Effect: Clarify GlEffect javadoc exception cause.
PiperOrigin-RevId: 504273335
2023-01-25 18:40:54 +00:00
tofunmi
7864d327e8 correct comments in fragment_shader.
PiperOrigin-RevId: 504259419
2023-01-25 18:38:04 +00:00
andrewlewis
b85109e700 Add a way to specify default buffer size
Based on experimentation, when CameraX is producing input for frame processor the buffer size is not being set to match the camera capture resolution, so the output has lower resolution than expected. Expose the default buffer size setter on `SurfaceTexture` to allow apps to process frames at full resolution for use cases like this one where the producer doesn't override the default buffer size.

PiperOrigin-RevId: 504022107
2023-01-25 18:36:02 +00:00
huangdarwin
4b4904899c HDR: Clarify media3.effect hdrStaticInfo / colorRange support.
Clarify that we always output on full range colors, and don't handle
hdrStaticInfo input yet.

PiperOrigin-RevId: 503224687
2023-01-23 12:32:31 +00:00
kimvde
d4db33a535 Avoid re-encoding if video effects are no-op
This is to avoid regressions introduced by removing the convenience
methods from TransformationRequest.

PiperOrigin-RevId: 502864512
2023-01-23 12:23:42 +00:00
kimvde
7803716a77 Remove setScale and setRotationDegrees from TransformationRequest
Also remove usages of TransformationRequest convenience methods
(setScale, setRotationDegrees and setResolution).

Some usages of setResolution can't be removed yet because they are used
for fallback.

PiperOrigin-RevId: 502415748
2023-01-17 02:14:20 +00:00
kimvde
15ba0c5fa6 Add the possility to shift frame timestamps in SampleConsumer
This is needed for constrained multi-asset to shift the timestamps of
the media items that are not the first in the sequence.

PiperOrigin-RevId: 502409923
2023-01-17 02:12:48 +00:00
huangdarwin
7878615f22 Effect: Automatically save bitmaps in pixel test.
Also, omit the "actual" label from output files, as this boilerplate isn't necessary
(it doesn't disambiguate between any other saved filename like "expected").

PiperOrigin-RevId: 502378188
2023-01-17 02:10:24 +00:00
huangdarwin
3c476e2d4b Effect: Create GlEffectsFrameProcessorTestRunner.
Makes GlEffectsFrameProcessorPixelTest slightly more modular in preparation for
copying this into transformer/mh.

Refactoring change. No functional change intended.

PiperOrigin-RevId: 501902223
2023-01-17 02:05:42 +00:00
claincly
693600a444 Add a frame cache
Frame cache compensates for the fluctuation in frame processing times.

Imagine a frame takes 10ms to process, and the interval between two frames is
33ms. The third frame took 40ms to process.

If we don't have frame cache:
- Process frame 1, ready after 10ms, starts playback, now t=0 ms
- Start processing frame 2, ready at t=10ms,
- Release frame 2 at t=33ms
- We start processing the third frame at t=33ms
- The third frame is due presentation at t=66ms
- But frame 3 is available at t=73ms, late

If we have a frame cache of say 3 frams,
- Process frame 1, ready after 10ms, starts playback, now t=0 ms
- Start processing frame 2, ready at t=10ms
- Start processing frame 3, ready at t=50ms
- Release frame 2 at t=33ms
- Start frame 4, ready at t=60ms
- Frame 3 is due presentation at t=66ms
- Frame 3 isn't late

PiperOrigin-RevId: 501869948
2023-01-17 02:04:06 +00:00
huangdarwin
d16e84e296 Effect: Move BitmapTestUtil to common test util class.
Move BitmapTestUtil from media3.effect to media3.test.utils.

This allows this class to be accessed from both transformer and effect tests.

Refactoring change. No functional change intended.

PiperOrigin-RevId: 501837130
2023-01-17 02:01:34 +00:00
huangdarwin
18ce29feee HDR: Update glsl color transfer errors to use unique colors.
Each error will make the output be a solid color with a unique color.

PiperOrigin-RevId: 501824355
2023-01-17 02:00:51 +00:00
huangdarwin
d1e03a41ab HDR: Implement PQ to SDR tone-mapping.
Tested manually on the Pixel 7 and Samsung S10.

PiperOrigin-RevId: 501626354
2023-01-17 01:59:21 +00:00
tofunmi
a9135e2eff Move BitmapLoader to common.
The migration strategy is to deprecate `androidx.media3.session.BitmapLoader` and copy the file into common since BitmapLoader is a public interface that apps could be relying on.

PiperOrigin-RevId: 501266521
2023-01-17 01:50:18 +00:00
andrewlewis
a59c2b8222 Fix some minor issues/typos
PiperOrigin-RevId: 499808853
2023-01-10 18:30:50 +00:00