public abstract class

AudioSpec

extends java.lang.Object

 java.lang.Object

↳androidx.camera.video.AudioSpec

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

Audio specification that is options to config audio source and encoding.

Summary

Fields
public static final <any>BITRATE_RANGE_AUTO

Bitrate range representing no preference for bitrate.

public static final intCHANNEL_COUNT_AUTO

Allows the audio source to choose the appropriate number of channels.

public static final intCHANNEL_COUNT_MONO

A channel count corresponding to a single audio channel.

public static final intCHANNEL_COUNT_NONE

A channel count which is equivalent to no audio.

public static final intCHANNEL_COUNT_STEREO

A channel count corresponding to two audio channels.

public static final AudioSpecNO_AUDIO

An audio specification that corresponds to no audio.

public static final <any>SAMPLE_RATE_RANGE_AUTO

Sample rate range representing no preference for sample rate.

public static final intSOURCE_AUTO

The audio source representing no preference for audio source.

public static final intSOURCE_CAMCORDER

Microphone audio source tuned for video recording, with the same orientation as the camera if available.

public static final intSOURCE_FORMAT_AUTO

The audio source format representing no preference for audio source format.

public static final intSOURCE_FORMAT_PCM_16BIT

The PCM 16 bit per sample audio source format.

Methods
public static AudioSpec.Builderbuilder()

Returns a build for this config.

public abstract <any>getBitrate()

Gets the bitrate.

public abstract intgetChannelCount()

Gets the channel count.

public abstract <any>getSampleRate()

Gets the sample bitrate.

public abstract intgetSource()

Gets the audio source.

public abstract intgetSourceFormat()

Gets the audio format.

public abstract AudioSpec.BuildertoBuilder()

Returns a AudioSpec.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 int SOURCE_FORMAT_AUTO

The audio source format representing no preference for audio source format.

public static final int SOURCE_FORMAT_PCM_16BIT

The PCM 16 bit per sample audio source format. Guaranteed to be supported by all devices.

public static final int CHANNEL_COUNT_AUTO

Allows the audio source to choose the appropriate number of channels.

public static final int CHANNEL_COUNT_NONE

A channel count which is equivalent to no audio.

public static final int CHANNEL_COUNT_MONO

A channel count corresponding to a single audio channel.

public static final int CHANNEL_COUNT_STEREO

A channel count corresponding to two audio channels.

public static final int SOURCE_AUTO

The audio source representing no preference for audio source.

public static final int SOURCE_CAMCORDER

Microphone audio source tuned for video recording, with the same orientation as the camera if available.

public static final <any> BITRATE_RANGE_AUTO

Bitrate range representing no preference for bitrate.

Using this value with AudioSpec.Builder informs the device it should choose any appropriate bitrate given the device and codec constraints.

public static final <any> SAMPLE_RATE_RANGE_AUTO

Sample rate range representing no preference for sample rate.

Using this value with AudioSpec.Builder informs the device it should choose any appropriate sample rate given the device and codec constraints.

public static final AudioSpec NO_AUDIO

An audio specification that corresponds to no audio.

This is equivalent to creating an AudioSpec with channel count set to AudioSpec.CHANNEL_COUNT_NONE.

Methods

public static AudioSpec.Builder builder()

Returns a build for this config.

public abstract <any> getBitrate()

Gets the bitrate.

public abstract int getSourceFormat()

Gets the audio format.

public abstract int getSource()

Gets the audio source.

public abstract <any> getSampleRate()

Gets the sample bitrate.

public abstract int getChannelCount()

Gets the channel count.

public abstract AudioSpec.Builder toBuilder()

Returns a AudioSpec.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.media.AudioFormat;
import android.media.MediaRecorder;
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;

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

    /**
     * The audio source format representing no preference for audio source format.
     */
    public static final int SOURCE_FORMAT_AUTO = -1;
    /**
     * The PCM 16 bit per sample audio source format. Guaranteed to be supported by all devices.
     */
    public static final int SOURCE_FORMAT_PCM_16BIT = AudioFormat.ENCODING_PCM_16BIT;

    @IntDef({SOURCE_FORMAT_AUTO, SOURCE_FORMAT_PCM_16BIT})
    @Retention(RetentionPolicy.SOURCE)
    @interface SourceFormat {
    }

    /**
     * Allows the audio source to choose the appropriate number of channels.
     */
    public static final int CHANNEL_COUNT_AUTO = -1;
    /**
     * A channel count which is equivalent to no audio.
     */
    public static final int CHANNEL_COUNT_NONE = 0;
    /**
     * A channel count corresponding to a single audio channel.
     */
    public static final int CHANNEL_COUNT_MONO = 1;
    /**
     * A channel count corresponding to two audio channels.
     */
    public static final int CHANNEL_COUNT_STEREO = 2;

    /** @hide */
    @IntDef(open = true,
            value = {CHANNEL_COUNT_AUTO, CHANNEL_COUNT_NONE, CHANNEL_COUNT_MONO,
                    CHANNEL_COUNT_STEREO})
    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    public @interface ChannelCount {
    }

    /**
     * The audio source representing no preference for audio source.
     */
    public static final int SOURCE_AUTO = -1;
    /**
     * Microphone audio source tuned for video recording, with the same orientation as the camera
     * if available.
     */
    public static final int SOURCE_CAMCORDER = MediaRecorder.AudioSource.CAMCORDER;

    /** @hide */
    @IntDef({SOURCE_AUTO, SOURCE_CAMCORDER})
    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    public @interface Source {
    }

    /**
     * Bitrate range representing no preference for bitrate.
     *
     * <p>Using this value with {@link AudioSpec.Builder#setBitrate(Range)} informs the device 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);

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

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

    /** Returns a build for this config. */
    @NonNull
    public static Builder builder() {
        return new AutoValue_AudioSpec.Builder()
                .setSourceFormat(SOURCE_FORMAT_AUTO)
                .setSource(SOURCE_AUTO)
                .setChannelCount(CHANNEL_COUNT_AUTO)
                .setBitrate(BITRATE_RANGE_AUTO)
                .setSampleRate(SAMPLE_RATE_RANGE_AUTO);
    }

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

    // Configurations for AudioRecord.
    // *********************************************************************************************

    /** Gets the audio format. */
    @SourceFormat
    public abstract int getSourceFormat();

    /** Gets the audio source. */
    @Source
    public abstract int getSource();

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

    /** Gets the channel count. */
    @ChannelCount
    public abstract int getChannelCount();

    // *********************************************************************************************

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

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

        /**
         * Sets the desired range of bitrates to be used by the encoder.
         *
         * <p>If not set, defaults to {@link #BITRATE_RANGE_AUTO}.
         */
        @NonNull
        public abstract Builder setBitrate(@NonNull Range<Integer> bitrate);

        // Configurations for AudioRecord.
        // *****************************************************************************************

        /**
         * Sets the audio source format.
         *
         * <p>Available values for source format are {@link #SOURCE_FORMAT_AUTO} and
         * {@link #SOURCE_FORMAT_PCM_16BIT}.
         *
         * <p>If not set, defaults to {@link #SOURCE_FORMAT_AUTO}.
         */
        @NonNull
        public abstract Builder setSourceFormat(@SourceFormat int audioFormat);

        /**
         * Sets the audio source.
         *
         * <p>Available values for source are {@link #SOURCE_AUTO} and {@link #SOURCE_CAMCORDER}.
         *
         * <p>If not set, defaults to {@link #SOURCE_AUTO}.
         */
        @NonNull
        public abstract Builder setSource(@Source int source);

        /**
         * Sets the desired range of sample rates to be used by the encoder.
         *
         * <p>If not set, defaults to {@link #SAMPLE_RATE_RANGE_AUTO}.
         */
        @NonNull
        public abstract Builder setSampleRate(@NonNull Range<Integer> sampleRate);

        /**
         * Sets the desired number of audio channels.
         *
         * <p>If not set, defaults to {@link #CHANNEL_COUNT_AUTO}. Other common channel counts
         * include {@link #CHANNEL_COUNT_MONO} or {@link #CHANNEL_COUNT_STEREO}.
         *
         * <p>Setting to {@link #CHANNEL_COUNT_NONE} is equivalent to requesting that no audio
         * should be present.
         */
        @NonNull
        public abstract Builder setChannelCount(@ChannelCount int channelCount);

        // *****************************************************************************************

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

    /**
     * An audio specification that corresponds to no audio.
     *
     * <p>This is equivalent to creating an {@link AudioSpec} with channel count set to
     * {@link #CHANNEL_COUNT_NONE}.
     */
    public static final AudioSpec NO_AUDIO = builder().setChannelCount(CHANNEL_COUNT_NONE).build();
}