dllmain_cuda.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_cuda_config.h"
  20. #include "plugin_cuda_utils.h"
  21. #include "tinymedia/tmedia_codec.h"
  22. #include "tsk_plugin.h"
  23. #include "tsk_debug.h"
  24. #include <windows.h>
  25. #if defined(_MSC_VER)
  26. # pragma comment(lib, "nvcuvenc")
  27. # pragma comment(lib, "nvcuvid")
  28. # pragma comment(lib, "cuda")
  29. # pragma comment(lib, "cudart")
  30. # pragma comment(lib, "d3d9")
  31. # pragma comment(lib, "d3dx9")
  32. #endif
  33. #if !defined(PLUGIN_CUDA_H264_ENABLE)
  34. # define PLUGIN_CUDA_H264_ENABLE 1
  35. #endif
  36. extern const tmedia_codec_plugin_def_t *cuda_codec_h264_main_plugin_def_t;
  37. extern const tmedia_codec_plugin_def_t *cuda_codec_h264_base_plugin_def_t;
  38. PLUGIN_CUDA_BEGIN_DECLS /* BEGIN */
  39. PLUGIN_CUDA_API int __plugin_get_def_count();
  40. PLUGIN_CUDA_API tsk_plugin_def_type_t __plugin_get_def_type_at(int index);
  41. PLUGIN_CUDA_API tsk_plugin_def_media_type_t __plugin_get_def_media_type_at(int index);
  42. PLUGIN_CUDA_API tsk_plugin_def_ptr_const_t __plugin_get_def_at(int index);
  43. PLUGIN_CUDA_END_DECLS /* END */
  44. BOOL APIENTRY DllMain( HMODULE hModule,
  45. DWORD ul_reason_for_call,
  46. LPVOID lpReserved
  47. )
  48. {
  49. switch (ul_reason_for_call) {
  50. case DLL_PROCESS_ATTACH:
  51. break;
  52. case DLL_THREAD_ATTACH:
  53. break;
  54. case DLL_THREAD_DETACH:
  55. break;
  56. case DLL_PROCESS_DETACH:
  57. break;
  58. }
  59. return TRUE;
  60. }
  61. typedef enum PLUGIN_INDEX_E {
  62. #if PLUGIN_CUDA_H264_ENABLE
  63. PLUGIN_INDEX_CODEC_H264_MAIN,
  64. PLUGIN_INDEX_CODEC_H264_BASE,
  65. #endif
  66. PLUGIN_INDEX_COUNT
  67. }
  68. PLUGIN_INDEX_T;
  69. int __plugin_get_def_count()
  70. {
  71. return CudaUtils::IsH264Supported() ? PLUGIN_INDEX_COUNT : 0;
  72. }
  73. tsk_plugin_def_type_t __plugin_get_def_type_at(int index)
  74. {
  75. #if PLUGIN_CUDA_H264_ENABLE
  76. switch(index) {
  77. case PLUGIN_INDEX_CODEC_H264_MAIN:
  78. case PLUGIN_INDEX_CODEC_H264_BASE: {
  79. return CudaUtils::IsH264Supported() ? tsk_plugin_def_type_codec : tsk_plugin_def_type_none;
  80. }
  81. }
  82. #endif
  83. TSK_DEBUG_ERROR("No plugin at index %d", index);
  84. return tsk_plugin_def_type_none;
  85. }
  86. tsk_plugin_def_media_type_t __plugin_get_def_media_type_at(int index)
  87. {
  88. #if PLUGIN_CUDA_H264_ENABLE
  89. switch(index) {
  90. case PLUGIN_INDEX_CODEC_H264_MAIN:
  91. case PLUGIN_INDEX_CODEC_H264_BASE: {
  92. return CudaUtils::IsH264Supported() ? tsk_plugin_def_media_type_video : tsk_plugin_def_media_type_none;
  93. }
  94. }
  95. #endif
  96. TSK_DEBUG_ERROR("No plugin at index %d", index);
  97. return tsk_plugin_def_media_type_none;
  98. }
  99. tsk_plugin_def_ptr_const_t __plugin_get_def_at(int index)
  100. {
  101. #if PLUGIN_CUDA_H264_ENABLE
  102. switch(index) {
  103. case PLUGIN_INDEX_CODEC_H264_MAIN: {
  104. return CudaUtils::IsH264Supported() ? cuda_codec_h264_main_plugin_def_t : tsk_null;
  105. }
  106. case PLUGIN_INDEX_CODEC_H264_BASE: {
  107. return CudaUtils::IsH264Supported() ? cuda_codec_h264_base_plugin_def_t : tsk_null;
  108. }
  109. }
  110. #endif
  111. TSK_DEBUG_ERROR("No plugin at index %d", index);
  112. return tsk_null;
  113. }