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