Пример #1
0
        /// <summary>
        /// Constructor to use when reading, can also be used for network streams (theoretically).
        /// </summary>
        /// <param name="stream"></param>
        public ISMFile(Stream stream)
        {
            ISMElement ismElement = null;
              try {
            _xmlReader = XmlReader.Create(stream);

            int trackID = 1; // mark each ism element with a unique track ID

            // crude parser
            while (_xmlReader.Read()) {
              if (_xmlReader.NodeType != XmlNodeType.Element) {
            continue;
              }

              if (_xmlReader.Name == "audio" || _xmlReader.Name == "video") {
            // ismElement MUST be null at this point
            if (ismElement != null)
              throw new Exception("ISMFile: time scale param not found");

            ismElement = new ISMElement(_baseFolder);
            if (_xmlReader.Name == "audio") {
              ismElement.FragmentType = FragmentType.Audio;
            }
            else if (_xmlReader.Name == "video") {
              ismElement.FragmentType = FragmentType.Video;
            }

            ismElement.Source = _xmlReader.GetAttribute("src");
            ismElement.Bitrate = long.Parse(_xmlReader.GetAttribute("systemBitrate"));
            ismElement.TrackID = trackID++;
              }
              else if (_xmlReader.Name == "param")
              {
            string paramName = _xmlReader.GetAttribute("name");
            string attributeValue = _xmlReader.GetAttribute("value");
            if (paramName == "trackID")
            {
              ismElement.ISMVTrackID = int.Parse(attributeValue);
            }
            else if (paramName == "timeScale")
            {
              ismElement.TimeScale = uint.Parse(attributeValue);
              _ismElements.Add(ismElement);
              ismElement = null;
            }
              }
            }
              } catch {
            throw;
              } finally {
            if (_xmlReader != null) {
              _xmlReader.Close();
            }
              }
        }
Пример #2
0
        public string GetSource(FragmentType mediaType, long bitrate)
        {
            ISMElement ismElement = GetISMElement(mediaType, bitrate);

            if (ismElement != null)
            {
                return(ismElement.Source);
            }

            return(null);
        }
Пример #3
0
        /// <summary>
        /// Constructor to use when reading an ismc file.
        /// </summary>
        /// <param name="inDir"></param>
        /// <param name="inFileName"></param>
        public ISMCFile(string inDir, string inFileName, List <ISMElement> ismElements) :
            this(new FileStream(Path.Combine(new string[] { inDir, inFileName + ".ismc" }), FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            ISMElement  qElement      = null;
            List <uint> fragDurations = null;

            strDir      = inDir;
            strFileName = inFileName;
            //Console.WriteLine("OPENING: " + inDir + inFileName);
            foreach (StreamIndex streamIndex in indexs)
            {
                fragDurations = new List <uint>(streamIndex.cs.Count);
                streamIndex.cs.ForEach((c) => fragDurations.Add(uint.Parse(c.d)));
                if (streamIndex.Type == "video")
                {
                    if (streamIndex.QualityLevels.Count != ismElements.Count(el => el.FragmentType == MP4.FragmentType.Video))
                    {
                        throw new Exception("ISMCFile: count of quality levels for video does not match count of video elements in ISM file");
                    }
                    foreach (QualityLevel qlevel in streamIndex.QualityLevels)
                    {
                        qElement       = ismElements.First(elmnt => (elmnt.TrackID == int.Parse(qlevel.TrackID) + 1) && (elmnt.FragmentType == MP4.FragmentType.Video));
                        qElement.Codec = new Codec(CodecTypes.Video);
                        qElement.Codec.PrivateCodecData = qlevel.CodecPrivateData;
                        qElement.FourCC            = qlevel.FourCC;
                        qElement.Height            = int.Parse(qlevel.Height);
                        qElement.Width             = int.Parse(qlevel.Width);
                        qElement.FragmentDurations = fragDurations;
                    }
                }
                else if (streamIndex.Type == "audio")
                {
                    if (streamIndex.QualityLevels.Count != ismElements.Count(el => el.FragmentType == MP4.FragmentType.Audio))
                    {
                        throw new Exception("ISMCFile: count of quality levels for audio does not match count of audio elements in ISM file");
                    }
                    // we assume there is only ONE audio quality level
                    qElement       = ismElements.First(elmnt => (elmnt.FragmentType == MP4.FragmentType.Audio));
                    qElement.Codec = new Codec(CodecTypes.Audio);
                    QualityLevel qlevel = streamIndex.QualityLevels[0];
                    qElement.Codec.PrivateCodecData = "038080220000000480801640150020000001F4000001F4000580800511900000000680800102"; // qlevel.CodecPrivateData;
                    qElement.FourCC            = qlevel.FourCC;
                    qElement.ChannelCount      = int.Parse(qlevel.Channels);
                    qElement.SampleRate        = int.Parse(qlevel.SamplingRate);
                    qElement.SampleSize        = int.Parse(qlevel.BitsPerSample);
                    qElement.FragmentDurations = fragDurations;
                }
            }
        }
Пример #4
0
 public ISMVTrackFormat(string inDir, string inFileName, ISMElement element)
     : this(inDir, inFileName)
 {
     _ismElement = element;
       if (element.FragmentType == FragmentType.Video)
       {
     _handlerType = "vide";
     FrameSize.Height = element.Height;
     FrameSize.Width = element.Width;
       }
       else if (element.FragmentType == FragmentType.Audio)
       {
     _handlerType = "soun";
     _channelCount = _ismElement.ChannelCount;
     _samplesize = _ismElement.SampleSize;
     _sampleRate = _ismElement.SampleRate;
       }
       DurationIn100NanoSecs = (ulong)_ismElement.FragmentDurations.Sum((uint u) => { return (long)u; });
 }
Пример #5
0
 public ISMVTrackFormat(string inDir, string inFileName, ISMElement element)
     : this(inDir, inFileName)
 {
     _ismElement = element;
     if (element.FragmentType == FragmentType.Video)
     {
         _handlerType     = "vide";
         FrameSize.Height = element.Height;
         FrameSize.Width  = element.Width;
     }
     else if (element.FragmentType == FragmentType.Audio)
     {
         _handlerType  = "soun";
         _channelCount = _ismElement.ChannelCount;
         _samplesize   = _ismElement.SampleSize;
         _sampleRate   = _ismElement.SampleRate;
     }
     DurationIn100NanoSecs = (ulong)_ismElement.FragmentDurations.Sum((uint u) => { return((long)u); });
 }
Пример #6
0
        /// <summary>
        /// Constructor to use when reading, can also be used for network streams (theoretically).
        /// </summary>
        /// <param name="stream"></param>
        public ISMFile(Stream stream)
        {
            ISMElement ismElement = null;

            try {
                _xmlReader = XmlReader.Create(stream);

                int trackID = 1; // mark each ism element with a unique track ID

                // crude parser
                while (_xmlReader.Read())
                {
                    if (_xmlReader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (_xmlReader.Name == "audio" || _xmlReader.Name == "video")
                    {
                        // ismElement MUST be null at this point
                        if (ismElement != null)
                        {
                            throw new Exception("ISMFile: time scale param not found");
                        }

                        ismElement = new ISMElement(_baseFolder);
                        if (_xmlReader.Name == "audio")
                        {
                            ismElement.FragmentType = FragmentType.Audio;
                        }
                        else if (_xmlReader.Name == "video")
                        {
                            ismElement.FragmentType = FragmentType.Video;
                        }

                        ismElement.Source  = _xmlReader.GetAttribute("src");
                        ismElement.Bitrate = long.Parse(_xmlReader.GetAttribute("systemBitrate"));
                        ismElement.TrackID = trackID++;
                    }
                    else if (_xmlReader.Name == "param")
                    {
                        string paramName      = _xmlReader.GetAttribute("name");
                        string attributeValue = _xmlReader.GetAttribute("value");
                        if (paramName == "trackID")
                        {
                            ismElement.ISMVTrackID = int.Parse(attributeValue);
                        }
                        else if (paramName == "timeScale")
                        {
                            ismElement.TimeScale = uint.Parse(attributeValue);
                            _ismElements.Add(ismElement);
                            ismElement = null;
                        }
                    }
                }
            } catch {
                throw;
            } finally {
                if (_xmlReader != null)
                {
                    _xmlReader.Close();
                }
            }
        }