823 Commits

Author SHA1 Message Date
huangdarwin
465301da7c MediaFormatUtil: Reduce Color API 29 restriction to API 24.
Implement getMediaFormatInteger, a helper method simulating mediaformat.getInteger(name, defaultValue).

This reduces the API 29 restriction from MediaFormatUtil.getColorInfo to API 24, in
particular removing the method-based restriction to a constant-based restriction,
so that we can reduce usage of the API 29 class.

This also allows us to slightly simplify prior use-cases where we'd check
containsKey and getInteger to have a default value.

PiperOrigin-RevId: 511184301
2023-02-27 18:18:53 +00:00
kimvde
faad46318b Fix clipping in AudioSamplePipeline
When clipping a MediaItem with start time > 0, the audio was ending
before the video. This is because:
- Audio timestamps are computed based on the sample sizes, with a start
  time set to streamOffsetUs (i.e. the streamStartPositionUs is not
  taken into account).
- The SamplePipeline was subtracting streamStartPositionUs from the
  timestamps before sending the samples to the muxer.
- As a result, the audio timestamps were shifted by
  streamStartPositionUs, while they should be shifter by streamOffsetUs.

PiperOrigin-RevId: 511175923
2023-02-27 18:18:00 +00:00
samrobinson
37bb432869 Expand and refactor TransformerInternal#shouldTranscode.
* Account for `AssetLoader` output types.
* Consider cases that are not audio/video specific.
* Use `Format#sampleMimeType` for track specific conditions to check.
* Untangle `SamplePipeline` initilization from `AssetLoader` state.

PiperOrigin-RevId: 511020865
2023-02-27 18:14:47 +00:00
kimvde
86dca78845 Support added/removed audio track between MediaItems
- Add silent audio when the output contains an audio track but the
  current MediaItem doesn't have any audio.
- Add an audio track when generateSilentAudio is set to true.

PiperOrigin-RevId: 511005887
2023-02-27 18:13:58 +00:00
huangdarwin
518fe3771a HDR: Fix ForceInterpretHdrVideoAsSdrTest, and expand to all APIs.
Previously, this was limited to API 29. Expand this to all API versions.

Also, update the test to:
(1) skip based on SDR format input instead of HDR format input
(2) Check the exception message in order to disambiguate between the decoder tone
mapping error, and general video format support error.

PiperOrigin-RevId: 511002218
2023-02-27 18:12:06 +00:00
kimvde
ac12b96f11 Fix stuck muxer
Unstuck the muxer if the next timestamp in the track with the minimum
timestamp is larger than this minimum timestamp plus
MAX_TRACK_WRITE_AHEAD_US.

PiperOrigin-RevId: 510977088
2023-02-27 18:09:20 +00:00
huangdarwin
d1df8e21d2 HDR: Remove comment explaining force sdr behavior with assetloaders.
Before, if the upstream AssetLoader provides HDR to the VideoSamplePipeline when
HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR is requested, the
VideoSamplePipeline would attempt to tell the AssetLoader to output SDR, which
could be accomplished via MediaCodec tone-mapping in the AssetLoader.

However, this makes an assumption of the AssetLoader implementation, and
AssetLoaders may not all implement support for decoder tone-mapping. Remove javadoc
attempting to explain how AssetLoaders (ex. custom ones) could behave.

PiperOrigin-RevId: 510956820
2023-02-27 18:05:16 +00:00
samrobinson
4a7326a286 Pass AudioFormat to ASP#computeNextEncoderInputBufferTimeUs.
This method uses sampleRate, channelCount and pcmEncoding, so passing
AudioFormat is easier.

This will lead into a future change that builds the
encoderInputAudioFormat from encoder.getConfigurationFormat()

PiperOrigin-RevId: 510956177
2023-02-27 18:04:26 +00:00
huangdarwin
84acfe7867 Effect: Rename to ScaleAndRotateTransformation
Rename ScaleToFitTransformation to ScaleAndRotateTransformation.

This better represents the operations that can be accomplished using this
effect. The name was originally named ScaleToFit* because it's not obvious how
to scale to fit using OpenGL, and this effect handled the scaling to fit in a way that no other MatrixTransformations did.

However, it's hard to discover how to rotate when skimming names of effects, so
it's probably more useful to convey that this effect rotates, than that it
scales to fit.

PiperOrigin-RevId: 510480078
2023-02-27 18:02:45 +00:00
huangdarwin
f295dd4211 HDR: Add colorinfo to exception logs.
Format.toString unfortunately doesn't log colorInfo, and as Format holds a very
large set of values, it's unclear that it should. ColorInfo is useful for codec
exceptions though, so log this in ExportException.createForCodec.

PiperOrigin-RevId: 510475520
2023-02-27 18:01:53 +00:00
andrewlewis
b89b13f16b Align test codec caps check with real implementation
PiperOrigin-RevId: 510437262
2023-02-27 17:57:30 +00:00
kimvde
5806414fba Move generateSilentAudio to Composition
Also rename to forceAudioTrack

PiperOrigin-RevId: 510394620
2023-02-27 17:55:27 +00:00
huangdarwin
da8b4db278 HDR: Catch test util decoder support error.
Otherwise, a lack of HDR decoding support will result in the tests checking output files for HDR output, like HdrEditingTest.transform_noRequestedTranscode_hdr10File_transformsOrThrows, failing.

PiperOrigin-RevId: 510213020
2023-02-17 11:53:53 +00:00
samrobinson
e3484d632f Remove space in exception message.
This space was added by mistake in a prior CL of mine.

PiperOrigin-RevId: 510157363
2023-02-17 11:53:03 +00:00
huangdarwin
77ea31e01c HDR: Add comment explaining force-SDR and AssetLoader interaction.
PiperOrigin-RevId: 510155318
2023-02-17 11:52:13 +00:00
huangdarwin
fb8bbce5f1 HDR: Put force HDR as SDR into AssetLoader
This allows us to fix usage of HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR.

Before, this was checked in the VideoSamplePipeline, which no longer decides on the decoder configuration input format.

PiperOrigin-RevId: 510142097
2023-02-17 11:51:23 +00:00
kimvde
221c5afb1b Rename occurrences of transform in lib-transformer
PiperOrigin-RevId: 510118760
2023-02-17 11:50:20 +00:00
andrewlewis
5d8a83f924 Remove Pixel watch check
It's unlikely anyone will try to use Transformer on watches.

PiperOrigin-RevId: 510115645
2023-02-17 11:49:29 +00:00
andrewlewis
2ed5819a19 Check capabilities for more tests
Some of the test methods in `TransformationTest` don't check
capabilities. Add a check just scoped to decoding (not checking
encoding, but the default encoder factory may fall back).

PiperOrigin-RevId: 510088562
2023-02-17 11:45:46 +00:00
kimvde
afb52627b6 Rename TransformationTest to ExportTest
PiperOrigin-RevId: 510087543
2023-02-17 11:44:57 +00:00
kimvde
c2fdab847f Rename TransformationException to ExportException
PiperOrigin-RevId: 510062674
2023-02-17 11:42:50 +00:00
huangdarwin
cf768329e6 Effect: Rename FrameProcessor
Rename FrameProcessor to VideoFrameProcessor, and GlEffectsFrameProcessor to
DefaultVideoFrameProcessor.

Most changes are semi-mechanical, semi-manual find-replace, preserving case:
* "FrameProc" -> "VideoFrameProc" (ex. FrameProcessor -> VideoFrameProcessor, and
   FrameProcessingException -> VideoFrameProcessingException)
* "GlEffectsVideoFrameProc" -> "DefaultVideoFrameProc"

PiperOrigin-RevId: 509887384
2023-02-17 11:41:06 +00:00
andrewlewis
41a03dd8a6 Fix some minor nits
PiperOrigin-RevId: 509879029
2023-02-17 11:40:13 +00:00
tofunmi
7e33bdfc94 Change FrameProcessor.create() inputTrackType parameter to a boolean
PiperOrigin-RevId: 509808913
2023-02-15 18:17:52 +00:00
andrewlewis
f03a6ba0f0 Skip tests if muxing is unsupported
PiperOrigin-RevId: 509802784
2023-02-15 18:17:00 +00:00
samrobinson
3608c2e831 Use MediaFormatUtil for creating MediaFormat from Format.
PiperOrigin-RevId: 509785247
2023-02-15 12:14:10 +00:00
samrobinson
79a3464014 Clarify the mime type used in EncoderUtilTest.
PiperOrigin-RevId: 509750806
2023-02-15 12:12:33 +00:00
samrobinson
ee8832ff21 Align ASP and VSP on findSupportedMimeTypeForEncoder/Muxer logic.
* Moved the logic to SamplePipeline.
* Pass the requested values via Format.
* Moved exception throwing inside the methods.
* Build up the mimeTypesToCheck as a set - removing possible duplicate
checks.
* Simplified logic that calls the findSupportedMimeType method.
* Improved javadoc.

PiperOrigin-RevId: 509594062
2023-02-15 12:11:42 +00:00
samrobinson
ccc349abfd Preserve aspect ratio when scaling resolution is insufficient.
PiperOrigin-RevId: 509546771
2023-02-15 12:10:48 +00:00
claincly
3aca3ad170 Use ColorInfo.Builder in transformer and common.
Because the ColorInfo constructor is deprecated.

PiperOrigin-RevId: 509468663
2023-02-14 10:28:33 +00:00
samrobinson
c94adf9041 Generalize getSupportedEncodersForHdr to return List<MediaCodecInfo>.
This now matches EncoderUtil.getSupportedEncoders return type.

PiperOrigin-RevId: 509222078
2023-02-13 15:33:02 +00:00
huangdarwin
fdf636bc7e Test: Move FileUtil to mh from mh.analysis.
FileUtil is only ever used in mh, and never in mh.analysis

PiperOrigin-RevId: 509206721
2023-02-13 14:12:46 +00:00
huangdarwin
cf089b34f0 HDR: Remove HDR-specific error codes.
It may be confusing for 3P apps, for us to have separate error codes for (1) if
encoding HDR is not supported at all by the device, and (2) if encoding the
format, which happens to be HDR, is not supported by the device. Instead, we can
communicate this in the error message.

PiperOrigin-RevId: 509188666
2023-02-13 12:22:55 +00:00
kimvde
fedb74907e Handle when some MediaItems require transcoding but others don't
- For single-asset, the behavior stays the same. Transcode if and only
  if it's necessary,
- For constrained multi-asset, always transcode, except if the setter to
  transmux is set. This is to avoid failing if a MediaItem that doesn't
  require transcoding is followed by a MediaItem that does require
  transcoding.

PiperOrigin-RevId: 508097798
2023-02-14 14:22:52 +00:00
kimvde
16db2bd0a1 Add an API entry point to pass a Composition
PiperOrigin-RevId: 508031337
2023-02-08 14:11:13 +00:00
huangdarwin
0c0c972ea0 Effect: Create GlEffect.isNoOp to simplify Transformer.
This will also allow us to skip transcodes in the future for other effects, like
cropping, color effects, etc.

PiperOrigin-RevId: 507765618
2023-02-08 14:07:41 +00:00
kimvde
c434cc0c9f Rename TransformationResult to ExportResult
Also replace some usages of deprecated Transformer listeners with the new
ones.

PiperOrigin-RevId: 507743860
2023-02-08 14:06:51 +00:00
tofunmi
9224a36add Update CompositeAssetLoader to override queueInputBitmap
PiperOrigin-RevId: 507515587
2023-02-08 14:03:17 +00:00
kimvde
0eb11e269c Rename startTransformation to start
Also update some Javadoc in Transformer

PiperOrigin-RevId: 507395956
2023-02-08 13:59:41 +00:00
tofunmi
4e3c6c6167 Update sample pipelines and frame processors to handle image input.
PiperOrigin-RevId: 506965394
2023-02-08 13:58:50 +00:00
huangdarwin
c45859dde1 HDR: Move codec errors from VideoSamplePipeline
It doesn't actually make sense for them to be placed in the Transformer, because the error's root causes are actually only in codecs. Also, a few codec errors were
repeated, so deduplicate these instances

PiperOrigin-RevId: 506937695
2023-02-08 13:57:57 +00:00
tofunmi
f67569d2dd Update FrameProcessor.create() to accept an input track type.
Based on [this conversation thread](https://chat.google.com/room/AAAA--f88ao/76Rem_cRCK8), I've opted to update the existing FrameProcessor.create() rather than deprecate it, as it is unlikely to be in use by apps outside google3.

PiperOrigin-RevId: 506920930
2023-02-08 13:57:02 +00:00
huangdarwin
c4faae6b03 Demo: Request READ_MEDIA_VIDEO on API 33+
More info in: https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions

PiperOrigin-RevId: 506908079
2023-02-08 13:56:06 +00:00
kimvde
9cb2b6e196 Update Composition structure to take List instead of ImmutableList
This is more flexible for apps and more consitent with the Player API.

PiperOrigin-RevId: 506901645
2023-02-08 13:55:14 +00:00
samrobinson
e2adb567bf Expand createNoSupportedMimeTypeException for HDR ColorInfo case.
PiperOrigin-RevId: 506900817
2023-02-08 13:54:22 +00:00
kimvde
9fdc64785a Adapt TransformationResult for multi-asset
PiperOrigin-RevId: 506898392
2023-02-08 13:53:27 +00:00
samrobinson
2754529ce7 Refactor TransformationException.createForCodec method overloads.
* Overload added `(cause, errorCode, isVideo, isDecoder, details)`,
where `details` is a string of values to be added to the error message
of the `TransformationException`.
* Overload with `MediaFormat` and `mediaCodecName` moved to
`DefaultCodec`, because all usages of that overload were from
`DefaultCodec`, and this allows a simplified API because of internally
stored values.
* `mediaCodecName` removed from overload that takes a `Format`.
* Reordered `createForCodec` parameters.

PiperOrigin-RevId: 506895268
2023-02-08 13:52:32 +00:00
kimvde
dce83d70c5 Rename Transformer callbacks
PiperOrigin-RevId: 506890459
2023-02-08 13:51:40 +00:00
samrobinson
0b7679ed88 Implement a ChannelMixingAudioProcessor.
PiperOrigin-RevId: 506886903
2023-02-08 13:50:45 +00:00
claincly
3b7ebecf16 Prefer hardware encoders in EncoderSelector.
In encoding small and odd-numbered resolutions, like `316x61` ([this image](https://upload.wikimedia.org/wikipedia/commons/6/65/100winners.png)), the current fallback logic prefers a software encoder to hardware ones. The assumption was, the encoder factory applies the encoder size alignment and changes the resolution to `316x60` for SW encoders and `316x64` for HW ones. SW encoders is selected because the supported resolution 60 is closer to requested 61, than the hardware supported 64.

This change changes the default encoder selection process to only expose hardware encoders if there is any.

PiperOrigin-RevId: 506879983
2023-02-08 13:49:52 +00:00