private void DoConfigure(int codecType, bool encoder, MediaCodecTypes supportType) { Debug.Assert(Enum.IsDefined(typeof(SupportedCodecType), codecType)); int flags = (int)(encoder ? MediaCodecCodingType.Encoder : MediaCodecCodingType.Decoder); flags |= (int)supportType; int ret = Interop.MediaCodec.Configure(_handle, codecType, flags); if (ret == (int)MediaCodecErrorCode.NotSupportedOnDevice) { throw new NotSupportedException("The format is not supported."); } MultimediaDebug.AssertNoError(ret); }
private void ConfigureVideo(VideoMediaFormat format, bool encoder, MediaCodecTypes supportType) { int codecType = (int)format.MimeType & CodecTypeMask; if (!Enum.IsDefined(typeof(SupportedCodecType), codecType)) { throw new NotSupportedException("The format is not supported." + $"mime type : { Enum.GetName(typeof(MediaFormatVideoMimeType), format.MimeType) }"); } DoConfigure(codecType, encoder, supportType); if (encoder) { Native.SetVideoEncoderInfo(_handle, format.Size.Width, format.Size.Height, format.FrameRate, format.BitRate / 1000). ThrowIfFailed("Failed to set video encoder information."); } else { Native.SetVideoDecoderInfo(_handle, format.Size.Width, format.Size.Height). ThrowIfFailed("Failed to set video decoder information."); } }
private void ConfigureAudio(AudioMediaFormat format, bool encoder, MediaCodecTypes supportType) { int codecType = (int)format.MimeType & CodecTypeMask; if (!Enum.IsDefined(typeof(SupportedCodecType), codecType)) { throw new NotSupportedException("The format is not supported " + $"mime type : { Enum.GetName(typeof(MediaFormatAudioMimeType), format.MimeType) }"); } DoConfigure(codecType, encoder, supportType); if (encoder) { Native.SetAudioEncoderInfo(_handle, format.SampleRate, format.Channel, format.Bit, format.BitRate). ThrowIfFailed("Failed to set audio encoder information."); } else { Native.SetAudioDecoderInfo(_handle, format.SampleRate, format.Channel, format.Bit). ThrowIfFailed("Failed to set audio decoder information."); } }