⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capvbi.c

📁 一个视频采集驱动程序的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//==========================================================================;
//
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
//  PURPOSE.
//
//  Copyright (c) 1992 - 1999  Microsoft Corporation.  All Rights Reserved.
//
//==========================================================================;

#include "strmini.h"
#include "ksmedia.h"
#include "capmain.h"
#include "capdebug.h"
#include "vbixfer.h"
#include "ntstatus.h"


/*
** VBICaptureRoutine()
**
**    Routine to generate video frames based on a timer.
**
**    Note:  Devices capable of using interrupts should always
**           trigger capture on a VSYNC interrupt, and not use a timer.
**
** Arguments:
**
** Returns: nothing
**
** Side Effects:  none
*/

VOID 
STREAMAPI 
VBICaptureRoutine(
    IN PSTREAMEX pStrmEx
    )
{
    PHW_DEVICE_EXTENSION    pHwDevExt = pStrmEx->pHwDevExt;
    int                     StreamNumber = pStrmEx->pStreamObject->StreamNumber;
    PKSSTREAM_HEADER        pDataPacket;
    PKS_VBI_FRAME_INFO      pVBIFrameInfo;

    // If we're stopped and the timer is still running, just return.
    // This will stop the timer.

    if (pStrmEx->KSState == KSSTATE_STOP) {  
        return;
    }

    
    // Find out what time it is, if we're using a clock

    if (pStrmEx->hMasterClock) {
        HW_TIME_CONTEXT TimeContext;

        TimeContext.HwDeviceExtension = pHwDevExt; 
        TimeContext.HwStreamObject = pStrmEx->pStreamObject;
        TimeContext.Function = TIME_GET_STREAM_TIME;

        StreamClassQueryMasterClockSync (
                pStrmEx->hMasterClock,
                &TimeContext);

        pStrmEx->QST_StreamTime = TimeContext.Time;
        pStrmEx->QST_Now = TimeContext.SystemTime;
    
        if (pStrmEx->QST_NextFrame == 0) {  
            pStrmEx->QST_NextFrame =
                pStrmEx->QST_StreamTime
                + pStrmEx->pVBIStreamFormat->ConfigCaps.MinFrameInterval;
        }

#ifdef CREATE_A_FLURRY_OF_TIMING_SPEW
        DbgLogTrace(("TestCap:    Time=%16lx\n", TimeContext.Time));
        DbgLogTrace(("TestCap: SysTime=%16lx\n", TimeContext.SystemTime));
#endif
    }


    // Only capture in the RUN state

    if (pStrmEx->KSState == KSSTATE_RUN) {  

        //
        // Determine if it is time to capture a frame based on 
        // how much time has elapsed since capture started.
        // If there isn't a clock available, then capture immediately.
        //

        if ((!pStrmEx->hMasterClock) ||
             (pStrmEx->QST_StreamTime >= pStrmEx->QST_NextFrame)) {

            PHW_STREAM_REQUEST_BLOCK pSrb;

            // Increment the picture count (usually this is VSYNC count)

            pStrmEx->VBIFrameInfo.PictureNumber++;

            //
            // Get the next queue SRB (if any)
            //

            pSrb = VideoQueueRemoveSRB (pHwDevExt, StreamNumber);

            if (pSrb) {

                pDataPacket = pSrb->CommandData.DataBufferArray;
                pVBIFrameInfo = (PKS_VBI_FRAME_INFO)(pDataPacket + 1);

                pStrmEx->VBIFrameInfo.dwFrameFlags = 0;

                //
                // If needed, send out VBIInfoHeader
                //
                if (!(pStrmEx->SentVBIInfoHeader)) {
                    pStrmEx->SentVBIInfoHeader = 1;
                    pStrmEx->VBIFrameInfo.dwFrameFlags |=
                            KS_VBI_FLAG_VBIINFOHEADER_CHANGE;
                    pStrmEx->VBIFrameInfo.VBIInfoHeader = StreamFormatVBI.VBIInfoHeader;
                }

                // Set additional info fields about the data captured such as:
                //   Frames Captured
                //   Frames Dropped
                //   Field Polarity
                //   Protection status
                //
                pStrmEx->VBIFrameInfo.ExtendedHeaderSize =
                    pVBIFrameInfo->ExtendedHeaderSize;

                if (pStrmEx->VBIFrameInfo.PictureNumber & 1)
                    pStrmEx->VBIFrameInfo.dwFrameFlags |= KS_VBI_FLAG_FIELD1;
                else
                    pStrmEx->VBIFrameInfo.dwFrameFlags |= KS_VBI_FLAG_FIELD2;

                pStrmEx->VBIFrameInfo.dwFrameFlags |=
                    pHwDevExt->ProtectionStatus & (KS_VBI_FLAG_MV_PRESENT
                                                    |KS_VBI_FLAG_MV_HARDWARE
                                                    |KS_VBI_FLAG_MV_DETECTED);

                *pVBIFrameInfo = pStrmEx->VBIFrameInfo;

                // Copy this into stream header so ring 3 filters can see it
                pDataPacket->TypeSpecificFlags = pVBIFrameInfo->dwFrameFlags;

                // Init the flags to zero
                pDataPacket->OptionsFlags = 0;

                // Set the discontinuity flag if frames have been previously
                // dropped, and then reset our internal flag

                if (pStrmEx->fDiscontinuity) {
                    pDataPacket->OptionsFlags |= KSSTREAM_HEADER_OPTIONSF_DATADISCONTINUITY;
                    pStrmEx->fDiscontinuity = FALSE;
                }

                //
                // Return the timestamp for the frame
                //
                pDataPacket->PresentationTime.Numerator = 1;
                pDataPacket->PresentationTime.Denominator = 1;
                pDataPacket->Duration = pStrmEx->pVBIStreamFormat->ConfigCaps.MinFrameInterval;

                //
                // if we have a master clock AND this is a capture stream
                // 
                if (pStrmEx->hMasterClock
                    && (StreamNumber == STREAM_Capture
                            || StreamNumber == STREAM_VBI))
                {

                    pDataPacket->PresentationTime.Time = pStrmEx->QST_StreamTime;
                    pDataPacket->OptionsFlags |= 
                        KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
                        KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
                }
                else {
                    //
                    // No clock or not a capture stream,
                    //  so just mark the time as unknown
                    //
                    pDataPacket->PresentationTime.Time = 0;
                    // clear the timestamp valid flags
                    pDataPacket->OptionsFlags &= 
                        ~(KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
                          KSSTREAM_HEADER_OPTIONSF_DURATIONVALID);
                }

                // Every frame we generate is a key frame (aka SplicePoint)
                // Delta frames (B or P) should not set this flag

                pDataPacket->OptionsFlags |= KSSTREAM_HEADER_OPTIONSF_SPLICEPOINT;

                //
                // Call the routine which synthesizes images
                //
                VBI_ImageSynth(pSrb);

                // Output a frame count every 300th frame (~5 sec) in Debug mode
                if (pStrmEx->VBIFrameInfo.PictureNumber % 300 == 0) {
                   DbgLogInfo(("TestCap: Picture %u, Stream=%d\n", 
                           (unsigned int)pStrmEx->VBIFrameInfo.PictureNumber, 
                           StreamNumber));
                }

                CompleteStreamSRB(pSrb);
                
            } // if we have an SRB

            else {

                //
                // No buffer was available when we should have captured one

                // Increment the counter which keeps track of
                // dropped frames

                pStrmEx->VBIFrameInfo.DropCount++;

                // Set the (local) discontinuity flag
                // This will cause the next packet processed to have the
                //   KSSTREAM_HEADER_OPTIONSF_DATADISCONTINUITY flag set.

                pStrmEx->fDiscontinuity = TRUE;

            }

            // Figure out when to capture the next frame
            pStrmEx->QST_NextFrame += pStrmEx->pVBIStreamFormat->ConfigCaps.MinFrameInterval;

        } // endif time to capture a frame
    } // endif we're running
}


/*
** VBIhwCaptureRoutine()
**
**    Routine to capture video frames based on a timer.
**
**    Notes:  * Devices capable of using interrupts should always trigger
**              capture on a VSYNC interrupt, and not use a timer.
**            * This routine is used by VBI streams which do NOT have extended
**              headers, such as CC and NABTS.
**
** Arguments:
**
** Returns: nothing
**
** Side Effects:  none
*/

VOID 
STREAMAPI 
VBIhwCaptureRoutine(
    IN PSTREAMEX pStrmEx
    )
{
    PHW_DEVICE_EXTENSION    pHwDevExt = pStrmEx->pHwDevExt;
    int                     StreamNumber = pStrmEx->pStreamObject->StreamNumber;
    PKSSTREAM_HEADER        pDataPacket;

    // If we're stopped and the timer is still running, just return.
    // This will stop the timer.

    if (pStrmEx->KSState == KSSTATE_STOP) {  
        return;
    }

    
    // Find out what time it is, if we're using a clock

    if (pStrmEx->hMasterClock ) {
        HW_TIME_CONTEXT TimeContext;

        TimeContext.HwDeviceExtension = pHwDevExt; 
        TimeContext.HwStreamObject = pStrmEx->pStreamObject;
        TimeContext.Function = TIME_GET_STREAM_TIME;

        StreamClassQueryMasterClockSync (
                pStrmEx->hMasterClock,
                &TimeContext);

        pStrmEx->QST_StreamTime = TimeContext.Time;
        pStrmEx->QST_Now = TimeContext.SystemTime;
    
        if (pStrmEx->QST_NextFrame == 0) {  
            pStrmEx->QST_NextFrame =
                pStrmEx->QST_StreamTime
                + pStrmEx->pVBIStreamFormat->ConfigCaps.MinFrameInterval;
        }

#ifdef CREATE_A_FLURRY_OF_TIMING_SPEW
        DbgLogTrace(("TestCap:    Time=%16lx\n", TimeContext.Time));
        DbgLogTrace(("TestCap: SysTime=%16lx\n", TimeContext.SystemTime));
#endif
    }


    // Only capture in the RUN state

    if (pStrmEx->KSState == KSSTATE_RUN) {  

        //
        // Determine if it is time to capture a frame based on 
        // how much time has elapsed since capture started.
        // If there isn't a clock available, then capture immediately.
        //

        if ((!pStrmEx->hMasterClock) ||
             (pStrmEx->QST_StreamTime >= pStrmEx->QST_NextFrame)) {

            PHW_STREAM_REQUEST_BLOCK pSrb;

            // Increment the picture count (usually this is VSYNC count)

            pStrmEx->VBIFrameInfo.PictureNumber++;

            //
            // Get the next queue SRB (if any)
            //

            pSrb = VideoQueueRemoveSRB (pHwDevExt, StreamNumber);

            if (pSrb) {

                pDataPacket = pSrb->CommandData.DataBufferArray;

                // Init the flags to zero
                pDataPacket->OptionsFlags = 0;

                // Set the discontinuity flag if frames have been previously
                // dropped, and then reset our internal flag
                if (pStrmEx->fDiscontinuity) {
                    pDataPacket->OptionsFlags |= KSSTREAM_HEADER_OPTIONSF_DATADISCONTINUITY;
                    pStrmEx->fDiscontinuity = FALSE;
                }

                //
                // Return the timestamp for the frame
                //
                pDataPacket->PresentationTime.Numerator = 1;
                pDataPacket->PresentationTime.Denominator = 1;
                pDataPacket->Duration = pStrmEx->pVBIStreamFormat->ConfigCaps.MinFrameInterval;

                //
                // if we have a master clock AND this is the capture stream
                // 
                if (pStrmEx->hMasterClock && (StreamNumber == 0)) {

                    pDataPacket->PresentationTime.Time = pStrmEx->QST_StreamTime;
                    pDataPacket->OptionsFlags |= 
                        KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
                        KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
                }
                else {
                    //
                    // No clock or the preview stream,
                    //  so just mark the time as unknown
                    //
                    pDataPacket->PresentationTime.Time = 0;
                    // clear the timestamp valid flags
                    pDataPacket->OptionsFlags &= 
                        ~(KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
                          KSSTREAM_HEADER_OPTIONSF_DURATIONVALID);
                }

                // Every frame we generate is a key frame (aka SplicePoint)
                // Delta frames (B or P) should not set this flag

                pDataPacket->OptionsFlags |= KSSTREAM_HEADER_OPTIONSF_SPLICEPOINT;

                //
                // Call the routine which synthesizes images
                //
                switch (StreamNumber) {
                    case STREAM_NABTS:
                        NABTS_ImageSynth(pSrb);
                        break;

                    case STREAM_CC:
                        CC_ImageSynth(pSrb);
                        break;

                    default:
                    case STREAM_VBI:
                        DbgLogError(("TestCap::VBIhwCaptureRoutine: Bad stream %d\n", StreamNumber));
                        break;
                }

                CompleteStreamSRB (pSrb);
                
            } // if we have an SRB

            else {

                //
                // No buffer was available when we should have captured one

                // Increment the counter which keeps track of
                // dropped frames

                pStrmEx->VBIFrameInfo.DropCount++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -