474 Commits

Author SHA1 Message Date
andrewlewis
011fc9d5d3 Fix possible lost end of stream notification
In `ExternalTextureManager` in seemingly rare cases end of stream is signaled
at the point where a frame is currently pending processing. In that case the
video end of stream signal was lost.  If the muxer timeout was enabled this
case would result in throwing an exception, but otherwise the operation would
get stuck

Add code to signal end of stream in `onInputFrameProcessed` as well, so that we
signal end of stream when the pending frame is handled.

Tested by running
`TransformerEndToEndTest.loopingTranscodedVideo_producesExpectedResult` several
times.

PiperOrigin-RevId: 524361069
2023-04-17 17:13:22 +01:00
huangdarwin
0e85491d4e Transformer: Update TODOs to use new bug link
PiperOrigin-RevId: 524349341
2023-04-17 17:12:28 +01:00
Googler
52a9ce3265 Shader portion is bloat given we're scaling and biasing the colors. Swap out implementation.
PiperOrigin-RevId: 524113489
2023-04-17 17:04:19 +01:00
tofunmi
2f23774d53 Add FrameDropping GlEffect
PiperOrigin-RevId: 524030672
2023-04-17 17:03:21 +01:00
claincly
32be985c7c Remove setters for streamOffset.
In addition to the changes in 3a5c4277a7

This change essentially reverts 30e5bc9837 (Merged Jul 2022).

From this CL on, `VideoFrameProcessor` takes in non-offset, monotonically
increasing timestamps. For example, with one 5s and one 10s video,

- `VideoFrameProcessor`'s input should start from 0
- On switching to the second video (10s), the timestamp of the first frame in
  the second video should be at 5s.

In ExoPlayer however, `streamOffset` is managed differently and thus needs
correction before sending the frames to `VideoFrameProcessor`:
- The timestamp of the first video is offset by a large int, so the first frame
  of the first media item has timestamp (assuming) 10000000000000000
- The last frame of the first media item has 10000005000000000
- At this point the stream off set is updated to 10000005000000000
- The pts of the first frame of the second video starts from 0 again.

PiperOrigin-RevId: 523444236
2023-04-12 16:52:48 +01:00
huangdarwin
acdb7ee921 HDR: Add HDR pixel tests.
Implement HDR input support for texture output, and add HDR pixel tests.

PiperOrigin-RevId: 523417701
2023-04-12 16:51:51 +01:00
huangdarwin
e4bb1045ef Test: Restrict visibility of string constants.
Turns out these could have been private, so not sure why they were public.

PiperOrigin-RevId: 522545698
2023-04-11 10:36:27 +01:00
huangdarwin
b4e7e74a2c effect: Remove duplicate javadoc.
This javadoc is also clear from the Builder.setEnableColorTransfers javadoc, so omit it here to avoid duplication.

PiperOrigin-RevId: 522404884
2023-04-11 10:35:30 +01:00
huangdarwin
0d30edae75 Test: Add TextureOutputListener for texture output tests
Before this CL, SurfaceTexture.onFrameAvailable was used to tell whether a frame
was available in the VideoFrameProcessor's output texture. This was incorrect, as
it would rely on having the texture be written to before the
SurfaceTexture.onFrameAvailableListener is invoked, leading to null-pointer-
exceptions on timeouts.

Instead of using DefaultVideoFrameProcessor different interfaces to set that we
want to output to a texture, and get that output texture, use one interface that
sets a listener, and renders to a texture iff that listener is set. As this
listener is executed on the GL thread, this also allows us to no longer need to
expand visibility for the GL task executor and tasks.

PiperOrigin-RevId: 522362101
2023-04-11 10:34:38 +01:00
tofunmi
54ebfa986a disable transfer colors in DefaultShaderProgram.createApplyingOetf
PiperOrigin-RevId: 522347729
2023-04-11 10:33:41 +01:00
tofunmi
d66dd50263 Change output color transfers when rendering Frame To Debug Surface
PiperOrigin-RevId: 522010318
2023-04-05 12:00:06 +01:00
tofunmi
5d6ffaaf55 Fix HDR effect pipeline
NPE in toneMap_hlgFrame_matchesGoldenFile and toneMap_pqFrame_matchesGoldenFile was created because a uEnableColorTransfer uniform was being created on the HDR path, when HDR shader files don't have this uniform. (they don't support disable color transfers right now)

Fix: only create the uniform when input is SDR.

manually tested on failing tests

PiperOrigin-RevId: 522002603
2023-04-05 11:14:04 +01:00
tofunmi
08a9ccc743 Effect: Add support for disabling color transfers for SDR
PiperOrigin-RevId: 521805477
2023-04-05 15:48:10 +01:00
claincly
952edb3f0a Add a base class for GL shader programs.
By having a single base class for GL shader programs we simplify the customization
of new shader programs. The concrete cases include

- Allow frame dropping in shader program
- Creating a FrameCache that selectively (based on timestamp) replays and clears
  the cached content

PiperOrigin-RevId: 520322060
2023-03-30 17:21:17 +00:00
huangdarwin
a0838771d3 HDR: Implement DefaultVideoFrameProcessor texture output for tests.
Previously, we always used ImageReader to read from the output of DefaultVideoFrameProcessor, for pixel tests. This has a limitation of not being
able to read HDR contents, so that we couldn't support HDR pixel tests.

Reading from a texture allows us to use glReadPixels to read from
DefaultVideoFrameProcessor, and build upon this to implement HDR pixel tests. We do
still want tests for surface output though, because real use-cases only will output
to Surfaces.

Also, add some tests for outputting to textures, since this test infrastructure is
a bit complex.

PiperOrigin-RevId: 519786535
2023-03-30 17:14:15 +00:00
claincly
b70e7ca9e7 Remove redundant volatile.
PiperOrigin-RevId: 519099339
2023-03-30 17:08:05 +00:00
Googler
67f8fbf3bd [Media3][Shader] Reset the composite RGB matrix upon update
Since the composite matrix is ultimately rewritten to, we need to ensure it's cleared (to identity) before update.

Test plan: use an effect as a time based approach and see that the effect no longer clips

PiperOrigin-RevId: 518886623
2023-03-30 17:05:23 +00:00
huangdarwin
cbaf0f8232 Effect: Early return and rename variable (+ nits).
Reduce nesting by using an early return. Also, rename
`outputSizeOrRotationChanged` to `outputChanged`, because this also applies to when the output surface changes.

Also, update local variable initialization, add some javadoc, and remove unneeded
local variable

PiperOrigin-RevId: 518241708
2023-03-21 14:22:46 +00:00
tofunmi
de3678e461 Remove glUtil.clearOutputFrame from GLObjectsProvider.
d288891c77 added clearing depth buffers to GLUtil, so there is no need to have allow apps to have a custom clearOutputFrame.
Also removes default implementations in GLObjectsProvider know that these methods have been implemented.

PiperOrigin-RevId: 517156304
2023-03-21 14:13:59 +00:00
huangdarwin
9beddc2cc4 Effect: Update InternalTextureManager to use double timestamps.
Instead of using a long frameDurationUs with Math.floor, use a double
frameDurationUs with Math.round,

Before, playing an image with 30 fps over 1 second would result in the final
timestamp not being aligned to the expected 1 second timestamp. Over long
periods of time, this can lead to significant timestamp drift. Additionally,
for TimestampWrapper and constrained multi-asset, where TimestampWrapper
begins the 2nd effect on the 2nd asset's startTimeUs, this floor() behavior
can lead to the first few frames of the 2nd asset using the first asset's
effects, due to timestamps being mismatched.

PiperOrigin-RevId: 516529240
2023-03-14 15:57:32 +00:00
tofunmi
82c9479dd2 Update GlObjectsProvider to cover creating surface.
PiperOrigin-RevId: 516300480
2023-03-14 07:56:05 +00:00
huangdarwin
f0d91b30d5 Effect: Implement TimestampWrapper.
To allow applying an effect only on a range of timestamps.

PiperOrigin-RevId: 515615662
2023-03-14 07:52:12 +00:00
Googler
6f25c74a95 [Media3][Test] Add save location to test utils for bitmap utils
Test plan: run tests on ImageX with saving

PiperOrigin-RevId: 515068443
2023-03-14 07:43:56 +00:00
tofunmi
68578be372 Update createStaticBitmapOverlay to take in context.
By making this method accept context, we can use DefaultDataSource.Factory in the DatasourceBitmapLoader to support a wider range on URI schemes in Bitmap Overlays. (and implement a local file picker for images for custom bitmap overlays in the demo transformer app)

PiperOrigin-RevId: 515013460
2023-03-14 07:39:43 +00:00
huangdarwin
b3023ffe9a Effect: Remove todo to consider using Gamma 2.2 everywhere.
Per testing, using gamma 2.2 everywhere resulted in undesirable color
shifting.

PiperOrigin-RevId: 515008279
2023-03-14 07:38:59 +00:00
tofunmi
e478d81b52 Update effect to take in and use a GlObjectsProvider
PiperOrigin-RevId: 514744747
2023-03-14 07:33:25 +00:00
tofunmi
7303caffb5 Create GlObjectsProvider
To create this file TextureInfo has been moved to common and renamed to GLTextureInfo.

We'll look to expand the interface in future to cover more of the methods around GL object maintenance in future as required.

PiperOrigin-RevId: 514445397
2023-03-07 11:56:08 +00:00
huangdarwin
729066fbd6 GL: Delete frame buffers after use.
Before, we used to never call glDeleteFramebuffers, which could
in theory lead to leaks in the number of frame buffers
available and make releasing the GL context more expensive.

PiperOrigin-RevId: 514387847
2023-03-07 11:52:01 +00:00
ibaker
cb7d565fd4 Add missing @param tags
Dackka generates a warning if a method has at least one `@param` tag,
but not all of them are documented.

#minor-release

PiperOrigin-RevId: 513873453
2023-03-07 11:49:24 +00:00
tofunmi
efaf4e3f33 Remove effect/SimpleBitmapLoader & replace with DataSourceBitmapLoader
PiperOrigin-RevId: 513824487
2023-03-07 11:46:58 +00:00
andrewlewis
a28b691ced Fix name for FrameCacheGlShaderProgram
This implements `GlShaderProgram` (and is GL-specific).

PiperOrigin-RevId: 513528160
2023-03-02 17:19:29 +00:00
tofunmi
e425b6e082 Image frame processing color transfer fix
Used an actual captured image with set color profile for test to minimise the chance of the test flaking. Also renamed the media/bitmap/overlay folder to media/bitmap/input_images for clarity.

PiperOrigin-RevId: 513273353
2023-03-02 13:22:27 +00:00
andrewlewis
5b3f3e649a Increase GL release timeout to 500 ms
Based on 1000 test runs an emulator, with the current timeout releasing
fails (even with no custom effects) about one percent of the time.
Releasing normally completes in about 30 ms but occasionally
`eglTerminate` took up to 200 ms (and even releasing an effect
took up to 80 ms in one case).

With the new timeout of 500 ms, we still catch stuck effects reasonably
quickly but the number of flaky test failures should be less than one in
ten thousand.

PiperOrigin-RevId: 512690715
2023-03-01 17:20:37 +00:00
claincly
c7b4ec4d65 Allow video format change.
Uses the first mediaItem's format as the output format.

If there is `Presentation` supplied in the `Composition.effects`, add it as the
last effect of the first EditedMediaItem.

PiperOrigin-RevId: 512082659
2023-02-27 18:45:32 +00:00
andrewlewis
d1f3b81a76 Mark methods needing to be called on GL thread
Also remove @WorkerThread annotations, as static checks associated with
this annotation aren't useful in this part of the codebase because
almost no methods are called on the main thread.

This change should be a no-op.

PiperOrigin-RevId: 512060367
2023-02-27 18:42:43 +00:00
andrewlewis
0780a21b3f Continue releasing programs on failure
Currently if releasing a shader program throws we don't release the GL
context, which could leak resources, and any errors are silently dropped
as we suppress notifications during releasing.

Improve resource cleanup and debuggability of errors from custom effects
by continuing to release shaders on failure (for runtime and
`VideoFrameProcessingException`s) and always clean up the GL context.

Note: this doesn't help with the case where releasing a custom shader
blocks for a long time, causing releasing the frame processor to
time out.
PiperOrigin-RevId: 512042501
2023-02-27 18:40:49 +00:00
huangdarwin
d73c0b3cc0 Effect: Implement isNoOp on GlEffect interfaces.
Also, allow isNoOp to default to false without the TODO, so that implementations
of isNoOp must opt-in to implementing the override in order to be considered for
skipping the effect (ex. for transcoding in Transformer).

PiperOrigin-RevId: 511223540
2023-02-27 18:21:39 +00:00
huangdarwin
e282c0ad67 Effect: Add FloatRange to public GlEffect impl interfaces.
Using these annotations/checkers should hopefully make it marginally harder to use the wrong input values in the API.

PiperOrigin-RevId: 510966941
2023-02-27 18:08:28 +00:00
huangdarwin
92138fc83c Effect: Rename to DefaultShaderProgram.
Rename:
* MatrixShaderProgram to DefaultShaderProgram, and
* FinalMatrixShaderProgramWrapper to FinalShaderProgramWrapper.
PiperOrigin-RevId: 510498547
2023-02-27 18:03:38 +00:00
huangdarwin
84acfe7867 Effect: Rename to ScaleAndRotateTransformation
Rename ScaleToFitTransformation to ScaleAndRotateTransformation.

This better represents the operations that can be accomplished using this
effect. The name was originally named ScaleToFit* because it's not obvious how
to scale to fit using OpenGL, and this effect handled the scaling to fit in a way that no other MatrixTransformations did.

However, it's hard to discover how to rotate when skimming names of effects, so
it's probably more useful to convey that this effect rotates, than that it
scales to fit.

PiperOrigin-RevId: 510480078
2023-02-27 18:02:45 +00:00
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