561 Commits

Author SHA1 Message Date
kimvde
92a06606b4 Remove ability to run the DefaultVideoCompositor on its own GL thread.
- It's never used and handling multi-threading is costly.
- If the VideoCompositor and the VideoFrameProcessors use separate
threads and the same GlObjectsProvider, the GlObjectsProvider is
accessed from multiple threads. This class doesn't seem designed for
multi-threading.

PiperOrigin-RevId: 723448013
2025-02-05 03:55:42 -08:00
Googler
4ed9abd05b Rollback of 0fb4e3ba11
PiperOrigin-RevId: 722585306
2025-02-03 03:18:59 -08:00
Googler
0fb4e3ba11 Add DebugViewEffect
Also updated DefaultVideoFrameProcessor to create GlShaderPrograms with the working ColorInfo rather than the output ColorInfo.

PiperOrigin-RevId: 721748002
2025-01-31 06:13:57 -08:00
dancho
bb37aad170 Add an option to use different texture filtering
Add an option to GlMatrixTransformation to choose the OpenGL texture
minification filter.
When mipmaps are requested, mipmaps are generated with
`glGenerateMipmap()`.

PiperOrigin-RevId: 720629807
2025-01-28 10:44:26 -08:00
claincly
0d8e42238e Stop checking all inputs ended when releasing compositor
This could happen when the player is released before ending so not all input
has ended.

PiperOrigin-RevId: 716173884
2025-01-16 04:11:21 -08:00
kimvde
fbf9be2f00 Fix composition player repeat mode
Some checks in SingleInputVideoGraph were causing CompositionPlayer to
throw for a single media item sequence when repeat mode was enabled. The
reason was that, in this case, no new input stream is registered to the
VideoFrameProcessor.

PiperOrigin-RevId: 715409509
2025-01-14 09:20:14 -08:00
claincly
e9e0569425 Integrate MultiInputVideoGraph in CompositionPlayer
Currently doesn't support image/video transitions

PiperOrigin-RevId: 715393251
2025-01-14 08:33:39 -08:00
andrewlewis
0a27e7946f When reregistering frames automatically, drop after signaling EOS
In this mode there isn't an explicit signal from upstream that an input frame
is going to arrive at the `SurfaceTexture`. This means that when end-of-stream
is signaled we don't know when there won't be any more input frames.

Reject new frames in `onFrameAvailable` after input EOS is handled for the case
of reregistering frames automatically. This avoids those frames entering the
pipeline and causing us to unexpectedly handle frames after EOS.

PiperOrigin-RevId: 714858039
2025-01-13 00:43:45 -08:00
andrewlewis
e1b57c130d Make auto frame registration test non-flaky
Wait for each frame to be rendered before unblocking queueing the next one.

PiperOrigin-RevId: 713621811
2025-01-09 04:21:39 -08:00
kimvde
3a00960831 Remove stale Javadoc
PiperOrigin-RevId: 713253227
2025-01-08 05:16:01 -08:00
andrewlewis
0044d0cebc Fix GLES31 javadoc reference to be unambiguous and link correctly
PiperOrigin-RevId: 712848161
2025-01-07 03:35:30 -08:00
Googler
f06bfc2e15 Log errors in BaseGlShaderProgram and QueueingGlShaderProgram.
PiperOrigin-RevId: 708297631
2024-12-20 05:59:18 -08:00
claincly
675c1d898a Move interface locations
PiperOrigin-RevId: 702096389
2024-12-02 15:03:37 -08:00
claincly
8908d82cac Signal end of stream to VideoFrameProcessor in previewing
This will be used by VideoCompositor

PiperOrigin-RevId: 702031907
2024-12-02 11:30:20 -08:00
kimvde
52dfe25542 Fix flushing issue in DefaultVideoFrameProcessor
Before this CL, the following scenario could happen:
- A new input stream is registered to the DefaultVideoFrameProcessor.
- Before the pipeline is reconfigured, a seek is issued andd the
  DefaultVideoFrameProcessor is flushed.
- As a result, the new input stream registration is never taken into
  account.

As a result:
- If an input stream is registered after the seek (before queueing any
  frame), registerInputStream will block indefinitely because
  inputStreamRegisteredCondition will be closed.
- If a frame is queued after the seek, it will be linked to the input
  stream information of the previous frames.

This CL makes sure that any pending input stream is registered after a
flush.

PiperOrigin-RevId: 698736866
2024-11-21 05:00:32 -08:00
claincly
01c784775e Rename signalEndOfInputStream()
This is because the method is called for each media item, the current name
implies that the method is only called once for all videos in a sequence.

PiperOrigin-RevId: 695332916
2024-11-11 07:44:15 -08:00
dancho
f9fd8badec Prevent repeated release of the same EGLContext
All instances of PlaybackVideoGraphWrapper use the same
VIDEO_FRAME_PROCESSOR_FACTORY_SUPPLIER which uses the same
DefaultGlObjectsProvider.

Each call to DefaultGlObjectsProvider.release() releases
all previously created EGLContexts.

Lazily create a new DefaultGlObjectsProvider for each
DefaultVideoFrameProcessor (not one per factory).

PiperOrigin-RevId: 693658458
2024-11-06 03:18:42 -08:00
ibaker
286273c10e Enable lint in tests for modules that require no fixes
PiperOrigin-RevId: 693313908
2024-11-05 05:40:03 -08:00
shahddaghash
7f94aaf49f Remove deprecated SingleFrameGlShaderProgram class.
Class was deprecated in Media3 1.2.0. Use BaseGlShaderProgram class instead.

PiperOrigin-RevId: 691001562
2024-10-29 06:53:45 -07:00
dancho
e67660f326 Consistently use highp for HDR colors
GLSL 3.00 mediump doesn't require enough precision near zero
to correctly represent PQ colors where the [0, 1] GL range
represents [0, 10_000] nits.
This caused `noEffects_hlg10InputAndHdr10Output_matchesGoldenFile`
to fail on some devices.

PiperOrigin-RevId: 690627069
2024-10-28 08:50:19 -07:00
dancho
5bb9e1a932 UltraHDR Ovelays: remove texture unit clash
Do not use the same texture unit for two different textures.
This was causing tests to fail on multiple devices.

PiperOrigin-RevId: 690610094
2024-10-28 07:59:09 -07:00
kimvde
8260bb3d2e Refactor frame rate notification to release control
Frame rate change is currently notified to the release control when the
video frame processor input frame rate changes, but it should be when
the video frame processor output frame rate changes.

PiperOrigin-RevId: 688512300
2024-10-22 05:44:41 -07:00
kimvde
be8c58d51e Use Format object in VideoFrameProcessor
This is to use an existing media3 object rather than creating a new one.

PiperOrigin-RevId: 688481323
2024-10-22 03:46:03 -07:00
claincly
7335754b23 Spell out VFP as VideoFrameProcessor
PiperOrigin-RevId: 688465940
2024-10-22 02:40:22 -07:00
claincly
2a49ffcb23 Make OverlaySettings dynamic
PiperOrigin-RevId: 687269731
2024-10-18 05:43:33 -07:00
claincly
ba3d2b3fef Add a CanvasOverlay for easier drawing, and an example in demo app
PiperOrigin-RevId: 687223353
2024-10-18 02:29:43 -07:00
kimvde
38c27d45f1 Make VideoGraph and VideoFrameProcessor listener methods optional
PiperOrigin-RevId: 686833280
2024-10-17 02:38:03 -07:00
claincly
adb35ee7c4 Reword javadoc
The old javadoc is, IMO, quite hard to understand, so I simplified it a bit,
and added one example.

PiperOrigin-RevId: 685701916
2024-10-14 07:39:53 -07:00
claincly
b5680e8a65 Make OverlayEffect take a List
Otherwise, it cannot be used with Kotlin `listOf()`.

PiperOrigin-RevId: 682255423
2024-10-04 03:46:41 -07:00
dancho
7b08bedf2c Do not force EOS when decoder has produced all frames
The workaround in ExternalTextureManager.forceSignalEndOfStream
was being applied even when the decoder did output all frames, and only
the GL pipeline was slow.

This change ensures that workaround is not applied when the decoder
has already produced all output frames.

PiperOrigin-RevId: 680471587
2024-09-30 01:50:10 -07:00
ibaker
3e8ecbf564 Remove @DoNotInline annotations
This is no longer needed now our `compileSdk` implies a new-enough AGP
which does this out-lining automatically via R8. See also
https://issuetracker.google.com/345472586#comment7

There's no plan to remove the `ApiXXX` classes, but no new ones need
to be added.

PiperOrigin-RevId: 675940634
2024-09-18 04:47:39 -07:00
kimvde
2951a2599c Apply all video Composition effects to single sequence exports
PiperOrigin-RevId: 675933601
2024-09-18 04:18:55 -07:00
kimvde
a53ea621bb Stop rejecting frames later in ExternalTextureManager
If the task executor handles an available frame (task submitted in the
SurfaceTexture listener) between the call to registerInputFrame() and
the execution of the task submitted in the method (in this CL), it
should be rejected.

PiperOrigin-RevId: 672903756
2024-09-10 04:29:48 -07:00
kimvde
a1d2310170 Fix stuck player after seek
Seeking was causing the player to hang in the following scenario:
1. The surfaceTexture's onFrameAvailableListener is called in
   ExternalTextureManager to notify that a new frame is available.
2. This call submits a task on the GL thread.
3. A seek is performed and DefaultVideoFrameProcessor.flush() is called
   before the task submitted in 2 is executed.
4. DefaultVideoFrameProcessor.flush() flushes the task executor, so that
   the task submitted in 2 never gets executed.
5. Once the seek is over, the first frame is registered and rendered on
   the surface texture.
6. Playback hangs because the onFrameAvailableListener is never called
   for this new frame. This is because surfaceTexture.updateTexImage()
   was never called on the frame that became available in 1.

This fix is making sure that the task submitted in 2 always gets executed.

Issue: androidx/media#1535
PiperOrigin-RevId: 671389215
2024-09-05 08:54:55 -07:00
dancho
207684ca66 Prototype frame extraction based on analyzer mode
Make ByteBufferGlEffect public.
Build a speed test, and end to end test that verify
frames can be copied to CPU-accessible ByteBuffer

PiperOrigin-RevId: 670213343
2024-09-02 07:34:33 -07:00
dancho
dc9854cc5b Add GlRect helper class
Adds a class that represents an image rectangle
in OpenGL coordinate convention.

android.graphics.Rect puts (0, 0) as the top-left corner:
it enforces `Rect.top <= Rect.bottom` and this matches
`android.graphics.Bitmap` coordinates: docs https://developer.android.com/reference/android/graphics/Rect

This is different from OpenGL coordinates where (0, 0) is
at the bottom-left corner. I.e. GlRect.bottom <= GlRect.top: docs https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glReadPixels.xhtml

The reason for this change is to allow a public API GlRect
getScaledRegion() which selects a region of pixels of a GL texture
to be copied to CPU memory.

PiperOrigin-RevId: 669231826
2024-08-30 01:13:22 -07:00
kimvde
37561c829f Fix and refactor logic to remove all frames in ExternalTextureManager
The existing logic was not working sometimes because:

1. The repeated scheduling in releaseAllFramesFromMediaCodec was
starving the thread on which the SurfaceTexture frameAvailableListener
was called.

2. The case where a pending frame arrives on the surface after flush
finishes executing was not handled.

The consequence of both problems is that availableFrameCount ended up
being > pendingFrames.size().

PiperOrigin-RevId: 668916256
2024-08-29 06:37:20 -07:00
kimvde
8367e420ad Import correct nullable annotation
PiperOrigin-RevId: 668521379
2024-08-28 10:54:29 -07:00
dancho
5c2dc7ed4e Add ByteBufferGlEffect.Image for easier format conversion
PiperOrigin-RevId: 668506831
2024-08-28 10:22:01 -07:00
kimvde
070e8217ac Report swallowed exceptions in ExternalTextureManager
The error was swallowed if
ExternalTextureManager.removeAllSurfaceTextureFrames was throwing.

PiperOrigin-RevId: 668480565
2024-08-28 09:14:53 -07:00
dancho
c4930c4bb6 Default to OpenGL 3.0 context in DVFP
OpenGL ES 3.0 likely can be used since Android 18.
Moving to a higher version context more often can make
sharing GL context easier for apps

PiperOrigin-RevId: 667915331
2024-08-27 03:23:54 -07:00
dancho
563eb963fd Make ByteBufferConcurrentEffect asynchronous
* Changes to GlUtil to manage Pixel Buffer Objects and asynchronous
GPU -> CPU glReadPixels
* Make ByteBufferConcurrentEffect non-blocking

PiperOrigin-RevId: 667908805
2024-08-27 02:58:51 -07:00
dancho
ee93a9832e Add ByteBufferGlEffect for easier non-GPU video effects
* new ByteBufferGlEffect GlEffect that enables API users to
implement an effect that accesses video frame data via CPU-mapped ByteBuffer
* ByteBufferConcurrentEffect responsible for reading
video frame data in CPU-accessible ByteBuffer

PiperOrigin-RevId: 666375594
2024-08-22 09:18:32 -07:00
dancho
6e0e2d0cee Add QueuingGlShaderProgram for effects that run outside GL context
Implement a QueuingGlShaderProgram which queues up OpenGL frames and allows
asynchronous execution of effects that operate on video frames without a
performance penalty.

PiperOrigin-RevId: 666326611
2024-08-22 06:38:28 -07:00
claincly
8f8e48731e Add a method to disallow VFP destroying shared eglContext
Previously in MultiInputVideoGraph, each VFP would destroy the shared
eglContext, such that the same eglContext object is destroyed multiple times.

Adding a flag to disallow this.

The alternative being we could add a flag on the VFP constructor, but I think
that is too subscriptive (meaning if we later might want to add another boolean
to control another GL behaviour, multiple booleans would make the class less
reason-able), and would incur a lot of code changes at places.

PiperOrigin-RevId: 660354367
2024-08-07 05:50:32 -07:00
dancho
ddc86686b7 Experimental flag to limit the number of frames in encoder
Transformer.experimentalSetMaxFramesInEncoder controls max number
of frames in encoder.

VideoFrameProcessor now allows delayed releasing of frames to Surface,
while still using the original presentation time.

VideoSampleExporter can now configure video graphs to not render frames
automatically to output surface.

VideoSampleExporter.VideoGraphWrapper tracks how many frames are ready
to be rendered to Surface, and how many frames are already in-use by encoder.

PiperOrigin-RevId: 658429969
2024-08-01 09:33:16 -07:00
dancho
6e678e511b Enable experimentalRepeatInputBitmapWithoutResampling
Speed up image to video export by default.

PiperOrigin-RevId: 657958037
2024-07-31 04:40:29 -07:00
dancho
940e28e4db Refactor threading in FinalShaderProgramWrapper
Public methods either assert they're running GL thread, or
submit a task to run on GL thread.

Move methods to keep interface implementations together.

Add javadoc to VideoFrameProcessingTaskExecutor to clarify which
thread can call each public method.

PiperOrigin-RevId: 655978796
2024-07-25 09:23:41 -07:00
tofunmi
043de45763 Store the speed provider in timestamp adjustment
PiperOrigin-RevId: 655928480
2024-07-25 06:09:02 -07:00
dancho
7103f21da9 Use WORKING_COLOR_SPACE_DEFAULT in multi-sequence compositions
Build upon Transformer.videoFrameProcessorFactory in MultipleInputVideoGraph
Check that Transformer.videoFrameProcessorFactory is DefaultVideoFrameProcessor
for multi-input video

Fixes https://github.com/androidx/media/issues/1509

PiperOrigin-RevId: 655232381
2024-07-23 11:14:12 -07:00