[gstreamermm] Examples: Add a "Hello World" example.
- From: Josà Alburquerque <jaalburqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gstreamermm] Examples: Add a "Hello World" example.
- Date: Thu, 3 Nov 2011 04:12:17 +0000 (UTC)
commit 0ee67ab7e89f8add1d53961bd623ac9ff9630fde
Author: Josà Alburquerque <jaalburqu svn gnome org>
Date: Thu Nov 3 00:10:21 2011 -0400
Examples: Add a "Hello World" example.
* examples/Makefile.am:
* examples/hello_world/main.cc: Add a translation of the GStreamer
helloworld example so that the GStreamer bindings page can be updated
correctly (see the e-mail:
http://lists.freedesktop.org/archives/gstreamer-devel/2011-October/033776.html)
ChangeLog | 10 ++++
examples/Makefile.am | 2 +
examples/hello_world/main.cc | 114 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 126 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1ade8ce..95906c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-11-02 Josà Alburquerque <jaalburqu svn gnome org>
+
+ Examples: Add a "Hello World" example.
+
+ * examples/Makefile.am:
+ * examples/hello_world/main.cc: Add a translation of the GStreamer
+ helloworld example so that the GStreamer bindings page can be updated
+ correctly (see the e-mail:
+ http://lists.freedesktop.org/archives/gstreamer-devel/2011-October/033776.html)
+
2011-09-06 Josà Alburquerque <jaalburqu svn gnome org>
Preset: Add an include to fix the build with git sources.
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 70daff6..c2fcc1a 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -25,6 +25,7 @@ endif
noinst_PROGRAMS = \
element_link/example \
+ hello_world/example \
ogg_player/example \
optiongroup/example \
typefind/example \
@@ -38,6 +39,7 @@ AM_CXXFLAGS = $(GSTREAMERMM_WXXFLAGS)
LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm)
element_link_example_SOURCES = element_link/element_link.cc
+hello_world_example_SOURCES = hello_world/main.cc
media_player_gtkmm_example_SOURCES = media_player_gtkmm/main.cc \
media_player_gtkmm/player_window.cc \
media_player_gtkmm/player_window.h
diff --git a/examples/hello_world/main.cc b/examples/hello_world/main.cc
new file mode 100644
index 0000000..cb006bc
--- /dev/null
+++ b/examples/hello_world/main.cc
@@ -0,0 +1,114 @@
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2011 The gstreamermm Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <gstreamermm.h>
+#include <iostream>
+#include <stdlib.h>
+
+namespace
+{
+
+Glib::RefPtr<Glib::MainLoop> mainloop;
+
+// This function is used to receive asynchronous messages in the main loop.
+bool on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */,
+ const Glib::RefPtr<Gst::Message>& message)
+{
+ switch(message->get_message_type()) {
+ case Gst::MESSAGE_EOS:
+ std::cout << std::endl << "End of stream" << std::endl;
+ mainloop->quit();
+ return false;
+ case Gst::MESSAGE_ERROR:
+ {
+ Glib::RefPtr<Gst::MessageError> msgError =
+ Glib::RefPtr<Gst::MessageError>::cast_dynamic(message);
+
+ if(msgError)
+ {
+ Glib::Error err;
+ err = msgError->parse();
+ std::cerr << "Error: " << err.what() << std::endl;
+ }
+ else
+ std::cerr << "Error." << std::endl;
+
+ mainloop->quit();
+ return false;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+} // anonymous namespace
+
+int main(int argc, char** argv)
+{
+ // Initialize gstreamermm:
+ Gst::init(argc, argv);
+
+ // Check input arguments:
+ if(argc < 2)
+ {
+ std::cout << "Usage: " << argv[0] << " <media file or uri>" << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // Create a playbin2 element.
+ Glib::RefPtr<Gst::PlayBin2> playbin = Gst::PlayBin2::create();
+
+ if(!playbin)
+ {
+ std::cerr << "The playbin2 element could not be created." << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // Take the commandline argument and ensure that it is a uri:
+ Glib::ustring uri;
+
+ if(gst_uri_is_valid(argv[1]))
+ uri = argv[1];
+ else
+ uri = Glib::filename_to_uri(argv[1]);
+
+ // Set the playbyin2's uri property.
+ playbin->property_uri() = uri;
+
+ // Create the main loop.
+ mainloop = Glib::MainLoop::create();
+
+ // Get the bus from the playbin, and add a bus watch to the default main
+ // context with the default priority:
+ Glib::RefPtr<Gst::Bus> bus = playbin->get_bus();
+ bus->add_watch(sigc::ptr_fun(&on_bus_message));
+
+ // Now set the playbin to the PLAYING state and start the main loop:
+ std::cout << "Setting to PLAYING." << std::endl;
+ playbin->set_state(Gst::STATE_PLAYING);
+ std::cout << "Running." << std::endl;
+ mainloop->run();
+
+ // Clean up nicely:
+ std::cout << "Returned. Stopping playback." << std::endl;
+ playbin->set_state(Gst::STATE_NULL);
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]