168 Commits

Author SHA1 Message Date
claincly
651fa0dbb7 Apply suggested AVC profile depending on the API version.
PiperOrigin-RevId: 424322341
2022-01-28 09:19:29 +00:00
kimvde
793a0993c5 Various nits in Transformer
PiperOrigin-RevId: 423822317
2022-01-25 19:53:21 +00:00
hschlueter
2f4ef89510 Delete old TODO.
This was resolved in 081700f72b where the
Video/AudioSamplePipeline call this method before calling
the FallbackListener.

PiperOrigin-RevId: 423284258
2022-01-25 19:33:44 +00:00
hschlueter
4cf9106581 Transcode to a muxer-supported sample MIME type.
If the output sample MIME type is inferred from the input
but is not supported by the muxer, we fallback to transcoding
to a supported sample MIME type.
The audio and video renderers need to make sure not to select the PassthroughSamplePipeline for this case. Which sample MIME type
to choose is decided by the EncoderFactory.

PiperOrigin-RevId: 423272812
2022-01-25 19:22:23 +00:00
hschlueter
081700f72b Communicate sample MIME type changes to FallbackListener.
We may fall back to a different sample MIME type because
a) the sample MIME type inferred from the input is not supported
by the muxer or b) no encoders are available for the the requested
sample MIME type.

PiperOrigin-RevId: 422849036
2022-01-25 19:01:49 +00:00
hschlueter
6212e6c8ee Make defensive copies of the transformation matrix.
TransformationRequest is otherwise immutable, so if we modify the
transformationMatrix in place (done before this cl) this may cause
confusing behaviour for apps when they reuse a TransformationRequest.

PiperOrigin-RevId: 422822916
2022-01-25 18:53:48 +00:00
hschlueter
dbc4dcf0f2 Merge muxer and encoder output format error codes.
After implementing fallback, it won't always be possible to
differentiate between muxer and encoder as the cause of an output
format not being supported.

PiperOrigin-RevId: 422780443
2022-01-25 18:41:34 +00:00
claincly
9942d42f69 Support encoding square videos.
PiperOrigin-RevId: 422585277
2022-01-25 18:33:06 +00:00
claincly
e0aa61681d Throw NPE instead of IAE when sampleMimeType is null.
PiperOrigin-RevId: 422550627
2022-01-25 18:29:00 +00:00
claincly
9b3483ec5f Use encoder output format for configuring the Encoder.
This CL implements fixing the input format to the encoder spec. Fixed
parameters include:
- MIME type
- Profile & level
- Resolution
- frame rate, and
- bitrate

PiperOrigin-RevId: 422513738
2022-01-25 18:14:41 +00:00
huangdarwin
bb0a641555 Transformer GL: Add image diff in test.
PiperOrigin-RevId: 422392959
2022-01-25 18:06:21 +00:00
huangdarwin
41be22ef65 Transformer GL: Add pixel tests for transformation.
Rotation, translation, and scale tests on a normal video.

PiperOrigin-RevId: 422383176
2022-01-25 18:02:30 +00:00
hschlueter
4145273bc4 Revise TransformationRequest MIME type validation.
PiperOrigin-RevId: 422333929
2022-01-17 14:36:18 +00:00
hschlueter
2e7ca0b7b8 Add javadoc to TransformationRequest's public fields.
PiperOrigin-RevId: 422325859
2022-01-17 14:31:40 +00:00
hschlueter
f747fed874 Add FallbackListener.
The app will be notified about fallback using a callback on
Transformer.Listener. Fallback may be applied separately for
the audio and video options, so an intermediate internal
FallbackListener is needed to accumulate and merge the track-specific
changes to the TransformationRequest.

PiperOrigin-RevId: 421839991
2022-01-17 14:01:10 +00:00
huangdarwin
f216fa2042 Transformer GL: Clarify variables and comments.
Simplifying and clarifying variables, and adding comments.

Tested by confirming demo-gl and demo-transformer both
correctly display videos

PiperOrigin-RevId: 421792079
2022-01-14 15:34:09 +00:00
hschlueter
80851807f2 Use specific error code for exceptions during encoding/decoding.
After this change exceptions throw by MediaCodec during
encoding/decoding will result in TransformationExceptions with
ERROR_CODE_ENCODING_FAILED/ERROR_CODE_DECODING_FAILED.
Before this change ERROR_CODE_FAILED_RUNTIME_CHECK was used.

PiperOrigin-RevId: 421560396
2022-01-14 15:09:52 +00:00
huangdarwin
05924eaa52 Transformer GL: Add pixel test instructions for physical devices
Expected images are taken on emulators, so a larger acceptable
difference from expected images must be accepted on physical devices.

PiperOrigin-RevId: 421543441
2022-01-14 15:06:10 +00:00
samrobinson
4647a747ca Uncomment line.
Accidentally commented out the Ignore annotation.

PiperOrigin-RevId: 421304369
2022-01-14 14:47:04 +00:00
samrobinson
d18c572d24 Add a Builder for TransformationResult.
PiperOrigin-RevId: 421278099
2022-01-14 14:43:10 +00:00
hschlueter
f8d84eec59 Allow multiple Transformer listeners to be registered.
Multiple listeners can be added to Transformer and its builder.
All or specific listeners can also be removed.

PiperOrigin-RevId: 421047650
2022-01-14 14:39:20 +00:00
hschlueter
bf32ae50d7 Remove MediaCodecAdapter dependency from Transformer.
Codec and its factories can use MediaCodec directly as for API >= 21,
the SynchronousMediaCodecAdapter methods used in Codec just correspond
to a single MediaCodec call each so there is no reason to have another
wrapping layer.

PiperOrigin-RevId: 421041177
2022-01-14 14:35:37 +00:00
hschlueter
a93e8cc620 Update Muxer exception javadoc to match MuxerWrapper.
PiperOrigin-RevId: 421039869
2022-01-14 14:31:41 +00:00
hschlueter
6888a791f0 Add error code and exception type for muxing failures.
Exceptions thrown by MediaMuxer are converted MuxerExceptions
and later to TransformationExceptions with ERROR_CODE_MUXING_FAILED.

PiperOrigin-RevId: 421033721
2022-01-14 14:27:51 +00:00
claincly
d59cfb736a Replace static method with a static field.
PiperOrigin-RevId: 420307694
2022-01-10 12:42:34 +00:00
hschlueter
8f8cde661f Refactor AudioSamplePipeline configuration.
The encoder and sonic are now set up in the constructor rather
than in a configuration method called from processData(). This
is more similar to VideoSamplePipeline and reduces null checks.

PiperOrigin-RevId: 420260526
2022-01-07 16:53:52 +00:00
hschlueter
6c6f91a3d9 Misc small fixes in Transformer.
PiperOrigin-RevId: 420056876
2022-01-07 16:50:00 +00:00
hschlueter
dfcb906d84 Wrap PlaybackExceptions in TransformationExceptions.
PiperOrigin-RevId: 420032157
2022-01-07 16:39:09 +00:00
hschlueter
e8843b8504 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-07 16:22:42 +00:00
huangdarwin
34ed8e2b5f 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:37:16 +00:00
hschlueter
54130bf0bd 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:32:21 +00:00
hschlueter
47f4d90515 Use TransformationException for GL errors.
PiperOrigin-RevId: 418820557
2022-01-04 17:17:29 +00:00
hschlueter
8b11902752 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-04 14:00:44 +00:00
huangdarwin
624338ccbd 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-04 13:06:39 +00:00
ibaker
5e8d1eb7f3 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-04 12:51:47 +00:00
andrewlewis
ad7c9e25a4 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-04 12:32:33 +00:00
hschlueter
4240da5966 Add TransformationRequest.
PiperOrigin-RevId: 417786661
2022-01-04 12:27:53 +00:00
claincly
bc891273b2 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
2021-12-21 17:22:17 +00:00
hschlueter
f2d337c33d 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
2021-12-20 12:40:22 +00:00
hschlueter
8bb53b409a Remove ExoPlaybackException dependency from sample pipelines.
Use TransformationException for codec and audio processor
initialization problems instead.

PiperOrigin-RevId: 416765510
2021-12-20 12:33:13 +00:00
hschlueter
66adeabb1b 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
2021-12-16 10:20:46 +00:00
hschlueter
5bd22c3ab7 Use TransformationException for error listener parameter.
PiperOrigin-RevId: 416307600
2021-12-14 17:47:23 +00:00
hschlueter
9cdcc58770 Add TransformationException with initial subset of error codes.
TransformationException will be used for all errors that occur
during a transformation.

PiperOrigin-RevId: 416032504
2021-12-14 10:30:35 +00:00
huangdarwin
e01ef47db9 Use static asserts more often.
PiperOrigin-RevId: 415529751
2021-12-13 12:17:07 +00:00
huangdarwin
7d93f2d40c 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 17:25:53 +00:00
claincly
18248733cd 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 17:25:53 +00:00
hschlueter
f3d76e9e2f 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 17:25:53 +00:00
huangdarwin
daa08535ac GL: Misc refactoring for clarity.
PiperOrigin-RevId: 415279434
2021-12-10 16:54:35 +00:00
andrewlewis
9676d548c3 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 16:35:06 +00:00
kimvde
458e4b7397 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:44:54 +00:00