Imported existing code

This commit is contained in:
Hazim Gazov
2010-04-02 02:48:44 -03:00
parent 48fbc5ae91
commit 7a86d01598
13996 changed files with 2468699 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
# -*- cmake -*-
add_subdirectory(base)
add_subdirectory(webkit)
add_subdirectory(gstreamer010)
if (WINDOWS OR DARWIN)
add_subdirectory(quicktime)
endif (WINDOWS OR DARWIN)
add_subdirectory(example)

View File

@@ -0,0 +1,57 @@
# -*- cmake -*-
project(media_plugin_base)
if(WORD_SIZE EQUAL 64)
set(REQUIRE_PIC)
endif(WORD_SIZE EQUAL 64)
include(00-Common)
include(LLCommon)
include(LLImage)
include(LLPlugin)
include(LLMath)
include(LLRender)
include(LLWindow)
include(Linking)
include(PluginAPI)
include(FindOpenGL)
include_directories(
${LLPLUGIN_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLIMAGE_INCLUDE_DIRS}
${LLRENDER_INCLUDE_DIRS}
${LLWINDOW_INCLUDE_DIRS}
)
### media_plugin_base
if(WORD_SIZE EQUAL 64)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif (WORD_SIZE EQUAL 64)
set(media_plugin_base_SOURCE_FILES
media_plugin_base.cpp
)
set(media_plugin_base_HEADER_FILES
CMakeLists.txt
media_plugin_base.h
)
add_library(media_plugin_base
${media_plugin_base_SOURCE_FILES}
)
add_dependencies(media_plugin_base
prepare
)

View File

@@ -0,0 +1,210 @@
/**
* @file media_plugin_base.cpp
* @brief Media plugin base class for LLMedia API plugin system
*
* All plugins should be a subclass of MediaPluginBase.
*
* $LicenseInfo:firstyear=2008&license=viewergpl$
*
* Copyright (c) 2008-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "media_plugin_base.h"
// TODO: Make sure that the only symbol exported from this library is LLPluginInitEntryPoint
////////////////////////////////////////////////////////////////////////////////
/// Media plugin constructor.
///
/// @param[in] host_send_func Function for sending messages from plugin to plugin loader shell
/// @param[in] host_user_data Message data for messages from plugin to plugin loader shell
MediaPluginBase::MediaPluginBase(
LLPluginInstance::sendMessageFunction host_send_func,
void *host_user_data )
{
mHostSendFunction = host_send_func;
mHostUserData = host_user_data;
mDeleteMe = false;
mPixels = 0;
mWidth = 0;
mHeight = 0;
mTextureWidth = 0;
mTextureHeight = 0;
mDepth = 0;
mStatus = STATUS_NONE;
}
/**
* Converts current media status enum value into string (STATUS_LOADING into "loading", etc.)
*
* @return Media status string ("loading", "playing", "paused", etc)
*
*/
std::string MediaPluginBase::statusString()
{
std::string result;
switch(mStatus)
{
case STATUS_LOADING: result = "loading"; break;
case STATUS_LOADED: result = "loaded"; break;
case STATUS_ERROR: result = "error"; break;
case STATUS_PLAYING: result = "playing"; break;
case STATUS_PAUSED: result = "paused"; break;
case STATUS_DONE: result = "done"; break;
default:
// keep the empty string
break;
}
return result;
}
/**
* Set media status.
*
* @param[in] status Media status (STATUS_LOADING, STATUS_PLAYING, STATUS_PAUSED, etc)
*
*/
void MediaPluginBase::setStatus(EStatus status)
{
if(mStatus != status)
{
mStatus = status;
sendStatus();
}
}
/**
* Receive message from plugin loader shell.
*
* @param[in] message_string Message string
* @param[in] user_data Message data
*
*/
void MediaPluginBase::staticReceiveMessage(const char *message_string, void **user_data)
{
MediaPluginBase *self = (MediaPluginBase*)*user_data;
if(self != NULL)
{
self->receiveMessage(message_string);
// If the plugin has processed the delete message, delete it.
if(self->mDeleteMe)
{
delete self;
*user_data = NULL;
}
}
}
/**
* Send message to plugin loader shell.
*
* @param[in] message Message data being sent to plugin loader shell
*
*/
void MediaPluginBase::sendMessage(const LLPluginMessage &message)
{
std::string output = message.generate();
mHostSendFunction(output.c_str(), &mHostUserData);
}
/**
* Notifies plugin loader shell that part of display area needs to be redrawn.
*
* @param[in] left Left X coordinate of area to redraw (0,0 is at top left corner)
* @param[in] top Top Y coordinate of area to redraw (0,0 is at top left corner)
* @param[in] right Right X-coordinate of area to redraw (0,0 is at top left corner)
* @param[in] bottom Bottom Y-coordinate of area to redraw (0,0 is at top left corner)
*
*/
void MediaPluginBase::setDirty(int left, int top, int right, int bottom)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "updated");
message.setValueS32("left", left);
message.setValueS32("top", top);
message.setValueS32("right", right);
message.setValueS32("bottom", bottom);
sendMessage(message);
}
/**
* Sends "media_status" message to plugin loader shell ("loading", "playing", "paused", etc.)
*
*/
void MediaPluginBase::sendStatus()
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "media_status");
message.setValue("status", statusString());
sendMessage(message);
}
#if LL_WINDOWS
# define LLSYMEXPORT __declspec(dllexport)
#elif LL_LINUX
# define LLSYMEXPORT __attribute__ ((visibility("default")))
#else
# define LLSYMEXPORT /**/
#endif
extern "C"
{
LLSYMEXPORT int LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data);
}
/**
* Plugin initialization and entry point. Establishes communication channel for messages between plugin and plugin loader shell. TODO:DOC - Please check!
*
* @param[in] host_send_func Function for sending messages from plugin to plugin loader shell
* @param[in] host_user_data Message data for messages from plugin to plugin loader shell
* @param[out] plugin_send_func Function for plugin to receive messages from plugin loader shell
* @param[out] plugin_user_data Pointer to plugin instance
*
* @return int, where 0=success
*
*/
LLSYMEXPORT int
LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data)
{
return init_media_plugin(host_send_func, host_user_data, plugin_send_func, plugin_user_data);
}
#ifdef WIN32
int WINAPI DllEntryPoint( HINSTANCE hInstance, unsigned long reason, void* params )
{
return 1;
}
#endif

View File

@@ -0,0 +1,2 @@
_LLPluginInitEntryPoint

View File

@@ -0,0 +1,133 @@
/**
* @file media_plugin_base.h
* @brief Media plugin base class for LLMedia API plugin system
*
* $LicenseInfo:firstyear=2008&license=viewergpl$
*
* Copyright (c) 2008-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llplugininstance.h"
#include "llpluginmessage.h"
#include "llpluginmessageclasses.h"
class MediaPluginBase
{
public:
MediaPluginBase(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data);
/** Media plugin destructor. */
virtual ~MediaPluginBase() {}
/** Handle received message from plugin loader shell. */
virtual void receiveMessage(const char *message_string) = 0;
static void staticReceiveMessage(const char *message_string, void **user_data);
protected:
/** Plugin status. */
typedef enum
{
STATUS_NONE,
STATUS_LOADING,
STATUS_LOADED,
STATUS_ERROR,
STATUS_PLAYING,
STATUS_PAUSED,
STATUS_DONE
} EStatus;
/** Plugin shared memory. */
class SharedSegmentInfo
{
public:
/** Shared memory address. */
void *mAddress;
/** Shared memory size. */
size_t mSize;
};
void sendMessage(const LLPluginMessage &message);
void sendStatus();
std::string statusString();
void setStatus(EStatus status);
/// Note: The quicktime plugin overrides this to add current time and duration to the message.
virtual void setDirty(int left, int top, int right, int bottom);
/** Map of shared memory names to shared memory. */
typedef std::map<std::string, SharedSegmentInfo> SharedSegmentMap;
/** Function to send message from plugin to plugin loader shell. */
LLPluginInstance::sendMessageFunction mHostSendFunction;
/** Message data being sent to plugin loader shell by mHostSendFunction. */
void *mHostUserData;
/** Flag to delete plugin instance (self). */
bool mDeleteMe;
/** Pixel array to display. TODO:DOC are pixels always 24-bit RGB format, aligned on 32-bit boundary? Also: calling this a pixel array may be misleading since 1 pixel > 1 char. */
unsigned char* mPixels;
/** TODO:DOC what's this for -- does a texture have its own piece of shared memory? updated on size_change_request, cleared on shm_remove */
std::string mTextureSegmentName;
/** Width of plugin display in pixels. */
int mWidth;
/** Height of plugin display in pixels. */
int mHeight;
/** Width of plugin texture. */
int mTextureWidth;
/** Height of plugin texture. */
int mTextureHeight;
/** Pixel depth (pixel size in bytes). */
int mDepth;
/** Current status of plugin. */
EStatus mStatus;
/** Map of shared memory segments. */
SharedSegmentMap mSharedSegments;
};
/** The plugin <b>must</b> define this function to create its instance.
* It should look something like this:
* @code
* {
* MediaPluginFoo *self = new MediaPluginFoo(host_send_func, host_user_data);
* *plugin_send_func = MediaPluginFoo::staticReceiveMessage;
* *plugin_user_data = (void*)self;
*
* return 0;
* }
* @endcode
*/
int init_media_plugin(
LLPluginInstance::sendMessageFunction host_send_func,
void *host_user_data,
LLPluginInstance::sendMessageFunction *plugin_send_func,
void **plugin_user_data);

View File

@@ -0,0 +1,86 @@
# -*- cmake -*-
project(media_plugin_example)
if(WORD_SIZE EQUAL 64)
set(REQUIRE_PIC)
endif(WORD_SIZE EQUAL 64)
include(00-Common)
include(LLCommon)
include(LLImage)
include(LLPlugin)
include(LLMath)
include(LLRender)
include(LLWindow)
include(Linking)
include(PluginAPI)
include(MediaPluginBase)
include(FindOpenGL)
include(ExamplePlugin)
include_directories(
${LLPLUGIN_INCLUDE_DIRS}
${MEDIA_PLUGIN_BASE_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLIMAGE_INCLUDE_DIRS}
${LLRENDER_INCLUDE_DIRS}
${LLWINDOW_INCLUDE_DIRS}
)
### media_plugin_example
if(WORD_SIZE EQUAL 64)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif (WORD_SIZE EQUAL 64)
set(media_plugin_example_SOURCE_FILES
media_plugin_example.cpp
)
add_library(media_plugin_example
SHARED
${media_plugin_example_SOURCE_FILES}
)
target_link_libraries(media_plugin_example
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
${EXAMPLE_PLUGIN_LIBRARIES}
${PLUGIN_API_WINDOWS_LIBRARIES}
)
add_dependencies(media_plugin_example
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
)
if (WINDOWS)
set_target_properties(
media_plugin_example
PROPERTIES
LINK_FLAGS "/MANIFEST:NO"
)
endif (WINDOWS)
if (DARWIN)
# Don't prepend 'lib' to the executable name, and don't embed a full path in the library's install name
set_target_properties(
media_plugin_example
PROPERTIES
PREFIX ""
BUILD_WITH_INSTALL_RPATH 1
INSTALL_NAME_DIR "@executable_path"
LINK_FLAGS "-exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/../base/media_plugin_base.exp"
)
endif (DARWIN)

View File

@@ -0,0 +1,488 @@
/**
* @file media_plugin_example.cpp
* @brief Example plugin for LLMedia API plugin system
*
* $LicenseInfo:firstyear=2008&license=viewergpl$
*
* Copyright (c) 2009, Linden Research, Inc.
*
* 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
*
* 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
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llgl.h"
#include "llplugininstance.h"
#include "llpluginmessage.h"
#include "llpluginmessageclasses.h"
#include "media_plugin_base.h"
#include <time.h>
////////////////////////////////////////////////////////////////////////////////
//
class MediaPluginExample :
public MediaPluginBase
{
public:
MediaPluginExample( LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data );
~MediaPluginExample();
/*virtual*/ void receiveMessage( const char* message_string );
private:
bool init();
void update( F64 milliseconds );
void write_pixel( int x, int y, unsigned char r, unsigned char g, unsigned char b );
bool mFirstTime;
time_t mLastUpdateTime;
enum Constants { ENumObjects = 10 };
unsigned char* mBackgroundPixels;
int mColorR[ ENumObjects ];
int mColorG[ ENumObjects ];
int mColorB[ ENumObjects ];
int mXpos[ ENumObjects ];
int mYpos[ ENumObjects ];
int mXInc[ ENumObjects ];
int mYInc[ ENumObjects ];
int mBlockSize[ ENumObjects ];
bool mMouseButtonDown;
bool mStopAction;
};
////////////////////////////////////////////////////////////////////////////////
//
MediaPluginExample::MediaPluginExample( LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data ) :
MediaPluginBase( host_send_func, host_user_data )
{
mFirstTime = true;
mWidth = 0;
mHeight = 0;
mDepth = 4;
mPixels = 0;
mMouseButtonDown = false;
mStopAction = false;
mLastUpdateTime = 0;
}
////////////////////////////////////////////////////////////////////////////////
//
MediaPluginExample::~MediaPluginExample()
{
}
////////////////////////////////////////////////////////////////////////////////
//
void MediaPluginExample::receiveMessage( const char* message_string )
{
LLPluginMessage message_in;
if ( message_in.parse( message_string ) >= 0 )
{
std::string message_class = message_in.getClass();
std::string message_name = message_in.getName();
if ( message_class == LLPLUGIN_MESSAGE_CLASS_BASE )
{
if ( message_name == "init" )
{
LLPluginMessage message( "base", "init_response" );
LLSD versions = LLSD::emptyMap();
versions[ LLPLUGIN_MESSAGE_CLASS_BASE ] = LLPLUGIN_MESSAGE_CLASS_BASE_VERSION;
versions[ LLPLUGIN_MESSAGE_CLASS_MEDIA ] = LLPLUGIN_MESSAGE_CLASS_MEDIA_VERSION;
versions[ LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER ] = LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER_VERSION;
message.setValueLLSD( "versions", versions );
std::string plugin_version = "Example media plugin, Example Version 1.0.0.0";
message.setValue( "plugin_version", plugin_version );
sendMessage( message );
// Plugin gets to decide the texture parameters to use.
message.setMessage( LLPLUGIN_MESSAGE_CLASS_MEDIA, "texture_params" );
message.setValueS32( "default_width", mWidth );
message.setValueS32( "default_height", mHeight );
message.setValueS32( "depth", mDepth );
message.setValueU32( "internalformat", GL_RGBA );
message.setValueU32( "format", GL_RGBA );
message.setValueU32( "type", GL_UNSIGNED_BYTE );
message.setValueBoolean( "coords_opengl", false );
sendMessage( message );
}
else
if ( message_name == "idle" )
{
// no response is necessary here.
F64 time = message_in.getValueReal( "time" );
// Convert time to milliseconds for update()
update( time );
}
else
if ( message_name == "cleanup" )
{
// clean up here
}
else
if ( message_name == "shm_added" )
{
SharedSegmentInfo info;
info.mAddress = message_in.getValuePointer( "address" );
info.mSize = ( size_t )message_in.getValueS32( "size" );
std::string name = message_in.getValue( "name" );
mSharedSegments.insert( SharedSegmentMap::value_type( name, info ) );
}
else
if ( message_name == "shm_remove" )
{
std::string name = message_in.getValue( "name" );
SharedSegmentMap::iterator iter = mSharedSegments.find( name );
if( iter != mSharedSegments.end() )
{
if ( mPixels == iter->second.mAddress )
{
// This is the currently active pixel buffer.
// Make sure we stop drawing to it.
mPixels = NULL;
mTextureSegmentName.clear();
};
mSharedSegments.erase( iter );
}
else
{
//std::cerr << "MediaPluginExample::receiveMessage: unknown shared memory region!" << std::endl;
};
// Send the response so it can be cleaned up.
LLPluginMessage message( "base", "shm_remove_response" );
message.setValue( "name", name );
sendMessage( message );
}
else
{
//std::cerr << "MediaPluginExample::receiveMessage: unknown base message: " << message_name << std::endl;
};
}
else
if ( message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA )
{
if ( message_name == "size_change" )
{
std::string name = message_in.getValue( "name" );
S32 width = message_in.getValueS32( "width" );
S32 height = message_in.getValueS32( "height" );
S32 texture_width = message_in.getValueS32( "texture_width" );
S32 texture_height = message_in.getValueS32( "texture_height" );
if ( ! name.empty() )
{
// Find the shared memory region with this name
SharedSegmentMap::iterator iter = mSharedSegments.find( name );
if ( iter != mSharedSegments.end() )
{
mPixels = ( unsigned char* )iter->second.mAddress;
mWidth = width;
mHeight = height;
mTextureWidth = texture_width;
mTextureHeight = texture_height;
init();
};
};
LLPluginMessage message( LLPLUGIN_MESSAGE_CLASS_MEDIA, "size_change_response" );
message.setValue( "name", name );
message.setValueS32( "width", width );
message.setValueS32( "height", height );
message.setValueS32( "texture_width", texture_width );
message.setValueS32( "texture_height", texture_height );
sendMessage( message );
}
else
if ( message_name == "load_uri" )
{
std::string uri = message_in.getValue( "uri" );
if ( ! uri.empty() )
{
};
}
else
if ( message_name == "mouse_event" )
{
std::string event = message_in.getValue( "event" );
S32 button = message_in.getValueS32( "button" );
// left mouse button
if ( button == 0 )
{
int mouse_x = message_in.getValueS32( "x" );
int mouse_y = message_in.getValueS32( "y" );
std::string modifiers = message_in.getValue( "modifiers" );
if ( event == "move" )
{
if ( mMouseButtonDown )
write_pixel( mouse_x, mouse_y, rand() % 0x80 + 0x80, rand() % 0x80 + 0x80, rand() % 0x80 + 0x80 );
}
else
if ( event == "down" )
{
mMouseButtonDown = true;
}
else
if ( event == "up" )
{
mMouseButtonDown = false;
}
else
if ( event == "double_click" )
{
};
};
}
else
if ( message_name == "key_event" )
{
std::string event = message_in.getValue( "event" );
S32 key = message_in.getValueS32( "key" );
std::string modifiers = message_in.getValue( "modifiers" );
if ( event == "down" )
{
if ( key == ' ')
{
mLastUpdateTime = 0;
update( 0.0f );
};
};
}
else
{
//std::cerr << "MediaPluginExample::receiveMessage: unknown media message: " << message_string << std::endl;
};
}
else
if ( message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER )
{
if ( message_name == "browse_reload" )
{
mLastUpdateTime = 0;
mFirstTime = true;
mStopAction = false;
update( 0.0f );
}
else
if ( message_name == "browse_stop" )
{
for( int n = 0; n < ENumObjects; ++n )
mXInc[ n ] = mYInc[ n ] = 0;
mStopAction = true;
update( 0.0f );
}
else
{
//std::cerr << "MediaPluginExample::receiveMessage: unknown media_browser message: " << message_string << std::endl;
};
}
else
{
//std::cerr << "MediaPluginExample::receiveMessage: unknown message class: " << message_class << std::endl;
};
};
}
////////////////////////////////////////////////////////////////////////////////
//
void MediaPluginExample::write_pixel( int x, int y, unsigned char r, unsigned char g, unsigned char b )
{
// make sure we don't write outside the buffer
if ( ( x < 0 ) || ( x >= mWidth ) || ( y < 0 ) || ( y >= mHeight ) )
return;
if ( mBackgroundPixels != NULL )
{
unsigned char *pixel = mBackgroundPixels;
pixel += y * mWidth * mDepth;
pixel += ( x * mDepth );
pixel[ 0 ] = b;
pixel[ 1 ] = g;
pixel[ 2 ] = r;
setDirty( x, y, x + 1, y + 1 );
};
}
////////////////////////////////////////////////////////////////////////////////
//
void MediaPluginExample::update( F64 milliseconds )
{
if ( mWidth < 1 || mWidth > 2048 || mHeight < 1 || mHeight > 2048 )
return;
if ( mPixels == 0 )
return;
if ( mFirstTime )
{
for( int n = 0; n < ENumObjects; ++n )
{
mXpos[ n ] = ( mWidth / 2 ) + rand() % ( mWidth / 16 ) - ( mWidth / 32 );
mYpos[ n ] = ( mHeight / 2 ) + rand() % ( mHeight / 16 ) - ( mHeight / 32 );
mColorR[ n ] = rand() % 0x60 + 0x60;
mColorG[ n ] = rand() % 0x60 + 0x60;
mColorB[ n ] = rand() % 0x60 + 0x60;
mXInc[ n ] = 0;
while ( mXInc[ n ] == 0 )
mXInc[ n ] = rand() % 7 - 3;
mYInc[ n ] = 0;
while ( mYInc[ n ] == 0 )
mYInc[ n ] = rand() % 9 - 4;
mBlockSize[ n ] = rand() % 0x30 + 0x10;
};
delete [] mBackgroundPixels;
mBackgroundPixels = new unsigned char[ mWidth * mHeight * mDepth ];
mFirstTime = false;
};
if ( mStopAction )
return;
if ( time( NULL ) > mLastUpdateTime + 3 )
{
const int num_squares = rand() % 20 + 4;
int sqr1_r = rand() % 0x80 + 0x20;
int sqr1_g = rand() % 0x80 + 0x20;
int sqr1_b = rand() % 0x80 + 0x20;
int sqr2_r = rand() % 0x80 + 0x20;
int sqr2_g = rand() % 0x80 + 0x20;
int sqr2_b = rand() % 0x80 + 0x20;
for ( int y1 = 0; y1 < num_squares; ++y1 )
{
for ( int x1 = 0; x1 < num_squares; ++x1 )
{
int px_start = mWidth * x1 / num_squares;
int px_end = ( mWidth * ( x1 + 1 ) ) / num_squares;
int py_start = mHeight * y1 / num_squares;
int py_end = ( mHeight * ( y1 + 1 ) ) / num_squares;
for( int y2 = py_start; y2 < py_end; ++y2 )
{
for( int x2 = px_start; x2 < px_end; ++x2 )
{
int rowspan = mWidth * mDepth;
if ( ( y1 % 2 ) ^ ( x1 % 2 ) )
{
mBackgroundPixels[ y2 * rowspan + x2 * mDepth + 0 ] = sqr1_r;
mBackgroundPixels[ y2 * rowspan + x2 * mDepth + 1 ] = sqr1_g;
mBackgroundPixels[ y2 * rowspan + x2 * mDepth + 2 ] = sqr1_b;
}
else
{
mBackgroundPixels[ y2 * rowspan + x2 * mDepth + 0 ] = sqr2_r;
mBackgroundPixels[ y2 * rowspan + x2 * mDepth + 1 ] = sqr2_g;
mBackgroundPixels[ y2 * rowspan + x2 * mDepth + 2 ] = sqr2_b;
};
};
};
};
};
time( &mLastUpdateTime );
};
memcpy( mPixels, mBackgroundPixels, mWidth * mHeight * mDepth );
for( int n = 0; n < ENumObjects; ++n )
{
if ( rand() % 50 == 0 )
{
mXInc[ n ] = 0;
while ( mXInc[ n ] == 0 )
mXInc[ n ] = rand() % 7 - 3;
mYInc[ n ] = 0;
while ( mYInc[ n ] == 0 )
mYInc[ n ] = rand() % 9 - 4;
};
if ( mXpos[ n ] + mXInc[ n ] < 0 || mXpos[ n ] + mXInc[ n ] >= mWidth - mBlockSize[ n ] )
mXInc[ n ] =- mXInc[ n ];
if ( mYpos[ n ] + mYInc[ n ] < 0 || mYpos[ n ] + mYInc[ n ] >= mHeight - mBlockSize[ n ] )
mYInc[ n ] =- mYInc[ n ];
mXpos[ n ] += mXInc[ n ];
mYpos[ n ] += mYInc[ n ];
for( int y = 0; y < mBlockSize[ n ]; ++y )
{
for( int x = 0; x < mBlockSize[ n ]; ++x )
{
mPixels[ ( mXpos[ n ] + x ) * mDepth + ( mYpos[ n ] + y ) * mDepth * mWidth + 0 ] = mColorR[ n ];
mPixels[ ( mXpos[ n ] + x ) * mDepth + ( mYpos[ n ] + y ) * mDepth * mWidth + 1 ] = mColorG[ n ];
mPixels[ ( mXpos[ n ] + x ) * mDepth + ( mYpos[ n ] + y ) * mDepth * mWidth + 2 ] = mColorB[ n ];
};
};
};
setDirty( 0, 0, mWidth, mHeight );
};
////////////////////////////////////////////////////////////////////////////////
//
bool MediaPluginExample::init()
{
LLPluginMessage message( LLPLUGIN_MESSAGE_CLASS_MEDIA, "name_text" );
message.setValue( "name", "Example Plugin" );
sendMessage( message );
return true;
};
////////////////////////////////////////////////////////////////////////////////
//
int init_media_plugin( LLPluginInstance::sendMessageFunction host_send_func,
void* host_user_data,
LLPluginInstance::sendMessageFunction *plugin_send_func,
void **plugin_user_data )
{
MediaPluginExample* self = new MediaPluginExample( host_send_func, host_user_data );
*plugin_send_func = MediaPluginExample::staticReceiveMessage;
*plugin_user_data = ( void* )self;
return 0;
}

View File

@@ -0,0 +1,85 @@
# -*- cmake -*-
project(media_plugin_gstreamer010)
if(WORD_SIZE EQUAL 64)
set(REQUIRE_PIC)
endif(WORD_SIZE EQUAL 64)
include(00-Common)
include(LLCommon)
include(LLImage)
include(LLPlugin)
include(LLMath)
include(LLRender)
include(LLWindow)
include(Linking)
include(PluginAPI)
include(MediaPluginBase)
include(FindOpenGL)
include(GStreamer010Plugin)
include_directories(
${LLPLUGIN_INCLUDE_DIRS}
${MEDIA_PLUGIN_BASE_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLIMAGE_INCLUDE_DIRS}
${LLRENDER_INCLUDE_DIRS}
${LLWINDOW_INCLUDE_DIRS}
${GSTREAMER010_INCLUDE_DIRS}
${GSTREAMER010_PLUGINS_BASE_INCLUDE_DIRS}
)
### media_plugin_gstreamer010
if(WORD_SIZE EQUAL 64)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif (WORD_SIZE EQUAL 64)
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
)
if (LINUX)
if (${CXX_VERSION} GREATER 419)
# Work around a bad interaction between broken gstreamer headers and
# g++ 4.2's increased strictness.
set_source_files_properties(llmediaimplgstreamervidplug.cpp PROPERTIES
COMPILE_FLAGS -Wno-write-strings)
endif (${CXX_VERSION} GREATER 419)
endif (LINUX)
add_library(media_plugin_gstreamer010
SHARED
${media_plugin_gstreamer010_SOURCE_FILES}
)
target_link_libraries(media_plugin_gstreamer010
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
${PLUGIN_API_WINDOWS_LIBRARIES}
${GSTREAMER010_LIBRARIES}
)
add_dependencies(media_plugin_gstreamer010
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
)

View File

@@ -0,0 +1,57 @@
/**
* @file llmediaimplgstreamer.h
* @author Tofu Linden
* @brief implementation that supports media playback via GStreamer.
*
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
// header guard
#ifndef llmediaimplgstreamer_h
#define llmediaimplgstreamer_h
#if LL_GSTREAMER010_ENABLED
extern "C" {
#include <stdio.h>
#include <gst/gst.h>
#include "apr_pools.h"
#include "apr_dso.h"
}
extern "C" {
gboolean llmediaimplgstreamer_bus_callback (GstBus *bus,
GstMessage *message,
gpointer data);
}
#endif // LL_GSTREAMER010_ENABLED
#endif // llmediaimplgstreamer_h

View File

@@ -0,0 +1,171 @@
/**
* @file llmediaimplgstreamer_syms.cpp
* @brief dynamic GStreamer symbol-grabbing code
*
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#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,78 @@
/**
* @file llmediaimplgstreamer_syms.h
* @brief dynamic GStreamer symbol-grabbing code
*
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#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

@@ -0,0 +1,59 @@
/**
* @file llmediaimplgstreamertriviallogging.h
* @brief minimal logging utilities.
*
* $LicenseInfo:firstyear=2009&license=viewergpl$
*
* Copyright (c) 2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#ifndef __LLMEDIAIMPLGSTREAMERTRIVIALLOGGING_H__
#define __LLMEDIAIMPLGSTREAMERTRIVIALLOGGING_H__
#include <cstdio>
extern "C" {
#include <sys/types.h>
#include <unistd.h>
}
/////////////////////////////////////////////////////////////////////////
// Debug/Info/Warning macros.
#define MSGMODULEFOO "(media plugin)"
#define STDERRMSG(...) do{\
fprintf(stderr, " pid:%d: ", (int)getpid());\
fprintf(stderr, MSGMODULEFOO " %s:%d: ", __FUNCTION__, __LINE__);\
fprintf(stderr, __VA_ARGS__);\
fputc('\n',stderr);\
}while(0)
#define NULLMSG(...) do{}while(0)
#define DEBUGMSG NULLMSG
#define INFOMSG STDERRMSG
#define WARNMSG STDERRMSG
/////////////////////////////////////////////////////////////////////////
#endif /* __LLMEDIAIMPLGSTREAMERTRIVIALLOGGING_H__ */

View File

@@ -0,0 +1,531 @@
/**
* @file llmediaimplgstreamervidplug.cpp
* @brief Video-consuming static GStreamer plugin for gst-to-LLMediaImpl
*
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#if LL_GSTREAMER010_ENABLED
#include "linden_common.h"
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideosink.h>
#include "llmediaimplgstreamer_syms.h"
#include "llmediaimplgstreamertriviallogging.h"
#include "llmediaimplgstreamervidplug.h"
GST_DEBUG_CATEGORY_STATIC (gst_slvideo_debug);
#define GST_CAT_DEFAULT gst_slvideo_debug
#define SLV_SIZECAPS ", width=(int)[1,2048], height=(int)[1,2048] "
#define SLV_ALLCAPS GST_VIDEO_CAPS_RGBx SLV_SIZECAPS
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE (
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (SLV_ALLCAPS)
);
GST_BOILERPLATE (GstSLVideo, gst_slvideo, GstVideoSink,
GST_TYPE_VIDEO_SINK);
static void gst_slvideo_set_property (GObject * object, guint prop_id,
const GValue * value,
GParamSpec * pspec);
static void gst_slvideo_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void
gst_slvideo_base_init (gpointer gclass)
{
static GstElementDetails element_details = {
(gchar*)"PluginTemplate",
(gchar*)"Generic/PluginTemplate",
(gchar*)"Generic Template Element",
(gchar*)"Linden Lab"
};
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
llgst_element_class_add_pad_template (element_class,
llgst_static_pad_template_get (&sink_factory));
llgst_element_class_set_details (element_class, &element_details);
}
static void
gst_slvideo_finalize (GObject * object)
{
GstSLVideo *slvideo;
slvideo = GST_SLVIDEO (object);
if (slvideo->caps)
{
llgst_caps_unref(slvideo->caps);
}
G_OBJECT_CLASS(parent_class)->finalize (object);
}
static GstFlowReturn
gst_slvideo_show_frame (GstBaseSink * bsink, GstBuffer * buf)
{
GstSLVideo *slvideo;
llg_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
slvideo = GST_SLVIDEO(bsink);
DEBUGMSG("transferring a frame of %dx%d <- %p (%d)",
slvideo->width, slvideo->height, GST_BUFFER_DATA(buf),
slvideo->format);
if (GST_BUFFER_DATA(buf))
{
// copy frame and frame info into neutral territory
GST_OBJECT_LOCK(slvideo);
slvideo->retained_frame_ready = TRUE;
slvideo->retained_frame_width = slvideo->width;
slvideo->retained_frame_height = slvideo->height;
slvideo->retained_frame_format = slvideo->format;
int rowbytes =
SLVPixelFormatBytes[slvideo->retained_frame_format] *
slvideo->retained_frame_width;
int needbytes = rowbytes * slvideo->retained_frame_width;
// resize retained frame hunk only if necessary
if (needbytes != slvideo->retained_frame_allocbytes)
{
delete[] slvideo->retained_frame_data;
slvideo->retained_frame_data = new unsigned char[needbytes];
slvideo->retained_frame_allocbytes = needbytes;
}
// copy the actual frame data to neutral territory -
// flipped, for GL reasons
for (int ypos=0; ypos<slvideo->height; ++ypos)
{
memcpy(&slvideo->retained_frame_data[(slvideo->height-1-ypos)*rowbytes],
&(((unsigned char*)GST_BUFFER_DATA(buf))[ypos*rowbytes]),
rowbytes);
}
// done with the shared data
GST_OBJECT_UNLOCK(slvideo);
}
return GST_FLOW_OK;
}
static GstStateChangeReturn
gst_slvideo_change_state(GstElement * element, GstStateChange transition)
{
GstSLVideo *slvideo;
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
slvideo = GST_SLVIDEO (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
slvideo->fps_n = 0;
slvideo->fps_d = 1;
GST_VIDEO_SINK_WIDTH(slvideo) = 0;
GST_VIDEO_SINK_HEIGHT(slvideo) = 0;
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
default:
break;
}
return ret;
}
static GstCaps *
gst_slvideo_get_caps (GstBaseSink * bsink)
{
GstSLVideo *slvideo;
slvideo = GST_SLVIDEO(bsink);
return llgst_caps_ref (slvideo->caps);
}
/* this function handles the link with other elements */
static gboolean
gst_slvideo_set_caps (GstBaseSink * bsink, GstCaps * caps)
{
GstSLVideo *filter;
GstStructure *structure;
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
filter = GST_SLVIDEO(bsink);
int width, height;
gboolean ret;
const GValue *fps;
const GValue *par;
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 = llgst_structure_get_value (structure, "pixel-aspect-ratio");
if (!ret)
return FALSE;
INFOMSG("** filter caps set with width=%d, height=%d", width, height);
GST_OBJECT_LOCK(filter);
filter->width = width;
filter->height = height;
filter->fps_n = llgst_value_get_fraction_numerator(fps);
filter->fps_d = llgst_value_get_fraction_denominator(fps);
if (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(llgst_structure_get_name(structure),
"video/x-raw-rgb"))
{
int red_mask;
int green_mask;
int 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)
{
filter->format = SLV_PF_RGBX;
//fprintf(stderr, "\n\nPIXEL FORMAT RGB\n\n");
} else if ((unsigned int)red_mask == 0x0000FF00 &&
(unsigned int)green_mask == 0x00FF0000 &&
(unsigned int)blue_mask == 0xFF000000)
{
filter->format = SLV_PF_BGRX;
//fprintf(stderr, "\n\nPIXEL FORMAT BGR\n\n");
}
}*/
filter->format = SLV_PF_RGBX;
GST_OBJECT_UNLOCK(filter);
return TRUE;
}
static gboolean
gst_slvideo_start (GstBaseSink * bsink)
{
GstSLVideo *slvideo;
gboolean ret = TRUE;
slvideo = GST_SLVIDEO(bsink);
return ret;
}
static gboolean
gst_slvideo_stop (GstBaseSink * bsink)
{
GstSLVideo *slvideo;
slvideo = GST_SLVIDEO(bsink);
// free-up retained frame buffer
GST_OBJECT_LOCK(slvideo);
slvideo->retained_frame_ready = FALSE;
delete[] slvideo->retained_frame_data;
slvideo->retained_frame_data = NULL;
slvideo->retained_frame_allocbytes = 0;
GST_OBJECT_UNLOCK(slvideo);
return TRUE;
}
static GstFlowReturn
gst_slvideo_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
GstCaps * caps, GstBuffer ** buf)
{
gint width, height;
GstStructure *structure = NULL;
GstSLVideo *slvideo;
slvideo = GST_SLVIDEO(bsink);
// caps == requested caps
// 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 = 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 = llgst_buffer_new();
bool made_bufferdata_ptr = false;
#define MAXDEPTHHACK 4
GST_OBJECT_LOCK(slvideo);
if (slvideo->resize_forced_always) // app is giving us a fixed size to work with
{
gint slwantwidth, slwantheight;
slwantwidth = slvideo->resize_try_width;
slwantheight = slvideo->resize_try_height;
if (slwantwidth != width ||
slwantheight != height)
{
// don't like requested caps, we will issue our own suggestion - copy
// the requested caps but substitute our own width and height and see
// if our peer is happy with that.
GstCaps *desired_caps;
GstStructure *desired_struct;
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);
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);
llgst_structure_set_value (desired_struct, "height", &value);
if (llgst_pad_peer_accept_caps (GST_VIDEO_SINK_PAD (slvideo),
desired_caps))
{
// todo: re-use buffers from a pool?
// todo: set MALLOCDATA to null, set DATA to point straight to shm?
// peer likes our cap suggestion
DEBUGMSG("peer loves us :)");
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);
llgst_buffer_set_caps (GST_BUFFER_CAST(newbuf), desired_caps);
made_bufferdata_ptr = true;
} else {
// peer hates our cap suggestion
INFOMSG("peer hates us :(");
llgst_caps_unref(desired_caps);
}
}
}
GST_OBJECT_UNLOCK(slvideo);
if (!made_bufferdata_ptr) // need to fallback to malloc at original 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);
llgst_buffer_set_caps (GST_BUFFER_CAST(newbuf), caps);
}
*buf = GST_BUFFER_CAST(newbuf);
return GST_FLOW_OK;
}
/* initialize the plugin's class */
static void
gst_slvideo_class_init (GstSLVideoClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
GstBaseSinkClass *gstbasesink_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gstbasesink_class = (GstBaseSinkClass *) klass;
gobject_class->finalize = gst_slvideo_finalize;
gobject_class->set_property = gst_slvideo_set_property;
gobject_class->get_property = gst_slvideo_get_property;
gstelement_class->change_state = gst_slvideo_change_state;
#define LLGST_DEBUG_FUNCPTR(p) (p)
gstbasesink_class->get_caps = LLGST_DEBUG_FUNCPTR (gst_slvideo_get_caps);
gstbasesink_class->set_caps = LLGST_DEBUG_FUNCPTR( gst_slvideo_set_caps);
gstbasesink_class->buffer_alloc=LLGST_DEBUG_FUNCPTR(gst_slvideo_buffer_alloc);
//gstbasesink_class->get_times = LLGST_DEBUG_FUNCPTR (gst_slvideo_get_times);
gstbasesink_class->preroll = LLGST_DEBUG_FUNCPTR (gst_slvideo_show_frame);
gstbasesink_class->render = LLGST_DEBUG_FUNCPTR (gst_slvideo_show_frame);
gstbasesink_class->start = LLGST_DEBUG_FUNCPTR (gst_slvideo_start);
gstbasesink_class->stop = LLGST_DEBUG_FUNCPTR (gst_slvideo_stop);
// gstbasesink_class->unlock = LLGST_DEBUG_FUNCPTR (gst_slvideo_unlock);
#undef LLGST_DEBUG_FUNCPTR
}
/* initialize the new element
* instantiate pads and add them to element
* set functions
* initialize structure
*/
static void
gst_slvideo_init (GstSLVideo * filter,
GstSLVideoClass * gclass)
{
filter->caps = NULL;
filter->width = -1;
filter->height = -1;
// this is the info we share with the client app
GST_OBJECT_LOCK(filter);
filter->retained_frame_ready = FALSE;
filter->retained_frame_data = NULL;
filter->retained_frame_allocbytes = 0;
filter->retained_frame_width = filter->width;
filter->retained_frame_height = filter->height;
filter->retained_frame_format = SLV_PF_UNKNOWN;
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);
}
static void
gst_slvideo_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
llg_return_if_fail (GST_IS_SLVIDEO (object));
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_slvideo_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
llg_return_if_fail (GST_IS_SLVIDEO (object));
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/* entry point to initialize the plug-in
* initialize the plug-in itself
* register the element factories and pad templates
* register the features
*/
static gboolean
plugin_init (GstPlugin * plugin)
{
DEBUGMSG("PLUGIN INIT");
GST_DEBUG_CATEGORY_INIT (gst_slvideo_debug, (gchar*)"private-slvideo-plugin",
0, (gchar*)"Second Life Video Sink");
return llgst_element_register (plugin, "private-slvideo",
GST_RANK_NONE, GST_TYPE_SLVIDEO);
}
/* this is the structure that gstreamer looks for to register plugins
*/
/* NOTE: Can't rely upon GST_PLUGIN_DEFINE_STATIC to self-register, since
some g++ versions buggily avoid __attribute__((constructor)) functions -
so we provide an explicit plugin init function.
*/
void gst_slvideo_init_class (void)
{
#define PACKAGE "packagehack"
// this macro quietly refers to PACKAGE internally
static GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"private-slvideoplugin",
"SL Video sink plugin",
plugin_init, "0.1", GST_LICENSE_UNKNOWN,
"Second Life",
"http://www.secondlife.com/");
#undef PACKAGE
ll_gst_plugin_register_static (&gst_plugin_desc);
DEBUGMSG("CLASS INIT");
}
#endif // LL_GSTREAMER010_ENABLED

View File

@@ -0,0 +1,109 @@
/**
* @file llmediaimplgstreamervidplug.h
* @brief Video-consuming static GStreamer plugin for gst-to-LLMediaImpl
*
* $LicenseInfo:firstyear=2007&license=viewergpl$
*
* Copyright (c) 2007-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#ifndef __GST_SLVIDEO_H__
#define __GST_SLVIDEO_H__
#if LL_GSTREAMER010_ENABLED
extern "C" {
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideosink.h>
}
G_BEGIN_DECLS
/* #defines don't like whitespacey bits */
#define GST_TYPE_SLVIDEO \
(gst_slvideo_get_type())
#define GST_SLVIDEO(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SLVIDEO,GstSLVideo))
#define GST_SLVIDEO_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SLVIDEO,GstSLVideoClass))
#define GST_IS_SLVIDEO(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SLVIDEO))
#define GST_IS_SLVIDEO_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SLVIDEO))
typedef struct _GstSLVideo GstSLVideo;
typedef struct _GstSLVideoClass GstSLVideoClass;
typedef enum {
SLV_PF_UNKNOWN = 0,
SLV_PF_RGBX = 1,
SLV_PF_BGRX = 2,
SLV__END = 3
} SLVPixelFormat;
const int SLVPixelFormatBytes[SLV__END] = {1, 4, 4};
struct _GstSLVideo
{
GstVideoSink video_sink;
GstCaps *caps;
int fps_n, fps_d;
int par_n, par_d;
int height, width;
SLVPixelFormat format;
// SHARED WITH APPLICATION:
// Access to the following should be protected by GST_OBJECT_LOCK() on
// the GstSLVideo object, and should be totally consistent upon UNLOCK
// (i.e. all written at once to reflect the current retained frame info
// when the retained frame is updated.)
bool retained_frame_ready; // new frame ready since flag last reset. (*TODO: could get the writer to wait on a semaphore instead of having the reader poll, potentially making dropped frames somewhat cheaper.)
unsigned char* retained_frame_data;
int retained_frame_allocbytes;
int retained_frame_width, retained_frame_height;
SLVPixelFormat retained_frame_format;
// sticky resize info
bool resize_forced_always;
int resize_try_width;
int resize_try_height;
};
struct _GstSLVideoClass
{
GstVideoSinkClass parent_class;
};
GType gst_slvideo_get_type (void);
void gst_slvideo_init_class (void);
G_END_DECLS
#endif // LL_GSTREAMER010_ENABLED
#endif /* __GST_SLVIDEO_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,91 @@
# -*- cmake -*-
project(media_plugin_quicktime)
include(00-Common)
include(LLCommon)
include(LLImage)
include(LLPlugin)
include(LLMath)
include(LLRender)
include(LLWindow)
include(Linking)
include(PluginAPI)
include(MediaPluginBase)
include(FindOpenGL)
include(QuickTimePlugin)
include_directories(
${LLPLUGIN_INCLUDE_DIRS}
${MEDIA_PLUGIN_BASE_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLIMAGE_INCLUDE_DIRS}
${LLRENDER_INCLUDE_DIRS}
${LLWINDOW_INCLUDE_DIRS}
)
if (DARWIN)
include(CMakeFindFrameworks)
find_library(CARBON_LIBRARY Carbon)
endif (DARWIN)
### media_plugin_quicktime
set(media_plugin_quicktime_SOURCE_FILES
media_plugin_quicktime.cpp
)
add_library(media_plugin_quicktime
SHARED
${media_plugin_quicktime_SOURCE_FILES}
)
target_link_libraries(media_plugin_quicktime
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
${QUICKTIME_LIBRARY}
${PLUGIN_API_WINDOWS_LIBRARIES}
)
add_dependencies(media_plugin_quicktime
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
)
if (WINDOWS)
set_target_properties(
media_plugin_quicktime
PROPERTIES
LINK_FLAGS "/MANIFEST:NO"
)
endif (WINDOWS)
if (QUICKTIME)
add_definitions(-DLL_QUICKTIME_ENABLED=1)
if (DARWIN)
# Don't prepend 'lib' to the executable name, and don't embed a full path in the library's install name
set_target_properties(
media_plugin_quicktime
PROPERTIES
PREFIX ""
BUILD_WITH_INSTALL_RPATH 1
INSTALL_NAME_DIR "@executable_path"
LINK_FLAGS "-exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/../base/media_plugin_base.exp"
)
# We use a bunch of deprecated system APIs.
set_source_files_properties(
media_plugin_quicktime.cpp PROPERTIES
COMPILE_FLAGS -Wno-deprecated-declarations
)
find_library(CARBON_LIBRARY Carbon)
target_link_libraries(media_plugin_quicktime ${CARBON_LIBRARY})
endif (DARWIN)
endif (QUICKTIME)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
# -*- cmake -*-
project(media_plugin_webkit)
if(WORD_SIZE EQUAL 64)
set(REQUIRE_PIC)
endif(WORD_SIZE EQUAL 64)
include(00-Common)
include(LLCommon)
include(LLImage)
include(LLPlugin)
include(LLMath)
include(LLRender)
include(LLWindow)
include(Linking)
include(PluginAPI)
include(MediaPluginBase)
include(FindOpenGL)
include(WebKitLibPlugin)
include_directories(
${LLPLUGIN_INCLUDE_DIRS}
${MEDIA_PLUGIN_BASE_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLIMAGE_INCLUDE_DIRS}
${LLRENDER_INCLUDE_DIRS}
${LLWINDOW_INCLUDE_DIRS}
)
### media_plugin_webkit
set(media_plugin_webkit_SOURCE_FILES
media_plugin_webkit.cpp
)
if(WORD_SIZE EQUAL 64)
if(WINDOWS)
add_definitions(/FIXED:NO)
else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
add_definitions(-fPIC)
endif(WINDOWS)
endif (WORD_SIZE EQUAL 64)
add_library(media_plugin_webkit
SHARED
${media_plugin_webkit_SOURCE_FILES}
)
target_link_libraries(media_plugin_webkit
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
${WEBKIT_PLUGIN_LIBRARIES}
${PLUGIN_API_WINDOWS_LIBRARIES}
)
add_dependencies(media_plugin_webkit
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
${LLCOMMON_LIBRARIES}
)
if (WINDOWS)
set_target_properties(
media_plugin_webkit
PROPERTIES
LINK_FLAGS "/MANIFEST:NO"
)
endif (WINDOWS)
if (DARWIN)
# Don't prepend 'lib' to the executable name, and don't embed a full path in the library's install name
set_target_properties(
media_plugin_webkit
PROPERTIES
PREFIX ""
BUILD_WITH_INSTALL_RPATH 1
INSTALL_NAME_DIR "@executable_path"
LINK_FLAGS "-exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/../base/media_plugin_base.exp"
)
# copy the webkit dylib to the build directory
add_custom_command(
TARGET media_plugin_webkit POST_BUILD
# OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/libllqtwebkit.dylib
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/../libraries/universal-darwin/lib_release/libllqtwebkit.dylib ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/
DEPENDS media_plugin_webkit ${CMAKE_SOURCE_DIR}/../libraries/universal-darwin/lib_release/libllqtwebkit.dylib
)
endif (DARWIN)

View File

@@ -0,0 +1,957 @@
/**
* @file media_plugin_webkit.cpp
* @brief Webkit plugin for LLMedia API plugin system
*
* $LicenseInfo:firstyear=2008&license=viewergpl$
*
* Copyright (c) 2008-2009, Linden Research, Inc.
*
* 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://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* 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://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llqtwebkit.h"
#include "linden_common.h"
#include "indra_constants.h" // for indra keyboard codes
#include "llgl.h"
#include "llplugininstance.h"
#include "llpluginmessage.h"
#include "llpluginmessageclasses.h"
#include "media_plugin_base.h"
#if LL_WINDOWS
#include <direct.h>
#else
#include <unistd.h>
#include <stdlib.h>
#endif
#if LL_WINDOWS
// NOTE - This captures the module handle of the dll. This is used below
// to get the path to this dll for webkit initialization.
// I don't know how/if this can be done with apr...
namespace { HMODULE gModuleHandle;};
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
gModuleHandle = (HMODULE) hinstDLL;
return TRUE;
}
#endif
////////////////////////////////////////////////////////////////////////////////
//
class MediaPluginWebKit :
public MediaPluginBase,
public LLEmbeddedBrowserWindowObserver
{
public:
MediaPluginWebKit(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data);
~MediaPluginWebKit();
/*virtual*/ void receiveMessage(const char *message_string);
private:
std::string mProfileDir;
enum
{
INIT_STATE_UNINITIALIZED, // Browser instance hasn't been set up yet
INIT_STATE_NAVIGATING, // Browser instance has been set up and initial navigate to about:blank has been issued
INIT_STATE_NAVIGATE_COMPLETE, // initial navigate to about:blank has completed
INIT_STATE_WAIT_REDRAW, // First real navigate begin has been received, waiting for page changed event to start handling redraws
INIT_STATE_RUNNING // All initialization gymnastics are complete.
};
int mBrowserWindowId;
int mInitState;
std::string mInitialNavigateURL;
bool mNeedsUpdate;
bool mCanCut;
bool mCanCopy;
bool mCanPaste;
int mLastMouseX;
int mLastMouseY;
bool mFirstFocus;
void setInitState(int state)
{
// std::cerr << "changing init state to " << state << std::endl;
mInitState = state;
}
////////////////////////////////////////////////////////////////////////////////
//
void update(int milliseconds)
{
LLQtWebKit::getInstance()->pump( milliseconds );
checkEditState();
if(mInitState == INIT_STATE_NAVIGATE_COMPLETE)
{
if(!mInitialNavigateURL.empty())
{
// We already have the initial navigate URL -- kick off the navigate.
LLQtWebKit::getInstance()->navigateTo( mBrowserWindowId, mInitialNavigateURL );
mInitialNavigateURL.clear();
}
}
if ( (mInitState == INIT_STATE_RUNNING) && mNeedsUpdate )
{
const unsigned char* browser_pixels = LLQtWebKit::getInstance()->grabBrowserWindow( mBrowserWindowId );
unsigned int buffer_size = LLQtWebKit::getInstance()->getBrowserRowSpan( mBrowserWindowId ) * LLQtWebKit::getInstance()->getBrowserHeight( mBrowserWindowId );
// std::cerr << "webkit plugin: updating" << std::endl;
// TODO: should get rid of this memcpy if possible
if ( mPixels && browser_pixels )
{
// std::cerr << " memcopy of " << buffer_size << " bytes" << std::endl;
memcpy( mPixels, browser_pixels, buffer_size );
}
if ( mWidth > 0 && mHeight > 0 )
{
// std::cerr << "Setting dirty, " << mWidth << " x " << mHeight << std::endl;
setDirty( 0, 0, mWidth, mHeight );
}
mNeedsUpdate = false;
};
};
////////////////////////////////////////////////////////////////////////////////
//
bool initBrowser()
{
// already initialized
if ( mInitState > INIT_STATE_UNINITIALIZED )
return true;
// not enough information to initialize the browser yet.
if ( mWidth < 0 || mHeight < 0 || mDepth < 0 ||
mTextureWidth < 0 || mTextureHeight < 0 )
{
return false;
};
// set up directories
char cwd[ FILENAME_MAX ]; // I *think* this is defined on all platforms we use
if (NULL == getcwd( cwd, FILENAME_MAX - 1 ))
{
llwarns << "Couldn't get cwd - probably too long - failing to init." << llendl;
return false;
}
std::string application_dir = std::string( cwd );
#if LL_WINDOWS
// NOTE - On windows, at least, the component path is the
// location of this dll's image file.
std::string component_dir;
char dll_path[_MAX_PATH];
DWORD len = GetModuleFileNameA(gModuleHandle, (LPCH)&dll_path, _MAX_PATH);
while(len && dll_path[ len ] != ('\\') )
{
len--;
}
if(len >= 0)
{
dll_path[len] = 0;
component_dir = dll_path;
}
else
{
// NOTE - This case should be a rare exception.
// GetModuleFileNameA should always give you a full path.
component_dir = application_dir;
}
#else
std::string component_dir = application_dir;
#endif
// window handle - needed on Windows and must be app window.
#if LL_WINDOWS
char window_title[ MAX_PATH ];
GetConsoleTitleA( window_title, MAX_PATH );
void* native_window_handle = (void*)FindWindowA( NULL, window_title );
#else
void* native_window_handle = 0;
#endif
// main browser initialization
bool result = LLQtWebKit::getInstance()->init( application_dir, component_dir, mProfileDir, native_window_handle );
if ( result )
{
// create single browser window
mBrowserWindowId = LLQtWebKit::getInstance()->createBrowserWindow( mWidth, mHeight );
#if LL_WINDOWS
// Enable plugins
LLQtWebKit::getInstance()->enablePlugins(true);
#elif LL_DARWIN
// Enable plugins
LLQtWebKit::getInstance()->enablePlugins(true);
#elif LL_LINUX
// Enable plugins
LLQtWebKit::getInstance()->enablePlugins(true);
#endif
// Enable cookies
LLQtWebKit::getInstance()->enableCookies( true );
// tell LLQtWebKit about the size of the browser window
LLQtWebKit::getInstance()->setSize( mBrowserWindowId, mWidth, mHeight );
// observer events that LLQtWebKit emits
LLQtWebKit::getInstance()->addObserver( mBrowserWindowId, this );
// append details to agent string
LLQtWebKit::getInstance()->setBrowserAgentId( "LLPluginMedia Web Browser" );
// don't flip bitmap
LLQtWebKit::getInstance()->flipWindow( mBrowserWindowId, true );
// set background color to be black - mostly for initial login page
LLQtWebKit::getInstance()->setBackgroundColor( mBrowserWindowId, 0x00, 0x00, 0x00 );
// Set state _before_ starting the navigate, since onNavigateBegin might get called before this call returns.
setInitState(INIT_STATE_NAVIGATING);
// Don't do this here -- it causes the dreaded "white flash" when loading a browser instance.
// FIXME: Re-added this because navigating to a "page" initializes things correctly - especially
// for the HTTP AUTH dialog issues (DEV-41731). Will fix at a later date.
LLQtWebKit::getInstance()->navigateTo( mBrowserWindowId, "about:blank" );
return true;
};
return false;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onCursorChanged(const EventType& event)
{
LLQtWebKit::ECursor llqt_cursor = (LLQtWebKit::ECursor)event.getIntValue();
std::string name;
switch(llqt_cursor)
{
case LLQtWebKit::C_ARROW:
name = "arrow";
break;
case LLQtWebKit::C_IBEAM:
name = "ibeam";
break;
case LLQtWebKit::C_SPLITV:
name = "splitv";
break;
case LLQtWebKit::C_SPLITH:
name = "splith";
break;
case LLQtWebKit::C_POINTINGHAND:
name = "hand";
break;
default:
llwarns << "Unknown cursor ID: " << (int)llqt_cursor << llendl;
break;
}
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "cursor_changed");
message.setValue("name", name);
sendMessage(message);
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onPageChanged( const EventType& event )
{
if(mInitState == INIT_STATE_WAIT_REDRAW)
{
setInitState(INIT_STATE_RUNNING);
}
// flag that an update is required
mNeedsUpdate = true;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onNavigateBegin(const EventType& event)
{
if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "navigate_begin");
message.setValue("uri", event.getEventUri());
sendMessage(message);
setStatus(STATUS_LOADING);
}
if(mInitState == INIT_STATE_NAVIGATE_COMPLETE)
{
setInitState(INIT_STATE_WAIT_REDRAW);
}
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onNavigateComplete(const EventType& event)
{
if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "navigate_complete");
message.setValue("uri", event.getEventUri());
message.setValueS32("result_code", event.getIntValue());
message.setValue("result_string", event.getStringValue());
message.setValueBoolean("history_back_available", LLQtWebKit::getInstance()->userActionIsEnabled( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_BACK));
message.setValueBoolean("history_forward_available", LLQtWebKit::getInstance()->userActionIsEnabled( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_FORWARD));
sendMessage(message);
setStatus(STATUS_LOADED);
}
else if(mInitState == INIT_STATE_NAVIGATING)
{
setInitState(INIT_STATE_NAVIGATE_COMPLETE);
}
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onUpdateProgress(const EventType& event)
{
if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "progress");
message.setValueS32("percent", event.getIntValue());
sendMessage(message);
}
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onStatusTextChange(const EventType& event)
{
if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "status_text");
message.setValue("status", event.getStringValue());
sendMessage(message);
}
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onTitleChange(const EventType& event)
{
if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "name_text");
message.setValue("name", event.getStringValue());
sendMessage(message);
}
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onLocationChange(const EventType& event)
{
if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "location_changed");
message.setValue("uri", event.getEventUri());
sendMessage(message);
}
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onClickLinkHref(const EventType& event)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_href");
message.setValue("uri", event.getStringValue());
message.setValue("target", event.getStringValue2());
sendMessage(message);
}
////////////////////////////////////////////////////////////////////////////////
// virtual
void onClickLinkNoFollow(const EventType& event)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_nofollow");
message.setValue("uri", event.getStringValue());
sendMessage(message);
}
LLQtWebKit::EKeyboardModifier decodeModifiers(std::string &modifiers)
{
int result = 0;
if(modifiers.find("shift") != std::string::npos)
result |= LLQtWebKit::KM_MODIFIER_SHIFT;
if(modifiers.find("alt") != std::string::npos)
result |= LLQtWebKit::KM_MODIFIER_ALT;
if(modifiers.find("control") != std::string::npos)
result |= LLQtWebKit::KM_MODIFIER_CONTROL;
if(modifiers.find("meta") != std::string::npos)
result |= LLQtWebKit::KM_MODIFIER_META;
return (LLQtWebKit::EKeyboardModifier)result;
}
////////////////////////////////////////////////////////////////////////////////
//
void keyEvent(LLQtWebKit::EKeyEvent key_event, int key, LLQtWebKit::EKeyboardModifier modifiers)
{
int llqt_key;
// The incoming values for 'key' will be the ones from indra_constants.h
// the outgoing values are the ones from llqtwebkit.h
switch((KEY)key)
{
// This is the list that the llqtwebkit implementation actually maps into Qt keys.
// case KEY_XXX: llqt_key = LL_DOM_VK_CANCEL; break;
// case KEY_XXX: llqt_key = LL_DOM_VK_HELP; break;
case KEY_BACKSPACE: llqt_key = LL_DOM_VK_BACK_SPACE; break;
case KEY_TAB: llqt_key = LL_DOM_VK_TAB; break;
// case KEY_XXX: llqt_key = LL_DOM_VK_CLEAR; break;
case KEY_RETURN: llqt_key = LL_DOM_VK_RETURN; break;
case KEY_PAD_RETURN: llqt_key = LL_DOM_VK_ENTER; break;
case KEY_SHIFT: llqt_key = LL_DOM_VK_SHIFT; break;
case KEY_CONTROL: llqt_key = LL_DOM_VK_CONTROL; break;
case KEY_ALT: llqt_key = LL_DOM_VK_ALT; break;
// case KEY_XXX: llqt_key = LL_DOM_VK_PAUSE; break;
case KEY_CAPSLOCK: llqt_key = LL_DOM_VK_CAPS_LOCK; break;
case KEY_ESCAPE: llqt_key = LL_DOM_VK_ESCAPE; break;
case KEY_PAGE_UP: llqt_key = LL_DOM_VK_PAGE_UP; break;
case KEY_PAGE_DOWN: llqt_key = LL_DOM_VK_PAGE_DOWN; break;
case KEY_END: llqt_key = LL_DOM_VK_END; break;
case KEY_HOME: llqt_key = LL_DOM_VK_HOME; break;
case KEY_LEFT: llqt_key = LL_DOM_VK_LEFT; break;
case KEY_UP: llqt_key = LL_DOM_VK_UP; break;
case KEY_RIGHT: llqt_key = LL_DOM_VK_RIGHT; break;
case KEY_DOWN: llqt_key = LL_DOM_VK_DOWN; break;
// case KEY_XXX: llqt_key = LL_DOM_VK_PRINTSCREEN; break;
case KEY_INSERT: llqt_key = LL_DOM_VK_INSERT; break;
case KEY_DELETE: llqt_key = LL_DOM_VK_DELETE; break;
// case KEY_XXX: llqt_key = LL_DOM_VK_CONTEXT_MENU; break;
default:
if(key < KEY_SPECIAL)
{
// Pass the incoming key through -- it should be regular ASCII, which should be correct for webkit.
llqt_key = key;
}
else
{
// Don't pass through untranslated special keys -- they'll be all wrong.
llqt_key = 0;
}
break;
}
// std::cerr << "keypress, original code = 0x" << std::hex << key << ", converted code = 0x" << std::hex << llqt_key << std::dec << std::endl;
if(llqt_key != 0)
{
LLQtWebKit::getInstance()->keyEvent( mBrowserWindowId, key_event, llqt_key, modifiers);
}
checkEditState();
};
////////////////////////////////////////////////////////////////////////////////
//
void unicodeInput( const std::string &utf8str, LLQtWebKit::EKeyboardModifier modifiers)
{
LLWString wstr = utf8str_to_wstring(utf8str);
unsigned int i;
for(i=0; i < wstr.size(); i++)
{
// std::cerr << "unicode input, code = 0x" << std::hex << (unsigned long)(wstr[i]) << std::dec << std::endl;
if(wstr[i] == 32)
{
// For some reason, the webkit plugin really wants the space bar to come in through the key-event path, not the unicode path.
LLQtWebKit::getInstance()->keyEvent( mBrowserWindowId, LLQtWebKit::KE_KEY_DOWN, 32, modifiers);
LLQtWebKit::getInstance()->keyEvent( mBrowserWindowId, LLQtWebKit::KE_KEY_UP, 32, modifiers);
}
else
{
LLQtWebKit::getInstance()->unicodeInput(mBrowserWindowId, wstr[i], modifiers);
}
}
checkEditState();
};
void checkEditState(void)
{
bool can_cut = LLQtWebKit::getInstance()->userActionIsEnabled( mBrowserWindowId, LLQtWebKit::UA_EDIT_CUT);
bool can_copy = LLQtWebKit::getInstance()->userActionIsEnabled( mBrowserWindowId, LLQtWebKit::UA_EDIT_COPY);
bool can_paste = LLQtWebKit::getInstance()->userActionIsEnabled( mBrowserWindowId, LLQtWebKit::UA_EDIT_PASTE);
if((can_cut != mCanCut) || (can_copy != mCanCopy) || (can_paste != mCanPaste))
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "edit_state");
if(can_cut != mCanCut)
{
mCanCut = can_cut;
message.setValueBoolean("cut", can_cut);
}
if(can_copy != mCanCopy)
{
mCanCopy = can_copy;
message.setValueBoolean("copy", can_copy);
}
if(can_paste != mCanPaste)
{
mCanPaste = can_paste;
message.setValueBoolean("paste", can_paste);
}
sendMessage(message);
}
}
};
MediaPluginWebKit::MediaPluginWebKit(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data) :
MediaPluginBase(host_send_func, host_user_data)
{
// std::cerr << "MediaPluginWebKit constructor" << std::endl;
mBrowserWindowId = 0;
mInitState = INIT_STATE_UNINITIALIZED;
mNeedsUpdate = true;
mCanCut = false;
mCanCopy = false;
mCanPaste = false;
mLastMouseX = 0;
mLastMouseY = 0;
mFirstFocus = true;
}
MediaPluginWebKit::~MediaPluginWebKit()
{
// unhook observer
LLQtWebKit::getInstance()->remObserver( mBrowserWindowId, this );
// clean up
LLQtWebKit::getInstance()->reset();
// std::cerr << "MediaPluginWebKit destructor" << std::endl;
}
void MediaPluginWebKit::receiveMessage(const char *message_string)
{
// std::cerr << "MediaPluginWebKit::receiveMessage: received message: \"" << message_string << "\"" << std::endl;
LLPluginMessage message_in;
if(message_in.parse(message_string) >= 0)
{
std::string message_class = message_in.getClass();
std::string message_name = message_in.getName();
if(message_class == LLPLUGIN_MESSAGE_CLASS_BASE)
{
if(message_name == "init")
{
std::string user_data_path = message_in.getValue("user_data_path"); // n.b. always has trailing platform-specific dir-delimiter
mProfileDir = user_data_path + "browser_profile";
LLPluginMessage message("base", "init_response");
LLSD versions = LLSD::emptyMap();
versions[LLPLUGIN_MESSAGE_CLASS_BASE] = LLPLUGIN_MESSAGE_CLASS_BASE_VERSION;
versions[LLPLUGIN_MESSAGE_CLASS_MEDIA] = LLPLUGIN_MESSAGE_CLASS_MEDIA_VERSION;
versions[LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER] = LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER_VERSION;
message.setValueLLSD("versions", versions);
std::string plugin_version = "Webkit media plugin, Webkit version ";
plugin_version += LLQtWebKit::getInstance()->getVersion();
message.setValue("plugin_version", plugin_version);
sendMessage(message);
// Plugin gets to decide the texture parameters to use.
mDepth = 4;
message.setMessage(LLPLUGIN_MESSAGE_CLASS_MEDIA, "texture_params");
message.setValueS32("default_width", 1024);
message.setValueS32("default_height", 1024);
message.setValueS32("depth", mDepth);
message.setValueU32("internalformat", GL_RGBA);
message.setValueU32("format", GL_RGBA);
message.setValueU32("type", GL_UNSIGNED_BYTE);
message.setValueBoolean("coords_opengl", true);
sendMessage(message);
}
else if(message_name == "idle")
{
// no response is necessary here.
F64 time = message_in.getValueReal("time");
// Convert time to milliseconds for update()
update((int)(time * 1000.0f));
}
else if(message_name == "cleanup")
{
// DTOR most likely won't be called but the recent change to the way this process
// is (not) killed means we see this message and can do what we need to here.
// Note: this cleanup is ultimately what writes cookies to the disk
LLQtWebKit::getInstance()->remObserver( mBrowserWindowId, this );
LLQtWebKit::getInstance()->reset();
}
else if(message_name == "shm_added")
{
SharedSegmentInfo info;
info.mAddress = message_in.getValuePointer("address");
info.mSize = (size_t)message_in.getValueS32("size");
std::string name = message_in.getValue("name");
// std::cerr << "MediaPluginWebKit::receiveMessage: shared memory added, name: " << name
// << ", size: " << info.mSize
// << ", address: " << info.mAddress
// << std::endl;
mSharedSegments.insert(SharedSegmentMap::value_type(name, info));
}
else if(message_name == "shm_remove")
{
std::string name = message_in.getValue("name");
// std::cerr << "MediaPluginWebKit::receiveMessage: shared memory remove, name = " << name << std::endl;
SharedSegmentMap::iterator iter = mSharedSegments.find(name);
if(iter != mSharedSegments.end())
{
if(mPixels == iter->second.mAddress)
{
// This is the currently active pixel buffer. Make sure we stop drawing to it.
mPixels = NULL;
mTextureSegmentName.clear();
}
mSharedSegments.erase(iter);
}
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown shared memory region!" << std::endl;
}
// Send the response so it can be cleaned up.
LLPluginMessage message("base", "shm_remove_response");
message.setValue("name", name);
sendMessage(message);
}
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown base message: " << message_name << std::endl;
}
}
else if(message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA)
{
if(message_name == "size_change")
{
std::string name = message_in.getValue("name");
S32 width = message_in.getValueS32("width");
S32 height = message_in.getValueS32("height");
S32 texture_width = message_in.getValueS32("texture_width");
S32 texture_height = message_in.getValueS32("texture_height");
if(!name.empty())
{
// Find the shared memory region with this name
SharedSegmentMap::iterator iter = mSharedSegments.find(name);
if(iter != mSharedSegments.end())
{
mPixels = (unsigned char*)iter->second.mAddress;
mWidth = width;
mHeight = height;
// initialize (only gets called once)
initBrowser();
// size changed so tell the browser
LLQtWebKit::getInstance()->setSize( mBrowserWindowId, mWidth, mHeight );
// std::cerr << "webkit plugin: set size to " << mWidth << " x " << mHeight
// << ", rowspan is " << LLQtWebKit::getInstance()->getBrowserRowSpan(mBrowserWindowId) << std::endl;
S32 real_width = LLQtWebKit::getInstance()->getBrowserRowSpan(mBrowserWindowId) / LLQtWebKit::getInstance()->getBrowserDepth(mBrowserWindowId);
// The actual width the browser will be drawing to is probably smaller... let the host know by modifying texture_width in the response.
if(real_width <= texture_width)
{
texture_width = real_width;
}
else
{
// This won't work -- it'll be bigger than the allocated memory. This is a fatal error.
// std::cerr << "Fatal error: browser rowbytes greater than texture width" << std::endl;
mDeleteMe = true;
return;
}
mTextureWidth = texture_width;
mTextureHeight = texture_height;
};
};
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "size_change_response");
message.setValue("name", name);
message.setValueS32("width", width);
message.setValueS32("height", height);
message.setValueS32("texture_width", texture_width);
message.setValueS32("texture_height", texture_height);
sendMessage(message);
}
else if(message_name == "load_uri")
{
std::string uri = message_in.getValue("uri");
// std::cout << "loading URI: " << uri << std::endl;
if(!uri.empty())
{
if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE)
{
LLQtWebKit::getInstance()->navigateTo( mBrowserWindowId, uri );
}
else
{
mInitialNavigateURL = uri;
}
}
}
else if(message_name == "mouse_event")
{
std::string event = message_in.getValue("event");
S32 button = message_in.getValueS32("button");
mLastMouseX = message_in.getValueS32("x");
mLastMouseY = message_in.getValueS32("y");
std::string modifiers = message_in.getValue("modifiers");
// Treat unknown mouse events as mouse-moves.
LLQtWebKit::EMouseEvent mouse_event = LLQtWebKit::ME_MOUSE_MOVE;
if(event == "down")
{
mouse_event = LLQtWebKit::ME_MOUSE_DOWN;
}
else if(event == "up")
{
mouse_event = LLQtWebKit::ME_MOUSE_UP;
}
else if(event == "double_click")
{
mouse_event = LLQtWebKit::ME_MOUSE_DOUBLE_CLICK;
}
LLQtWebKit::getInstance()->mouseEvent( mBrowserWindowId, mouse_event, button, mLastMouseX, mLastMouseY, decodeModifiers(modifiers));
checkEditState();
}
else if(message_name == "scroll_event")
{
S32 x = message_in.getValueS32("x");
S32 y = message_in.getValueS32("y");
std::string modifiers = message_in.getValue("modifiers");
// Incoming scroll events are adjusted so that 1 detent is approximately 1 unit.
// Qt expects 1 detent to be 120 units.
// It also seems that our y scroll direction is inverted vs. what Qt expects.
x *= 120;
y *= -120;
LLQtWebKit::getInstance()->scrollWheelEvent(mBrowserWindowId, mLastMouseX, mLastMouseY, x, y, decodeModifiers(modifiers));
}
else if(message_name == "key_event")
{
std::string event = message_in.getValue("event");
S32 key = message_in.getValueS32("key");
std::string modifiers = message_in.getValue("modifiers");
// Treat unknown events as key-up for safety.
LLQtWebKit::EKeyEvent key_event = LLQtWebKit::KE_KEY_UP;
if(event == "down")
{
key_event = LLQtWebKit::KE_KEY_DOWN;
}
else if(event == "repeat")
{
key_event = LLQtWebKit::KE_KEY_REPEAT;
}
keyEvent(key_event, key, decodeModifiers(modifiers));
}
else if(message_name == "text_event")
{
std::string text = message_in.getValue("text");
std::string modifiers = message_in.getValue("modifiers");
unicodeInput(text, decodeModifiers(modifiers));
}
if(message_name == "edit_cut")
{
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_CUT );
checkEditState();
}
if(message_name == "edit_copy")
{
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_COPY );
checkEditState();
}
if(message_name == "edit_paste")
{
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_PASTE );
checkEditState();
}
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown media message: " << message_string << std::endl;
};
}
else if(message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER)
{
if(message_name == "focus")
{
bool val = message_in.getValueBoolean("focused");
LLQtWebKit::getInstance()->focusBrowser( mBrowserWindowId, val );
if(mFirstFocus && val)
{
// On the first focus, post a tab key event. This fixes a problem with initial focus.
std::string empty;
keyEvent(LLQtWebKit::KE_KEY_DOWN, KEY_TAB, decodeModifiers(empty));
keyEvent(LLQtWebKit::KE_KEY_UP, KEY_TAB, decodeModifiers(empty));
mFirstFocus = false;
}
}
else if(message_name == "clear_cache")
{
LLQtWebKit::getInstance()->clearCache();
}
else if(message_name == "clear_cookies")
{
LLQtWebKit::getInstance()->clearAllCookies();
}
else if(message_name == "enable_cookies")
{
bool val = message_in.getValueBoolean("enable");
LLQtWebKit::getInstance()->enableCookies( val );
}
else if(message_name == "proxy_setup")
{
bool val = message_in.getValueBoolean("enable");
std::string host = message_in.getValue("host");
int port = message_in.getValueS32("port");
LLQtWebKit::getInstance()->enableProxy( val, host, port );
}
else if(message_name == "browse_stop")
{
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_STOP );
}
else if(message_name == "browse_reload")
{
// foo = message_in.getValueBoolean("ignore_cache");
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_RELOAD );
}
else if(message_name == "browse_forward")
{
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_FORWARD );
}
else if(message_name == "browse_back")
{
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_BACK );
}
else if(message_name == "set_status_redirect")
{
int code = message_in.getValueS32("code");
std::string url = message_in.getValue("url");
if ( 404 == code ) // browser lib only supports 404 right now
{
LLQtWebKit::getInstance()->set404RedirectUrl( mBrowserWindowId, url );
};
}
else if(message_name == "set_user_agent")
{
std::string user_agent = message_in.getValue("user_agent");
LLQtWebKit::getInstance()->setBrowserAgentId( user_agent );
}
else if(message_name == "init_history")
{
// Initialize browser history
LLSD history = message_in.getValueLLSD("history");
// First, clear the URL history
LLQtWebKit::getInstance()->clearHistory(mBrowserWindowId);
// Then, add the history items in order
LLSD::array_iterator iter_history = history.beginArray();
LLSD::array_iterator end_history = history.endArray();
for(; iter_history != end_history; ++iter_history)
{
std::string url = (*iter_history).asString();
if(! url.empty()) {
LLQtWebKit::getInstance()->prependHistoryUrl(mBrowserWindowId, url);
}
}
}
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown media_browser message: " << message_string << std::endl;
};
}
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown message class: " << message_class << std::endl;
};
}
}
int init_media_plugin(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data)
{
MediaPluginWebKit *self = new MediaPluginWebKit(host_send_func, host_user_data);
*plugin_send_func = MediaPluginWebKit::staticReceiveMessage;
*plugin_user_data = (void*)self;
return 0;
}