DSOutputFilter.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou DIOP.
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. *
  19. */
  20. #include "internals/DSOutputFilter.h"
  21. #include "internals/DSOutputStream.h"
  22. #include "internals/DSUtils.h"
  23. #include "tsk_memory.h"
  24. DSOutputFilter::DSOutputFilter(LPUNKNOWN pUnk, HRESULT *phr)
  25. : CSource(_T("TDSHOW_OUTPUT"), pUnk, CLSID_TdshowOutputFilter)
  26. {
  27. #if !(defined(_WIN32_WCE) && defined(_DEBUG))
  28. CAutoLock cAutoLock(&m_cStateLock);
  29. #endif
  30. // Add one source stream (output pin)!
  31. this->outputStream = new DSOutputStream(phr, this, _T("Out"));
  32. }
  33. DSOutputFilter::~DSOutputFilter()
  34. {
  35. //SAFE_RELEASE(this->outputStream);
  36. }
  37. void DSOutputFilter::setBuffer(void *pointer, int size)
  38. {
  39. this->outputStream->lockBuffer();
  40. if(pointer && size) {
  41. if(this->outputStream->buffer_size != size) {
  42. if((this->outputStream->buffer = tsk_realloc(this->outputStream->buffer, size))) {
  43. this->outputStream->buffer_size = size;
  44. }
  45. else {
  46. goto done;
  47. }
  48. }
  49. memcpy(this->outputStream->buffer, pointer, size);
  50. }
  51. done:
  52. this->outputStream->unlockBuffer();
  53. }
  54. void DSOutputFilter::getMediaType(AM_MEDIA_TYPE* &pmt)
  55. {
  56. //if(pmt)
  57. //{
  58. // memcpy(pmt, &this->outputStream->pmt, sizeof(AM_MEDIA_TYPE));
  59. //}
  60. }
  61. HRESULT DSOutputFilter::setMediaType(const AM_MEDIA_TYPE* pmt)
  62. {
  63. return this->ReconnectPin(this->outputStream, pmt);
  64. }
  65. HRESULT DSOutputFilter::setImageFormat(UINT width, UINT height)
  66. {
  67. return this->outputStream->setImageFormat(width, height);
  68. }
  69. bool DSOutputFilter::getImageFormat(UINT &width, UINT &height)
  70. {
  71. if(this->outputStream) {
  72. return this->outputStream->getImageFormat(width, height);
  73. }
  74. return false;
  75. }
  76. void DSOutputFilter::setFps(int fps_)
  77. {
  78. this->outputStream->setFps(fps_);
  79. }
  80. void DSOutputFilter::showOverlay(int value)
  81. {
  82. this->outputStream->showOverlay(value);
  83. }
  84. void DSOutputFilter::reset()
  85. {
  86. this->outputStream->frameNumber = 0;
  87. this->outputStream->lockBuffer();
  88. this->outputStream->buffer = NULL;
  89. this->outputStream->buffer_size = 0;
  90. this->outputStream->unlockBuffer();
  91. }
  92. #ifdef _WIN32_WCE
  93. STDMETHODIMP_(ULONG) DSOutputFilter::NonDelegatingRelease()
  94. {
  95. if(InterlockedDecrement(&m_cRef) == 0) {
  96. delete this;
  97. return 0;
  98. }
  99. return m_cRef;
  100. }
  101. #endif