Exemple #1
0
            /// <summary>
            /// begin recording
            /// </summary>
            public void OpenStreams()
            {
                if (currVideoCodecToken == null)
                {
                    throw new InvalidOperationException("set a video codec token before opening the streams!");
                }

                // open compressed video stream
                Win32.AVICOMPRESSOPTIONS opts = new Win32.AVICOMPRESSOPTIONS();
                currVideoCodecToken.AllocateToAVICOMPRESSOPTIONS(ref opts);
                bool failed = Win32.FAILED(Win32.AVIMakeCompressedStream(out pAviCompressedVideoStream, pAviRawVideoStream, ref opts, IntPtr.Zero));

                CodecToken.DeallocateAVICOMPRESSOPTIONS(ref opts);

                if (failed)
                {
                    CloseStreams();
                    throw new InvalidOperationException("Failed making compressed video stream");
                }

                // set the compressed video stream input format
                Win32.BITMAPINFOHEADER bmih = new Win32.BITMAPINFOHEADER();
                if (bit32)
                {
                    parameters.PopulateBITMAPINFOHEADER32(ref bmih);
                }
                else
                {
                    parameters.PopulateBITMAPINFOHEADER24(ref bmih);
                }

                if (Win32.FAILED(Win32.AVIStreamSetFormat(pAviCompressedVideoStream, 0, ref bmih, Marshal.SizeOf(bmih))))
                {
                    bit32 = true;                     // we'll try again
                    CloseStreams();
                    throw new InvalidOperationException("Failed setting compressed video stream input format");
                }

                // set audio stream input format
                Win32.WAVEFORMATEX wfex = new Win32.WAVEFORMATEX();
                parameters.PopulateWAVEFORMATEX(ref wfex);
                if (Win32.FAILED(Win32.AVIStreamSetFormat(pAviRawAudioStream, 0, ref wfex, Marshal.SizeOf(wfex))))
                {
                    CloseStreams();
                    throw new InvalidOperationException("Failed setting raw audio stream input format");
                }
            }