1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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;
}
|