Ejemplo n.º 1
0
 /// <summary>
 /// Add a frame.
 /// </summary>
 /// <param name="MatroskaFileFrame">The frame to add.</param>
 /// <param name=""></param>
 public void addFrame(MatroskaFileFrame frame)
 {
     if (!Cluster.AddFrame(frame))
     {
         Flush();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a frame to the cluster.
        /// </summary>
        /// <param name="frame">The <code>MatroskaFileFrame</code></param>
        /// <returns>false if you should begin another cluster.</returns>
        public bool AddFrame(MatroskaFileFrame frame)
        {
            if (frame.Timecode < ClusterTimecode)
            {
                ClusterTimecode = frame.Timecode;
            }

            frames.Enqueue(frame);
            totalSize += (int)(frame.Data.Length - frame.Data.Position);
            Tracks.Add(frame.TrackNumber);
            return(((frame.Timecode - ClusterTimecode) < (ulong)DurationLimit) && (totalSize < SizeLimit));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the next MatroskaFileFrame, limited by TrackNo
        /// </summary>
        /// <param name="trackNumber">The track number to only get MatroskaFileName(s) from.</param>
        /// <returns>The next MatroskaFileFrame in the queue, or null if there are no more frames for the TrackNumber Track.</returns>
        public MatroskaFileFrame GetNextFrame(int trackNumber)
        {
            if (frameQueue.Count == 0)
            {
                fillFrameQueue();
            }

            if (frameQueue.Count == 0)
            {
                return(null);
            }

            int tryCount            = 0;
            MatroskaFileFrame frame = null;

            try
            {
                var iterator = frameQueue.GetEnumerator();
                while (frame == null)
                {
                    if (iterator.MoveNext())
                    {
                        frame = iterator.Current;
                        if (frame.TrackNumber == trackNumber)
                        {
                            lock (frameQueue)
                            {
                                frameQueue.Remove(frame);
                            }
                            return(frame);
                        }
                        frame = null;
                    }
                    else
                    {
                        fillFrameQueue();
                        if (++tryCount > CLUSTER_TRACK_SEARCH_COUNT)
                        {
                            return(null);
                        }
                    }
                }
            } catch (Exception e)
            {
                logger?.LogError(e.StackTrace);
                return(null);
            }

            return(frame);
        }
Ejemplo n.º 4
0
        protected bool badMp3Headers()
        {
            var iter = frameQueue.GetEnumerator();

            while (iter.MoveNext())
            {
                MatroskaFileFrame frame = iter.Current;
                if (frame.TrackNumber == 2 &&
                    frame.Data.ToArray()[3] != 0x54)
                {
                    throw new Exception("Bad MP3 Header! Index: " + iter);
                }
            }
            return(false);
        }
 public MatroskaFileFrame(MatroskaFileFrame copy)
 {
     TrackNumber = copy.TrackNumber;
     Timecode    = copy.Timecode;
     Duration    = copy.Duration;
     IsKeyFrame  = copy.IsKeyFrame;
     References  = new List <ulong>();
     if (copy.References != null)
     {
         this.References.AddRange(copy.References);
     }
     if (copy.Data != null)
     {
         this.Data = copy.Data;
     }
 }
        public bool AddFrame(MatroskaFileFrame frame)
        {
            Timecode    = (short)frame.Timecode;
            TrackNumber = frame.TrackNumber;
            TotalSize  += (int)(frame.Data.Length - frame.Data.Position);
            Frames.Add(frame);
            if (frame.Duration != ulong.MinValue)
            {
                Duration = frame.Duration;
            }

            if (frame.Data.Position - frame.Data.Length > MAX_LACE_SIZE)
            {
                LaceMode = MatroskaLaceMode.NONE;
                return(false);
            }

            TotalSize += 4;

            return(!IsSimpleBlock() || !(LaceMode == MatroskaLaceMode.NONE) || Frames.Count > 8);
        }
Ejemplo n.º 7
0
        private void parseNextCluster(Element level1)
        {
            Element level2          = null;
            Element level3          = null;
            ulong   clusterTimecode = 0;

            level2 = ((MasterElement)level1).ReadNextChild(reader);

            while (level2 != null)
            {
                if (level2.IsType(MatroskaDocTypes.Timecode.Type))
                {
                    level2.ReadData(stream);
                    clusterTimecode = ((UnsignedIntegerElement)level2).Value;
                }
                else if (level2.IsType(MatroskaDocTypes.SimpleBlock.Type))
                {
                    level2.ReadData(stream);
                    MatroskaBlock block         = null;
                    ulong         blockDuration = 0;
                    block = new MatroskaBlock(level2.Data);

                    block.ParseBlock();
                    MatroskaFileFrame frame = new MatroskaFileFrame();
                    frame.TrackNumber = block.TrackNumber;
                    frame.Timecode    = block.AdjustedBlockTimecode(clusterTimecode, TimecodeScale);
                    frame.Duration    = blockDuration;
                    frame.Data        = block.GetFrame(0);
                    frame.IsKeyFrame  = block.IsKeyFrame;
                    lock (frameQueue)
                    {
                        frameQueue.Add(new MatroskaFileFrame(frame));
                    }

                    if (block.FrameCount > 1)
                    {
                        for (int f = 1; f < block.FrameCount; f++)
                        {
                            frame.Data = block.GetFrame(f);
                            frameQueue.Add(new MatroskaFileFrame(frame));
                        }
                    }
                    level2.SkipData(stream);
                }
                else if (level2.IsType(MatroskaDocTypes.BlockGroup.Type))
                {
                    ulong blockDuration  = 0;
                    ulong blockReference = 0;

                    level3 = ((MasterElement)level2).ReadNextChild(reader);

                    MatroskaBlock block = null;
                    while (level3 != null)
                    {
                        if (level3.IsType(MatroskaDocTypes.Block.Type))
                        {
                            level3.ReadData(stream);
                            block = new MatroskaBlock(level3.Data);
                            block.ParseBlock();
                        }
                        else if (level3.IsType(MatroskaDocTypes.BlockDuration.Type))
                        {
                            level3.ReadData(stream);
                            blockDuration = ((UnsignedIntegerElement)level3).Value;
                        }
                        else if (level3.IsType(MatroskaDocTypes.ReferenceBlock.Type))
                        {
                            level3.ReadData(stream);
                            blockReference = ((SignedIntegerElement)level3).Value;
                        }

                        level3.SkipData(stream);
                        level3 = ((MasterElement)level2).ReadNextChild(reader);
                    }

                    if (block == null)
                    {
                        throw new NullReferenceException("BlockGroup element with no child Block!");
                    }

                    MatroskaFileFrame frame = new MatroskaFileFrame();
                    frame.TrackNumber = block.TrackNumber;
                    frame.Timecode    = block.AdjustedBlockTimecode(clusterTimecode, TimecodeScale);
                    frame.Duration    = blockDuration;
                    frame.References.Add(blockReference);
                    frame.Data = block.GetFrame(0);
                    frameQueue.Add(new MatroskaFileFrame(frame));

                    if (block.FrameCount > 1)
                    {
                        for (int f = 1; f < block.FrameCount; f++)
                        {
                            frame.Data = block.GetFrame(f);
                            frameQueue.Add(new MatroskaFileFrame(frame));
                        }
                    }
                }

                level2.SkipData(stream);
                level2 = ((MasterElement)level1).ReadNextChild(reader);
            }
        }