Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ GST_DEBUG_CATEGORY_STATIC(gst_projectm_debug);
struct _GstProjectMPrivate {
GLenum gl_format;
projectm_handle handle;
projectm_playlist_handle playlist;
GRecMutex projectm_lock;

GstClockTime first_frame_time;
gboolean first_frame_received;
Expand All @@ -47,9 +49,11 @@ void gst_projectm_set_property(GObject *object, guint property_id,

switch (property_id) {
case PROP_PRESET_PATH:
g_free(plugin->preset_path);
plugin->preset_path = g_strdup(g_value_get_string(value));
break;
case PROP_TEXTURE_DIR_PATH:
g_free(plugin->texture_dir_path);
plugin->texture_dir_path = g_strdup(g_value_get_string(value));
break;
case PROP_BEAT_SENSITIVITY:
Expand Down Expand Up @@ -201,22 +205,32 @@ static void gst_projectm_init(GstProjectM *plugin) {
plugin->easter_egg = DEFAULT_EASTER_EGG;
plugin->preset_locked = DEFAULT_PRESET_LOCKED;
plugin->priv->handle = NULL;
plugin->priv->playlist = NULL;
g_rec_mutex_init(&plugin->priv->projectm_lock);
}

static void gst_projectm_finalize(GObject *object) {
GstProjectM *plugin = GST_PROJECTM(object);
g_free(plugin->preset_path);
g_free(plugin->texture_dir_path);
g_rec_mutex_clear(&plugin->priv->projectm_lock);
G_OBJECT_CLASS(gst_projectm_parent_class)->finalize(object);
}

static void gst_projectm_gl_stop(GstGLBaseAudioVisualizer *src) {
GstProjectM *plugin = GST_PROJECTM(src);
g_rec_mutex_lock(&plugin->priv->projectm_lock);
if (plugin->priv->playlist) {
GST_DEBUG_OBJECT(plugin, "Destroying ProjectM playlist instance");
projectm_playlist_destroy(plugin->priv->playlist);
plugin->priv->playlist = NULL;
}
if (plugin->priv->handle) {
GST_DEBUG_OBJECT(plugin, "Destroying ProjectM instance");
projectm_destroy(plugin->priv->handle);
plugin->priv->handle = NULL;
}
g_rec_mutex_unlock(&plugin->priv->projectm_lock);
}

static gboolean gst_projectm_gl_start(GstGLBaseAudioVisualizer *glav) {
Expand All @@ -231,17 +245,20 @@ static gboolean gst_projectm_gl_start(GstGLBaseAudioVisualizer *glav) {
return FALSE;
}
#endif
g_rec_mutex_lock(&plugin->priv->projectm_lock);

// Check if ProjectM instance exists, and create if not
if (!plugin->priv->handle) {
// Create ProjectM instance
plugin->priv->handle = projectm_init(plugin);
if (!plugin->priv->handle) {
bool result =
projectm_init(plugin, &plugin->priv->handle, &plugin->priv->playlist);
if (!result || !plugin->priv->handle) {
GST_ERROR_OBJECT(plugin, "ProjectM could not be initialized");
return FALSE;
}
gl_error_handler(glav->context, plugin);
}
g_rec_mutex_unlock(&plugin->priv->projectm_lock);

return TRUE;
}
Expand Down Expand Up @@ -320,6 +337,8 @@ static gboolean gst_projectm_render(GstGLBaseAudioVisualizer *glav,
GstBuffer *audio, GstVideoFrame *video) {
GstProjectM *plugin = GST_PROJECTM(glav);

g_rec_mutex_lock(&plugin->priv->projectm_lock);

GstMapInfo audioMap;
gboolean result = TRUE;

Expand Down Expand Up @@ -351,6 +370,7 @@ static gboolean gst_projectm_render(GstGLBaseAudioVisualizer *glav,
projectm_get_window_size(plugin->priv->handle, &windowWidth, &windowHeight);

projectm_opengl_render_frame(plugin->priv->handle);
g_rec_mutex_unlock(&plugin->priv->projectm_lock);
gl_error_handler(glav->context, plugin);

glFunctions->ReadPixels(0, 0, windowWidth, windowHeight,
Expand Down
11 changes: 7 additions & 4 deletions src/projectm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
GST_DEBUG_CATEGORY_STATIC(projectm_debug);
#define GST_CAT_DEFAULT projectm_debug

projectm_handle projectm_init(GstProjectM *plugin) {
bool projectm_init(GstProjectM *plugin, projectm_handle *ret_handle,
projectm_playlist_handle *ret_playlist) {
projectm_handle handle = NULL;
projectm_playlist_handle playlist = NULL;

Expand All @@ -29,16 +30,18 @@ projectm_handle projectm_init(GstProjectM *plugin) {
GST_DEBUG_OBJECT(
plugin,
"project_create() returned NULL, projectM instance was not created!");
return NULL;
return FALSE;
} else {
GST_DEBUG_OBJECT(plugin, "Created projectM instance!");
}
*ret_handle = handle;

if (plugin->enable_playlist) {
GST_DEBUG_OBJECT(plugin, "Playlist enabled");

// initialize preset playlist
playlist = projectm_playlist_create(handle);
*ret_playlist = playlist;
projectm_playlist_set_shuffle(playlist, plugin->shuffle_presets);
// projectm_playlist_set_preset_switched_event_callback(_playlist,
// &ProjectMWrapper::PresetSwitchedEvent, static_cast<void*>(this));
Expand Down Expand Up @@ -73,7 +76,7 @@ projectm_handle projectm_init(GstProjectM *plugin) {

// Load preset file if path is provided
if (plugin->preset_path != NULL) {
int added_count =
unsigned int added_count =
projectm_playlist_add_path(playlist, plugin->preset_path, true, false);
GST_INFO("Loaded preset path: %s, presets found: %d", plugin->preset_path,
added_count);
Expand Down Expand Up @@ -113,7 +116,7 @@ projectm_handle projectm_init(GstProjectM *plugin) {
projectm_set_window_size(handle, GST_VIDEO_INFO_WIDTH(&bscope->vinfo),
GST_VIDEO_INFO_HEIGHT(&bscope->vinfo));

return handle;
return TRUE;
}

// void projectm_render(GstProjectM *plugin, gint16 *samples, gint sample_count)
Expand Down
4 changes: 3 additions & 1 deletion src/projectm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include <glib.h>

#include "plugin.h"
#include <projectM-4/playlist.h>
#include <projectM-4/projectM.h>

G_BEGIN_DECLS

/**
* @brief Initialize ProjectM
*/
projectm_handle projectm_init(GstProjectM *plugin);
bool projectm_init(GstProjectM *plugin, projectm_handle *handle,
projectm_playlist_handle *playlist);

/**
* @brief Render ProjectM
Expand Down
Loading