summaryrefslogtreecommitdiff
path: root/avstream/avscamera/sys/imagecapture.cpp
blob: 7ba53fa4155fd3482a5e6e2d4abafddfbdd15f17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**************************************************************************

    A/V Stream Camera Sample

    Copyright (c) 2001, Microsoft Corporation.

    File:

        imagecapture.cpp

    Abstract:

        An implementation of CImageCapturePin

    History:

        created 3/8/2001

**************************************************************************/

#include "Common.h"

#ifdef ALLOC_PRAGMA
#pragma code_seg("PAGE")
#endif // ALLOC_PRAGMA

CImageCapturePin::
CImageCapturePin(
    _In_    PKSPIN Pin
)   : CCapturePin (Pin)
{
    PAGED_CODE();
}

NTSTATUS
CImageCapturePin::
DispatchCreate(
    _In_    PKSPIN Pin,
    _In_    PIRP Irp
)
/*++

Routine Description:

    Static member function called when a pin is created.  Instantiate a 
    CImageCapturePin and attach it to our filter object.

Arguments:

    Pin - 
        The KSPIN to wrap.

    Irp -
        The IRP assocated with this request.

Return Value:

    Success / Failure

--*/
{
    PAGED_CODE();

    DBG_ENTER("(Pin=%d)", Pin->Id);

    NTSTATUS Status = STATUS_SUCCESS;

    CCaptureFilter* pFilter = reinterpret_cast <CCaptureFilter*>(KsPinGetParentFilter(Pin)->Context);
    CImageCapturePin *CapPin = new (NonPagedPoolNx) CImageCapturePin (Pin);

    if( !CapPin )
    {
        // Fail if we couldn't create the pin.
        Status = STATUS_INSUFFICIENT_RESOURCES;
    }
    else
    {
        //  Query the filter for the PhotoMode so we can figure out how many frames should be allocated.
        CExtendedPhotoMode  Mode;
        Mode.PinId = Pin->Id;       // Use Pin ID from KS.
        Status = pFilter->GetPhotoMode( &Mode );

        //  CSensor::GetPhotoMode could fail if the framework gives us a Pin ID that doesn't match our descriptors...
        if( NT_SUCCESS(Status) )
        {
            //  Override the number of frames.
            CapPin->SetDesiredFrames( 
                ( (Mode.Flags & KSCAMERA_EXTENDEDPROP_PHOTOMODE_SEQUENCE) ? 
                    Mode.RequestedHistoryFrames() : 1)
                        + IMAGE_CAPTURE_PIN_MINIMUM_FRAMES );

            Status = 
                CapPin->Initialize();
        }
    }

    if (NT_SUCCESS (Status)) 
    {
        //
        // Adjust the stream header size.  The video packets have extended
        // header info (KS_FRAME_INFO).
        //
        pFilter->setPin(CapPin, Pin->Id);
    }
    else
    {
        //  Clean up.
        delete CapPin;
    }

    DBG_LEAVE("(Pin=%d)=0x%08X", Pin->Id, Status);
    return Status;
}


NTSTATUS
CImageCapturePin::
Close(
    _In_    PIRP Irp
)
{
    PAGED_CODE();

    //  Reset the image sim's counts and queues.
    Reset();

    //  Call the base Close operation.
    return CCapturePin::Close(Irp);
}

// ImageCapturePinDispatch:
//
// This is the dispatch table for the capture pin.  It provides notifications
// about creation, closure, processing, data formats, etc...
// just a copy of CapturePinDispatch for now.
//
DEFINE_CAMERA_KSPIN_DISPATCH( ImageCapturePinDispatch, CImageCapturePin );


//
// ImagePinAllocatorFraming:
//
// This is the simple framing structure for the capture pin.  Note that this
// will be modified via KsEdit when the actual capture format is determined.
// just a copy of CapturePinAllocatorFraming for now.
//
DECLARE_SIMPLE_FRAMING_EX (
    ImageCapturePinAllocatorFraming,
    STATICGUIDOF (KSMEMORY_TYPE_KERNEL_NONPAGED),
    KSALLOCATOR_REQUIREMENTF_SYSTEM_MEMORY |
    KSALLOCATOR_REQUIREMENTF_PREFERENCES_ONLY,
    4,
    0,
    2 * PAGE_SIZE,
    2 * PAGE_SIZE
);