From: Antonio Ospite Date: Thu, 24 Oct 2013 12:47:29 +0000 (+0200) Subject: Add a c/ subdir for experiments with the C API X-Git-Url: https://git.ao2.it/experiments/gstreamer.git/commitdiff_plain/9371b7d21875e6a8ae1c79765e462b77fef0c601 Add a c/ subdir for experiments with the C API --- diff --git a/c/gst-basic-example/Makefile b/c/gst-basic-example/Makefile new file mode 100644 index 0000000..f1e87cb --- /dev/null +++ b/c/gst-basic-example/Makefile @@ -0,0 +1,39 @@ +CFLAGS = -std=c99 -pedantic -pedantic-errors -Wall -g3 -O2 -D_ANSI_SOURCE_ +CFLAGS += -fno-common \ + -Wall \ + -Wdeclaration-after-statement \ + -Wextra \ + -Wformat=2 \ + -Winit-self \ + -Winline \ + -Wpacked \ + -Wp,-D_FORTIFY_SOURCE=2 \ + -Wpointer-arith \ + -Wlarger-than-65500 \ + -Wmissing-declarations \ + -Wmissing-format-attribute \ + -Wmissing-noreturn \ + -Wmissing-prototypes \ + -Wnested-externs \ + -Wold-style-definition \ + -Wredundant-decls \ + -Wsign-compare \ + -Wstrict-aliasing=2 \ + -Wstrict-prototypes \ + -Wundef \ + -Wunreachable-code \ + -Wunsafe-loop-optimizations \ + -Wunused-but-set-variable \ + -Wwrite-strings + +CFLAGS += $(shell pkg-config --cflags gstreamer-1.0) +LDLIBS += $(shell pkg-config --libs gstreamer-1.0) + +gst-basic-example: gst-basic-example.o + +clean: + rm -f *~ *.o gst-basic-example + +test: gst-basic-example + G_DEBUG=gc-friendly G_SLICE=always-malloc \ + valgrind --leak-check=full --show-reachable=yes ./gst-basic-example diff --git a/c/gst-basic-example/gst-basic-example.c b/c/gst-basic-example/gst-basic-example.c new file mode 100644 index 0000000..5c0ffce --- /dev/null +++ b/c/gst-basic-example/gst-basic-example.c @@ -0,0 +1,97 @@ +/* gst-basic-example - basic example program for the GStreamer 1,0 API + * + * Copyright (C) 2013 Antonio Ospite + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +static gboolean on_message(GstBus *bus, GstMessage *message, gpointer user_data) +{ + GMainLoop *loop = (GMainLoop *)user_data; + + switch (GST_MESSAGE_TYPE(message)) { + case GST_MESSAGE_ERROR: + g_error("Got ERROR"); + g_main_loop_quit(loop); + break; + case GST_MESSAGE_WARNING: + g_warning("Got WARNING"); + g_main_loop_quit(loop); + break; + case GST_MESSAGE_EOS: + g_main_loop_quit(loop); + break; + default: + break; + } + + return TRUE; +} + +int main(void) +{ + GstElement *pipeline, *src, *capsfilter, *conv, *sink; + GstCaps *caps; + GstBus *bus; + GMainLoop *loop; + int ret; + + gst_init(NULL, NULL); + + pipeline = gst_element_factory_make("pipeline", NULL); + + src = gst_element_factory_make("videotestsrc", NULL); + + caps = gst_caps_from_string("video/x-raw,format=AYUV,width=800,height=480"); + + capsfilter = gst_element_factory_make("capsfilter", NULL); + g_object_set(G_OBJECT(capsfilter), "caps", caps, NULL); + + conv = gst_element_factory_make("videoconvert", NULL); + + sink = gst_element_factory_make("autovideosink", NULL); + g_return_val_if_fail(sink != NULL, -1); + + gst_bin_add_many(GST_BIN(pipeline), src, capsfilter, conv, sink, NULL); + ret = gst_element_link_many(src, capsfilter, conv, sink, NULL); + if (!ret) { + g_error("Failed to link elements"); + return -2; + } + + loop = g_main_loop_new(NULL, FALSE); + + bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); + gst_bus_add_signal_watch(bus); + g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(on_message), + loop); + gst_object_unref(GST_OBJECT(bus)); + + ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + if (ret == GST_STATE_CHANGE_FAILURE) { + g_error("Failed to go into PLAYING state"); + return -3; + } + + g_main_loop_run(loop); + + gst_element_set_state(pipeline, GST_STATE_NULL); + + g_main_loop_unref(loop); + gst_object_unref(pipeline); + + return 0; +}