outputq.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. {
  56. return m_List != NULL;
  57. };
  58. // The critical section MUST be held when this is called
  59. void QueueSample(IMediaSample *pSample);
  60. BOOL IsSpecialSample(IMediaSample *pSample)
  61. {
  62. return (DWORD_PTR)pSample > (DWORD_PTR)(LONG_PTR)(-16);
  63. };
  64. // Remove and Release() batched and queued samples
  65. void FreeSamples();
  66. // Notify the thread there is something to do
  67. void NotifyThread();
  68. protected:
  69. // Queue 'messages'
  70. #define SEND_PACKET ((IMediaSample *)(LONG_PTR)(-2)) // Send batch
  71. #define EOS_PACKET ((IMediaSample *)(LONG_PTR)(-3)) // End of stream
  72. #define RESET_PACKET ((IMediaSample *)(LONG_PTR)(-4)) // Reset m_hr
  73. #define NEW_SEGMENT ((IMediaSample *)(LONG_PTR)(-5)) // send NewSegment
  74. // new segment packet is always followed by one of these
  75. struct NewSegmentPacket {
  76. REFERENCE_TIME tStart;
  77. REFERENCE_TIME tStop;
  78. double dRate;
  79. };
  80. // Remember input stuff
  81. IPin * const m_pPin;
  82. IMemInputPin * m_pInputPin;
  83. BOOL const m_bBatchExact;
  84. LONG const m_lBatchSize;
  85. CSampleList * m_List;
  86. HANDLE m_hSem;
  87. CAMEvent m_evFlushComplete;
  88. HANDLE m_hThread;
  89. __field_ecount_opt(m_lBatchSize) IMediaSample ** m_ppSamples;
  90. __range(0, m_lBatchSize) LONG m_nBatched;
  91. // Wait optimization
  92. LONG m_lWaiting;
  93. // Flush synchronization
  94. BOOL m_bFlushing;
  95. // flushing optimization. some downstream filters have trouble
  96. // with the queue's flushing optimization. other rely on it
  97. BOOL m_bFlushed;
  98. bool m_bFlushingOpt;
  99. // Terminate now
  100. BOOL m_bTerminate;
  101. // Send anyway flag for batching
  102. BOOL m_bSendAnyway;
  103. // Deferred 'return code'
  104. HRESULT volatile m_hr;
  105. // an event that can be fired after every deliver
  106. HANDLE m_hEventPop;
  107. };