2014-06-01 04:11:04 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2014-05-08 20:09:53 +00:00
|
|
|
|
using System;
|
2014-04-23 00:50:47 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Dlna
|
|
|
|
|
{
|
|
|
|
|
public class MediaFormatProfileResolver
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
public MediaFormatProfile[] ResolveVideoFormat(string container, string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestampType)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "asf"))
|
2014-04-24 05:08:10 +00:00
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
MediaFormatProfile? val = ResolveVideoASFFormat(videoCodec, audioCodec, width, height);
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return val.HasValue ? new MediaFormatProfile[] { val.Value } : new MediaFormatProfile[]{};
|
2014-04-24 05:08:10 +00:00
|
|
|
|
}
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "mp4"))
|
2014-04-24 05:08:10 +00:00
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
MediaFormatProfile? val = ResolveVideoMP4Format(videoCodec, audioCodec, width, height);
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return val.HasValue ? new MediaFormatProfile[] { val.Value } : new MediaFormatProfile[] { };
|
2014-04-24 05:08:10 +00:00
|
|
|
|
}
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "avi"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.AVI };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "mkv"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.MATROSKA };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "mpeg2ps") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(container, "ts"))
|
2014-04-24 05:08:10 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.MPEG_PS_NTSC, MediaFormatProfile.MPEG_PS_PAL };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "mpeg1video"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.MPEG1 };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "mpeg2ts") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(container, "mpegts") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(container, "m2ts"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
2014-04-24 05:08:10 +00:00
|
|
|
|
return ResolveVideoMPEG2TSFormat(videoCodec, audioCodec, width, height, timestampType);
|
2014-04-23 00:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "flv"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.FLV };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "wtv"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.WTV };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "3gp"))
|
2014-04-24 05:08:10 +00:00
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
MediaFormatProfile? val = ResolveVideo3GPFormat(videoCodec, audioCodec);
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return val.HasValue ? new MediaFormatProfile[] { val.Value } : new MediaFormatProfile[] { };
|
2014-04-24 05:08:10 +00:00
|
|
|
|
}
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "ogv") || StringHelper.EqualsIgnoreCase(container, "ogg"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.OGV };
|
2014-04-18 05:03:01 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { };
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
private MediaFormatProfile[] ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestampType)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
string suffix = "";
|
2014-04-18 05:03:01 +00:00
|
|
|
|
|
2014-04-18 17:16:25 +00:00
|
|
|
|
switch (timestampType)
|
|
|
|
|
{
|
2014-04-25 02:45:06 +00:00
|
|
|
|
case TransportStreamTimestamp.None:
|
2014-04-18 17:16:25 +00:00
|
|
|
|
suffix = "_ISO";
|
|
|
|
|
break;
|
2014-04-25 02:45:06 +00:00
|
|
|
|
case TransportStreamTimestamp.Valid:
|
2014-04-18 17:16:25 +00:00
|
|
|
|
suffix = "_T";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:44:17 +00:00
|
|
|
|
string resolution = "S";
|
2014-04-18 17:16:25 +00:00
|
|
|
|
if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
|
|
|
|
|
{
|
|
|
|
|
resolution = "H";
|
|
|
|
|
}
|
2014-04-18 05:03:01 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg2video"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
{
|
2014-05-08 20:44:17 +00:00
|
|
|
|
List<MediaFormatProfile> list = new List<MediaFormatProfile>();
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
|
|
|
|
list.Add(ValueOf("MPEG_TS_SD_NA" + suffix));
|
|
|
|
|
list.Add(ValueOf("MPEG_TS_SD_EU" + suffix));
|
|
|
|
|
list.Add(ValueOf("MPEG_TS_SD_KO" + suffix));
|
2014-04-18 05:03:01 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if ((timestampType == TransportStreamTimestamp.Valid) && StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(MediaFormatProfile.MPEG_TS_JP_T);
|
|
|
|
|
}
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return list.ToArray(list.Count);
|
2014-04-23 00:50:47 +00:00
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(videoCodec, "h264"))
|
2014-04-18 17:16:25 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "lpcm"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_50_LPCM_T };
|
2014-04-18 17:16:25 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "dts"))
|
2014-04-18 17:16:25 +00:00
|
|
|
|
{
|
2014-04-25 02:45:06 +00:00
|
|
|
|
if (timestampType == TransportStreamTimestamp.None)
|
2014-04-18 17:16:25 +00:00
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_DTS_ISO };
|
2014-04-18 17:16:25 +00:00
|
|
|
|
}
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_DTS_T };
|
2014-04-18 17:16:25 +00:00
|
|
|
|
}
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2015-02-05 21:14:19 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "mp2"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
{
|
2014-04-25 02:45:06 +00:00
|
|
|
|
if (timestampType == TransportStreamTimestamp.None)
|
2014-04-23 00:50:47 +00:00
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_ISO", resolution)) };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_T", resolution)) };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AAC_MULT5{1}", resolution, suffix)) };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_MPEG1_L3{1}", resolution, suffix)) };
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) ||
|
2014-06-01 04:11:04 +00:00
|
|
|
|
StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AC3{1}", resolution, suffix)) };
|
2014-04-18 17:16:25 +00:00
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (StringHelper.EqualsIgnoreCase(videoCodec, "vc1"))
|
2014-04-18 17:16:25 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
|
2014-04-18 17:16:25 +00:00
|
|
|
|
{
|
|
|
|
|
if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.VC1_TS_AP_L2_AC3_ISO };
|
2014-04-18 17:16:25 +00:00
|
|
|
|
}
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { MediaFormatProfile.VC1_TS_AP_L1_AC3_ISO };
|
2014-04-18 17:16:25 +00:00
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "dts"))
|
2014-04-24 05:08:10 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
suffix = StringHelper.EqualsIgnoreCase(suffix, "_ISO") ? suffix : "_T";
|
2014-04-24 05:08:10 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("VC1_TS_HD_DTS{0}", suffix)) };
|
2014-04-24 05:08:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg4") || StringHelper.EqualsIgnoreCase(videoCodec, "msmpeg4"))
|
2014-04-24 05:08:10 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AAC{0}", suffix)) };
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG1_L3{0}", suffix)) };
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "mp2"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG2_L2{0}", suffix)) };
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AC3{0}", suffix)) };
|
2014-04-18 17:16:25 +00:00
|
|
|
|
}
|
2014-04-18 05:03:01 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return new MediaFormatProfile[]{};
|
2014-04-23 00:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MediaFormatProfile ValueOf(string value)
|
|
|
|
|
{
|
|
|
|
|
return (MediaFormatProfile)Enum.Parse(typeof(MediaFormatProfile), value, true);
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 05:08:10 +00:00
|
|
|
|
private MediaFormatProfile? ResolveVideoMP4Format(string videoCodec, string audioCodec, int? width, int? height)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(videoCodec, "h264"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "lpcm"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.AVC_MP4_LPCM;
|
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) ||
|
2014-06-01 04:11:04 +00:00
|
|
|
|
StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.AVC_MP4_MP_SD_AC3;
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.AVC_MP4_MP_SD_MPEG1_L3;
|
|
|
|
|
}
|
|
|
|
|
if (width.HasValue && height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if ((width.Value <= 720) && (height.Value <= 576))
|
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.AVC_MP4_MP_SD_AAC_MULT5;
|
|
|
|
|
}
|
|
|
|
|
else if ((width.Value <= 1280) && (height.Value <= 720))
|
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.AVC_MP4_MP_HD_720p_AAC;
|
|
|
|
|
}
|
|
|
|
|
else if ((width.Value <= 1920) && (height.Value <= 1080))
|
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.AVC_MP4_MP_HD_1080i_AAC;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg4") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(videoCodec, "msmpeg4"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (width.HasValue && height.HasValue && width.Value <= 720 && height.Value <= 576)
|
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.MPEG4_P2_MP4_ASP_AAC;
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "ac3") || StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.MPEG4_P2_MP4_NDSD;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.MPEG4_P2_MP4_SP_L6_AAC;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (StringHelper.EqualsIgnoreCase(videoCodec, "h263") && StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.MPEG4_H263_MP4_P0_L10_AAC;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return null;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
private MediaFormatProfile? ResolveVideo3GPFormat(string videoCodec, string audioCodec)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(videoCodec, "h264"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.AVC_3GPP_BL_QCIF15_AAC;
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg4") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(videoCodec, "msmpeg4"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "wma"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.MPEG4_P2_3GPP_SP_L0B_AAC;
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(audioCodec, "amrnb"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.MPEG4_P2_3GPP_SP_L0B_AMR;
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (StringHelper.EqualsIgnoreCase(videoCodec, "h263") && StringHelper.EqualsIgnoreCase(audioCodec, "amrnb"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.MPEG4_H263_3GPP_P0_L10_AMR;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return null;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
|
|
|
|
private MediaFormatProfile? ResolveVideoASFFormat(string videoCodec, string audioCodec, int? width, int? height)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(videoCodec, "wmv") &&
|
|
|
|
|
(string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "wma") || StringHelper.EqualsIgnoreCase(videoCodec, "wmapro")))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (width.HasValue && height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if ((width.Value <= 720) && (height.Value <= 576))
|
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "wma"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.WMVMED_FULL;
|
|
|
|
|
}
|
|
|
|
|
return MediaFormatProfile.WMVMED_PRO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "wma"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.WMVHIGH_FULL;
|
|
|
|
|
}
|
|
|
|
|
return MediaFormatProfile.WMVHIGH_PRO;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(videoCodec, "vc1"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (width.HasValue && height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if ((width.Value <= 720) && (height.Value <= 576))
|
|
|
|
|
return MediaFormatProfile.VC1_ASF_AP_L1_WMA;
|
|
|
|
|
if ((width.Value <= 1280) && (height.Value <= 720))
|
|
|
|
|
return MediaFormatProfile.VC1_ASF_AP_L2_WMA;
|
|
|
|
|
if ((width.Value <= 1920) && (height.Value <= 1080))
|
|
|
|
|
return MediaFormatProfile.VC1_ASF_AP_L3_WMA;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-01 04:11:04 +00:00
|
|
|
|
else if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg2video"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.DVR_MS;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return null;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
public MediaFormatProfile? ResolveAudioFormat(string container, int? bitrate, int? frequency, int? channels)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "asf"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return ResolveAudioASFFormat(bitrate);
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "mp3"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.MP3;
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "lpcm"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return ResolveAudioLPCMFormat(frequency, channels);
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "mp4") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(container, "aac"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return ResolveAudioMP4Format(bitrate);
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "adts"))
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return ResolveAudioADTSFormat(bitrate);
|
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "flac"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.FLAC;
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "oga") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(container, "ogg"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.OGG;
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
private MediaFormatProfile ResolveAudioASFFormat(int? bitrate)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (bitrate.HasValue && bitrate.Value <= 193)
|
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.WMA_BASE;
|
|
|
|
|
}
|
|
|
|
|
return MediaFormatProfile.WMA_FULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
private MediaFormatProfile? ResolveAudioLPCMFormat(int? frequency, int? channels)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (frequency.HasValue && channels.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (frequency.Value == 44100 && channels.Value == 1)
|
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.LPCM16_44_MONO;
|
|
|
|
|
}
|
|
|
|
|
if (frequency.Value == 44100 && channels.Value == 2)
|
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.LPCM16_44_STEREO;
|
|
|
|
|
}
|
|
|
|
|
if (frequency.Value == 48000 && channels.Value == 1)
|
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.LPCM16_48_MONO;
|
|
|
|
|
}
|
2017-04-11 17:04:13 +00:00
|
|
|
|
if (frequency.Value == 48000 && channels.Value == 2)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.LPCM16_48_STEREO;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return null;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MediaFormatProfile.LPCM16_48_STEREO;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
private MediaFormatProfile ResolveAudioMP4Format(int? bitrate)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (bitrate.HasValue && bitrate.Value <= 320)
|
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.AAC_ISO_320;
|
|
|
|
|
}
|
|
|
|
|
return MediaFormatProfile.AAC_ISO;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
private MediaFormatProfile ResolveAudioADTSFormat(int? bitrate)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (bitrate.HasValue && bitrate.Value <= 320)
|
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.AAC_ADTS_320;
|
|
|
|
|
}
|
|
|
|
|
return MediaFormatProfile.AAC_ADTS;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
public MediaFormatProfile? ResolveImageFormat(string container, int? width, int? height)
|
2014-04-18 05:03:01 +00:00
|
|
|
|
{
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "jpeg") ||
|
|
|
|
|
StringHelper.EqualsIgnoreCase(container, "jpg"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return ResolveImageJPGFormat(width, height);
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "png"))
|
2014-08-06 04:18:13 +00:00
|
|
|
|
return ResolveImagePNGFormat(width, height);
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "gif"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.GIF_LRG;
|
2014-04-23 00:50:47 +00:00
|
|
|
|
|
2014-06-01 04:11:04 +00:00
|
|
|
|
if (StringHelper.EqualsIgnoreCase(container, "raw"))
|
2014-04-18 05:03:01 +00:00
|
|
|
|
return MediaFormatProfile.RAW;
|
|
|
|
|
|
2014-04-23 00:50:47 +00:00
|
|
|
|
return null;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MediaFormatProfile ResolveImageJPGFormat(int? width, int? height)
|
|
|
|
|
{
|
|
|
|
|
if (width.HasValue && height.HasValue)
|
|
|
|
|
{
|
2014-08-01 00:37:06 +00:00
|
|
|
|
if ((width.Value <= 160) && (height.Value <= 160))
|
2014-08-06 04:18:13 +00:00
|
|
|
|
return MediaFormatProfile.JPEG_TN;
|
2014-08-01 00:37:06 +00:00
|
|
|
|
|
2014-04-18 05:03:01 +00:00
|
|
|
|
if ((width.Value <= 640) && (height.Value <= 480))
|
|
|
|
|
return MediaFormatProfile.JPEG_SM;
|
|
|
|
|
|
|
|
|
|
if ((width.Value <= 1024) && (height.Value <= 768))
|
|
|
|
|
{
|
|
|
|
|
return MediaFormatProfile.JPEG_MED;
|
|
|
|
|
}
|
2014-08-01 00:37:06 +00:00
|
|
|
|
|
|
|
|
|
return MediaFormatProfile.JPEG_LRG;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-01 00:37:06 +00:00
|
|
|
|
return MediaFormatProfile.JPEG_SM;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
2014-08-06 04:18:13 +00:00
|
|
|
|
|
|
|
|
|
private MediaFormatProfile ResolveImagePNGFormat(int? width, int? height)
|
|
|
|
|
{
|
|
|
|
|
if (width.HasValue && height.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if ((width.Value <= 160) && (height.Value <= 160))
|
|
|
|
|
return MediaFormatProfile.PNG_TN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MediaFormatProfile.PNG_LRG;
|
|
|
|
|
}
|
2014-04-18 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|