1
+ #include <projectM-4/parameters.h>
1
2
#ifdef HAVE_CONFIG_H
2
3
#include "config.h"
3
4
#endif
@@ -26,6 +27,9 @@ struct _GstProjectMPrivate
26
27
{
27
28
GLenum gl_format ;
28
29
projectm_handle handle ;
30
+
31
+ GstClockTime first_frame_time ;
32
+ gboolean first_frame_received ;
29
33
};
30
34
31
35
G_DEFINE_TYPE_WITH_CODE (GstProjectM , gst_projectm , GST_TYPE_GL_BASE_AUDIO_VISUALIZER , G_ADD_PRIVATE (GstProjectM )
@@ -286,6 +290,25 @@ static gboolean gst_projectm_setup(GstGLBaseAudioVisualizer *glav) {
286
290
return TRUE;
287
291
}
288
292
293
+ static double get_seconds_since_first_frame (GstProjectM * plugin , GstVideoFrame * frame )
294
+ {
295
+ if (!plugin -> priv -> first_frame_received ) {
296
+ // Store the timestamp of the first frame
297
+ plugin -> priv -> first_frame_time = GST_BUFFER_PTS (frame -> buffer );
298
+ plugin -> priv -> first_frame_received = TRUE;
299
+ return 0.0 ;
300
+ }
301
+
302
+ // Calculate elapsed time
303
+ GstClockTime current_time = GST_BUFFER_PTS (frame -> buffer );
304
+ GstClockTime elapsed_time = current_time - plugin -> priv -> first_frame_time ;
305
+
306
+ // Convert to fractional seconds
307
+ gdouble elapsed_seconds = (gdouble ) elapsed_time / GST_SECOND ;
308
+
309
+ return elapsed_seconds ;
310
+ }
311
+
289
312
290
313
// TODO: CLEANUP & ADD DEBUGGING
291
314
static gboolean gst_projectm_render (GstGLBaseAudioVisualizer * glav , GstBuffer * audio , GstVideoFrame * video )
@@ -295,6 +318,10 @@ static gboolean gst_projectm_render(GstGLBaseAudioVisualizer *glav, GstBuffer *a
295
318
GstMapInfo audioMap ;
296
319
gboolean result = TRUE;
297
320
321
+ // get current gst (PTS) time and set projectM time
322
+ double seconds_since_first_frame = get_seconds_since_first_frame (plugin , video );
323
+ projectm_set_frame_time (plugin -> priv -> handle , seconds_since_first_frame );
324
+
298
325
// AUDIO
299
326
gst_buffer_map (audio , & audioMap , GST_MAP_READ );
300
327
@@ -444,4 +471,4 @@ static gboolean plugin_init(GstPlugin *plugin)
444
471
445
472
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR , GST_VERSION_MINOR , projectm ,
446
473
"plugin to visualize audio using the ProjectM library" , plugin_init ,
447
- PACKAGE_VERSION , PACKAGE_LICENSE , PACKAGE_NAME , PACKAGE_ORIGIN )
474
+ PACKAGE_VERSION , PACKAGE_LICENSE , PACKAGE_NAME , PACKAGE_ORIGIN )
0 commit comments