137 Commits

Author SHA1 Message Date
hschlueter
e2c4fd80d3 Wrap PlaybackExceptions in TransformationExceptions.
PiperOrigin-RevId: 420032157
2022-01-11 13:30:09 +00:00
hschlueter
cdbcf9f6f2 Make TransformationException constructor private.
Only allowing TransformationExceptions to be created using the factory methods helps keeping error messages consistent. This is consistent with ExoPlaybackException.

PiperOrigin-RevId: 419841025
2022-01-11 13:25:05 +00:00
huangdarwin
79f471b59a Transformer GL: Fix rotation distortion by considering aspect ratio
Compensate for aspect ratio of input frames, so that they're applied on
rectangular frames instead of square normalized-device-coordinate frames.

This fixes distortion most visible when rotating any GL video 45°
(non-rectangular frames) or 90° (stretched frames)

Tested by rotating several landscape/portrait demo videos.
(Automated tests will follow in <unknown commit>)

PiperOrigin-RevId: 419619743
2022-01-05 12:15:35 +00:00
hschlueter
f60dc148f8 Refactor checking muxer support.
* Move checking that the output format is supported by the muxer
  from supportsFormat (which deals with the input format) to
  ensureConfigured.
* Add maps for the supported MIME types so that the muxer can
  return what MIME types it supports rather than just check a
  MIME type.

PiperOrigin-RevId: 419578165
2022-01-05 12:15:34 +00:00
hschlueter
1af1213154 Use TransformationException for GL errors.
PiperOrigin-RevId: 418820557
2022-01-05 12:15:27 +00:00
hschlueter
fe1ffdb959 Throw when inferred sample MIME type is not supported by the muxer.
This is better than silently dropping tracks as done previously. Later,
we will implement fallback to transcoding to a supported MIME type.

PiperOrigin-RevId: 418006258
2022-01-05 12:14:58 +00:00
huangdarwin
c37319c519 Transformer GL: Document lack of support for non-square pixels.
This may one day change, but at least for now, we don't intend
to support non-square pixels.

PiperOrigin-RevId: 417983516
2022-01-05 10:52:51 +00:00
ibaker
34a1f884dc Add MediaSource.Factory and deprecate MediaSourceFactory
This more closely matches the pattern we have for all implementations
except DefaultMediaSourceFactory (e.g. ProgressiveMediaSource.Factory)
and other factory interfaces like (Http)DataSource.Factory.

PiperOrigin-RevId: 417826803
2022-01-05 10:51:41 +00:00
andrewlewis
920d0c5842 Switch naming convention for shaders
Switch to using sentence-case naming convention but with one character prefixes for different types.

This is a no-op change.

PiperOrigin-RevId: 417791624
2022-01-05 10:47:35 +00:00
hschlueter
0e61f44d4d Add TransformationRequest.
PiperOrigin-RevId: 417786661
2022-01-05 10:46:36 +00:00
claincly
4706d3a59f Rename MediaCodecAdapterWrapper to Codec.
Move static factories into a separate class and make it implement an interface
that will let tests customize encoder/decoder creation.

PiperOrigin-RevId: 417610825
2022-01-05 10:43:18 +00:00
hschlueter
991a22ec75 Convert PlaybackExceptions to TransformationExceptions.
Transformer uses ExoPlayer for reading input. Apps using Transformer
do not need to know this. So, PlaybackExceptions are converted to
TransformationExceptions with the same message, cause and error code.

The corresponding IO error codes are copied from PlaybackException.

PiperOrigin-RevId: 416793741
2022-01-05 10:28:27 +00:00
hschlueter
a8dbc744db Remove ExoPlaybackException dependency from sample pipelines.
Use TransformationException for codec and audio processor
initialization problems instead.

PiperOrigin-RevId: 416765510
2022-01-05 10:26:36 +00:00
hschlueter
e094ceb079 Use C.LENGTH_UNSET for resolution parameter instead of Format.NO_VALUE.
Format.NO_VALUE should only be used for Format fields.

PiperOrigin-RevId: 416646415
2022-01-05 10:24:36 +00:00
hschlueter
cdc0e2e618 Use TransformationException for error listener parameter.
PiperOrigin-RevId: 416307600
2022-01-05 10:11:14 +00:00
hschlueter
b8ccd6197b Add TransformationException with initial subset of error codes.
TransformationException will be used for all errors that occur
during a transformation.

PiperOrigin-RevId: 416032504
2022-01-05 10:03:13 +00:00
huangdarwin
20fb153cbf Use static asserts more often.
PiperOrigin-RevId: 415529751
2022-01-05 09:53:29 +00:00
huangdarwin
edbfdd0d6c Transformer GL: Remove UnsupportedEglVersionException().
UnsupportedEglVersionException() is only used once, and seems a bit too
specific for Transformer. Also, it's possible for eglCreateContext to fail for
other reasons besides lack of support, so it wasn't always accurate when
thrown.

It is possible for devices not to support EGL version 2.0 though, per
https://source.android.com/devices/graphics/implement-opengl-es, which doesn't
specify the EGL version that must be supported.

PiperOrigin-RevId: 415489396
2021-12-10 16:02:20 +00:00
claincly
1c9f99f939 Make repetitive decode/draw.
tl;dr:
In the previous transformer, the transcoding flow is

- If a the GL's input surface (from decoder) does not have data, wait 10ms
 (DO_SOME_WORK)
- Else, make the decoder render **ONE** frame to the GL's input surface
  - Wait at least 10ms, until the frame's texture is available
  - Then process the texture

The process is quite slow, so in the new version, we do:
- If a the GL's input surface (from decoder) does not have data, wait 10ms
 (DO_SOME_WORK) **same**
- Else, make the decoder render **as many frames** to the GL's input surface
  - Process **as many** available textures in this DO_SOME_WORK cycle

PiperOrigin-RevId: 415474722
2021-12-10 16:00:56 +00:00
hschlueter
815f5da91a Keep orientation information during the transformation.
The input rotation is used to rotate the video during decoding, the
video is rotated so that it is in landscape orientation before encoding
and a rotation is added to the output format where necessary so that
the output video has the same orientation as the input.

PiperOrigin-RevId: 415301328
2021-12-10 11:24:36 +00:00
huangdarwin
df8a3dc362 GL: Misc refactoring for clarity.
PiperOrigin-RevId: 415279434
2021-12-10 11:20:51 +00:00
andrewlewis
174120a7cf Add support for showing debug info during transformation
Being able to see the output of the GL pipeline is useful for debugging. For
example, when we previously saw flakiness it would have been useful to be able
to tell quickly whether the output looked wrong without needing to run a
transformation to the end then inspect the output file, and when working on
support for HDR editing it's useful to be able to do manual testing on devices
that don't support HDR encoding (but do support decoding/processing it with
GL).

Also change the progress indicator to be linear as this looks better in the
demo app when shown next to the debug preview.

PiperOrigin-RevId: 414999491
2021-12-10 11:13:03 +00:00
kimvde
94caa8ad6c Fix re-encoding after flattening
The decoder is using the SVC NAL unit prefix data on some Samsung
devices.

PiperOrigin-RevId: 414457181
2021-12-07 17:37:31 +00:00
kimvde
5264da59b3 Various small improvements in Transformer
PiperOrigin-RevId: 414428415
2021-12-07 17:37:31 +00:00
huangdarwin
1b0742f54a Transformer GL: Create demo UI for changing resolution.
Also, add 144p as an acceptable output resolution, to allow for
a more obvious resolution difference when running the demo.

PiperOrigin-RevId: 414406664
2021-12-07 17:37:31 +00:00
hschlueter
8bd5d8bcbe Fix condition for when to use the FrameEditor.
outputHeight is the actual output height while
transformation.outputHeight could be Format.NO_VALUE
causing the FrameEditor to be used more often than
necessary in the old version.

PiperOrigin-RevId: 414304251
2021-12-07 17:37:31 +00:00
olly
f2ad8ccd3c Shorten log tags to 23 char limit
When calling Android's Log class directly, there's a LongLogTag
lint check that detects tags over the 23 char limit, however it
cannot detect long log tags in ExoPlayer due to the way that we
log via our own Log class. This commit adds @Size annotations to
enforce the same rule.

PiperOrigin-RevId: 413976364
2021-12-07 17:37:31 +00:00
andrewlewis
fdc57d2d66 Make FrameEditorTest less flaky
Increase timeout for dequeueing a frame from the codec to reduce
flakiness. At a timeout of 2 seconds there was a 2/1000 flake rate and
at 3 seconds 0/1000. Set the timeout to 5 seconds to give plenty of
leeway.

PiperOrigin-RevId: 413946915
2021-12-07 17:36:48 +00:00
hschlueter
ef1788dcea Only use a FrameEditor if editing is needed.
When no editing is needed, the OpenGL steps can be skipped.

PiperOrigin-RevId: 413884305
2021-12-07 16:45:42 +00:00
hschlueter
14b849aba8 Reduce conditional nesting.
PiperOrigin-RevId: 413682281
2021-12-07 16:42:18 +00:00
huangdarwin
58a8aceb97 Transformer GL: Apply transformation_matrix to vertex position.
Previously, transformation_matrix was incorrectly applied to
texture sampling coordinates, which led to transformations
seemingly moving in the opposite position, and an undesirable
GL_CLAMP_TO_EDGE behavior when sampling outside the edge of
the texture.

PiperOrigin-RevId: 413653360
2021-12-07 16:40:04 +00:00
andrewlewis
e077edded5 Update javadoc to reflect removal of WebM container option
It seems fine to remove the documentation about the WebM case now we are only supporting unfragmented MP4, so that new users coming to this API aren't confused about how to set the container MIME type.

PiperOrigin-RevId: 413611472
2021-12-02 11:56:42 +00:00
huangdarwin
73ed482094 Transformer GL: Create setTransformationMatrix().
Allows a transformation matrix to be input into Transformer,
to apply vertex transformations like cropping, rotation,
and other transformations built into android.graphics.Matrix.

Not building out into a VertexTransformation class yet, as
that class structure wouldn't make sense until we can modify
resolution, per TODOs.

PiperOrigin-RevId: 413384409
2021-12-02 11:56:42 +00:00
andrewlewis
a803604605 Increase transformer min API version to 21
This will remove the need to implement compat code handling very old API
versions where some symbols are not available, and it reduces the burden of
dealing with media framework issues around concurrent codec usage that are
worse on older API versions. Top apps that we've surveyed as potential users
for transformer library features are using API 21 or later.

PiperOrigin-RevId: 413341540
2021-12-02 11:56:42 +00:00
hschlueter
8105394ac2 Flip input buffer even if the end of stream is reached.
Sometimes the empty end of stream buffer has a non-zero
data limit. Calling flip first, resets the limit to the
position which is zero in these cases.

PiperOrigin-RevId: 413156455
2021-12-02 11:55:55 +00:00
andrewlewis
1b25e2f93d Add unit test for FrameEditor
The test extracts and decodes the first video frame in the test media, renders it to the frame editor's input surface and then processes data. It then reads back the output from the frame editor, converts it to a bitmap and then compares that with a 'golden' bitmap (which is just the same as the test media's first video frame).

PiperOrigin-RevId: 413131811
2021-12-02 11:55:55 +00:00
ibaker
43328d7623 Rollback of f637bb3d40
*** Original commit ***

Remove usage of @ForOverride.

Fixes the gradle compilation failures.

Gradle dependencies need revising if we want to be using this, as
checkerframework is ahead of their latest version, such that we
can't compile.

***

PiperOrigin-RevId: 412901827
2021-12-02 11:55:55 +00:00
samrobinson
d55f9876ac Make use of try with-resources to auto close file.
PiperOrigin-RevId: 412901581
2021-12-02 11:55:55 +00:00
samrobinson
dd9d87549d Create and write the TransformationResult to on-device text file.
PiperOrigin-RevId: 412856100
2021-12-02 11:55:55 +00:00
hschlueter
fb0768e0d2 Use audio passthrough if flattening is requested but not needed.
When the input is not a slow motion video, then flattening should do
nothing, so there is no need to re-encode audio.

PiperOrigin-RevId: 412443097
2021-12-02 11:55:55 +00:00
samrobinson
2ba7422da3 Move tests into a mh package.
PiperOrigin-RevId: 412438389
2021-12-02 11:55:44 +00:00
huangdarwin
60ce9ae345 Misc refactoring.
Use @VisibleForTesting and add some comments for GL code.

Refactoring change only. No functional changes intended

PiperOrigin-RevId: 412428196
2021-12-02 11:55:44 +00:00
kimvde
a520e7f559 Miscellaneous small fixes in Transformer
PiperOrigin-RevId: 412286692
2021-12-02 11:55:44 +00:00
samrobinson
2054b29089 Pull files from the device cache after a test concludes.
PiperOrigin-RevId: 412251020
2021-12-02 11:55:32 +00:00
kimvde
b7f0071e8c Rename decoderInputFormat in transformer renderers
- This format is passed to the PassthroughPipeline, which doesn't use
  any decoder.
- In most other cases where it is used, it is not relevant that this
  format will be or has been passed to the decoder. What's relevant is
  that it is the format of the input.

PiperOrigin-RevId: 412093371
2021-12-02 10:12:40 +00:00
samrobinson
e45140871e Derive test output video name from the TAG.
We need the filename of the output videos to be predictable, because
MobileHarness requires the exact filename to pull the file.

PiperOrigin-RevId: 412092347
2021-12-02 10:11:39 +00:00
huangdarwin
c18cbf1b22 Transformer: Move required Builder context to be a constructor arg.
Deprecates setContext() and moves the required Context arg into the constructor.

This way, the parameter can later be final and non-null, per the comment at:
79f03bb135/depot/google3/third_party/java_src/android_libs/media/libraries/transformer/src/main/java/androidx/media3/transformer/TranscodingTransformer.java (97L)

Also, fixes setOutputMimeType_unsupportedMimeType_throws by providing a context
in the builder, and updating the FrameworkMuxer#supportsOutputMimeType to catch
IllegalArgumentExceptions thrown by FrameworkMuxer#mimeTypeToMuxerOutputFormat.

PiperOrigin-RevId: 412053564
2021-12-02 10:09:52 +00:00
samrobinson
f637bb3d40 Remove usage of @ForOverride.
Fixes the gradle compilation failures.

Gradle dependencies need revising if we want to be using this, as
checkerframework is ahead of their latest version, such that we
can't compile.

PiperOrigin-RevId: 412004021
2021-12-02 10:07:54 +00:00
hschlueter
551a47e1fc Deduplicate transformer audio and video renderer implementations.
This change moves methods that are the same in
`TransformerAudioRenderer` and `TransformerVideoRenderer` to
`TransformerBaseRenderer`.

PiperOrigin-RevId: 411758928
2021-12-02 10:06:19 +00:00
kimvde
6adf41f03a Transformer: rename OpenGlFrameEditor to FrameEditor
PiperOrigin-RevId: 411751425
2021-12-02 10:04:27 +00:00