Exemple #1
0
        private unsafe void DecodeAVIHeader(RiffParser rp, int unpaddedLength, 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;
            }
        }
Exemple #2
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, unpaddedLength, paddedLength);
            }
            else if (AviRiffData.ckidAVIStreamHeader == FourCC)
            {
                // Stream header
                DecodeAVIStream(rp, unpaddedLength, 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);
            }
        }
Exemple #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);
     }
 }
Exemple #4
0
        private unsafe void DecodeAVIStream(RiffParser rp, int unpaddedLength, 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;
                    }
                }
            }
        }
Exemple #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;
            }
        }
Exemple #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 = new RiffParser.ProcessChunkElement(ProcessAVIChunk);
            RiffParser.ProcessListElement  pal = new RiffParser.ProcessListElement(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);
            }
        }
Exemple #7
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);
 }
Exemple #8
0
 /// <summary>
 /// Defaulkt chunk handler - skip chunk data
 /// </summary>
 /// <param name="rp"></param>
 /// <param name="FourCC"></param>
 /// <param name="unpaddedLength"></param>
 /// <param name="paddedLength"></param>
 private static void ProcessChunk(RiffParser rp, int FourCC, int unpaddedLength, int paddedLength)
 {
     rp.SkipData(paddedLength);
 }
Exemple #9
0
 public RiffDecodeHeader(RiffParser rp)
 {
     m_parser = rp;
 }