Java 类android.media.MediaCodecInfo 实例源码

项目:Fatigue-Detection    文件:VideoEncoderCore.java   
/**
 * Configures encoder and muxer state, and prepares the input Surface.
 */
public VideoEncoderCore(int width, int height, int bitRate, MMediaMuxer MMediaMuxer)
        throws IOException {
    super(MMediaMuxer);

    MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);

    // Set some properties.  Failing to specify some of these can cause the MediaCodec
    // configure() call to throw an unhelpful exception.
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
            MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, calcBitRate(width,height));
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
    if (VERBOSE) Log.d(TAG, "format: " + format);

    // 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);

    mInputSurface = mEncoder.createInputSurface();
    mEncoder.start();
}
项目:libRtmp    文件:AndroidUntil.java   
/**
 * Returns the first codec capable of encoding the specified MIME type, or null if no match was
 * found.
 */
@TargetApi(18)
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
项目:libRtmp    文件:AndroidUntil.java   
@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;
    }
项目:Amazing    文件:ScreenRecordActivity.java   
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void printInfo() {
    MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] codecInfos = list.getCodecInfos();
    for (MediaCodecInfo info : codecInfos) {
        if (info.isEncoder()) {
            StringBuilder sb = new StringBuilder();
            sb.append(info.getName() + " types=");
            String[] supportedTypes = info.getSupportedTypes();
            for (String string : supportedTypes) {
                sb.append(" " + string);
            }
            LogUtil.e(sb.toString());
        }
    }
}
项目:heifreader    文件:HeifReader.java   
/**
 * Initialize HeifReader module.
 *
 * @param context Context.
 */
public static void initialize(Context context) {
    mRenderScript = RenderScript.create(context);
    mCacheDir = context.getCacheDir();

    // find best HEVC decoder
    mDecoderName = null;
    mDecoderSupportedSize = new Size(0, 0);
    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (codecInfo.isEncoder()) {
            continue;
        }
        for (String type : codecInfo.getSupportedTypes()) {
            if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
                MediaCodecInfo.CodecCapabilities cap = codecInfo.getCapabilitiesForType(MediaFormat.MIMETYPE_VIDEO_HEVC);
                MediaCodecInfo.VideoCapabilities vcap = cap.getVideoCapabilities();
                Size supportedSize = new Size(vcap.getSupportedWidths().getUpper(), vcap.getSupportedHeights().getUpper());
                Log.d(TAG, "HEVC decoder=\"" + codecInfo.getName() + "\""
                        + " supported-size=" + supportedSize
                        + " color-formats=" + Arrays.toString(cap.colorFormats)
                );
                if (mDecoderSupportedSize.getWidth() * mDecoderSupportedSize.getHeight() < supportedSize.getWidth() * supportedSize.getHeight()) {
                    mDecoderName = codecInfo.getName();
                    mDecoderSupportedSize = supportedSize;
                }
            }
        }
    }
    if (mDecoderName == null) {
        throw new RuntimeException("no HEVC decoding support");
    }
    Log.i(TAG, "HEVC decoder=\"" + mDecoderName + "\" supported-size=" + mDecoderSupportedSize);
}
项目:19porn    文件:EncodeUtils.java   
public static void showCodecInfo() {
    int mediaCodecCount = MediaCodecList.getCodecCount();

    for (int i = 0; i < mediaCodecCount; i++) {
        MediaCodecInfo mediaCodecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!mediaCodecInfo.isEncoder()) {
            continue;
        }

        Log.e(ERROR_TAGE, "CodecName:" + mediaCodecInfo.getName());
        String types[] = mediaCodecInfo.getSupportedTypes();

        String strTypes = "";
        for (int j = 0; j < types.length; j++) {
            if (!strTypes.isEmpty()) {
                final String SPLITE = ",  ";
                strTypes += SPLITE;
            }
            strTypes += types[j];
        }

        Log.e(ERROR_TAGE, "Suport Type:" + strTypes);
    }
}
项目:19porn    文件:EncodeUtils.java   
private static String FindHardWareEncoder16(String mime) {
    int mediaCodecCount = MediaCodecList.getCodecCount();

    for (int i = 0; i < mediaCodecCount; i++) {
        MediaCodecInfo mediaCodecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!mediaCodecInfo.isEncoder()) {
            continue;
        }

        String types[] = mediaCodecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mime)) {
                String decoderName = mediaCodecInfo.getName();
                Log.e(ERROR_TAGE, "hwDecoderName = " + decoderName);
                boolean isHardwareEncode = (decoderName.indexOf("google") == -1);
                if (isHardwareEncode) {
                    return decoderName;
                }
            }
        }
    }

    return null;
}
项目:MegviiFacepp-Android-SDK    文件:MediaVideoEncoder.java   
/**
 * select the first codec that match a specific MIME type
 * @param mimeType
 * @return null if no codec matched
 */
protected static final MediaCodecInfo selectVideoCodec(final String mimeType) {
    if (DEBUG) Log.v(TAG, "selectVideoCodec:");

    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

        if (!codecInfo.isEncoder()) {   // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                if (DEBUG) Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
项目:mao-android    文件:MediaVideoEncoder.java   
/**
 * select the first codec that match a specific MIME type
 *
 * @param mimeType
 * @return null if no codec matched
 */
protected static final MediaCodecInfo selectVideoCodec(final String mimeType) {
    if (DEBUG) Log.v(TAG, "selectVideoCodec:");

    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                if (DEBUG) Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
项目:PeSanKita-android    文件:AudioCodec.java   
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;
}
项目:airgram    文件:MediaController.java   
@SuppressLint("NewApi")
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}
项目:mao-android    文件:MediaAudioEncoder.java   
/**
 * select the first codec that match a specific MIME type
 *
 * @param mimeType
 * @return
 */
private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
    if (DEBUG) Log.v(TAG, "selectAudioCodec:");

    MediaCodecInfo result = null;
    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    LOOP:
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
            if (types[j].equalsIgnoreCase(mimeType)) {
                if (result == null) {
                    result = codecInfo;
                    break LOOP;
                }
            }
        }
    }
    return result;
}
项目:MegviiFacepp-Android-SDK    文件:MediaAudioEncoder.java   
/**
     * select the first codec that match a specific MIME type
     * @param mimeType
     * @return
     */
    private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
        if (DEBUG) Log.v(TAG, "selectAudioCodec:");

        MediaCodecInfo result = null;
        // get the list of available codecs
        final int numCodecs = MediaCodecList.getCodecCount();
LOOP:   for (int i = 0; i < numCodecs; i++) {
            final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
            if (!codecInfo.isEncoder()) {   // skipp decoder
                continue;
            }
            final String[] types = codecInfo.getSupportedTypes();
            for (int j = 0; j < types.length; j++) {
                if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
                if (types[j].equalsIgnoreCase(mimeType)) {
                    if (result == null) {
                        result = codecInfo;
                        break LOOP;
                    }
                }
            }
        }
        return result;
    }
项目:EZFilter    文件:MediaAudioEncoder.java   
private static MediaCodecInfo selectAudioCodec(final String mimeType) {
    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        final String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
项目:Fatigue-Detection    文件:MediaCodecUtils.java   
@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;
}
项目:Fatigue-Detection    文件:MediaVideoEncoder.java   
/**
 * select the first codec that match a specific MIME type
 * @param mimeType
 * @return null if no codec matched
 */
protected static final MediaCodecInfo selectVideoCodec(final String mimeType) {
    if (DEBUG) Log.v(TAG, "selectVideoCodec:");

    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

        if (!codecInfo.isEncoder()) {   // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                if (DEBUG) Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
项目:Fatigue-Detection    文件:MediaVideoEncoder.java   
/**
   * select color format available on specific codec and we can use.
   * @return 0 if no colorFormat is matched
   */
  protected static final int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
if (DEBUG) Log.i(TAG, "selectColorFormat: ");
    int result = 0;
    final MediaCodecInfo.CodecCapabilities caps;
    try {
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        caps = codecInfo.getCapabilitiesForType(mimeType);
    } finally {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
    }
      int colorFormat;
      for (int i = 0; i < caps.colorFormats.length; i++) {
        colorFormat = caps.colorFormats[i];
          if (isRecognizedViewoFormat(colorFormat)) {
            if (result == 0)
                result = colorFormat;
              break;
          }
      }
      if (result == 0)
        Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
      return result;
  }
项目:Fatigue-Detection    文件:AudioEncoderCore.java   
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;
        }
    }
项目:AI-Powered-Intelligent-Banking-Platform    文件:AudioUtils.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(int sampleRate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaFormat format = MediaFormatFactory.createMediaFormat(MediaFormatFactory.Type.FLAC, sampleRate);
        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        String encoderAsStr = mcl.findEncoderForFormat(format);
        List<String> encoders = new ArrayList<>();
        for (MediaCodecInfo info : mcl.getCodecInfos()) {
            if (info.isEncoder()) {
                if (info.getName().equals(encoderAsStr)) {
                    encoders.add("*** " + info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                } else {
                    encoders.add(info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                }
            }
        }
        return encoders;
    }
    return Collections.emptyList();
}
项目:Cable-Android    文件:AudioCodec.java   
private byte[] createAdtsHeader(int length) {
  int    frameLength = length + 7;
  byte[] adtsHeader  = new byte[7];

  adtsHeader[0]  = (byte) 0xFF; // Sync Word
  adtsHeader[1]  = (byte) 0xF1; // MPEG-4, Layer (0), No CRC
  adtsHeader[2]  = (byte) ((MediaCodecInfo.CodecProfileLevel.AACObjectLC - 1) << 6);
  adtsHeader[2] |= (((byte) SAMPLE_RATE_INDEX) << 2);
  adtsHeader[2] |= (((byte) CHANNELS) >> 2);
  adtsHeader[3]  = (byte) (((CHANNELS & 3) << 6) | ((frameLength >> 11) & 0x03));
  adtsHeader[4]  = (byte) ((frameLength >> 3) & 0xFF);
  adtsHeader[5]  = (byte) (((frameLength & 0x07) << 5) | 0x1f);
  adtsHeader[6]  = (byte) 0xFC;

  return adtsHeader;
}
项目:MegviiFacepp-Android-SDK    文件:MediaVideoEncoder.java   
/**
   * select color format available on specific codec and we can use.
   * @return 0 if no colorFormat is matched
   */
  protected static final int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
if (DEBUG) Log.i(TAG, "selectColorFormat: ");
    int result = 0;
    final MediaCodecInfo.CodecCapabilities caps;
    try {
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        caps = codecInfo.getCapabilitiesForType(mimeType);
    } finally {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
    }
      int colorFormat;
      for (int i = 0; i < caps.colorFormats.length; i++) {
        colorFormat = caps.colorFormats[i];
          if (isRecognizedViewoFormat(colorFormat)) {
            if (result == 0)
                result = colorFormat;
              break;
          }
      }
      if (result == 0)
        Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
      return result;
  }
项目:EasyScreenRecorder    文件:MediaAudioEncoder.java   
/**
     * select the first codec that match a specific MIME type
     * @param mimeType
     * @return
     */
    private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
        if (DEBUG) Log.v(TAG, "selectAudioCodec:");

        MediaCodecInfo result = null;
        // get the list of available codecs
        final int numCodecs = MediaCodecList.getCodecCount();
LOOP:   for (int i = 0; i < numCodecs; i++) {
            final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
            if (!codecInfo.isEncoder()) {   // skipp decoder
                continue;
            }
            final String[] types = codecInfo.getSupportedTypes();
            for (int j = 0; j < types.length; j++) {
                if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
                if (types[j].equalsIgnoreCase(mimeType)) {
                    if (result == null) {
                        result = codecInfo;
                        break LOOP;
                    }
                }
            }
        }
        return result;
    }
项目:EasyScreenRecorder    文件:MediaVideoEncoderBase.java   
/**
   * select color format available on specific codec and we can use.
   * @return 0 if no colorFormat is matched
   */
  protected static final int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
if (DEBUG) Log.i(TAG, "selectColorFormat: ");
    int result = 0;
    final MediaCodecInfo.CodecCapabilities caps;
    try {
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        caps = codecInfo.getCapabilitiesForType(mimeType);
    } finally {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
    }
      int colorFormat;
      for (int i = 0; i < caps.colorFormats.length; i++) {
        colorFormat = caps.colorFormats[i];
          if (isRecognizedViewoFormat(colorFormat)) {
            if (result == 0)
                result = colorFormat;
              break;
          }
      }
      if (result == 0)
        Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
      return result;
  }
项目:KrGallery    文件:MediaController.java   
@SuppressLint("NewApi")
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}
项目:Cable-Android    文件:AudioCodec.java   
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;
}
项目:AppRTC-Android    文件:HardwareVideoDecoderFactory.java   
private MediaCodecInfo findCodecForType(VideoCodecType type) {
  // HW decoding is not supported on builds before KITKAT.
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
    return null;
  }

  for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
    MediaCodecInfo info = null;
    try {
      info = MediaCodecList.getCodecInfoAt(i);
    } catch (IllegalArgumentException e) {
      Logging.e(TAG, "Cannot retrieve encoder codec info", e);
    }

    if (info == null || info.isEncoder()) {
      continue;
    }

    if (isSupportedCodec(info, type)) {
      return info;
    }
  }
  return null; // No support for this type.
}
项目:AppRTC-Android    文件:HardwareVideoDecoderFactory.java   
private boolean isHardwareSupported(MediaCodecInfo info, VideoCodecType type) {
  String name = info.getName();
  switch (type) {
    case VP8:
      // QCOM, Intel, Exynos, and Nvidia all supported for VP8.
      return name.startsWith(QCOM_PREFIX) || name.startsWith(INTEL_PREFIX)
          || name.startsWith(EXYNOS_PREFIX) || name.startsWith(NVIDIA_PREFIX);
    case VP9:
      // QCOM and Exynos supported for VP9.
      return name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX);
    case H264:
      // QCOM, Intel, and Exynos supported for H264.
      return name.startsWith(QCOM_PREFIX) || name.startsWith(INTEL_PREFIX)
          || name.startsWith(EXYNOS_PREFIX);
    default:
      return false;
  }
}
项目:AppRTC-Android    文件:HardwareVideoEncoderFactory.java   
@Override
public VideoEncoder createEncoder(VideoCodecInfo input) {
  VideoCodecType type = VideoCodecType.valueOf(input.name);
  MediaCodecInfo info = findCodecForType(type);

  if (info == null) {
    return null; // No support for this type.
  }

  String codecName = info.getName();
  String mime = type.mimeType();
  Integer surfaceColorFormat = MediaCodecUtils.selectColorFormat(
      MediaCodecUtils.TEXTURE_COLOR_FORMATS, info.getCapabilitiesForType(mime));
  Integer yuvColorFormat = MediaCodecUtils.selectColorFormat(
      MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(mime));

  return new HardwareVideoEncoder(codecName, type, surfaceColorFormat, yuvColorFormat,
      input.params, getKeyFrameIntervalSec(type), getForcedKeyFrameIntervalMs(type, codecName),
      createBitrateAdjuster(type, codecName), sharedContext);
}
项目:AppRTC-Android    文件:HardwareVideoEncoderFactory.java   
@Override
public VideoCodecInfo[] getSupportedCodecs() {
  List<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>();
  // Generate a list of supported codecs in order of preference:
  // VP8, VP9, H264 (high profile), and H264 (baseline profile).
  for (VideoCodecType type :
      new VideoCodecType[] {VideoCodecType.VP8, VideoCodecType.VP9, VideoCodecType.H264}) {
    MediaCodecInfo codec = findCodecForType(type);
    if (codec != null) {
      String name = type.name();
      if (type == VideoCodecType.H264 && isH264HighProfileSupported(codec)) {
        supportedCodecInfos.add(new VideoCodecInfo(0, name, getCodecProperties(type, true)));
      }

      supportedCodecInfos.add(new VideoCodecInfo(0, name, getCodecProperties(type, false)));
    }
  }
  return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
}
项目:AppRTC-Android    文件:HardwareVideoEncoderFactory.java   
private MediaCodecInfo findCodecForType(VideoCodecType type) {
  for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
    MediaCodecInfo info = null;
    try {
      info = MediaCodecList.getCodecInfoAt(i);
    } catch (IllegalArgumentException e) {
      Logging.e(TAG, "Cannot retrieve encoder codec info", e);
    }

    if (info == null || !info.isEncoder()) {
      continue;
    }

    if (isSupportedCodec(info, type)) {
      return info;
    }
  }
  return null; // No support for this type.
}
项目:VideoCompressor    文件:VideoController.java   
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}
项目:PlusGram    文件:MediaController.java   
@SuppressLint("NewApi")
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}
项目:AI-Powered-Intelligent-Banking-Platform    文件:AudioUtils.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(int sampleRate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaFormat format = MediaFormatFactory.createMediaFormat(MediaFormatFactory.Type.FLAC, sampleRate);
        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        String encoderAsStr = mcl.findEncoderForFormat(format);
        List<String> encoders = new ArrayList<>();
        for (MediaCodecInfo info : mcl.getCodecInfos()) {
            if (info.isEncoder()) {
                if (info.getName().equals(encoderAsStr)) {
                    encoders.add("*** " + info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                } else {
                    encoders.add(info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                }
            }
        }
        return encoders;
    }
    return Collections.emptyList();
}
项目:EZFilter    文件:MediaVideoEncoder.java   
private static MediaCodecInfo selectVideoCodec(final String mimeType) {
    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        for (String type : codecInfo.getSupportedTypes()) {
            if (type.equalsIgnoreCase(mimeType)) {
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
项目:EZFilter    文件:MediaVideoEncoder.java   
private static int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
    int result = 0;
    final MediaCodecInfo.CodecCapabilities caps;
    try {
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        caps = codecInfo.getCapabilitiesForType(mimeType);
    } finally {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
    }
    for (int colorFormat : caps.colorFormats) {
        if (isRecognizedVideoFormat(colorFormat)) {
            result = colorFormat;
            break;
        }
    }
    if (result == 0) {
        Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
    }
    return result;
}
项目:AAVT    文件:CameraRecorder.java   
public Configuration(int width,int height){
    mAudioFormat=MediaFormat.createAudioFormat("audio/mp4a-latm",48000,2);
    mAudioFormat.setInteger(MediaFormat.KEY_BIT_RATE,128000);
    mAudioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);

    mVideoFormat=MediaFormat.createVideoFormat("video/avc",width,height);
    mVideoFormat.setInteger(MediaFormat.KEY_FRAME_RATE,24);
    mVideoFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL,1);
    mVideoFormat.setInteger(MediaFormat.KEY_BIT_RATE,width*height*5);
    mVideoFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
}
项目:19porn    文件:HardwareDecoder.java   
@SuppressWarnings("deprecation")
public int FindHardWareDecoder16(){
    String mimeType = mAVCodeIDToMime.get(mCodeId);
       Log.e(TAG, "mimeType = " + mimeType + "codeid = " + mCodeId);

       int mediaCodecCount = MediaCodecList.getCodecCount();

    for (int i = 0; i < mediaCodecCount; i++) {
        MediaCodecInfo mediaCodecInfo = MediaCodecList.getCodecInfoAt(i);
           if(mediaCodecInfo.isEncoder()){
               continue;
           }

           String types[] = mediaCodecInfo.getSupportedTypes();
           for (int j = 0;j < types.length;j++){
               if (types[j].equalsIgnoreCase(mimeType)){
                   String decoderName = mediaCodecInfo.getName();
                   Log.e(TAG,"hwDecoderName = " + decoderName);
                   if(decoderName.indexOf("google") == -1){
                    mHWDecoderName = decoderName;
                    return 1;
                   }
               }
           }
    }
    return 0;
   }
项目:19porn    文件:HardwareDecoder.java   
public int FindHardWareDecoder21(){
    String mimeType = mAVCodeIDToMime.get(mCodeId);
    Log.e(TAG, "mimeType = " + mimeType + "codeid = " + mCodeId);

    MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] mediaCodecInfos =  mediaCodecList.getCodecInfos();

    for (int i = 0;i < mediaCodecInfos.length;i++){
        MediaCodecInfo mediaCodecInfo = mediaCodecInfos[i];
        if(mediaCodecInfo.isEncoder()){
            continue;
        }

        String types[] = mediaCodecInfo.getSupportedTypes();
        for (int j = 0;j < types.length;j++){
            if (types[j].equalsIgnoreCase(mimeType)){
                String decoderName = mediaCodecInfo.getName();
                Log.e(TAG,"hwDecoderName = " + decoderName);
                if(decoderName.indexOf("google") == -1){
                    mHWDecoderName = decoderName;
                    return 1;
                }
            }
        }
    }
    return  0;
}
项目:live_master    文件:SrsEncoder.java   
private int chooseVideoEncoder() {
    // choose the encoder "video/avc":
    //      1. select default one when type matched.
    //      2. google avc is unusable.
    //      3. choose qcom avc.
    vmci = chooseVideoEncoder(null);
    //vmci = chooseVideoEncoder("google");
    //vmci = chooseVideoEncoder("qcom");

    int matchedColorFormat = 0;
    MediaCodecInfo.CodecCapabilities cc = vmci.getCapabilitiesForType(VCODEC);
    for (int i = 0; i < cc.colorFormats.length; i++) {
        int cf = cc.colorFormats[i];
        Log.i(TAG, String.format("vencoder %s supports color fomart 0x%x(%d)", vmci.getName(), cf, cf));

        // choose YUV for h.264, prefer the bigger one.
        // corresponding to the color space transform in onPreviewFrame
        if (cf >= cc.COLOR_FormatYUV420Planar && cf <= cc.COLOR_FormatYUV420SemiPlanar) {
            if (cf > matchedColorFormat) {
                matchedColorFormat = cf;
            }
        }
    }

    for (int i = 0; i < cc.profileLevels.length; i++) {
        MediaCodecInfo.CodecProfileLevel pl = cc.profileLevels[i];
        Log.i(TAG, String.format("vencoder %s support profile %d, level %d", vmci.getName(), pl.profile, pl.level));
    }

    Log.i(TAG, String.format("vencoder %s choose color format 0x%x(%d)", vmci.getName(), matchedColorFormat, matchedColorFormat));
    return matchedColorFormat;
}
项目:airgram    文件:MediaController.java   
private static boolean isRecognizedFormat(int colorFormat) {
    switch (colorFormat) {
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar:
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedPlanar:
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar:
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedSemiPlanar:
        case MediaCodecInfo.CodecCapabilities.COLOR_TI_FormatYUV420PackedSemiPlanar:
            return true;
        default:
            return false;
    }
}