| 1 | /* |
| 2 | * The example presents how to initialize gstreamermm, read |
| 3 | * version of GStreamer, and use GStreamer option group together |
| 4 | * with your application's option group. |
| 5 | */ |
| 6 | #include <gstreamermm.h> |
| 7 | #include <glibmm/optioncontext.h> |
| 8 | |
| 9 | #include <iostream> |
| 10 | |
| 11 | class MainOptionGroup : public Glib::OptionGroup |
| 12 | { |
| 13 | public: |
| 14 | MainOptionGroup(); |
| 15 | |
| 16 | bool version; |
| 17 | }; |
| 18 | |
| 19 | MainOptionGroup::MainOptionGroup() |
| 20 | : Glib::OptionGroup("main_group", "main group"), |
| 21 | version(false) |
| 22 | { |
| 23 | Glib::OptionEntry entry1; |
| 24 | entry1.set_long_name("version"); |
| 25 | entry1.set_short_name('v'); |
| 26 | entry1.set_description("Show gstreamer version"); |
| 27 | add_entry(entry1, version); |
| 28 | } |
| 29 | |
| 30 | static void print_gstreamer_version() |
| 31 | { |
| 32 | guint major, minor, micro, nano; |
| 33 | |
| 34 | // Read GStreamer version |
| 35 | Gst::version(major, minor, micro, nano); |
| 36 | |
| 37 | std::string nano_str; |
| 38 | |
| 39 | switch (nano) { |
| 40 | case 1: nano_str = "(CSV)"; break; |
| 41 | case 2: nano_str = "(Prerelease)"; break; |
| 42 | } |
| 43 | |
| 44 | std::cout << "This program is linked against GStreamer " |
| 45 | << major << "." << minor << "." << micro << "." |
| 46 | << nano << " " << nano_str << std::endl; |
| 47 | } |
| 48 | |
| 49 | int main (int argc, char *argv[]) |
| 50 | { |
| 51 | // Initialize gstreamermm |
| 52 | Gst::init(argc, argv); |
| 53 | |
| 54 | Glib::OptionContext context("- gstreamermm init example"); |
| 55 | |
| 56 | MainOptionGroup main_group; |
| 57 | context.set_main_group(main_group); |
| 58 | |
| 59 | // Get GStreamer option group and add it to the context |
| 60 | Glib::OptionGroup gst_group = Gst::get_option_group(); |
| 61 | context.add_group(gst_group); |
| 62 | |
| 63 | try |
| 64 | { |
| 65 | context.parse(argc, argv); |
| 66 | } |
| 67 | catch (const Glib::Error& ex) |
| 68 | { |
| 69 | std::cerr << "Failed to initialize: " << ex.what() << std::endl; |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | if (main_group.version) |
| 74 | { |
| 75 | print_gstreamer_version(); |
| 76 | } |
| 77 | |
| 78 | std::cout << "Run me with --help to see the Application options appended." << std::endl; |
| 79 | |
| 80 | return 0; |
| 81 | } |