665 Commits

Author SHA1 Message Date
huangdarwin
c5b4cbed75 HDR: Update limited range and add full range YUV to RGB color transforms.
PiperOrigin-RevId: 467910378
(cherry picked from commit 130a536287f705ea823c9351d053f01512bf7e3c)
2022-08-16 13:33:32 +00:00
Googler
4a4bfc7b96 Avoid spinning in between intermediate texture processors.
This change adds a new method onReadyToAcceptInputFrame to
GlTextureProcesssor.InputListener and changes maybeQueueInputFrame
to queueInputFrame, removing the boolean return value.
This avoids the re-trying in ChainingGlTextureProcessorListener
by allowing it to only feed frames from the producing to the consuming
GlTextureProcessor when there is capacity.

MediaPipeProcessor still needs re-trying when processing isn't 1:1.

PiperOrigin-RevId: 466626369
(cherry picked from commit 9c366b3cfdd06cad046dd5ce1b0ecad21c5c44ba)
2022-08-10 09:56:24 +00:00
huangdarwin
b84945db62 Demo: Add legacy external storage permission for intents.
Without this permission, files in `/sdcard` or other directories cannot be read by the demo, as they're not in the transformer demo's scoped storage container.

For more information, see https://developer.android.com/training/data-storage/use-cases

Tested by uninstalling and re-installing the demo app, granting permission by
starting a transformation, and launching an intent using a local file in `/sdcard`
to start another transformation. Without this CL, this threw an error, and with
this CL it succeeded.

PiperOrigin-RevId: 466399023
(cherry picked from commit 051dee68e362b8d610a42ac01f7ed9cc5f6b894a)
2022-08-09 17:28:31 +00:00
Googler
c33a8e3d3a Split GlTextureProcessor.Listener into input/output/error listener.
This simplifies ChainingGlTextureProcessor as it now only connects a
consuming and a producing GlTextureProcessor rather than a previous,
current, and next GlTextureProcessor.

Also use default no-op implementations of the listeners in
SingleFrameGlTextureProcessor and MediaPipeProcessor to avoid
null-checks.

PiperOrigin-RevId: 466301642
(cherry picked from commit a2166a414212a4e10c31b72dfa21ff45367ee31a)
2022-08-09 10:05:14 +00:00
Googler
03b490b47f Fix ConcurrentHashMap usage in demo MediaPipeProcessor.
PiperOrigin-RevId: 465563540
(cherry picked from commit 6e4fc4752248f1a1d233dea041305718cae08cd0)
2022-08-05 14:56:54 +00:00
Googler
db2545b8a1 Use multiple output frames in transformer MediaPipe demo pre API 23.
PiperOrigin-RevId: 465545764
(cherry picked from commit 6da0a3543491a9d9bb3dbfaf1b203a04f7a19f5c)
2022-08-05 12:58:48 +00:00
Googler
89a2685052 Move effects functionality out of transformer to effects module.
PiperOrigin-RevId: 465038852
(cherry picked from commit 707b0618384db17f6d9d4947a445c0eed1c9c630)
2022-08-03 13:19:15 +00:00
Googler
63db89793a Move FrameProcessor and related interfaces to common.
This will allow effects preview in ExoPlayer to use the
Effect and FrameProcessor interface (and the interfaces
they depend on) without depending on transformer or the
future effects module.

PiperOrigin-RevId: 464060047
(cherry picked from commit 06d41c2775137158f831a1b2f19f137efb1e08b0)
2022-07-29 12:54:30 +00:00
leonwind
21c0eb3d68 Add slider option for contrast in demo app
PiperOrigin-RevId: 464050072
(cherry picked from commit 9df0d40583f868ec923a066bbe2609c7ba862760)
2022-07-29 11:30:44 +00:00
Googler
5c7dcf42a0 Add Effect marker interface.
This allows non-GL effects to be passed to custom FrameProcessor
implementations.

PiperOrigin-RevId: 463696384
(cherry picked from commit 66dde42989dbc8fedeee59897a05644d86240cf6)
2022-07-27 22:40:20 +00:00
Googler
3483131a88 Replace Size with Pair in effects.
Size requires API 21. Using Pair instead will allow effects to be
used from API 18 during previewing once they are moved out of
transformer.

PiperOrigin-RevId: 463206474
(cherry picked from commit b994f8bfa06c82fbfe96044b986cd7b8d243acdd)
2022-07-25 23:39:59 +00:00
hschlueter
b9f6df79cb Allow stream offset passed to GlEffectsFrameProcessor to change.
This is needed for applying effects to a playlist.

The effects are applied based on the presentation time of the
frame in its corresponding media item and the offset is added
back before encoding.

Each time the offset changes, end of input stream is signalled
to the texture processors. This is needed because the texture
processors can expect monotonically increasing timestamp within
the same input stream but when the offset changes, the timstamps
jump back to 0.

PiperOrigin-RevId: 462714966
(cherry picked from commit 46ab06b816d93c2a034c182552fa4483a6d82cba)
2022-07-22 23:18:55 +01:00
huangdarwin
83bebd3339 HDR: Implement HLG EOTF and OETF.
This allows us to use BT.2020 RGB linear for intermediate shaders, which also
allows us to re-enable PeriodicVignetteProcessor, which should work properly in
linear color-spaces.

Manually tested by adding a GlEffectsWrapper, and confirming that HLG HDR editing still looks correct.

PiperOrigin-RevId: 462265821
(cherry picked from commit 1ecf1eb7bfdd469fe855edf6126b2822b52ff07f)
2022-07-21 00:24:41 +00:00
olly
8a848db2fb Add ContrastProcessor for contrast adjustments.
PiperOrigin-RevId: 462232813
(cherry picked from commit 7ef41c73218ec70ee9a5c372369d308273fddd8b)
2022-07-20 21:38:10 +00:00
huangdarwin
76093e25db HDR: Use FP16 color representation for texture processors.
* Introduced `useHdr` for `GlEffect#toGlTextureProcessor`, so
  `TextureProcessor` implementations can decide how to handle HDR.
* Creating FP16 color textures for HDR input.

Tested via manual testing, adding a no-op GlEffectWrapper to the transformation to
force use of intermediate textures, adding a linear ramp to the fragment shader,
and trying to ascertain that there's a real reduction in posterization when
switching from 4-bit to 8-bit unsigned bytes, and again from 8-bit unsigned bytes
to 16-bit floating point.

PiperOrigin-RevId: 461613117
(cherry picked from commit f67c1a73f443f411771676b761ceb03e7a0d48e4)
2022-07-18 14:21:17 +00:00
andrewlewis
ce3cdf8577 Update demo HDR10 video URL
The old URL doesn't correctly signal the HDR10 color info in the container.

The new URL signals ST2084 (PQ) transfer function and BT.2020 color space as expected.

PiperOrigin-RevId: 461560107
(cherry picked from commit 405be80fe5aed5cbc315a128010e6e6ecd7c2c73)
2022-07-18 08:51:54 +00:00
hschlueter
25ece32dda Move DebugViewProvider out of Transformer class.
The GlEffectsFrameProcessor that will be part of the effects module
uses the DebugViewProvider. So it does not make sense for it
to be an inner interface of Transformer.

PiperOrigin-RevId: 458014932
(cherry picked from commit f41e6796ce39469f9fc3a844ec88725ab56d3356)
2022-06-29 17:56:53 +00:00
hschlueter
9ad2d7123e Rename setVideoFrameEffects to setVideoEffects.
PiperOrigin-RevId: 457023382
(cherry picked from commit 20d220193e4051811e307b67a7e631b290449e23)
2022-06-24 17:04:45 +01:00
samrobinson
1ba723a89f Add a Builder for DefaultEncoderFactory.
PiperOrigin-RevId: 456728032
(cherry picked from commit 19bdff96ba9e053110bd701724c671ac10ae7cef)
2022-06-23 11:37:19 +01:00
hschlueter
6edd1d2a2f 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
(cherry picked from commit e25bf811959baf1066ba18adc37e8bbdaad4791a)
2022-06-22 17:16:54 +01:00
hschlueter
f96a6c71b8 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
(cherry picked from commit 3a966916545f92c5ce08a640c912054ede215152)
2022-06-22 12:03:41 +01:00
hschlueter
6cc442debf 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
(cherry picked from commit a444bb8ca2d59650811ea3f1c1274140b0be86c6)
2022-06-20 13:50:16 +01:00
hschlueter
e4605583bc 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
(cherry picked from commit 3f718b0d10e1d577620cca9ec76d0af38efc542c)
2022-06-09 18:22:39 +00:00
hschlueter
9ecf722824 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
(cherry picked from commit dc668f2b59bb0df12cdbb77cb88072babe0218eb)
2022-06-09 17:53:39 +00:00
hschlueter
df6c8f1d8a 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
(cherry picked from commit 0b37d860d13df1ac638f5a75c7af32c840e02956)
2022-06-08 09:44:25 +00:00
hschlueter
23b0610a37 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
(cherry picked from commit 54d44d38b6bb4a7a5dc69ed8cfd878aebe46f4b4)
2022-05-31 09:36:18 +00:00
olly
3748cc8a82 Fix handling of content URIs by demo apps
PiperOrigin-RevId: 453510883
(cherry picked from commit 21ad8cfd6b55096029556b5c7fe226891173a8fb)
2022-06-07 20:23:51 +00:00
andrewlewis
6e735ac297 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
(cherry picked from commit 14ed32c68f091328bb5feaa472b4bd359e11f41d)
2022-05-31 14:06:59 +00:00
bachinger
49c5e324fd Remove deprecated calls
#minor-release

PiperOrigin-RevId: 452006137
(cherry picked from commit 5460ac8e60095131dfd3ec0c6ec01d05a30cc43b)
2022-05-31 13:50:40 +00:00
hschlueter
541460a01d 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 17:11:57 +00:00
hschlueter
d37cf34131 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 17:01:17 +00:00
ibaker
b8769b2717 Fix some inconsistencies in the MediaItem API
* Rename (via deprecation)
  `MediaItem.DrmConfiguration.Builder#forceSessionsForAudioAndVideoTracks`
  to `setForceSessionsForAudioAndVideoTracks`. This is more consistent
  with existing 'force' method names both in this class and in
  `TrackSelectionParameters.Builder`.
* Add missing `@Nullable` annotation to the parameter for
  `MediaItem.SubtitleConfiguration.Builder#setMimeType`. This annotation
  is already present on the `MediaItem.SubtitleConfiguration#mimeType`
  field that this setter corresponds to.

PiperOrigin-RevId: 450941336
2022-05-26 13:07:37 +00:00
ibaker
e39a324b19 Add DefaultMediaSourceFactory.setDataSourceFactory
Also add this to the stable API instead of the constructor that takes
`DataSource.Factory`.

PiperOrigin-RevId: 450414119
2022-05-23 13:26:05 +01:00
andrewlewis
4277ac3835 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 12:23:50 +01:00
andrewlewis
bea17b4357 Attempt to load OpenCV when loading MediaPipe
PiperOrigin-RevId: 449227706
2022-05-24 11:33:49 +01:00
andrewlewis
d6dc3c5351 Fix initialization of media pipe processors with assets
PiperOrigin-RevId: 449221156
2022-05-24 11:30:29 +01:00
andrewlewis
578afa883d 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 11:20:08 +01:00
ibaker
938728ce00 Add DefaultMediaSourceFactory.{set,clear}LocalAdInsertionConfig
Deprecate the setAdsLoaderProvider and setAdViewProvider methods these
replace.

PiperOrigin-RevId: 448251423
2022-05-24 10:59:01 +01:00
hschlueter
f08fdf6ab2 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-09 14:46:53 +01:00
hschlueter
e89189e35f 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 18:02:20 +01:00
hschlueter
ff1305cd19 Remove redundant attribute from matrix transformation vertex shader.
The texture coordinates can be derived from the frame coordinates.

PiperOrigin-RevId: 446770538
2022-05-05 19:24:44 +01:00
andrewlewis
ee3a183041 Add frame processor based on MediaPipe to demo
PiperOrigin-RevId: 446432695
2022-05-04 13:48:56 +01:00
ibaker
8bb11f3f2b Migrate usages of the deprecated TrackSelectionParameters.CREATOR
PiperOrigin-RevId: 446400192
2022-05-04 10:13:35 +01:00
hschlueter
0bba5c6329 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-03 18:58:59 +01:00
ibaker
eb1dc508a5 Opt some more bits of the main demo app into the unstable API
PiperOrigin-RevId: 446161354
2022-05-09 13:30:13 +01:00
ibaker
1809a0b9f9 Migrate usages from C.TYPE_* to C.CONTENT_TYPE_*
PiperOrigin-RevId: 446156308
2022-05-09 12:00:38 +01:00
hschlueter
76627d7138 Introduce GlEffect interface for effect specification.
PiperOrigin-RevId: 446143537
2022-05-09 11:53:52 +01:00
ibaker
b0df946f67 Use cronet for DRM requests in the main demo app
This ensures that both content and licenses are requested using the
same HTTP stack.

#minor-release

PiperOrigin-RevId: 445378940
2022-05-09 11:34:42 +01:00
ibaker
a840f9732f Add copies of PlayerControlView's public listeners to PlayerView
Developers are expected to (eventually) only use methods on
PlayerView (and not PlayerControlView) to interact with the UI
controller.

PiperOrigin-RevId: 445361488
2022-05-09 11:21:14 +01:00
huangdarwin
c67d69100d Transformer: Misc nits
* Add a /* paramName= */ comment
* Remove an unnecessary comma.
* Remove extra "internal " for a b/### link

PiperOrigin-RevId: 445169649
2022-05-09 11:01:12 +01:00