The files are already published in the tutorial web site.
We do not need gst examples in nnstreamer git.
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
+++ /dev/null
-cmake_minimum_required(VERSION 2.8)
-
-project(gst_example)
-
-add_definitions(-DVERSION="0.0.0")
-
-set(PREFIX ${CMAKE_INSTALL_PREFIX})
-set(EXEC_PREFIX "${PREFIX}/bin")
-if(LIB_INSTALL_DIR)
-else(LIB_INSTALL_DIR)
- set(LIB_INSTALL_DIR "${PREFIX}/lib")
-endif(LIB_INSTALL_DIR)
-
-find_package(PkgConfig REQUIRED)
-pkg_check_modules(GST REQUIRED gstreamer-1.0 gstreamer-base-1.0 gstreamer-controller-1.0 gstreamer-video-1.0 gstreamer-audio-1.0 glib-2.0)
-INCLUDE_DIRECTORIES(${GST_INCLUDE_DIRS})
-LINK_DIRECTORIES(${GST_LIBRARY_DIRS})
-LINK_LIBRARIES(${GST_LIBRARIES})
-
-
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GST_CFLAGS_OTHER}")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GST_CFLAGS_OTHER}")
-
-add_executable(basic-tutorial-1 tutorial1/basic-tutorial-1.c)
-
-add_executable(basic-tutorial-2 tutorial2/basic-tutorial-2.c)
-
-add_executable(basic-tutorial-2-add-filter tutorial2/basic-tutorial-2-add-filter.c)
-
-add_executable(basic-tutorial-3 tutorial3/basic-tutorial-3.c)
-
-add_executable(basic-tutorial-3-exercise tutorial3/basic-tutorial-3-exercise.c)
-
-add_executable(basic-tutorial-6 tutorial6/basic-tutorial-6.c)
-
-add_executable(basic-tutorial-7 tutorial7/basic-tutorial-7.c)
-
-add_executable(basic-tutorial-8 tutorial8/basic-tutorial-8.c)
-
-install(TARGETS basic-tutorial-1 basic-tutorial-2 basic-tutorial-2-add-filter basic-tutorial-3 basic-tutorial-3-exercise basic-tutorial-6 basic-tutorial-7 basic-tutorial-8
- RUNTIME DESTINATION ${EXEC_PREFIX}
- LIBRARY DESTINATION ${LIB_INSTALL_DIR}
- ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
- )
+++ /dev/null
-#include <gst/gst.h>
-
-int main(int argc, char *argv[]) {
- GstElement *pipeline;
- GstBus *bus;
- GstMessage *msg;
-
- gst_init(&argc, &argv);
-
- pipeline = gst_parse_launch("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);
-
- gst_element_set_state(pipeline, GST_STATE_PLAYING);
-
- bus = gst_element_get_bus(pipeline);
- msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
-
- if (msg != NULL)
- gst_message_unref(msg);
- gst_object_unref(bus);
- gst_element_set_state(pipeline, GST_STATE_NULL);
- gst_object_unref(pipeline);
- return 0;
-}
+++ /dev/null
-#include <gst/gst.h>
-
-int main(int argc, char *argv[]) {
- GstElement *pipeline, *source, *sink, *filter;
- GstBus *bus;
- GstMessage *msg;
- GstStateChangeReturn ret;
-
- gst_init(&argc, &argv);
-
- source = gst_element_factory_make("videotestsrc", "source");
- sink = gst_element_factory_make("autovideosink", "sink");
- filter = gst_element_factory_make("vertigotv", "filter1");
-
- pipeline = gst_pipeline_new("test-pipeline");
-
- if (!pipeline || !source || !sink || !filter) {
- g_printerr("Cannot create elements.\n");
- return -1;
- }
-
- gst_bin_add_many(GST_BIN(pipeline), source, sink, filter, NULL);
- if (gst_element_link(source, filter) != TRUE) {
- g_printerr("Cannot linke source and filter\n");
- gst_object_unref(pipeline);
- return -1;
- }
- if (gst_element_link(filter, sink) != TRUE) {
- g_printerr("Cannot linke filter and sink\n");
- gst_object_unref(pipeline);
- return -1;
- }
-
- g_object_set(source, "pattern", 0, NULL);
-
- ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr("Cannot setup pipeline as playing");
- gst_object_unref(pipeline);
- return -1;
- }
-
- bus = gst_element_get_bus(pipeline);
- msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
-
-
- 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);
- break;
- case GST_MESSAGE_EOS:
- g_print("End Of Stream.\n");
- break;
- default:
- g_printerr("Undefined gst message.\n");
- }
- }
-
- gst_object_unref(bus);
- gst_element_set_state(pipeline, GST_STATE_NULL);
- gst_object_unref(pipeline);
- return 0;
-}
+++ /dev/null
-#include <gst/gst.h>
-
-int main(int argc, char *argv[]) {
- GstElement *pipeline, *source, *sink;
- GstBus *bus;
- GstMessage *msg;
- GstStateChangeReturn ret;
-
- gst_init(&argc, &argv);
-
- source = gst_element_factory_make("videotestsrc", "source");
- sink = gst_element_factory_make("autovideosink", "sink");
-
- pipeline = gst_pipeline_new("test-pipeline");
-
- if (!pipeline || !source || !sink) {
- g_printerr("Cannot create elements.\n");
- return -1;
- }
-
- gst_bin_add_many(GST_BIN(pipeline), source, sink, NULL);
- if (gst_element_link(source, sink) != TRUE) {
- g_printerr("Cannot linke source and sink\n");
- gst_object_unref(pipeline);
- return -1;
- }
-
- g_object_set(source, "pattern", 0, NULL);
-
- ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr("Cannot setup pipeline as playing");
- gst_object_unref(pipeline);
- return -1;
- }
-
- bus = gst_element_get_bus(pipeline);
- msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
-
-
- 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);
- break;
- case GST_MESSAGE_EOS:
- g_print("End Of Stream.\n");
- break;
- default:
- g_printerr("Undefined gst message.\n");
- }
- }
-
- gst_object_unref(bus);
- gst_element_set_state(pipeline, GST_STATE_NULL);
- gst_object_unref(pipeline);
- return 0;
-}
+++ /dev/null
-#include <gst/gst.h>
-
-typedef struct _CustomData {
- GstElement *pipeline;
- GstElement *source;
- GstElement *convert;
- GstElement *sink;
-
- GstElement *vconvert;
- GstElement *vsink;
-} CustomData;
-
-static void pad_added_handler (GstElement *src, GstPad *pad, CustomData *data);
-
-int main(int argc, char *argv[]) {
- CustomData data;
- GstBus *bus;
- GstMessage *msg;
- GstStateChangeReturn ret;
- gboolean terminate = FALSE;
-
- gst_init(&argc, &argv);
-
- data.source = gst_element_factory_make("uridecodebin", "source");
- data.convert = gst_element_factory_make("audioconvert", "convert");
- data.sink = gst_element_factory_make("autoaudiosink", "sink");
- data.vconvert = gst_element_factory_make("videoconvert", "vconvert");
- data.vsink = gst_element_factory_make("autovideosink", "vsink");
-
- data.pipeline = gst_pipeline_new("test-pipeline");
-
- if (!data.pipeline || !data.source || !data.convert || !data.sink || !data.vconvert || !data.vsink) {
- g_printerr("There is an element not created.\n");
- return -1;
- }
-
- gst_bin_add_many(GST_BIN(data.pipeline), data.source, data.convert, data.sink, data.vconvert, data.vsink, NULL);
- if (!gst_element_link(data.convert, data.sink)) {
- g_printerr("Element cannot be linked for audio.\n");
- gst_object_unref(data.pipeline);
- return -1;
- }
- if (!gst_element_link(data.vconvert, data.vsink)) {
- g_printerr("Element cannot be linked for video.\n");
- gst_object_unref(data.pipeline);
- return -1;
- }
-
- g_object_set(data.source, "uri", "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);
-
- g_signal_connect(data.source, "pad-added", G_CALLBACK(pad_added_handler), &data);
-
- ret = gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr("Unsable to set th epipeline to the playing state.\n");
- gst_object_unref(data.pipeline);
- return -1;
- }
-
- bus = gst_element_get_bus(data.pipeline);
- do {
- msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
-
- 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 from %s: %s\n", GST_OBJECT_NAME(msg->src), err->message);
- g_printerr("Debug info: %s\n", debug_info ? debug_info : "none");
- g_clear_error(&err);
- g_free(debug_info);
- terminate = TRUE;
- break;
- case GST_MESSAGE_EOS:
- g_print("EOS.\n");
- terminate = TRUE;
- break;
- case GST_MESSAGE_STATE_CHANGED:
- if (GST_MESSAGE_SRC(msg) == GST_OBJECT(data.pipeline)) {
- GstState old_state, new_state, pending_state;
- gst_message_parse_state_changed(msg, &old_state, &new_state, &pending_state);
- g_print("Pipeline state %s --> %s\n", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
- }
- break;
- default:
- g_printerr("Unexpected message.\n");
- break;
- }
- gst_message_unref(msg);
- }
- } while(!terminate);
-
- gst_object_unref(bus);
- gst_element_set_state(data.pipeline, GST_STATE_NULL);
- gst_object_unref(data.pipeline);
- return 0;
-}
-
-static void pad_added_handler(GstElement *src, GstPad *new_pad, CustomData *data) {
- GstPad *sink_pad = gst_element_get_static_pad(data->convert, "sink");
- GstPad *vsink_pad = gst_element_get_static_pad(data->vconvert, "sink");
- GstPadLinkReturn ret;
- GstCaps *new_pad_caps = NULL;
- GstStructure *new_pad_struct = NULL;
- const gchar *new_pad_type = NULL;
-
- g_print("Received new pad '%s' from '%s':\n", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src));
-
- if (gst_pad_is_linked(sink_pad)) {
- g_print(" We are already linked. Ignoring\n");
- goto exit;
- }
-
- new_pad_caps = gst_pad_query_caps(new_pad, NULL);
- new_pad_struct = gst_caps_get_structure(new_pad_caps, 0);
- new_pad_type = gst_structure_get_name(new_pad_struct);
- if (g_str_has_prefix(new_pad_type, "audio/x-raw")) {
- ret = gst_pad_link(new_pad, sink_pad);
- if (GST_PAD_LINK_FAILED(ret)) {
- g_print(" Type is '%s' but link failed\n", new_pad_type);
- } else {
- g_print(" Link succeeded (type '%s')\n", new_pad_type);
- }
- } else if (g_str_has_prefix(new_pad_type, "video/x-raw")) {
- ret = gst_pad_link(new_pad, vsink_pad);
- if (GST_PAD_LINK_FAILED(ret)) {
- g_print(" Type is '%s' but link failed for video\n", new_pad_type);
- } else {
- g_print(" Link succeeded for video (type '%s')\n", new_pad_type);
- }
- } else {
- g_print(" It has type '%s' which is not raw audio. Ignoring.\n", new_pad_type);
- goto exit;
- }
-
-exit:
- if (new_pad_caps != NULL)
- gst_caps_unref(new_pad_caps);
- gst_object_unref(sink_pad);
-}
+++ /dev/null
-#include <gst/gst.h>
-
-typedef struct _CustomData {
- GstElement *pipeline;
- GstElement *source;
- GstElement *convert;
- GstElement *sink;
-} CustomData;
-
-static void pad_added_handler (GstElement *src, GstPad *pad, CustomData *data);
-
-int main(int argc, char *argv[]) {
- CustomData data;
- GstBus *bus;
- GstMessage *msg;
- GstStateChangeReturn ret;
- gboolean terminate = FALSE;
-
- gst_init(&argc, &argv);
-
- data.source = gst_element_factory_make("uridecodebin", "source");
- data.convert = gst_element_factory_make("audioconvert", "convert");
- data.sink = gst_element_factory_make("autoaudiosink", "sink");
-
- data.pipeline = gst_pipeline_new("test-pipeline");
-
- if (!data.pipeline || !data.source || !data.convert || !data.sink) {
- g_printerr("There is an element not created.\n");
- return -1;
- }
-
- gst_bin_add_many(GST_BIN(data.pipeline), data.source, data.convert, data.sink, NULL);
- if (!gst_element_link(data.convert, data.sink)) {
- g_printerr("Element cannot be linked.\n");
- gst_object_unref(data.pipeline);
- return -1;
- }
-
- g_object_set(data.source, "uri", "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);
-
- g_signal_connect(data.source, "pad-added", G_CALLBACK(pad_added_handler), &data);
-
- ret = gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr("Unsable to set th epipeline to the playing state.\n");
- gst_object_unref(data.pipeline);
- return -1;
- }
-
- bus = gst_element_get_bus(data.pipeline);
- do {
- msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
-
- 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 from %s: %s\n", GST_OBJECT_NAME(msg->src), err->message);
- g_printerr("Debug info: %s\n", debug_info ? debug_info : "none");
- g_clear_error(&err);
- g_free(debug_info);
- terminate = TRUE;
- break;
- case GST_MESSAGE_EOS:
- g_print("EOS.\n");
- terminate = TRUE;
- break;
- case GST_MESSAGE_STATE_CHANGED:
- if (GST_MESSAGE_SRC(msg) == GST_OBJECT(data.pipeline)) {
- GstState old_state, new_state, pending_state;
- gst_message_parse_state_changed(msg, &old_state, &new_state, &pending_state);
- g_print("Pipeline state %s --> %s\n", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
- }
- break;
- default:
- g_printerr("Unexpected message.\n");
- break;
- }
- gst_message_unref(msg);
- }
- } while(!terminate);
-
- gst_object_unref(bus);
- gst_element_set_state(data.pipeline, GST_STATE_NULL);
- gst_object_unref(data.pipeline);
- return 0;
-}
-
-static void pad_added_handler(GstElement *src, GstPad *new_pad, CustomData *data) {
- GstPad *sink_pad = gst_element_get_static_pad(data->convert, "sink");
- GstPadLinkReturn ret;
- GstCaps *new_pad_caps = NULL;
- GstStructure *new_pad_struct = NULL;
- const gchar *new_pad_type = NULL;
-
- g_print("Received new pad '%s' from '%s':\n", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src));
-
- if (gst_pad_is_linked(sink_pad)) {
- g_print(" We are already linked. Ignoring\n");
- goto exit;
- }
-
- new_pad_caps = gst_pad_query_caps(new_pad, NULL);
- new_pad_struct = gst_caps_get_structure(new_pad_caps, 0);
- new_pad_type = gst_structure_get_name(new_pad_struct);
- if (!g_str_has_prefix(new_pad_type, "audio/x-raw")) {
- g_print(" It has type '%s' which is not raw audio. Ignoring.\n", new_pad_type);
- goto exit;
- }
-
- ret = gst_pad_link(new_pad, sink_pad);
- if (GST_PAD_LINK_FAILED(ret)) {
- g_print(" Type is '%s' but link failed\n", new_pad_type);
- } else {
- g_print(" Link succeeded (type '%s')\n", new_pad_type);
- }
-
-exit:
- if (new_pad_caps != NULL)
- gst_caps_unref(new_pad_caps);
- gst_object_unref(sink_pad);
-}
+++ /dev/null
-#include <gst/gst.h>
-
-/* Functions below print the Capabilities in a human-friendly format */
-static gboolean print_field (GQuark field, const GValue * value, gpointer pfx) {
- gchar *str = gst_value_serialize (value);
-
- g_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
- g_free (str);
- return TRUE;
-}
-
-static void print_caps (const GstCaps * caps, const gchar * pfx) {
- guint i;
-
- g_return_if_fail (caps != NULL);
-
- if (gst_caps_is_any (caps)) {
- g_print ("%sANY\n", pfx);
- return;
- }
- if (gst_caps_is_empty (caps)) {
- g_print ("%sEMPTY\n", pfx);
- return;
- }
-
- for (i = 0; i < gst_caps_get_size (caps); i++) {
- GstStructure *structure = gst_caps_get_structure (caps, i);
-
- g_print ("%s%s\n", pfx, gst_structure_get_name (structure));
- gst_structure_foreach (structure, print_field, (gpointer) pfx);
- }
-}
-
-/* Prints information about a Pad Template, including its Capabilities */
-static void print_pad_templates_information (GstElementFactory * factory) {
- const GList *pads;
- GstStaticPadTemplate *padtemplate;
-
- g_print ("Pad Templates for %s:\n", gst_element_factory_get_longname (factory));
- if (!gst_element_factory_get_num_pad_templates (factory)) {
- g_print (" none\n");
- return;
- }
-
- pads = gst_element_factory_get_static_pad_templates (factory);
- while (pads) {
- padtemplate = pads->data;
- pads = g_list_next (pads);
-
- if (padtemplate->direction == GST_PAD_SRC)
- g_print (" SRC template: '%s'\n", padtemplate->name_template);
- else if (padtemplate->direction == GST_PAD_SINK)
- g_print (" SINK template: '%s'\n", padtemplate->name_template);
- else
- g_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
-
- if (padtemplate->presence == GST_PAD_ALWAYS)
- g_print (" Availability: Always\n");
- else if (padtemplate->presence == GST_PAD_SOMETIMES)
- g_print (" Availability: Sometimes\n");
- else if (padtemplate->presence == GST_PAD_REQUEST) {
- g_print (" Availability: On request\n");
- } else
- g_print (" Availability: UNKNOWN!!!\n");
-
- if (padtemplate->static_caps.string) {
- GstCaps *caps;
- g_print (" Capabilities:\n");
- caps = gst_static_caps_get (&padtemplate->static_caps);
- print_caps (caps, " ");
- gst_caps_unref (caps);
-
- }
-
- g_print ("\n");
- }
-}
-
-/* Shows the CURRENT capabilities of the requested pad in the given element */
-static void print_pad_capabilities (GstElement *element, gchar *pad_name) {
- GstPad *pad = NULL;
- GstCaps *caps = NULL;
-
- /* Retrieve pad */
- pad = gst_element_get_static_pad (element, pad_name);
- if (!pad) {
- g_printerr ("Could not retrieve pad '%s'\n", pad_name);
- return;
- }
-
- /* Retrieve negotiated caps (or acceptable caps if negotiation is not finished yet) */
- caps = gst_pad_get_current_caps (pad);
- if (!caps)
- caps = gst_pad_query_caps (pad, NULL);
-
- /* Print and free */
- g_print ("Caps for the %s pad:\n", pad_name);
- print_caps (caps, " ");
- gst_caps_unref (caps);
- gst_object_unref (pad);
-}
-
-int main(int argc, char *argv[]) {
- GstElement *pipeline, *source, *sink;
- GstElementFactory *source_factory, *sink_factory;
- GstBus *bus;
- GstMessage *msg;
- GstStateChangeReturn ret;
- gboolean terminate = FALSE;
-
- /* Initialize GStreamer */
- gst_init (&argc, &argv);
-
- /* Create the element factories */
- source_factory = gst_element_factory_find ("audiotestsrc");
- sink_factory = gst_element_factory_find ("autoaudiosink");
- if (!source_factory || !sink_factory) {
- g_printerr ("Not all element factories could be created.\n");
- return -1;
- }
-
- /* Print information about the pad templates of these factories */
- print_pad_templates_information (source_factory);
- print_pad_templates_information (sink_factory);
-
- /* Ask the factories to instantiate actual elements */
- source = gst_element_factory_create (source_factory, "source");
- sink = gst_element_factory_create (sink_factory, "sink");
-
- /* Create the empty pipeline */
- pipeline = gst_pipeline_new ("test-pipeline");
-
- if (!pipeline || !source || !sink) {
- g_printerr ("Not all elements could be created.\n");
- return -1;
- }
-
- /* Build the pipeline */
- gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
- if (gst_element_link (source, sink) != TRUE) {
- g_printerr ("Elements could not be linked.\n");
- gst_object_unref (pipeline);
- return -1;
- }
-
- /* Print initial negotiated caps (in NULL state) */
- g_print ("In NULL state:\n");
- print_pad_capabilities (sink, "sink");
-
- /* Start playing */
- ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr ("Unable to set the pipeline to the playing state (check the bus for error messages).\n");
- }
-
- /* Wait until error, EOS or State Change */
- bus = gst_element_get_bus (pipeline);
- do {
- msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS |
- GST_MESSAGE_STATE_CHANGED);
-
- /* 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_STATE_CHANGED:
- /* We are only interested in state-changed messages from the pipeline */
- if (GST_MESSAGE_SRC (msg) == GST_OBJECT (pipeline)) {
- GstState old_state, new_state, pending_state;
- gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
- g_print ("\nPipeline state changed from %s to %s:\n",
- gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
- /* Print the current capabilities of the sink element */
- print_pad_capabilities (sink, "sink");
- }
- break;
- default:
- /* We should not reach here because we only asked for ERRORs, EOS and STATE_CHANGED */
- g_printerr ("Unexpected message received.\n");
- break;
- }
- gst_message_unref (msg);
- }
- } while (!terminate);
-
- /* Free resources */
- gst_object_unref (bus);
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_object_unref (pipeline);
- gst_object_unref (source_factory);
- gst_object_unref (sink_factory);
- return 0;
-}
-
+++ /dev/null
-#include <gst/gst.h>
-
-int main(int argc, char *argv[]) {
- GstElement *pipeline, *audio_source, *tee, *audio_queue, *audio_convert, *audio_resample, *audio_sink;
- GstElement *video_queue, *visual, *video_convert, *video_sink;
- GstBus *bus;
- GstMessage *msg;
- GstPad *tee_audio_pad, *tee_video_pad;
- GstPad *queue_audio_pad, *queue_video_pad;
-
- /* Initialize GStreamer */
- gst_init (&argc, &argv);
-
- /* Create the elements */
- audio_source = gst_element_factory_make ("audiotestsrc", "audio_source");
- tee = gst_element_factory_make ("tee", "tee");
- audio_queue = gst_element_factory_make ("queue", "audio_queue");
- audio_convert = gst_element_factory_make ("audioconvert", "audio_convert");
- audio_resample = gst_element_factory_make ("audioresample", "audio_resample");
- audio_sink = gst_element_factory_make ("autoaudiosink", "audio_sink");
- video_queue = gst_element_factory_make ("queue", "video_queue");
- visual = gst_element_factory_make ("wavescope", "visual");
- video_convert = gst_element_factory_make ("videoconvert", "csp");
- video_sink = gst_element_factory_make ("autovideosink", "video_sink");
-
- /* Create the empty pipeline */
- pipeline = gst_pipeline_new ("test-pipeline");
-
- if (!pipeline || !audio_source || !tee || !audio_queue || !audio_convert || !audio_resample || !audio_sink ||
- !video_queue || !visual || !video_convert || !video_sink) {
- g_printerr ("Not all elements could be created.\n");
- return -1;
- }
-
- /* Configure elements */
- g_object_set (audio_source, "freq", 215.0f, NULL);
- g_object_set (visual, "shader", 0, "style", 1, NULL);
-
- /* Link all elements that can be automatically linked because they have "Always" pads */
- gst_bin_add_many (GST_BIN (pipeline), audio_source, tee, audio_queue, audio_convert, audio_resample, audio_sink,
- video_queue, visual, video_convert, video_sink, NULL);
- if (gst_element_link_many (audio_source, tee, NULL) != TRUE ||
- gst_element_link_many (audio_queue, audio_convert, audio_resample, audio_sink, NULL) != TRUE ||
- gst_element_link_many (video_queue, visual, video_convert, video_sink, NULL) != TRUE) {
- g_printerr ("Elements could not be linked.\n");
- gst_object_unref (pipeline);
- return -1;
- }
-
- /* Manually link the Tee, which has "Request" pads */
- tee_audio_pad = gst_element_get_request_pad (tee, "src_%u");
- g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad));
- queue_audio_pad = gst_element_get_static_pad (audio_queue, "sink");
- tee_video_pad = gst_element_get_request_pad (tee, "src_%u");
- g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad));
- queue_video_pad = gst_element_get_static_pad (video_queue, "sink");
- if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK ||
- gst_pad_link (tee_video_pad, queue_video_pad) != GST_PAD_LINK_OK) {
- g_printerr ("Tee could not be linked.\n");
- gst_object_unref (pipeline);
- return -1;
- }
- gst_object_unref (queue_audio_pad);
- gst_object_unref (queue_video_pad);
-
- /* Start playing the pipeline */
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
- g_print ("Starting Playing\n");
-
- /* Wait until error or EOS */
- bus = gst_element_get_bus (pipeline);
- msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
-
- 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);
- break;
- case GST_MESSAGE_EOS:
- g_print ("End-Of-Stream reached.\n");
- break;
- }
- }
-
- /* Release the request pads from the Tee, and unref them */
- gst_element_release_request_pad (tee, tee_audio_pad);
- gst_element_release_request_pad (tee, tee_video_pad);
- gst_object_unref (tee_audio_pad);
- gst_object_unref (tee_video_pad);
-
- /* Free resources */
- if (msg != NULL)
- gst_message_unref (msg);
- gst_object_unref (bus);
- gst_element_set_state (pipeline, GST_STATE_NULL);
-
- gst_object_unref (pipeline);
- return 0;
-}
-
+++ /dev/null
-#include <gst/gst.h>
-#include <gst/audio/audio.h>
-#include <string.h>
-
-#define CHUNK_SIZE 1024 /* Amount of bytes we are sending in each buffer */
-#define SAMPLE_RATE 44100 /* Samples per second we are sending */
-
-/* Structure to contain all our information, so we can pass it to callbacks */
-typedef struct _CustomData {
- GstElement *pipeline, *app_source, *tee, *audio_queue, *audio_convert1, *audio_resample, *audio_sink;
- GstElement *video_queue, *audio_convert2, *visual, *video_convert, *video_sink;
- GstElement *app_queue, *app_sink;
-
- guint64 num_samples; /* Number of samples generated so far (for timestamp generation) */
- gfloat a, b, c, d; /* For waveform generation */
-
- guint sourceid; /* To control the GSource */
-
- GMainLoop *main_loop; /* GLib's Main Loop */
-} CustomData;
-
-/* This method is called by the idle GSource in the mainloop, to feed CHUNK_SIZE bytes into appsrc.
- * The ide handler is added to the mainloop when appsrc requests us to start sending data (need-data signal)
- * and is removed when appsrc has enough data (enough-data signal).
- */
-static gboolean push_data (CustomData *data) {
- GstBuffer *buffer;
- GstFlowReturn ret;
- int i;
- GstMapInfo map;
- gint16 *raw;
- gint num_samples = CHUNK_SIZE / 2; /* Because each sample is 16 bits */
- gfloat freq;
-
- /* Create a new empty buffer */
- buffer = gst_buffer_new_and_alloc (CHUNK_SIZE);
-
- /* Set its timestamp and duration */
- GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (data->num_samples, GST_SECOND, SAMPLE_RATE);
- GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (CHUNK_SIZE, GST_SECOND, SAMPLE_RATE);
-
- /* Generate some psychodelic waveforms */
- gst_buffer_map (buffer, &map, GST_MAP_WRITE);
- raw = (gint16 *)map.data;
- data->c += data->d;
- data->d -= data->c / 1000;
- freq = 1100 + 1000 * data->d;
- for (i = 0; i < num_samples; i++) {
- data->a += data->b;
- data->b -= data->a / freq;
- raw[i] = (gint16)(500 * data->a);
- }
- gst_buffer_unmap (buffer, &map);
- data->num_samples += num_samples;
-
- /* Push the buffer into the appsrc */
- g_signal_emit_by_name (data->app_source, "push-buffer", buffer, &ret);
-
- /* Free the buffer now that we are done with it */
- gst_buffer_unref (buffer);
-
- if (ret != GST_FLOW_OK) {
- /* We got some error, stop sending data */
- return FALSE;
- }
-
- return TRUE;
-}
-
-/* This signal callback triggers when appsrc needs data. Here, we add an idle handler
- * to the mainloop to start pushing data into the appsrc */
-static void start_feed (GstElement *source, guint size, CustomData *data) {
- if (data->sourceid == 0) {
- g_print ("Start feeding\n");
- data->sourceid = g_idle_add ((GSourceFunc) push_data, data);
- }
-}
-
-/* This callback triggers when appsrc has enough data and we can stop sending.
- * We remove the idle handler from the mainloop */
-static void stop_feed (GstElement *source, CustomData *data) {
- if (data->sourceid != 0) {
- g_print ("Stop feeding\n");
- g_source_remove (data->sourceid);
- data->sourceid = 0;
- }
-}
-
-/* The appsink has received a buffer */
-static void new_sample (GstElement *sink, CustomData *data) {
- GstSample *sample;
-
- /* Retrieve the buffer */
- g_signal_emit_by_name (sink, "pull-sample", &sample);
- if (sample) {
- /* The only thing we do in this example is print a * to indicate a received buffer */
- g_print ("*");
- gst_buffer_unref (sample);
- }
-}
-
-/* This function is called when an error message is posted on the bus */
-static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
- GError *err;
- gchar *debug_info;
-
- /* Print error details on the screen */
- 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);
-
- g_main_loop_quit (data->main_loop);
-}
-
-int main(int argc, char *argv[]) {
- CustomData data;
- GstPad *tee_audio_pad, *tee_video_pad, *tee_app_pad;
- GstPad *queue_audio_pad, *queue_video_pad, *queue_app_pad;
- GstAudioInfo info;
- GstCaps *audio_caps;
- GstBus *bus;
-
- /* Initialize cumstom data structure */
- memset (&data, 0, sizeof (data));
- data.b = 1; /* For waveform generation */
- data.d = 1;
-
- /* Initialize GStreamer */
- gst_init (&argc, &argv);
-
- /* Create the elements */
- data.app_source = gst_element_factory_make ("appsrc", "audio_source");
- data.tee = gst_element_factory_make ("tee", "tee");
- data.audio_queue = gst_element_factory_make ("queue", "audio_queue");
- data.audio_convert1 = gst_element_factory_make ("audioconvert", "audio_convert1");
- data.audio_resample = gst_element_factory_make ("audioresample", "audio_resample");
- data.audio_sink = gst_element_factory_make ("autoaudiosink", "audio_sink");
- data.video_queue = gst_element_factory_make ("queue", "video_queue");
- data.audio_convert2 = gst_element_factory_make ("audioconvert", "audio_convert2");
- data.visual = gst_element_factory_make ("wavescope", "visual");
- data.video_convert = gst_element_factory_make ("videoconvert", "csp");
- data.video_sink = gst_element_factory_make ("autovideosink", "video_sink");
- data.app_queue = gst_element_factory_make ("queue", "app_queue");
- data.app_sink = gst_element_factory_make ("appsink", "app_sink");
-
- /* Create the empty pipeline */
- data.pipeline = gst_pipeline_new ("test-pipeline");
-
- if (!data.pipeline || !data.app_source || !data.tee || !data.audio_queue || !data.audio_convert1 ||
- !data.audio_resample || !data.audio_sink || !data.video_queue || !data.audio_convert2 || !data.visual ||
- !data.video_convert || !data.video_sink || !data.app_queue || !data.app_sink) {
- g_printerr ("Not all elements could be created.\n");
- return -1;
- }
-
- /* Configure wavescope */
- g_object_set (data.visual, "shader", 0, "style", 0, NULL);
-
- /* Configure appsrc */
- gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16, SAMPLE_RATE, 1, NULL);
- audio_caps = gst_audio_info_to_caps (&info);
- g_object_set (data.app_source, "caps", audio_caps, "format", GST_FORMAT_TIME, NULL);
- g_signal_connect (data.app_source, "need-data", G_CALLBACK (start_feed), &data);
- g_signal_connect (data.app_source, "enough-data", G_CALLBACK (stop_feed), &data);
-
- /* Configure appsink */
- g_object_set (data.app_sink, "emit-signals", TRUE, "caps", audio_caps, NULL);
- g_signal_connect (data.app_sink, "new-sample", G_CALLBACK (new_sample), &data);
- gst_caps_unref (audio_caps);
-
- /* Link all elements that can be automatically linked because they have "Always" pads */
- gst_bin_add_many (GST_BIN (data.pipeline), data.app_source, data.tee, data.audio_queue, data.audio_convert1, data.audio_resample,
- data.audio_sink, data.video_queue, data.audio_convert2, data.visual, data.video_convert, data.video_sink, data.app_queue,
- data.app_sink, NULL);
- if (gst_element_link_many (data.app_source, data.tee, NULL) != TRUE ||
- gst_element_link_many (data.audio_queue, data.audio_convert1, data.audio_resample, data.audio_sink, NULL) != TRUE ||
- gst_element_link_many (data.video_queue, data.audio_convert2, data.visual, data.video_convert, data.video_sink, NULL) != TRUE ||
- gst_element_link_many (data.app_queue, data.app_sink, NULL) != TRUE) {
- g_printerr ("Elements could not be linked.\n");
- gst_object_unref (data.pipeline);
- return -1;
- }
-
- /* Manually link the Tee, which has "Request" pads */
- tee_audio_pad = gst_element_get_request_pad (data.tee, "src_%u");
- g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad));
- queue_audio_pad = gst_element_get_static_pad (data.audio_queue, "sink");
- tee_video_pad = gst_element_get_request_pad (data.tee, "src_%u");
- g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad));
- queue_video_pad = gst_element_get_static_pad (data.video_queue, "sink");
- tee_app_pad = gst_element_get_request_pad (data.tee, "src_%u");
- g_print ("Obtained request pad %s for app branch.\n", gst_pad_get_name (tee_app_pad));
- queue_app_pad = gst_element_get_static_pad (data.app_queue, "sink");
- if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK ||
- gst_pad_link (tee_video_pad, queue_video_pad) != GST_PAD_LINK_OK ||
- gst_pad_link (tee_app_pad, queue_app_pad) != GST_PAD_LINK_OK) {
- g_printerr ("Tee could not be linked\n");
- gst_object_unref (data.pipeline);
- return -1;
- }
- gst_object_unref (queue_audio_pad);
- gst_object_unref (queue_video_pad);
- gst_object_unref (queue_app_pad);
-
- /* Instruct the bus to emit signals for each received message, and connect to the interesting signals */
- bus = gst_element_get_bus (data.pipeline);
- gst_bus_add_signal_watch (bus);
- g_signal_connect (G_OBJECT (bus), "message::error", (GCallback)error_cb, &data);
- gst_object_unref (bus);
-
- /* Start playing the pipeline */
- gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
-
- /* Create a GLib Main Loop and set it to run */
- data.main_loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (data.main_loop);
-
- /* Release the request pads from the Tee, and unref them */
- gst_element_release_request_pad (data.tee, tee_audio_pad);
- gst_element_release_request_pad (data.tee, tee_video_pad);
- gst_element_release_request_pad (data.tee, tee_app_pad);
- gst_object_unref (tee_audio_pad);
- gst_object_unref (tee_video_pad);
- gst_object_unref (tee_app_pad);
-
- /* Free resources */
- gst_element_set_state (data.pipeline, GST_STATE_NULL);
- gst_object_unref (data.pipeline);
- return 0;
-}
-