QtGStreamer  0.10.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
element.cpp
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 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 #include "element.h"
00018 #include "pad.h"
00019 #include "query.h"
00020 #include "clock.h"
00021 #include "event.h"
00022 #include <gst/gstelement.h>
00023 #include <gst/gstutils.h>
00024 
00025 namespace QGst {
00026 
00027 State Element::currentState() const
00028 {
00029     State r;
00030     getState(&r, NULL, 0);
00031     return r;
00032 }
00033 
00034 State Element::pendingState() const
00035 {
00036     State r;
00037     getState(NULL, &r, 0);
00038     return r;
00039 }
00040 
00041 StateChangeReturn Element::getState(State *state, State *pending, ClockTime timeout) const
00042 {
00043     GstState curState, pendingState;
00044     GstStateChangeReturn result = gst_element_get_state(object<GstElement>(),
00045                                                         &curState, &pendingState, timeout);
00046     if (state) {
00047         *state = static_cast<State>(curState);
00048     }
00049     if (pending) {
00050         *pending = static_cast<State>(pendingState);
00051     }
00052     return static_cast<StateChangeReturn>(result);
00053 }
00054 
00055 StateChangeReturn Element::setState(State state)
00056 {
00057     return static_cast<StateChangeReturn>(gst_element_set_state(object<GstElement>(),
00058                                                                 static_cast<GstState>(state)));
00059 }
00060 
00061 bool Element::syncStateWithParent()
00062 {
00063    return gst_element_sync_state_with_parent(object<GstElement>());
00064 }
00065 
00066 bool Element::stateIsLocked() const
00067 {
00068     return gst_element_is_locked_state(object<GstElement>());
00069 }
00070 
00071 bool Element::setStateLocked(bool locked)
00072 {
00073     return gst_element_set_locked_state(object<GstElement>(), locked);
00074 }
00075 
00076 bool Element::addPad(const PadPtr & pad)
00077 {
00078     return gst_element_add_pad(object<GstElement>(), pad);
00079 }
00080 
00081 PadPtr Element::getStaticPad(const char *name)
00082 {
00083     GstPad *pad = gst_element_get_static_pad(object<GstElement>(), name);
00084     return PadPtr::wrap(pad, false);
00085 }
00086 
00087 PadPtr Element::getRequestPad(const char *name)
00088 {
00089     GstPad *pad = gst_element_get_request_pad(object<GstElement>(), name);
00090     return PadPtr::wrap(pad, false);
00091 }
00092 
00093 void Element::releaseRequestPad(const PadPtr & pad)
00094 {
00095     gst_element_release_request_pad(object<GstElement>(), pad);
00096 }
00097 
00098 bool Element::link(const char *srcPadName, const ElementPtr & dest,
00099                    const char *sinkPadName, const CapsPtr & filter)
00100 {
00101     return gst_element_link_pads_filtered(object<GstElement>(), srcPadName,
00102                                           dest, sinkPadName, filter);
00103 }
00104 
00105 bool Element::link(const char *srcPadName, const ElementPtr & dest, const CapsPtr & filter)
00106 {
00107     return link(srcPadName, dest, NULL, filter);
00108 }
00109 
00110 bool Element::link(const ElementPtr & dest, const char *sinkPadName, const CapsPtr & filter)
00111 {
00112     return link(NULL, dest, sinkPadName, filter);
00113 }
00114 
00115 bool Element::link(const ElementPtr & dest, const CapsPtr & filter)
00116 {
00117     return link(NULL, dest, NULL, filter);
00118 }
00119 
00120 void Element::unlink(const char *srcPadName, const ElementPtr & dest, const char *sinkPadName)
00121 {
00122     gst_element_unlink_pads(object<GstElement>(), srcPadName, dest, sinkPadName);
00123 }
00124 
00125 void Element::unlink(const ElementPtr & dest, const char *sinkPadName)
00126 {
00127     unlink(NULL, dest, sinkPadName);
00128 }
00129 
00130 bool Element::query(const QueryPtr & query)
00131 {
00132     return gst_element_query(object<GstElement>(), query);
00133 }
00134 
00135 ClockPtr Element::clock() const
00136 {
00137     if (gst_element_provides_clock(object<GstElement>())) {
00138         return ClockPtr::wrap(gst_element_get_clock(object<GstElement>()), false);
00139     } else {
00140         return ClockPtr();
00141     }
00142 }
00143 
00144 bool Element::setClock(const ClockPtr & clock)
00145 {
00146     return gst_element_set_clock(object<GstElement>(), clock);
00147 }
00148 
00149 bool Element::sendEvent(const EventPtr &event)
00150 {
00151     //Sending an event passes ownership of it, so we need to strong ref() it as we still
00152     //hold a pointer to the object, and will release it when the wrapper is cleared.
00153     gst_event_ref(event);
00154     return gst_element_send_event(object<GstElement>(), event);
00155 }
00156 
00157 bool Element::seek(Format format, SeekFlags flags, quint64 position)
00158 {
00159     return gst_element_seek_simple(object<GstElement>(), static_cast<GstFormat>(format),
00160                                    static_cast<GstSeekFlags>(static_cast<int>(flags)), position);
00161 }
00162 
00163 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator