dshow_filter.c 5.2 KB

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