Example #1
0
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                var itemsCount = reader.ReadByte();

                UnkData = new audMathOperationSoundData[itemsCount];

                for (int i = 0; i < itemsCount; i++)
                {
                    UnkData[i] = new audMathOperationSoundData
                    {
                        UnkByte        = reader.ReadByte(),
                        UnkInt         = reader.ReadInt32(),
                        UnkInt1        = reader.ReadInt32(),
                        UnkInt2        = reader.ReadInt32(),
                        UnkInt3        = reader.ReadInt32(),
                        UnkInt4        = reader.ReadInt32(),
                        ParameterHash  = new audHashString(parent, reader.ReadUInt32()),
                        ParameterHash1 = new audHashString(parent, reader.ReadUInt32())
                    };
                }

                return((int)reader.BaseStream.Position);
            }
        }
Example #2
0
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                var itemsCount = reader.ReadInt32();

                Items = new audSoundSetItem[itemsCount];

                for (int i = 0; i < itemsCount; i++)
                {
                    Items[i] = new audSoundSetItem
                    {
                        ScriptName = new audHashString(parent, reader.ReadUInt32()),
                        SoundName  = new audHashString(parent, reader.ReadUInt32())
                    };

                    AudioTracks.Add(new audHashDesc(Items[i].SoundName,
                                                    bytesRead + ((int)reader.BaseStream.Position - 4)));
                }
            }

            return(data.Length);
        }
Example #3
0
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                UnkShort = reader.ReadUInt16();

                UnkShort1 = reader.ReadUInt16();

                UnkShort2 = reader.ReadUInt16();

                UnkShort3 = reader.ReadUInt16();

                UnkHash = new audHashString(parent, reader.ReadUInt32());

                ParameterHash = new audHashString(parent, reader.ReadUInt32());

                ParameterHash1 = new audHashString(parent, reader.ReadUInt32());

                ParameterHash2 = new audHashString(parent, reader.ReadUInt32());

                ParameterHash3 = new audHashString(parent, reader.ReadUInt32());

                int numItems = reader.ReadByte();

                for (int i = 0; i < numItems; i++)
                {
                    AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                    bytesRead + ((int)reader.BaseStream.Position - 4));
                }
            }

            return(data.Length);
        }
Example #4
0
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                UnkByte = reader.ReadByte();

                DataStart = reader.ReadByte();

                reader.ReadBytes(DataStart);

                int numItems = reader.ReadByte();

                AudioTrackUnkFloats = new float[numItems];

                for (int i = 0; i < numItems; i++)
                {
                    AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                    bytesRead + ((int)reader.BaseStream.Position - 4));

                    AudioTrackUnkFloats[i] = reader.ReadSingle();
                }
            }

            return(data.Length);
        }
Example #5
0
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()), bytesRead + ((int)reader.BaseStream.Position - 4));

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()), bytesRead + ((int)reader.BaseStream.Position - 4));

                UnkFloat = reader.ReadSingle();                                  //0x8

                UnkFloat1 = reader.ReadSingle();                                 //0xC

                ParameterHash = new audHashString(parent, reader.ReadUInt32());  //0x10

                ParameterHash1 = new audHashString(parent, reader.ReadUInt32()); //0x14

                ParameterHash2 = new audHashString(parent, reader.ReadUInt32()); //0x18

                ParameterHash3 = new audHashString(parent, reader.ReadUInt32()); //0x1C

                ParameterHash4 = new audHashString(parent, reader.ReadUInt32()); //0x20

                UnkInt = reader.ReadInt32();                                     //0x24-0x28

                ParameterHash5 = new audHashString(parent, reader.ReadUInt32()); //0x28-0x2C

                UnkByte = reader.ReadByte();                                     //0x2C-0x2D

                return((int)reader.BaseStream.Position);
            }
        }
Example #6
0
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()), bytesRead + ((int)reader.BaseStream.Position - 4));

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()), bytesRead + ((int)reader.BaseStream.Position - 4));

                UnkByte = reader.ReadByte();

                UnkFloat = reader.ReadSingle();

                UnkFloat1 = reader.ReadSingle();

                UnkInt2 = reader.ReadInt32();

                UnkCurvesHash = new audHashString(parent, reader.ReadUInt32());

                ParameterHash = new audHashString(parent, reader.ReadUInt32());

                ParameterHash1 = new audHashString(parent, reader.ReadUInt32());

                ParameterHash2 = new audHashString(parent, reader.ReadUInt32());

                ParameterHash3 = new audHashString(parent, reader.ReadUInt32());

                ParameterHash4 = new audHashString(parent, reader.ReadUInt32());

                return((int)reader.BaseStream.Position);
            }
        }
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                UnkShort = reader.ReadUInt16();

                UnkShort1 = reader.ReadUInt16();

                UnkShort2 = reader.ReadUInt16();

                UnkShort3 = reader.ReadUInt16();

                ParameterHash = new audHashString(parent, reader.ReadUInt32());

                ParameterHash1 = new audHashString(parent, reader.ReadUInt32());

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                return((int)reader.BaseStream.Position);
            }
        }
Example #8
0
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()), bytesRead + ((int)reader.BaseStream.Position - 4));

                FrameStartTime = reader.ReadInt32();

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()), bytesRead + ((int)reader.BaseStream.Position - 4));

                FrameTimeInterval = reader.ReadInt16();

                int itemsCount = reader.ReadByte();

                Variables = new audHashString[itemsCount];

                for (int i = 0; i < itemsCount; i++)
                {
                    Variables[i] = new audHashString(parent, reader.ReadUInt32());
                }

                UnkByteData = new byte[itemsCount];

                for (int i = 0; i < itemsCount; i++)
                {
                    UnkByteData[i] = reader.ReadByte();
                }

                return((int)reader.BaseStream.Position);
            }
        }
Example #9
0
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                int numItems = reader.ReadByte();

                Variables = new AudVariable[numItems];

                for (int i = 0; i < numItems; i++)
                {
                    Variables[i] = new AudVariable
                    {
                        Name     = new audHashString(parent, reader.ReadUInt32()),
                        Value    = reader.ReadSingle(),
                        UnkFloat = reader.ReadSingle(),
                        Flags    = reader.ReadByte()
                    };
                }
            }

            return(data.Length);
        }
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader =
                       new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                UnkShortA = reader.ReadUInt16();                                 //0x0-0x2

                UnkShortA1 = reader.ReadUInt16();                                //0x2-0x4

                UnkShortB = reader.ReadUInt16();                                 //0x4-0x6

                UnkShortB1 = reader.ReadUInt16();                                //0x6-0x8

                UnkByteA = reader.ReadByte();                                    //0x8-0x9

                UnkByteA1 = reader.ReadByte();                                   //0x9-0xA

                UnkInt = reader.ReadInt32();                                     //0xA-0xE

                UnkShortC = reader.ReadUInt16();                                 //0xE-0x10

                UnkIntA = reader.ReadInt32();                                    //0x10-0x14

                UnkIntA1 = reader.ReadInt32();                                   //0x14-0x18

                CurvesUnkHash = new audHashString(parent, reader.ReadUInt32());  //0x18-0x1C

                CurvesUnkHash1 = new audHashString(parent, reader.ReadUInt32()); //0x1C-0x20

                CurvesUnkHash2 = new audHashString(parent, reader.ReadUInt32()); //0x20-0x24

                ParameterHash = new audHashString(parent, reader.ReadUInt32());  //0x24-0x28

                ParameterHash1 = new audHashString(parent, reader.ReadUInt32()); //0x28-0x2C

                ParameterHash2 = new audHashString(parent, reader.ReadUInt32()); //0x2C-0x30

                ParameterHash3 = new audHashString(parent, reader.ReadUInt32()); //0x30-0x34

                ParameterHash4 = new audHashString(parent, reader.ReadUInt32()); //0x34-0x38

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4)); //0x38-0x3C

                UnkIntC = reader.ReadInt32();                                       //0x3C-0x40

                ParameterHash5 = new audHashString(parent, reader.ReadUInt32());    //0x40-0x44

                UnkFloat = reader.ReadSingle();                                     //0x44-0x48

                UnkFloat1 = reader.ReadSingle();                                    //0x48-0x4C

                return((int)reader.BaseStream.Position);
            }
        }
Example #11
0
 public void AddAudioTrack(LocalAudioTrack track, string deviceName)
 {
     ThreadHelper.EnsureIsMainThread();
     AudioTracks.Add(new AudioTrackViewModel(track, deviceName));
     LocalTracks.Add(new LocalTrackViewModel(Symbol.Volume)
     {
         DisplayName = deviceName
     });
 }
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4)); //0x0-0x4

                var itemCount = reader.ReadInt32();                                 //0x4-0x8

                UnkArrayData = new audParameterTransformData[itemCount];

                for (int i = 0; i < itemCount; i++)
                {
                    UnkArrayData[i] = new audParameterTransformData
                    {
                        ParameterHash = new audHashString(parent, reader.ReadUInt32()),
                        UnkFloat      = reader.ReadSingle(),
                        UnkFloat1     = reader.ReadSingle()
                    };

                    var nestedItemCount = reader.ReadInt32();

                    UnkArrayData[i].NestedData = new audParameterTransformDataNested[nestedItemCount];

                    for (int x = 0; x < nestedItemCount; x++)
                    {
                        UnkArrayData[i].NestedData[x] = new audParameterTransformDataNested
                        {
                            UnkFloat      = reader.ReadSingle(),
                            UnkInt        = reader.ReadInt32(),
                            ParameterHash = new audHashString(parent, reader.ReadUInt32()),
                            UnkFloat1     = reader.ReadSingle(),
                            UnkFloat2     = reader.ReadSingle()
                        };

                        var pairItemCount = reader.ReadInt32();

                        UnkArrayData[i].NestedData[x].NestedItems = new Pair <float, float> [pairItemCount];

                        for (int y = 0; y < pairItemCount; y++)
                        {
                            UnkArrayData[i].NestedData[x].NestedItems[y] =
                                new Pair <float, float>(reader.ReadSingle(), reader.ReadSingle());
                        }
                    }
                }

                return((int)reader.BaseStream.Position);
            }
        }
Example #13
0
        /// <summary>
        /// Callback on remote audio track added.
        ///
        /// For simplicity this grabs the first remote audio track found. However currently the user has no
        /// control over audio output, so this is only used for audio statistics.
        /// </summary>
        /// <param name="track">The audio track added.</param>
        /// <seealso cref="RemoteAudioTrack_FrameReady"/>
        private void OnRemoteAudioTrackAdded(RemoteAudioTrack track)
        {
            Logger.Log($"Added remote audio track {track.Name} of transceiver {track.Transceiver.Name}.");

            ThreadHelper.RunOnMainThread(() =>
            {
                var trvm = Transceivers.SingleOrDefault(tr => tr.Transceiver == track.Transceiver);
                Debug.Assert(trvm.Transceiver.RemoteAudioTrack == track);
                trvm.NotifyReceiverChanged(); // this is thread-aware
                // This raises property changed events in current thread, needs to be main one
                AudioTracks.Add(new AudioTrackViewModel(track));
            });
        }
Example #14
0
 private async void OnMediaTrackAdded(TrackType type, int trackId, string name)
 {
     var item = new DictionaryKeyValue
     {
         Id   = trackId,
         Name = name
     };
     await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () =>
     {
         if (type == TrackType.Audio)
         {
             if (AudioTracks.Count == 0)
             {
                 AudioTracks.Add(new DictionaryKeyValue {
                     Id = -1, Name = "Disabled"
                 });
             }
             AudioTracks.Add(item);
             if (_currentAudioTrack == null)
             {
                 _currentAudioTrack = item;
             }
             OnPropertyChanged(nameof(AudioTracks));
             OnPropertyChanged(nameof(CurrentAudioTrack));
         }
         else if (type == TrackType.Subtitle)
         {
             if (Subtitles.Count == 0)
             {
                 Subtitles.Add(new DictionaryKeyValue {
                     Id = -1, Name = "Disabled"
                 });
             }
             Subtitles.Add(item);
             if (_currentSubtitle == null)
             {
                 _currentSubtitle = item;
             }
             OnPropertyChanged(nameof(Subtitles));
             OnPropertyChanged(nameof(CurrentSubtitle));
         }
         else
         {
             Locator.NavigationService.Go(VLCPage.VideoPlayerPage);
         }
     });
 }
Example #15
0
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                UnkFloat = reader.ReadSingle();

                UnkFloat1 = reader.ReadSingle();

                UnkFloat2 = reader.ReadSingle();
            }

            return(data.Length);
        }
Example #16
0
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                var itemsCount = reader.ReadByte();

                UnkData = new audUnknownSoundData[itemsCount];

                for (int i = 0; i < itemsCount; i++)
                {
                    UnkData[i] = new audUnknownSoundData(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());

                    AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                    bytesRead + ((int)reader.BaseStream.Position - 4));
                }

                return((int)reader.BaseStream.Position);
            }
        }
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader =
                       new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                var itemCount = reader.ReadInt32();

                UnkArrayData = new audFluctuatorSoundData[itemCount];

                for (int i = 0; i < itemCount; i++)
                {
                    UnkArrayData[i] = new audFluctuatorSoundData
                    {
                        UnkByte       = reader.ReadByte(),
                        UnkByte1      = reader.ReadByte(),
                        ParameterHash = new audHashString(parent, reader.ReadUInt32()),
                        UnkFloat      = reader.ReadSingle(),
                        UnkFloat1     = reader.ReadSingle(),
                        UnkFloat2     = reader.ReadSingle(),
                        UnkFloat3     = reader.ReadSingle(),
                        UnkFloat4     = reader.ReadSingle(),
                        UnkFloat5     = reader.ReadSingle(),
                        UnkFloat6     = reader.ReadSingle(),
                        UnkFloat7     = reader.ReadSingle(),
                        UnkFloat8     = reader.ReadSingle(),
                        UnkFloat9     = reader.ReadSingle(),
                        UnkFloat10    = reader.ReadSingle()
                    };
                }
            }

            return(data.Length);
        }
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                OptAmpUnkHash = new audHashString(parent, reader.ReadUInt32()); //0x0-0x4

                UnkHash1 = new audHashString(parent, reader.ReadUInt32());      //0x4-0x8

                UnkFloat = reader.ReadSingle();                                 //0x8-0xC

                UnkInt2 = reader.ReadInt32();                                   //0xC-0x10

                trackCount = reader.ReadInt32();                                //0x10-0x14

                for (int i = 0; i < 4; i++)
                {
                    AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                    bytesRead + ((int)reader.BaseStream.Position - 4));
                }

                var itemCount = reader.ReadInt32();

                UnkArrayData = new audModularSynthSoundData[itemCount];

                for (int i = 0; i < itemCount; i++)
                {
                    UnkArrayData[i] = new audModularSynthSoundData(
                        new audHashString(parent, reader.ReadUInt32()),
                        new audHashString(parent, reader.ReadUInt32()),
                        reader.ReadSingle());
                }

                return((int)reader.BaseStream.Position);
            }
        }
Example #19
0
        private SessionModel()
        {
            _peerConnection.Connected                += OnPeerConnected;
            _peerConnection.LocalSdpReadytoSend      += OnLocalSdpReadyToSend;
            _peerConnection.IceCandidateReadytoSend  += OnIceCandidateReadyToSend;
            _peerConnection.IceStateChanged          += OnIceStateChanged;
            _peerConnection.IceGatheringStateChanged += OnIceGatheringStateChanged;
            _peerConnection.RenegotiationNeeded      += OnRenegotiationNeeded;
            _peerConnection.TransceiverAdded         += OnTransceiverAdded;
            _peerConnection.AudioTrackAdded          += OnRemoteAudioTrackAdded;
            _peerConnection.AudioTrackRemoved        += OnRemoteAudioTrackRemoved;
            _peerConnection.VideoTrackAdded          += OnRemoteVideoTrackAdded;
            _peerConnection.VideoTrackRemoved        += OnRemoteVideoTrackRemoved;
            _peerConnection.DataChannelAdded         += OnDataChannelAdded;
            _peerConnection.DataChannelRemoved       += OnDataChannelRemoved;

            NodeDssSignaler.OnConnect     += DssSignaler_OnConnected;
            NodeDssSignaler.OnDisconnect  += DssSignaler_OnDisconnected;
            NodeDssSignaler.OnMessage     += DssSignaler_OnMessage;
            NodeDssSignaler.OnFailure     += DssSignaler_OnFailure;
            NodeDssSignaler.OnPollingDone += DssSignaler_OnPollingDone;

            AudioTracks.Add(NullAudioTrack);
            VideoTracks.Add(NullVideoTrack);

            AudioTracks.CollectionChanged += LocalAudioTrackCollectionChanged;
            VideoTracks.CollectionChanged += LocalVideoTrackCollectionChanged;

            LocalTracks.Add(new AddNewTrackViewModel()
            {
                DisplayName = "Add audio track", PageType = typeof(AddAudioTrackPage)
            });
            LocalTracks.Add(new AddNewTrackViewModel()
            {
                DisplayName = "Add video track", PageType = typeof(AddVideoTrackPage)
            });
        }
Example #20
0
        public override int Deserialize(byte[] data)
        {
            int bytesRead = base.Deserialize(data);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                UnkFloat = reader.ReadSingle();

                UnkFloat1 = reader.ReadSingle();

                ParameterHash = new audHashString(parent, reader.ReadUInt32());

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                WaveSlotId = reader.ReadInt32();

                UnkHash1 = new audHashString(parent, reader.ReadUInt32());

                var itemCount = reader.ReadInt32();

                UnkArrayData = new Pair <int, audHashString> [itemCount];

                for (int i = 0; i < itemCount; i++)
                {
                    UnkArrayData[i] = new Pair <int, audHashString>(
                        reader.ReadInt32(),
                        new audHashString(parent, reader.ReadUInt32()));
                }

                return((int)reader.BaseStream.Position);
            }
        }
Example #21
0
        public DASHPlaylist(string[] playlistUrls, bool[] playlistsAudioOnly, List <AudioTrackMetadata> audioMetadata = null)
        {
            foreach ((string playlistUrl, bool audioOnly) in playlistUrls.Zip(playlistsAudioOnly))
            {
                string originalPlaylist = Requests.Request(playlistUrl, null);

                XmlDocument xmlDoc = new XmlDocument();

                try
                {
                    xmlDoc.LoadXml(originalPlaylist);
                    OriginalPlaylists.Add(originalPlaylist);
                }
                catch
                {
                    continue;
                }

                string baseUrl = playlistUrl.Substring(0, playlistUrl.LastIndexOf("/") + 1);

                Dictionary <string, string> initDataPairs = new Dictionary <string, string>();

                foreach (XmlElement adaptationSet in xmlDoc["MPD"]["Period"].GetElementsByTagName("AdaptationSet"))
                {
                    try
                    {
                        string keyId;
                        try
                        {
                            keyId = adaptationSet.GetElementsByTagName("ContentProtection").Cast <XmlElement>().Where(x => x.HasAttribute("cenc:default_KID")).FirstOrDefault().GetAttribute("cenc:default_KID");
                        }
                        catch
                        {
                            keyId = adaptationSet.GetElementsByTagName("ContentProtection").Cast <XmlElement>().Where(x => x.HasAttribute("_:default_KID")).FirstOrDefault().GetAttribute("_:default_KID");
                        }
                        string initData = adaptationSet.GetElementsByTagName("ContentProtection").Cast <XmlElement>().Where(x => x.GetAttribute("schemeIdUri").ToLower().Contains("edef8ba9-79d6-4ace-a3c8-27dcd51d21ed")).FirstOrDefault().FirstChild.InnerText;
                        if (!initDataPairs.ContainsKey(keyId))
                        {
                            initDataPairs.Add(keyId, initData);
                        }
                    }
                    catch { }
                }

                foreach (XmlElement adaptationSet in xmlDoc["MPD"]["Period"].GetElementsByTagName("AdaptationSet"))
                {
                    bool   isEncrypted = false;
                    string initDataB64 = null;

                    XmlNodeList contentProtectionElements = adaptationSet.GetElementsByTagName("ContentProtection");

                    if (contentProtectionElements.Count > 0)
                    {
                        isEncrypted = true;
                        string keyId;
                        try
                        {
                            keyId = contentProtectionElements.Cast <XmlElement>().Where(x => x.HasAttribute("cenc:default_KID")).FirstOrDefault().GetAttribute("cenc:default_KID");
                        }
                        catch
                        {
                            keyId = contentProtectionElements.Cast <XmlElement>().Where(x => x.HasAttribute("_:default_KID")).FirstOrDefault().GetAttribute("_:default_KID");
                        }
                        initDataB64 = initDataPairs[keyId];
                    }

                    foreach (XmlElement representation in adaptationSet.GetElementsByTagName("Representation"))
                    {
                        string url = representation.GetElementsByTagName("BaseURL")[0].InnerText;

                        if (!url.Contains("https://") && !url.Contains("http://"))
                        {
                            url = baseUrl + url;
                        }

                        if (url.StartsWith("http:"))
                        {
                            url = url.Replace("http:", "https:");
                        }

                        if (adaptationSet.GetAttribute("contentType").ToLower() == "audio" || adaptationSet.GetAttribute("mimeType").ToLower().Contains("audio"))
                        {
                            string name = null;
                            if (adaptationSet.HasAttribute("label"))
                            {
                                name = adaptationSet.GetAttribute("label");
                            }

                            string codec = null;

                            if (representation.HasAttribute("codecs"))
                            {
                                codec = representation.GetAttribute("codecs");
                            }
                            else
                            {
                                codec = adaptationSet.GetAttribute("codecs");
                            }

                            int channels = 2;

                            try
                            {
                                XmlElement audioChannelConfiguration = null;

                                try
                                {
                                    audioChannelConfiguration = representation.GetElementsByTagName("AudioChannelConfiguration").Cast <XmlElement>().FirstOrDefault();
                                }
                                catch
                                {
                                    audioChannelConfiguration = adaptationSet.GetElementsByTagName("AudioChannelConfiguration").Cast <XmlElement>().FirstOrDefault();
                                }

                                if (audioChannelConfiguration == null)
                                {
                                    audioChannelConfiguration = adaptationSet.GetElementsByTagName("AudioChannelConfiguration").Cast <XmlElement>().FirstOrDefault();
                                }

                                string channelValue = audioChannelConfiguration.GetAttribute("value");

                                if (channelValue == "2")
                                {
                                    channels = 2;
                                }
                                else if (channelValue == "A000")
                                {
                                    channels = 2;
                                }
                                else if (channelValue == "F801" || channelValue == "6")
                                {
                                    channels = 6;
                                }
                                else if (channelValue == "FA01" || channelValue == "8")
                                {
                                    channels = 8;
                                }
                            }
                            catch
                            {
                                channels = 2;
                            }

                            int bandwidth = int.Parse(representation.GetAttribute("bandwidth"));

                            string id = representation.GetAttribute("id");
                            if (adaptationSet.HasAttribute("audioTrackId"))
                            {
                                id = adaptationSet.GetAttribute("audioTrackId") + "_" + id;
                            }

                            string lang;

                            try
                            {
                                //amzn
                                lang = id.Split("_")[0];
                            }
                            catch
                            {
                                lang = adaptationSet.GetAttribute("lang");
                            }

                            if (lang == null || lang == "")
                            {
                                lang = "en";
                            }

                            if (audioMetadata != null && audioMetadata.Count > 1 && adaptationSet.HasAttribute("audioTrackId"))
                            {
                                string trackId = adaptationSet.GetAttribute("audioTrackId");

                                name = audioMetadata.FirstOrDefault(x => x.AudioTrackId == trackId).DisplayName;
                            }
                            else if (audioMetadata != null && audioMetadata.Count == 1)
                            {
                                name = audioMetadata[0].DisplayName;
                            }

                            if (name == null)
                            {
                                name = lang;
                            }

                            var audioTrack = new AudioTrack
                            {
                                Encrypted     = isEncrypted,
                                Id            = id,
                                Name          = name,
                                InitDataB64   = initDataB64,
                                Urls          = new string[] { url },
                                Segments      = 1,
                                Codec         = codec,
                                Bitrate       = bandwidth,
                                Channels      = channels,
                                Language      = lang,
                                SecurityLevel = ITrack.SecurityLevel.Unknown
                            };

                            AudioTracks.Add(audioTrack);
                        }
                        else if ((adaptationSet.GetAttribute("contentType").ToLower() == "video" || adaptationSet.GetAttribute("mimeType").ToLower().Contains("video")) && !audioOnly)
                        {
                            string frameRate = "24000/1001";

                            if (representation.HasAttribute("frameRate"))
                            {
                                frameRate = representation.GetAttribute("frameRate");
                            }
                            else
                            {
                                frameRate = adaptationSet.GetAttribute("frameRate");
                            }

                            var frameRateValue = 0.0;
                            if (frameRate.Contains("/"))
                            {
                                frameRateValue = Utils.EvaluateEquation(frameRate);
                            }
                            else
                            {
                                frameRateValue = float.Parse(frameRate);
                            }

                            int bandwidth = int.Parse(representation.GetAttribute("bandwidth"));

                            try
                            {
                                bandwidth = int.Parse(representation.GetAttribute("id").Split("=")[1]);
                            }
                            catch { }

                            var videoTrack = new VideoTrack
                            {
                                Encrypted     = isEncrypted,
                                Id            = representation.GetAttribute("id"),
                                InitDataB64   = initDataB64,
                                Urls          = new string[] { url },
                                Segments      = 1,
                                Codec         = representation.GetAttribute("codecs"),
                                Bitrate       = bandwidth,
                                Width         = int.Parse(representation.GetAttribute("width")),
                                Height        = int.Parse(representation.GetAttribute("height")),
                                FrameRate     = frameRateValue,
                                SecurityLevel = ITrack.SecurityLevel.Unknown
                            };

                            VideoTracks.Add(videoTrack);
                        }
                    }
                }
            }
        }
        public override int Deserialize(byte[] data)
        {
            var bytesRead = base.Deserialize(data);

            using (BinaryReader reader =
                       new BinaryReader(new MemoryStream(data, bytesRead, data.Length - bytesRead)))
            {
                WaveSlotIndex = reader.ReadInt32();

                WaveA = new audWaveFile(
                    new audHashString(parent, reader.ReadUInt32()),
                    new audHashString(parent, reader.ReadUInt32()));

                AudioContainers.Add(WaveA.ContainerName, bytesRead + ((int)reader.BaseStream.Position - 8));

                WaveB = new audWaveFile(
                    new audHashString(parent, reader.ReadUInt32()),
                    new audHashString(parent, reader.ReadUInt32()));

                AudioContainers.Add(WaveB.ContainerName, bytesRead + ((int)reader.BaseStream.Position - 8));

                WaveC = new audWaveFile(
                    new audHashString(parent, reader.ReadUInt32()),
                    new audHashString(parent, reader.ReadUInt32()));

                AudioContainers.Add(WaveC.ContainerName, bytesRead + ((int)reader.BaseStream.Position - 8));

                WaveD = new audWaveFile(
                    new audHashString(parent, reader.ReadUInt32()),
                    new audHashString(parent, reader.ReadUInt32()));

                AudioContainers.Add(WaveD.ContainerName, bytesRead + ((int)reader.BaseStream.Position - 8));

                WaveE = new audWaveFile(
                    new audHashString(parent, reader.ReadUInt32()),
                    new audHashString(parent, reader.ReadUInt32()));

                AudioContainers.Add(WaveE.ContainerName, bytesRead + ((int)reader.BaseStream.Position - 8));

                WaveF = new audWaveFile(
                    new audHashString(parent, reader.ReadUInt32()),
                    new audHashString(parent, reader.ReadUInt32()));

                AudioContainers.Add(WaveF.ContainerName, bytesRead + ((int)reader.BaseStream.Position - 8));

                DataItem1 = new audGranularSoundData(reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadSingle());

                DataItem2 = new audGranularSoundData(reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadSingle());

                DataItem3 = new audGranularSoundData(reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadSingle());

                DataItem4 = new audGranularSoundData(reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadSingle());

                DataItem5 = new audGranularSoundData(reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadSingle());

                DataItem6 = new audGranularSoundData(reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadByte(),
                                                     reader.ReadSingle());

                UnkInt6 = reader.ReadInt32();

                UnkInt7 = reader.ReadInt32();

                UnkShort = reader.ReadUInt16();

                UnkShort1 = reader.ReadUInt16();

                UnkShort2 = reader.ReadUInt16();

                UnkShort3 = reader.ReadUInt16();

                UnkShort4 = reader.ReadUInt16();

                UnkShort5 = reader.ReadUInt16();

                AudioTracks.Add(new audHashString(parent, reader.ReadUInt32()),
                                bytesRead + ((int)reader.BaseStream.Position - 4));

                var itemCount = reader.ReadByte();

                UnkFloatData = new Pair <float, float> [itemCount];

                for (int i = 0; i < itemCount; i++)
                {
                    UnkFloatData[i] = new Pair <float, float>(reader.ReadSingle(),
                                                              reader.ReadSingle());
                }

                return(data.Length);
            }
        }