/// <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.MainAviHeader == fourCc) { DecodeAviHeader(rp, paddedLength); // Main AVI header } else if (AviRiffData.AviStreamHeader == fourCc) { DecodeAviStream(rp, paddedLength); // Stream header } else if (AviRiffData.AviIsft == fourCc) { var ba = new byte[paddedLength]; rp.ReadData(ba, 0, paddedLength); var sb = new StringBuilder(unpaddedLength); for (int i = 0; i < unpaddedLength; ++i) { if (0 != ba[i]) { sb.Append((char)ba[i]); } } _isft = sb.ToString(); } else { rp.SkipData(paddedLength); // Unknown chunk - skip } }
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; } }
/// <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); } }
private void DecodeAviStream(RiffParser rp, int length) { var ba = new byte[length]; if (rp.ReadData(ba, 0, length) != length) { throw new RiffParserException("Problem reading AVI header."); } var aviStreamHeader = new AviStreamHeader { FccType = GetInt(ba, 0), FccHandler = GetInt(ba, 4), Scale = GetInt(ba, 20), Rate = GetInt(ba, 24), Start = GetInt(ba, 28), Length = GetInt(ba, 32), SampleSize = GetInt(ba, 44), }; if (AviRiffData.StreamTypeVideo == aviStreamHeader.FccType) { _vidHandler = RiffParser.FromFourCc(aviStreamHeader.FccHandler); if (aviStreamHeader.Scale > 0) { _vidDataRate = (double)aviStreamHeader.Rate / aviStreamHeader.Scale; } else { _vidDataRate = 0.0; } } else if (AviRiffData.StreamTypeAudio == aviStreamHeader.FccType) { if (AviRiffData.Mp3 == aviStreamHeader.FccHandler) { _audHandler = "MP3"; } else { _audHandler = RiffParser.FromFourCc(aviStreamHeader.FccHandler); } if (aviStreamHeader.Scale > 0) { _audDataRate = 8.0 * aviStreamHeader.Rate / aviStreamHeader.Scale; if (aviStreamHeader.SampleSize > 0) { _audDataRate /= aviStreamHeader.SampleSize; } } else { _audDataRate = 0.0; } } }
private void DecodeAviStream(RiffParser rp, int length) { var ba = new byte[length]; if (rp.ReadData(ba, 0, length) != length) { throw new RiffParserException("Problem reading AVI header."); } var aviStreamHeader = new AVISTREAMHEADER { fccType = GetInt(ba, 0), fccHandler = GetInt(ba, 4), dwScale = GetInt(ba, 20), dwRate = GetInt(ba, 24), dwStart = GetInt(ba, 28), dwLength = GetInt(ba, 32), dwSampleSize = GetInt(ba, 44), }; if (AviRiffData.streamtypeVIDEO == aviStreamHeader.fccType) { _vidHandler = RiffParser.FromFourCc(aviStreamHeader.fccHandler); if (aviStreamHeader.dwScale > 0) { _vidDataRate = (double)aviStreamHeader.dwRate / aviStreamHeader.dwScale; } else { _vidDataRate = 0.0; } } else if (AviRiffData.streamtypeAUDIO == aviStreamHeader.fccType) { if (AviRiffData.ckidMP3 == aviStreamHeader.fccHandler) { _audHandler = "MP3"; } else { _audHandler = RiffParser.FromFourCc(aviStreamHeader.fccHandler); } if (aviStreamHeader.dwScale > 0) { _audDataRate = 8.0 * aviStreamHeader.dwRate / aviStreamHeader.dwScale; if (aviStreamHeader.dwSampleSize > 0) { _audDataRate /= aviStreamHeader.dwSampleSize; } } else { _audDataRate = 0.0; } } }
private void DecodeWave(RiffParser rp, int length) { var ba = new byte[length]; rp.ReadData(ba, 0, length); _numChannels = GetShort(ba, 2); _bitsPerSec = GetInt(ba, 8); _bitsPerSample = GetShort(ba, 14); _samplesPerSec = GetInt(ba, 4); }
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; } } } }
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; } }
private void DecodeAviHeader(RiffParser rp, int length) { var ba = new byte[length]; if (rp.ReadData(ba, 0, length) != length) { throw new RiffParserException("Problem reading AVI header."); } _frameRate = GetInt(ba, 0); _maxBitRate = GetInt(ba, 4); _totalFrames = GetInt(ba, 16); _numStreams = GetInt(ba, 24); _width = GetInt(ba, 32); _height = GetInt(ba, 36); }
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; } }
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; } } } }
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; } }
/// <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); } }