dshow_filter.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #define NO_DSHOW_STRSAFE
  22. #include "dshow_capture.h"
  23. DECLARE_QUERYINTERFACE(libAVFilter,
  24. { {&IID_IUnknown,0}, {&IID_IBaseFilter,0} })
  25. DECLARE_ADDREF(libAVFilter)
  26. DECLARE_RELEASE(libAVFilter)
  27. long WINAPI
  28. libAVFilter_GetClassID(libAVFilter *this, CLSID *id)
  29. {
  30. dshowdebug("libAVFilter_GetClassID(%p)\n", this);
  31. /* I'm not creating a ClassID just for this. */
  32. return E_FAIL;
  33. }
  34. long WINAPI
  35. libAVFilter_Stop(libAVFilter *this)
  36. {
  37. dshowdebug("libAVFilter_Stop(%p)\n", this);
  38. this->state = State_Stopped;
  39. return S_OK;
  40. }
  41. long WINAPI
  42. libAVFilter_Pause(libAVFilter *this)
  43. {
  44. dshowdebug("libAVFilter_Pause(%p)\n", this);
  45. this->state = State_Paused;
  46. return S_OK;
  47. }
  48. long WINAPI
  49. libAVFilter_Run(libAVFilter *this, REFERENCE_TIME start)
  50. {
  51. dshowdebug("libAVFilter_Run(%p) %"PRId64"\n", this, start);
  52. this->state = State_Running;
  53. this->start_time = start;
  54. return S_OK;
  55. }
  56. long WINAPI
  57. libAVFilter_GetState(libAVFilter *this, DWORD ms, FILTER_STATE *state)
  58. {
  59. dshowdebug("libAVFilter_GetState(%p)\n", this);
  60. if (!state)
  61. return E_POINTER;
  62. *state = this->state;
  63. return S_OK;
  64. }
  65. long WINAPI
  66. libAVFilter_SetSyncSource(libAVFilter *this, IReferenceClock *clock)
  67. {
  68. dshowdebug("libAVFilter_SetSyncSource(%p)\n", this);
  69. if (this->clock != clock) {
  70. if (this->clock)
  71. IReferenceClock_Release(this->clock);
  72. this->clock = clock;
  73. if (clock)
  74. IReferenceClock_AddRef(clock);
  75. }
  76. return S_OK;
  77. }
  78. long WINAPI
  79. libAVFilter_GetSyncSource(libAVFilter *this, IReferenceClock **clock)
  80. {
  81. dshowdebug("libAVFilter_GetSyncSource(%p)\n", this);
  82. if (!clock)
  83. return E_POINTER;
  84. if (this->clock)
  85. IReferenceClock_AddRef(this->clock);
  86. *clock = this->clock;
  87. return S_OK;
  88. }
  89. long WINAPI
  90. libAVFilter_EnumPins(libAVFilter *this, IEnumPins **enumpin)
  91. {
  92. libAVEnumPins *new;
  93. dshowdebug("libAVFilter_EnumPins(%p)\n", this);
  94. if (!enumpin)
  95. return E_POINTER;
  96. new = libAVEnumPins_Create(this->pin, this);
  97. if (!new)
  98. return E_OUTOFMEMORY;
  99. *enumpin = (IEnumPins *) new;
  100. return S_OK;
  101. }
  102. long WINAPI
  103. libAVFilter_FindPin(libAVFilter *this, const wchar_t *id, IPin **pin)
  104. {
  105. libAVPin *found = NULL;
  106. dshowdebug("libAVFilter_FindPin(%p)\n", this);
  107. if (!id || !pin)
  108. return E_POINTER;
  109. if (!wcscmp(id, L"In")) {
  110. found = this->pin;
  111. libAVPin_AddRef(found);
  112. }
  113. *pin = (IPin *) found;
  114. if (!found)
  115. return VFW_E_NOT_FOUND;
  116. return S_OK;
  117. }
  118. long WINAPI
  119. libAVFilter_QueryFilterInfo(libAVFilter *this, FILTER_INFO *info)
  120. {
  121. dshowdebug("libAVFilter_QueryFilterInfo(%p)\n", this);
  122. if (!info)
  123. return E_POINTER;
  124. if (this->info.pGraph)
  125. IFilterGraph_AddRef(this->info.pGraph);
  126. *info = this->info;
  127. return S_OK;
  128. }
  129. long WINAPI
  130. libAVFilter_JoinFilterGraph(libAVFilter *this, IFilterGraph *graph,
  131. const wchar_t *name)
  132. {
  133. dshowdebug("libAVFilter_JoinFilterGraph(%p)\n", this);
  134. this->info.pGraph = graph;
  135. if (name)
  136. wcscpy(this->info.achName, name);
  137. return S_OK;
  138. }
  139. long WINAPI
  140. libAVFilter_QueryVendorInfo(libAVFilter *this, wchar_t **info)
  141. {
  142. dshowdebug("libAVFilter_QueryVendorInfo(%p)\n", this);
  143. if (!info)
  144. return E_POINTER;
  145. *info = wcsdup(L"libAV");
  146. return S_OK;
  147. }
  148. static int
  149. libAVFilter_Setup(libAVFilter *this, void *priv_data, void *callback,
  150. enum dshowDeviceType type)
  151. {
  152. IBaseFilterVtbl *vtbl = this->vtbl;
  153. SETVTBL(vtbl, libAVFilter, QueryInterface);
  154. SETVTBL(vtbl, libAVFilter, AddRef);
  155. SETVTBL(vtbl, libAVFilter, Release);
  156. SETVTBL(vtbl, libAVFilter, GetClassID);
  157. SETVTBL(vtbl, libAVFilter, Stop);
  158. SETVTBL(vtbl, libAVFilter, Pause);
  159. SETVTBL(vtbl, libAVFilter, Run);
  160. SETVTBL(vtbl, libAVFilter, GetState);
  161. SETVTBL(vtbl, libAVFilter, SetSyncSource);
  162. SETVTBL(vtbl, libAVFilter, GetSyncSource);
  163. SETVTBL(vtbl, libAVFilter, EnumPins);
  164. SETVTBL(vtbl, libAVFilter, FindPin);
  165. SETVTBL(vtbl, libAVFilter, QueryFilterInfo);
  166. SETVTBL(vtbl, libAVFilter, JoinFilterGraph);
  167. SETVTBL(vtbl, libAVFilter, QueryVendorInfo);
  168. this->pin = libAVPin_Create(this);
  169. this->priv_data = priv_data;
  170. this->callback = callback;
  171. this->type = type;
  172. return 1;
  173. }
  174. static int
  175. libAVFilter_Cleanup(libAVFilter *this)
  176. {
  177. libAVPin_Release(this->pin);
  178. return 1;
  179. }
  180. DECLARE_CREATE(libAVFilter, libAVFilter_Setup(this, priv_data, callback, type),
  181. void *priv_data, void *callback, enum dshowDeviceType type)
  182. DECLARE_DESTROY(libAVFilter, libAVFilter_Cleanup)