1 //------------------------------------------------------------------------------
4 // Desc: DirectShow base classes - defines the COutputQueue class, which
5 // makes a queue of samples and sends them to an output pin. The
6 // class will optionally send the samples to the pin directly.
8 // Copyright (c) 1992-2002 Microsoft Corporation. All rights reserved.
9 //------------------------------------------------------------------------------
12 typedef CGenericList
<IMediaSample
> CSampleList
;
14 class COutputQueue
: public CCritSec
18 COutputQueue(IPin
*pInputPin
, // Pin to send stuff to
19 HRESULT
*phr
, // 'Return code'
20 BOOL bAuto
= TRUE
, // Ask pin if blocks
21 BOOL bQueue
= TRUE
, // Send through queue (ignored if
23 LONG lBatchSize
= 1, // Batch
24 BOOL bBatchExact
= FALSE
,// Batch exactly to BatchSize
25 LONG lListSize
= // Likely number in the list
27 DWORD dwPriority
= // Priority of thread to create
28 THREAD_PRIORITY_NORMAL
,
29 bool bFlushingOpt
= false // flushing optimization
33 // enter flush state - discard all data
34 void BeginFlush(); // Begin flushing samples
36 // re-enable receives (pass this downstream)
37 void EndFlush(); // Complete flush of samples - downstream
38 // pin guaranteed not to block at this stage
40 void EOS(); // Call this on End of stream
42 void SendAnyway(); // Send batched samples anyway (if bBatchExact set)
45 REFERENCE_TIME tStart
,
49 HRESULT
Receive(IMediaSample
*pSample
);
51 // do something with these media samples
52 HRESULT
ReceiveMultiple (
53 IMediaSample
**pSamples
,
55 long *nSamplesProcessed
);
57 void Reset(); // Reset m_hr ready for more data
59 // See if its idle or not
62 // give the class an event to fire after everything removed from the queue
63 void SetPopEvent(HANDLE hEvent
);
66 static DWORD WINAPI
InitialThreadProc(LPVOID pv
);
70 return m_List
!= NULL
;
73 // The critical section MUST be held when this is called
74 void QueueSample(IMediaSample
*pSample
);
76 BOOL
IsSpecialSample(IMediaSample
*pSample
)
78 return (DWORD_PTR
)pSample
> (DWORD_PTR
)(LONG_PTR
)(-16);
81 // Remove and Release() batched and queued samples
84 // Notify the thread there is something to do
90 #define SEND_PACKET ((IMediaSample *)(LONG_PTR)(-2)) // Send batch
91 #define EOS_PACKET ((IMediaSample *)(LONG_PTR)(-3)) // End of stream
92 #define RESET_PACKET ((IMediaSample *)(LONG_PTR)(-4)) // Reset m_hr
93 #define NEW_SEGMENT ((IMediaSample *)(LONG_PTR)(-5)) // send NewSegment
95 // new segment packet is always followed by one of these
96 struct NewSegmentPacket
{
97 REFERENCE_TIME tStart
;
102 // Remember input stuff
104 IMemInputPin
* m_pInputPin
;
105 BOOL
const m_bBatchExact
;
106 LONG
const m_lBatchSize
;
108 CSampleList
* m_List
;
110 CAMEvent m_evFlushComplete
;
112 IMediaSample
** m_ppSamples
;
117 // Flush synchronization
120 // flushing optimization. some downstream filters have trouble
121 // with the queue's flushing optimization. other rely on it
128 // Send anyway flag for batching
131 // Deferred 'return code'
134 // an event that can be fired after every deliver