当前位置: 首页>>代码示例>>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;未经允许,请勿转载。