Last active
November 30, 2016 15:20
-
-
Save tetkuz/a764b64adb52c47751b1c1114c503e15 to your computer and use it in GitHub Desktop.
GStreamer 1.10 new API: property_notify_watch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -Wall -Wextra property_notify_watch.c `pkg-config --cflags --libs gstreamer-1.0` | |
#include <unistd.h> | |
#include <signal.h> | |
#include <sys/types.h> | |
#include <gst/gst.h> | |
#define HIGH (30) | |
#define SLOW (10) | |
GstElement *pipeline; | |
GstElement *videorate; | |
void sigint_handler(int sig) { | |
gint rate = HIGH; | |
(void)sig; | |
if (videorate) { | |
g_object_get (G_OBJECT (videorate), "max-rate", &rate, NULL); | |
if (rate <= SLOW) { | |
g_print("rate: %d => %d\n", rate, HIGH); | |
rate = HIGH; | |
} else { | |
g_print("rate: %d => %d\n", rate, SLOW); | |
rate = SLOW; | |
} | |
g_object_set (G_OBJECT (videorate), "max-rate", rate, NULL); | |
} | |
} | |
int main(int argc, char *argv[]) { | |
GstBus *bus; | |
GstMessage *msg; | |
gboolean terminate = FALSE; | |
gulong watch_id; | |
const gchar* prop_name; | |
const GValue* prop_value; | |
/* Initialize GStreamer */ | |
gst_init (&argc, &argv); | |
g_print("%d", getpid()); | |
signal(SIGINT, sigint_handler); | |
/* Build the pipeline */ | |
pipeline = gst_parse_launch ( | |
"gst-launch-1.0 videotestsrc pattern=ball ! " | |
"videorate name=rate max-rate=30 ! " | |
"videoconvert ! ximagesink", NULL); | |
videorate = gst_bin_get_by_name ((GstBin *) pipeline, "rate"); | |
watch_id = gst_element_add_property_notify_watch (videorate, "max-rate", TRUE); | |
/* Start playing */ | |
gst_element_set_state (pipeline, GST_STATE_PLAYING); | |
/* Wait until error or EOS */ | |
bus = gst_element_get_bus (pipeline); | |
while (!terminate) { | |
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, | |
GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_PROPERTY_NOTIFY); | |
/* Parse message */ | |
if (msg != NULL) { | |
GError *err; | |
gchar *debug_info; | |
switch (GST_MESSAGE_TYPE (msg)) { | |
case GST_MESSAGE_ERROR: | |
gst_message_parse_error (msg, &err, &debug_info); | |
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); | |
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none"); | |
g_clear_error (&err); | |
g_free (debug_info); | |
terminate = TRUE; | |
break; | |
case GST_MESSAGE_EOS: | |
g_print ("End-Of-Stream reached.\n"); | |
terminate = TRUE; | |
break; | |
case GST_MESSAGE_PROPERTY_NOTIFY: | |
g_print ("Property notify catched.\n"); | |
gst_message_parse_property_notify (msg, NULL, &prop_name, &prop_value); | |
if (G_VALUE_HOLDS_INT(prop_value)) { | |
g_print (" %s: %d\n", prop_name, g_value_get_int(prop_value)); | |
} | |
break; | |
default: | |
/* We should not reach here */ | |
g_printerr ("Unexpected message received.\n"); | |
break; | |
} | |
gst_message_unref (msg); | |
} | |
}; | |
/* Free resources */ | |
if (msg != NULL) | |
gst_message_unref (msg); | |
gst_object_unref (bus); | |
gst_element_remove_property_notify_watch (videorate, watch_id); | |
gst_element_set_state (pipeline, GST_STATE_NULL); | |
gst_object_unref (pipeline); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment