dllmain_mf.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* Copyright (C) 2013 Mamadou DIOP
  2. * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
  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. #include "plugin_win_mf_config.h"
  20. #include "internals/mf_utils.h"
  21. #include "tinymedia/tmedia_producer.h"
  22. #include "tinymedia/tmedia_consumer.h"
  23. #include "tinymedia/tmedia_converter_video.h"
  24. #include "tsk_plugin.h"
  25. #include "tsk_debug.h"
  26. #include <windows.h>
  27. #if defined(_MSC_VER)
  28. # pragma comment(lib, "mfplat")
  29. # pragma comment(lib, "mf")
  30. # pragma comment(lib, "mfuuid")
  31. # pragma comment(lib, "shlwapi")
  32. # pragma comment(lib, "Strmiids")
  33. #endif
  34. #if !defined(PLUGIN_MF_ENABLE_AUDIO_IO)
  35. # define PLUGIN_MF_ENABLE_AUDIO_IO 0 /* audio not good as DirectSound */
  36. #endif
  37. #if !defined(PLUGIN_MF_ENABLE_VIDEO_CONVERTER)
  38. # define PLUGIN_MF_ENABLE_VIDEO_CONVERTER 1
  39. #endif
  40. #if !defined(PLUGIN_MF_ENABLE_VIDEO_IO)
  41. # define PLUGIN_MF_ENABLE_VIDEO_IO 1
  42. #endif
  43. extern const tmedia_codec_plugin_def_t *mf_codec_h264_main_plugin_def_t;
  44. extern const tmedia_codec_plugin_def_t *mf_codec_h264_base_plugin_def_t;
  45. #if PLUGIN_MF_ENABLE_VIDEO_CONVERTER
  46. extern const tmedia_converter_video_plugin_def_t *plugin_win_mf_converter_video_ms_plugin_def_t;
  47. #endif
  48. #if PLUGIN_MF_ENABLE_VIDEO_IO
  49. extern const tmedia_producer_plugin_def_t *plugin_win_mf_producer_video_plugin_def_t;
  50. extern const tmedia_consumer_plugin_def_t *plugin_win_mf_consumer_video_plugin_def_t;
  51. #endif
  52. #if PLUGIN_MF_ENABLE_AUDIO_IO
  53. extern const tmedia_producer_plugin_def_t *plugin_win_mf_producer_audio_plugin_def_t;
  54. extern const tmedia_consumer_plugin_def_t *plugin_win_mf_consumer_audio_plugin_def_t;
  55. #endif
  56. PLUGIN_WIN_MF_BEGIN_DECLS /* BEGIN */
  57. PLUGIN_WIN_MFP_API int __plugin_get_def_count();
  58. PLUGIN_WIN_MFP_API tsk_plugin_def_type_t __plugin_get_def_type_at(int index);
  59. PLUGIN_WIN_MFP_API tsk_plugin_def_media_type_t __plugin_get_def_media_type_at(int index);
  60. PLUGIN_WIN_MFP_API tsk_plugin_def_ptr_const_t __plugin_get_def_at(int index);
  61. PLUGIN_WIN_MF_END_DECLS /* END */
  62. BOOL APIENTRY DllMain( HMODULE hModule,
  63. DWORD ul_reason_for_call,
  64. LPVOID lpReserved
  65. )
  66. {
  67. switch (ul_reason_for_call) {
  68. case DLL_PROCESS_ATTACH:
  69. break;
  70. case DLL_THREAD_ATTACH:
  71. break;
  72. case DLL_THREAD_DETACH:
  73. break;
  74. case DLL_PROCESS_DETACH:
  75. break;
  76. }
  77. return TRUE;
  78. }
  79. typedef enum PLUGIN_INDEX_E {
  80. #if PLUGIN_MF_ENABLE_AUDIO_IO
  81. PLUGIN_INDEX_AUDIO_CONSUMER,
  82. PLUGIN_INDEX_AUDIO_PRODUCER,
  83. #endif
  84. #if PLUGIN_MF_ENABLE_VIDEO_IO
  85. PLUGIN_INDEX_VIDEO_PRODUCER,
  86. PLUGIN_INDEX_VIDEO_CONSUMER,
  87. #endif
  88. #if PLUGIN_MF_ENABLE_VIDEO_CONVERTER
  89. PLUGIN_INDEX_VIDEO_CONVERTER,
  90. #endif
  91. PLUGIN_INDEX_CODEC_H264_MAIN,
  92. PLUGIN_INDEX_CODEC_H264_BASE,
  93. PLUGIN_INDEX_COUNT
  94. }
  95. PLUGIN_INDEX_T;
  96. int __plugin_get_def_count()
  97. {
  98. int count = PLUGIN_INDEX_COUNT;
  99. if(!MFUtils::IsLowLatencyH264Supported()) {
  100. count -= 2;
  101. }
  102. return count;
  103. }
  104. tsk_plugin_def_type_t __plugin_get_def_type_at(int index)
  105. {
  106. switch(index) {
  107. #if PLUGIN_MF_ENABLE_AUDIO_IO
  108. case PLUGIN_INDEX_AUDIO_CONSUMER:
  109. case PLUGIN_INDEX_AUDIO_PRODUCER: {
  110. return (index == PLUGIN_INDEX_AUDIO_CONSUMER) ? tsk_plugin_def_type_consumer : tsk_plugin_def_type_producer;
  111. }
  112. #endif
  113. #if PLUGIN_MF_ENABLE_VIDEO_IO
  114. case PLUGIN_INDEX_VIDEO_CONSUMER: {
  115. return MFUtils::IsD3D9Supported() ? tsk_plugin_def_type_consumer : tsk_plugin_def_type_none;
  116. }
  117. case PLUGIN_INDEX_VIDEO_PRODUCER: {
  118. return tsk_plugin_def_type_producer;
  119. }
  120. #endif
  121. #if PLUGIN_MF_ENABLE_VIDEO_CONVERTER
  122. case PLUGIN_INDEX_VIDEO_CONVERTER: {
  123. return tsk_plugin_def_type_converter;
  124. }
  125. #endif
  126. case PLUGIN_INDEX_CODEC_H264_MAIN:
  127. case PLUGIN_INDEX_CODEC_H264_BASE: {
  128. return MFUtils::IsLowLatencyH264Supported() ? tsk_plugin_def_type_codec : tsk_plugin_def_type_none;
  129. }
  130. default: {
  131. TSK_DEBUG_ERROR("No plugin at index %d", index);
  132. return tsk_plugin_def_type_none;
  133. }
  134. }
  135. }
  136. tsk_plugin_def_media_type_t __plugin_get_def_media_type_at(int index)
  137. {
  138. switch(index) {
  139. #if PLUGIN_MF_ENABLE_AUDIO_IO
  140. case PLUGIN_INDEX_AUDIO_CONSUMER:
  141. case PLUGIN_INDEX_AUDIO_PRODUCER: {
  142. return tsk_plugin_def_media_type_audio;
  143. }
  144. #endif
  145. #if PLUGIN_MF_ENABLE_VIDEO_IO
  146. case PLUGIN_INDEX_VIDEO_CONSUMER: {
  147. return MFUtils::IsD3D9Supported() ? tsk_plugin_def_media_type_video : tsk_plugin_def_media_type_none;
  148. }
  149. case PLUGIN_INDEX_VIDEO_PRODUCER: {
  150. return tsk_plugin_def_media_type_video;
  151. }
  152. #endif
  153. #if PLUGIN_MF_ENABLE_VIDEO_CONVERTER
  154. case PLUGIN_INDEX_VIDEO_CONVERTER: {
  155. return tsk_plugin_def_media_type_video;
  156. }
  157. #endif
  158. case PLUGIN_INDEX_CODEC_H264_MAIN:
  159. case PLUGIN_INDEX_CODEC_H264_BASE: {
  160. return MFUtils::IsLowLatencyH264Supported() ? tsk_plugin_def_media_type_video : tsk_plugin_def_media_type_none;
  161. }
  162. default: {
  163. TSK_DEBUG_ERROR("No plugin at index %d", index);
  164. return tsk_plugin_def_media_type_none;
  165. }
  166. }
  167. }
  168. tsk_plugin_def_ptr_const_t __plugin_get_def_at(int index)
  169. {
  170. switch(index) {
  171. #if PLUGIN_MF_ENABLE_VIDEO_IO
  172. case PLUGIN_INDEX_VIDEO_PRODUCER: {
  173. return plugin_win_mf_producer_video_plugin_def_t;
  174. }
  175. case PLUGIN_INDEX_VIDEO_CONSUMER: {
  176. return MFUtils::IsD3D9Supported() ? plugin_win_mf_consumer_video_plugin_def_t : tsk_null;
  177. }
  178. #endif
  179. #if PLUGIN_MF_ENABLE_AUDIO_IO
  180. case PLUGIN_INDEX_AUDIO_PRODUCER: {
  181. return plugin_win_mf_producer_audio_plugin_def_t;
  182. }
  183. case PLUGIN_INDEX_AUDIO_CONSUMER: {
  184. return plugin_win_mf_consumer_audio_plugin_def_t;
  185. }
  186. #endif
  187. #if PLUGIN_MF_ENABLE_VIDEO_CONVERTER
  188. case PLUGIN_INDEX_VIDEO_CONVERTER: {
  189. return plugin_win_mf_converter_video_ms_plugin_def_t;
  190. }
  191. #endif
  192. case PLUGIN_INDEX_CODEC_H264_MAIN: {
  193. return MFUtils::IsLowLatencyH264Supported() ? mf_codec_h264_main_plugin_def_t : tsk_null;
  194. }
  195. case PLUGIN_INDEX_CODEC_H264_BASE: {
  196. return MFUtils::IsLowLatencyH264Supported() ? mf_codec_h264_base_plugin_def_t : tsk_null;
  197. }
  198. default: {
  199. TSK_DEBUG_ERROR("No plugin at index %d", index);
  200. return tsk_null;
  201. }
  202. }
  203. }