| 1 | /* |
| 2 | * This example presents how to use Gst::ElementFactory class, getting |
| 3 | * information and create specific element. |
| 4 | */ |
| 5 | #include <gstreamermm.h> |
| 6 | |
| 7 | #include <iostream> |
| 8 | |
| 9 | int main(int argc, char *argv[]) |
| 10 | { |
| 11 | Gst::init(argc, argv); |
| 12 | |
| 13 | // Get list of all primary demuxers in the system |
| 14 | std::cout << "List of primary demuxers: " << std::endl; |
| 15 | for (Glib::RefPtr<Gst::ElementFactory> factory |
| 16 | : Gst::ElementFactory::get_elements(Gst::ELEMENT_FACTORY_TYPE_DEMUXER, Gst::RANK_PRIMARY)) |
| 17 | { |
| 18 | std::cout << " * " << factory->get_name() << std::endl; |
| 19 | } |
| 20 | std::cout << std::endl; |
| 21 | |
| 22 | Glib::RefPtr<Gst::ElementFactory> fakesrc_factory = Gst::ElementFactory::find("fakesrc"); |
| 23 | if (!fakesrc_factory) |
| 24 | { |
| 25 | std::cerr << "Failed to find factory of type 'fakesrc'" << std::endl; |
| 26 | return -1; |
| 27 | } |
| 28 | |
| 29 | // Read information about an author of the element |
| 30 | std::cout << "Author of the element '" << fakesrc_factory->get_name() << "' is " |
| 31 | << fakesrc_factory->get_metadata(GST_ELEMENT_METADATA_AUTHOR) << std::endl << std::endl; |
| 32 | |
| 33 | // Read all available information about the element |
| 34 | std::cout << "All information about element '" << fakesrc_factory->get_name() << "':" << std::endl; |
| 35 | for (auto metadata_key : fakesrc_factory->get_metadata_keys()) |
| 36 | { |
| 37 | std::cout << " * " << metadata_key << ": " << fakesrc_factory->get_metadata(metadata_key) << std::endl; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | // Create element fakesrc |
| 42 | |
| 43 | // Method 1 |
| 44 | { |
| 45 | Glib::RefPtr<Gst::Element> fakesrc = fakesrc_factory->create("source"); |
| 46 | |
| 47 | if (!fakesrc) |
| 48 | { |
| 49 | std::cerr << "Failed to create element of type 'fakesrc'" << std::endl; |
| 50 | return -1; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // Method 2 |
| 55 | { |
| 56 | Glib::RefPtr<Gst::Element> fakesrc = Gst::ElementFactory::create_element("fakesrc", "source"); |
| 57 | if (!fakesrc) |
| 58 | { |
| 59 | std::cerr << "Failed to create element of type 'fakesrc'" << std::endl; |
| 60 | return -1; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |