From 6b6e4993b97cef6343df967cfb3fdab09b555887 Mon Sep 17 00:00:00 2001 From: kimvde Date: Tue, 17 Jan 2023 18:00:34 +0000 Subject: [PATCH] Add EditedMediaItem class This class will be used in a follow-up CL. PiperOrigin-RevId: 502615323 --- .../transformer/EditedMediaItem.java | 46 ++++++++++++++ .../exoplayer2/transformer/Effects.java | 63 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 library/transformer/src/main/java/com/google/android/exoplayer2/transformer/EditedMediaItem.java create mode 100644 library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Effects.java diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/EditedMediaItem.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/EditedMediaItem.java new file mode 100644 index 00000000000..ff47ce57e67 --- /dev/null +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/EditedMediaItem.java @@ -0,0 +1,46 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.transformer; + +import com.google.android.exoplayer2.MediaItem; +import com.google.common.collect.ImmutableList; + +/** A {@link MediaItem} with the transformations to apply to it. */ +public class EditedMediaItem { + + /* package */ final MediaItem mediaItem; + /* package */ final Effects effects; + + /** + * Creates an instance with no {@link Effects}. + * + * @param mediaItem The {@link MediaItem} to edit. + */ + public EditedMediaItem(MediaItem mediaItem) { + this(mediaItem, new Effects(ImmutableList.of(), ImmutableList.of())); + } + + /** + * Creates an instance. + * + * @param mediaItem The {@link MediaItem} to edit. + * @param effects The {@link Effects} to apply to the {@code mediaItem}. + */ + public EditedMediaItem(MediaItem mediaItem, Effects effects) { + this.mediaItem = mediaItem; + this.effects = effects; + } +} diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Effects.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Effects.java new file mode 100644 index 00000000000..1a5b2ed62d1 --- /dev/null +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Effects.java @@ -0,0 +1,63 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.transformer; + +import com.google.android.exoplayer2.MediaItem; +import com.google.android.exoplayer2.audio.AudioProcessor; +import com.google.android.exoplayer2.effect.GlEffectsFrameProcessor; +import com.google.android.exoplayer2.util.Effect; +import com.google.android.exoplayer2.util.FrameProcessor; +import com.google.common.collect.ImmutableList; + +/** Effects to apply to a {@link MediaItem}. */ +public final class Effects { + + /* package */ final ImmutableList audioProcessors; + /* package */ final ImmutableList videoEffects; + /* package */ final FrameProcessor.Factory frameProcessorFactory; + + /** + * Creates an instance using a {@link GlEffectsFrameProcessor.Factory}. + * + *

This is equivalent to calling {@link Effects#Effects(ImmutableList, ImmutableList, + * FrameProcessor.Factory)} with a {@link GlEffectsFrameProcessor.Factory}. + */ + public Effects( + ImmutableList audioProcessors, ImmutableList videoEffects) { + this(audioProcessors, videoEffects, new GlEffectsFrameProcessor.Factory()); + } + + /** + * Creates an instance. + * + * @param audioProcessors The list of {@link AudioProcessor} instances to apply to audio buffers. + * They are applied in the order of the list, and buffers will only be modified by that {@link + * AudioProcessor} if it {@link AudioProcessor#isActive()} based on the current configuration. + * @param videoEffects The list of {@link Effect} instances to apply to each video frame. They are + * applied in the order of the list, after {@linkplain + * TransformationRequest.Builder#setFlattenForSlowMotion(boolean) slow-motion flattening}. + * @param frameProcessorFactory The {@link FrameProcessor.Factory} for the {@link FrameProcessor} + * to use when applying the {@code videoEffects} to the video frames. + */ + public Effects( + ImmutableList audioProcessors, + ImmutableList videoEffects, + FrameProcessor.Factory frameProcessorFactory) { + this.audioProcessors = audioProcessors; + this.videoEffects = videoEffects; + this.frameProcessorFactory = frameProcessorFactory; + } +}