コード例 #1
0
ファイル: Smooth.cs プロジェクト: pinglossy/smoothget
 public AudioTrackInfo(XmlNode element, IDictionary<string, string> streamAttributes, uint index, StreamInfo stream)
     : base(element, index, stream)
 {
     WaveFormatEx waveFormatEx;
       if (base.Attributes.ContainsKey("WaveFormatEx")) {
     byte[] data = Parse.HexStringAttribute(base.Attributes, "WaveFormatEx");
     waveFormatEx = new WaveFormatEx(data);
       }
       else {
     ushort wFormatTag = Parse.UInt16Attribute(base.Attributes, "AudioTag");
     ushort nChannels = Parse.UInt16Attribute(base.Attributes, "Channels");
     uint nSamplesPerSec = Parse.UInt32Attribute(base.Attributes, "SamplingRate");
     uint num = Parse.UInt32Attribute(base.Attributes, "Bitrate");
     ushort nBlockAlign = Parse.UInt16Attribute(base.Attributes, "PacketSize");
     ushort wBitsPerSample = Parse.UInt16Attribute(base.Attributes, "BitsPerSample");
     byte[] decoderSpecificData = Parse.HexStringAttribute(base.Attributes, "CodecPrivateData");
     waveFormatEx = new WaveFormatEx(wFormatTag, nChannels, nSamplesPerSec, num / 8u, nBlockAlign, wBitsPerSample, decoderSpecificData);
       }
       byte[] audioInfoBytes = MkvUtils.GetAudioInfoBytes(
       waveFormatEx.nSamplesPerSec, (ulong)waveFormatEx.nChannels, (ulong)waveFormatEx.wBitsPerSample);
       switch (waveFormatEx.wFormatTag) {
     case 353: case 354: {
       base.TrackEntry = new TrackEntry(TrackType.Audio, audioInfoBytes, CodecID.A_MS, waveFormatEx.GetBytes());
       break;
     }
     case 255: case 5633: {
       base.TrackEntry = new TrackEntry(TrackType.Audio, audioInfoBytes, CodecID.A_AAC, GetAudioSpecificConfigBytes(
       waveFormatEx.nSamplesPerSec, (byte)waveFormatEx.nChannels));
       break;
     }
     case 1: {
       throw new Exception("Unsupported audio format: 'LPCM'!");
     }
     case 65534: {
       throw new Exception("Unsupported audio format: 'Vendor-extensible format'!");
     }
     default: {
       throw new Exception("Unsupported AudioTag: '" + waveFormatEx.wFormatTag + "'");
     }
       }
       if (base.Attributes.ContainsKey("Name")) {
     base.TrackEntry.Name = Parse.StringAttribute(streamAttributes, "Name");
       }
       base.TrackEntry.Language = LanguageID.Hungarian;  // TODO: Make this configurable.
       base.Description = string.Format("{0} {1} channels {2} Hz @ {3} kbps", new object[] {
       GetCodecNameForAudioTag(waveFormatEx.wFormatTag), waveFormatEx.nChannels, waveFormatEx.nSamplesPerSec,
       base.Bitrate / 1000u });
 }
コード例 #2
0
ファイル: Smooth.cs プロジェクト: pinglossy/smoothget
 public VideoTrackInfo(XmlNode element, IDictionary<string, string> streamAttributes, uint index, StreamInfo stream)
     : base(element, index, stream)
 {
     uint pixelWidth = base.Attributes.ContainsKey("MaxWidth") ? Parse.UInt32Attribute(base.Attributes, "MaxWidth") :
                 base.Attributes.ContainsKey("Width") ? Parse.UInt32Attribute(base.Attributes, "Width") :
                 streamAttributes.ContainsKey("MaxWidth") ? Parse.UInt32Attribute(streamAttributes, "MaxWidth") : 0u;
       if (pixelWidth == 0u) {
     throw new Exception("Missing video width attribute!");
       }
       uint pixelHeight = base.Attributes.ContainsKey("MaxHeight") ? Parse.UInt32Attribute(base.Attributes, "MaxHeight") :
                  base.Attributes.ContainsKey("Height") ? Parse.UInt32Attribute(base.Attributes, "Height") :
                  streamAttributes.ContainsKey("MaxHeight") ? Parse.UInt32Attribute(streamAttributes, "MaxHeight") : 0u;
       if (pixelHeight == 0u) {
     throw new Exception("Missing video height attribute!");
       }
       uint displayWidth = streamAttributes.ContainsKey("DisplayWidth") ?
                   Parse.UInt32Attribute(streamAttributes, "DisplayWidth") : 0u;
       if (displayWidth == 0u) {
     displayWidth = pixelWidth;
       }
       uint displayHeight = streamAttributes.ContainsKey("DisplayHeight") ?
                    Parse.UInt32Attribute(streamAttributes, "DisplayHeight") : 0u;
       if (displayHeight == 0u) {
     displayHeight = pixelHeight;
       }
       byte[] videoInfoBytes = MkvUtils.GetVideoInfoBytes(
       (ulong)pixelWidth, (ulong)pixelHeight, (ulong)displayWidth, (ulong)displayHeight);
       byte[] codecPrivateData = base.Attributes.ContainsKey("CodecPrivateData") ?
                         Parse.HexStringAttribute(base.Attributes, "CodecPrivateData") : null;
       if (codecPrivateData == null) {
     throw new Exception("Missing CodecPrivateData attribute!");
       }
       string fourcc = base.Attributes.ContainsKey("FourCC") ? Parse.StringAttribute(base.Attributes, "FourCC") :
               streamAttributes.ContainsKey("FourCC") ? Parse.StringAttribute(streamAttributes, "FourCC") : null;
       switch (fourcc) {
     case "WVC1": {
       base.TrackEntry = new TrackEntry(
       TrackType.Video, videoInfoBytes, CodecID.V_MS, VideoTrackInfo.GetVfWCodecPrivate(
           pixelWidth, pixelHeight, fourcc, codecPrivateData));
       break;
     }
     case "H264": {
       ushort nalUnitLengthField = 4;
       if (base.Attributes.ContainsKey("NALUnitLengthField")) {
     nalUnitLengthField = Parse.UInt16Attribute(base.Attributes, "NALUnitLengthField");
       }
       base.TrackEntry = new TrackEntry(
       TrackType.Video, videoInfoBytes, CodecID.V_AVC,
       this.GetAVCCodecPrivate(codecPrivateData, nalUnitLengthField));
       break;
     }
     case null: {
       throw new Exception("Missing FourCC attribute!");
     }
     default: {
       throw new Exception("Unsupported video FourCC: '" + fourcc + "'");
     }
       }
       if (base.Attributes.ContainsKey("Name")) {
     base.TrackEntry.Name = Parse.StringAttribute(streamAttributes, "Name");
       }
       base.TrackEntry.Language = LanguageID.Hungarian;  // TODO: Make this configurable.
       base.Description = string.Format("{0} {1}x{2} ({3}x{4}) @ {5} kbps", new object[] {
       fourcc, pixelWidth, pixelHeight, displayWidth, displayHeight, base.Bitrate / 1000u });
 }
コード例 #3
0
ファイル: Smooth.cs プロジェクト: pinglossy/smoothget
 public TrackInfo(XmlNode element, uint index, StreamInfo stream)
 {
     if (element.Name != "QualityLevel") {
     throw new Exception("Source element is not a(n) QualityLevel element!");
       }
       this.Attributes = Parse.Attributes(element);
       this.CustomAttributes = Parse.CustomAttributes(element);
       this.Index = index;
       if (this.Attributes.ContainsKey("Index")) {
     this.Index = Parse.UInt32Attribute(this.Attributes, "Index");
       }
       if (this.Index != index) {
     throw new Exception("Missing quality level index: " + index);
       }
       this.Bitrate = Parse.UInt32Attribute(this.Attributes, "Bitrate");
       this.Stream = stream;
 }