QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
element.h
00001 /*
00002     Copyright (C) 2010  George Kiagiadakis <kiagiadakis.george@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as published
00006     by the Free Software Foundation; either version 2.1 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public License
00015     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 #ifndef QGST_ELEMENT_H
00018 #define QGST_ELEMENT_H
00019 
00020 #include "object.h"
00021 #include "caps.h"
00022 #include "clocktime.h"
00023 
00024 #if !QGLIB_HAVE_CXX0X
00025 # include <boost/preprocessor.hpp>
00026 #endif
00027 
00028 namespace QGst {
00029 
00033 class QTGSTREAMER_EXPORT Element : public Object
00034 {
00035     QGST_WRAPPER(Element)
00036 public:
00037     State currentState() const;
00038     State pendingState() const;
00039     StateChangeReturn getState(State *state, State *pending, ClockTime timeout) const;
00040     StateChangeReturn setState(State state);
00041     bool syncStateWithParent();
00042 
00043     bool stateIsLocked() const;
00044     bool setStateLocked(bool locked);
00045 
00046     bool addPad(const PadPtr & pad);
00047     bool removePad(const PadPtr & pad);
00048 
00049     PadPtr getStaticPad(const char *name);
00050     PadPtr getRequestPad(const char *name);
00051     void releaseRequestPad(const PadPtr & pad);
00052 
00053     ClockPtr clock() const;
00054     bool setClock(const ClockPtr & clock);
00055 
00056     bool link(const char *srcPadName, const ElementPtr & dest,
00057               const char *sinkPadName, const CapsPtr & filter = CapsPtr());
00058     bool link(const char *srcPadName, const ElementPtr & dest,
00059               const CapsPtr & filter = CapsPtr());
00060     bool link(const ElementPtr & dest, const char *sinkPadName,
00061               const CapsPtr & filter = CapsPtr());
00062     bool link(const ElementPtr & dest, const CapsPtr & filter = CapsPtr());
00063 
00064 #ifndef DOXYGEN_RUN
00065     //FIXME-0.11 Remove the default NULL parameter from the first version
00066     //and remove entirely sinkPadName from the second version
00067     void unlink(const char *srcPadName, const ElementPtr & dest,
00068                 const char *sinkPadName = NULL);
00069     void unlink(const ElementPtr & dest, const char *sinkPadName = NULL);
00070 #else
00071     //documentation should show those functions as they are meant to be used.
00074     void unlink(const char *srcPadName, const ElementPtr & dest, const char *sinkPadName);
00075 
00077     void unlink(const ElementPtr & dest);
00078 #endif
00079 
00080 #ifndef DOXYGEN_RUN
00081 private:
00082     static inline bool linkMany(const ElementPtr & first, const ElementPtr & second)
00083     {
00084         return first->link(second);
00085     }
00086 
00087     static inline void unlinkMany(const ElementPtr & first, const ElementPtr & second)
00088     {
00089         first->unlink(second);
00090     }
00091 public:
00092 #endif
00093 
00094 #if QGLIB_HAVE_CXX0X
00095 
00101     template <typename First, typename Second, typename Third, typename... Rest>
00102     static inline bool linkMany(const First & first, const Second & second,
00103                                 const Third & third, const Rest & ... rest)
00104     {
00105         if (!first->link(second)) return false;
00106         return linkMany(second, third, rest...);
00107     }
00108 
00115     template <typename First, typename Second, typename Third, typename... Rest>
00116     static inline void unlinkMany(const First & first, const Second & second,
00117                                   const Third & third, const Rest & ... rest)
00118     {
00119         first->unlink(second);
00120         unlinkMany(second, third, rest...);
00121     }
00122 #else //QGLIB_HAVE_CXX0X
00123 
00124 # ifndef QGST_ELEMENT_LINK_MANY_MAX_ARGS
00125 #  define QGST_ELEMENT_LINK_MANY_MAX_ARGS 10
00126 # endif
00127 
00128 # ifndef QGST_ELEMENT_UNLINK_MANY_MAX_ARGS
00129 #  define QGST_ELEMENT_UNLINK_MANY_MAX_ARGS 10
00130 # endif
00131 
00132 # define QGST_ELEMENT_LINK_MANY_DECLARATION(z, n, data) \
00133     static inline bool linkMany(BOOST_PP_ENUM_PARAMS(n, const ElementPtr & e)) \
00134     { \
00135         if (!e0->link(e1)) return false; \
00136         return linkMany(BOOST_PP_ENUM_SHIFTED_PARAMS(n, e)); \
00137     };
00138 
00139 # define QGST_ELEMENT_UNLINK_MANY_DECLARATION(z, n, data) \
00140     static inline void unlinkMany(BOOST_PP_ENUM_PARAMS(n, const ElementPtr & e)) \
00141     { \
00142         e0->unlink(e1); \
00143         unlinkMany(BOOST_PP_ENUM_SHIFTED_PARAMS(n, e)); \
00144     };
00145 
00146     BOOST_PP_REPEAT_FROM_TO(3, BOOST_PP_INC(QGST_ELEMENT_LINK_MANY_MAX_ARGS),
00147                             QGST_ELEMENT_LINK_MANY_DECLARATION, dummy)
00148     BOOST_PP_REPEAT_FROM_TO(3, BOOST_PP_INC(QGST_ELEMENT_UNLINK_MANY_MAX_ARGS),
00149                             QGST_ELEMENT_UNLINK_MANY_DECLARATION, dummy)
00150 
00151 # undef QGST_ELEMENT_LINK_MANY_DECLARATION
00152 # undef QGST_ELEMENT_UNLINK_MANY_DECLARATION
00153 
00154 #endif //QGLIB_HAVE_CXX0X
00155 
00156     bool query(const QueryPtr & query);
00157     bool sendEvent(const EventPtr & event);
00158     bool seek(Format format, SeekFlags flags, quint64 position);
00159 };
00160 
00161 }
00162 
00163 QGST_REGISTER_TYPE(QGst::Element)
00164 
00165 #endif // QGST_ELEMENT_H