/* 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 _DEFS(gstreamermm,gst) namespace Gst { /** A base class for simple transform filters. * This base class is for filter elements that process data. * * It provides for: * - one sinkpad and one srcpad * - Possible formats on sink and source pad implemented with custom * transform_caps_vfunc() function. By default uses same format on sink and * source. * - Handles state changes. * - Does flushing. * - Push mode. * - Pull mode if the sub-class transform_vfunc() can operate on arbitrary * data. * *

Use Cases:

* - 1. Passthrough mode * - Element has no interest in modifying the buffer. It may want to * inspect it, in which case the element should have a * transform_ip_vfunc() function. If there is no transform_ip_vfunc() * function in passthrough mode, the buffer is pushed intact. * - On the GstBaseTransformClass is the passthrough_on_same_caps * variable which will automatically set/unset passthrough based on * whether the element negotiates the same caps on both pads. * - passthrough_on_same_caps on an element that doesn't implement a * transform_caps_vfunc() function is useful for elements that only * inspect data (such as level). * . * Example elements * - Level * - VideoScale, AudioConvert, FfmpegColorSpace, AudioResample in * certain modes. * . * - 2. Modifications in-place - input buffer and output buffer are the * same thing. * - The element must implement a transform_ip_vfunc() function. * - Output buffer size must <= input buffer size. * - If the always_in_place flag is set, non-writable buffers will be * copied and passed to the transform_ip_vfunc() function, otherwise * a new buffer will be created and the transform_vfunc() function * called. * - Incoming writable buffers will be passed to the * transform_ip_vfunc() function immediately. * - only implementing transform_ip_vfunc() and not transform_vfunc() * implies always_in_place = TRUE. * . * Example elements * - Volume. * - AudioConvert in certain modes (signed/unsigned conversion). * - FfmpegColorSpace in certain modes (endianness swapping). * * - 3. Modifications only to the caps/metadata of a buffer * - The element does not require writable data, but non-writable * buffers should be subbuffered so that the meta-information can be * replaced. * - Elements wishing to operate in this mode should replace the * prepare_output_buffer_vfunc() method to create subbuffers of the * input buffer and set always_in_place to TRUE. * . * Example elements * - CapsFilter when setting caps on outgoing buffers that have none. * - Identity when it is going to re-timestamp buffers by datarate. * * - 4. Normal mode * - always_in_place flag is not set, or there is no * transform_ip_vfunc() function. * - Element will receive an input buffer and output buffer to * operate on. * - Output buffer is allocated by calling the * prepare_output_buffer_vfunc() function. * . * Example elements * - VideoScale, FfmpegColorSpace, AudioConvert when doing * scaling/conversions. * * - 5. Special output buffer allocations * - Elements which need to do special allocation of their output * buffers other than what Gst::Pad::alloc_buffer() allows should * implement a prepare_output_buffer_vfunc() method, which calls the * parent implementation and passes the newly allocated buffer. * . * Example elements * - Efence. * * Sub-class settable flags on Gst::BaseTransform * * - passthrough * - Implies that in the current configuration, the sub-class is not * interested in modifying the buffers. * - Elements which are always in passthrough mode whenever the same * caps has been negotiated on both pads can set the class variable * passthrough_on_same_caps to have this behaviour automatically. * . * - always_in_place * - Determines whether a non-writable buffer will be copied before * passing to the transform_ip function. * - Implied TRUE if no transform function is implemented. * - Implied FALSE if ONLY transform function is implemented. * * Last reviewed on 2016-05-16 (1.8.0). * * @ingroup GstBaseClasses **/ class BaseTransform : public Element { _CLASS_GOBJECT(BaseTransform, GstBaseTransform, GST_BASE_TRANSFORM, Element, GstElement) public: /** The name of the templates for the sink pad ("sink"). */ static const Glib::ustring SINK_NAME; /** The name of the templates for the source pad ("src"). */ static const Glib::ustring SRC_NAME; /** A Gst::FlowReturn that can be returned from transform_vfunc and transform_ip_vfunc * to indicate that no output buffer was generated. */ static constexpr Gst::FlowReturn FLOW_DROPPED = static_cast(GST_BASE_TRANSFORM_FLOW_DROPPED); _WRAP_METHOD(bool is_passthrough() const, gst_base_transform_is_passthrough) _WRAP_METHOD(void set_passthrough(bool passthrough), gst_base_transform_set_passthrough) _WRAP_METHOD(bool is_in_place() const, gst_base_transform_is_in_place) _WRAP_METHOD(void set_in_place(bool in_place), gst_base_transform_set_in_place) _WRAP_METHOD(bool is_qos_enabled() const, gst_base_transform_is_qos_enabled) _WRAP_METHOD(void set_qos_enabled(bool enabled), gst_base_transform_set_qos_enabled) _WRAP_METHOD(void update_qos(double proportion, Gst::ClockTimeDiff diff, Gst::ClockTime timestamp), gst_base_transform_update_qos) _WRAP_METHOD(void set_gap_aware(bool gap_aware), gst_base_transform_set_gap_aware) _WRAP_METHOD(void reconfigure_sink(), gst_base_transform_reconfigure_sink) _WRAP_METHOD(void reconfigure_src(), gst_base_transform_reconfigure_src) _WRAP_METHOD(void set_prefer_passthrough(bool prefer_passthrough), gst_base_transform_set_prefer_passthrough) _WRAP_METHOD(bool update_src_caps(const Glib::RefPtr& updated_caps), gst_base_transform_update_src_caps) /* Return the memory @allocator used by the base class and its @a params. * @param params The Gst::AllocationParams of the allocator. * @return A Gst::Allocator used. */ Glib::RefPtr get_allocator(Gst::AllocationParams& params); _IGNORE(gst_base_transform_get_allocator) /** Gives the refptr to the sink Gst::Pad object of the element. */ _MEMBER_GET_GOBJECT(sink_pad, sinkpad, Gst::Pad, GstPad*) /** Gives the refptr to the source Gst::Pad object of the element. */ _MEMBER_GET_GOBJECT(src_pad, srcpad, Gst::Pad, GstPad*) _WRAP_PROPERTY("qos", bool) /** Optional. Given the pad in this direction and the given caps, what caps * are allowed on the other pad in this element ? */ _WRAP_VFUNC(Glib::RefPtr transform_caps(PadDirection direction, const Glib::RefPtr& caps, const Glib::RefPtr& filter), "transform_caps", refreturn_ctype) /** Optional. Given the pad in this direction and the given caps, fixate the * caps on the other pad. */ _WRAP_VFUNC(Glib::RefPtr fixate_caps(PadDirection direction, const Glib::RefPtr& caps, const Glib::RefPtr& othercaps), "fixate_caps", refreturn_ctype) //TODO: This virtual function can't be wrapped without causing execution //errors with the ogg_player_gtkmm example. ///** Optional. Given the size of a buffer in the given direction with the //* given caps, calculate the size in bytes of a buffer on the other pad with //* the given other caps. The default implementation uses //* get_unit_size_vfunc() and keeps the number of units the same. //*/ //_WRAP_VFUNC(bool transform_size(PadDirection direction, const Glib::RefPtr& caps, guint size, const Glib::RefPtr& othercaps, guint& othersize), "transform_size") /** Required if the transform is not in-place. Get the size in bytes of one * unit for the given caps. */ _WRAP_VFUNC(bool get_unit_size(const Glib::RefPtr& caps, gsize& size) const, "get_unit_size") /** Allows the subclass to be notified of the actual caps set. */ _WRAP_VFUNC(bool set_caps(const Glib::RefPtr& incaps, const Glib::RefPtr& outcaps), "set_caps", return_value true) #m4 _CONVERSION(`GstEvent*', `const Glib::RefPtr&', `Glib::wrap($3, true)') /** Required if the element does not operate in-place. Transforms one * incoming buffer to one outgoing buffer. The function is allowed to change * size/timestamp/duration of the outgoing buffer. */ virtual FlowReturn transform_vfunc(const Glib::RefPtr& inbuf, const Glib::RefPtr& outbuf); /** Required if the element operates in-place. Transform the incoming buffer * in-place. */ _WRAP_VFUNC(FlowReturn transform_ip(const Glib::RefPtr& buf), "transform_ip") /** Optional. Subclasses can override this to do their own allocation of * output buffers. Elements that only do analysis can return a subbuffer or * even just increment the reference to the input buffer (if in passthrough * mode). */ virtual FlowReturn prepare_output_buffer_vfunc(const Glib::RefPtr& input, Glib::RefPtr& buffer); /** Optional. Event handler on the source pad. The default implementation * handles the event and forwards it downstream. */ _WRAP_VFUNC(bool src_event(const Glib::RefPtr& event), "src_event") /** Optional. Event handler on the sink pad. The default implementation handles * the event and forwards it downstream. */ _WRAP_VFUNC(bool sink_event(const Glib::RefPtr& event), "sink_event") /** Optional. This method is called right before the base class * will start processing. Dynamic properties or other delayed configuration * could be performed in this method. */ _WRAP_VFUNC(void before_transform(const Glib::RefPtr& buffer), "before_transform") /** Optional. Subclasses can override this method to check if * the caps can be handled by the element. The default implementation might * not be the most optimal way to check this in all cases. */ _WRAP_VFUNC(bool accept_caps(PadDirection direction, const Glib::RefPtr& caps), "accept_caps") /** Optional. Called when the element starts processing. Allows opening * external resources. */ _WRAP_VFUNC(bool start(), "start", return_value true) /** Optional. Called when the element starts processing. Allows opening * external resources. */ _WRAP_VFUNC(bool stop(), "stop", return_value true) #m4 _CONVERSION(`GstQuery*', `const Glib::RefPtr&', `Glib::wrap($3, true)') /** Setup the allocation parameters for allocating output buffers. The passed * in query contains the result of the downstream allocation query.This function * is only called when not operating in passthrough mode. The default implementation * will remove all memory dependent metadata. If there is a filter_meta method * implementation, it will be called for all metadata API in the downstream query, * otherwise the metadata API is removed. */ virtual bool decide_allocation_vfunc(const Glib::RefPtr& query); /** Return TRUE if the metadata API should be proposed in the upstream allocation query. * The default implementation is NULL and will cause all metadata to be removed. */ _WRAP_VFUNC(bool filter_meta(const Glib::RefPtr& query, GType api, const Gst::Structure& params), "filter_meta", return_value true) /** Propose buffer allocation parameters for upstream elements. This function must * be implemented if the element reads or writes the buffer content. * The query that was passed to the decide_allocation is passed in this method (or nullptr * when the element is in passthrough mode). The default implementation will pass the * query downstream when in passthrough mode and will copy all the filtered metadata API * in non-passthrough mode. */ virtual bool propose_allocation_vfunc(const Glib::RefPtr& decide_query, const Glib::RefPtr& query); #m4 _CONVERSION(`GstBuffer*', `const Glib::RefPtr&', `Glib::wrap($3, true)') /** Function which accepts a new input buffer and pre-processes it. The default * implementation performs caps (re)negotiation, then QoS if needed, and places * the input buffer into the queued_buf member variable. If the buffer is dropped * due to QoS, it returns Gst::BASE_TRANSFORM_FLOW_DROPPED. If this input buffer * is not contiguous with any previous input buffer, then is_discont is set to TRUE. */ _WRAP_VFUNC(Gst::FlowReturn submit_input_buffer(bool is_discont, const Glib::RefPtr& input), "submit_input_buffer") /** Called after each new input buffer is submitted repeatedly until it either generates * an error or fails to generate an output buffer. The default implementation takes the * contents of the queued_buf variable, generates an output buffer if needed by calling * the class prepare_output_buffer, and then calls either transform or transform_ip. * Elements that don't do 1-to-1 transformations on input to output buffers can either * return Gst::BASE_TRANSFORM_FLOW_DROPPED or simply not generate an output buffer until * they are ready to do so. */ virtual Gst::FlowReturn generate_output_vfunc(Glib::RefPtr& buffer); // TODO: wrap GstMeta first. //_WRAP_VFUNC(bool transform_meta(const Glib::RefPtr& outbuf, const Glib::RefPtr& meta, const Glib::RefPtr& inbuf), "transform_meta") /** Optional. Copy the metadata from the input buffer to the output buffer. * The default implementation will copy the flags, timestamps and offsets of the buffer. */ _WRAP_VFUNC(bool copy_metadata(const Glib::RefPtr& input, const Glib::RefPtr& outbuf), "copy_metadata") /** Optional. Handle a requested query. Subclasses that implement this should must chain up to * the parent if they didn't handle the query */ bool base_transform_query_vfunc(Gst::PadDirection direction, const Glib::RefPtr& query); protected: #m4begin _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS) klass->prepare_output_buffer = &prepare_output_buffer_vfunc_callback; klass->transform = &transform_vfunc_callback; klass->generate_output = &generate_output_vfunc_callback; klass->query = &query_vfunc_callback; klass->propose_allocation = &propose_allocation_vfunc_callback; klass->decide_allocation = &decide_allocation_vfunc_callback; _SECTION(SECTION_PH_VFUNCS) static GstFlowReturn prepare_output_buffer_vfunc_callback(GstBaseTransform* self, GstBuffer* input, GstBuffer** buf); static GstFlowReturn transform_vfunc_callback(GstBaseTransform* self, GstBuffer* inbuf, GstBuffer* outbuf); static GstFlowReturn generate_output_vfunc_callback(GstBaseTransform* self, GstBuffer** outbuf); static gboolean query_vfunc_callback(GstBaseTransform* self, GstPadDirection direction, GstQuery* query); static gboolean propose_allocation_vfunc_callback(GstBaseTransform* self, GstQuery* decide_query, GstQuery* query); static gboolean decide_allocation_vfunc_callback(GstBaseTransform* self, GstQuery* query); _POP() #m4end }; } //namespace Gst