[Andorid] [ExoPlayer] 如何给 MediaCodec 增加 configure 阶段的自定义字段

前言:

ExoPlayer 使用 MediaCodec 作为底层解码组件,如果希望 MediaCodec 在 configure 的时候增加自定义字段,则可以通过如下的方式。

调用路径:

private void initCodec(MediaCodecInfo codecInfo, MediaCrypto crypto) throws Exception

=>  getMediaCodecConfiguration

修改点:

MediaCodecVideoRenderer.java        

MediaCodecVideoRenderer.java

  @TargetApi(17) // Needed for dummySurface usage. dummySurface is always null on API level 16.
  @Override
  protected MediaCodecAdapter.Configuration getMediaCodecConfiguration(
      MediaCodecInfo codecInfo,
      Format format,
      @Nullable MediaCrypto crypto,
      float codecOperatingRate) {
    if (dummySurface != null && dummySurface.secure != codecInfo.secure) {
      // We can't re-use the current DummySurface instance with the new decoder.
      releaseDummySurface();
    }
    String codecMimeType = codecInfo.codecMimeType;
    codecMaxValues = getCodecMaxValues(codecInfo, format, getStreamFormats());
    MediaFormat mediaFormat =
        getMediaFormat(
            format,
            codecMimeType,
            codecMaxValues,
            codecOperatingRate,
            deviceNeedsNoPostProcessWorkaround,
            tunneling ? tunnelingAudioSessionId : C.AUDIO_SESSION_ID_UNSET);
    if (surface == null) {
      if (!shouldUseDummySurface(codecInfo)) {
        throw new IllegalStateException();
      }
      if (dummySurface == null) {
        dummySurface = DummySurface.newInstanceV17(context, codecInfo.secure);
      }
      surface = dummySurface;
    }
	
	//+++++++++++ 增加这一段 ++++++++++
	mediaFormat.setInteger("segment-need-to-add",0);
	//+++++++++++ 增加这一段 ++++++++++
	
    return MediaCodecAdapter.Configuration.createForVideoDecoding(
        codecInfo, mediaFormat, format, surface, crypto);
  }

你可能感兴趣的:(Android,framework,android)