UInt32Attribute() public static method

public static UInt32Attribute ( string>.IDictionary attributes, string key ) : uint
attributes string>.IDictionary
key string
return uint
Example #1
0
 public ChunkInfo(XmlNode element, uint index, ulong starttime)
 {
     if (element.Name != "c")
     {
         throw new Exception("Source element is not a(n) c element!");
     }
     this.Attributes = Parse.Attributes(element);
     this.Index      = index;
     if (this.Attributes.ContainsKey("n"))
     {
         this.Index = Parse.UInt32Attribute(this.Attributes, "n");
     }
     if (this.Index != index)
     {
         throw new Exception("Missing chunk index: " + index);
     }
     this.StartTime = starttime;
     if (this.Attributes.ContainsKey("t"))
     {
         this.StartTime = Parse.UInt64Attribute(this.Attributes, "t");
     }
     if (this.Attributes.ContainsKey("d"))
     {
         this.Duration = Parse.UInt64Attribute(this.Attributes, "d");
     }
 }
Example #2
0
        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
            });
        }
Example #3
0
 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;
 }
Example #4
0
 private ManifestInfo(XmlNode element, Uri uri)
 {
     this.Uri = uri;
     if (element.Name != "SmoothStreamingMedia")
     {
         throw new Exception("Source element is not a(n) SmoothStreamingMedia element!");
     }
     this.Attributes   = Parse.Attributes(element);
     this.MajorVersion = Parse.UInt32Attribute(this.Attributes, "MajorVersion");
     this.MinorVersion = Parse.UInt32Attribute(this.Attributes, "MinorVersion");
     this.Duration     = Parse.UInt64Attribute(this.Attributes, "Duration");
     this.IsLive       = false;
     if (this.Attributes.ContainsKey("IsLive"))
     {
         this.IsLive = Parse.BoolAttribute(this.Attributes, "IsLive");
     }
     this.TimeScale = 10000000uL;
     if (this.Attributes.ContainsKey("TimeScale"))
     {
         this.TimeScale = Parse.UInt64Attribute(this.Attributes, "TimeScale");
     }
     this.AvailableStreams = new List <StreamInfo>();
     foreach (XmlNode element2 in element.SelectNodes("StreamIndex")) // Automatic cast to XmlNode.
     {
         this.AvailableStreams.Add(new StreamInfo(element2, this.Uri));
     }
     this.SelectedStreams = new List <StreamInfo>();
     for (int i = 0; i < this.AvailableStreams.Count; i++)
     {
         if (this.AvailableStreams[i].Type != MediaStreamType.Script)
         {
             this.SelectedStreams.Add(this.AvailableStreams[i]);
         }
     }
     this.TotalTicks = this.IsLive ? 0 : (ulong)(this.Duration / this.TimeScale * 10000000.0);
 }
Example #5
0
        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,
                    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
            });
        }
Example #6
0
        public StreamInfo(XmlNode element, Uri manifestUri)
        {
            if (element.Name != "StreamIndex")
            {
                throw new Exception("Source element is not a(n) StreamIndex element!");
            }
            this.Attributes       = Parse.Attributes(element);
            this.CustomAttributes = Parse.CustomAttributes(element);
            this.Type             = Parse.MediaStreamTypeAttribute(this.Attributes, "Type");
            this.Subtype          = this.Attributes.ContainsKey("Subtype") ? Parse.StringAttribute(this.Attributes, "Subtype") : "";
            if (this.Attributes.ContainsKey("Url"))
            {
                this.CheckUrlAttribute();
            }
            this.AvailableTracks = new List <TrackInfo>();
            XmlNodeList xmlNodeList = element.SelectNodes("QualityLevel");
            int         i;

            for (i = 0; i < xmlNodeList.Count; ++i)
            {
                TrackInfo trackInfo;
                if (this.Type == MediaStreamType.Audio)
                {
                    trackInfo = new AudioTrackInfo(xmlNodeList[i], this.Attributes, (uint)i, this);
                }
                else if (this.Type == MediaStreamType.Video)
                {
                    trackInfo = new VideoTrackInfo(xmlNodeList[i], this.Attributes, (uint)i, this);
                }
                else
                {
                    continue;
                }
                int num = 0;
                while (num < this.AvailableTracks.Count && this.AvailableTracks[num].Bitrate > trackInfo.Bitrate)
                {
                    num++;
                }
                this.AvailableTracks.Insert(num, trackInfo);
            }
            this.ChunkList = new List <ChunkInfo>();
            XmlNodeList xmlNodeList2 = element.SelectNodes("c");
            ulong       num2         = 0uL;

            for (i = 0; i < xmlNodeList2.Count; i++)
            {
                ChunkInfo chunkInfo = new ChunkInfo(xmlNodeList2[i], (uint)i, num2);
                this.ChunkList.Add(chunkInfo);
                num2 += chunkInfo.Duration;
            }
            if (this.Attributes.ContainsKey("Chunks"))
            {
                uint chunkCount = Parse.UInt32Attribute(this.Attributes, "Chunks");
                if (this.ChunkList.Count > 0 && this.ChunkList.Count != chunkCount)
                {
                    throw new Exception("Chunk count mismatch: c=" + this.ChunkList.Count + " chunks=" + chunkCount);
                }
                this.ChunkCount = (int)chunkCount;
            }
            else
            {
                this.ChunkCount = this.ChunkList.Count; // Can be 0 if no `<c' tags.
            }
            this.pureUrl        = manifestUri.AbsoluteUri;
            this.pureUrl        = this.pureUrl.Substring(0, this.pureUrl.LastIndexOf('/'));
            this.SelectedTracks = new List <TrackInfo>();
            if (this.AvailableTracks.Count > 0)
            {
                this.SelectedTracks.Add(this.AvailableTracks[0]);
            }
        }