533 Commits

Author SHA1 Message Date
tofunmi
0ab7bafa87 Migrate Gaussian Blur Effect to media3.
PiperOrigin-RevId: 593164068
2023-12-22 14:13:19 -08:00
huangdarwin
0ed19937d3 Test: Remove setInputColorInfo from VFP test runner.
Instead, for input videos, use the colorInfo provided by the extractor. Similarly, for input images, use sRGB, the only color currently in use.

Textures do still need the input ColorInfo provided though.

PiperOrigin-RevId: 592875967
2023-12-21 09:06:55 -08:00
huangdarwin
bde56b6b43 Effect: Move inputColorInfo javadoc to registerInputStream.
Oops, I forgot to move these in the earlier change, http://<unknown commit>.

PiperOrigin-RevId: 591300964
2023-12-15 10:52:22 -08:00
huangdarwin
7579693739 Effect: Move VideoFrameProcessor inputColorInfo interface to FrameInfo.
Move `inputColorInfo` from `VideoFrameProcessor`'s `Factory.create` to `FrameInfo`,
input via `registerInputStream`.

Also, manually tested on exoplayer demo that setVideoEffects still works.

PiperOrigin-RevId: 591273545
2023-12-15 09:17:39 -08:00
claincly
7e65cce967 Fix first frame not force rendered
This is because currently

1. Player sets a surfaceView to render to
2. Player intializes the renderer
3. MCVR initializes the VideoSinkProvider, by extension VideoGraph

But when 1 happens, MCVR doesn't set the surfaceView on the VideoGraph because
it's not initialized. Consequently after VideoGraph is initialized, it doesn't
have a surface to render to, and thus dropping the first a few frames.

Also adds a test for first frame to verify the correct first frame is rendered.

PiperOrigin-RevId: 591228174
2023-12-15 06:01:12 -08:00
christosts
7df3e9e779 Integrate ImageRenderer with composition preview
PiperOrigin-RevId: 591218013
2023-12-15 05:01:50 -08:00
huangdarwin
0baf777c96 Effect: Release FinalShaderProgramWrapper when releasing DVFP.
Otherwise, there's a memory leak of ~30MB, as this is never released.

This likely used to be considered released as part of what now became
`intermediateGlShaderPrograms`, but its release was missed after we split
`finalShaderProgramWrapper` out from the larger glShaderProgram list.

PiperOrigin-RevId: 590954785
2023-12-14 08:59:38 -08:00
huangdarwin
97e9ed3f7b Effect: Move inputColorInfo usage to registerInputStream.
To prepare to move `inputColorInfo` from `VFP.Factory.create` to
`VFP.registerInputStream`, move all usage of `inputColorInfo` to be *after*
`registerInputStream`.

To do this, defer creation of `externalShaderProgram` instances, which require
`inputColorInfo`. However, we must still initialize `InputSwitcher` and OpenGL
ES 3.0 contexts in the VFP create, to create and request the input surface from
ExternalTextureManager.

PiperOrigin-RevId: 590937251
2023-12-14 07:50:04 -08:00
huangdarwin
a15dfd75be GL: Request OpenGL ES 3.0 context on API 29+, with fallback to 2.0.
Despite GL 3.0 not being required on API 29+, it is experimentally
determined to always be supported on our testing devices, on API 29+.

That said, still fall back to OpenGL 2.0 if 3.0 is not supported,
just in case.

PiperOrigin-RevId: 590569772
2023-12-13 06:01:08 -08:00
tofunmi
5b3491082b fix: make BitmapOverlay constructor public
So developers can subclass it
#minor-release

PiperOrigin-RevId: 586638134
2023-11-30 04:54:06 -08:00
huangdarwin
a2a4ef5f40 Effect: Fix overlay alpha handling.
Before, a translucent overlay over an opaque video would result in a
translucent output. This is not consistent with physical properties of light
(if putting a translucent object in front of an opaque object, you can't see
behind the opaque object).

Using the mixing properties from DefaultVideoCompositor.

PiperOrigin-RevId: 586636275
2023-11-30 04:43:21 -08:00
huangdarwin
9add30e582 Effect: Use Bitmap generation ID to detect changes.
This is much simpler than using protected methods that signal updates in
bitmaps.

PiperOrigin-RevId: 586295312
2023-11-29 04:29:49 -08:00
huangdarwin
e5ef31b277 Effect: Avoid allocating bitmaps and textures in Overlays.
In `TextOverlay` and `DrawableOverlay`, treat `Bitmap` as a buffer, where we
allocate it rarely and reuse it as long as possible before making a new one.

In `BitmapOverlay`, avoid allocating GL textures too often as well.

Strongly reduces allocations and memory usage growth (saving ~100-150 MB on 4k60fps
at high end), at the cost of more code complexity and low-end using 70MB more, on
1/1 comparisons.

PiperOrigin-RevId: 585990602
2023-11-28 08:44:30 -08:00
andrewlewis
b8c1e22389 Clarify threading-related comments in texture manager
In `ExternalTextureManager` fields are accessed from the GL thread and the class needs to be constructed on the GL thread.

Also visibly document threading requirement in the parent class.

PiperOrigin-RevId: 585941284
2023-11-28 05:30:15 -08:00
andrewlewis
7bbf72c202 Use JsonWriter to convert to JSON
Before the change the output was JSON-like but not valid because it had commas
after objects/arrays.

PiperOrigin-RevId: 585929345
2023-11-28 04:39:50 -08:00
tofunmi
b598c96c2f Update emulator device names
PiperOrigin-RevId: 585682881
2023-11-27 10:02:02 -08:00
andrewlewis
1c7c06999e Turn off debug trace logging by default
The issue that motivated adding this (frames unexpectedly being dropped by the
decoder) has been addressed, so we can turn off the logging to reduce
unnecessary allocations during transformation. We can easily turn on debug
logging in future as needed by setting `DebugTraceUtil.DEBUG = true`.

Also avoid allocations for string building at logging call sites by passing a
format string for extra info. Formatting the string now only happens when
debugging is turned on.

Tested manually by running transformations in the new state (DEBUG = false) and
with debugging turned on.

PiperOrigin-RevId: 585666349
2023-11-27 08:57:30 -08:00
huangdarwin
c650f05234 Document TimestampWrapper not working with previewing.
Mentioned in https://github.com/androidx/media/issues/821

PiperOrigin-RevId: 585595948
2023-11-27 03:25:31 -08:00
christosts
2a74cb7ef2 Move VideoFrameProcessor reflective loading code
Move the reflective loading of VideoFrameProcessor from
MediaCodecVideoRenderer to the CompositingVideoSinkProvider. This is so
that all reflective code lives in one place. The
CompositingVideoSinkProvider already has reflective code to load the
default PreviewingVideoGraph.Factory.

PiperOrigin-RevId: 584852547
2023-11-23 03:54:18 -08:00
huangdarwin
0f040e6c6e Use static import for Util.formatInvariant.
In OverlayShaderProgram, this method is used quite a lot, and is the only method from Util.java in this file. Marginally reduce complexity by using a static import instead.

PiperOrigin-RevId: 584828455
2023-11-23 01:45:19 -08:00
huangdarwin
dc037b22cd Effect: Flip texture in OpenGL instead of allocating a Bitmap.
Reduce short-lived allocations of potentially large objects, like Bitmap.

Unfortunately, this does make the TextureOverlay interface more messy though, requiring a way to signal whether the texture should be flipped vertically.

PiperOrigin-RevId: 584661400
2023-11-22 10:17:10 -08:00
christosts
6435ddb89e Create VideoFrameRenderControl
Split CompositingVideoSinkProvider.VideoSinkImpl in two classes:
- VideoSinkImpl now only receives input from MediaCodecVideoRenderer and
  forwards frames to its connected VideoFrameProcessor
- VideoFrameRenderControl takes composited frames out of the VideoGraph
  and schedules the rendering of those.
- CompositingVideoSinkProvider connects VideoSinkImpl with
  VideoFramesRenderer.

PiperOrigin-RevId: 584605078
2023-11-22 06:05:04 -08:00
huangdarwin
8f69bb0d9d HDR: Update PQ to SDR tone-mapping to renderengine.
Use renderengine's PQ to SDR tone-mapping implementation instead
of naive implementation from before.

This improves luminance on highlights, as seen in the test image.

PiperOrigin-RevId: 582318045
2023-11-14 07:43:39 -08:00
huangdarwin
28c095d8d0 Effect: Clarify threading for VideoFrameProcessor methods.
All methods in VideoFrameProcessor are expected to be called by the owning thread,
as far as I understand (vs. 10 threads each queuing frames/textures/streams, which
invalidates blocking done by registerInputStream and flush)

PiperOrigin-RevId: 582295240
2023-11-14 06:07:27 -08:00
claincly
f172923f0d Remove possibly retained bitmap reference
PiperOrigin-RevId: 580579054
2023-11-08 10:39:52 -08:00
claincly
414b72619b Remove unnecessary memory allocation in OpenGL
PiperOrigin-RevId: 579835031
2023-11-06 07:21:23 -08:00
claincly
98e9022c0e Ensure the exception thrown in the constructor is reported
PiperOrigin-RevId: 579776559
2023-11-06 02:44:22 -08:00
huangdarwin
920d588575 Effect: Clarify ExternalTextureManager thread access.
Turns out more things are accessed only on the GL thread than labelled.

PiperOrigin-RevId: 579244695
2023-11-03 11:25:16 -07:00
huangdarwin
44f317693b Flush: Move TextureManager flush logic to abstract class.
This also adds flush support to texture input.

PiperOrigin-RevId: 578536040
2023-11-01 09:08:10 -07:00
huangdarwin
fed88cf6f5 Flush: Disallow flushing when there's no active input.
Throws when calling flush when there's no active input, for example
before an input stream is registered or after all output streams have
ended.

PiperOrigin-RevId: 577165419
2023-10-27 05:23:38 -07:00
huangdarwin
346b9257ba Flush: VideoFrameProcessor texture output
PiperOrigin-RevId: 576928149
2023-10-26 11:06:04 -07:00
huangdarwin
e91ce868ad Flush: Add javadoc to mention flush limitation.
PiperOrigin-RevId: 576482193
2023-10-25 04:10:32 -07:00
huangdarwin
a8a590c305 Effect: Clarify flush behavior in javadoc
PiperOrigin-RevId: 576118064
2023-10-24 06:13:22 -07:00
simakova
1ba1998e8d Update param description in TimestampWrapper
PiperOrigin-RevId: 575806256
2023-10-23 07:02:09 -07:00
Daniele Sparano
f14732873f Change isColorValid with isDataSpaceValid 2023-10-17 11:42:33 +00:00
Daniele Sparano
1fe9c3303e Resume toLogString() in ColorInfo; revert DebugTextViewHelper 2023-10-17 11:42:33 +00:00
huangdarwin
89a1bb528d Flush: VideoFrameProcessor Image Input.
Much simpler than ExternalTextureManager flushing, because
ExternalTextureManager complexity is due to decoder race condition behavior,
which we won't see for Bitmaps due to a more well-defined interface.

This is needed to test texture output flushing.

PiperOrigin-RevId: 570896363
2023-10-04 21:20:23 -07:00
huangdarwin
fa51f8cd4d Effect: Move common statement out of switch/case
PiperOrigin-RevId: 570323141
2023-10-03 02:37:48 -07:00
claincly
34dddfe9d5 Add previewing specific video graph.
PiperOrigin-RevId: 569473178
2023-09-29 06:16:16 -07:00
claincly
cd6f8a42a5 Move Single/MultiVideoGraph impl to effect
PiperOrigin-RevId: 569188658
2023-09-28 08:27:06 -07:00
huangdarwin
444cb3fb3a Test: Rename getBitmap to getBitmapAtPresentationTimeUs
PiperOrigin-RevId: 567683139
2023-09-22 12:06:57 -07:00
huangdarwin
190fd7abc6 Compositor: Clarify javadoc, to mention VideoCompositorSettings.
Clarify that we use OverlaySettings to place frames over one another,
as passed in via VideoCompositorSettings

PiperOrigin-RevId: 567321828
2023-09-21 09:01:32 -07:00
huangdarwin
93d06180ef Compositor: Remove obsolete TODO
PiperOrigin-RevId: 566327798
2023-09-18 09:39:29 -07:00
claincly
fef16b05d9 Fix flaky test becasue ExtTexMgr is not using emulator settings
When running on emulators, ExternalTextureManager needs a longer timeout for
forcing EOS, but we didn't catch a device name running on blaze: `generic_x86`

PiperOrigin-RevId: 565513152
2023-09-14 16:45:38 -07:00
huangdarwin
c77b8c8479 Compositor: Split out OpenGL drawing logic into inner class.
Organize logic a bit by splitting logic about how we draw using OpenGL onto a
texture, out from the larger class, which has lots of logic discussing how we select
frames and streams.

No functional change intended, but a few method calls are shuffled around to
simplify things.

PiperOrigin-RevId: 565426225
2023-09-14 11:26:14 -07:00
huangdarwin
5ef5d46708 Compositor: Move Settings to DefaultVideoCompositor.
This previously was in the VideoCompositor class, but wasn't
referenced at all from that interface.

PiperOrigin-RevId: 565409646
2023-09-14 10:33:25 -07:00
huangdarwin
98009d396a Compositor: Document VideoCompositor interface thread safety.
PiperOrigin-RevId: 565388982
2023-09-14 09:22:08 -07:00
claincly
5106f2f45a Rollback of e2882c051b
PiperOrigin-RevId: 565069442
2023-09-13 09:15:35 -07:00
huangdarwin
e0de405e68 Compositor: Move input source javadoc to class-level.
As discussed offline, this is important for users of the class, and not all users may choose to read method javadoc, so best to make sure it's visible by leaving it at the class-level.

PiperOrigin-RevId: 565057677
2023-09-13 08:30:15 -07:00
Googler
282171cb6f Rollback of e2882c051b
PiperOrigin-RevId: 564802194
2023-09-12 12:40:57 -07:00