1
0

CWAVideoRenderer.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "CWAVideoRenderer.h"
  2. #include "Main.h"
  3. char *toChar(const GUID &guid, char *target)
  4. {
  5. // {1B3CA60C-DA98-4826-B4A9-D79748A5FD73}
  6. StringCchPrintfA(target, 39, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  7. (int)guid.Data1, (int)guid.Data2, (int)guid.Data3,
  8. (int)guid.Data4[0], (int)guid.Data4[1],
  9. (int)guid.Data4[2], (int)guid.Data4[3],
  10. (int)guid.Data4[4], (int)guid.Data4[5],
  11. (int)guid.Data4[6], (int)guid.Data4[7] );
  12. return target;
  13. }
  14. CWAVideoRenderer::CWAVideoRenderer()
  15. : CBaseRenderer(CLSID_WAVideoRend, TEXT("WAVideoRenderer"), NULL, NULL)
  16. {
  17. m_callback = NULL;
  18. m_reent = 0;
  19. }
  20. CWAVideoRenderer::~CWAVideoRenderer()
  21. {
  22. delete m_callback;
  23. }
  24. HRESULT CWAVideoRenderer::DoRenderSample(IMediaSample *pMediaSample)
  25. {
  26. if (m_callback)
  27. {
  28. REFERENCE_TIME StartTime, StopTime;
  29. pMediaSample->GetTime( &StartTime, &StopTime);
  30. StartTime += m_pInputPin->CurrentStartTime( );
  31. StopTime += m_pInputPin->CurrentStartTime( );
  32. m_callback->sample_cb(StartTime, StopTime, pMediaSample);
  33. }
  34. return NOERROR;
  35. }
  36. HRESULT CWAVideoRenderer::CheckMediaType(const CMediaType *pmt)
  37. {
  38. if (pmt->majortype != MEDIATYPE_Video) return E_INVALIDARG;
  39. if (pmt->formattype != FORMAT_VideoInfo && pmt->formattype != FORMAT_VideoInfo2) return E_INVALIDARG;
  40. #if 0
  41. {
  42. char blah[512] = {0};
  43. toChar(pmt->subtype, blah);
  44. OutputDebugString(blah);
  45. }
  46. #endif
  47. if (pmt->subtype != MEDIASUBTYPE_YUY2 &&
  48. pmt->subtype != MEDIASUBTYPE_YV12 &&
  49. pmt->subtype != MEDIASUBTYPE_RGB32 &&
  50. pmt->subtype != MEDIASUBTYPE_RGB24 &&
  51. pmt->subtype != MEDIASUBTYPE_RGB8 /* &&
  52. pmt->subtype!=MEDIASUBTYPE_YVYU*/) return E_INVALIDARG;
  53. return NOERROR;
  54. }
  55. HRESULT CWAVideoRenderer::SetMediaType(const CMediaType *pmt)
  56. {
  57. m_mt = *pmt;
  58. //fix for upside down videos
  59. if (!m_reent && (pmt->subtype == MEDIASUBTYPE_YUY2 || pmt->subtype == MEDIASUBTYPE_YV12) )
  60. {
  61. m_reent = 1;
  62. IPin *p = m_pInputPin->GetConnected();
  63. p->Disconnect();
  64. m_pInputPin->Disconnect();
  65. if (pmt->formattype == FORMAT_VideoInfo)
  66. {
  67. VIDEOINFOHEADER *pHeader = (VIDEOINFOHEADER*)pmt->pbFormat;
  68. pHeader->bmiHeader.biHeight = -pHeader->bmiHeader.biHeight;
  69. }
  70. else
  71. {
  72. VIDEOINFOHEADER2 *pHeader = (VIDEOINFOHEADER2*)pmt->pbFormat;
  73. pHeader->bmiHeader.biHeight = -pHeader->bmiHeader.biHeight;
  74. }
  75. if (p->Connect(m_pInputPin, pmt))
  76. {
  77. //oops it failed (like with MJPEG decompressor) so lets get it back to normal
  78. if (pmt->formattype == FORMAT_VideoInfo)
  79. {
  80. VIDEOINFOHEADER *pHeader = (VIDEOINFOHEADER*)pmt->pbFormat;
  81. pHeader->bmiHeader.biHeight = -pHeader->bmiHeader.biHeight;
  82. }
  83. else
  84. {
  85. VIDEOINFOHEADER2 *pHeader = (VIDEOINFOHEADER2*)pmt->pbFormat;
  86. pHeader->bmiHeader.biHeight = -pHeader->bmiHeader.biHeight;
  87. }
  88. p->Connect(m_pInputPin, pmt);
  89. }
  90. m_reent = 0;
  91. }
  92. return NOERROR;
  93. }
  94. // GUID GetAcceptedType() {
  95. CMediaType *CWAVideoRenderer::GetAcceptedType()
  96. {
  97. return &m_mt;
  98. // return m_mt.subtype;
  99. }
  100. HRESULT CWAVideoRenderer::SetCallback(CSampleCB *Callback)
  101. {
  102. m_callback = Callback;
  103. return NOERROR;
  104. }
  105. HRESULT CWAVideoRenderer::ShouldDrawSampleNow(IMediaSample *pMediaSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime)
  106. {
  107. return S_OK;
  108. }
  109. HRESULT CWAVideoRenderer::GetSampleTimes(IMediaSample *pMediaSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime)
  110. {
  111. return S_OK;
  112. }
  113. HRESULT CWAVideoRenderer::EndOfStream(void)
  114. {
  115. if (m_callback)
  116. m_callback->endofstream();
  117. return CBaseRenderer::EndOfStream();
  118. }