/indra/media_plugins/gstreamer010/llmediaimplgstreamer_syms.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 167 lines · 106 code · 28 blank · 33 comment · 14 complexity · f69b504fa1a79e14f1e9b5a4fc8a5c95 MD5 · raw file

  1. /**
  2. * @file llmediaimplgstreamer_syms.cpp
  3. * @brief dynamic GStreamer symbol-grabbing code
  4. *
  5. * @cond
  6. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. * @endcond
  27. */
  28. #if LL_GSTREAMER010_ENABLED
  29. #include <string>
  30. extern "C" {
  31. #include <gst/gst.h>
  32. #include "apr_pools.h"
  33. #include "apr_dso.h"
  34. }
  35. #include "llmediaimplgstreamertriviallogging.h"
  36. #define LL_GST_SYM(REQ, GSTSYM, RTN, ...) RTN (*ll##GSTSYM)(__VA_ARGS__) = NULL
  37. #include "llmediaimplgstreamer_syms_raw.inc"
  38. #include "llmediaimplgstreamer_syms_rawv.inc"
  39. #undef LL_GST_SYM
  40. // a couple of stubs for disgusting reasons
  41. GstDebugCategory*
  42. ll_gst_debug_category_new(gchar *name, guint color, gchar *description)
  43. {
  44. static GstDebugCategory dummy;
  45. return &dummy;
  46. }
  47. void ll_gst_debug_register_funcptr(GstDebugFuncPtr func, gchar* ptrname)
  48. {
  49. }
  50. static bool sSymsGrabbed = false;
  51. static apr_pool_t *sSymGSTDSOMemoryPool = NULL;
  52. static apr_dso_handle_t *sSymGSTDSOHandleG = NULL;
  53. static apr_dso_handle_t *sSymGSTDSOHandleV = NULL;
  54. bool grab_gst_syms(std::string gst_dso_name,
  55. std::string gst_dso_name_vid)
  56. {
  57. if (sSymsGrabbed)
  58. {
  59. // already have grabbed good syms
  60. return TRUE;
  61. }
  62. bool sym_error = false;
  63. bool rtn = false;
  64. apr_status_t rv;
  65. apr_dso_handle_t *sSymGSTDSOHandle = NULL;
  66. #define LL_GST_SYM(REQ, GSTSYM, RTN, ...) do{rv = apr_dso_sym((apr_dso_handle_sym_t*)&ll##GSTSYM, sSymGSTDSOHandle, #GSTSYM); if (rv != APR_SUCCESS) {INFOMSG("Failed to grab symbol: %s", #GSTSYM); if (REQ) sym_error = true;} else DEBUGMSG("grabbed symbol: %s from %p", #GSTSYM, (void*)ll##GSTSYM);}while(0)
  67. //attempt to load the shared libraries
  68. apr_pool_create(&sSymGSTDSOMemoryPool, NULL);
  69. if ( APR_SUCCESS == (rv = apr_dso_load(&sSymGSTDSOHandle,
  70. gst_dso_name.c_str(),
  71. sSymGSTDSOMemoryPool) ))
  72. {
  73. INFOMSG("Found DSO: %s", gst_dso_name.c_str());
  74. #include "llmediaimplgstreamer_syms_raw.inc"
  75. if ( sSymGSTDSOHandle )
  76. {
  77. sSymGSTDSOHandleG = sSymGSTDSOHandle;
  78. sSymGSTDSOHandle = NULL;
  79. }
  80. if ( APR_SUCCESS ==
  81. (rv = apr_dso_load(&sSymGSTDSOHandle,
  82. gst_dso_name_vid.c_str(),
  83. sSymGSTDSOMemoryPool) ))
  84. {
  85. INFOMSG("Found DSO: %s", gst_dso_name_vid.c_str());
  86. #include "llmediaimplgstreamer_syms_rawv.inc"
  87. rtn = !sym_error;
  88. }
  89. else
  90. {
  91. INFOMSG("Couldn't load DSO: %s", gst_dso_name_vid.c_str());
  92. rtn = false; // failure
  93. }
  94. }
  95. else
  96. {
  97. INFOMSG("Couldn't load DSO: %s", gst_dso_name.c_str());
  98. rtn = false; // failure
  99. }
  100. if (sym_error)
  101. {
  102. WARNMSG("Failed to find necessary symbols in GStreamer libraries.");
  103. }
  104. if ( sSymGSTDSOHandle )
  105. {
  106. sSymGSTDSOHandleV = sSymGSTDSOHandle;
  107. sSymGSTDSOHandle = NULL;
  108. }
  109. #undef LL_GST_SYM
  110. sSymsGrabbed = !!rtn;
  111. return rtn;
  112. }
  113. void ungrab_gst_syms()
  114. {
  115. // should be safe to call regardless of whether we've
  116. // actually grabbed syms.
  117. if ( sSymGSTDSOHandleG )
  118. {
  119. apr_dso_unload(sSymGSTDSOHandleG);
  120. sSymGSTDSOHandleG = NULL;
  121. }
  122. if ( sSymGSTDSOHandleV )
  123. {
  124. apr_dso_unload(sSymGSTDSOHandleV);
  125. sSymGSTDSOHandleV = NULL;
  126. }
  127. if ( sSymGSTDSOMemoryPool )
  128. {
  129. apr_pool_destroy(sSymGSTDSOMemoryPool);
  130. sSymGSTDSOMemoryPool = NULL;
  131. }
  132. // NULL-out all of the symbols we'd grabbed
  133. #define LL_GST_SYM(REQ, GSTSYM, RTN, ...) do{ll##GSTSYM = NULL;}while(0)
  134. #include "llmediaimplgstreamer_syms_raw.inc"
  135. #include "llmediaimplgstreamer_syms_rawv.inc"
  136. #undef LL_GST_SYM
  137. sSymsGrabbed = false;
  138. }
  139. #endif // LL_GSTREAMER010_ENABLED