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; } }
/// <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); } }
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; } } } }
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; } }