QtGStreamer 1.2.0
Loading...
Searching...
No Matches
message.cpp
1/*
2 Copyright (C) 2009-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 "message.h"
18#include "element.h"
19#include "../QGlib/error.h"
20#include "../QGlib/string_p.h"
21#include <QtCore/QDebug>
22#include <gst/gst.h>
23
24namespace QGst {
25
26ObjectPtr Message::source() const
27{
28 return ObjectPtr::wrap(GST_MESSAGE_SRC(object<GstMessage>()));
29}
30
31quint64 Message::timestamp() const
32{
33 return object<GstMessage>()->timestamp;
34}
35
36QString Message::typeName() const
37{
38 return QString::fromUtf8(GST_MESSAGE_TYPE_NAME(object<GstMessage>()));
39}
40
41MessageType Message::type() const
42{
43 return static_cast<MessageType>(GST_MESSAGE_TYPE(object<GstMessage>()));
44}
45
46StructureConstPtr Message::internalStructure()
47{
48 const GstStructure *structure = gst_message_get_structure(object<GstMessage>());
49 return SharedStructure::fromMiniObject(const_cast<GstStructure *>(structure), MiniObjectPtr(this));
50}
51
52quint32 Message::sequenceNumber() const
53{
54 return gst_message_get_seqnum(object<GstMessage>());
55}
56
57void Message::setSequenceNumber(quint32 num)
58{
59 gst_message_set_seqnum(object<GstMessage>(), num);
60}
61
62//********************************************************
63
64EosMessagePtr EosMessage::create(const ObjectPtr & source)
65{
66 return EosMessagePtr::wrap(gst_message_new_eos(source), false);
67}
68
69//********************************************************
70
71ErrorMessagePtr ErrorMessage::create(const ObjectPtr & source,
72 const QGlib::Error & error, const char *debug)
73{
74 //stupid GstMessage api takes non-const GError while it should
75 GError *e = const_cast<GError*>(static_cast<const GError*>(error));
76 return ErrorMessagePtr::wrap(gst_message_new_error(source, e, debug), false);
77}
78
79QGlib::Error ErrorMessage::error() const
80{
81 GError *e;
82 gst_message_parse_error(object<GstMessage>(), &e, NULL);
83 return QGlib::Error(e);
84}
85
86QString ErrorMessage::debugMessage() const
87{
88 gchar *debug;
89 GError *e;
90 //Passing a NULL pointer for the GError is not supported
91 gst_message_parse_error(object<GstMessage>(), &e, &debug);
92 if (e) {
93 g_error_free (e);
94 }
95 return QGlib::Private::stringFromGCharPtr(debug);
96}
97
98//********************************************************
99
100WarningMessagePtr WarningMessage::create(const ObjectPtr & source,
101 const QGlib::Error & error, const char *debug)
102{
103 //stupid GstMessage api takes non-const GError while it should
104 GError *e = const_cast<GError*>(static_cast<const GError*>(error));
105 return WarningMessagePtr::wrap(gst_message_new_warning(source, e, debug), false);
106}
107
108QGlib::Error WarningMessage::error() const
109{
110 GError *e;
111 gst_message_parse_warning(object<GstMessage>(), &e, NULL);
112 return QGlib::Error(e);
113}
114
115QString WarningMessage::debugMessage() const
116{
117 gchar *debug;
118 GError *e;
119 //Passing a NULL pointer for the GError is not supported
120 gst_message_parse_warning(object<GstMessage>(), &e, &debug);
121 if (e) {
122 g_error_free (e);
123 }
124 return QGlib::Private::stringFromGCharPtr(debug);
125}
126
127//********************************************************
128
129InfoMessagePtr InfoMessage::create(const ObjectPtr & source,
130 const QGlib::Error & error, const char *debug)
131{
132 //stupid GstMessage api takes non-const GError while it should
133 GError *e = const_cast<GError*>(static_cast<const GError*>(error));
134 return InfoMessagePtr::wrap(gst_message_new_info(source, e, debug), false);
135}
136
137QGlib::Error InfoMessage::error() const
138{
139 GError *e;
140 gst_message_parse_info(object<GstMessage>(), &e, NULL);
141 return QGlib::Error(e);
142}
143
144QString InfoMessage::debugMessage() const
145{
146 gchar *debug;
147 GError *e;
148 //Passing a NULL pointer for the GError is not supported
149 gst_message_parse_info(object<GstMessage>(), &e, &debug);
150 if (e) {
151 g_error_free (e);
152 }
153 return QGlib::Private::stringFromGCharPtr(debug);
154}
155
156//********************************************************
157
158TagMessagePtr TagMessage::create(const ObjectPtr & source, const TagList & taglist)
159{
160 GstMessage *m = gst_message_new_tag(source, gst_tag_list_copy(&taglist));
161 return TagMessagePtr::wrap(m, false);
162}
163
164TagList TagMessage::taglist() const
165{
166 GstTagList * t;
167 gst_message_parse_tag(object<GstMessage>(), &t);
168 TagList tl(t);
169 gst_tag_list_free(t);
170 return tl;
171}
172
173//********************************************************
174
175BufferingMessagePtr BufferingMessage::create(const ObjectPtr & source, int percent)
176{
177 GstMessage *m = gst_message_new_buffering(source, percent);
178 return BufferingMessagePtr::wrap(m, false);
179}
180
181int BufferingMessage::percent() const
182{
183 gint p;
184 gst_message_parse_buffering(object<GstMessage>(), &p);
185 return p;
186}
187
188BufferingMode BufferingMessage::mode() const
189{
190 GstBufferingMode m;
191 gst_message_parse_buffering_stats(object<GstMessage>(), &m, NULL, NULL, NULL);
192 return static_cast<BufferingMode>(m);
193}
194
195int BufferingMessage::averageInputRate() const
196{
197 gint a;
198 gst_message_parse_buffering_stats(object<GstMessage>(), NULL, &a, NULL, NULL);
199 return a;
200}
201
202int BufferingMessage::averageOutputRate() const
203{
204 gint a;
205 gst_message_parse_buffering_stats(object<GstMessage>(), NULL, NULL, &a, NULL);
206 return a;
207}
208
209qint64 BufferingMessage::bufferingTimeLeft() const
210{
211 gint64 a;
212 gst_message_parse_buffering_stats(object<GstMessage>(), NULL, NULL, NULL, &a);
213 return a;
214}
215
216void BufferingMessage::setStats(BufferingMode mode, int avgIn, int avgOut, qint64 bufferingLeft)
217{
218 gst_message_set_buffering_stats(object<GstMessage>(), static_cast<GstBufferingMode>(mode),
219 avgIn, avgOut, bufferingLeft);
220}
221
222//********************************************************
223
224StateChangedMessagePtr StateChangedMessage::create(const ObjectPtr & source,
225 State oldState, State newState, State pending)
226{
227 GstMessage *m = gst_message_new_state_changed(source, static_cast<GstState>(oldState),
228 static_cast<GstState>(newState),
229 static_cast<GstState>(pending));
230 return StateChangedMessagePtr::wrap(m, false);
231}
232
233State StateChangedMessage::oldState() const
234{
235 GstState s;
236 gst_message_parse_state_changed(object<GstMessage>(), &s, NULL, NULL);
237 return static_cast<State>(s);
238}
239
240State StateChangedMessage::newState() const
241{
242 GstState s;
243 gst_message_parse_state_changed(object<GstMessage>(), NULL, &s, NULL);
244 return static_cast<State>(s);
245}
246
247State StateChangedMessage::pendingState() const
248{
249 GstState s;
250 gst_message_parse_state_changed(object<GstMessage>(), NULL, NULL, &s);
251 return static_cast<State>(s);
252}
253
254//********************************************************
255
256StepDoneMessagePtr StepDoneMessage::create(const ObjectPtr & source, Format format,
257 quint64 amount, double rate, bool flush,
258 bool intermediate, quint64 duration, bool eos)
259{
260 GstMessage *m = gst_message_new_step_done(source, static_cast<GstFormat>(format), amount,
261 rate, flush, intermediate, duration, eos);
262 return StepDoneMessagePtr::wrap(m, false);
263}
264
265Format StepDoneMessage::format() const
266{
267 GstFormat f;
268 gst_message_parse_step_done(object<GstMessage>(), &f, NULL, NULL, NULL, NULL, NULL, NULL);
269 return static_cast<Format>(f);
270}
271
272quint64 StepDoneMessage::amount() const
273{
274 guint64 a;
275 gst_message_parse_step_done(object<GstMessage>(), NULL, &a, NULL, NULL, NULL, NULL, NULL);
276 return a;
277}
278
279double StepDoneMessage::rate() const
280{
281 gdouble d;
282 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, &d, NULL, NULL, NULL, NULL);
283 return d;
284}
285
286bool StepDoneMessage::isFlushingStep() const
287{
288 gboolean b;
289 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, &b, NULL, NULL, NULL);
290 return b;
291}
292
293bool StepDoneMessage::isIntermediateStep() const
294{
295 gboolean b;
296 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, NULL, &b, NULL, NULL);
297 return b;
298}
299
300quint64 StepDoneMessage::duration() const
301{
302 guint64 d;
303 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, NULL, NULL, &d, NULL);
304 return d;
305}
306
307bool StepDoneMessage::causedEos() const
308{
309 gboolean e;
310 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, NULL, NULL, NULL, &e);
311 return e;
312}
313
314//********************************************************
315
316StreamStatusMessagePtr StreamStatusMessage::create(const ObjectPtr & source,
317 StreamStatusType type, const ElementPtr & owner)
318{
319 GstMessage *m = gst_message_new_stream_status(source, static_cast<GstStreamStatusType>(type), owner);
320 return StreamStatusMessagePtr::wrap(m, false);
321}
322
323StreamStatusType StreamStatusMessage::statusType() const
324{
325 GstStreamStatusType t;
326 gst_message_parse_stream_status(object<GstMessage>(), &t, NULL);
327 return static_cast<StreamStatusType>(t);
328}
329
330ElementPtr StreamStatusMessage::owner() const
331{
332 GstElement *e;
333 gst_message_parse_stream_status(object<GstMessage>(), NULL, &e);
334 return ElementPtr::wrap(e);
335}
336
337QGlib::Value StreamStatusMessage::streamStatusObject() const
338{
339 return QGlib::Value(gst_message_get_stream_status_object(object<GstMessage>()));
340}
341
342void StreamStatusMessage::setStreamStatusObject(const QGlib::Value & obj)
343{
344 gst_message_set_stream_status_object(object<GstMessage>(), obj);
345}
346
347//********************************************************
348
349ApplicationMessagePtr ApplicationMessage::create(const ObjectPtr & source, const Structure & structure)
350{
351 GstStructure *s = structure.isValid() ? gst_structure_copy(structure) : NULL;
352 return ApplicationMessagePtr::wrap(gst_message_new_application(source, s), false);
353}
354
355//********************************************************
356
357ElementMessagePtr ElementMessage::create(const ObjectPtr & source, const Structure & structure)
358{
359 GstStructure *s = structure.isValid() ? gst_structure_copy(structure) : NULL;
360 return ElementMessagePtr::wrap(gst_message_new_element(source, s), false);
361}
362
363//********************************************************
364
365SegmentDoneMessagePtr SegmentDoneMessage::create(const ObjectPtr & source, Format format, qint64 position)
366{
367 GstMessage *m = gst_message_new_segment_done(source, static_cast<GstFormat>(format), position);
368 return SegmentDoneMessagePtr::wrap(m, false);
369}
370
371Format SegmentDoneMessage::format() const
372{
373 GstFormat f;
374 gst_message_parse_segment_done(object<GstMessage>(), &f, NULL);
375 return static_cast<Format>(f);
376}
377
378qint64 SegmentDoneMessage::position() const
379{
380 gint64 p;
381 gst_message_parse_segment_done(object<GstMessage>(), NULL, &p);
382 return p;
383}
384
385//********************************************************
386
387DurationChangedMessagePtr DurationChangedMessage::create(const ObjectPtr & source)
388{
389 GstMessage *m = gst_message_new_duration_changed(source);
390 return DurationChangedMessagePtr::wrap(m, false);
391}
392
393//********************************************************
394
395LatencyMessagePtr LatencyMessage::create(const ObjectPtr & source)
396{
397 return LatencyMessagePtr::wrap(gst_message_new_latency(source), false);
398}
399
400//********************************************************
401
402AsyncDoneMessagePtr AsyncDoneMessage::create(const ObjectPtr & source, ClockTime running_time)
403{
404 return AsyncDoneMessagePtr::wrap(gst_message_new_async_done(source, running_time), false);
405}
406
407ClockTime AsyncDoneMessage::runningTime() const
408{
409 GstClockTime c;
410 gst_message_parse_async_done(object<GstMessage>(), &c);
411 return static_cast<ClockTime>(c);
412}
413
414//********************************************************
415
416RequestStateMessagePtr RequestStateMessage::create(const ObjectPtr & source, State state)
417{
418 GstMessage *m = gst_message_new_request_state(source, static_cast<GstState>(state));
419 return RequestStateMessagePtr::wrap(m, false);
420}
421
422State RequestStateMessage::state() const
423{
424 GstState s;
425 gst_message_parse_request_state(object<GstMessage>(), &s);
426 return static_cast<State>(s);
427}
428
429//********************************************************
430
431StepStartMessagePtr StepStartMessage::create(const ObjectPtr & source, bool active, Format format,
432 quint64 amount, double rate, bool flush, bool intermediate)
433{
434 GstMessage *m = gst_message_new_step_start(source, active, static_cast<GstFormat>(format),
435 amount, rate, flush, intermediate);
436 return StepStartMessagePtr::wrap(m, false);
437}
438
439bool StepStartMessage::isActive() const
440{
441 gboolean a;
442 gst_message_parse_step_start(object<GstMessage>(), &a, NULL, NULL, NULL, NULL, NULL);
443 return a;
444}
445
446Format StepStartMessage::format() const
447{
448 GstFormat f;
449 gst_message_parse_step_start(object<GstMessage>(), NULL, &f, NULL, NULL, NULL, NULL);
450 return static_cast<Format>(f);
451}
452
453quint64 StepStartMessage::amount() const
454{
455 guint64 a;
456 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, &a, NULL, NULL, NULL);
457 return a;
458}
459
460double StepStartMessage::rate() const
461{
462 gdouble d;
463 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, NULL, &d, NULL, NULL);
464 return d;
465}
466
467bool StepStartMessage::isFlushingStep() const
468{
469 gboolean b;
470 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, NULL, NULL, &b, NULL);
471 return b;
472}
473
474bool StepStartMessage::isIntermediateStep() const
475{
476 gboolean b;
477 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, NULL, NULL, NULL, &b);
478 return b;
479}
480
481//********************************************************
482
483QosMessagePtr QosMessage::create(const ObjectPtr & source, bool live, quint64 runningTime,
484 quint64 streamTime, quint64 timestamp, quint64 duration)
485{
486 GstMessage *m = gst_message_new_qos(source, live, runningTime, streamTime, timestamp, duration);
487 return QosMessagePtr::wrap(m, false);
488}
489
490bool QosMessage::live() const
491{
492 gboolean l;
493 gst_message_parse_qos(object<GstMessage>(), &l, NULL, NULL, NULL, NULL);
494 return l;
495}
496
497quint64 QosMessage::runningTime() const
498{
499 guint64 t;
500 gst_message_parse_qos(object<GstMessage>(), NULL, &t, NULL, NULL, NULL);
501 return t;
502}
503
504quint64 QosMessage::streamTime() const
505{
506 guint64 t;
507 gst_message_parse_qos(object<GstMessage>(), NULL, NULL, &t, NULL, NULL);
508 return t;
509}
510
511quint64 QosMessage::timestamp() const
512{
513 guint64 t;
514 gst_message_parse_qos(object<GstMessage>(), NULL, NULL, NULL, &t, NULL);
515 return t;
516}
517
518quint64 QosMessage::duration() const
519{
520 guint64 t;
521 gst_message_parse_qos(object<GstMessage>(), NULL, NULL, NULL, NULL, &t);
522 return t;
523}
524
525qint64 QosMessage::jitter() const
526{
527 gint64 j;
528 gst_message_parse_qos_values(object<GstMessage>(), &j, NULL, NULL);
529 return j;
530}
531
532double QosMessage::proportion() const
533{
534 double d;
535 gst_message_parse_qos_values(object<GstMessage>(), NULL, &d, NULL);
536 return d;
537}
538
539int QosMessage::quality() const
540{
541 gint q;
542 gst_message_parse_qos_values(object<GstMessage>(), NULL, NULL, &q);
543 return q;
544}
545
546void QosMessage::setValues(qint64 jitter, double proportion, int quality)
547{
548 gst_message_set_qos_values(object<GstMessage>(), jitter, proportion, quality);
549}
550
551Format QosMessage::format() const
552{
553 GstFormat f;
554 gst_message_parse_qos_stats(object<GstMessage>(), &f, NULL, NULL);
555 return static_cast<Format>(f);
556}
557
558quint64 QosMessage::processed() const
559{
560 guint64 p;
561 gst_message_parse_qos_stats(object<GstMessage>(), NULL, &p, NULL);
562 return p;
563}
564
565quint64 QosMessage::dropped() const
566{
567 guint64 p;
568 gst_message_parse_qos_stats(object<GstMessage>(), NULL, NULL, &p);
569 return p;
570}
571
572void QosMessage::setStats(Format format, quint64 processed, quint64 dropped)
573{
574 gst_message_set_qos_stats(object<GstMessage>(), static_cast<GstFormat>(format), processed,
575 dropped);
576}
577
578} //namespace QGst
Wrapper class for GError.
Definition error.h:31
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
Definition refpointer.h:328
Wrapper class for GValue.
Definition value.h:77
Wrappers for GStreamer classes.