Beispiel #1
0
        private void OpenEtlFile()
        {
            // Retained the delegate objects to avoid GC.
            EventRecordCallbackRetainer = new EventRecordCallback(EventRecordCallback);
            BufferCallbackRetainer      = new BufferCallback(BufferCallback);

            // Open the ETL log file.
            EVENT_TRACE_LOGFILE traceLogFile = new EVENT_TRACE_LOGFILE
            {
                LogFileName      = EtlFilePath,
                ProcessTraceMode = EventTracingApi.PROCESS_TRACE_MODE_EVENT_RECORD,
                BufferCallback   = BufferCallbackRetainer,
                EventCallback    = EventRecordCallbackRetainer,
            };

            TraceHandle = EventTracingApi.OpenTrace(ref traceLogFile);

            if (EventTracingApi.IsInvalidProcessTraceHandle(TraceHandle))
            {
                var win32ErrorCode = Marshal.GetLastWin32Error();

                string exceptionMessage;
                if (win32ErrorCode == Win32ErrorCode.ERROR_FILE_CORRUPT)
                {
                    exceptionMessage = string.Format("OpenTrace function failed. The file '{0}' is corrupted.", EtlFilePath);
                }
                else
                {
                    exceptionMessage = string.Format("OpenTrace function failed. The file tried to open was '{0}'.", EtlFilePath);
                }

                throw new Win32Exception(win32ErrorCode, exceptionMessage);
            }
        }
Beispiel #2
0
        long _forcedPicDuration = 3 * ONE_SECOND; // change this to 0 to encode each frame normally

        #endregion Fields

        #region Constructors

        public MpegManager(String fileName, int format, int sourceWidth, int sourceHeight)
        {
            // Reset the start position
            _curPicStart = 0;

            // sourceWidth and sourceHeight is the expected size of the bitmaps
            // If they do not match, they will be resized to that size
            _expectedWidth = sourceWidth;
            _expectedHeight = sourceHeight;

            // Open the output mpeg file. The data is sent in the callback at the
            // end of this file
            _fileStream = File.Create(fileName);
            _binaryWriter = new BinaryWriter(_fileStream);

            // Initialize the encoder
            StandardMpegEncoderDll.MediaFileInitialize();

            cb = new BufferCallback(MpegBufferCallback);

            // Select the format (mpeg-1, etc)
            SelectFormat(format);

            // Set the registration code
            RegisterLibrary();

            // Set the source width and height
            StandardMpegEncoderDll.MediaFileSetParameter("nInputX", sourceWidth.ToString());
            StandardMpegEncoderDll.MediaFileSetParameter("nInputY", sourceHeight.ToString());

            // switch off audio
            StandardMpegEncoderDll.MediaFileSetParameter("bWriteAudioStream", "0");

            // Set the MPEG data callback function. If you wish, pass your
            // user specific data as the first parameter
            IntPtr myData = (IntPtr)0;

            StandardMpegEncoderDll.MediaFileSetBufferCallback(myData, cb);

            // Create the file
            StandardMpegEncoderDll.MediaFileCreate();
        }
Beispiel #3
0
        /// <summary>
        /// Begins buffering read-buffer.
        /// </summary>
        /// <param name="async">If true then this method can complete asynchronously. If false, this method completed always syncronously.</param>
        /// <param name="asyncCallback">The callback that is executed when asynchronous operation completes. 
        /// If operation completes synchronously, no callback called.</param>
        /// <returns>
        /// Returns true if the I/O operation is pending. The BufferReadAsyncEventArgs.Completed event on the context parameter will be raised upon completion of the operation. 
        /// Returns false if the I/O operation completed synchronously. The BufferReadAsyncEventArgs.Completed event on the context parameter will not be raised and the context object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation. 
        /// </returns>
        /// <exception cref="InvalidOperationException">Is raised when there is data in read buffer and this method is called.</exception>
        private bool BufferRead(bool async, BufferCallback asyncCallback)
        {
            if (BytesInReadBuffer != 0)
            {
                throw new InvalidOperationException("There is already data in read buffer.");
            }

            m_ReadBufferOffset = 0;
            m_ReadBufferCount = 0;

            m_pReadBufferOP.ReleaseEvents();
            m_pReadBufferOP.Completed += delegate(object s, EventArgs<BufferReadAsyncOP> e)
                                             {
                                                 if (e.Value.Error != null)
                                                 {
                                                     if (asyncCallback != null)
                                                     {
                                                         asyncCallback(e.Value.Error);
                                                     }
                                                 }
                                                 else
                                                 {
                                                     m_ReadBufferOffset = 0;
                                                     m_ReadBufferCount = e.Value.BytesInBuffer;
                                                     m_BytesReaded += e.Value.BytesInBuffer;
                                                     m_LastActivity = DateTime.Now;

                                                     if (asyncCallback != null)
                                                     {
                                                         asyncCallback(null);
                                                     }
                                                 }
                                             };

            if (async)
            {
                //Console.WriteLine(new StackTrace().ToString());
            }

            if (!m_pReadBufferOP.Start(async, m_pReadBuffer, m_pReadBuffer.Length))
            {
                return true;
            }
            else
            {
                if (m_pReadBufferOP.Error != null)
                {
                    throw m_pReadBufferOP.Error;
                }
                else
                {
                    m_ReadBufferOffset = 0;
                    m_ReadBufferCount = m_pReadBufferOP.BytesInBuffer;
                    m_BytesReaded += m_pReadBufferOP.BytesInBuffer;
                    m_LastActivity = DateTime.Now;
                }

                return false;
            }

            /* REMOVE ME:
            if(!m_pReadBufferOP.Start(m_pReadBuffer,m_pReadBuffer.Length)){
                if(async == false){
                    // Wait while async operation completes.
                    while(!m_pReadBufferOP.IsCompleted){
                        Thread.Sleep(1);
                    }

                    return false;
                }
                else{
                    return true;
                }
            }
            else{
                if(m_pReadBufferOP.Error != null){
                    throw m_pReadBufferOP.Error;
                }
                else{
                    m_ReadBufferOffset =  0;
                    m_ReadBufferCount  =  m_pReadBufferOP.BytesInBuffer;
                    m_BytesReaded      += m_pReadBufferOP.BytesInBuffer;
                    m_LastActivity     =  DateTime.Now; 
                }

                return false;
            } */
        }
        /// <summary>
        /// Begins buffering read-buffer.
        /// </summary>
        /// <param name="async">If true then this method can complete asynchronously. If false, this method completed always syncronously.</param>
        /// <param name="asyncCallback">The callback that is executed when asynchronous operation completes. 
        /// If operation completes synchronously, no callback called.</param>
        /// <returns>
        /// Returns true if the I/O operation is pending. The BufferReadAsyncEventArgs.Completed event on the context parameter will be raised upon completion of the operation. 
        /// Returns false if the I/O operation completed synchronously. The BufferReadAsyncEventArgs.Completed event on the context parameter will not be raised and the context object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation. 
        /// </returns>
        /// <exception cref="InvalidOperationException">Is raised when there is data in read buffer and this method is called.</exception>
        private bool BufferRead(bool async,BufferCallback asyncCallback)
        {
            if(this.BytesInReadBuffer != 0){
                throw new InvalidOperationException("There is already data in read buffer.");
            }

            m_ReadBufferOffset =  0;
            m_ReadBufferCount  =  0;

            #region async

            if(async){
                m_pReadBufferOP.ReleaseEvents();
                m_pReadBufferOP.Completed += new EventHandler<EventArgs<BufferReadAsyncOP>>(delegate(object s,EventArgs<BufferReadAsyncOP> e){            
                    if(e.Value.Error != null){
                        if(asyncCallback != null){
                            asyncCallback(e.Value.Error);
                        }
                    }
                    else{
                        m_ReadBufferOffset =  0;
                        m_ReadBufferCount  =  e.Value.BytesInBuffer;
                        m_BytesReaded      += e.Value.BytesInBuffer;
                        m_LastActivity     =  DateTime.Now; 

                        if(asyncCallback != null){
                            asyncCallback(null);
                        }
                    }
                });
                        
                if(!m_pReadBufferOP.Start(async,m_pReadBuffer,m_pReadBuffer.Length)){
                    return true;
                }
                else{
                    if(m_pReadBufferOP.Error != null){
                        throw m_pReadBufferOP.Error;
                    }
                    else{
                        m_ReadBufferOffset =  0;
                        m_ReadBufferCount  =  m_pReadBufferOP.BytesInBuffer;
                        m_BytesReaded      += m_pReadBufferOP.BytesInBuffer;
                        m_LastActivity     =  DateTime.Now; 
                    }

                    return false;
                }
            }

            #endregion

            #region sync

            else{
                int countReaded = m_pStream.Read(m_pReadBuffer,0,m_pReadBuffer.Length);
                m_ReadBufferCount  =  countReaded;
                m_BytesReaded      += countReaded;
                m_LastActivity     =  DateTime.Now;

                return false;
            }

            #endregion                        
        }
Beispiel #5
0
 public static extern int MediaFileSetBufferCallback(IntPtr pUserData, BufferCallback callbackFunc);
Beispiel #6
0
 public static extern IntPtr SCL_CreateMonitorCaptureConfiguration(BufferCallback callback);
Beispiel #7
0
 public static extern int MediaFileSetBufferCallback(IntPtr pUserData, BufferCallback callbackFunc);