Beispiel #1
0
        internal DecoderConfiguration(ref Reader reader)
        {
            var dcd = reader.readStructure <DecoderConfigDescriptor>();

            objectType         = (eObjectType)dcd.objectTypeIndication;
            streamType         = (eStreamType)dcd.streamType;
            upStream           = dcd.upStream;
            decodingBufferSize = dcd.bufferSizeDB;
            maximumBitrate     = dcd.maxBitrate;
            averageBitrate     = dcd.avgBitrate;

            // The reader gotta be positioned at the start of AudioSpecificConfig tag.
            // See ISO/IEC 14496-1 annex "E" for more info on tags and sizes.
            eDescriptorTag tag = (eDescriptorTag)reader.readByte();

            if (tag != eDescriptorTag.DecoderSpecificInfo)
            {
                throw new ArgumentException($"Expected eDescriptorTag.DecoderSpecificInfo, got { tag } instead");
            }
            int cb = reader.readSize();

            if (reader.bytesLeft < cb)
            {
                throw new EndOfStreamException($"DecoderSpecificInfo has size { cb } in the header, yet the stream only has { reader.bytesLeft } unread bytes left");
            }
            audioSpecificConfig = new byte[cb];
            reader.readBytes(audioSpecificConfig.AsSpan());
        }
Beispiel #2
0
 public String Get(eStreamType StreamKind, int StreamNumber, int Parameter, eInfoType KindOfInfo)
 {
     if(MustUseAnsi)
         return Marshal.PtrToStringAnsi(MediaInfoA_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo));
     else
         return Marshal.PtrToStringUni(MediaInfo_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo));
 }
Beispiel #3
0
        private static void CreateChaptersMIL(XmlDocument xmlDoc, XmlNode chaptersNode, IMediaInfo mediaInfo)
        {
            Func <string, string, XmlNode> createNode = (name, value) => {
                var n = xmlDoc.CreateElement(name);
                if (value != null)
                {
                    n.AppendChild(xmlDoc.CreateTextNode(value));
                }
                return(n);
            };

            XmlNode     editionEntryNode, chapterAtomNode, chapterDisplayNode;
            eStreamType streamKind = eStreamType.Menu;
            int         streamCount, entryCount;

            streamCount = mediaInfo.Count_Get(streamKind);

            for (int i = 0; i < streamCount; i++)
            {
                entryCount       = mediaInfo.Count_Get(streamKind, i);
                editionEntryNode = chaptersNode.AppendChild(xmlDoc.CreateElement("EditionEntry"));

                int indexStart, indexEnd;
                if (int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_Begin"), out indexStart) && int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_End"), out indexEnd))
                {
                    chapterAtomNode = editionEntryNode.AppendChild(xmlDoc.CreateElement("ChapterAtom"));
                    for (; indexStart < indexEnd; indexStart++)
                    {
                        Func <string, ulong> conv = (str) => {
                            var timeParts = str.Split(new char[] { ':', '.' }).Select(s => ulong.Parse(s.Trim())).ToArray();
                            return((((timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2]) * 1000 + timeParts[3]) * 1000000);
                        };

                        var   timeStamps     = mediaInfo.Get(streamKind, i, indexStart, eInfoType.Name).Split('-');
                        ulong timestampStart = conv(timeStamps[0].Trim());
                        ulong timestampEnd;
                        if (timeStamps.Length > 1)
                        {
                            timestampEnd = conv(timeStamps[1].Trim());
                        }


                        chapterAtomNode.AppendChild(createNode("ChapterTimeStart", timestampStart.ToString()));
                        chapterDisplayNode = chapterAtomNode.AppendChild(xmlDoc.CreateElement("ChapterDisplay"));

                        string languageTitle, language, title;
                        languageTitle = mediaInfo.Get(streamKind, i, indexStart, eInfoType.Text);
                        language      = languageTitle.Contains(':') ? languageTitle.Substring(0, languageTitle.IndexOf(':')) : null;
                        title         = languageTitle.Substring(language == null ? 0 : language.Length + 1);
                        chapterDisplayNode.AppendChild(createNode("ChapterString", title));
                        if (language != null)
                        {
                            chapterDisplayNode.AppendChild(createNode("ChapterLanguage", language.Equals("en") ? "eng" : language));
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private string Get(eStreamType type, int index, string key, Converter <string, string> converter = null)
        {
            string value = MIL.Get(type, index, key);

            if (string.IsNullOrEmpty(value))
            {
                return("");
            }
            return(converter != null?converter(value) : value);
        }
Beispiel #5
0
 public String Get(eStreamType StreamKind, int StreamNumber, String Parameter, eInfoType KindOfInfo, eInfoType KindOfSearch)
 {
     if(MustUseAnsi) {
         IntPtr Parameter_Ptr = Marshal.StringToHGlobalAnsi(Parameter);
         String ToReturn = Marshal.PtrToStringAnsi(MediaInfoA_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter_Ptr, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch));
         Marshal.FreeHGlobal(Parameter_Ptr);
         return ToReturn;
     } else
         return Marshal.PtrToStringUni(MediaInfo_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch));
 }
Beispiel #6
0
 public String Get(eStreamType StreamKind, int StreamNumber, int Parameter, eInfoType KindOfInfo)
 {
     if (MustUseAnsi)
     {
         return(Marshal.PtrToStringAnsi(MediaInfoA_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)));
     }
     else
     {
         return(Marshal.PtrToStringUni(MediaInfo_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)));
     }
 }
Beispiel #7
0
 public String Get(eStreamType StreamKind, int StreamNumber, String Parameter, eInfoType KindOfInfo, eInfoType KindOfSearch)
 {
     if (MustUseAnsi)
     {
         IntPtr Parameter_Ptr = Marshal.StringToHGlobalAnsi(Parameter);
         String ToReturn      = Marshal.PtrToStringAnsi(MediaInfoA_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter_Ptr, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch));
         Marshal.FreeHGlobal(Parameter_Ptr);
         return(ToReturn);
     }
     else
     {
         return(Marshal.PtrToStringUni(MediaInfo_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch)));
     }
 }
Beispiel #8
0
        private static void CreateChaptersNode(XmlDocument xmlDoc, XmlNode n, IMediaInfo mediaInfo)
        {
            Func <string, ulong> conv = (str) => {
                var timeParts = str.Split(new char[] { ':', '.' }).Select(s => ulong.Parse(s.Trim())).ToArray();
                return((((timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2]) * 1000 + timeParts[3]) * 1000000);
            };

            int         streamCount, entryCount;
            eStreamType streamKind = eStreamType.Menu;
            XmlNode     entryNode, subNode;
            string      languageTitle, language, title;

            streamCount = mediaInfo.Count_Get(streamKind);
            for (int i = 0; i < streamCount; i++)
            {
                entryCount = mediaInfo.Count_Get(streamKind, i);
                int indexStart, indexEnd;
                if (int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_Begin"), out indexStart) && int.TryParse(mediaInfo.Get(streamKind, i, "Chapters_Pos_End"), out indexEnd))
                {
                    for (; indexStart < indexEnd; indexStart++)
                    {
                        entryNode = n.AppendChild(xmlDoc.CreateElement("Entry"));

                        var timeStamp = conv(mediaInfo.Get(streamKind, i, indexStart, eInfoType.Name).Split('-')[0].Trim());
                        subNode = entryNode.AppendChild(xmlDoc.CreateElement("Pos"));
                        subNode.Attributes.Append(xmlDoc.CreateAttribute("start")).Value = (timeStamp / 1000).ToString("0.###");

                        languageTitle = mediaInfo.Get(streamKind, i, indexStart, eInfoType.Text);
                        language      = languageTitle.Contains(':') ? languageTitle.Substring(0, languageTitle.IndexOf(':')) : null;
                        title         = languageTitle.Substring(language == null ? 0 : language.Length + 1);

                        subNode = entryNode.AppendChild(xmlDoc.CreateElement("Title"));
                        subNode.AppendChild(xmlDoc.CreateTextNode(title));
                        if (language != null)
                        {
                            subNode.Attributes.Append(xmlDoc.CreateAttribute("lang")).Value = language;
                        }
                    }
                }
            }
        }
Beispiel #9
0
 public String Get(int FilePos, eStreamType StreamKind, int StreamNumber, int Parameter, eInfoType KindOfInfo)
 {
     return(Marshal.PtrToStringUni(MediaInfoList_GetI(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)));
 }
Beispiel #10
0
 private string Get(eStreamType type, int index, string key, Converter<string, string> converter = null)
 {
     string value = MIL.Get(type, index, key);
     if(string.IsNullOrEmpty(value)) return "";
     return converter != null ? converter(value) : value;
 }
Beispiel #11
0
 public String Get(eStreamType StreamKind, int StreamNumber, int Parameter)
 {
     return(Get(StreamKind, StreamNumber, Parameter, eInfoType.Text));
 }
Beispiel #12
0
 public int Count_Get(eStreamType StreamKind)
 {
     return Count_Get(StreamKind, -1);
 }
Beispiel #13
0
 public String Get(int FilePos, eStreamType StreamKind, int StreamNumber, String Parameter)
 {
     return Get(FilePos, StreamKind, StreamNumber, Parameter, eInfoType.Text, eInfoType.Name);
 }
Beispiel #14
0
 public int Count_Get(eStreamType StreamKind, int StreamNumber)
 {
     return (int)MediaInfo_Count_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber);
 }
Beispiel #15
0
 public String Get(int FilePos, eStreamType StreamKind, int StreamNumber, int Parameter, eInfoType KindOfInfo)
 {
     return Marshal.PtrToStringUni(MediaInfoList_GetI(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo));
 }
Beispiel #16
0
 public int Count_Get(int FilePos, eStreamType StreamKind)
 {
     return Count_Get(FilePos, StreamKind, -1);
 }
Beispiel #17
0
 public int Count_Get(int FilePos, eStreamType StreamKind, int StreamNumber)
 {
     return (int)MediaInfoList_Count_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber);
 }
Beispiel #18
0
 public int Count_Get(eStreamType StreamKind, int StreamNumber)
 {
     return((int)MediaInfo_Count_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber));
 }
Beispiel #19
0
 public int Count_Get(int FilePos, eStreamType StreamKind)
 {
     return(Count_Get(FilePos, StreamKind, -1));
 }
Beispiel #20
0
 //Default values, if you know how to set default values in C#, say me
 public String Get(eStreamType StreamKind, int StreamNumber, String Parameter, eInfoType KindOfInfo)
 {
     return(Get(StreamKind, StreamNumber, Parameter, KindOfInfo, eInfoType.Name));
 }
Beispiel #21
0
 //Default values, if you know how to set default values in C#, say me
 public String Get(eStreamType StreamKind, int StreamNumber, String Parameter, eInfoType KindOfInfo)
 {
     return Get(StreamKind, StreamNumber, Parameter, KindOfInfo, eInfoType.Name);
 }
Beispiel #22
0
 public int Count_Get(eStreamType StreamKind)
 {
     return(Count_Get(StreamKind, -1));
 }
Beispiel #23
0
 public String Get(eStreamType StreamKind, int StreamNumber, int Parameter)
 {
     return Get(StreamKind, StreamNumber, Parameter, eInfoType.Text);
 }
Beispiel #24
0
 public String Get(int FilePos, eStreamType StreamKind, int StreamNumber, String Parameter)
 {
     return(Get(FilePos, StreamKind, StreamNumber, Parameter, eInfoType.Text, eInfoType.Name));
 }
Beispiel #25
0
 public int Count_Get(int FilePos, eStreamType StreamKind, int StreamNumber)
 {
     return((int)MediaInfoList_Count_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber));
 }