| 1 |
//------------------------------------------------------------------------------ |
| 2 |
// File: OutputQ.h |
| 3 |
// |
| 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. |
| 7 |
// |
| 8 |
// Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved. |
| 9 |
//------------------------------------------------------------------------------ |
| 10 |
|
| 11 |
|
| 12 |
typedef CGenericList<IMediaSample> CSampleList; |
| 13 |
|
| 14 |
class COutputQueue : public CCritSec |
| 15 |
{ |
| 16 |
public: |
| 17 |
// Constructor |
| 18 |
COutputQueue(IPin *pInputPin, // Pin to send stuff to |
| 19 |
__inout HRESULT *phr, // 'Return code' |
| 20 |
BOOL bAuto = TRUE, // Ask pin if blocks |
| 21 |
BOOL bQueue = TRUE, // Send through queue (ignored if |
| 22 |
// bAuto set) |
| 23 |
LONG lBatchSize = 1, // Batch |
| 24 |
BOOL bBatchExact = FALSE,// Batch exactly to BatchSize |
| 25 |
LONG lListSize = // Likely number in the list |
| 26 |
DEFAULTCACHE, |
| 27 |
DWORD dwPriority = // Priority of thread to create |
| 28 |
THREAD_PRIORITY_NORMAL, |
| 29 |
bool bFlushingOpt = false // flushing optimization |
| 30 |
); |
| 31 |
~COutputQueue(); |
| 32 |
|
| 33 |
// enter flush state - discard all data |
| 34 |
void BeginFlush(); // Begin flushing samples |
| 35 |
|
| 36 |
// re-enable receives (pass this downstream) |
| 37 |
void EndFlush(); // Complete flush of samples - downstream |
| 38 |
// pin guaranteed not to block at this stage |
| 39 |
|
| 40 |
void EOS(); // Call this on End of stream |
| 41 |
|
| 42 |
void SendAnyway(); // Send batched samples anyway (if bBatchExact set) |
| 43 |
|
| 44 |
void NewSegment( |
| 45 |
REFERENCE_TIME tStart, |
| 46 |
REFERENCE_TIME tStop, |
| 47 |
double dRate); |
| 48 |
|
| 49 |
HRESULT Receive(IMediaSample *pSample); |
| 50 |
|
| 51 |
// do something with these media samples |
| 52 |
HRESULT ReceiveMultiple ( |
| 53 |
__in_ecount(nSamples) IMediaSample **pSamples, |
| 54 |
long nSamples, |
| 55 |
__out long *nSamplesProcessed); |
| 56 |
|
| 57 |
void Reset(); // Reset m_hr ready for more data |
| 58 |
|
| 59 |
// See if its idle or not |
| 60 |
BOOL IsIdle(); |
| 61 |
|
| 62 |
// give the class an event to fire after everything removed from the queue |
| 63 |
void SetPopEvent(HANDLE hEvent); |
| 64 |
|
| 65 |
protected: |
| 66 |
static DWORD WINAPI InitialThreadProc(__in LPVOID pv); |
| 67 |
DWORD ThreadProc(); |
| 68 |
BOOL IsQueued() |
| 69 |
{ |
| 70 |
return m_List != NULL; |
| 71 |
}; |
| 72 |
|
| 73 |
// The critical section MUST be held when this is called |
| 74 |
void QueueSample(IMediaSample *pSample); |
| 75 |
|
| 76 |
BOOL IsSpecialSample(IMediaSample *pSample) |
| 77 |
{ |
| 78 |
return (DWORD_PTR)pSample > (DWORD_PTR)(LONG_PTR)(-16); |
| 79 |
}; |
| 80 |
|
| 81 |
// Remove and Release() batched and queued samples |
| 82 |
void FreeSamples(); |
| 83 |
|
| 84 |
// Notify the thread there is something to do |
| 85 |
void NotifyThread(); |
| 86 |
|
| 87 |
|
| 88 |
protected: |
| 89 |
// Queue 'messages' |
| 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 |
| 94 |
|
| 95 |
// new segment packet is always followed by one of these |
| 96 |
struct NewSegmentPacket { |
| 97 |
REFERENCE_TIME tStart; |
| 98 |
REFERENCE_TIME tStop; |
| 99 |
double dRate; |
| 100 |
}; |
| 101 |
|
| 102 |
// Remember input stuff |
| 103 |
IPin * const m_pPin; |
| 104 |
IMemInputPin * m_pInputPin; |
| 105 |
BOOL const m_bBatchExact; |
| 106 |
LONG const m_lBatchSize; |
| 107 |
|
| 108 |
CSampleList * m_List; |
| 109 |
HANDLE m_hSem; |
| 110 |
CAMEvent m_evFlushComplete; |
| 111 |
HANDLE m_hThread; |
| 112 |
__field_ecount_opt(m_lBatchSize) IMediaSample ** m_ppSamples; |
| 113 |
__range(0, m_lBatchSize) LONG m_nBatched; |
| 114 |
|
| 115 |
// Wait optimization |
| 116 |
LONG m_lWaiting; |
| 117 |
// Flush synchronization |
| 118 |
BOOL m_bFlushing; |
| 119 |
|
| 120 |
// flushing optimization. some downstream filters have trouble |
| 121 |
// with the queue's flushing optimization. other rely on it |
| 122 |
BOOL m_bFlushed; |
| 123 |
bool m_bFlushingOpt; |
| 124 |
|
| 125 |
// Terminate now |
| 126 |
BOOL m_bTerminate; |
| 127 |
|
| 128 |
// Send anyway flag for batching |
| 129 |
BOOL m_bSendAnyway; |
| 130 |
|
| 131 |
// Deferred 'return code' |
| 132 |
HRESULT volatile m_hr; |
| 133 |
|
| 134 |
// an event that can be fired after every deliver |
| 135 |
HANDLE m_hEventPop; |
| 136 |
}; |
| 137 |
|