199 Commits

Author SHA1 Message Date
hschlueter
69ab79418e Use GlTextureProcessor to avoid redundant copy in MediaPipeProcessor.
After this change GlEffects can use any GlTextureProcessor not just
SingleFrameGlTextureProcessor.
MediaPipeProcessor now implements GlTextureProcessor directly which
allows it to reuse MediaPipe's output texture for its output texture
and avoids an extra copy shader step.

PiperOrigin-RevId: 456530718
2022-06-27 10:37:35 +01:00
hschlueter
555ab97e34 Support chaining async GlTextureProcessors in FrameProcessorChain.
After this change, FrameProcessorChain chains any GlTextureProcessors
instead of only SingleFrameGlTextureProcessors.

The GlTextureProcessors are chained in a bidirectional manner using
ChainingGlTextureProcessorListener to feed input and output related
events forward and release events backwards.

PiperOrigin-RevId: 456478414
2022-06-27 10:36:51 +01:00
hschlueter
931562c243 Add option to disable debug preview.
This is useful for testing Transformer in the same way as it is used
in tests and to see only the real transformation time.

PiperOrigin-RevId: 456058466
2022-06-27 10:33:40 +01:00
hschlueter
a105d033a7 Check targetSdkVersion for frame dropping workaround.
Based on
https://developer.android.com/reference/android/media/MediaCodec#using-an-output-surface,
frame dropping behaviour depends on the target SDK version.
After this change transformer will only use
MediaFormat#KEY_ALLOW_FRAME_DROP if both the target and system SDK
version are at least 29 and default to its pre 29 behaviour where each
decoder output frame must be processed before a new one is rendered
to prevent frame dropping otherwise.

Also remove deprecated Transformer.Builder constructor without a
context and the context setter.

PiperOrigin-RevId: 453971097
2022-06-09 18:48:45 +00:00
hschlueter
cc1f32d094 Make GlUtil.GlException checked and remove flag to disable it.
Transformer always enabled glAssertionsEnabled, so there should
be no functional change.

ExoPlayer previously disabled glAssertionsEnabled, so GlUtil logged
GlExceptions instead of throwing them. The GlExceptions are now
caught and logged by the callers so that there should also be no
functional change overall.

This change also replaces EGLSurfaceTexture#GlException with
GlUtil#GlException.

PiperOrigin-RevId: 453963741
2022-06-09 18:47:46 +00:00
hschlueter
457f446114 Implement default GlTextureProcessor in SingleFrameGlTextureProcessor.
SingleFrameGlTextureProcessor is now an abstract class containing a
default implementation of the more flexible GlTextureProcessor interface
while still exposing the same simple abstract methods for single frame
processing it previously did.

FrameProcessorChain and GlEffect will be changed to use
GlTextureProcessor in follow-ups.

PiperOrigin-RevId: 453633000
2022-06-09 17:41:09 +00:00
olly
96274bfd98 Fix handling of content URIs by demo apps
PiperOrigin-RevId: 453510883
2022-06-09 17:38:11 +00:00
andrewlewis
208a9114a9 Create withMediaPipe variant only if AAR is present
This should fix running `./gradlew clean test` if MediaPipe hasn't been built, for example.

PiperOrigin-RevId: 452033698
2022-05-31 13:55:58 +00:00
hschlueter
87ab96d352 Move program initialization to texture processor constructor.
Once the more advanced GlTextureProcessor interface exists,
it will be possible to change the output size of a GlTextureProcessor
between frames. To keep the re-configuration based on the frame sizes
minimal, things indepedent of the frame size, such as the GlProgram,
can be initialized in the constructor.

PiperOrigin-RevId: 451997584
2022-05-31 10:43:47 +00:00
hschlueter
fe3831c5b4 Fix handling clipping in transformer renderers.
Decode-only video frames (needed when the frame at / first frame after the
clipping start is not a key frame) need to be decoded but not passed to
the frame processor chain or encoder.

The clipping start offset needs to be removed from the frame timestamps
in the passthrough and video pipelines.
There are no changes needed for this in the audio pipeline, as it doesn't
use the input timestamps -- it uses its own timestamps derived from the
buffer sizes instead.

Also add demo option to try this out.

#minor-release

PiperOrigin-RevId: 451353609
2022-05-30 16:34:38 +00:00
hschlueter
0eaf3d30c8 Rename GlFrameProcessor to SingleFrameGlTextureProcessor.
Also update names of implementations to match design doc.
In follow-ups, SingleFrameGlTextureProcessor will become
an abstract implementation of a new GlTextureProcessor
interface.

Texture processor makes sense as it processes OpenGL textures.
The term frame processor will be used for something else in
follow-ups.

PiperOrigin-RevId: 451142085
2022-05-30 16:31:13 +00:00
andrewlewis
0fa0735935 Reorder demo samples
Put cloud storage samples at the top to avoid having a sample at the top of the list where we don't control the server.

Also update labels not to mention progressive container type, as it's irrelevant for Transformer, which always transmuxes even if it doesn't transcode.

#ame-bug-week

PiperOrigin-RevId: 450403784
2022-05-24 11:09:55 +01:00
andrewlewis
a9bdd6e2e9 Attempt to load OpenCV when loading MediaPipe
PiperOrigin-RevId: 449227706
2022-05-24 10:51:36 +01:00
andrewlewis
d8caa2b4c1 Fix initialization of media pipe processors with assets
PiperOrigin-RevId: 449221156
2022-05-24 10:50:41 +01:00
andrewlewis
66b3527a22 Fix demo app crash when media pipe isn't loaded
The toast message about media pipe not loading needs to be shown on the main
(UI) thread.

PiperOrigin-RevId: 449199285
2022-05-24 10:47:57 +01:00
hschlueter
63dcdf5803 Add listener for FrameProcessingExceptions.
This listener replaces
FrameProcessorChain#getAndRethrowBackgroundExceptions.
The listener uses a new exception type FrameProcessingException
separate from TransformationException as the frame processing
components will be made reusable outside of transformer soon.

PiperOrigin-RevId: 447455746
2022-05-10 17:47:22 +01:00
hschlueter
2e544224c2 Fix GlUtil vector size constant name.
This constant is used for https://docs.gl/es2/glVertexAttribPointer
which takes the number of components per generic vertex attribute
(meaning the size of the individual coordinate vectors here) not the
number of attributes (the number of vertices that the old constant
name referred to).

PiperOrigin-RevId: 447427241
2022-05-10 17:42:39 +01:00
hschlueter
e9919f6da1 Remove redundant attribute from matrix transformation vertex shader.
The texture coordinates can be derived from the frame coordinates.

PiperOrigin-RevId: 446770538
2022-05-09 11:01:33 +01:00
andrewlewis
e6518126ac Add frame processor based on MediaPipe to demo
PiperOrigin-RevId: 446432695
2022-05-09 10:56:08 +01:00
hschlueter
c94035278c Separate matrix effect specification and implementation.
This change splits AdvancedFrameProcessor into 4 files:
- MatrixTransformationFrameProcessor for the GlFrameProcessor
  implementation
- MatrixTransformation and GlMatrixTransformation for the GlEffect
  specification
- MatrixUtils for the static matrix helpers

PiperOrigin-RevId: 446236384
2022-05-09 10:51:14 +01:00
hschlueter
b410a922fe Introduce GlEffect interface for effect specification.
PiperOrigin-RevId: 446143537
2022-05-09 10:44:30 +01:00
huangdarwin
0de9955eb2 Transformer: Misc nits
* Add a /* paramName= */ comment
* Remove an unnecessary comma.
* Remove extra "internal " for a b/### link

PiperOrigin-RevId: 445169649
2022-05-09 10:30:18 +01:00
hschlueter
6312cfb221 Fix PeriodicVignetteFrameProcessor javadoc.
The parameter was removed in a previous CL but wasn't removed
from the javadoc yet.

PiperOrigin-RevId: 444879675
2022-05-09 10:23:30 +01:00
huangdarwin
4cf1207c0c Transformer Demo: Add video with pixelWidthHeightRatio != 1.
This can allow apps to test and demonstrate support for videos with
pixelWidthHeightRatio != 1.

PiperOrigin-RevId: 444815182
2022-05-09 10:17:19 +01:00
hschlueter
5248bbb882 Add context param to GlFrameProcessor initialize().
PiperOrigin-RevId: 442826391
2022-04-26 14:46:24 +01:00
huangdarwin
d629e45cfa Transformer Demo: Add short test video
Add a very short (1 second) video, so that some manual tests / prototyping,
including tests for the start and end of a video, encoder selection, or
changes applied to frames, can finish quickly.

PiperOrigin-RevId: 441756901
2022-04-26 14:38:36 +01:00
hschlueter
f25c912c72 Rename GlFrameProcessor updateProgramAndDraw to drawFrame.
What a minimal implementation should include is now explained in the
interface javadoc while the method name reflects what the method does.

PiperOrigin-RevId: 441432059
2022-04-26 14:34:11 +01:00
hschlueter
f3b80fd54d Add bitmap overlay effect to transformer demo.
The new demo GlFrameProcessor is based on BitmapOverlayVideoProcessor
from the gl-demo. The demo-only GlFrameProcessor can be deleted once
Transformer supports this functionality.

PiperOrigin-RevId: 440059735
2022-04-26 14:15:31 +01:00
hschlueter
f5792dab92 Add periodic dimming effect to transformer demo.
PeriodicDimmingFrameProcessor is an example of how a custom fragment
shader can be used to apply color changes that change over time.

PiperOrigin-RevId: 439840609
2022-04-26 14:08:55 +01:00
hschlueter
c235e4f447 Add matrix provider for AdvancedFrameProcessor and examples in demo.
The matrix provider allows the transformation matrix to be updated
for each frame based on the timestamp.

The following example effects using this were added to the demo:
* a zoom-in transition for the start of the video,
* cropping a rotating rectangular frame portion,
* rotating the frame around the y-axis in 3D.

PiperOrigin-RevId: 439791592
2022-04-26 14:06:36 +01:00
huangdarwin
59f87a5134 Transformer Demo: Disable SDR button for API <31.
This makes it more clear to users of the demo that this is only available under API 31.

PiperOrigin-RevId: 439358674
2022-04-06 11:57:58 +01:00
huangdarwin
f6808c9645 Transformer Demo: Open source previously-internal demo video files.
PiperOrigin-RevId: 439267827
2022-04-06 11:52:58 +01:00
andrewlewis
d2a9419ad3 Add support for requesting color transfer to SDR
From Android T onwards `MediaCodec` supports requesting tone-mapping down to
SDR. Add an option to request this behavior and document that it isn't
supported before T. Also add an option in the demo app to try it out.

Tested manually on a prerelease build.

PiperOrigin-RevId: 437765325
2022-04-06 11:10:06 +01:00
huangdarwin
6858fe9116 Transformer Demo: Add 8k24fps video option.
This can help allow Transformer be more aware of issues in high-res videos.

PiperOrigin-RevId: 437313282
2022-04-06 11:04:52 +01:00
huangdarwin
2a14e3c604 FrameProcessor: Add a ScaleToFitFrameProcessor builder.
This allows us to input scale and rotation in an easier-to-use manner.

PiperOrigin-RevId: 436175982
2022-03-21 12:08:18 +00:00
hschlueter
cf85d1bdc8 Only allow HEVC output MIME selection in demo for API>=24.
The muxer doesn't support HEVC below API 24. The is documented in
the TransformationRequest javadoc and the Transformer.Builder will
throw if HEVC is requested below API 24 so the option should not
be part of the demo for those devices.

#mse-bug-week

PiperOrigin-RevId: 429343805
2022-02-18 14:56:25 +00:00
samrobinson
061aac7ab2 Add new public 4k60 portrait video to the demo application.
#mse-bug-week

PiperOrigin-RevId: 429323642
2022-02-18 14:52:48 +00:00
hschlueter
61354497e3 Add enable fallback option to transformer demo.
Also invert disableFallback parameter in DefaultEncoderFactory
to enableFallback. Fallback is still enabled by default.

PiperOrigin-RevId: 429253266
2022-02-17 14:59:32 +00:00
kimvde
f8d8bfb664 Handle player release timing out in transformer
- The resources were released twice before, which is not necessary since
  the MSG_RELEASE message is already in the internal player queue.
- The demo app was failing because the stop watch was stopped in
  onTransformationError after being reset.

#minor-release
#mse-bug-week

PiperOrigin-RevId: 428794426
2022-02-17 11:52:23 +00:00
huangdarwin
78b461f94c Transformer GL: Update TODOs.
Document some suboptimal things, and remove TODOs that were
fixed already or no longer relevant. Comment-only change.

PiperOrigin-RevId: 428749344
2022-02-17 11:52:23 +00:00
andrewlewis
1afba9676e Fix debug frame showing through player on old devices
PiperOrigin-RevId: 428524300
2022-02-17 10:38:13 +00:00
andrewlewis
6adf2f8c91 Improve transformer activity layout
On Samsung S21 with light theme the debug labels weren't showing up because the player view was visible (with a black background) while the transformation was in progress, matching the debug label text color. Hide the player view until the transformation is complete to fix this.

Also tweak the layout slightly to add space between the card border and the labels.

#mse-bug-week

PiperOrigin-RevId: 428455824
2022-02-17 10:31:56 +00:00
huangdarwin
b5ed01d479 Transformer GL: Implement auto-scaling to preserve input frame.
PiperOrigin-RevId: 427982223
2022-02-17 10:21:59 +00:00
samrobinson
403d92a4d4 Output from the Transformer the average audio & video bitrates.
PiperOrigin-RevId: 426956151
2022-02-08 10:27:15 +00:00
huangdarwin
ab0cbbea47 Transformer Demo: Remove unneeded external storage permission
Tested by confirming transformations still work and write to a output file in a
scoped-storage directory on a:
* Nexus 6P API 23 emulator
* Google Pixel 4 API 31 physical device

PiperOrigin-RevId: 425644266
2022-02-01 18:23:39 +00:00
hschlueter
aec92606a8 Make transformer demo configuration options scrollable.
On devices with a smaller screen / low resolution not all
options fit, so scrolling is needed.

PiperOrigin-RevId: 425635224
2022-02-01 18:22:27 +00:00
andrewlewis
dd83eca7d4 Add support for experimenting with HDR
- Add a checkbox in the demo app to enable experimental HDR editing.
- Add an `experimental_` method to `TransformationRequest` to enable HDR editing.
- Add fragment/vertex shaders for the experimental HDR pipeline. The main difference compared to the existing shaders is that we sample from the decoder in YUV rather than RGB (because the YUV -> RGB conversion in the graphics driver is not precisely defined, so we need to do this to get consistent results), which requires the use of ES 3, and then do a crude YUV -> RGB conversion in the shader (ignoring the input color primaries for now).
- When HDR editing is enabled, we force using `FrameEditor` (no passthrough) to avoid the need to select another edit operation, and use the new shaders. The `EGLContext` and `EGLSurface` also need to be set up differently for this path.

PiperOrigin-RevId: 425570639
2022-02-01 14:30:16 +00:00
andrewlewis
195d05dabd Switch from valueOf to parse methods
This fixes some warnings that show up in Android Studio (due to using methods
that autobox unnecessarily).

PiperOrigin-RevId: 424892352
2022-02-01 14:08:57 +00:00
andrewlewis
ce4a028829 Publish the transformer demo app
PiperOrigin-RevId: 424850283
2022-01-28 16:48:06 +00:00