當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaCodec.configure方法代碼示例

本文整理匯總了Java中android.media.MediaCodec.configure方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaCodec.configure方法的具體用法?Java MediaCodec.configure怎麽用?Java MediaCodec.configure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaCodec的用法示例。


在下文中一共展示了MediaCodec.configure方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getVideoMediaCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
@TargetApi(21)
    public static MediaCodec getVideoMediaCodec() {
        int videoWidth = getVideoSize(Options.getInstance().video.width);
        int videoHeight = getVideoSize(Options.getInstance().video.height);
        MediaFormat format = MediaFormat.createVideoFormat(Options.getInstance().video.mime, videoWidth, videoHeight);
        format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
                MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
        format.setInteger(MediaFormat.KEY_BIT_RATE, Options.getInstance().video.maxBps* 1024);
        int fps = Options.getInstance().video.fps;
        //設置攝像頭預覽幀率
//        if(BlackListHelper.deviceInFpsBlacklisted()) {
//            SopCastLog.d(SopCastConstant.TAG, "Device in fps setting black list, so set mediacodec fps 15");
//            fps = 15;
//        }
        format.setInteger(MediaFormat.KEY_FRAME_RATE, fps);
        format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, Options.getInstance().video.ifi);
        format.setInteger(MediaFormat.KEY_BITRATE_MODE, MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_VBR);
        format.setInteger(MediaFormat.KEY_COMPLEXITY, MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_CBR);
        MediaCodec mediaCodec = null;

        try {
            mediaCodec = MediaCodec.createEncoderByType(Options.getInstance().video.mime);
            mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        }catch (Exception e) {
            e.printStackTrace();
            if (mediaCodec != null) {
                mediaCodec.stop();
                mediaCodec.release();
                mediaCodec = null;
            }
        }
        return mediaCodec;
    }
 
開發者ID:wuyisheng,項目名稱:libRtmp,代碼行數:34,代碼來源:AndroidUntil.java

示例2: configureDecoder

import android.media.MediaCodec; //導入方法依賴的package包/類
private static MediaCodec configureDecoder(ImageInfo info, int maxInputSize, Surface surface) {
    if (mDecoderSupportedSize.getWidth() < info.size.getWidth() || mDecoderSupportedSize.getHeight() < info.size.getHeight()) {
        Log.w(TAG, "HEVC image may exceed decoder capability");
    }
    try {
        MediaCodec decoder = MediaCodec.createByCodecName(mDecoderName);
        MediaFormat inputFormat = MediaFormat.createVideoFormat(
                MediaFormat.MIMETYPE_VIDEO_HEVC, info.size.getWidth(), info.size.getHeight());
        inputFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
        inputFormat.setByteBuffer("csd-0", info.paramset);
        Log.d(TAG, "HEVC input-format=" + inputFormat);
        decoder.configure(inputFormat, surface, null, 0);
        return decoder;
    }  catch (IOException ex) {
        throw new RuntimeException("no HEVC decoding support");
    }
}
 
開發者ID:yohhoy,項目名稱:heifreader,代碼行數:18,代碼來源:HeifReader.java

示例3: createMediaCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
private MediaCodec createMediaCodec(int bufferSize) throws IOException {
  MediaCodec  mediaCodec  = MediaCodec.createEncoderByType("audio/mp4a-latm");
  MediaFormat mediaFormat = new MediaFormat();

  mediaFormat.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, SAMPLE_RATE);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, CHANNELS);
  mediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, bufferSize);
  mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
  mediaFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);

  try {
    mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
  } catch (Exception e) {
    Log.w(TAG, e);
    mediaCodec.release();
    throw new IOException(e);
  }

  return mediaCodec;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:22,代碼來源:AudioCodec.java

示例4: checkMediaCodecAudioEncoderSupport

import android.media.MediaCodec; //導入方法依賴的package包/類
@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;
}
 
開發者ID:zhangyaqiang,項目名稱:Fatigue-Detection,代碼行數:26,代碼來源:MediaCodecUtils.java

示例5: getAudioMediaCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
@TargetApi(18)
public static MediaCodec getAudioMediaCodec(){
    MediaFormat format = MediaFormat.createAudioFormat(
            Options.getInstance().audio.mime,
            Options.getInstance().audio.frequency,
            Options.getInstance().audio.channelCount);
    if(Options.getInstance().audio.mime.equals(Options.DEFAULT_MIME)) {
        format.setInteger(MediaFormat.KEY_AAC_PROFILE, Options.getInstance().audio.aacProfile);
    }
    format.setInteger(MediaFormat.KEY_BIT_RATE, Options.getInstance().audio.maxBps * 1024);
    format.setInteger(MediaFormat.KEY_SAMPLE_RATE, Options.getInstance().audio.frequency);
    int maxInputSize = getRecordBufferSize();
    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
    format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, Options.getInstance().audio.channelCount);

    MediaCodec mediaCodec = null;
    try {
        mediaCodec = MediaCodec.createEncoderByType(Options.getInstance().audio.mime);
        mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    } catch (Exception e) {
        e.printStackTrace();
        if (mediaCodec != null) {
            mediaCodec.stop();
            mediaCodec.release();
            mediaCodec = null;
        }
    }
    return mediaCodec;
}
 
開發者ID:wuyisheng,項目名稱:libRtmp,代碼行數:30,代碼來源:AndroidUntil.java

示例6: configureCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
@Override
protected void configureCodec(MediaCodec codec, boolean codecIsAdaptive,
    android.media.MediaFormat format, android.media.MediaCrypto crypto) {
  String mimeType = format.getString(android.media.MediaFormat.KEY_MIME);
  if (passthroughEnabled) {
    // Override the MIME type used to configure the codec if we are using a passthrough decoder.
    format.setString(android.media.MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW);
    codec.configure(format, null, crypto, 0);
    format.setString(android.media.MediaFormat.KEY_MIME, mimeType);
    passthroughMediaFormat = format;
  } else {
    codec.configure(format, null, crypto, 0);
    passthroughMediaFormat = null;
  }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:16,代碼來源:MediaCodecAudioTrackRenderer.java

示例7: getMediaCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
public static MediaCodec getMediaCodec () {
    MediaCodec encoder = null;
    try {
        encoder = MediaCodec.createEncoderByType(AccessConstants.FORMAT);
    } catch (IOException e) {
        e.printStackTrace();
    }
    encoder.configure(DeEncodecCommon.getFormat(), null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    return encoder;
}
 
開發者ID:kaixuanluo,項目名稱:pc-android-controller-android,代碼行數:11,代碼來源:DeEncodecCommon.java

示例8: checkMediaCodecVideoEncoderSupport

import android.media.MediaCodec; //導入方法依賴的package包/類
@TargetApi(MIN_API_LEVEL_VIDEO)
public static int checkMediaCodecVideoEncoderSupport(){
    if(getApiLevel()<MIN_API_LEVEL_VIDEO){
        Log.d(TAG, "checkMediaCodecVideoEncoderSupport: Min API is 18");
        return CODEC_REQ_API_NOT_SATISFIED;
    }
    MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE_VIDEO, TEST_WIDTH, TEST_HEIGHT);
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
            MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, TEST_VIDEO_BIT_RATE);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, TEST_FRAME_RATE);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, TEST_IFRAME_INTERVAL);
    MediaCodec mediaCodec;
    try {
        mediaCodec = MediaCodec.createEncoderByType(MIME_TYPE_VIDEO);
        mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mediaCodec.createInputSurface();
        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;
}
 
開發者ID:zhangyaqiang,項目名稱:Fatigue-Detection,代碼行數:28,代碼來源:MediaCodecUtils.java

示例9: configureCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
@Override
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
    MediaCrypto crypto) {
  codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
  if (passthroughEnabled) {
    // Override the MIME type used to configure the codec if we are using a passthrough decoder.
    passthroughMediaFormat = format.getFrameworkMediaFormatV16();
    passthroughMediaFormat.setString(MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW);
    codec.configure(passthroughMediaFormat, null, crypto, 0);
    passthroughMediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
  } else {
    codec.configure(format.getFrameworkMediaFormatV16(), null, crypto, 0);
    passthroughMediaFormat = null;
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:16,代碼來源:MediaCodecAudioRenderer.java

示例10: configureCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
@Override
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
    MediaCrypto crypto) throws DecoderQueryException {
  codecMaxValues = getCodecMaxValues(codecInfo, format, streamFormats);
  MediaFormat mediaFormat = getMediaFormat(format, codecMaxValues, deviceNeedsAutoFrcWorkaround,
      tunnelingAudioSessionId);
  codec.configure(mediaFormat, surface, crypto, 0);
  if (Util.SDK_INT >= 23 && tunneling) {
    tunnelingOnFrameRenderedListener = new OnFrameRenderedListenerV23(codec);
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:12,代碼來源:MediaCodecVideoRenderer.java

示例11: configureCodec

import android.media.MediaCodec; //導入方法依賴的package包/類
@Override
protected void configureCodec(MediaCodec codec, boolean codecIsAdaptive,
    android.media.MediaFormat format, MediaCrypto crypto) {
  maybeSetMaxInputSize(format, codecIsAdaptive);
  codec.configure(format, surface, crypto, 0);
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:7,代碼來源:MediaCodecVideoTrackRenderer.java


注:本文中的android.media.MediaCodec.configure方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。