1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.camera.video.internal; 18 19 import static java.util.Collections.unmodifiableList; 20 21 import androidx.camera.core.impl.EncoderProfilesProxy; 22 import androidx.core.util.Preconditions; 23 24 import com.google.auto.value.AutoValue; 25 26 import org.jspecify.annotations.NonNull; 27 import org.jspecify.annotations.Nullable; 28 29 import java.util.ArrayList; 30 import java.util.List; 31 32 /** 33 * VideoValidatedEncoderProfilesProxy is an implementation of {@link EncoderProfilesProxy} that 34 * guarantees to provide video information. 35 */ 36 @AutoValue 37 public abstract class VideoValidatedEncoderProfilesProxy implements EncoderProfilesProxy { 38 39 /** Creates a VideoValidatedEncoderProfilesProxy instance from {@link EncoderProfilesProxy}. */ from( @onNull EncoderProfilesProxy profiles)40 public static @NonNull VideoValidatedEncoderProfilesProxy from( 41 @NonNull EncoderProfilesProxy profiles) { 42 return create( 43 profiles.getDefaultDurationSeconds(), 44 profiles.getRecommendedFileFormat(), 45 profiles.getAudioProfiles(), 46 profiles.getVideoProfiles() 47 ); 48 } 49 50 /** Creates a VideoValidatedEncoderProfilesProxy instance. */ create( int defaultDurationSeconds, int recommendedFileFormat, @NonNull List<AudioProfileProxy> audioProfiles, @NonNull List<VideoProfileProxy> videoProfiles)51 public static @NonNull VideoValidatedEncoderProfilesProxy create( 52 int defaultDurationSeconds, 53 int recommendedFileFormat, 54 @NonNull List<AudioProfileProxy> audioProfiles, 55 @NonNull List<VideoProfileProxy> videoProfiles) { 56 Preconditions.checkArgument(!videoProfiles.isEmpty(), 57 "Should contain at least one VideoProfile."); 58 VideoProfileProxy defaultVideoProfile = videoProfiles.get(0); 59 60 AudioProfileProxy defaultAudioProfile = null; 61 if (!audioProfiles.isEmpty()) { 62 defaultAudioProfile = audioProfiles.get(0); 63 } 64 65 return new AutoValue_VideoValidatedEncoderProfilesProxy( 66 defaultDurationSeconds, 67 recommendedFileFormat, 68 unmodifiableList(new ArrayList<>(audioProfiles)), 69 unmodifiableList(new ArrayList<>(videoProfiles)), 70 defaultAudioProfile, 71 defaultVideoProfile 72 ); 73 } 74 75 /** Returns the default {@link AudioProfileProxy} or null if not existed. */ getDefaultAudioProfile()76 public abstract @Nullable AudioProfileProxy getDefaultAudioProfile(); 77 78 /** Returns the default {@link VideoProfileProxy}. */ getDefaultVideoProfile()79 public abstract @NonNull VideoProfileProxy getDefaultVideoProfile(); 80 } 81