public abstract class

AudioEncoderConfig

extends java.lang.Object

implements EncoderConfig

 java.lang.Object

↳androidx.camera.video.internal.encoder.AudioEncoderConfig

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

Summary

Methods
public static AudioEncoderConfig.Builderbuilder()

Returns a build for this config.

public abstract intgetBitrate()

Gets the bitrate.

public abstract intgetChannelCount()

Gets the channel count.

public abstract java.lang.StringgetMimeType()

public abstract intgetProfile()

public abstract intgetSampleRate()

Gets the sample bitrate.

public MediaFormattoMediaFormat()

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

Methods

public static AudioEncoderConfig.Builder builder()

Returns a build for this config.

public abstract java.lang.String getMimeType()

public abstract int getProfile()

Default is EncoderConfig.CODEC_PROFILE_NONE.

public abstract int getBitrate()

Gets the bitrate.

public abstract int getSampleRate()

Gets the sample bitrate.

public abstract int getChannelCount()

Gets the channel count.

public MediaFormat toMediaFormat()

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.internal.encoder;

import android.media.MediaFormat;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.google.auto.value.AutoValue;

import java.util.Objects;

/** {@inheritDoc} */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
@AutoValue
public abstract class AudioEncoderConfig implements EncoderConfig {

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

    /** Returns a build for this config. */
    @NonNull
    public static Builder builder() {
        return new AutoValue_AudioEncoderConfig.Builder()
                .setProfile(EncoderConfig.CODEC_PROFILE_NONE);
    }

    /** {@inheritDoc} */
    @Override
    @NonNull
    public abstract String getMimeType();

    /**
     * {@inheritDoc}
     *
     * <p>Default is {@link EncoderConfig#CODEC_PROFILE_NONE}.
     */
    @Override
    public abstract int getProfile();

    /** Gets the bitrate. */
    public abstract int getBitrate();

    /** Gets the sample bitrate. */
    public abstract int getSampleRate();

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

    /** {@inheritDoc} */
    @NonNull
    @Override
    public MediaFormat toMediaFormat() {
        MediaFormat mediaFormat = MediaFormat.createAudioFormat(getMimeType(), getSampleRate(),
                getChannelCount());
        mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, getBitrate());
        if (getProfile() != CODEC_PROFILE_NONE) {
            if (getMimeType().equals(MediaFormat.MIMETYPE_AUDIO_AAC)) {
                mediaFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, getProfile());
            } else {
                mediaFormat.setInteger(MediaFormat.KEY_PROFILE, getProfile());
            }
        }

        return mediaFormat;
    }

    /** The builder of the config. */
    @AutoValue.Builder
    public abstract static class Builder {
        // Restrict construction to same package
        Builder() {
        }

        /**
         * Sets the mime type.
         *
         * <p>If the mime type is set to AAC, i.e. {@link MediaFormat#MIMETYPE_AUDIO_AAC}, then a
         * profile must be set with {@link #setProfile(int)}. If a profile isn't set or is set to
         * {@link EncoderConfig#CODEC_PROFILE_NONE}, an IllegalArgumentException will be thrown by
         * {@link #build()}.
         */
        @NonNull
        public abstract Builder setMimeType(@NonNull String mimeType);

        /** Sets (optional) profile for the mime type specified by {@link #setMimeType(String)}. */
        @NonNull
        public abstract Builder setProfile(int profile);

        /** Sets the bitrate. */
        @NonNull
        public abstract Builder setBitrate(int bitrate);

        /** Sets the sample rate. */
        @NonNull
        public abstract Builder setSampleRate(int sampleRate);

        /** Sets the channel count. */
        @NonNull
        public abstract Builder setChannelCount(int channelCount);

        @NonNull
        abstract AudioEncoderConfig autoBuild();

        /** Builds the config instance. */
        @NonNull
        public AudioEncoderConfig build() {
            AudioEncoderConfig config = autoBuild();
            if (Objects.equals(config.getMimeType(), MediaFormat.MIMETYPE_AUDIO_AAC)
                    && config.getProfile() == CODEC_PROFILE_NONE) {
                throw new IllegalArgumentException("Encoder mime set to AAC, but no AAC profile "
                        + "was provided.");
            }

            return config;
        }
    }
}