DSFrameRateFilter.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright (C) 2011-2013 Doubango Telecom <http://www.doubango.org>
  2. *
  3. * This file is part of Open Source Doubango Framework.
  4. *
  5. * DOUBANGO is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * DOUBANGO is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with DOUBANGO.
  17. */
  18. #include "internals/DSFrameRateFilter.h"
  19. #include <iostream>
  20. #include <string>
  21. using namespace std;
  22. #define FPS_INPUT 30
  23. #define FPS_OUTPUT 5
  24. // {7F9F08CF-139F-40b2-A283-01C4EC26A452}
  25. TDSHOW_DEFINE_GUID(CLSID_DSFrameRateFilter,
  26. 0x7f9f08cf, 0x139f, 0x40b2, 0xa2, 0x83, 0x1, 0xc4, 0xec, 0x26, 0xa4, 0x52);
  27. DSFrameRateFilter::DSFrameRateFilter(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr)
  28. :CTransInPlaceFilter (tszName, punk, CLSID_DSFrameRateFilter, phr)
  29. {
  30. this->m_rtFrameLength = (10000000)/FPS_OUTPUT;
  31. this->m_inputFps = FPS_INPUT;
  32. this->m_outputFps = FPS_OUTPUT;
  33. this->m_iFrameNumber = 0;
  34. this->m_progress = 0;
  35. this->m_bProcessFrame = true;
  36. }
  37. DSFrameRateFilter::~DSFrameRateFilter()
  38. {
  39. }
  40. HRESULT DSFrameRateFilter::SetFps(int inputFps, int outputFps)
  41. {
  42. if(inputFps <= 0 || outputFps <= 0) {
  43. return E_FAIL;
  44. }
  45. // Stop prcessing
  46. this->m_bProcessFrame = false;
  47. if (inputFps < outputFps) {
  48. this->m_inputFps = this->m_outputFps = inputFps;
  49. }
  50. else {
  51. this->m_outputFps = outputFps;
  52. this->m_inputFps = inputFps;
  53. }
  54. // Restart processing
  55. this->m_iFrameNumber = 0;
  56. this->m_progress = 0;
  57. this->m_bProcessFrame = true;
  58. return S_OK;
  59. }
  60. HRESULT DSFrameRateFilter::Transform(IMediaSample *pSample)
  61. {
  62. if(!this->m_bProcessFrame) {
  63. return S_FALSE;
  64. }
  65. CheckPointer(pSample, E_POINTER);
  66. HRESULT hr = S_OK;
  67. HRESULT ret = S_FALSE;
  68. pSample->SetTime(NULL, NULL);
  69. // Drop frame?
  70. if (this->m_iFrameNumber == 0) {
  71. ret = S_OK;
  72. }
  73. else if (this->m_progress >= this->m_inputFps) {
  74. this->m_progress -= this->m_inputFps;
  75. ret = S_OK;
  76. }
  77. // Mark frame as accepted
  78. if (ret == S_OK) {
  79. // Set TRUE on every sample for uncompressed frames
  80. pSample->SetSyncPoint(TRUE);
  81. }
  82. this->m_progress += this->m_outputFps;
  83. this->m_iFrameNumber++;
  84. return ret;
  85. }
  86. HRESULT DSFrameRateFilter::CheckInputType(const CMediaType* mtIn)
  87. {
  88. return S_OK;
  89. }
  90. //Implement CreateInstance for your filter object. Typically, CreateInstance calls the constructor of your filter clas
  91. CUnknown * WINAPI DSFrameRateFilter::CreateInstance(LPUNKNOWN punk, HRESULT *phr)
  92. {
  93. DSFrameRateFilter *pNewObject = new DSFrameRateFilter(_T("Tdshow DirectShow Framerate Limiter Filter."), punk, phr );
  94. if (pNewObject == NULL) {
  95. *phr = E_OUTOFMEMORY;
  96. }
  97. return pNewObject;
  98. }