コード例 #1
0
ファイル: Form1.cs プロジェクト: tararonis/CustomSamples
        private void thread_DoWork(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                if (encode || live)
                {
                    MFFrame    frameLive = null;
                    MFFrame    frameFile = null;
                    M_AV_PROPS props     = new M_AV_PROPS();
                    if (live)
                    {
                        M_VID_PROPS vidProps = new M_VID_PROPS();
                        vidProps.eVideoFormat = eMVideoFormat.eMVF_HD1080_5994i;
                        m_objLive.FormatVideoSet(eMFormatType.eMFT_Input, ref vidProps);
                        props.vidProps.eVideoFormat = eMVideoFormat.eMVF_Custom;
                        m_objLive.SourceFrameConvertedGet(ref props, -1, out frameLive, "");
                    }
                    if (encode)
                    {
                        props.vidProps.eVideoFormat = eMVideoFormat.eMVF_HD1080_5994i;

                        m_objReader.SourceFrameConvertedGet(ref props, -1, out frameFile, "");
                        if (frameLive != null)
                        {
                            frameLive.MFOverlay(frameFile, null, 0, 0, 0, "audio_gain=0", "ch1");
                        }
                    }

                    if (frameLive != null)
                    {
                        m_objPreview.ReceiverFramePut(frameLive, -1, "");
                    }
                    else
                    {
                        m_objPreview.ReceiverFramePut(frameFile, -1, "");
                    }

                    if (frameLive != null)
                    {
                        Marshal.FinalReleaseComObject(frameLive);
                    }
                    if (frameFile != null)
                    {
                        Marshal.FinalReleaseComObject(frameFile);
                    }
                }
            }
        }
コード例 #2
0
        private bool NextFrame()
        {
            // Get request pos and set pause and reverse flags
            double dblRequest = -1.0;
            string strParams  = string.Empty;

            // Update player state
            lock (m_playerState.stateLock)
            {
                if (m_playerState.state == eState.eST_Pause)
                {
                    strParams = " pause=true";
                }
                else if (m_playerState.state == eState.eST_PlayRev || m_playerState.state == eState.eST_StepRev)
                {
                    strParams = " reverse=true";
                }

                // Update player state
                if (m_playerState.state == eState.eST_StepFwd || m_playerState.state == eState.eST_StepRev)
                {
                    // Pause on next iteration - because single frame was requested
                    m_playerState.state = eState.eST_Pause;
                }

                // Get request time and set next cycle request to next frame
                // -1 as first parameter means "give me next frame", -5 means "give me next next 5th frame" etc,
                // this works accordingly when the reverse=true parameter is set.
                // positive values are uninterpreted as "give me frame at position"
                dblRequest = m_playerState.dblFrameRequest;
                m_playerState.dblFrameRequest = -1 * (int)(m_playerState.dblRate);
            }


            // Next frame cycle:
            // Get frame from reader and send to preview
            // Note: Preview keep frame according to frame time

            MFFrame pFrame = null;

            lock (m_objLock) // For prevent reader replace in OpenFile() and overlay change
            {
                // Get next frame or frame by position
                // -1 as first parameter means "give me next frame", -5 means "give me next next 5th frame" etc,
                // this works accordingly when the reverse=true parameter is set.
                // positive values are uninterpreted as "give me frame at position"
                try
                {
                    if (m_objMFReader != null)
                    {
                        m_objMFReader.SourceFrameConvertedGetByTime(ref m_avProps, dblRequest, -1, out pFrame, strParams + " rate=0.1");
                    }
                    int samples;
                    pFrame.MFAVPropsGet(out currentProps, out samples);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error occurs during file decoding:\n\n" + ex.Message, m_playerState.strFileName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
            }

            if (pFrame == null)
            {
                Thread.Sleep(5);
                return(true);
            }

            try
            {
                // Demonstrate overlay - overlay another frame if any
                if (m_frOverlay != null)
                {
                    pFrame.MFOverlay(m_frOverlay, null, 50, 100, 0.5, "", "");
                }

                // Show CG object
                if (checkBoxCG.Checked)
                {
                    ShowPluggin(m_objCharGen, ref pFrame);
                    if (cgEditor != null)
                    {
                        cgEditor.m_objEditor_FrameProcessed(pFrame, null);
                    }
                }

                // Show CC
                if (checkBoxCC.Checked)
                {
                    if (m_objCCDisplay != null)
                    {
                        ShowPluggin(m_objCCDisplay, ref pFrame);
                    }
                }

                // Show HTML
                if (checkBoxHTML.Checked)
                {
                    lock (m_objHTMLLock)
                    {
                        if (m_objOverlayHTML != null)
                        {
                            ShowPluggin(m_objOverlayHTML, ref pFrame);
                            if (overlayHTMLWind != null && !overlayHTMLWind.IsDisposed)
                            {
                                overlayHTMLWind.UpdatePreview(pFrame);
                            }
                        }
                    }
                }

                mAudioMeter1.pFrame = pFrame;
                mAudioMeter1.SetValues();
                // Get frame timings
                pFrame.MFTimeGet(out mTime);

                double dblDur = 0;
                m_objMFReader.ReaderDurationGet(out dblDur);
                if (m_playerState.dblDuration != dblDur)
                {
                    m_playerState.dblDuration = dblDur;
                }

                // Send frame to Renderer
                SendToRenderer(pFrame);

                //Send frame to the preview
                m_objPreview.ReceiverFramePut(pFrame, checkBoxRenderer.Checked ? 0 : -1, "");

                //Send to Sink
                SendToSink(pFrame);

                //Release frame - DO NOT FORGOT TO DO THIS !!!
                releaseComObj(pFrame);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error occurs during frame processing:\n\n" + ex.Message, m_playerState.strFileName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            // Check for the last frame
            if ((mTime.eFFlags & eMFrameFlags.eMFF_Last) != 0)
            {
                lock (m_playerState.stateLock)
                {
                    // Pause playback at the end of the file if loop is disabled
                    if (!m_playerState.bLoop)
                    {
                        pause();
                    }

                    if (m_playerState.state == eState.eST_PlayRev)
                    {
                        // Rewind to end in case of reverse playback
                        rewindToEnd();
                    }
                    else if (m_playerState.state == eState.eST_PlayFwd)
                    {
                        // Rewind to start in case of direct playback
                        rewindToStart();
                    }
                }
            }

            return(true);
        }