dshow_filter.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * DirectShow capture interface
  3. * Copyright (c) 2010 Ramiro Polla
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "dshow_capture.h"
  22. DECLARE_QUERYINTERFACE(filter, DShowFilter,
  23. { {&IID_IUnknown,0}, {&IID_IBaseFilter,0} })
  24. DECLARE_ADDREF(filter, DShowFilter)
  25. DECLARE_RELEASE(filter, DShowFilter)
  26. long WINAPI ff_dshow_filter_GetClassID(DShowFilter *this, CLSID *id)
  27. {
  28. dshowdebug("ff_dshow_filter_GetClassID(%p)\n", this);
  29. /* I'm not creating a ClassID just for this. */
  30. return E_FAIL;
  31. }
  32. long WINAPI ff_dshow_filter_Stop(DShowFilter *this)
  33. {
  34. dshowdebug("ff_dshow_filter_Stop(%p)\n", this);
  35. this->state = State_Stopped;
  36. return S_OK;
  37. }
  38. long WINAPI ff_dshow_filter_Pause(DShowFilter *this)
  39. {
  40. dshowdebug("ff_dshow_filter_Pause(%p)\n", this);
  41. this->state = State_Paused;
  42. return S_OK;
  43. }
  44. long WINAPI ff_dshow_filter_Run(DShowFilter *this, REFERENCE_TIME start)
  45. {
  46. dshowdebug("ff_dshow_filter_Run(%p) %"PRId64"\n", this, start);
  47. this->state = State_Running;
  48. this->start_time = start;
  49. return S_OK;
  50. }
  51. long WINAPI ff_dshow_filter_GetState(DShowFilter *this, DWORD ms, FILTER_STATE *state)
  52. {
  53. dshowdebug("ff_dshow_filter_GetState(%p)\n", this);
  54. if (!state)
  55. return E_POINTER;
  56. *state = this->state;
  57. return S_OK;
  58. }
  59. long WINAPI ff_dshow_filter_SetSyncSource(DShowFilter *this, IReferenceClock *clock)
  60. {
  61. dshowdebug("ff_dshow_filter_SetSyncSource(%p)\n", this);
  62. if (this->clock != clock) {
  63. if (this->clock)
  64. IReferenceClock_Release(this->clock);
  65. this->clock = clock;
  66. if (clock)
  67. IReferenceClock_AddRef(clock);
  68. }
  69. return S_OK;
  70. }
  71. long WINAPI ff_dshow_filter_GetSyncSource(DShowFilter *this, IReferenceClock **clock)
  72. {
  73. dshowdebug("ff_dshow_filter_GetSyncSource(%p)\n", this);
  74. if (!clock)
  75. return E_POINTER;
  76. if (this->clock)
  77. IReferenceClock_AddRef(this->clock);
  78. *clock = this->clock;
  79. return S_OK;
  80. }
  81. long WINAPI ff_dshow_filter_EnumPins(DShowFilter *this, IEnumPins **enumpin)
  82. {
  83. DShowEnumPins *new;
  84. dshowdebug("ff_dshow_filter_EnumPins(%p)\n", this);
  85. if (!enumpin)
  86. return E_POINTER;
  87. new = ff_dshow_enumpins_Create(this->pin, this);
  88. if (!new)
  89. return E_OUTOFMEMORY;
  90. *enumpin = (IEnumPins *) new;
  91. return S_OK;
  92. }
  93. long WINAPI ff_dshow_filter_FindPin(DShowFilter *this, const wchar_t *id, IPin **pin)
  94. {
  95. DShowPin *found = NULL;
  96. dshowdebug("ff_dshow_filter_FindPin(%p)\n", this);
  97. if (!id || !pin)
  98. return E_POINTER;
  99. if (!wcscmp(id, L"In")) {
  100. found = this->pin;
  101. ff_dshow_pin_AddRef(found);
  102. }
  103. *pin = (IPin *) found;
  104. if (!found)
  105. return VFW_E_NOT_FOUND;
  106. return S_OK;
  107. }
  108. long WINAPI ff_dshow_filter_QueryFilterInfo(DShowFilter *this, FILTER_INFO *info)
  109. {
  110. dshowdebug("ff_dshow_filter_QueryFilterInfo(%p)\n", this);
  111. if (!info)
  112. return E_POINTER;
  113. if (this->info.pGraph)
  114. IFilterGraph_AddRef(this->info.pGraph);
  115. *info = this->info;
  116. return S_OK;
  117. }
  118. long WINAPI ff_dshow_filter_JoinFilterGraph(DShowFilter *this, IFilterGraph *graph,
  119. const wchar_t *name)
  120. {
  121. dshowdebug("ff_dshow_filter_JoinFilterGraph(%p)\n", this);
  122. this->info.pGraph = graph;
  123. if (name)
  124. wcscpy_s(this->info.achName, sizeof(this->info.achName) / sizeof(wchar_t), name);
  125. return S_OK;
  126. }
  127. long WINAPI ff_dshow_filter_QueryVendorInfo(DShowFilter *this, wchar_t **info)
  128. {
  129. dshowdebug("ff_dshow_filter_QueryVendorInfo(%p)\n", this);
  130. if (!info)
  131. return E_POINTER;
  132. return E_NOTIMPL; /* don't have to do anything here */
  133. }
  134. static int
  135. ff_dshow_filter_Setup(DShowFilter *this, void *priv_data, void *callback,
  136. enum dshowDeviceType type)
  137. {
  138. IBaseFilterVtbl *vtbl = this->vtbl;
  139. SETVTBL(vtbl, filter, QueryInterface);
  140. SETVTBL(vtbl, filter, AddRef);
  141. SETVTBL(vtbl, filter, Release);
  142. SETVTBL(vtbl, filter, GetClassID);
  143. SETVTBL(vtbl, filter, Stop);
  144. SETVTBL(vtbl, filter, Pause);
  145. SETVTBL(vtbl, filter, Run);
  146. SETVTBL(vtbl, filter, GetState);
  147. SETVTBL(vtbl, filter, SetSyncSource);
  148. SETVTBL(vtbl, filter, GetSyncSource);
  149. SETVTBL(vtbl, filter, EnumPins);
  150. SETVTBL(vtbl, filter, FindPin);
  151. SETVTBL(vtbl, filter, QueryFilterInfo);
  152. SETVTBL(vtbl, filter, JoinFilterGraph);
  153. SETVTBL(vtbl, filter, QueryVendorInfo);
  154. this->pin = ff_dshow_pin_Create(this);
  155. this->priv_data = priv_data;
  156. this->callback = callback;
  157. this->type = type;
  158. return 1;
  159. }
  160. static int ff_dshow_filter_Cleanup(DShowFilter *this)
  161. {
  162. ff_dshow_pin_Release(this->pin);
  163. return 1;
  164. }
  165. DECLARE_CREATE(filter, DShowFilter, ff_dshow_filter_Setup(this, priv_data, callback, type),
  166. void *priv_data, void *callback, enum dshowDeviceType type)
  167. DECLARE_DESTROY(filter, DShowFilter, ff_dshow_filter_Cleanup)