[gstreamermm] Examples: add few simple examples
- From: Marcin Kolny <mkolny src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gstreamermm] Examples: add few simple examples
- Date: Sun, 28 Aug 2016 18:51:14 +0000 (UTC)
commit 6dbbbb3cd6133392f64140627d2e3f2e5e36d60d
Author: Marcin Kolny <marcin kolny gmail com>
Date: Sun Aug 28 20:47:24 2016 +0200
Examples: add few simple examples
.gitignore | 2 +
examples/Makefile.am | 8 +++-
examples/basics/element_factory.cc | 65 ++++++++++++++++++++++++++++
examples/basics/init_gstreamermm.cc | 81 +++++++++++++++++++++++++++++++++++
gstreamer/gstreamermm/init.h | 5 ++
gstreamer/src/elementfactory.hg | 4 ++
6 files changed, 164 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index dab89f3..7e79bd9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,6 +39,8 @@ stamp-h?
#examples/
/examples/*/example
+/examples/basics/element_factory
+/examples/basics/init_gstreamermm
# gstreamer/
gstreamer/gstreamermm/allocator.cc
diff --git a/examples/Makefile.am b/examples/Makefile.am
index b7d00bc..dd9b47a 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -55,12 +55,14 @@ noinst_PROGRAMS = \
ogg_rewriter/example \
typefind/example \
optiongroup/example \
+ basics/element_factory \
+ basics/init_gstreamermm \
$(gl_examples) \
$(gui_examples)
AM_CPPFLAGS = -I$(top_builddir) $(gstreamermm_includes) $(examples_cppflags)
-AM_CXXFLAGS = $(GSTREAMERMM_WXXFLAGS) -std=c++0x
+AM_CXXFLAGS = $(GSTREAMERMM_WXXFLAGS) -std=c++11
LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm)
all_media_player_example_SOURCES = all_media_player/main.cc
@@ -74,3 +76,7 @@ ogg_player_example_SOURCES = ogg_player/main.cc
opengl_filter_example_SOURCES = opengl_filter/main.cc
optiongroup_example_SOURCES = optiongroup/main.cc
typefind_example_SOURCES = typefind/main.cc
+
+# basic examples
+basics_element_factory_SOURCES = basics/element_factory.cc
+basics_init_gstreamermm_SOURCES = basics/init_gstreamermm.cc
diff --git a/examples/basics/element_factory.cc b/examples/basics/element_factory.cc
new file mode 100644
index 0000000..5ba8418
--- /dev/null
+++ b/examples/basics/element_factory.cc
@@ -0,0 +1,65 @@
+/*
+ * This example presents how to use Gst::ElementFactory class, getting
+ * information and create specific element.
+ */
+#include <gstreamermm.h>
+
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+ Gst::init(argc, argv);
+
+ // Get list of all primary demuxers in the system
+ std::cout << "List of primary demuxers: " << std::endl;
+ for (Glib::RefPtr<Gst::ElementFactory> factory
+ : Gst::ElementFactory::get_elements(Gst::ELEMENT_FACTORY_TYPE_DEMUXER, Gst::RANK_PRIMARY))
+ {
+ std::cout << " * " << factory->get_name() << std::endl;
+ }
+ std::cout << std::endl;
+
+ Glib::RefPtr<Gst::ElementFactory> fakesrc_factory = Gst::ElementFactory::find("fakesrc");
+ if (!fakesrc_factory)
+ {
+ std::cerr << "Failed to find factory of type 'fakesrc'" << std::endl;
+ return -1;
+ }
+
+ // Read information about an author of the element
+ std::cout << "Author of the element '" << fakesrc_factory->get_name() << "' is "
+ << fakesrc_factory->get_metadata(GST_ELEMENT_METADATA_AUTHOR) << std::endl << std::endl;
+
+ // Read all available information about the element
+ std::cout << "All information about element '" << fakesrc_factory->get_name() << "':" << std::endl;
+ for (auto metadata_key : fakesrc_factory->get_metadata_keys())
+ {
+ std::cout << " * " << metadata_key << ": " << fakesrc_factory->get_metadata(metadata_key) << std::endl;
+ }
+
+
+ // Create element fakesrc
+
+ // Method 1
+ {
+ Glib::RefPtr<Gst::Element> fakesrc = fakesrc_factory->create("source");
+
+ if (!fakesrc)
+ {
+ std::cerr << "Failed to create element of type 'fakesrc'" << std::endl;
+ return -1;
+ }
+ }
+
+ // Method 2
+ {
+ Glib::RefPtr<Gst::Element> fakesrc = Gst::ElementFactory::create_element("fakesrc", "source");
+ if (!fakesrc)
+ {
+ std::cerr << "Failed to create element of type 'fakesrc'" << std::endl;
+ return -1;
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/basics/init_gstreamermm.cc b/examples/basics/init_gstreamermm.cc
new file mode 100644
index 0000000..da54d0a
--- /dev/null
+++ b/examples/basics/init_gstreamermm.cc
@@ -0,0 +1,81 @@
+/*
+ * The example presents how to initialize gstreamermm, read
+ * version of GStreamer, and use GStreamer option group together
+ * with your application's option group.
+ */
+#include <gstreamermm.h>
+#include <glibmm.h>
+
+#include <iostream>
+
+class MainOptionGroup : public Glib::OptionGroup
+{
+public:
+ MainOptionGroup();
+
+ bool version;
+};
+
+MainOptionGroup::MainOptionGroup()
+: Glib::OptionGroup("main_group", "main group"),
+ version(false)
+{
+ Glib::OptionEntry entry1;
+ entry1.set_long_name("version");
+ entry1.set_short_name('v');
+ entry1.set_description("Show gstreamer version");
+ add_entry(entry1, version);
+}
+
+static void print_gstreamer_version()
+{
+ guint major, minor, micro, nano;
+
+ // Read GStreamer version
+ Gst::version(major, minor, micro, nano);
+
+ std::string nano_str;
+
+ switch (nano) {
+ case 1: nano_str = "(CSV)"; break;
+ case 2: nano_str = "(Prerelease)"; break;
+ }
+
+ std::cout << "This program is linked against GStreamer "
+ << major << "." << minor << "." << micro << "."
+ << nano << " " << nano_str << std::endl;
+}
+
+int main (int argc, char *argv[])
+{
+ // Initialize gstreamermm
+ Gst::init(argc, argv);
+
+ Glib::OptionContext context("- gstreamermm init example");
+
+ MainOptionGroup main_group;
+ context.set_main_group(main_group);
+
+ // Get GStreamer option group and add it to the context
+ Glib::OptionGroup gst_group = Gst::get_option_group();
+ context.add_group(gst_group);
+
+ try
+ {
+ context.parse(argc, argv);
+ }
+ catch (const Glib::Error& ex)
+ {
+ std::cerr << "Failed to initialize: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ if (main_group.version)
+ {
+ print_gstreamer_version();
+ }
+
+ std::cout << "Run me with --help to see the Application options appended." << std::endl;
+
+ return 0;
+}
diff --git a/gstreamer/gstreamermm/init.h b/gstreamer/gstreamermm/init.h
index 4382068..87fcbff 100644
--- a/gstreamer/gstreamermm/init.h
+++ b/gstreamer/gstreamermm/init.h
@@ -250,6 +250,11 @@ void registry_fork_set_enabled(bool enabled);
*/
bool update_registry();
+
+/*! A gstreamermm init example.
+ * @example basics/init_gstreamermm.cc
+ */
+
}//end namespace Gst
#endif //_GSTREAMERMM_INIT_H
diff --git a/gstreamer/src/elementfactory.hg b/gstreamer/src/elementfactory.hg
index d3cefb2..3169ab9 100644
--- a/gstreamer/src/elementfactory.hg
+++ b/gstreamer/src/elementfactory.hg
@@ -150,4 +150,8 @@ public:
_WRAP_METHOD(bool is_type(ElementFactoryListType type) const, gst_element_factory_list_is_type)
};
+/*! A gstreamermm Gst::ElementFactory example.
+ * @example basics/element_factory.cc
+ */
+
} // namespace Gst
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]