QtGStreamer  0.10.2
 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 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 #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 bool Element::removePad(const PadPtr & pad)
00082 {
00083     return gst_element_remove_pad(object<GstElement>(), pad);
00084 }
00085 
00086 PadPtr Element::getStaticPad(const char *name)
00087 {
00088     GstPad *pad = gst_element_get_static_pad(object<GstElement>(), name);
00089     return PadPtr::wrap(pad, false);
00090 }
00091 
00092 PadPtr Element::getRequestPad(const char *name)
00093 {
00094     GstPad *pad = gst_element_get_request_pad(object<GstElement>(), name);
00095     return PadPtr::wrap(pad, false);
00096 }
00097 
00098 void Element::releaseRequestPad(const PadPtr & pad)
00099 {
00100     gst_element_release_request_pad(object<GstElement>(), pad);
00101 }
00102 
00103 bool Element::link(const char *srcPadName, const ElementPtr & dest,
00104                    const char *sinkPadName, const CapsPtr & filter)
00105 {
00106     return gst_element_link_pads_filtered(object<GstElement>(), srcPadName,
00107                                           dest, sinkPadName, filter);
00108 }
00109 
00110 bool Element::link(const char *srcPadName, const ElementPtr & dest, const CapsPtr & filter)
00111 {
00112     return link(srcPadName, dest, NULL, filter);
00113 }
00114 
00115 bool Element::link(const ElementPtr & dest, const char *sinkPadName, const CapsPtr & filter)
00116 {
00117     return link(NULL, dest, sinkPadName, filter);
00118 }
00119 
00120 bool Element::link(const ElementPtr & dest, const CapsPtr & filter)
00121 {
00122     return link(NULL, dest, NULL, filter);
00123 }
00124 
00125 void Element::unlink(const char *srcPadName, const ElementPtr & dest, const char *sinkPadName)
00126 {
00127     //FIXME-0.11 This is not entirely correct. Unfortunately I didn't notice
00128     //that gst_element_unlink_pads requires both pad names when I wrote this
00129     //function, and it cannot be changed now. For the moment, if the sink
00130     //pad name is not given, we will assume it is "sink".
00131     if (!sinkPadName) {
00132         sinkPadName = "sink";
00133     }
00134 
00135     gst_element_unlink_pads(object<GstElement>(), srcPadName, dest, sinkPadName);
00136 }
00137 
00138 void Element::unlink(const ElementPtr & dest, const char *sinkPadName)
00139 {
00140     if (sinkPadName) {
00141         //FIXME-0.11 This is not entirely correct. Unfortunately I didn't notice
00142         //that gst_element_unlink_pads requires both pad names when I wrote this
00143         //function, and it cannot be changed now. For the moment, if the source
00144         //pad name is not given, we will assume it is "src".
00145         unlink("src", dest, sinkPadName);
00146     } else {
00147         gst_element_unlink(object<GstElement>(), dest);
00148     }
00149 }
00150 
00151 bool Element::query(const QueryPtr & query)
00152 {
00153     return gst_element_query(object<GstElement>(), query);
00154 }
00155 
00156 ClockPtr Element::clock() const
00157 {
00158     if (gst_element_provides_clock(object<GstElement>())) {
00159         return ClockPtr::wrap(gst_element_get_clock(object<GstElement>()), false);
00160     } else {
00161         return ClockPtr();
00162     }
00163 }
00164 
00165 bool Element::setClock(const ClockPtr & clock)
00166 {
00167     return gst_element_set_clock(object<GstElement>(), clock);
00168 }
00169 
00170 bool Element::sendEvent(const EventPtr &event)
00171 {
00172     //Sending an event passes ownership of it, so we need to strong ref() it as we still
00173     //hold a pointer to the object, and will release it when the wrapper is cleared.
00174     gst_event_ref(event);
00175     return gst_element_send_event(object<GstElement>(), event);
00176 }
00177 
00178 bool Element::seek(Format format, SeekFlags flags, quint64 position)
00179 {
00180     return gst_element_seek_simple(object<GstElement>(), static_cast<GstFormat>(format),
00181                                    static_cast<GstSeekFlags>(static_cast<int>(flags)), position);
00182 }
00183 
00184 }