PageRenderTime 22ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 29#if LL_GSTREAMER010_ENABLED
 30
 31#include <string>
 32
 33extern "C" {
 34#include <gst/gst.h>
 35
 36#include "apr_pools.h"
 37#include "apr_dso.h"
 38}
 39
 40#include "llmediaimplgstreamertriviallogging.h"
 41
 42#define LL_GST_SYM(REQ, GSTSYM, RTN, ...) RTN (*ll##GSTSYM)(__VA_ARGS__) = NULL
 43#include "llmediaimplgstreamer_syms_raw.inc"
 44#include "llmediaimplgstreamer_syms_rawv.inc"
 45#undef LL_GST_SYM
 46
 47// a couple of stubs for disgusting reasons
 48GstDebugCategory*
 49ll_gst_debug_category_new(gchar *name, guint color, gchar *description)
 50{
 51	static GstDebugCategory dummy;
 52	return &dummy;
 53}
 54void ll_gst_debug_register_funcptr(GstDebugFuncPtr func, gchar* ptrname)
 55{
 56}
 57
 58static bool sSymsGrabbed = false;
 59static apr_pool_t *sSymGSTDSOMemoryPool = NULL;
 60static apr_dso_handle_t *sSymGSTDSOHandleG = NULL;
 61static apr_dso_handle_t *sSymGSTDSOHandleV = NULL;
 62
 63
 64bool grab_gst_syms(std::string gst_dso_name,
 65		   std::string gst_dso_name_vid)
 66{
 67	if (sSymsGrabbed)
 68	{
 69		// already have grabbed good syms
 70		return TRUE;
 71	}
 72
 73	bool sym_error = false;
 74	bool rtn = false;
 75	apr_status_t rv;
 76	apr_dso_handle_t *sSymGSTDSOHandle = NULL;
 77
 78#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)
 79
 80	//attempt to load the shared libraries
 81	apr_pool_create(&sSymGSTDSOMemoryPool, NULL);
 82  
 83	if ( APR_SUCCESS == (rv = apr_dso_load(&sSymGSTDSOHandle,
 84					       gst_dso_name.c_str(),
 85					       sSymGSTDSOMemoryPool) ))
 86	{
 87		INFOMSG("Found DSO: %s", gst_dso_name.c_str());
 88#include "llmediaimplgstreamer_syms_raw.inc"
 89      
 90		if ( sSymGSTDSOHandle )
 91		{
 92			sSymGSTDSOHandleG = sSymGSTDSOHandle;
 93			sSymGSTDSOHandle = NULL;
 94		}
 95      
 96		if ( APR_SUCCESS ==
 97		     (rv = apr_dso_load(&sSymGSTDSOHandle,
 98					gst_dso_name_vid.c_str(),
 99					sSymGSTDSOMemoryPool) ))
100		{
101			INFOMSG("Found DSO: %s", gst_dso_name_vid.c_str());
102#include "llmediaimplgstreamer_syms_rawv.inc"
103			rtn = !sym_error;
104		}
105		else
106		{
107			INFOMSG("Couldn't load DSO: %s", gst_dso_name_vid.c_str());
108			rtn = false; // failure
109		}
110	}
111	else
112	{
113		INFOMSG("Couldn't load DSO: %s", gst_dso_name.c_str());
114		rtn = false; // failure
115	}
116
117	if (sym_error)
118	{
119		WARNMSG("Failed to find necessary symbols in GStreamer libraries.");
120	}
121	
122	if ( sSymGSTDSOHandle )
123	{
124		sSymGSTDSOHandleV = sSymGSTDSOHandle;
125		sSymGSTDSOHandle = NULL;
126	}
127#undef LL_GST_SYM
128
129	sSymsGrabbed = !!rtn;
130	return rtn;
131}
132
133
134void ungrab_gst_syms()
135{ 
136	// should be safe to call regardless of whether we've
137	// actually grabbed syms.
138
139	if ( sSymGSTDSOHandleG )
140	{
141		apr_dso_unload(sSymGSTDSOHandleG);
142		sSymGSTDSOHandleG = NULL;
143	}
144	
145	if ( sSymGSTDSOHandleV )
146	{
147		apr_dso_unload(sSymGSTDSOHandleV);
148		sSymGSTDSOHandleV = NULL;
149	}
150	
151	if ( sSymGSTDSOMemoryPool )
152	{
153		apr_pool_destroy(sSymGSTDSOMemoryPool);
154		sSymGSTDSOMemoryPool = NULL;
155	}
156	
157	// NULL-out all of the symbols we'd grabbed
158#define LL_GST_SYM(REQ, GSTSYM, RTN, ...) do{ll##GSTSYM = NULL;}while(0)
159#include "llmediaimplgstreamer_syms_raw.inc"
160#include "llmediaimplgstreamer_syms_rawv.inc"
161#undef LL_GST_SYM
162
163	sSymsGrabbed = false;
164}
165
166
167#endif // LL_GSTREAMER010_ENABLED