QtGStreamer 1.2.0
Loading...
Searching...
No Matches
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/gst.h>
23
24namespace QGst {
25
26State Element::currentState() const
27{
28 State r;
29 getState(&r, NULL, 0);
30 return r;
31}
32
33State Element::pendingState() const
34{
35 State r;
36 getState(NULL, &r, 0);
37 return r;
38}
39
40StateChangeReturn Element::getState(State *state, State *pending, ClockTime timeout) const
41{
42 GstState curState, pendingState;
43 GstStateChangeReturn result = gst_element_get_state(object<GstElement>(),
44 &curState, &pendingState, timeout);
45 if (state) {
46 *state = static_cast<State>(curState);
47 }
48 if (pending) {
49 *pending = static_cast<State>(pendingState);
50 }
51 return static_cast<StateChangeReturn>(result);
52}
53
54StateChangeReturn Element::setState(State state)
55{
56 return static_cast<StateChangeReturn>(gst_element_set_state(object<GstElement>(),
57 static_cast<GstState>(state)));
58}
59
60bool Element::syncStateWithParent()
61{
62 return gst_element_sync_state_with_parent(object<GstElement>());
63}
64
65bool Element::stateIsLocked() const
66{
67 return gst_element_is_locked_state(object<GstElement>());
68}
69
70bool Element::setStateLocked(bool locked)
71{
72 return gst_element_set_locked_state(object<GstElement>(), locked);
73}
74
75bool Element::addPad(const PadPtr & pad)
76{
77 return gst_element_add_pad(object<GstElement>(), pad);
78}
79
80bool Element::removePad(const PadPtr & pad)
81{
82 return gst_element_remove_pad(object<GstElement>(), pad);
83}
84
85PadPtr Element::getStaticPad(const char *name)
86{
87 GstPad *pad = gst_element_get_static_pad(object<GstElement>(), name);
88 return PadPtr::wrap(pad, false);
89}
90
91PadPtr Element::getRequestPad(const char *name)
92{
93 GstPad *pad = gst_element_get_request_pad(object<GstElement>(), name);
94 return PadPtr::wrap(pad, false);
95}
96
97void Element::releaseRequestPad(const PadPtr & pad)
98{
99 gst_element_release_request_pad(object<GstElement>(), pad);
100}
101
102bool Element::link(const char *srcPadName, const ElementPtr & dest,
103 const char *sinkPadName, const CapsPtr & filter)
104{
105 return gst_element_link_pads_filtered(object<GstElement>(), srcPadName,
106 dest, sinkPadName, filter);
107}
108
109bool Element::link(const char *srcPadName, const ElementPtr & dest, const CapsPtr & filter)
110{
111 return link(srcPadName, dest, NULL, filter);
112}
113
114bool Element::link(const ElementPtr & dest, const char *sinkPadName, const CapsPtr & filter)
115{
116 return link(NULL, dest, sinkPadName, filter);
117}
118
119bool Element::link(const ElementPtr & dest, const CapsPtr & filter)
120{
121 return link(NULL, dest, NULL, filter);
122}
123
124void Element::unlink(const char *srcPadName, const ElementPtr & dest, const char *sinkPadName)
125{
126 //FIXME-0.11 This is not entirely correct. Unfortunately I didn't notice
127 //that gst_element_unlink_pads requires both pad names when I wrote this
128 //function, and it cannot be changed now. For the moment, if the sink
129 //pad name is not given, we will assume it is "sink".
130 if (!sinkPadName) {
131 sinkPadName = "sink";
132 }
133
134 gst_element_unlink_pads(object<GstElement>(), srcPadName, dest, sinkPadName);
135}
136
137void Element::unlink(const ElementPtr & dest, const char *sinkPadName)
138{
139 if (sinkPadName) {
140 //FIXME-0.11 This is not entirely correct. Unfortunately I didn't notice
141 //that gst_element_unlink_pads requires both pad names when I wrote this
142 //function, and it cannot be changed now. For the moment, if the source
143 //pad name is not given, we will assume it is "src".
144 unlink("src", dest, sinkPadName);
145 } else {
146 gst_element_unlink(object<GstElement>(), dest);
147 }
148}
149
150bool Element::query(const QueryPtr & query)
151{
152 return gst_element_query(object<GstElement>(), query);
153}
154
155ClockPtr Element::clock() const
156{
157 return ClockPtr::wrap(gst_element_get_clock(object<GstElement>()), false);
158}
159
160bool Element::setClock(const ClockPtr & clock)
161{
162 return gst_element_set_clock(object<GstElement>(), clock);
163}
164
165bool Element::sendEvent(const EventPtr &event)
166{
167 //Sending an event passes ownership of it, so we need to strong ref() it as we still
168 //hold a pointer to the object, and will release it when the wrapper is cleared.
169 gst_event_ref(event);
170 return gst_element_send_event(object<GstElement>(), event);
171}
172
173bool Element::seek(Format format, SeekFlags flags, quint64 position)
174{
175 return gst_element_seek_simple(object<GstElement>(), static_cast<GstFormat>(format),
176 static_cast<GstSeekFlags>(static_cast<int>(flags)), position);
177}
178
179}
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
Definition refpointer.h:328
void unlink(const char *srcPadName, const ElementPtr &dest, const char *sinkPadName)
Definition element.cpp:124
Wrappers for GStreamer classes.