gstreamer from 2.x

This commit is contained in:
Siana Gearz
2010-12-25 01:41:09 +01:00
parent 5e01f8a0e6
commit 4d860094d6
12 changed files with 704 additions and 1019 deletions

View File

@@ -30,13 +30,23 @@ include_directories(
### media_plugin_gstreamer010
if(NOT WORD_SIZE EQUAL 32)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif(NOT WORD_SIZE EQUAL 32)
set(media_plugin_gstreamer010_SOURCE_FILES
media_plugin_gstreamer010.cpp
llmediaimplgstreamer_syms.cpp
llmediaimplgstreamervidplug.cpp
)
set(media_plugin_gstreamer010_HEADER_FILES
llmediaimplgstreamervidplug.h
llmediaimplgstreamer_syms.h
llmediaimplgstreamertriviallogging.h
)

37
indra/media_plugins/gstreamer010/llmediaimplgstreamer.h Executable file → Normal file
View File

@@ -4,33 +4,26 @@
* @brief implementation that supports media playback via GStreamer.
*
* @cond
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2010, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/

View File

@@ -0,0 +1,167 @@
/**
* @file llmediaimplgstreamer_syms.cpp
* @brief dynamic GStreamer symbol-grabbing code
*
* @cond
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
#if LL_GSTREAMER010_ENABLED
#include <string>
extern "C" {
#include <gst/gst.h>
#include "apr_pools.h"
#include "apr_dso.h"
}
#include "llmediaimplgstreamertriviallogging.h"
#define LL_GST_SYM(REQ, GSTSYM, RTN, ...) RTN (*ll##GSTSYM)(__VA_ARGS__) = NULL
#include "llmediaimplgstreamer_syms_raw.inc"
#include "llmediaimplgstreamer_syms_rawv.inc"
#undef LL_GST_SYM
// a couple of stubs for disgusting reasons
GstDebugCategory*
ll_gst_debug_category_new(gchar *name, guint color, gchar *description)
{
static GstDebugCategory dummy;
return &dummy;
}
void ll_gst_debug_register_funcptr(GstDebugFuncPtr func, gchar* ptrname)
{
}
static bool sSymsGrabbed = false;
static apr_pool_t *sSymGSTDSOMemoryPool = NULL;
static apr_dso_handle_t *sSymGSTDSOHandleG = NULL;
static apr_dso_handle_t *sSymGSTDSOHandleV = NULL;
bool grab_gst_syms(std::string gst_dso_name,
std::string gst_dso_name_vid)
{
if (sSymsGrabbed)
{
// already have grabbed good syms
return TRUE;
}
bool sym_error = false;
bool rtn = false;
apr_status_t rv;
apr_dso_handle_t *sSymGSTDSOHandle = NULL;
#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)
//attempt to load the shared libraries
apr_pool_create(&sSymGSTDSOMemoryPool, NULL);
if ( APR_SUCCESS == (rv = apr_dso_load(&sSymGSTDSOHandle,
gst_dso_name.c_str(),
sSymGSTDSOMemoryPool) ))
{
INFOMSG("Found DSO: %s", gst_dso_name.c_str());
#include "llmediaimplgstreamer_syms_raw.inc"
if ( sSymGSTDSOHandle )
{
sSymGSTDSOHandleG = sSymGSTDSOHandle;
sSymGSTDSOHandle = NULL;
}
if ( APR_SUCCESS ==
(rv = apr_dso_load(&sSymGSTDSOHandle,
gst_dso_name_vid.c_str(),
sSymGSTDSOMemoryPool) ))
{
INFOMSG("Found DSO: %s", gst_dso_name_vid.c_str());
#include "llmediaimplgstreamer_syms_rawv.inc"
rtn = !sym_error;
}
else
{
INFOMSG("Couldn't load DSO: %s", gst_dso_name_vid.c_str());
rtn = false; // failure
}
}
else
{
INFOMSG("Couldn't load DSO: %s", gst_dso_name.c_str());
rtn = false; // failure
}
if (sym_error)
{
WARNMSG("Failed to find necessary symbols in GStreamer libraries.");
}
if ( sSymGSTDSOHandle )
{
sSymGSTDSOHandleV = sSymGSTDSOHandle;
sSymGSTDSOHandle = NULL;
}
#undef LL_GST_SYM
sSymsGrabbed = !!rtn;
return rtn;
}
void ungrab_gst_syms()
{
// should be safe to call regardless of whether we've
// actually grabbed syms.
if ( sSymGSTDSOHandleG )
{
apr_dso_unload(sSymGSTDSOHandleG);
sSymGSTDSOHandleG = NULL;
}
if ( sSymGSTDSOHandleV )
{
apr_dso_unload(sSymGSTDSOHandleV);
sSymGSTDSOHandleV = NULL;
}
if ( sSymGSTDSOMemoryPool )
{
apr_pool_destroy(sSymGSTDSOMemoryPool);
sSymGSTDSOMemoryPool = NULL;
}
// NULL-out all of the symbols we'd grabbed
#define LL_GST_SYM(REQ, GSTSYM, RTN, ...) do{ll##GSTSYM = NULL;}while(0)
#include "llmediaimplgstreamer_syms_raw.inc"
#include "llmediaimplgstreamer_syms_rawv.inc"
#undef LL_GST_SYM
sSymsGrabbed = false;
}
#endif // LL_GSTREAMER010_ENABLED

View File

@@ -0,0 +1,74 @@
/**
* @file llmediaimplgstreamer_syms.h
* @brief dynamic GStreamer symbol-grabbing code
*
* @cond
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
#include "linden_common.h"
#if LL_GSTREAMER010_ENABLED
extern "C" {
#include <gst/gst.h>
}
bool grab_gst_syms(std::string gst_dso_name,
std::string gst_dso_name_vid);
void ungrab_gst_syms();
#define LL_GST_SYM(REQ, GSTSYM, RTN, ...) extern RTN (*ll##GSTSYM)(__VA_ARGS__)
#include "llmediaimplgstreamer_syms_raw.inc"
#include "llmediaimplgstreamer_syms_rawv.inc"
#undef LL_GST_SYM
// regrettable hacks to give us better runtime compatibility with older systems
#define llg_return_if_fail(COND) do{if (!(COND)) return;}while(0)
#define llg_return_val_if_fail(COND,V) do{if (!(COND)) return V;}while(0)
// regrettable hacks because GStreamer was not designed for runtime loading
#undef GST_TYPE_MESSAGE
#define GST_TYPE_MESSAGE (llgst_message_get_type())
#undef GST_TYPE_OBJECT
#define GST_TYPE_OBJECT (llgst_object_get_type())
#undef GST_TYPE_PIPELINE
#define GST_TYPE_PIPELINE (llgst_pipeline_get_type())
#undef GST_TYPE_ELEMENT
#define GST_TYPE_ELEMENT (llgst_element_get_type())
#undef GST_TYPE_VIDEO_SINK
#define GST_TYPE_VIDEO_SINK (llgst_video_sink_get_type())
// more regrettable hacks to stub-out these .h-exposed GStreamer internals
void ll_gst_debug_register_funcptr(GstDebugFuncPtr func, gchar* ptrname);
#undef _gst_debug_register_funcptr
#define _gst_debug_register_funcptr ll_gst_debug_register_funcptr
GstDebugCategory* ll_gst_debug_category_new(gchar *name, guint color, gchar *description);
#undef _gst_debug_category_new
#define _gst_debug_category_new ll_gst_debug_category_new
#undef __gst_debug_enabled
#define __gst_debug_enabled (0)
// more hacks
#define LLGST_MESSAGE_TYPE_NAME(M) (llgst_message_type_get_name(GST_MESSAGE_TYPE(M)))
#endif // LL_GSTREAMER010_ENABLED

View File

@@ -0,0 +1,51 @@
// required symbols to grab
LL_GST_SYM(true, gst_pad_peer_accept_caps, gboolean, GstPad *pad, GstCaps *caps);
LL_GST_SYM(true, gst_buffer_new, GstBuffer*, void);
LL_GST_SYM(true, gst_buffer_set_caps, void, GstBuffer*, GstCaps *);
LL_GST_SYM(true, gst_structure_set_value, void, GstStructure *, const gchar *, const GValue*);
LL_GST_SYM(true, gst_init_check, gboolean, int *argc, char **argv[], GError ** err);
LL_GST_SYM(true, gst_message_get_type, GType, void);
LL_GST_SYM(true, gst_message_type_get_name, const gchar*, GstMessageType type);
LL_GST_SYM(true, gst_message_parse_error, void, GstMessage *message, GError **gerror, gchar **debug);
LL_GST_SYM(true, gst_message_parse_warning, void, GstMessage *message, GError **gerror, gchar **debug);
LL_GST_SYM(true, gst_message_parse_state_changed, void, GstMessage *message, GstState *oldstate, GstState *newstate, GstState *pending);
LL_GST_SYM(true, gst_element_set_state, GstStateChangeReturn, GstElement *element, GstState state);
LL_GST_SYM(true, gst_object_unref, void, gpointer object);
LL_GST_SYM(true, gst_object_get_type, GType, void);
LL_GST_SYM(true, gst_pipeline_get_type, GType, void);
LL_GST_SYM(true, gst_pipeline_get_bus, GstBus*, GstPipeline *pipeline);
LL_GST_SYM(true, gst_bus_add_watch, guint, GstBus * bus, GstBusFunc func, gpointer user_data);
LL_GST_SYM(true, gst_element_factory_make, GstElement*, const gchar *factoryname, const gchar *name);
LL_GST_SYM(true, gst_element_get_type, GType, void);
LL_GST_SYM(true, gst_static_pad_template_get, GstPadTemplate*, GstStaticPadTemplate *pad_template);
LL_GST_SYM(true, gst_element_class_add_pad_template, void, GstElementClass *klass, GstPadTemplate *temp);
LL_GST_SYM(true, gst_element_class_set_details, void, GstElementClass *klass, const GstElementDetails *details);
LL_GST_SYM(true, gst_caps_unref, void, GstCaps* caps);
LL_GST_SYM(true, gst_caps_ref, GstCaps *, GstCaps* caps);
//LL_GST_SYM(true, gst_caps_is_empty, gboolean, const GstCaps *caps);
LL_GST_SYM(true, gst_caps_from_string, GstCaps *, const gchar *string);
LL_GST_SYM(true, gst_caps_replace, void, GstCaps **caps, GstCaps *newcaps);
LL_GST_SYM(true, gst_caps_get_structure, GstStructure *, const GstCaps *caps, guint index);
LL_GST_SYM(true, gst_caps_copy, GstCaps *, const GstCaps * caps);
//LL_GST_SYM(true, gst_caps_intersect, GstCaps *, const GstCaps *caps1, const GstCaps *caps2);
LL_GST_SYM(true, gst_element_register, gboolean, GstPlugin *plugin, const gchar *name, guint rank, GType type);
LL_GST_SYM(true, _gst_plugin_register_static, void, GstPluginDesc *desc);
LL_GST_SYM(true, gst_structure_get_int, gboolean, const GstStructure *structure, const gchar *fieldname, gint *value);
LL_GST_SYM(true, gst_structure_get_value, G_CONST_RETURN GValue *, const GstStructure *structure, const gchar *fieldname);
LL_GST_SYM(true, gst_value_get_fraction_numerator, gint, const GValue *value);
LL_GST_SYM(true, gst_value_get_fraction_denominator, gint, const GValue *value);
LL_GST_SYM(true, gst_structure_get_name, G_CONST_RETURN gchar *, const GstStructure *structure);
LL_GST_SYM(true, gst_element_seek, bool, GstElement *, gdouble, GstFormat, GstSeekFlags, GstSeekType, gint64, GstSeekType, gint64);
// optional symbols to grab
LL_GST_SYM(false, gst_registry_fork_set_enabled, void, gboolean enabled);
LL_GST_SYM(false, gst_segtrap_set_enabled, void, gboolean enabled);
LL_GST_SYM(false, gst_message_parse_buffering, void, GstMessage *message, gint *percent);
LL_GST_SYM(false, gst_message_parse_info, void, GstMessage *message, GError **gerror, gchar **debug);
LL_GST_SYM(false, gst_element_query_position, gboolean, GstElement *element, GstFormat *format, gint64 *cur);
LL_GST_SYM(false, gst_version, void, guint *major, guint *minor, guint *micro, guint *nano);
// GStreamer 'internal' symbols which may not be visible in some runtimes but are still used in expanded GStreamer header macros - yuck! We'll substitute our own stubs for these.
//LL_GST_SYM(true, _gst_debug_register_funcptr, void, GstDebugFuncPtr func, gchar* ptrname);
//LL_GST_SYM(true, _gst_debug_category_new, GstDebugCategory *, gchar *name, guint color, gchar *description);

View File

@@ -0,0 +1,5 @@
// required symbols to grab
LL_GST_SYM(true, gst_video_sink_get_type, GType, void);
// optional symbols to grab

View File

@@ -3,33 +3,26 @@
* @brief minimal logging utilities.
*
* @cond
* $LicenseInfo:firstyear=2009&license=viewergpl$
*
* Copyright (c) 2009-2010, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2009&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/
@@ -38,19 +31,16 @@
#include <cstdio>
/////////////////////////////////////////////////////////////////////////
// Debug/Info/Warning macros.
#if LL_WINDOWS
#include <process.h>
#define LL_GETPID GetCurrentProcessId
#else
extern "C" {
#include <sys/types.h>
#include <unistd.h>
#define LL_GETPID getpid
#endif
}
/////////////////////////////////////////////////////////////////////////
// Debug/Info/Warning macros.
#define MSGMODULEFOO "(media plugin)"
#define STDERRMSG(...) do{\
fprintf(stderr, " pid:%d: ", (int)LL_GETPID());\
fprintf(stderr, " pid:%d: ", (int)getpid());\
fprintf(stderr, MSGMODULEFOO " %s:%d: ", __FUNCTION__, __LINE__);\
fprintf(stderr, __VA_ARGS__);\
fputc('\n',stderr);\

View File

@@ -3,33 +3,26 @@
* @brief Video-consuming static GStreamer plugin for gst-to-LLMediaImpl
*
* @cond
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2010, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/
@@ -41,29 +34,15 @@
#include <gst/video/video.h>
#include <gst/video/gstvideosink.h>
#include "llmediaimplgstreamer_syms.h"
#include "llmediaimplgstreamertriviallogging.h"
// #include "llthread.h"
#include "llmediaimplgstreamervidplug.h"
GST_DEBUG_CATEGORY_STATIC (gst_slvideo_debug);
#define GST_CAT_DEFAULT gst_slvideo_debug
/* Filter signals and args *//*
enum
{
*//* FILL ME *//*
LAST_SIGNAL
};
enum
{
ARG_0
};
#define SLV_SIZECAPS ", width=(int){1,2,4,8,16,32,64,128,256,512,1024}, height=(int){1,2,4,8,16,32,64,128,256,512,1024} "
#define SLV_ALLCAPS GST_VIDEO_CAPS_RGBx SLV_SIZECAPS ";" GST_VIDEO_CAPS_BGRx SLV_SIZECAPS
*/
#define SLV_SIZECAPS ", width=(int)[1,2048], height=(int)[1,2048] "
#define SLV_ALLCAPS GST_VIDEO_CAPS_RGBx SLV_SIZECAPS
@@ -95,9 +74,9 @@ gst_slvideo_base_init (gpointer gclass)
};
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
gst_element_class_set_details (element_class, &element_details);
llgst_element_class_add_pad_template (element_class,
llgst_static_pad_template_get (&sink_factory));
llgst_element_class_set_details (element_class, &element_details);
}
@@ -108,7 +87,7 @@ gst_slvideo_finalize (GObject * object)
slvideo = GST_SLVIDEO (object);
if (slvideo->caps)
{
gst_caps_unref(slvideo->caps);
llgst_caps_unref(slvideo->caps);
}
G_OBJECT_CLASS(parent_class)->finalize (object);
@@ -119,7 +98,7 @@ static GstFlowReturn
gst_slvideo_show_frame (GstBaseSink * bsink, GstBuffer * buf)
{
GstSLVideo *slvideo;
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
llg_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
slvideo = GST_SLVIDEO(bsink);
@@ -211,7 +190,7 @@ gst_slvideo_get_caps (GstBaseSink * bsink)
GstSLVideo *slvideo;
slvideo = GST_SLVIDEO(bsink);
return gst_caps_ref (slvideo->caps);
return llgst_caps_ref (slvideo->caps);
}
@@ -221,32 +200,21 @@ gst_slvideo_set_caps (GstBaseSink * bsink, GstCaps * caps)
{
GstSLVideo *filter;
GstStructure *structure;
// GstCaps *intersection;
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
filter = GST_SLVIDEO(bsink);
/*
intersection = gst_caps_intersect (filter->caps, caps);
if (gst_caps_is_empty (intersection))
{
// no overlap between our caps and requested caps
return FALSE;
}
gst_caps_unref(intersection);
*/
int width = 0;
int height = 0;
int width, height;
gboolean ret;
const GValue *fps;
const GValue *par;
structure = gst_caps_get_structure (caps, 0);
ret = gst_structure_get_int (structure, "width", &width);
ret = ret && gst_structure_get_int (structure, "height", &height);
fps = gst_structure_get_value (structure, "framerate");
structure = llgst_caps_get_structure (caps, 0);
ret = llgst_structure_get_int (structure, "width", &width);
ret = ret && llgst_structure_get_int (structure, "height", &height);
fps = llgst_structure_get_value (structure, "framerate");
ret = ret && (fps != NULL);
par = gst_structure_get_value (structure, "pixel-aspect-ratio");
par = llgst_structure_get_value (structure, "pixel-aspect-ratio");
if (!ret)
return FALSE;
@@ -256,35 +224,34 @@ gst_slvideo_set_caps (GstBaseSink * bsink, GstCaps * caps)
filter->width = width;
filter->height = height;
filter->fps_n = gst_value_get_fraction_numerator(fps);
filter->fps_d = gst_value_get_fraction_denominator(fps);
filter->fps_n = llgst_value_get_fraction_numerator(fps);
filter->fps_d = llgst_value_get_fraction_denominator(fps);
if (par)
{
filter->par_n = gst_value_get_fraction_numerator(par);
filter->par_d = gst_value_get_fraction_denominator(par);
filter->par_n = llgst_value_get_fraction_numerator(par);
filter->par_d = llgst_value_get_fraction_denominator(par);
}
else
{
filter->par_n = 1;
filter->par_d = 1;
}
GST_VIDEO_SINK_WIDTH(filter) = width;
GST_VIDEO_SINK_HEIGHT(filter) = height;
// crufty lump - we *always* accept *only* RGBX now.
/*
filter->format = SLV_PF_UNKNOWN;
if (0 == strcmp(gst_structure_get_name(structure),
if (0 == strcmp(llgst_structure_get_name(structure),
"video/x-raw-rgb"))
{
int red_mask;
int green_mask;
int blue_mask;
gst_structure_get_int(structure, "red_mask", &red_mask);
gst_structure_get_int(structure, "green_mask", &green_mask);
gst_structure_get_int(structure, "blue_mask", &blue_mask);
llgst_structure_get_int(structure, "red_mask", &red_mask);
llgst_structure_get_int(structure, "green_mask", &green_mask);
llgst_structure_get_int(structure, "blue_mask", &blue_mask);
if ((unsigned int)red_mask == 0xFF000000 &&
(unsigned int)green_mask == 0x00FF0000 &&
(unsigned int)blue_mask == 0x0000FF00)
@@ -298,13 +265,12 @@ gst_slvideo_set_caps (GstBaseSink * bsink, GstCaps * caps)
filter->format = SLV_PF_BGRX;
//fprintf(stderr, "\n\nPIXEL FORMAT BGR\n\n");
}
}*/
}*/
filter->format = SLV_PF_RGBX;
GST_OBJECT_UNLOCK(filter);
return TRUE;
}
@@ -351,15 +317,15 @@ gst_slvideo_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
// we can ignore these and reverse-negotiate our preferred dimensions with
// the peer if we like - we need to do this to obey dynamic resize requests
// flowing in from the app.
structure = gst_caps_get_structure (caps, 0);
if (!gst_structure_get_int(structure, "width", &width) ||
!gst_structure_get_int(structure, "height", &height))
structure = llgst_caps_get_structure (caps, 0);
if (!llgst_structure_get_int(structure, "width", &width) ||
!llgst_structure_get_int(structure, "height", &height))
{
GST_WARNING_OBJECT (slvideo, "no width/height in caps %" GST_PTR_FORMAT, caps);
return GST_FLOW_NOT_NEGOTIATED;
}
GstBuffer *newbuf = gst_buffer_new();
GstBuffer *newbuf = llgst_buffer_new();
bool made_bufferdata_ptr = false;
#define MAXDEPTHHACK 4
@@ -379,19 +345,19 @@ gst_slvideo_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
GstCaps *desired_caps;
GstStructure *desired_struct;
desired_caps = gst_caps_copy (caps);
desired_struct = gst_caps_get_structure (desired_caps, 0);
desired_caps = llgst_caps_copy (caps);
desired_struct = llgst_caps_get_structure (desired_caps, 0);
GValue value = {0};
g_value_init(&value, G_TYPE_INT);
g_value_set_int(&value, slwantwidth);
gst_structure_set_value (desired_struct, "width", &value);
llgst_structure_set_value (desired_struct, "width", &value);
g_value_unset(&value);
g_value_init(&value, G_TYPE_INT);
g_value_set_int(&value, slwantheight);
gst_structure_set_value (desired_struct, "height", &value);
llgst_structure_set_value (desired_struct, "height", &value);
if (gst_pad_peer_accept_caps (GST_VIDEO_SINK_PAD (slvideo),
if (llgst_pad_peer_accept_caps (GST_VIDEO_SINK_PAD (slvideo),
desired_caps))
{
// todo: re-use buffers from a pool?
@@ -402,13 +368,13 @@ gst_slvideo_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
GST_BUFFER_SIZE(newbuf) = slwantwidth * slwantheight * MAXDEPTHHACK;
GST_BUFFER_MALLOCDATA(newbuf) = (guint8*)g_malloc(GST_BUFFER_SIZE(newbuf));
GST_BUFFER_DATA(newbuf) = GST_BUFFER_MALLOCDATA(newbuf);
gst_buffer_set_caps (GST_BUFFER_CAST(newbuf), desired_caps);
llgst_buffer_set_caps (GST_BUFFER_CAST(newbuf), desired_caps);
made_bufferdata_ptr = true;
} else {
// peer hates our cap suggestion
INFOMSG("peer hates us :(");
gst_caps_unref(desired_caps);
llgst_caps_unref(desired_caps);
}
}
}
@@ -420,7 +386,7 @@ gst_slvideo_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
GST_BUFFER_SIZE(newbuf) = width * height * MAXDEPTHHACK;
GST_BUFFER_MALLOCDATA(newbuf) = (guint8*)g_malloc(GST_BUFFER_SIZE(newbuf));
GST_BUFFER_DATA(newbuf) = GST_BUFFER_MALLOCDATA(newbuf);
gst_buffer_set_caps (GST_BUFFER_CAST(newbuf), caps);
llgst_buffer_set_caps (GST_BUFFER_CAST(newbuf), caps);
}
*buf = GST_BUFFER_CAST(newbuf);
@@ -462,20 +428,6 @@ gst_slvideo_class_init (GstSLVideoClass * klass)
#undef LLGST_DEBUG_FUNCPTR
}
/*
static void
gst_slvideo_update_caps (GstSLVideo * slvideo)
{
GstCaps *caps;
// GStreamer will automatically convert colourspace if necessary.
// GStreamer will automatically resize media to one of these enumerated
// powers-of-two that we ask for (yay GStreamer!)
caps = gst_caps_from_string (SLV_ALLCAPS);
gst_caps_replace (&slvideo->caps, caps);
}
*/
/* initialize the new element
* instantiate pads and add them to element
@@ -498,24 +450,24 @@ gst_slvideo_init (GstSLVideo * filter,
filter->retained_frame_width = filter->width;
filter->retained_frame_height = filter->height;
filter->retained_frame_format = SLV_PF_UNKNOWN;
GstCaps *caps = gst_caps_from_string (SLV_ALLCAPS);
gst_caps_replace (&filter->caps, caps);
GstCaps *caps = llgst_caps_from_string (SLV_ALLCAPS);
llgst_caps_replace (&filter->caps, caps);
filter->resize_forced_always = false;
filter->resize_try_width = -1;
filter->resize_try_height = -1;
GST_OBJECT_UNLOCK(filter);
//gst_slvideo_update_caps(filter);
}
static void
gst_slvideo_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
g_return_if_fail (GST_IS_SLVIDEO (object));
llg_return_if_fail (GST_IS_SLVIDEO (object));
if (prop_id) {
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@@ -523,10 +475,12 @@ static void
gst_slvideo_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
g_return_if_fail (GST_IS_SLVIDEO (object));
llg_return_if_fail (GST_IS_SLVIDEO (object));
if (prop_id) {
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@@ -544,7 +498,7 @@ plugin_init (GstPlugin * plugin)
GST_DEBUG_CATEGORY_INIT (gst_slvideo_debug, (gchar*)"private-slvideo-plugin",
0, (gchar*)"Second Life Video Sink");
return gst_element_register (plugin, "private-slvideo",
return llgst_element_register (plugin, "private-slvideo",
GST_RANK_NONE, GST_TYPE_SLVIDEO);
}
@@ -554,19 +508,20 @@ plugin_init (GstPlugin * plugin)
some g++ versions buggily avoid __attribute__((constructor)) functions -
so we provide an explicit plugin init function.
*/
#define PACKAGE (gchar*)"packagehack"
// this macro quietly refers to PACKAGE internally
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
(gchar*)"private-slvideoplugin",
(gchar*)"SL Video sink plugin",
plugin_init, (gchar*)"1.0", (gchar*)"LGPL",
(gchar*)"Second Life",
(gchar*)"http://www.secondlife.com/");
#undef PACKAGE
void gst_slvideo_init_class (void)
{
gst_plugin_register_static( GST_VERSION_MAJOR,
GST_VERSION_MINOR,
(const gchar *)"private-slvideoplugin",
(gchar *)"SL Video sink plugin",
plugin_init,
(const gchar *)"0.1",
GST_LICENSE_UNKNOWN,
(const gchar *)"Second Life",
(const gchar *)"Second Life",
(const gchar *)"http://www.secondlife.com/" );
ll_gst_plugin_register_static (&gst_plugin_desc);
DEBUGMSG("CLASS INIT");
}
#endif // LL_GSTREAMER010_ENABLED

View File

@@ -3,33 +3,26 @@
* @brief Video-consuming static GStreamer plugin for gst-to-LLMediaImpl
*
* @cond
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2010, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/
@@ -42,7 +35,6 @@ extern "C" {
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideosink.h>
// #include <glib/gthread.h>
}
G_BEGIN_DECLS

View File

@@ -3,45 +3,31 @@
* @brief GStreamer-0.10 plugin for LLMedia API plugin system
*
* @cond
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2010, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlife.com/developers/opensource/flossexception
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/
#include "linden_common.h"
// Needed for _getcwd() RC
#ifdef LL_WINDOWS
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#endif
#include "llgl.h"
#include "llplugininstance.h"
@@ -53,7 +39,6 @@
extern "C" {
#include <gst/gst.h>
#include <gst/gstelement.h>
}
#include "llmediaimplgstreamer.h"
@@ -61,6 +46,8 @@ extern "C" {
#include "llmediaimplgstreamervidplug.h"
#include "llmediaimplgstreamer_syms.h"
//////////////////////////////////////////////////////////////////////////////
//
class MediaPluginGStreamer010 : public MediaPluginBase
@@ -74,8 +61,6 @@ public:
static bool startup();
static bool closedown();
static void set_gst_plugin_path();
gboolean processGSTEvents(GstBus *bus,
GstMessage *message);
@@ -91,7 +76,7 @@ private:
bool play(double rate);
bool getTimePos(double &sec_out);
#define MIN_LOOP_SEC 1.0F
static const double MIN_LOOP_SEC = 1.0F;
bool mIsLooping;
@@ -147,12 +132,11 @@ private:
bool mSeekWanted;
double mSeekDestination;
std::string mLastTitle;
// Very GStreamer-specific
GMainLoop *mPump; // event pump for this media
GstElement *mPlaybin;
GstElement *mVisualizer;
GstSLVideo *mVideoSink;
};
@@ -171,11 +155,12 @@ MediaPluginGStreamer010::MediaPluginGStreamer010(
mSeekDestination(0.0),
mPump ( NULL ),
mPlaybin ( NULL ),
mVisualizer ( NULL ),
mVideoSink ( NULL ),
mCommand ( COMMAND_NONE )
{
std::ostringstream str;
INFOMSG("MediaPluginGStreamer010 constructor - my PID=%u", U32(LL_GETPID()));
INFOMSG("MediaPluginGStreamer010 constructor - my PID=%u", U32(getpid()));
}
///////////////////////////////////////////////////////////////////////////////
@@ -206,179 +191,149 @@ MediaPluginGStreamer010::processGSTEvents(GstBus *bus,
GST_MESSAGE_TYPE(message) != GST_MESSAGE_BUFFERING)
{
DEBUGMSG("Got GST message type: %s",
GST_MESSAGE_TYPE_NAME (message));
LLGST_MESSAGE_TYPE_NAME (message));
}
else
{
// TODO: grok 'duration' message type
DEBUGMSG("Got GST message type: %s",
GST_MESSAGE_TYPE_NAME (message));
LLGST_MESSAGE_TYPE_NAME (message));
}
switch (GST_MESSAGE_TYPE (message))
{
case GST_MESSAGE_BUFFERING:
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_BUFFERING: {
// NEEDS GST 0.10.11+
if (llgst_message_parse_buffering)
{
// NEEDS GST 0.10.11+ and America discovered by C.Columbus
gint percent = 0;
gst_message_parse_buffering(message, &percent);
llgst_message_parse_buffering(message, &percent);
DEBUGMSG("GST buffering: %d%%", percent);
}
break;
}
case GST_MESSAGE_STATE_CHANGED: {
GstState old_state;
GstState new_state;
GstState pending_state;
llgst_message_parse_state_changed(message,
&old_state,
&new_state,
&pending_state);
#ifdef LL_GST_REPORT_STATE_CHANGES
// not generally very useful, and rather spammy.
DEBUGMSG("state change (old,<new>,pending): %s,<%s>,%s",
get_gst_state_name(old_state),
get_gst_state_name(new_state),
get_gst_state_name(pending_state));
#endif // LL_GST_REPORT_STATE_CHANGES
switch (new_state) {
case GST_STATE_VOID_PENDING:
break;
case GST_STATE_NULL:
break;
case GST_STATE_READY:
setStatus(STATUS_LOADED);
break;
case GST_STATE_PAUSED:
setStatus(STATUS_PAUSED);
break;
case GST_STATE_PLAYING:
setStatus(STATUS_PLAYING);
break;
}
case GST_MESSAGE_STATE_CHANGED: {
GstState old_state;
GstState new_state;
GstState pending_state;
gst_message_parse_state_changed(message,
&old_state,
&new_state,
&pending_state);
#ifdef LL_GST_REPORT_STATE_CHANGES
// not generally very useful, and rather spammy.
DEBUGMSG("state change (old,<new>,pending): %s,<%s>,%s",
get_gst_state_name(old_state),
get_gst_state_name(new_state),
get_gst_state_name(pending_state));
#endif // LL_GST_REPORT_STATE_CHANGES
break;
}
case GST_MESSAGE_ERROR: {
GError *err = NULL;
gchar *debug = NULL;
switch (new_state)
{
case GST_STATE_VOID_PENDING:
break;
case GST_STATE_NULL:
break;
case GST_STATE_READY:
setStatus(STATUS_LOADED);
break;
case GST_STATE_PAUSED:
setStatus(STATUS_PAUSED);
break;
case GST_STATE_PLAYING:
setStatus(STATUS_PLAYING);
break;
}
break;
}
case GST_MESSAGE_ERROR:
{
GError *err = NULL;
gchar *debug = NULL;
gst_message_parse_error (message, &err, &debug);
WARNMSG("GST error: %s", err?err->message:"(unknown)");
if (err)
g_error_free (err);
g_free (debug);
mCommand = COMMAND_STOP;
setStatus(STATUS_ERROR);
break;
}
case GST_MESSAGE_INFO:
llgst_message_parse_error (message, &err, &debug);
WARNMSG("GST error: %s", err?err->message:"(unknown)");
if (err)
g_error_free (err);
g_free (debug);
mCommand = COMMAND_STOP;
setStatus(STATUS_ERROR);
break;
}
case GST_MESSAGE_INFO: {
if (llgst_message_parse_info)
{
GError *err = NULL;
gchar *debug = NULL;
gst_message_parse_info (message, &err, &debug);
llgst_message_parse_info (message, &err, &debug);
INFOMSG("GST info: %s", err?err->message:"(unknown)");
if (err)
g_error_free (err);
g_free (debug);
break;
}
case GST_MESSAGE_WARNING:
break;
}
case GST_MESSAGE_WARNING: {
GError *err = NULL;
gchar *debug = NULL;
llgst_message_parse_warning (message, &err, &debug);
WARNMSG("GST warning: %s", err?err->message:"(unknown)");
if (err)
g_error_free (err);
g_free (debug);
break;
}
case GST_MESSAGE_EOS:
/* end-of-stream */
DEBUGMSG("GST end-of-stream.");
if (mIsLooping)
{
GError *err = NULL;
gchar *debug = NULL;
gst_message_parse_warning (message, &err, &debug);
WARNMSG("GST warning: %s", err?err->message:"(unknown)");
if (err)
g_error_free (err);
g_free (debug);
break;
}
case GST_MESSAGE_TAG:
{
GstTagList *new_tags;
DEBUGMSG("looping media...");
double eos_pos_sec = 0.0F;
bool got_eos_position = getTimePos(eos_pos_sec);
gst_message_parse_tag( message, &new_tags );
gchar *title = NULL;
if ( gst_tag_list_get_string(new_tags, GST_TAG_TITLE, &title) )
if (got_eos_position && eos_pos_sec < MIN_LOOP_SEC)
{
//WARMING("Title: %s", title);
std::string newtitle(title);
gst_tag_list_free(new_tags);
if ( newtitle != mLastTitle && !newtitle.empty() )
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "name_text");
message.setValue("name", newtitle );
sendMessage( message );
mLastTitle = newtitle;
}
g_free(title);
// if we know that the movie is really short, don't
// loop it else it can easily become a time-hog
// because of GStreamer spin-up overhead
DEBUGMSG("really short movie (%0.3fsec) - not gonna loop this, pausing instead.", eos_pos_sec);
// inject a COMMAND_PAUSE
mCommand = COMMAND_PAUSE;
}
break;
}
case GST_MESSAGE_EOS:
{
/* end-of-stream */
DEBUGMSG("GST end-of-stream.");
if (mIsLooping)
else
{
DEBUGMSG("looping media...");
double eos_pos_sec = 0.0F;
bool got_eos_position = getTimePos(eos_pos_sec);
if (got_eos_position && eos_pos_sec < MIN_LOOP_SEC)
#undef LLGST_LOOP_BY_SEEKING
// loop with a stop-start instead of a seek, because it actually seems rather
// faster than seeking on remote streams.
#ifdef LLGST_LOOP_BY_SEEKING
// first, try looping by an explicit rewind
bool seeksuccess = seek(0.0);
if (seeksuccess)
{
// if we know that the movie is really short, don't
// loop it else it can easily become a time-hog
// because of GStreamer spin-up overhead
DEBUGMSG("really short movie (%0.3fsec) - not gonna loop this, pausing instead.", eos_pos_sec);
// inject a COMMAND_PAUSE
mCommand = COMMAND_PAUSE;
play(1.0);
}
else
{
#undef LLGST_LOOP_BY_SEEKING
// loop with a stop-start instead of a seek, because it actually seems rather
// faster than seeking on remote streams.
#ifdef LLGST_LOOP_BY_SEEKING
// first, try looping by an explicit rewind
bool seeksuccess = seek(0.0);
if (seeksuccess)
{
play(1.0);
}
else
#endif // LLGST_LOOP_BY_SEEKING
{ // use clumsy stop-start to loop
DEBUGMSG("didn't loop by rewinding - stopping and starting instead...");
stop();
play(1.0);
}
#endif // LLGST_LOOP_BY_SEEKING
{ // use clumsy stop-start to loop
DEBUGMSG("didn't loop by rewinding - stopping and starting instead...");
stop();
play(1.0);
}
}
else // not a looping media
{
// inject a COMMAND_STOP
mCommand = COMMAND_STOP;
}
} break;
default:
/* unhandled message */
break;
}
else // not a looping media
{
// inject a COMMAND_STOP
mCommand = COMMAND_STOP;
}
break;
default:
/* unhandled message */
break;
}
/* we want to be notified again the next time there is a message
@@ -584,8 +539,12 @@ MediaPluginGStreamer010::pause()
{
DEBUGMSG("pausing media...");
// todo: error-check this?
gst_element_set_state(mPlaybin, GST_STATE_PAUSED);
return true;
if (mDoneInit && mPlaybin)
{
llgst_element_set_state(mPlaybin, GST_STATE_PAUSED);
return true;
}
return false;
}
bool
@@ -593,8 +552,12 @@ MediaPluginGStreamer010::stop()
{
DEBUGMSG("stopping media...");
// todo: error-check this?
gst_element_set_state(mPlaybin, GST_STATE_READY);
return true;
if (mDoneInit && mPlaybin)
{
llgst_element_set_state(mPlaybin, GST_STATE_READY);
return true;
}
return false;
}
bool
@@ -604,8 +567,12 @@ MediaPluginGStreamer010::play(double rate)
DEBUGMSG("playing media... rate=%f", rate);
// todo: error-check this?
gst_element_set_state(mPlaybin, GST_STATE_PLAYING);
return true;
if (mDoneInit && mPlaybin)
{
llgst_element_set_state(mPlaybin, GST_STATE_PLAYING);
return true;
}
return false;
}
bool
@@ -633,7 +600,7 @@ MediaPluginGStreamer010::seek(double time_sec)
bool success = false;
if (mDoneInit && mPlaybin)
{
success = gst_element_seek(mPlaybin, 1.0F, GST_FORMAT_TIME,
success = llgst_element_seek(mPlaybin, 1.0F, GST_FORMAT_TIME,
GstSeekFlags(GST_SEEK_FLAG_FLUSH |
GST_SEEK_FLAG_KEY_UNIT),
GST_SEEK_TYPE_SET, gint64(time_sec*GST_SECOND),
@@ -648,13 +615,15 @@ bool
MediaPluginGStreamer010::getTimePos(double &sec_out)
{
bool got_position = false;
if (mPlaybin)
if (mDoneInit && mPlaybin)
{
gint64 pos;
GstFormat timefmt = GST_FORMAT_TIME;
got_position = gst_element_query_position(mPlaybin,
&timefmt,
&pos);
got_position =
llgst_element_query_position &&
llgst_element_query_position(mPlaybin,
&timefmt,
&pos);
got_position = got_position
&& (timefmt == GST_FORMAT_TIME);
// GStreamer may have other ideas, but we consider the current position
@@ -696,7 +665,7 @@ MediaPluginGStreamer010::load()
DEBUGMSG("setting up media...");
mIsLooping = false;
mVolume = (float) 0.1234567; // minor hack to force an initial volume update
mVolume = 0.1234567; // minor hack to force an initial volume update
// Create a pumpable main-loop for this media
mPump = g_main_loop_new (NULL, FALSE);
@@ -707,7 +676,7 @@ MediaPluginGStreamer010::load()
}
// instantiate a playbin element to do the hard work
mPlaybin = gst_element_factory_make ("playbin", "play");
mPlaybin = llgst_element_factory_make ("playbin", "play");
if (!mPlaybin)
{
setStatus(STATUS_ERROR);
@@ -715,21 +684,50 @@ MediaPluginGStreamer010::load()
}
// get playbin's bus
GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (mPlaybin));
GstBus *bus = llgst_pipeline_get_bus (GST_PIPELINE (mPlaybin));
if (!bus)
{
setStatus(STATUS_ERROR);
return false; // error
}
mBusWatchID = gst_bus_add_watch (bus,
mBusWatchID = llgst_bus_add_watch (bus,
llmediaimplgstreamer_bus_callback,
this);
gst_object_unref (bus);
llgst_object_unref (bus);
#if 0 // not quite stable/correct yet
// get a visualizer element (bonus feature!)
char* vis_name = getenv("LL_GST_VIS_NAME");
if (!vis_name ||
(vis_name && std::string(vis_name)!="none"))
{
if (vis_name)
{
mVisualizer = llgst_element_factory_make (vis_name, "vis");
}
if (!mVisualizer)
{
mVisualizer = llgst_element_factory_make ("libvisual_jess", "vis");
if (!mVisualizer)
{
mVisualizer = llgst_element_factory_make ("goom", "vis");
if (!mVisualizer)
{
mVisualizer = llgst_element_factory_make ("libvisual_lv_scope", "vis");
if (!mVisualizer)
{
// That's okay, we don't NEED this.
}
}
}
}
}
#endif
if (NULL == getenv("LL_GSTREAMER_EXTERNAL")) {
// instantiate a custom video sink
mVideoSink =
GST_SLVIDEO(gst_element_factory_make ("private-slvideo", "slvideo"));
GST_SLVIDEO(llgst_element_factory_make ("private-slvideo", "slvideo"));
if (!mVideoSink)
{
WARNMSG("Could not instantiate private-slvideo element.");
@@ -742,6 +740,11 @@ MediaPluginGStreamer010::load()
g_object_set(mPlaybin, "video-sink", mVideoSink, NULL);
}
if (mVisualizer)
{
g_object_set(mPlaybin, "vis-plugin", mVisualizer, NULL);
}
return true;
}
@@ -759,11 +762,17 @@ MediaPluginGStreamer010::unload ()
if (mPlaybin)
{
gst_element_set_state (mPlaybin, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (mPlaybin));
llgst_element_set_state (mPlaybin, GST_STATE_NULL);
llgst_object_unref (GST_OBJECT (mPlaybin));
mPlaybin = NULL;
}
if (mVisualizer)
{
llgst_object_unref (GST_OBJECT (mVisualizer));
mVisualizer = NULL;
}
if (mPump)
{
g_main_loop_quit(mPump);
@@ -793,10 +802,7 @@ MediaPluginGStreamer010::startup()
// Init the glib type system - we need it.
g_type_init();
set_gst_plugin_path();
/*
// Get symbols!
#if LL_DARWIN
if (! grab_gst_syms("libgstreamer-0.10.dylib",
@@ -812,24 +818,24 @@ MediaPluginGStreamer010::startup()
WARNMSG("Couldn't find suitable GStreamer 0.10 support on this system - video playback disabled.");
return false;
}
*/
// if (gst_segtrap_set_enabled)
// {
gst_segtrap_set_enabled(FALSE);
// }
// else
// {
// WARNMSG("gst_segtrap_set_enabled() is not available; plugin crashes won't be caught.");
// }
/*
if (llgst_segtrap_set_enabled)
{
llgst_segtrap_set_enabled(FALSE);
}
else
{
WARNMSG("gst_segtrap_set_enabled() is not available; plugin crashes won't be caught.");
}
#if LL_LINUX
// Gstreamer tries a fork during init, waitpid-ing on it,
// which conflicts with any installed SIGCHLD handler...
struct sigaction tmpact, oldact;
if (gst_registry_fork_set_enabled) {
if (llgst_registry_fork_set_enabled) {
// if we can disable SIGCHLD-using forking behaviour,
// do it.
gst_registry_fork_set_enabled(false);
llgst_registry_fork_set_enabled(false);
}
else {
// else temporarily install default SIGCHLD handler
@@ -840,24 +846,24 @@ MediaPluginGStreamer010::startup()
sigaction(SIGCHLD, &tmpact, &oldact);
}
#endif // LL_LINUX
*/
// Protect against GStreamer resetting the locale, yuck.
static std::string saved_locale;
saved_locale = setlocale(LC_ALL, NULL);
// finally, try to initialize GStreamer!
GError *err = NULL;
gboolean init_gst_success = gst_init_check(NULL, NULL, &err);
gboolean init_gst_success = llgst_init_check(NULL, NULL, &err);
// restore old locale
setlocale(LC_ALL, saved_locale.c_str() );
/*
#if LL_LINUX
// restore old SIGCHLD handler
if (!gst_registry_fork_set_enabled)
if (!llgst_registry_fork_set_enabled)
sigaction(SIGCHLD, &oldact, NULL);
#endif // LL_LINUX
*/
if (!init_gst_success) // fail
{
if (err)
@@ -871,139 +877,16 @@ MediaPluginGStreamer010::startup()
}
return false;
}
// Set up logging facilities
gst_debug_remove_log_function( gst_debug_log_default );
// gst_debug_add_log_function( gstreamer_log, NULL );
// Init our custom plugins - only really need do this once.
gst_slvideo_init_class();
/*
// List the plugins GStreamer can find
LL_DEBUGS("MediaImpl") << "Found GStreamer plugins:" << LL_ENDL;
GList *list;
GstRegistry *registry = gst_registry_get_default();
std::string loaded = "";
for (list = gst_registry_get_plugin_list(registry);
list != NULL;
list = g_list_next(list))
{
GstPlugin *list_plugin = (GstPlugin *)list->data;
(bool)gst_plugin_is_loaded(list_plugin) ? loaded = "Yes" : loaded = "No";
LL_DEBUGS("MediaImpl") << gst_plugin_get_name(list_plugin) << ", loaded? " << loaded << LL_ENDL;
}
gst_plugin_list_free(list);
*/
mDoneInit = true;
}
return true;
}
void MediaPluginGStreamer010::set_gst_plugin_path()
{
// Linux sets GST_PLUGIN_PATH in wrapper.sh, not here.
#if LL_WINDOWS || LL_DARWIN
std::string imp_dir = "";
// Get the current working directory:
#if LL_WINDOWS
char* raw_dir;
raw_dir = _getcwd(NULL,0);
if( raw_dir != NULL )
{
imp_dir = std::string( raw_dir );
}
#elif LL_DARWIN
CFBundleRef main_bundle = CFBundleGetMainBundle();
if( main_bundle != NULL )
{
CFURLRef bundle_url = CFBundleCopyBundleURL( main_bundle );
if( bundle_url != NULL )
{
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
char raw_dir[MAXPATHLEN];
if( CFURLGetFileSystemRepresentation( bundle_url, true, (UInt8 *)raw_dir, MAXPATHLEN) )
{
imp_dir = std::string( raw_dir ) + "/Contents/MacOS/";
}
CFRelease(bundle_url);
}
}
#endif
if( imp_dir == "" )
{
WARNMSG("Could not get application directory, not setting GST_PLUGIN_PATH.");
return;
}
DEBUGMSG("Imprudence is installed at %s", imp_dir);
// ":" on Mac and 'Nix, ";" on Windows
std::string separator = G_SEARCHPATH_SEPARATOR_S;
// Grab the current path, if it's set.
std::string old_plugin_path = "";
char *old_path = getenv("GST_PLUGIN_PATH");
if(old_path == NULL)
{
DEBUGMSG("Did not find user-set GST_PLUGIN_PATH.");
}
else
{
old_plugin_path = separator + std::string( old_path );
}
// Search both Imprudence and Imprudence\lib\gstreamer-plugins.
// But we also want to search the path the user has set, if any.
std::string plugin_path =
"GST_PLUGIN_PATH=" +
#if LL_WINDOWS
imp_dir + "\\lib\\gstreamer-plugins" +
#elif LL_DARWIN
imp_dir + separator +
imp_dir + "/../Resources/lib/gstreamer-plugins" +
#endif
old_plugin_path;
int put_result;
// Place GST_PLUGIN_PATH in the environment settings
#if LL_WINDOWS
put_result = _putenv( (char*)plugin_path.c_str() );
#elif LL_DARWIN
put_result = putenv( (char*)plugin_path.c_str() );
#endif
if( put_result == -1 )
{
WARNMSG("Setting GST_PLUGIN_PATH failed!");
}
else
{
DEBUGMSG("GST_PLUGIN_PATH set to %s", getenv("GST_PLUGIN_PATH"));
}
// Don't load system plugins. We only want to use ours, to avoid conflicts.
#if LL_WINDOWS
put_result = _putenv( "GST_PLUGIN_SYSTEM_PATH=\"\"" );
#elif LL_DARWIN
put_result = putenv( "GST_PLUGIN_SYSTEM_PATH=\"\"" );
#endif
if( put_result == -1 )
{
WARNMSG("Setting GST_PLUGIN_SYSTEM_PATH=\"\" failed!");
}
#endif // LL_WINDOWS || LL_DARWIN
}
void
MediaPluginGStreamer010::sizeChanged()
@@ -1045,7 +928,7 @@ MediaPluginGStreamer010::closedown()
if (!mDoneInit)
return false; // error
// ungrab_gst_syms();
ungrab_gst_syms();
mDoneInit = false;
@@ -1066,10 +949,11 @@ std::string
MediaPluginGStreamer010::getVersion()
{
std::string plugin_version = "GStreamer010 media plugin, GStreamer version ";
if (mDoneInit) // && gst_version)
if (mDoneInit &&
llgst_version)
{
guint major, minor, micro, nano;
gst_version(&major, &minor, &micro, &nano);
llgst_version(&major, &minor, &micro, &nano);
plugin_version += llformat("%u.%u.%u.%u (runtime), %u.%u.%u.%u (headers)", (unsigned int)major, (unsigned int)minor, (unsigned int)micro, (unsigned int)nano, (unsigned int)GST_VERSION_MAJOR, (unsigned int)GST_VERSION_MINOR, (unsigned int)GST_VERSION_MICRO, (unsigned int)GST_VERSION_NANO);
}
else