public abstract class

VideoSpec

extends java.lang.Object

 java.lang.Object

↳androidx.camera.video.VideoSpec

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-video', version: '1.2.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-video
  • version: 1.2.0-alpha01

Artifact androidx.camera:camera-video:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Video specification that is options to config video encoding.

Summary

Fields
public static final <any>BITRATE_RANGE_AUTO

Bitrate range representing no preference for bitrate.

public static final <any>FRAME_RATE_RANGE_AUTO

Frame rate range representing no preference for frame rate.

public static final QualitySelectorQUALITY_SELECTOR_AUTO

Quality selector representing no preference for quality.

Methods
public static VideoSpec.Builderbuilder()

Returns a build for this config.

public abstract <any>getBitrate()

Gets the bitrate.

public abstract <any>getFrameRate()

Gets the frame rate.

public abstract QualitySelectorgetQualitySelector()

Gets the QualitySelector.

public abstract VideoSpec.BuildertoBuilder()

Returns a VideoSpec.Builder instance with the same property values as this instance.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final <any> FRAME_RATE_RANGE_AUTO

Frame rate range representing no preference for frame rate.

Using this value with VideoSpec.Builder informs the video frame producer it should choose any appropriate frame rate given the device and codec constraints.

public static final <any> BITRATE_RANGE_AUTO

Bitrate range representing no preference for bitrate.

Using this value with VideoSpec.Builder informs the video frame producer it should choose any appropriate bitrate given the device and codec constraints.

public static final QualitySelector QUALITY_SELECTOR_AUTO

Quality selector representing no preference for quality.

Using this value with VideoSpec.Builder.setQualitySelector(QualitySelector) allows the video frame producer to choose video quality based on its current state.

Methods

public static VideoSpec.Builder builder()

Returns a build for this config.

public abstract QualitySelector getQualitySelector()

Gets the QualitySelector.

public abstract <any> getFrameRate()

Gets the frame rate.

public abstract <any> getBitrate()

Gets the bitrate.

public abstract VideoSpec.Builder toBuilder()

Returns a VideoSpec.Builder instance with the same property values as this instance.

Source

/*
 * Copyright 2020 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 androidx.camera.video;

import android.util.Range;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.Scope;

import com.google.auto.value.AutoValue;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;

/**
 * Video specification that is options to config video encoding.
 * @hide
 */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
@RestrictTo(Scope.LIBRARY)
@AutoValue
public abstract class VideoSpec {

    /**
     * Frame rate range representing no preference for frame rate.
     *
     * <p>Using this value with {@link Builder#setFrameRate(Range)} informs the video frame producer
     * it should choose any appropriate frame rate given the device and codec constraints.
     */
    @NonNull
    public static final Range<Integer> FRAME_RATE_RANGE_AUTO = new Range<>(0,
            Integer.MAX_VALUE);

    /**
     * Bitrate range representing no preference for bitrate.
     *
     * <p>Using this value with {@link Builder#setBitrate(Range)} informs the video frame producer
     * it should choose any appropriate bitrate given the device and codec constraints.
     */
    @NonNull
    public static final Range<Integer> BITRATE_RANGE_AUTO = new Range<>(0,
            Integer.MAX_VALUE);

    /**
     * Quality selector representing no preference for quality.
     *
     * <p>Using this value with {@link Builder#setQualitySelector(QualitySelector)} allows the
     * video frame producer to choose video quality based on its current state.
     */
    @NonNull
    public static final QualitySelector QUALITY_SELECTOR_AUTO =
            QualitySelector.fromOrderedList(Arrays.asList(Quality.FHD, Quality.HD, Quality.SD),
                    FallbackStrategy.higherQualityOrLowerThan(Quality.FHD));

    /**
     * The aspect ratio representing no preference for aspect ratio.
     *
     * <p>Using this value with {@link Builder#setAspectRatio(int)} allows the video frame
     * producer to choose an appropriate aspect ratio based on its current state.
     */
    static final int ASPECT_RATIO_AUTO = -1;
    /** The aspect ratio with width 16 by height 9. */
    static final int ASPECT_RATIO_4_3 = androidx.camera.core.AspectRatio.RATIO_4_3;
    /** The aspect ratio with width 4 by height 3. */
    static final int ASPECT_RATIO_16_9 = androidx.camera.core.AspectRatio.RATIO_16_9;

    /** @hide */
    @IntDef({ASPECT_RATIO_AUTO, ASPECT_RATIO_4_3, ASPECT_RATIO_16_9})
    @Retention(RetentionPolicy.SOURCE)
    @interface AspectRatio {
    }

    // Restrict constructor to same package
    VideoSpec() {
    }

    /** Returns a build for this config. */
    @NonNull
    public static Builder builder() {
        return new AutoValue_VideoSpec.Builder()
                .setQualitySelector(QUALITY_SELECTOR_AUTO)
                .setFrameRate(FRAME_RATE_RANGE_AUTO)
                .setBitrate(BITRATE_RANGE_AUTO)
                .setAspectRatio(ASPECT_RATIO_AUTO);
    }

    /** Gets the {@link QualitySelector}. */
    @NonNull
    public abstract QualitySelector getQualitySelector();

    /** Gets the frame rate. */
    @NonNull
    public abstract Range<Integer> getFrameRate();

    /** Gets the bitrate. */
    @NonNull
    public abstract Range<Integer> getBitrate();

    /** Gets the aspect ratio. */
    @AspectRatio
    abstract int getAspectRatio();

    /**
     * Returns a {@link Builder} instance with the same property values as this instance.
     */
    @NonNull
    public abstract Builder toBuilder();

    /**
     * The builder of the {@link VideoSpec}.
     * @hide
     */
    @RestrictTo(Scope.LIBRARY)
    @SuppressWarnings("StaticFinalBuilder")
    @AutoValue.Builder
    public abstract static class Builder {
        // Restrict construction to same package
        Builder() {
        }

        /**
         * Sets the {@link QualitySelector}.
         *
         * <p>Video encoding parameters such as frame rate and bitrate will often be automatically
         * determined according to quality. If video parameters are not set directly (such as
         * through {@link #setFrameRate(Range)}, the device will choose values calibrated for the
         * quality on that device.
         *
         * <p>If not set, defaults to {@link #QUALITY_SELECTOR_AUTO}.
         */
        @NonNull
        public abstract Builder setQualitySelector(@NonNull QualitySelector qualitySelector);

        /**
         * Sets the frame rate.
         *
         * <p>If not set, defaults to {@link #FRAME_RATE_RANGE_AUTO}.
         */
        @NonNull
        public abstract Builder setFrameRate(@NonNull Range<Integer> frameRate);

        /**
         * Sets the bitrate.
         *
         * <p>If not set, defaults to {@link #BITRATE_RANGE_AUTO}.
         */
        @NonNull
        public abstract Builder setBitrate(@NonNull Range<Integer> bitrate);

        /**
         * Sets the aspect ratio.
         *
         * <p>Available values for aspect ratio are {@link #ASPECT_RATIO_16_9},
         * {@link #ASPECT_RATIO_4_3} and {@link #ASPECT_RATIO_AUTO}.
         *
         * <p>If not set, defaults to {@link #ASPECT_RATIO_AUTO}.
         */
        @NonNull
        abstract Builder setAspectRatio(@AspectRatio int aspectRatio);

        /** Builds the VideoSpec instance. */
        @NonNull
        public abstract VideoSpec build();
    }
}