Пример #1
0
        /// <summary>
        /// Handle chunk elements found in the AVI file. Ignores unknown chunks and
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="FourCC"></param>
        /// <param name="unpaddedLength"></param>
        /// <param name="paddedLength"></param>
        private void ProcessAVIChunk(RiffParser rp, int FourCC, int unpaddedLength, int paddedLength)
        {
            if (AviRiffData.ckidMainAVIHeader == FourCC)
            {
                // Main AVI header
                DecodeAVIHeader(rp, paddedLength);
            }
            else if (AviRiffData.ckidAVIStreamHeader == FourCC)
            {
                // Stream header
                DecodeAVIStream(rp, paddedLength);
            }
            else if (AviRiffData.ckidAVIISFT == FourCC)
            {
                Byte[] ba = new byte[paddedLength];
                rp.ReadData(ba, 0, paddedLength);
                StringBuilder sb = new StringBuilder(unpaddedLength);
                for (int i = 0; i < unpaddedLength; ++i)
                {
                    if (0 != ba[i])
                    {
                        sb.Append((char)ba[i]);
                    }
                }

                m_isft = sb.ToString();
            }
            else
            {
                // Unknon chunk - skip
                rp.SkipData(paddedLength);
            }
        }
Пример #2
0
        private unsafe void DecodeAVIHeader(RiffParser rp, int length)
        {
            //if (length < sizeof(AVIMAINHEADER))
            //{
            //  throw new RiffParserException(String.Format("Header size mismatch. Needed {0} but only have {1}",
            //      sizeof(AVIMAINHEADER), length));
            //}

            byte[] ba = new byte[length];

            if (rp.ReadData(ba, 0, length) != length)
            {
                throw new RiffParserException("Problem reading AVI header.");
            }

            fixed(Byte *bp = &ba[0])
            {
                AVIMAINHEADER *avi = (AVIMAINHEADER *)bp;

                m_frameRate   = avi->dwMicroSecPerFrame;
                m_height      = avi->dwHeight;
                m_maxBitRate  = avi->dwMaxBytesPerSec;
                m_numStreams  = avi->dwStreams;
                m_totalFrames = avi->dwTotalFrames;
                m_width       = avi->dwWidth;
            }
        }
Пример #3
0
 private void ProcessWaveChunk(RiffParser rp, int FourCC, int unpaddedLength, int length)
 {
     // Is this a 'fmt' chunk?
     if (AviRiffData.ckidWaveFMT == FourCC)
     {
         DecodeWave(rp, length);
     }
     else
     {
         rp.SkipData(length);
     }
 }
Пример #4
0
        private unsafe void DecodeAVIStream(RiffParser rp, int length)
        {
            byte[] ba = new byte[length];

            if (rp.ReadData(ba, 0, length) != length)
            {
                throw new RiffParserException("Problem reading AVI header.");
            }

            fixed(Byte *bp = &ba[0])
            {
                AVISTREAMHEADER *avi = (AVISTREAMHEADER *)bp;

                if (AviRiffData.streamtypeVIDEO == avi->fccType)
                {
                    m_vidHandler = RiffParser.FromFourCC(avi->fccHandler);
                    if (avi->dwScale > 0)
                    {
                        m_vidDataRate = (double)avi->dwRate / (double)avi->dwScale;
                    }
                    else
                    {
                        m_vidDataRate = 0.0;
                    }
                }
                else if (AviRiffData.streamtypeAUDIO == avi->fccType)
                {
                    if (AviRiffData.ckidMP3 == avi->fccHandler)
                    {
                        m_audHandler = "MP3";
                    }
                    else
                    {
                        m_audHandler = RiffParser.FromFourCC(avi->fccHandler);
                    }
                    if (avi->dwScale > 0)
                    {
                        m_audDataRate = 8.0 * (double)avi->dwRate / (double)avi->dwScale;
                        if (avi->dwSampleSize > 0)
                        {
                            m_audDataRate /= (double)avi->dwSampleSize;
                        }
                    }
                    else
                    {
                        m_audDataRate = 0.0;
                    }
                }
            }
        }
Пример #5
0
        private unsafe void DecodeWave(RiffParser rp, int length)
        {
            byte[] ba = new byte[length];
            rp.ReadData(ba, 0, length);

            fixed(byte *bp = &ba[0])
            {
                WAVEFORMATEX *wave = (WAVEFORMATEX *)bp;

                m_numChannels   = wave->nChannels;
                m_bitsPerSec    = wave->nAvgBytesPerSec;
                m_bitsPerSample = wave->wBitsPerSample;
                m_samplesPerSec = wave->nSamplesPerSec;
            }
        }
Пример #6
0
        /// <summary>
        /// Handle List elements found in the AVI file. Ignores unknown lists and recursively looks
        /// at the content of known lists.
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="FourCC"></param>
        /// <param name="length"></param>
        private void ProcessAVIList(RiffParser rp, int FourCC, int length)
        {
            RiffParser.ProcessChunkElement pac = ProcessAVIChunk;
            RiffParser.ProcessListElement  pal = ProcessAVIList;

            // Is this the header?
            if ((AviRiffData.ckidAVIHeaderList == FourCC) ||
                (AviRiffData.ckidAVIStreamList == FourCC) ||
                (AviRiffData.ckidINFOList == FourCC))
            {
                while (length > 0)
                {
                    if (false == rp.ReadElement(ref length, pac, pal))
                    {
                        break;
                    }
                }
            }
            else
            {
                // Unknown lists - ignore
                rp.SkipData(length);
            }
        }
        /// <summary>
        /// The decode avi header.
        /// </summary>
        /// <param name="rp">
        /// The rp.
        /// </param>
        /// <param name="length">
        /// The length.
        /// </param>
        /// <exception cref="RiffParserException">
        /// </exception>
        private unsafe void DecodeAVIHeader(RiffParser rp, int length)
        {
            // if (length < sizeof(AVIMAINHEADER))
            // {
            // throw new RiffParserException(String.Format("Header size mismatch. Needed {0} but only have {1}",
            // sizeof(AVIMAINHEADER), length));
            // }
            byte[] ba = new byte[length];

            if (rp.ReadData(ba, 0, length) != length)
            {
                throw new RiffParserException("Problem reading AVI header.");
            }

            fixed (byte* bp = &ba[0])
            {
                AVIMAINHEADER* avi = (AVIMAINHEADER*)bp;
                this.m_frameRate = avi->dwMicroSecPerFrame;
                this.Height = avi->dwHeight;
                this.m_maxBitRate = avi->dwMaxBytesPerSec;
                this.m_numStreams = avi->dwStreams;
                this.TotalFrames = avi->dwTotalFrames;
                this.Width = avi->dwWidth;
            }
        }
        /// <summary>
        /// Handle chunk elements found in the AVI file. Ignores unknown chunks and
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="fourCc"></param>
        /// <param name="unpaddedLength"></param>
        /// <param name="paddedLength"></param>
        private void ProcessAviChunk(RiffParser rp, int fourCc, int unpaddedLength, int paddedLength)
        {
            if (AviRiffData.CkidMainAviHeader == fourCc)
            {
                // Main AVI header
                DecodeAviHeader(rp, paddedLength);
            }
            else if (AviRiffData.CkidAviStreamHeader == fourCc)
            {
                // Stream header
                DecodeAviStream(rp, paddedLength);
            }
            else if (AviRiffData.CkidAviisft == fourCc)
            {
                Byte[] ba = new byte[paddedLength];
                rp.ReadData(ba, 0, paddedLength);
                StringBuilder sb = new StringBuilder(unpaddedLength);
                for (int i = 0; i < unpaddedLength; ++i)
                {
                    if (0 != ba[i]) sb.Append((char)ba[i]);
                }

                Isft = sb.ToString();
            }
            else
            {
                // Unknon chunk - skip
                rp.SkipData(paddedLength);
            }
        }
        /// <summary>
        /// Handle List elements found in the AVI file. Ignores unknown lists and recursively looks
        /// at the content of known lists.
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="fourCc"></param>
        /// <param name="length"></param>
        private void ProcessAviList(RiffParser rp, int fourCc, int length)
        {
            RiffParser.ProcessChunkElement pac = ProcessAviChunk;
            RiffParser.ProcessListElement pal = ProcessAviList;

            // Is this the header?
            if ((AviRiffData.CkidAviHeaderList == fourCc)
                || (AviRiffData.CkidAviStreamList == fourCc)
                || (AviRiffData.CkidInfoList == fourCc))
            {
                while (length > 0)
                {
                    if (false == rp.ReadElement(ref length, pac, pal))
                    {
                        break;
                    }
                }
            }
            else
            {
                // Unknown lists - ignore
                rp.SkipData(length);
            }
        }
Пример #10
0
 public RiffDecodeHeader(RiffParser rp)
 {
     m_parser = rp;
 }
Пример #11
0
 /// <summary>
 /// Default list element handler - skip the entire list
 /// </summary>
 /// <param name="rp"></param>
 /// <param name="FourCC"></param>
 /// <param name="length"></param>
 private void ProcessList(RiffParser rp, int FourCC, int length)
 {
     rp.SkipData(length);
 }
 /// <summary>
 /// The process wave chunk.
 /// </summary>
 /// <param name="rp">
 /// The rp.
 /// </param>
 /// <param name="FourCC">
 /// The four cc.
 /// </param>
 /// <param name="unpaddedLength">
 /// The unpadded length.
 /// </param>
 /// <param name="length">
 /// The length.
 /// </param>
 private void ProcessWaveChunk(RiffParser rp, int FourCC, int unpaddedLength, int length)
 {
     // Is this a 'fmt' chunk?
     if (AviRiffData.ckidWaveFMT == FourCC)
     {
         this.DecodeWave(rp, length);
     }
     else
     {
         rp.SkipData(length);
     }
 }
        /// <summary>
        /// The decode wave.
        /// </summary>
        /// <param name="rp">
        /// The rp.
        /// </param>
        /// <param name="length">
        /// The length.
        /// </param>
        private unsafe void DecodeWave(RiffParser rp, int length)
        {
            byte[] ba = new byte[length];
            rp.ReadData(ba, 0, length);

            fixed (byte* bp = &ba[0])
            {
                WAVEFORMATEX* wave = (WAVEFORMATEX*)bp;
                this.m_numChannels = wave->nChannels;
                this.m_bitsPerSec = wave->nAvgBytesPerSec;
                this.m_bitsPerSample = wave->wBitsPerSample;
                this.m_samplesPerSec = wave->nSamplesPerSec;
            }
        }
 private void ProcessWaveChunk(RiffParser rp, int fourCc, int unpaddedLength, int length)
 {
     // Is this a 'fmt' chunk?
     if (AviRiffData.CkidWaveFmt == fourCc)
     {
         DecodeWave(rp, length);
     }
     else
     {
         rp.SkipData(length);
     }
 }
        private unsafe void DecodeWave(RiffParser rp, int length)
        {
            byte[] ba = new byte[length];
            rp.ReadData(ba, 0, length);

            fixed (byte* bp = &ba[0])
            {
                Waveformatex* wave = (Waveformatex*)bp;
                mNumChannels = wave->nChannels;
                mBitsPerSec = wave->nAvgBytesPerSec;
                mBitsPerSample = wave->wBitsPerSample;
                mSamplesPerSec = wave->nSamplesPerSec;
            }
        }
        /// <summary>
        /// Handle List elements found in the AVI file. Ignores unknown lists and recursively looks
        ///     at the content of known lists.
        /// </summary>
        /// <param name="rp">
        /// </param>
        /// <param name="FourCC">
        /// </param>
        /// <param name="length">
        /// </param>
        private void ProcessAVIList(RiffParser rp, int FourCC, int length)
        {
            RiffParser.ProcessChunkElement pac = this.ProcessAVIChunk;
            RiffParser.ProcessListElement pal = this.ProcessAVIList;

            // Is this the header?
            if ((AviRiffData.ckidAVIHeaderList == FourCC) || (AviRiffData.ckidAVIStreamList == FourCC) || (AviRiffData.ckidINFOList == FourCC))
            {
                while (length > 0)
                {
                    if (false == rp.ReadElement(ref length, pac, pal))
                    {
                        break;
                    }
                }
            }
            else
            {
                // Unknown lists - ignore
                rp.SkipData(length);
            }
        }
        /// <summary>
        /// Handle chunk elements found in the AVI file. Ignores unknown chunks and
        /// </summary>
        /// <param name="rp">
        /// </param>
        /// <param name="FourCC">
        /// </param>
        /// <param name="unpaddedLength">
        /// </param>
        /// <param name="paddedLength">
        /// </param>
        private void ProcessAVIChunk(RiffParser rp, int FourCC, int unpaddedLength, int paddedLength)
        {
            if (AviRiffData.ckidMainAVIHeader == FourCC)
            {
                // Main AVI header
                this.DecodeAVIHeader(rp, paddedLength);
            }
            else if (AviRiffData.ckidAVIStreamHeader == FourCC)
            {
                // Stream header
                this.DecodeAVIStream(rp, paddedLength);
            }
            else if (AviRiffData.ckidAVIISFT == FourCC)
            {
                byte[] ba = new byte[paddedLength];
                rp.ReadData(ba, 0, paddedLength);
                StringBuilder sb = new StringBuilder(unpaddedLength);
                for (int i = 0; i < unpaddedLength; ++i)
                {
                    if (0 != ba[i])
                    {
                        sb.Append((char)ba[i]);
                    }
                }

                this.ISFT = sb.ToString();
            }
            else
            {
                // Unknon chunk - skip
                rp.SkipData(paddedLength);
            }
        }
 /// <summary>
 /// Default list element handler - skip the entire list
 /// </summary>
 /// <param name="rp">
 /// </param>
 /// <param name="FourCC">
 /// </param>
 /// <param name="length">
 /// </param>
 private void ProcessList(RiffParser rp, int FourCC, int length)
 {
     rp.SkipData(length);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RiffDecodeHeader"/> class.
 /// </summary>
 /// <param name="rp">
 /// The rp.
 /// </param>
 public RiffDecodeHeader(RiffParser rp)
 {
     this.Parser = rp;
 }
 public RiffDecodeHeader(RiffParser rp)
 {
     m_parser = rp;
 }
        /// <summary>
        /// The decode avi stream.
        /// </summary>
        /// <param name="rp">
        /// The rp.
        /// </param>
        /// <param name="length">
        /// The length.
        /// </param>
        /// <exception cref="RiffParserException">
        /// </exception>
        private unsafe void DecodeAVIStream(RiffParser rp, int length)
        {
            byte[] ba = new byte[length];

            if (rp.ReadData(ba, 0, length) != length)
            {
                throw new RiffParserException("Problem reading AVI header.");
            }

            fixed (byte* bp = &ba[0])
            {
                AVISTREAMHEADER* avi = (AVISTREAMHEADER*)bp;

                if (AviRiffData.streamtypeVIDEO == avi->fccType)
                {
                    this.VideoHandler = RiffParser.FromFourCC(avi->fccHandler);
                    if (avi->dwScale > 0)
                    {
                        this.m_vidDataRate = avi->dwRate / (double)avi->dwScale;
                    }
                    else
                    {
                        this.m_vidDataRate = 0.0;
                    }
                }
                else if (AviRiffData.streamtypeAUDIO == avi->fccType)
                {
                    if (AviRiffData.ckidMP3 == avi->fccHandler)
                    {
                        this.m_audHandler = "MP3";
                    }
                    else
                    {
                        this.m_audHandler = RiffParser.FromFourCC(avi->fccHandler);
                    }

                    if (avi->dwScale > 0)
                    {
                        this.m_audDataRate = 8.0 * avi->dwRate / avi->dwScale;
                        if (avi->dwSampleSize > 0)
                        {
                            this.m_audDataRate /= avi->dwSampleSize;
                        }
                    }
                    else
                    {
                        this.m_audDataRate = 0.0;
                    }
                }
            }
        }
        private unsafe void DecodeAviStream(RiffParser rp, int length)
        {
            byte[] ba = new byte[length];

            if (rp.ReadData(ba, 0, length) != length)
            {
                throw new RiffParserException("Problem reading AVI header.");
            }

            fixed (Byte* bp = &ba[0])
            {
                Avistreamheader* avi = (Avistreamheader*)bp;

                if (AviRiffData.StreamtypeVideo == avi->fccType)
                {
                    mVidHandler = RiffParser.FromFourCc(avi->fccHandler);
                    if (avi->dwScale > 0)
                    {
                        mVidDataRate = (double)avi->dwRate / (double)avi->dwScale;
                    }
                    else
                    {
                        mVidDataRate = 0.0;
                    }
                }
                else if (AviRiffData.StreamtypeAudio == avi->fccType)
                {
                    mAudHandler = AviRiffData.CkidMp3 == avi->fccHandler ? "MP3" : RiffParser.FromFourCc(avi->fccHandler);
                    if (avi->dwScale > 0)
                    {
                        mAudDataRate = 8.0 * avi->dwRate / avi->dwScale;
                        if (avi->dwSampleSize > 0)
                        {
                            mAudDataRate /= avi->dwSampleSize;
                        }
                    }
                    else
                    {
                        mAudDataRate = 0.0;
                    }
                }
            }
        }