Esempio n. 1
0
            /// <summary>
            /// Acquires a video codec configuration from the user
            /// </summary>
            public IDisposable AcquireVideoCodecToken(IntPtr hwnd)
            {
                if (!IsOpen)
                {
                    throw new InvalidOperationException("File must be opened before acquiring a codec token (or else the stream formats wouldnt be known)");
                }

                //encoder params
                Win32.AVICOMPRESSOPTIONS comprOptions = new Win32.AVICOMPRESSOPTIONS();
                if (currVideoCodecToken != null)
                {
                    comprOptions = currVideoCodecToken.comprOptions;
                }
                if (AVISaveOptions(pAviRawVideoStream, ref comprOptions, hwnd) != 0)
                {
                    CodecToken ret = CodecToken.TakePossession(comprOptions);
                    // save to config as well
                    Global.Config.AVICodecToken = ret.Serialize();
                    return(ret);
                }
                else
                {
                    return(null);
                }
            }
        /// <summary>
        /// Acquires a video codec configuration from the user. you may save it for future use, but you must dispose of it when you're done with it.
        /// returns null if the user canceled the dialog
        /// </summary>
        public IDisposable AcquireVideoCodecToken(IDialogParent parent, Config config)
        {
            var tempParams = new Parameters
            {
                height       = 256,
                width        = 256,
                fps          = 60,
                fps_scale    = 1,
                a_bits       = 16,
                a_samplerate = 44100,
                a_channels   = 2
            };
            var    temp     = new AviWriterSegment();
            string tempfile = Path.GetTempFileName();

            File.Delete(tempfile);
            tempfile = Path.ChangeExtension(tempfile, "avi");
            temp.OpenFile(tempfile, tempParams, null);
            var        ret   = temp.AcquireVideoCodecToken(parent.SelfAsHandle.Handle, _currVideoCodecToken);
            CodecToken token = (CodecToken)ret;

            config.AviCodecToken = token?.Serialize();
            temp.CloseFile();
            File.Delete(tempfile);
            return(token);
        }
Esempio n. 3
0
            /// <summary>
            /// Acquires a video codec configuration from the user
            /// </summary>
            public IDisposable AcquireVideoCodecToken(IntPtr hwnd, CodecToken lastCodecToken)
            {
                if (!IsOpen)
                {
                    throw new InvalidOperationException("File must be opened before acquiring a codec token (or else the stream formats wouldnt be known)");
                }

                if (lastCodecToken != null)
                {
                    currVideoCodecToken = lastCodecToken;
                }

                //encoder params
                Win32.AVICOMPRESSOPTIONS comprOptions = new Win32.AVICOMPRESSOPTIONS();
                if (currVideoCodecToken != null)
                {
                    currVideoCodecToken.AllocateToAVICOMPRESSOPTIONS(ref comprOptions);
                }

                bool       result = AVISaveOptions(pAviRawVideoStream, ref comprOptions, hwnd) != 0;
                CodecToken ret    = CodecToken.CreateFromAVICOMPRESSOPTIONS(ref comprOptions);

                //so, AVISaveOptions may have changed some of the pointers
                //if it changed the pointers, did it it free the old ones? we don't know
                //let's assume it frees them. if we're wrong, we leak. if we assume otherwise and we're wrong, we may crash.
                //so that means any pointers that come in here are either
                //1. ones we allocated a minute ago
                //2. ones VFW allocated
                //guess what? doesn't matter. We'll free them all ourselves.
                CodecToken.DeallocateAVICOMPRESSOPTIONS(ref comprOptions);


                if (result)
                {
                    // save to config and return it
                    Global.Config.AVICodecToken = ret.Serialize();
                    return(ret);
                }
                else
                {
                    return(null);
                }
            }