Skip to content

Commit

Permalink
Fix compatibility with gstreamer < 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
svpcom committed Aug 16, 2024
1 parent 06a4734 commit 099e2ec
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CFLAGS += -DWFB_OSD_VERSION='"$(VERSION)-$(shell /bin/bash -c '_tmp=$(COMMIT); e
ifeq ($(mode), gst)
CFLAGS += -Wall -pthread -std=gnu99 -D__GST_OPENGL__ -fPIC $(shell pkg-config --cflags glib-2.0) $(shell pkg-config --cflags gstreamer-1.0)
LDFLAGS += $(shell pkg-config --libs glib-2.0) $(shell pkg-config --libs gstreamer-1.0) $(shell pkg-config --libs gstreamer-video-1.0) -lgstapp-1.0 -lpthread -lrt -lm
OBJS = main.o osdrender.o osdmavlink.o graphengine.o UAVObj.o m2dlib.o math3d.o osdconfig.o osdvar.o fonts.o font_outlined8x14.o font_outlined8x8.o appsrc.o
OBJS = main.o osdrender.o osdmavlink.o graphengine.o UAVObj.o m2dlib.o math3d.o osdconfig.o osdvar.o fonts.o font_outlined8x14.o font_outlined8x8.o appsrc.o gst-compat.o
else
CFLAGS += -Wall -pthread -std=gnu99 -D__BCM_OPENVG__ -I$(SYSROOT)/opt/vc/include/ -I$(SYSROOT)/opt/vc/include/interface/vcos/pthreads -I$(SYSROOT)/opt/vc/include/interface/vmcs_host/linux
LDFLAGS += -L$(SYSROOT)/opt/vc/lib/ -lbrcmGLESv2 -lbrcmEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpthread -lrt -lm
Expand Down
4 changes: 4 additions & 0 deletions appsrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

#include "graphengine.h"

// For gstreamer < 1.18
GstClockTime gst_element_get_current_running_time (GstElement * element);


static gboolean
on_message (GstBus * bus, GstMessage * message, gpointer user_data)
{
Expand Down
76 changes: 76 additions & 0 deletions gst-compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <gst/gst.h>
#include <gst/gstelement.h>

/**
* gst_element_get_current_clock_time:
* @element: a #GstElement.
*
* Returns the current clock time of the element, as in, the time of the
* element's clock, or GST_CLOCK_TIME_NONE if there is no clock.
*
* Returns: the clock time of the element, or GST_CLOCK_TIME_NONE if there is
* no clock.
*
* Since: 1.18
*/
GstClockTime
gst_element_get_current_clock_time (GstElement * element)
{
GstClock *clock = NULL;
GstClockTime ret;

g_return_val_if_fail (GST_IS_ELEMENT (element), GST_CLOCK_TIME_NONE);

clock = gst_element_get_clock (element);

if (!clock) {
GST_DEBUG_OBJECT (element, "Element has no clock");
return GST_CLOCK_TIME_NONE;
}

ret = gst_clock_get_time (clock);
gst_object_unref (clock);

return ret;
}

/**
* gst_element_get_current_running_time:
* @element: a #GstElement.
*
* Returns the running time of the element. The running time is the
* element's clock time minus its base time. Will return GST_CLOCK_TIME_NONE
* if the element has no clock, or if its base time has not been set.
*
* Returns: the running time of the element, or GST_CLOCK_TIME_NONE if the
* element has no clock or its base time has not been set.
*
* Since: 1.18
*/
GstClockTime
gst_element_get_current_running_time (GstElement * element)
{
GstClockTime base_time, clock_time;

g_return_val_if_fail (GST_IS_ELEMENT (element), GST_CLOCK_TIME_NONE);

base_time = gst_element_get_base_time (element);

if (!GST_CLOCK_TIME_IS_VALID (base_time)) {
GST_DEBUG_OBJECT (element, "Could not determine base time");
return GST_CLOCK_TIME_NONE;
}

clock_time = gst_element_get_current_clock_time (element);

if (!GST_CLOCK_TIME_IS_VALID (clock_time)) {
return GST_CLOCK_TIME_NONE;
}

if (clock_time < base_time) {
GST_DEBUG_OBJECT (element, "Got negative current running time");
return GST_CLOCK_TIME_NONE;
}

return clock_time - base_time;
}

0 comments on commit 099e2ec

Please sign in to comment.