Java Code Examples for android.media.MediaFormat#createAudioFormat()

The following examples show how to use android.media.MediaFormat#createAudioFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioEncoderCore.java    From Fatigue-Detection with MIT License 7 votes vote down vote up
public AudioEncoderCore(MMediaMuxer MMediaMuxer) throws IOException {
        super(MMediaMuxer);
        final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE, SAMPLE_RATE, 1);
        audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
        audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_MONO);
        audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
        audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
//		audioFormat.setLong(MediaFormat.KEY_MAX_INPUT_SIZE, inputFile.length());
//      audioFormat.setLong(MediaFormat.KEY_DURATION, (long)durationInMs );
        if (VERBOSE) Log.i(TAG, "format: " + audioFormat);
        mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
        mEncoder.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mEncoder.start();
        if (mAudioThread == null) {
            mAudioThread = new AudioThread();
            mAudioThread.start();
            capturing=true;
            stopped=false;
        }
    }
 
Example 2
Source File: MediaCodecUtils.java    From Fatigue-Detection with MIT License 6 votes vote down vote up
@TargetApi(MIN_API_LEVEL_AUDIO)
public static int checkMediaCodecAudioEncoderSupport(){
    if(getApiLevel()<MIN_API_LEVEL_AUDIO){
        Log.d(TAG, "checkMediaCodecAudioEncoderSupport: Min API is 16");
        return CODEC_REQ_API_NOT_SATISFIED;
    }
    final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE_AUDIO, TEST_SAMPLE_RATE, 1);
    audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_MONO);
    audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, TEST_AUDIO_BIT_RATE);
    audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
    MediaCodec mediaCodec;
    try {
        mediaCodec = MediaCodec.createEncoderByType(MIME_TYPE_AUDIO);
        mediaCodec.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mediaCodec.start();
        mediaCodec.stop();
        mediaCodec.release();
        mediaCodec = null;
    } catch (Exception ex) {
        Log.e(TAG, "Failed on creation of codec #", ex);
        return CODEC_ERROR;
    }
    return CODEC_SUPPORTED;
}
 
Example 3
Source File: AudioRecoder.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public AudioRecoder(MediaFormat inputAudioFormat, MediaExtractor extractor, int trackIndex) throws IOException {
    this.extractor = extractor;
    this.trackIndex = trackIndex;

    decoder = MediaCodec.createDecoderByType(inputAudioFormat.getString(MediaFormat.KEY_MIME));
    decoder.configure(inputAudioFormat, null, null, 0);
    decoder.start();


    encoder = MediaCodec.createEncoderByType(MediaController.AUIDO_MIME_TYPE);
    format = MediaFormat.createAudioFormat(MediaController.AUIDO_MIME_TYPE,
            inputAudioFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE),
            inputAudioFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)
    );
    format.setInteger(MediaFormat.KEY_BIT_RATE, 64 * 1024);
    encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    encoder.start();


    decoderInputBuffers = decoder.getInputBuffers();
    decoderOutputBuffers = decoder.getOutputBuffers();
    encoderInputBuffers = encoder.getInputBuffers();
    encoderOutputBuffers = encoder.getOutputBuffers();
}
 
Example 4
Source File: AbstractTLMediaAudioEncoder.java    From TimeLapseRecordingSample with Apache License 2.0 6 votes vote down vote up
@Override
	protected MediaFormat internal_prepare() throws IOException {
		if (DEBUG) Log.v(TAG, "prepare:");
		// prepare MediaCodec for AAC encoding of audio data from inernal mic.
		final MediaCodecInfo audioCodecInfo = selectAudioCodec(MIME_TYPE);
		if (audioCodecInfo == null) {
			Log.e(TAG, "Unable to find an appropriate codec for " + MIME_TYPE);
			return null;
		}
		if (DEBUG) Log.i(TAG, "selected codec: " + audioCodecInfo.getName());

		final MediaFormat format = MediaFormat.createAudioFormat(MIME_TYPE, mSampleRate, 1);
		format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
		format.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_MONO);
		format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
		format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
//		format.setLong(MediaFormat.KEY_MAX_INPUT_SIZE, inputFile.length());
//      format.setLong(MediaFormat.KEY_DURATION, (long)durationInMs );
		if (DEBUG) Log.i(TAG, "prepare finishing:format=" + format);
		return format;
	}
 
Example 5
Source File: MediaReaper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
@Override
protected MediaFormat createOutputFormat(final byte[] csd, final int size,
	final int ix0, final int ix1, final int ix2) {

	MediaFormat outFormat;
       if (ix0 >= 0) {
		if (DEBUG) Log.w(TAG, "csd may be wrong, it may be for video");
       }
       // audioの時はSTART_MARKが無いので全体をコピーして渡す
       outFormat = MediaFormat.createAudioFormat(MIME_TYPE, mSampleRate, mChannelCount);
       final ByteBuffer csd0 = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
       csd0.put(csd, 0, size);
       csd0.flip();
       outFormat.setByteBuffer("csd-0", csd0);
       return outFormat;
}
 
Example 6
Source File: VideoCapture.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/** Creates a {@link MediaFormat} using parameters for audio from the configuration */
private MediaFormat createAudioMediaFormat() {
    MediaFormat format =
        MediaFormat.createAudioFormat(AUDIO_MIME_TYPE, mAudioSampleRate,
            mAudioChannelCount);
    format.setInteger(
        MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitRate);

    return format;
}
 
Example 7
Source File: AudioEncoderCore.java    From kickflip-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Configures encoder and muxer state, and prepares the input Surface.
 */
public AudioEncoderCore(int numChannels, int bitRate, int sampleRate, Muxer muxer) throws IOException {
    switch (numChannels) {
        case 1:
            mChannelConfig = AudioFormat.CHANNEL_IN_MONO;
            break;
        case 2:
            mChannelConfig = AudioFormat.CHANNEL_IN_STEREO;
            break;
        default:
            throw new IllegalArgumentException("Invalid channel count. Must be 1 or 2");
    }
    mSampleRate = sampleRate;
    mMuxer = muxer;
    mBufferInfo = new MediaCodec.BufferInfo();

    MediaFormat format = MediaFormat.createAudioFormat(MIME_TYPE, mSampleRate, mChannelConfig);

    // Set some properties.  Failing to specify some of these can cause the MediaCodec
    // configure() call to throw an unhelpful exception.
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_SAMPLE_RATE, mSampleRate);
    format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, numChannels);
    format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 16384);

    // Create a MediaCodec encoder, and configure it with our format.  Get a Surface
    // we can use for input and wrap it with a class that handles the EGL work.
    mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
    mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    mEncoder.start();

    mTrackIndex = -1;
}
 
Example 8
Source File: Android480pFormatStrategy.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
    if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;

    // Use original sample rate, as resampling is not supported yet.
    final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,
            inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
    return format;
}
 
Example 9
Source File: AudioTransCoder.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
private void prepare() throws IOException {
    encoder = MediaCodec.createEncoderByType("audio/mp4a-latm");
    MediaFormat format = MediaFormat.createAudioFormat("audio/mp4a-latm", sampleRate, channelCount);
    format.setInteger(MediaFormat.KEY_BIT_RATE, 96000);
    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 512 * 1024);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    encoder.start();
}
 
Example 10
Source File: MediaUtil.java    From EZFilter with MIT License 5 votes vote down vote up
/**
 * 创建音频MediaFormat[aac]
 *
 * @param sampleRate   采样率
 * @param channelMask  声道
 * @param channelCount 声道数
 * @return
 */
public static MediaFormat createAudioFormat(int sampleRate, int channelMask, int channelCount) {
    MediaFormat format = MediaFormat.createAudioFormat(MIME_TYPE_AAC, sampleRate, channelCount);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    // 声道
    format.setInteger(MediaFormat.KEY_CHANNEL_MASK, channelMask);
    // 声道数
    format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, channelCount);
    // 音频bit率
    format.setInteger(MediaFormat.KEY_BIT_RATE, AUDIO_BIT_RATE);
    // 统一设置最大缓冲容量,否则在音频转码时因为大小不一致会报错
    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, BUFFER_SIZE);
    return format;
}
 
Example 11
Source File: Android16By9FormatStrategy.java    From android-transcoder with Apache License 2.0 5 votes vote down vote up
@Override
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
    if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;

    // Use original sample rate, as resampling is not supported yet.
    final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,
            inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
    return format;
}
 
Example 12
Source File: AbstractAudioEncoder.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
	protected boolean internalPrepare() throws Exception {
//		if (DEBUG) Log.v(TAG, "internalPrepare:");
        mTrackIndex = -1;
        mRecorderStarted = mIsEOS = false;

// 音声を取り込んでAACにエンコードするためのMediaCodecの準備
        final MediaCodecInfo audioCodecInfo = MediaCodecUtils.selectAudioEncoder(MIME_TYPE);
        if (audioCodecInfo == null) {
//			Log.e(TAG, "Unable to find an appropriate codec for " + MIME_TYPE);
            return true;
        }
//		if (DEBUG) Log.i(TAG, "selected codec: " + audioCodecInfo.getName());

        final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE, mSampleRate, mChannelCount);
		audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
		audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK,
			mChannelCount == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO);
		audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
		audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, mChannelCount);
//		audioFormat.setLong(MediaFormat.KEY_MAX_INPUT_SIZE, inputFile.length());
//      audioFormat.setLong(MediaFormat.KEY_DURATION, (long)durationInMs );
//		if (DEBUG) Log.i(TAG, "format: " + audioFormat);

		mMediaCodec = MediaCodec.createEncoderByType(MIME_TYPE);
        mMediaCodec.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mMediaCodec.start();
//		if (DEBUG) Log.i(TAG, "internalPrepare:finished");
		return false;
	}
 
Example 13
Source File: MediaTransformer.java    From LiTr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Nullable
private MediaFormat createTargetMediaFormat(@NonNull MediaSource mediaSource,
                                            int sourceTrackIndex) {
    MediaFormat sourceMediaFormat = mediaSource.getTrackFormat(sourceTrackIndex);
    MediaFormat targetMediaFormat = null;

    String mimeType = null;
    if (sourceMediaFormat.containsKey(MediaFormat.KEY_MIME)) {
        mimeType = sourceMediaFormat.getString(MediaFormat.KEY_MIME);
    }

    if (mimeType != null) {
        if (mimeType.startsWith("video")) {
            targetMediaFormat = MediaFormat.createVideoFormat(mimeType,
                                                              sourceMediaFormat.getInteger(MediaFormat.KEY_WIDTH),
                                                              sourceMediaFormat.getInteger(MediaFormat.KEY_HEIGHT));
            int targetBitrate = TranscoderUtils.estimateVideoTrackBitrate(mediaSource, sourceTrackIndex);
            targetMediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, targetBitrate);

            int targetKeyFrameInterval = DEFAULT_KEY_FRAME_INTERVAL;
            if (sourceMediaFormat.containsKey(MediaFormat.KEY_I_FRAME_INTERVAL)) {
                targetKeyFrameInterval = sourceMediaFormat.getInteger(MediaFormat.KEY_I_FRAME_INTERVAL);
            }
            targetMediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, targetKeyFrameInterval);
        } else if (mimeType.startsWith("audio")) {
            targetMediaFormat = MediaFormat.createAudioFormat(mimeType,
                                                              sourceMediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE),
                                                              sourceMediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT));
            targetMediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, sourceMediaFormat.getInteger(MediaFormat.KEY_BIT_RATE));
        }
    }

    return targetMediaFormat;
}
 
Example 14
Source File: AndroidStandardFormatStrategy.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
    if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS)
        return null;

    // Use original sample rate, as resampling is not supported yet.
    final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,
            inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
    return format;
}
 
Example 15
Source File: Android16By9FormatStrategy.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
    if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;

    // Use original sample rate, as resampling is not supported yet.
    final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,
            inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
    return format;
}
 
Example 16
Source File: MediaCodecBridge.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private static MediaFormat createAudioFormat(String mime, int SampleRate, int ChannelCount) {
    return MediaFormat.createAudioFormat(mime, SampleRate, ChannelCount);
}
 
Example 17
Source File: MediaCodecBridge.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private static MediaFormat createAudioFormat(String mime, int SampleRate, int ChannelCount) {
    return MediaFormat.createAudioFormat(mime, SampleRate, ChannelCount);
}
 
Example 18
Source File: MediaCodecBridge.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private static MediaFormat createAudioFormat(String mime, int sampleRate, int channelCount) {
    return MediaFormat.createAudioFormat(mime, sampleRate, channelCount);
}
 
Example 19
Source File: AudioTrackConverter.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private AudioTrackConverter(
        final @NonNull MediaExtractor audioExtractor,
        final int audioInputTrack,
        long timeFrom,
        long timeTo,
        int audioBitrate) throws IOException {

    mTimeFrom = timeFrom;
    mTimeTo = timeTo;
    mAudioExtractor = audioExtractor;
    mAudioBitrate = audioBitrate;

    final MediaCodecInfo audioCodecInfo = MediaConverter.selectCodec(OUTPUT_AUDIO_MIME_TYPE);
    if (audioCodecInfo == null) {
        // Don't fail CTS if they don't have an AAC codec (not here, anyway).
        Log.e(TAG, "Unable to find an appropriate codec for " + OUTPUT_AUDIO_MIME_TYPE);
        throw new FileNotFoundException();
    }
    if (VERBOSE) Log.d(TAG, "audio found codec: " + audioCodecInfo.getName());

    final MediaFormat inputAudioFormat = mAudioExtractor.getTrackFormat(audioInputTrack);
    mInputDuration = inputAudioFormat.containsKey(MediaFormat.KEY_DURATION) ? inputAudioFormat.getLong(MediaFormat.KEY_DURATION) : 0;

    final MediaFormat outputAudioFormat =
            MediaFormat.createAudioFormat(
                    OUTPUT_AUDIO_MIME_TYPE,
                    inputAudioFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE),
                    inputAudioFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT));
    outputAudioFormat.setInteger(MediaFormat.KEY_BIT_RATE, audioBitrate);
    outputAudioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, OUTPUT_AUDIO_AAC_PROFILE);
    outputAudioFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 16 * 1024);

    // Create a MediaCodec for the desired codec, then configure it as an encoder with
    // our desired properties. Request a Surface to use for input.
    mAudioEncoder = createAudioEncoder(audioCodecInfo, outputAudioFormat);
    // Create a MediaCodec for the decoder, based on the extractor's format.
    mAudioDecoder = createAudioDecoder(inputAudioFormat);

    mAudioDecoderInputBuffers = mAudioDecoder.getInputBuffers();
    mAudioDecoderOutputBuffers = mAudioDecoder.getOutputBuffers();
    mAudioEncoderInputBuffers = mAudioEncoder.getInputBuffers();
    mAudioEncoderOutputBuffers = mAudioEncoder.getOutputBuffers();
    mAudioDecoderOutputBufferInfo = new MediaCodec.BufferInfo();
    mAudioEncoderOutputBufferInfo = new MediaCodec.BufferInfo();

    if (mTimeFrom > 0) {
        mAudioExtractor.seekTo(mTimeFrom * 1000, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
        Log.i(TAG, "Seek audio:" + mTimeFrom + " " + mAudioExtractor.getSampleTime());
    }
}
 
Example 20
Source File: AudioEncoder.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
protected void prepare() throws IOException {
    AudioQuality audioQuality = getAudioQuality();

    String mimeType = audioQuality.getMimeType();

    List<MediaCodecInfo> infoList = getMediaCodecInfo(mimeType);
    if (infoList.isEmpty()) {
        throw new IOException(mimeType + " not supported.");
    }

    MediaFormat format = MediaFormat.createAudioFormat(audioQuality.getMimeType(),
            audioQuality.getSamplingRate(), audioQuality.getChannelCount());
    format.setString(MediaFormat.KEY_MIME, audioQuality.getMimeType());
    format.setInteger(MediaFormat.KEY_SAMPLE_RATE, audioQuality.getSamplingRate());
    format.setInteger(MediaFormat.KEY_BIT_RATE, audioQuality.getBitRate());
    format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, audioQuality.getChannelCount());
    format.setInteger(MediaFormat.KEY_CHANNEL_MASK, audioQuality.getChannel());
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    if (audioQuality.getMaxInputSize() > 0) {
        format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, audioQuality.getMaxInputSize());
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // 0: realtime priority
        // 1: non-realtime priority (best effort).
        format.setInteger(MediaFormat.KEY_PRIORITY, 0x00);
    }

    if (DEBUG) {
        Log.d(TAG, "List of MediaCodeInfo supported by MediaCodec.");
        for (MediaCodecInfo info : infoList) {
            Log.d(TAG, "  " + info.getName());
        }
        Log.i(TAG, "---");
        Log.i(TAG, "MIME_TYPE: " + audioQuality.getMimeType());
        Log.i(TAG, "SAMPLE_RATE: " + audioQuality.getSamplingRate());
        Log.i(TAG, "CHANNEL: " + audioQuality.getChannelCount());
        Log.i(TAG, "FORMAT: " + audioQuality.getFormat());
        Log.i(TAG, "BIT_RATE: " + audioQuality.getBitRate());
        Log.i(TAG, "---");
    }

    mMediaCodec = MediaCodec.createEncoderByType(audioQuality.getMimeType());
    mMediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
}