QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
event.cpp
1 /*
2  Copyright (C) 2010 Collabora Multimedia.
3  @author Mauricio Piacentini <mauricio.piacentini@collabora.co.uk>
4 
5  This library is free software; you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation; either version 2.1 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "event.h"
19 #include "message.h"
20 #include "object.h"
21 #include <QtCore/QDebug>
22 #include <gst/gst.h>
23 
24 namespace QGst {
25 
26 ObjectPtr Event::source() const
27 {
28  return ObjectPtr::wrap(GST_EVENT_SRC(object<GstEvent>()));
29 }
30 
31 quint64 Event::timestamp() const
32 {
33  return object<GstEvent>()->timestamp;
34 }
35 
36 EventType Event::type() const
37 {
38  return static_cast<EventType>(GST_EVENT_TYPE(object<GstEvent>()));
39 }
40 
41 QString Event::typeName() const
42 {
43  return QString::fromUtf8(GST_EVENT_TYPE_NAME(object<GstQuery>()));
44 }
45 
46 StructurePtr Event::internalStructure()
47 {
48  return SharedStructure::fromMiniObject(object<GstEvent>()->structure, MiniObjectPtr(this));
49 }
50 
51 quint32 Event::sequenceNumber() const
52 {
53  return gst_event_get_seqnum(object<GstEvent>());
54 }
55 
56 void Event::setSequenceNumber(quint32 num)
57 {
58  gst_event_set_seqnum(object<GstEvent>(), num);
59 }
60 
61 EventPtr Event::copy() const
62 {
63  return EventPtr::wrap(gst_event_copy(object<GstEvent>()), false);
64 }
65 
66 //********************************************************
67 
68 FlushStartEventPtr FlushStartEvent::create()
69 {
70  return FlushStartEventPtr::wrap(gst_event_new_flush_start(), false);
71 }
72 
73 //********************************************************
74 
75 FlushStopEventPtr FlushStopEvent::create()
76 {
77  return FlushStopEventPtr::wrap(gst_event_new_flush_stop(), false);
78 }
79 
80 //********************************************************
81 
82 EosEventPtr EosEvent::create()
83 {
84  return EosEventPtr::wrap(gst_event_new_eos(), false);
85 }
86 
87 //********************************************************
88 
89 NewSegmentEventPtr NewSegmentEvent::create(bool update, double rate, double appliedRate,
90  Format format, qint64 start, qint64 stop, qint64 position)
91 {
92  GstEvent * e = gst_event_new_new_segment_full(update, rate, appliedRate,
93  static_cast<GstFormat>(format), start, stop,
94  position);
95 
96  return NewSegmentEventPtr::wrap(e, false);
97 }
98 
99 bool NewSegmentEvent::isUpdate() const
100 {
101  gboolean u;
102  gst_event_parse_new_segment_full(object<GstEvent>(), &u, NULL, NULL, NULL, NULL, NULL, NULL);
103  return u;
104 }
105 
106 double NewSegmentEvent::rate() const
107 {
108  double r;
109  gst_event_parse_new_segment_full(object<GstEvent>(), NULL, &r, NULL, NULL, NULL, NULL, NULL);
110  return r;
111 }
112 
113 double NewSegmentEvent::appliedRate() const
114 {
115  double r;
116  gst_event_parse_new_segment_full(object<GstEvent>(), NULL, NULL, &r, NULL, NULL, NULL, NULL);
117  return r;
118 }
119 
120 Format NewSegmentEvent::format() const
121 {
122  GstFormat f;
123  gst_event_parse_new_segment_full(object<GstEvent>(), NULL, NULL, NULL, &f, NULL, NULL, NULL);
124  return static_cast<Format>(f);
125 }
126 
127 qint64 NewSegmentEvent::start() const
128 {
129  gint64 s;
130  gst_event_parse_new_segment_full(object<GstEvent>(), NULL, NULL, NULL, NULL, &s, NULL, NULL);
131  return s;
132 }
133 
134 qint64 NewSegmentEvent::stop() const
135 {
136  gint64 s;
137  gst_event_parse_new_segment_full(object<GstEvent>(), NULL, NULL, NULL, NULL, NULL, &s, NULL);
138  return s;
139 }
140 
141 qint64 NewSegmentEvent::position() const
142 {
143  gint64 p;
144  gst_event_parse_new_segment_full(object<GstEvent>(), NULL, NULL, NULL, NULL, NULL, NULL, &p);
145  return p;
146 }
147 
148 //********************************************************
149 
150 TagEventPtr TagEvent::create(const TagList & taglist)
151 {
152  GstEvent * e = gst_event_new_tag(gst_tag_list_copy(taglist));
153  return TagEventPtr::wrap(e, false);
154 }
155 
156 TagList TagEvent::taglist() const
157 {
158  GstTagList * t;
159  gst_event_parse_tag(object<GstEvent>(), &t);
160  TagList tl(t);
161  return tl;
162 }
163 
164 //********************************************************
165 
166 BufferSizeEventPtr BufferSizeEvent::create(Format format, qint64 minSize, qint64 maxSize,
167  bool isAsync)
168 {
169  GstEvent * e = gst_event_new_buffer_size(static_cast<GstFormat>(format), minSize, maxSize,
170  isAsync);
171 
172  return BufferSizeEventPtr::wrap(e, false);
173 }
174 
175 Format BufferSizeEvent::format() const
176 {
177  GstFormat f;
178  gst_event_parse_buffer_size(object<GstEvent>(), &f, NULL, NULL, NULL);
179  return static_cast<Format>(f);
180 }
181 
182 qint64 BufferSizeEvent::minSize() const
183 {
184  gint64 s;
185  gst_event_parse_buffer_size(object<GstEvent>(), NULL, &s, NULL, NULL);
186  return s;
187 }
188 
189 qint64 BufferSizeEvent::maxSize() const
190 {
191  gint64 s;
192  gst_event_parse_buffer_size(object<GstEvent>(), NULL, NULL, &s, NULL);
193  return s;
194 }
195 
196 bool BufferSizeEvent::isAsync() const
197 {
198  gboolean u;
199  gst_event_parse_buffer_size(object<GstEvent>(), NULL, NULL, NULL, &u);
200  return u;
201 }
202 
203 //********************************************************
204 
205 SinkMessageEventPtr SinkMessageEvent::create(const MessagePtr & msg)
206 {
207  GstEvent * e = gst_event_new_sink_message(msg);
208  return SinkMessageEventPtr::wrap(e, false);
209 }
210 
211 MessagePtr SinkMessageEvent::message() const
212 {
213  GstMessage * msg;
214  gst_event_parse_sink_message(object<GstEvent>(), &msg);
215  //Wrap message (refcount was already increased), will unref() when MessagePtr is destroyed
216  return MessagePtr::wrap(msg, false);
217 }
218 
219 //********************************************************
220 
221 QosEventPtr QosEvent::create(double proportion, ClockTimeDiff diff, ClockTime timeStamp)
222 {
223  GstEvent * e = gst_event_new_qos(proportion, diff, static_cast<GstClockTime>(timeStamp));
224  return QosEventPtr::wrap(e, false);
225 }
226 
227 double QosEvent::proportion() const
228 {
229  double d;
230  gst_event_parse_qos(object<GstEvent>(), &d, NULL, NULL);
231  return d;
232 }
233 
234 ClockTimeDiff QosEvent::diff() const
235 {
236  GstClockTimeDiff c;
237  gst_event_parse_qos(object<GstEvent>(), NULL, &c, NULL);
238  return c;
239 }
240 
241 ClockTime QosEvent::timestamp() const
242 {
243  GstClockTime c;
244  gst_event_parse_qos(object<GstEvent>(), NULL, NULL, &c);
245  return c;
246 }
247 
248 //********************************************************
249 
250 SeekEventPtr SeekEvent::create(double rate, Format format, SeekFlags flags, SeekType startType,
251  qint64 start, SeekType stopType, qint64 stop)
252 {
253  GstEvent * e = gst_event_new_seek(rate, static_cast<GstFormat>(format),
254  static_cast<GstSeekFlags>(static_cast<int>(flags)),
255  static_cast<GstSeekType>(startType), start,
256  static_cast<GstSeekType>(stopType), stop );
257  return SeekEventPtr::wrap(e, false);
258 }
259 
260 double SeekEvent::rate() const
261 {
262  double d;
263  gst_event_parse_seek(object<GstEvent>(), &d, NULL, NULL, NULL, NULL, NULL, NULL);
264  return d;
265 }
266 
267 Format SeekEvent::format() const
268 {
269  GstFormat f;
270  gst_event_parse_seek(object<GstEvent>(), NULL, &f, NULL, NULL, NULL, NULL, NULL);
271  return static_cast<Format>(f);
272 }
273 
274 SeekFlags SeekEvent::flags() const
275 {
276  GstSeekFlags f;
277  gst_event_parse_seek(object<GstEvent>(), NULL, NULL, &f, NULL, NULL, NULL, NULL);
278  return static_cast<SeekFlags>(f);
279 }
280 
281 SeekType SeekEvent::startType() const
282 {
283  GstSeekType t;
284  gst_event_parse_seek(object<GstEvent>(), NULL, NULL, NULL, &t, NULL, NULL, NULL);
285  return static_cast<SeekType>(t);
286 }
287 
288 qint64 SeekEvent::start() const
289 {
290  gint64 s;
291  gst_event_parse_seek(object<GstEvent>(), NULL, NULL, NULL, NULL, &s, NULL, NULL);
292  return s;
293 }
294 
295 SeekType SeekEvent::stopType() const
296 {
297  GstSeekType t;
298  gst_event_parse_seek(object<GstEvent>(), NULL, NULL, NULL, NULL, NULL, &t, NULL);
299  return static_cast<SeekType>(t);
300 }
301 
302 qint64 SeekEvent::stop() const
303 {
304  gint64 s;
305  gst_event_parse_seek(object<GstEvent>(), NULL, NULL, NULL, NULL, NULL, NULL, &s);
306  return s;
307 }
308 
309 //********************************************************
310 
311 NavigationEventPtr NavigationEvent::create(const Structure & structure)
312 {
313  GstStructure * s = structure.isValid() ? gst_structure_copy(structure) : NULL;
314  GstEvent * e = gst_event_new_navigation(s);
315  return NavigationEventPtr::wrap(e, false);
316 }
317 
318 //********************************************************
319 
320 LatencyEventPtr LatencyEvent::create(ClockTime latency)
321 {
322  GstEvent * e = gst_event_new_latency(latency);
323  return LatencyEventPtr::wrap(e, false);
324 }
325 
326 ClockTime LatencyEvent::latency() const
327 {
328  GstClockTime c;
329  gst_event_parse_latency(object<GstEvent>(), &c);
330  return c;
331 }
332 
333 //********************************************************
334 
335 StepEventPtr StepEvent::create(Format format, quint64 amount, double rate, bool flush,
336  bool intermediate)
337 {
338  GstEvent * e = gst_event_new_step(static_cast<GstFormat>(format), amount, rate, flush,
339  intermediate);
340  return StepEventPtr::wrap(e, false);
341 }
342 
343 Format StepEvent::format() const
344 {
345  GstFormat f;
346  gst_event_parse_step(object<GstEvent>(), &f, NULL, NULL, NULL, NULL);
347  return static_cast<Format>(f);
348 }
349 
350 quint64 StepEvent::amount() const
351 {
352  guint64 a;
353  gst_event_parse_step(object<GstEvent>(), NULL, &a, NULL, NULL, NULL);
354  return a;
355 }
356 
357 double StepEvent::rate() const
358 {
359  double d;
360  gst_event_parse_step(object<GstEvent>(), NULL, NULL, &d, NULL, NULL);
361  return d;
362 
363 }
364 
365 bool StepEvent::flush() const
366 {
367  gboolean f;
368  gst_event_parse_step(object<GstEvent>(), NULL, NULL, NULL, &f, NULL);
369  return f;
370 }
371 
372 bool StepEvent::intermediate() const
373 {
374  gboolean i;
375  gst_event_parse_step(object<GstEvent>(), NULL, NULL, NULL, NULL, &i);
376  return i;
377 }
378 
379 } //namespace QGst