outputq.h 4.5 KB

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