Пример #1
0
        /// <summary>
        ///     Constructs a <see cref="Track" /> parsing from provided
        ///     file data.
        ///     Parsing will be done reading from _file at position references by
        ///     parent element's data section.
        /// </summary>
        /// <param name="_file"><see cref="File" /> instance to read from.</param>
        /// <param name="element">Parent <see cref="EBMLreader" />.</param>
        public Track(File _file, EBMLreader element)
        {
            ulong i = 0;

            while (i < element.DataSize)
            {
                var child = new EBMLreader(_file, element.DataOffset + i);

                switch (child.ID)
                {
                case MatroskaID.TrackNumber:
                    track_number = child.ReadULong();
                    break;

                case MatroskaID.TrackUID:
                    _UID = child.ReadULong();
                    break;

                case MatroskaID.CodecID:
                    track_codec_id = child.ReadString();
                    break;

                case MatroskaID.CodecName:
                    track_codec_name = child.ReadString();
                    break;

                case MatroskaID.TrackName:
                    track_name = child.ReadString();
                    break;

                case MatroskaID.TrackLanguage:
                    track_language = child.ReadString();
                    break;

                case MatroskaID.TrackFlagEnabled:
                    track_enabled = child.ReadBool();
                    break;

                case MatroskaID.TrackFlagDefault:
                    track_default = child.ReadBool();
                    break;

                case MatroskaID.CodecPrivate:
                    codec_data = child.ReadBytes();
                    break;

                default:
                    UnknownElements.Add(child);
                    break;
                }

                i += child.Size;
            }
        }
Пример #2
0
        /// <summary>
        ///     Construct a <see cref="AudioTrack" /> reading information from
        ///     provided file data.
        ///     Parsing will be done reading from _file at position references by
        ///     parent element's data section.
        /// </summary>
        /// <param name="_file"><see cref="File" /> instance to read from.</param>
        /// <param name="element">Parent <see cref="EBMLreader" />.</param>
        public AudioTrack(File _file, EBMLreader element)
            : base(_file, element)
        {
            MatroskaID matroska_id;

            // Here we handle the unknown elements we know, and store the rest
            foreach (var elem in base.UnknownElements)
            {
                matroska_id = elem.ID;

                switch (matroska_id)
                {
                case MatroskaID.TrackAudio:
                {
                    ulong i = 0;

                    while (i < elem.DataSize)
                    {
                        var child = new EBMLreader(_file, elem.DataOffset + i);

                        matroska_id = child.ID;

                        switch (matroska_id)
                        {
                        case MatroskaID.AudioChannels:
                            channels = child.ReadULong();
                            break;

                        case MatroskaID.AudioBitDepth:
                            depth = child.ReadULong();
                            break;

                        case MatroskaID.AudioSamplingFreq:
                            rate = child.ReadDouble();
                            break;

                        default:
                            UnknownElements.Add(child);
                            break;
                        }

                        i += child.Size;
                    }

                    break;
                }

                default:
                    UnknownElements.Add(elem);
                    break;
                }
            }
        }
Пример #3
0
        private void ReadCreateSegmentInfo(EBMLreader element, EBMLelement ebml_sinfo)
        {
            ulong i = 0;

            while (i < element.DataSize)
            {
                var child = new EBMLreader(element, element.DataOffset + i);
                switch (child.ID)
                {
                case MatroskaID.Duration:
                    duration_unscaled = child.ReadDouble();
                    if (time_scale > 0)
                    {
                        duration = TimeSpan.FromMilliseconds(duration_unscaled * time_scale / 1000000);
                    }

                    break;

                case MatroskaID.TimeCodeScale:
                    time_scale = child.ReadULong();
                    if (duration_unscaled > 0)
                    {
                        duration = TimeSpan.FromMilliseconds(duration_unscaled * time_scale / 1000000);
                    }

                    break;

                case MatroskaID.Title:
                    break;
                }

                i += child.Size;
            }
        }
Пример #4
0
        private void ReadTrackEntry(EBMLreader element)
        {
            ulong i = 0;

            while (i < element.DataSize)
            {
                var child = new EBMLreader(element, element.DataOffset + i);

                switch (child.ID)
                {
                case MatroskaID.TrackType:
                {
                    switch ((TrackType)child.ReadULong())
                    {
                    case TrackType.Video:
                    {
                        var track = new VideoTrack(this, element);

                        tracks.Add(track);
                        break;
                    }

                    case TrackType.Audio:
                    {
                        var track = new AudioTrack(this, element);

                        tracks.Add(track);
                        break;
                    }
                    }

                    break;
                }
                }

                i += child.Size;
            }
        }
Пример #5
0
        private void ReadAttachedFile(EBMLreader element, ReadStyle propertiesStyle)
        {
            ulong i = 0;

#pragma warning restore 219

            while (i < element.DataSize)
            {
                var child = new EBMLreader(element, element.DataOffset + i);

                switch (child.ID)
                {
                case MatroskaID.FileName:
#pragma warning disable 219 // Assigned, never read
                    _ = child.ReadString();
                    break;

                case MatroskaID.FileMimeType:
                    _ = child.ReadString();
                    break;

                case MatroskaID.FileDescription:
                    _ = child.ReadString();
                    break;

                case MatroskaID.FileData:
                    break;

                case MatroskaID.FileUID:
                    _ = child.ReadULong();
                    break;
                }

                i += child.Size;
            }
        }
Пример #6
0
        /// <summary>
        ///     Constructs a <see cref="VideoTrack" /> parsing from provided
        ///     file data.
        ///     Parsing will be done reading from _file at position references by
        ///     parent element's data section.
        /// </summary>
        /// <param name="_file"><see cref="File" /> instance to read from.</param>
        /// <param name="element">Parent <see cref="EBMLreader" />.</param>
        public VideoTrack(File _file, EBMLreader element)
            : base(_file, element)
        {
            MatroskaID matroska_id;

            // Here we handle the unknown elements we know, and store the rest
            foreach (var elem in base.UnknownElements)
            {
                matroska_id = elem.ID;

                switch (matroska_id)
                {
                case MatroskaID.TrackVideo:
                {
                    ulong i = 0;

                    while (i < elem.DataSize)
                    {
                        var child = new EBMLreader(_file, elem.DataOffset + i);

                        matroska_id = child.ID;

                        switch (matroska_id)
                        {
                        case MatroskaID.VideoDisplayWidth:
                            disp_width = child.ReadULong();
                            break;

                        case MatroskaID.VideoDisplayHeight:
                            disp_height = child.ReadULong();
                            break;

                        case MatroskaID.VideoPixelWidth:
                            width = child.ReadULong();
                            break;

                        case MatroskaID.VideoPixelHeight:
                            height = child.ReadULong();
                            break;

                        case MatroskaID.VideoFrameRate:
                            framerate = child.ReadDouble();
                            break;

                        case MatroskaID.VideoFlagInterlaced:
                            interlaced = child.ReadBool();
                            break;

                        case MatroskaID.VideoAspectRatioType:
                            ratio_type = (VideoAspectRatioType)child.ReadULong();
                            break;

                        case MatroskaID.VideoColourSpace:
                            fourcc = child.ReadBytes();
                            break;

                        default:
                            UnknownElements.Add(child);
                            break;
                        }

                        i += child.Size;
                    }

                    break;
                }

                case MatroskaID.TrackDefaultDuration:
                    var tmp = elem.ReadULong();
                    framerate = 1000000000.0 / tmp;
                    break;

                default:
                    UnknownElements.Add(elem);
                    break;
                }
            }
        }
Пример #7
0
        private bool ReadSeekHead(EBMLreader element, List <EBMLreader> segm_list)
        {
            MatroskaID ebml_id       = 0;
            ulong      ebml_position = 0;

            ulong i = 0;

            while (i < element.DataSize)
            {
                var ebml_seek   = new EBMLreader(element, element.DataOffset + i);
                var matroska_id = ebml_seek.ID;

                if (matroska_id != MatroskaID.Seek)
                {
                    return(false);                    // corrupted SeekHead
                }

                ulong j = 0;
                while (j < ebml_seek.DataSize)
                {
                    var child = new EBMLreader(ebml_seek, ebml_seek.DataOffset + j);
                    matroska_id = child.ID;

                    switch (matroska_id)
                    {
                    case MatroskaID.SeekID:
                        ebml_id = (MatroskaID)child.ReadULong();
                        break;

                    case MatroskaID.SeekPosition:
                        ebml_position = child.ReadULong() + element.Offset;
                        break;
                    }

                    j += child.Size;
                }

                if (ebml_id > 0 && ebml_position > 0)
                {
                    // Create abstract EBML representation of the segment EBML
                    var ebml = new EBMLreader(element.Parent, ebml_position, ebml_id);

                    // Sort the seek-entries by increasing position order
                    int k;
                    for (k = segm_list.Count - 1; k >= 0; k--)
                    {
                        if (ebml_position > segm_list[k]
                            .Offset)
                        {
                            break;
                        }
                    }

                    segm_list.Insert(k + 1, ebml);

                    // Chained SeekHead recursive read
                    if (ebml_id == MatroskaID.SeekHead)
                    {
                        if (!ebml.Read())
                        {
                            return(false);                            // Corrupted
                        }

                        ReadSeekHead(ebml, segm_list);
                    }
                }

                i += ebml_seek.Size;
            }

            return(true);
        }