Exemple #1
0
        /// <summary>
        /// Discard chunk content and prepare the chunk object for possible reuse (in a case of Seek())
        /// </summary>
        public void Reset()
        {
            // This lock is against simultaneous change by Downloader
            lock (this)
            {
                Downloader = null;

                // Close our stream if it exists
                if (null != DownloadedPiece)
                {
                    DownloadedPiece.Close();
                    DownloadedPiece = null;
                }

                m_parser = null;
                DownloadPercent = 0;
                DurationLeft = 0;
                CurrentOffset = 0;
                Length = 0;
                SampleRequestsMissed = 0;
                State = ChunkState.Pending;
            }
        }
Exemple #2
0
        /// <summary>
        /// Parse the header data of this chunk
        /// </summary>
        /// <param name="parserFactory">the parser factory to use for this chunk</param>
        /// <returns>true if the chunk header was header</returns>
        public bool ParseHeader(IChunkParserFactory parserFactory)
        {
            bool isParsed = false;
            lock (this)
            {
                // We can only attempt to parse this chunk when it has been
                // completely loaded
                if (ChunkState.Loaded == State)
                {
                    bool result = false;
                    try
                    {
                        Tracer.Assert(DownloadedPiece != null);

                        // Create a new parser for this chunk
                        m_parser = parserFactory.CreateParserForStream(DownloadedPiece);
                        m_parser.SetPresentationTime(StartTime);
                        result = m_parser.ParseHeader(DownloadedPiece);
                        if (!result)
                        {
                            ErrorMessage = String.Format(CultureInfo.InvariantCulture, "{0} Failed to parse, not enough data (state {1}, {2}, {3} kbps)", Sid, State, DateTime.Now.ToUniversalTime().ToString(), Bitrate);
                            Tracer.Trace(TraceChannel.Error, ErrorMessage);
                        }
                    }
                    catch (ChunkParserException ex)
                    {
                        ErrorMessage = String.Format(CultureInfo.InvariantCulture, "{0} Failed to parse (state {1}, exception {2}, {3}, {4} kbps)", Sid, State, ex.Message, DateTime.Now.ToUniversalTime().ToString(), Bitrate);
                        Tracer.Trace(TraceChannel.Error, ErrorMessage);
                        Tracer.Assert(!result);
                    }

                    if (!result)
                    {
                        State = ChunkState.Error;
                        return false;
                    }

                    DurationLeft = Duration;
                    State = ChunkState.Parsed;
                }

                isParsed = ChunkState.Parsed == State || ChunkState.Pending == State;

                if (ChunkState.Parsed != State)
                {
                    Tracer.Trace(TraceChannel.Error, "{0} state after parsing header: {1}", Sid, State);
                }
            }

            return isParsed;
        }