From d3d635cb35fa1148e1738d46e9d6012c32105652 Mon Sep 17 00:00:00 2001 From: hsgwon Date: Tue, 14 Jul 2020 11:14:58 +0900 Subject: [PATCH] [MediaCodec] Add new codec type - Opus (#1812) --- .../MediaCodec/MediaCodec.cs | 27 ++++++++------- .../MediaCodec/SupportedCodecType.cs | 38 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs b/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs index 3f53b35..338f66f 100644 --- a/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs +++ b/src/Tizen.Multimedia.MediaCodec/MediaCodec/MediaCodec.cs @@ -172,6 +172,7 @@ namespace Tizen.Multimedia.MediaCodec Native.SupportedCodecCallback cb = (codecType, _) => { + codecType = TypeConverter.ToPublic((SupportedCodecType)codecType); if ((codecType & CodecKindMask) == CodecKindVideo) { MediaFormatVideoMimeType mimeType = 0; @@ -278,7 +279,7 @@ namespace Tizen.Multimedia.MediaCodec private void ConfigureAudio(AudioMediaFormat format, bool encoder, MediaCodecTypes supportType) { - int codecType = (int)format.MimeType & CodecTypeMask; + int codecType = TypeConverter.ToNative(format.MimeType); if (!Enum.IsDefined(typeof(SupportedCodecType), codecType)) { @@ -303,7 +304,7 @@ namespace Tizen.Multimedia.MediaCodec private void ConfigureVideo(VideoMediaFormat format, bool encoder, MediaCodecTypes supportType) { - int codecType = (int)format.MimeType & CodecTypeMask; + int codecType = TypeConverter.ToNative(format.MimeType); if (!Enum.IsDefined(typeof(SupportedCodecType), codecType)) { @@ -387,12 +388,12 @@ namespace Tizen.Multimedia.MediaCodec { ValidateNotDisposed(); - if (CheckMimeType(typeof(MediaFormatVideoMimeType), (int)type) == false) + if (CheckMimeType(typeof(MediaFormatVideoMimeType), type) == false) { return 0; } - return GetCodecType((int)type, encoder); + return GetCodecType(type, typeof(MediaFormatVideoMimeType), encoder); } /// @@ -409,17 +410,18 @@ namespace Tizen.Multimedia.MediaCodec { ValidateNotDisposed(); - if (CheckMimeType(typeof(MediaFormatAudioMimeType), (int)type) == false) + if (CheckMimeType(typeof(MediaFormatAudioMimeType), type) == false) { return 0; } - return GetCodecType((int)type, encoder); + return GetCodecType(type, typeof(MediaFormatAudioMimeType), encoder); } - private MediaCodecTypes GetCodecType(int mimeType, bool isEncoder) + private MediaCodecTypes GetCodecType(T mimeType, Type type, bool isEncoder) { - int codecType = mimeType & CodecTypeMask; + dynamic changedType = Convert.ChangeType(mimeType, type); + int codecType = TypeConverter.ToNative(changedType); Native.GetSupportedType(_handle, codecType, isEncoder, out int value). ThrowIfFailed("Failed to get supported media codec type."); @@ -427,15 +429,16 @@ namespace Tizen.Multimedia.MediaCodec return (MediaCodecTypes)value; } - private bool CheckMimeType(Type type, int value) + private bool CheckMimeType(Type mimeType, T value) { - int codecType = value & CodecTypeMask; - - if (!Enum.IsDefined(type, value)) + if (!Enum.IsDefined(mimeType, value)) { throw new ArgumentException($"The mime type value is invalid : { value }."); } + dynamic changedType = Convert.ChangeType(value, mimeType); + var codecType = TypeConverter.ToNative(changedType); + return Enum.IsDefined(typeof(SupportedCodecType), codecType); } diff --git a/src/Tizen.Multimedia.MediaCodec/MediaCodec/SupportedCodecType.cs b/src/Tizen.Multimedia.MediaCodec/MediaCodec/SupportedCodecType.cs index 999808f..3374c3c 100644 --- a/src/Tizen.Multimedia.MediaCodec/MediaCodec/SupportedCodecType.cs +++ b/src/Tizen.Multimedia.MediaCodec/MediaCodec/SupportedCodecType.cs @@ -36,6 +36,7 @@ namespace Tizen.Multimedia.MediaCodec Wma2 = 0x10A1, WmaPro = 0x10A2, WmaLossless = 0x10A3, + Opus = 0x10D0, H261 = 0x2010, H263 = 0x2020, @@ -49,4 +50,41 @@ namespace Tizen.Multimedia.MediaCodec // VP9 = 0x20A0, // VC1 = 0x20B0, } + + internal static class TypeConverter + { + private const int CodecTypeMask = 0xFFFF; + + internal static int ToPublic(SupportedCodecType type) + { + int ret = (int)type; + + switch (type) + { + case SupportedCodecType.Opus: + ret = (int)MediaFormatAudioMimeType.Opus & CodecTypeMask; + break; + } + + return ret; + } + + internal static int ToNative(MediaFormatAudioMimeType type) + { + int ret = (int)type & CodecTypeMask; + switch (type) + { + case MediaFormatAudioMimeType.Opus: + ret = (int)SupportedCodecType.Opus; + break; + } + + return ret; + } + + internal static int ToNative(MediaFormatVideoMimeType type) + { + return (int)type & CodecTypeMask; + } + } } -- 2.7.4