/* gstreamermm - a C++ wrapper for gstreamer * * Copyright 2008-2016 The gstreamermm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include _DEFS(gstreamermm,gst) namespace Gst { /** @defgroup GstBaseClasses gstreamermm Base Classes * Wrapped GStreamer base classes (plug-ins derrive from these). */ /** @defgroup GstPlugins gstreamermm Plugins * Wrapped GStreamer plugins. */ /** @defgroup GstInterfaces gstreamermm Interfaces * Wrapped GStreamer interfaces and classes related to them. */ class Bus; class Caps; class Context; class ElementFactory; class Event; class Pad; class PadTemplate; class Query; //Gst::Iterator<> forward declaration. template class Iterator; _WRAP_ENUM(ElementFlags, GstElementFlags) _WRAP_ENUM(StateChange, GstStateChange) _WRAP_ENUM(StateChangeReturn, GstStateChangeReturn) namespace Enums { /** Gets a string representing the given state. * * @param state A Gst::State to get the name of. * @return A Glib::ustring with the name of the state. */ Glib::ustring get_name(State state); /** Gets a string representing the given state change result. * * @param state_ret A Gst::StateChangeReturn to get the name of. * @return A Glib::ustring with the name of the state change result. */ Glib::ustring get_name(StateChangeReturn state_ret); } //namespace Enums /** Abstract base class for all pipeline elements * * Gst::Element is the abstract base class needed to construct an element that * can be used in a GStreamer pipeline. Please refer to the plugin writers * guide for more information on creating Gst::Element subclasses. * * The name of a Gst::Element can be get with get_name() and set with * set_name(). * * Elements can have pads (of the type Gst::Pad). These pads link to pads on * other elements. Gst::Buffer flow between these linked pads. * A Gst::Element has a GList of Gst::Pad structures for all their input (or sink) * and output (or source) pads. * Core and plug-in writers can add and remove pads with add_pad() * and remove_pad(). * * An existing pad of an element can be retrieved by name with * get_static_pad(). A new dynamic pad can be created using * request_pad() with a Gst::PadTemplate. * An iterator of all pads can be retrieved with iterate_pads(). * * Elements can be linked through their pads. * If the link is straightforward, use the link() * convenience function to link two elements. * Use link_filtered() to link two elements constrained by * a specified set of Gst::Caps. * For finer control, use link_pads() and * link_pads_filtered() to specify the pads to link on * each element by name. * * Each element has a state (see Gst::State). You can get and set the state * of an element with get_state() and set_state(). * Setting a state triggers a Gst::StateChange. To get a string representation * of a Gst::State, use Gst::Enums::get_name(). * * You can get and set a Gst::Clock on an element using get_clock() * and set_clock(). * Some elements can provide a clock for the pipeline if * the Gst::ELEMENT_FLAG_PROVIDE_CLOCK flag is set. With the * provide_clock() method one can retrieve the clock provided by * such an element. * Not all elements require a clock to operate correctly. If the * Gst::ELEMENT_FLAG_REQUIRE_CLOCK flag is set, a clock should be set on the * element with set_clock(). * * Note that clock selection and distribution is normally handled by the * toplevel Gst::Pipeline so the clock functions are only to be used in very * specific situations. * * Last reviewed on 2016-05-18 (1.8.0). * * @ingroup GstBaseClasses */ class Element : public Gst::Object { _CLASS_GOBJECT(Element, GstElement, GST_ELEMENT, Gst::Object, GstObject) public: /** Links this source element to the @a dest element. * The link must be from source to destination - the other direction will not * be tried. The function looks for existing pads that aren't linked yet. It * will request new pads if necessary. Such pads need to be released manually * when unlinking. If multiple links are possible, only one is established. * * Make sure you have added your elements to a bin or pipeline with * Gst::Bin::add() before trying to link them. * * @param dest the Gst::Element containing the destination pad. * @return the destination element for further linking if desired. * @throws std::runtime_error If the elements could not be linked. */ Glib::RefPtr link(const Glib::RefPtr& dest); _IGNORE(gst_element_link, gst_element_link_many) _WRAP_METHOD(bool add_pad(const Glib::RefPtr& pad), gst_element_add_pad) _WRAP_METHOD(void create_all_pads(), gst_element_create_all_pads) _WRAP_METHOD(Glib::RefPtr create_compatible_pad(const Glib::RefPtr& pad, const Glib::RefPtr& caps), gst_element_get_compatible_pad) _WRAP_METHOD(Glib::RefPtr get_compatible_pad_template(const Glib::RefPtr& compattempl), gst_element_get_compatible_pad_template, refreturn) _WRAP_METHOD(Glib::RefPtr get_compatible_pad_template(const Glib::RefPtr& compattempl) const, gst_element_get_compatible_pad_template, refreturn, constversion) //TODO: The documentation says "The pad should be released with gst_element_release_request_pad().", which is odd. murrayc _WRAP_METHOD(Glib::RefPtr get_request_pad(const Glib::ustring& name), gst_element_get_request_pad) //TODO: The documentation says "The pad should be released with gst_element_release_request_pad().", which is odd. murrayc _WRAP_METHOD(Glib::RefPtr request_pad(const Glib::RefPtr& templ, const Glib::ustring& name{?}, const Glib::RefPtr& caps{?}), gst_element_request_pad) _WRAP_METHOD(Glib::RefPtr get_static_pad(const Glib::ustring& name), gst_element_get_static_pad) _WRAP_METHOD(Glib::RefPtr get_static_pad(const Glib::ustring& name) const, gst_element_get_static_pad, constversion) _WRAP_METHOD(void no_more_pads(), gst_element_no_more_pads) /** Makes the element free the previously requested pad as obtained with * get_request_pad(). * MT safe. * @param pad The Gst::Pad to release. */ _WRAP_METHOD(void release_request_pad(const Glib::RefPtr& pad), gst_element_release_request_pad) _WRAP_METHOD(bool remove_pad(const Glib::RefPtr& pad), gst_element_remove_pad) _WRAP_METHOD(Gst::Iterator iterate_pads(), gst_element_iterate_pads) _WRAP_METHOD(Gst::Iterator iterate_pads() const, gst_element_iterate_pads) _WRAP_METHOD(Gst::Iterator iterate_sink_pads(), gst_element_iterate_sink_pads) _WRAP_METHOD(Gst::Iterator iterate_sink_pads() const, gst_element_iterate_sink_pads) _WRAP_METHOD(Gst::Iterator iterate_src_pads(), gst_element_iterate_src_pads) _WRAP_METHOD(Gst::Iterator iterate_src_pads() const, gst_element_iterate_src_pads) _WRAP_METHOD(void unlink(const Glib::RefPtr& dest), gst_element_unlink) _WRAP_METHOD(void set_context(const Glib::RefPtr& context), gst_element_set_context) _IGNORE(gst_element_unlink_many) //This is not like link() because link() was written to return the //destination element as a convenience for further linking to compensate for //C API's convenience function gst_element_link_many(). _WRAP_METHOD(bool link_pads(const Glib::ustring& srcpadname, const Glib::RefPtr& dest, const Glib::ustring& destpadname), gst_element_link_pads) _WRAP_METHOD(void unlink_pads(const Glib::ustring& srcpadname, const Glib::RefPtr& dest, const Glib::ustring& destpadname), gst_element_unlink_pads) //This is not like link() because link() was written to return the //destination element as a convenience for further linking to compensate for //C API's convenience function gst_element_link_many(). _WRAP_METHOD(bool link_pads(const Glib::ustring& srcpadname, const Glib::RefPtr& dest, const Glib::ustring& destpadname, const Glib::RefPtr& filter), gst_element_link_pads_filtered) //This is not like link() because link() was written to return the //destination element as a convenience for further linking to compensate for //C API's convenience function gst_element_link_many(). _WRAP_METHOD(bool link_pads(const Glib::ustring& srcpadname, const Glib::RefPtr& dest, const Glib::ustring& destpadname, PadLinkCheck flags), gst_element_link_pads_full) /** Links @a src to @a dest using the given caps as filtercaps. The link must * be from source to destination; the other direction will not be tried. The * function looks for existing pads that aren't linked yet. It will request * new pads if necessary. If multiple links are possible, only one is * established. * * Make sure you have added your elements to a bin or pipeline with * Gst::Bin::add() before trying to link them. * * @param dest The Gst::Element containing the destination pad. * @param filter The Gst::Caps to filter the link. * @return the destination element for further linking if desired. * @throws std::runtime_error If the elements could not be linked. */ Glib::RefPtr link(const Glib::RefPtr& dest, const Glib::RefPtr& filter); _IGNORE(gst_element_link_filtered) _WRAP_METHOD(void set_base_time(ClockTime time), gst_element_set_base_time) _WRAP_METHOD(ClockTime get_base_time() const, gst_element_get_base_time) _WRAP_METHOD(void set_start_time(Gst::ClockTime time), gst_element_set_start_time) _WRAP_METHOD(Gst::ClockTime get_start_time() const, gst_element_get_start_time) _WRAP_METHOD(void set_bus(const Glib::RefPtr& bus), gst_element_set_bus) _WRAP_METHOD(Glib::RefPtr get_bus(), gst_element_get_bus) _WRAP_METHOD(Glib::RefPtr get_bus() const, gst_element_get_bus, constversion) _WRAP_METHOD(Glib::RefPtr get_factory(), gst_element_get_factory, refreturn) _WRAP_METHOD(Glib::RefPtr get_factory() const, gst_element_get_factory, refreturn, constversion) // We don't wrap the gst_element_get_name(), gst_element_set_name(), // gst_element_get_parent(), and gst_element_set_parent() macros because they // just calls the base (GstObject) class's functions anyway. _WRAP_METHOD(bool set_clock(const Glib::RefPtr& clock), gst_element_set_clock) _WRAP_METHOD(Glib::RefPtr get_clock(), gst_element_get_clock) _WRAP_METHOD(Glib::RefPtr get_clock() const, gst_element_get_clock, constversion) _WRAP_METHOD(Glib::RefPtr provide_clock(), gst_element_provide_clock) _WRAP_METHOD(Glib::RefPtr provide_clock() const, gst_element_provide_clock, constversion) _WRAP_METHOD(StateChangeReturn set_state(State state), gst_element_set_state) _WRAP_METHOD(StateChangeReturn get_state(State& state, State& pending, ClockTime timeout) const, gst_element_get_state) _WRAP_METHOD(bool set_locked_state(gboolean locked_state), gst_element_set_locked_state) _WRAP_METHOD(bool is_locked_state() const, gst_element_is_locked_state) _WRAP_METHOD(void abort_state(), gst_element_abort_state) _WRAP_METHOD(StateChangeReturn continue_state(StateChangeReturn ret), gst_element_continue_state) _WRAP_METHOD(void lost_state(), gst_element_lost_state) _WRAP_METHOD(bool sync_state_with_parent(), gst_element_sync_state_with_parent) _WRAP_METHOD(StateChangeReturn change_state(StateChange transition), gst_element_change_state) /** Post an error, warning or info message on the bus from inside an element. * * type must be of Gst::MESSAGE_ERROR, Gst::MESSAGE_WARNING or * Gst::MESSAGE_INFO. * * MT safe. * * @param code The GError code belonging to the domain. * @param line The source code line where the error was generated. * @param type The GstMessageType. * @param domain The GStreamer GError domain this message belongs to. * @param text A text string to be used as a replacement for the default * message connected to code. * @param debug A debug message to be used as a replacement for the default * debugging information. * @param file The source code file where the error was generated. * @param function The source code function where the error was generated. */ void post_message(int code, int line, MessageType type = Gst::MESSAGE_INFO, const Glib::QueryQuark& domain = get_core_error_quark(), const Glib::ustring& text = Glib::ustring(), const Glib::ustring& debug = Glib::ustring(), const Glib::ustring& file = Glib::ustring(), const Glib::ustring& function = Glib::ustring()); _IGNORE(gst_element_message_full) _WRAP_METHOD(bool post_message(Glib::RefPtr&& message), gst_element_post_message) _WRAP_METHOD(bool query(const Glib::RefPtr& query) const, gst_element_query) _WRAP_METHOD(bool query_convert(Gst::Format src_format, gint64 src_val, Format dest_format, gint64& dest_val) const, gst_element_query_convert) _WRAP_METHOD(bool query_position(Gst::Format format, gint64& cur{?}) const, gst_element_query_position) _WRAP_METHOD(bool query_duration(Gst::Format format, gint64& duration{?}) const, gst_element_query_duration) _WRAP_METHOD(bool seek(Format format, SeekFlags seek_flags, gint64 seek_pos), gst_element_seek_simple) _WRAP_METHOD(bool seek(double rate, Format format, SeekFlags flags, SeekType cur_type, gint64 cur, SeekType stop_type, gint64 stop), gst_element_seek) _WRAP_METHOD(bool send_event(Glib::RefPtr&& event), gst_element_send_event) /// A send_event() convenience overload. Allows to re-use @a event parameter after function call. bool send_event(const Glib::RefPtr& event); _WRAP_METHOD(Glib::RefPtr get_context(const Glib::ustring& context_type), gst_element_get_context) _WRAP_METHOD(Glib::RefPtr get_context_unlocked(const Glib::ustring& context_type), gst_element_get_context_unlocked) #m4 _CONVERSION(`GList*', `std::vector< Glib::RefPtr >', `Glib::ListHandler< Glib::RefPtr >::list_to_vector(const_cast($3), Glib::OWNERSHIP_DEEP)') _WRAP_METHOD(std::vector< Glib::RefPtr > get_contexts(), gst_element_get_contexts) _WRAP_SIGNAL(void no_more_pads(), "no-more-pads") #m4 _CONVERSION(`GstPad*',`const Glib::RefPtr&',`Glib::wrap($3, true)') _WRAP_SIGNAL(void pad_added(const Glib::RefPtr& new_pad), "pad-added") _WRAP_SIGNAL(void pad_removed(const Glib::RefPtr& old_pad), "pad-removed") /** Called when a request pad is to be released. */ _WRAP_VFUNC(void release_pad(const Glib::RefPtr& pad), "release_pad") /** Called when a new pad is requested. */ _WRAP_VFUNC(Glib::RefPtr request_new_pad(Glib::RefPtr templ, const Glib::ustring& name, const Glib::RefPtr& caps), "request_new_pad") /** Get the state of the element. */ _WRAP_VFUNC(StateChangeReturn get_state(State& state, State& pending, ClockTime timeout) const, "get_state") /** Set a new state on the element. */ _WRAP_VFUNC(StateChangeReturn set_state(State state), "set_state") /** Called by set_state to perform an incremental state change. */ _WRAP_VFUNC(StateChangeReturn change_state(StateChange transition), "change_state") /** Called immediately after a new state was set. */ _WRAP_VFUNC(void state_changed(Gst::State oldstate, Gst::State newstate, Gst::State pending), "state_changed") #m4 _CONVERSION(`GstBus*', `const Glib::RefPtr&', `Glib::wrap($3, true)') /** Set a Gst::Bus on the element. */ _WRAP_VFUNC(void set_bus(const Glib::RefPtr& bus), "set_bus") /** Gets the Gst::Clock provided by the element. */ _WRAP_VFUNC(Glib::RefPtr provide_clock(), "provide_clock") #m4 _CONVERSION(`GstClock*', `const Glib::RefPtr&', `Glib::wrap($3, true)') /** Set the Gst::Clock on the element. */ _WRAP_VFUNC(bool set_clock(const Glib::RefPtr& clock), "set_clock", return_value true) #m4 _CONVERSION(`GstEvent*',`const Glib::RefPtr&', `Glib::wrap($3, true)') /** Send a Gst::Event to the element. */ _WRAP_VFUNC(bool send_event(const Glib::RefPtr& event), "send_event") #m4 _CONVERSION(`GstQuery*',`const Glib::RefPtr&', `Glib::wrap($3, true)') /** Perform a Gst::Query on the element. */ _WRAP_VFUNC(bool query(const Glib::RefPtr& query) const, "query") /** Set a Gst::Context on the element */ _WRAP_VFUNC(void set_context(const Glib::RefPtr& context), "set_context") #m4 _CONVERSION(`GstMessage*',`const Glib::RefPtr&',`Glib::wrap($3, true)') /** Called when a message is posted on the element. * Chain up to the parent class' handler to have it posted on the bus. */ _WRAP_VFUNC(bool post_message(const Glib::RefPtr& message), "post_message") Glib::RefPtr get_pad_template(const Glib::ustring &factory_name) const; /** * Sets specified property. Allows to create property-chain * (e.g. element->property("location", "test.ogg")->property("num_buffers", 20); * * @param name The property name. * @param value The property value. * * @return A this element. */ template Glib::RefPtr property(const Glib::ustring& name, const T& value) { set_property(name, value); return Glib::RefPtr( dynamic_cast (Glib::wrap_auto ((GObject*)(gobj()), true)) ); } }; } // namespace Gst