QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
element.cpp
1 /*
2  Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published
6  by the Free Software Foundation; either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "element.h"
18 #include "pad.h"
19 #include "query.h"
20 #include "clock.h"
21 #include "event.h"
22 #include <gst/gstelement.h>
23 #include <gst/gstutils.h>
24 
25 namespace QGst {
26 
27 State Element::currentState() const
28 {
29  State r;
30  getState(&r, NULL, 0);
31  return r;
32 }
33 
34 State Element::pendingState() const
35 {
36  State r;
37  getState(NULL, &r, 0);
38  return r;
39 }
40 
41 StateChangeReturn Element::getState(State *state, State *pending, ClockTime timeout) const
42 {
43  GstState curState, pendingState;
44  GstStateChangeReturn result = gst_element_get_state(object<GstElement>(),
45  &curState, &pendingState, timeout);
46  if (state) {
47  *state = static_cast<State>(curState);
48  }
49  if (pending) {
50  *pending = static_cast<State>(pendingState);
51  }
52  return static_cast<StateChangeReturn>(result);
53 }
54 
55 StateChangeReturn Element::setState(State state)
56 {
57  return static_cast<StateChangeReturn>(gst_element_set_state(object<GstElement>(),
58  static_cast<GstState>(state)));
59 }
60 
61 bool Element::syncStateWithParent()
62 {
63  return gst_element_sync_state_with_parent(object<GstElement>());
64 }
65 
66 bool Element::stateIsLocked() const
67 {
68  return gst_element_is_locked_state(object<GstElement>());
69 }
70 
71 bool Element::setStateLocked(bool locked)
72 {
73  return gst_element_set_locked_state(object<GstElement>(), locked);
74 }
75 
76 bool Element::addPad(const PadPtr & pad)
77 {
78  return gst_element_add_pad(object<GstElement>(), pad);
79 }
80 
81 bool Element::removePad(const PadPtr & pad)
82 {
83  return gst_element_remove_pad(object<GstElement>(), pad);
84 }
85 
86 PadPtr Element::getStaticPad(const char *name)
87 {
88  GstPad *pad = gst_element_get_static_pad(object<GstElement>(), name);
89  return PadPtr::wrap(pad, false);
90 }
91 
92 PadPtr Element::getRequestPad(const char *name)
93 {
94  GstPad *pad = gst_element_get_request_pad(object<GstElement>(), name);
95  return PadPtr::wrap(pad, false);
96 }
97 
98 void Element::releaseRequestPad(const PadPtr & pad)
99 {
100  gst_element_release_request_pad(object<GstElement>(), pad);
101 }
102 
103 bool Element::link(const char *srcPadName, const ElementPtr & dest,
104  const char *sinkPadName, const CapsPtr & filter)
105 {
106  return gst_element_link_pads_filtered(object<GstElement>(), srcPadName,
107  dest, sinkPadName, filter);
108 }
109 
110 bool Element::link(const char *srcPadName, const ElementPtr & dest, const CapsPtr & filter)
111 {
112  return link(srcPadName, dest, NULL, filter);
113 }
114 
115 bool Element::link(const ElementPtr & dest, const char *sinkPadName, const CapsPtr & filter)
116 {
117  return link(NULL, dest, sinkPadName, filter);
118 }
119 
120 bool Element::link(const ElementPtr & dest, const CapsPtr & filter)
121 {
122  return link(NULL, dest, NULL, filter);
123 }
124 
125 void Element::unlink(const char *srcPadName, const ElementPtr & dest, const char *sinkPadName)
126 {
127  //FIXME-0.11 This is not entirely correct. Unfortunately I didn't notice
128  //that gst_element_unlink_pads requires both pad names when I wrote this
129  //function, and it cannot be changed now. For the moment, if the sink
130  //pad name is not given, we will assume it is "sink".
131  if (!sinkPadName) {
132  sinkPadName = "sink";
133  }
134 
135  gst_element_unlink_pads(object<GstElement>(), srcPadName, dest, sinkPadName);
136 }
137 
138 void Element::unlink(const ElementPtr & dest, const char *sinkPadName)
139 {
140  if (sinkPadName) {
141  //FIXME-0.11 This is not entirely correct. Unfortunately I didn't notice
142  //that gst_element_unlink_pads requires both pad names when I wrote this
143  //function, and it cannot be changed now. For the moment, if the source
144  //pad name is not given, we will assume it is "src".
145  unlink("src", dest, sinkPadName);
146  } else {
147  gst_element_unlink(object<GstElement>(), dest);
148  }
149 }
150 
151 bool Element::query(const QueryPtr & query)
152 {
153  return gst_element_query(object<GstElement>(), query);
154 }
155 
156 ClockPtr Element::clock() const
157 {
158  if (gst_element_provides_clock(object<GstElement>())) {
159  return ClockPtr::wrap(gst_element_get_clock(object<GstElement>()), false);
160  } else {
161  return ClockPtr();
162  }
163 }
164 
165 bool Element::setClock(const ClockPtr & clock)
166 {
167  return gst_element_set_clock(object<GstElement>(), clock);
168 }
169 
170 bool Element::sendEvent(const EventPtr &event)
171 {
172  //Sending an event passes ownership of it, so we need to strong ref() it as we still
173  //hold a pointer to the object, and will release it when the wrapper is cleared.
174  gst_event_ref(event);
175  return gst_element_send_event(object<GstElement>(), event);
176 }
177 
178 bool Element::seek(Format format, SeekFlags flags, quint64 position)
179 {
180  return gst_element_seek_simple(object<GstElement>(), static_cast<GstFormat>(format),
181  static_cast<GstSeekFlags>(static_cast<int>(flags)), position);
182 }
183 
184 }