00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "message.h"
00018 #include "element.h"
00019 #include "../QGlib/error.h"
00020 #include "../QGlib/string_p.h"
00021 #include <QtCore/QDebug>
00022 #include <gst/gst.h>
00023
00024 namespace QGst {
00025
00026 ObjectPtr Message::source() const
00027 {
00028 return ObjectPtr::wrap(GST_MESSAGE_SRC(object<GstMessage>()));
00029 }
00030
00031 quint64 Message::timestamp() const
00032 {
00033 return object<GstMessage>()->timestamp;
00034 }
00035
00036 QString Message::typeName() const
00037 {
00038 return QString::fromUtf8(GST_MESSAGE_TYPE_NAME(object<GstMessage>()));
00039 }
00040
00041 MessageType Message::type() const
00042 {
00043 return static_cast<MessageType>(GST_MESSAGE_TYPE(object<GstMessage>()));
00044 }
00045
00046 StructurePtr Message::internalStructure()
00047 {
00048 return SharedStructure::fromMiniObject(object<GstMessage>()->structure, MiniObjectPtr(this));
00049 }
00050
00051 quint32 Message::sequenceNumber() const
00052 {
00053 return gst_message_get_seqnum(object<GstMessage>());
00054 }
00055
00056 void Message::setSequenceNumber(quint32 num)
00057 {
00058 gst_message_set_seqnum(object<GstMessage>(), num);
00059 }
00060
00061
00062
00063 EosMessagePtr EosMessage::create(const ObjectPtr & source)
00064 {
00065 return EosMessagePtr::wrap(gst_message_new_eos(source), false);
00066 }
00067
00068
00069
00070 ErrorMessagePtr ErrorMessage::create(const ObjectPtr & source,
00071 const QGlib::Error & error, const char *debug)
00072 {
00073
00074 GError *e = const_cast<GError*>(static_cast<const GError*>(error));
00075 return ErrorMessagePtr::wrap(gst_message_new_error(source, e, debug), false);
00076 }
00077
00078 QGlib::Error ErrorMessage::error() const
00079 {
00080 GError *e;
00081 gst_message_parse_error(object<GstMessage>(), &e, NULL);
00082 return QGlib::Error(e);
00083 }
00084
00085 QString ErrorMessage::debugMessage() const
00086 {
00087 gchar *debug;
00088 GError *e;
00089
00090 gst_message_parse_error(object<GstMessage>(), &e, &debug);
00091 if (e) {
00092 g_error_free (e);
00093 }
00094 return QGlib::Private::stringFromGCharPtr(debug);
00095 }
00096
00097
00098
00099 WarningMessagePtr WarningMessage::create(const ObjectPtr & source,
00100 const QGlib::Error & error, const char *debug)
00101 {
00102
00103 GError *e = const_cast<GError*>(static_cast<const GError*>(error));
00104 return WarningMessagePtr::wrap(gst_message_new_warning(source, e, debug), false);
00105 }
00106
00107 QGlib::Error WarningMessage::error() const
00108 {
00109 GError *e;
00110 gst_message_parse_warning(object<GstMessage>(), &e, NULL);
00111 return QGlib::Error(e);
00112 }
00113
00114 QString WarningMessage::debugMessage() const
00115 {
00116 gchar *debug;
00117 GError *e;
00118
00119 gst_message_parse_warning(object<GstMessage>(), &e, &debug);
00120 if (e) {
00121 g_error_free (e);
00122 }
00123 return QGlib::Private::stringFromGCharPtr(debug);
00124 }
00125
00126
00127
00128 InfoMessagePtr InfoMessage::create(const ObjectPtr & source,
00129 const QGlib::Error & error, const char *debug)
00130 {
00131
00132 GError *e = const_cast<GError*>(static_cast<const GError*>(error));
00133 return InfoMessagePtr::wrap(gst_message_new_info(source, e, debug), false);
00134 }
00135
00136 QGlib::Error InfoMessage::error() const
00137 {
00138 GError *e;
00139 gst_message_parse_info(object<GstMessage>(), &e, NULL);
00140 return QGlib::Error(e);
00141 }
00142
00143 QString InfoMessage::debugMessage() const
00144 {
00145 gchar *debug;
00146 GError *e;
00147
00148 gst_message_parse_info(object<GstMessage>(), &e, &debug);
00149 if (e) {
00150 g_error_free (e);
00151 }
00152 return QGlib::Private::stringFromGCharPtr(debug);
00153 }
00154
00155
00156
00157 TagMessagePtr TagMessage::create(const ObjectPtr & source, const TagList & taglist)
00158 {
00159 GstMessage *m = gst_message_new_tag(source, gst_tag_list_copy(taglist));
00160 return TagMessagePtr::wrap(m, false);
00161 }
00162
00163 TagList TagMessage::taglist() const
00164 {
00165 GstTagList * t;
00166 gst_message_parse_tag(object<GstMessage>(), &t);
00167 TagList tl(t);
00168 gst_tag_list_free(t);
00169 return tl;
00170 }
00171
00172
00173
00174 BufferingMessagePtr BufferingMessage::create(const ObjectPtr & source, int percent)
00175 {
00176 GstMessage *m = gst_message_new_buffering(source, percent);
00177 return BufferingMessagePtr::wrap(m, false);
00178 }
00179
00180 int BufferingMessage::percent() const
00181 {
00182 gint p;
00183 gst_message_parse_buffering(object<GstMessage>(), &p);
00184 return p;
00185 }
00186
00187 BufferingMode BufferingMessage::mode() const
00188 {
00189 GstBufferingMode m;
00190 gst_message_parse_buffering_stats(object<GstMessage>(), &m, NULL, NULL, NULL);
00191 return static_cast<BufferingMode>(m);
00192 }
00193
00194 int BufferingMessage::averageInputRate() const
00195 {
00196 gint a;
00197 gst_message_parse_buffering_stats(object<GstMessage>(), NULL, &a, NULL, NULL);
00198 return a;
00199 }
00200
00201 int BufferingMessage::averageOutputRate() const
00202 {
00203 gint a;
00204 gst_message_parse_buffering_stats(object<GstMessage>(), NULL, NULL, &a, NULL);
00205 return a;
00206 }
00207
00208 qint64 BufferingMessage::bufferingTimeLeft() const
00209 {
00210 gint64 a;
00211 gst_message_parse_buffering_stats(object<GstMessage>(), NULL, NULL, NULL, &a);
00212 return a;
00213 }
00214
00215 void BufferingMessage::setStats(BufferingMode mode, int avgIn, int avgOut, qint64 bufferingLeft)
00216 {
00217 gst_message_set_buffering_stats(object<GstMessage>(), static_cast<GstBufferingMode>(mode),
00218 avgIn, avgOut, bufferingLeft);
00219 }
00220
00221
00222
00223 StateChangedMessagePtr StateChangedMessage::create(const ObjectPtr & source,
00224 State oldState, State newState, State pending)
00225 {
00226 GstMessage *m = gst_message_new_state_changed(source, static_cast<GstState>(oldState),
00227 static_cast<GstState>(newState),
00228 static_cast<GstState>(pending));
00229 return StateChangedMessagePtr::wrap(m, false);
00230 }
00231
00232 State StateChangedMessage::oldState() const
00233 {
00234 GstState s;
00235 gst_message_parse_state_changed(object<GstMessage>(), &s, NULL, NULL);
00236 return static_cast<State>(s);
00237 }
00238
00239 State StateChangedMessage::newState() const
00240 {
00241 GstState s;
00242 gst_message_parse_state_changed(object<GstMessage>(), NULL, &s, NULL);
00243 return static_cast<State>(s);
00244 }
00245
00246 State StateChangedMessage::pendingState() const
00247 {
00248 GstState s;
00249 gst_message_parse_state_changed(object<GstMessage>(), NULL, NULL, &s);
00250 return static_cast<State>(s);
00251 }
00252
00253
00254
00255 StepDoneMessagePtr StepDoneMessage::create(const ObjectPtr & source, Format format,
00256 quint64 amount, double rate, bool flush,
00257 bool intermediate, quint64 duration, bool eos)
00258 {
00259 GstMessage *m = gst_message_new_step_done(source, static_cast<GstFormat>(format), amount,
00260 rate, flush, intermediate, duration, eos);
00261 return StepDoneMessagePtr::wrap(m, false);
00262 }
00263
00264 Format StepDoneMessage::format() const
00265 {
00266 GstFormat f;
00267 gst_message_parse_step_done(object<GstMessage>(), &f, NULL, NULL, NULL, NULL, NULL, NULL);
00268 return static_cast<Format>(f);
00269 }
00270
00271 quint64 StepDoneMessage::amount() const
00272 {
00273 guint64 a;
00274 gst_message_parse_step_done(object<GstMessage>(), NULL, &a, NULL, NULL, NULL, NULL, NULL);
00275 return a;
00276 }
00277
00278 double StepDoneMessage::rate() const
00279 {
00280 gdouble d;
00281 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, &d, NULL, NULL, NULL, NULL);
00282 return d;
00283 }
00284
00285 bool StepDoneMessage::isFlushingStep() const
00286 {
00287 gboolean b;
00288 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, &b, NULL, NULL, NULL);
00289 return b;
00290 }
00291
00292 bool StepDoneMessage::isIntermediateStep() const
00293 {
00294 gboolean b;
00295 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, NULL, &b, NULL, NULL);
00296 return b;
00297 }
00298
00299 quint64 StepDoneMessage::duration() const
00300 {
00301 guint64 d;
00302 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, NULL, NULL, &d, NULL);
00303 return d;
00304 }
00305
00306 bool StepDoneMessage::causedEos() const
00307 {
00308 gboolean e;
00309 gst_message_parse_step_done(object<GstMessage>(), NULL, NULL, NULL, NULL, NULL, NULL, &e);
00310 return e;
00311 }
00312
00313
00314
00315 StreamStatusMessagePtr StreamStatusMessage::create(const ObjectPtr & source,
00316 StreamStatusType type, const ElementPtr & owner)
00317 {
00318 GstMessage *m = gst_message_new_stream_status(source, static_cast<GstStreamStatusType>(type), owner);
00319 return StreamStatusMessagePtr::wrap(m, false);
00320 }
00321
00322 StreamStatusType StreamStatusMessage::statusType() const
00323 {
00324 GstStreamStatusType t;
00325 gst_message_parse_stream_status(object<GstMessage>(), &t, NULL);
00326 return static_cast<StreamStatusType>(t);
00327 }
00328
00329 ElementPtr StreamStatusMessage::owner() const
00330 {
00331 GstElement *e;
00332 gst_message_parse_stream_status(object<GstMessage>(), NULL, &e);
00333 return ElementPtr::wrap(e);
00334 }
00335
00336 QGlib::Value StreamStatusMessage::streamStatusObject() const
00337 {
00338 return QGlib::Value(gst_message_get_stream_status_object(object<GstMessage>()));
00339 }
00340
00341 void StreamStatusMessage::setStreamStatusObject(const QGlib::Value & obj)
00342 {
00343 gst_message_set_stream_status_object(object<GstMessage>(), obj);
00344 }
00345
00346
00347
00348 ApplicationMessagePtr ApplicationMessage::create(const ObjectPtr & source, const Structure & structure)
00349 {
00350 GstStructure *s = structure.isValid() ? gst_structure_copy(structure) : NULL;
00351 return ApplicationMessagePtr::wrap(gst_message_new_application(source, s), false);
00352 }
00353
00354
00355
00356 ElementMessagePtr ElementMessage::create(const ObjectPtr & source, const Structure & structure)
00357 {
00358 GstStructure *s = structure.isValid() ? gst_structure_copy(structure) : NULL;
00359 return ElementMessagePtr::wrap(gst_message_new_element(source, s), false);
00360 }
00361
00362
00363
00364 SegmentDoneMessagePtr SegmentDoneMessage::create(const ObjectPtr & source, Format format, qint64 position)
00365 {
00366 GstMessage *m = gst_message_new_segment_done(source, static_cast<GstFormat>(format), position);
00367 return SegmentDoneMessagePtr::wrap(m, false);
00368 }
00369
00370 Format SegmentDoneMessage::format() const
00371 {
00372 GstFormat f;
00373 gst_message_parse_segment_done(object<GstMessage>(), &f, NULL);
00374 return static_cast<Format>(f);
00375 }
00376
00377 qint64 SegmentDoneMessage::position() const
00378 {
00379 gint64 p;
00380 gst_message_parse_segment_done(object<GstMessage>(), NULL, &p);
00381 return p;
00382 }
00383
00384
00385
00386 DurationMessagePtr DurationMessage::create(const ObjectPtr & source, Format format, qint64 duration)
00387 {
00388 GstMessage *m = gst_message_new_duration(source, static_cast<GstFormat>(format), duration);
00389 return DurationMessagePtr::wrap(m, false);
00390 }
00391
00392 Format DurationMessage::format() const
00393 {
00394 GstFormat f;
00395 gst_message_parse_duration(object<GstMessage>(), &f, NULL);
00396 return static_cast<Format>(f);
00397 }
00398
00399 qint64 DurationMessage::duration() const
00400 {
00401 gint64 d;
00402 gst_message_parse_duration(object<GstMessage>(), NULL, &d);
00403 return d;
00404 }
00405
00406
00407
00408 LatencyMessagePtr LatencyMessage::create(const ObjectPtr & source)
00409 {
00410 return LatencyMessagePtr::wrap(gst_message_new_latency(source), false);
00411 }
00412
00413
00414
00415 AsyncDoneMessagePtr AsyncDoneMessage::create(const ObjectPtr & source)
00416 {
00417 return AsyncDoneMessagePtr::wrap(gst_message_new_async_done(source), false);
00418 }
00419
00420
00421
00422 RequestStateMessagePtr RequestStateMessage::create(const ObjectPtr & source, State state)
00423 {
00424 GstMessage *m = gst_message_new_request_state(source, static_cast<GstState>(state));
00425 return RequestStateMessagePtr::wrap(m, false);
00426 }
00427
00428 State RequestStateMessage::state() const
00429 {
00430 GstState s;
00431 gst_message_parse_request_state(object<GstMessage>(), &s);
00432 return static_cast<State>(s);
00433 }
00434
00435
00436
00437 StepStartMessagePtr StepStartMessage::create(const ObjectPtr & source, bool active, Format format,
00438 quint64 amount, double rate, bool flush, bool intermediate)
00439 {
00440 GstMessage *m = gst_message_new_step_start(source, active, static_cast<GstFormat>(format),
00441 amount, rate, flush, intermediate);
00442 return StepStartMessagePtr::wrap(m, false);
00443 }
00444
00445 bool StepStartMessage::isActive() const
00446 {
00447 gboolean a;
00448 gst_message_parse_step_start(object<GstMessage>(), &a, NULL, NULL, NULL, NULL, NULL);
00449 return a;
00450 }
00451
00452 Format StepStartMessage::format() const
00453 {
00454 GstFormat f;
00455 gst_message_parse_step_start(object<GstMessage>(), NULL, &f, NULL, NULL, NULL, NULL);
00456 return static_cast<Format>(f);
00457 }
00458
00459 quint64 StepStartMessage::amount() const
00460 {
00461 guint64 a;
00462 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, &a, NULL, NULL, NULL);
00463 return a;
00464 }
00465
00466 double StepStartMessage::rate() const
00467 {
00468 gdouble d;
00469 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, NULL, &d, NULL, NULL);
00470 return d;
00471 }
00472
00473 bool StepStartMessage::isFlushingStep() const
00474 {
00475 gboolean b;
00476 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, NULL, NULL, &b, NULL);
00477 return b;
00478 }
00479
00480 bool StepStartMessage::isIntermediateStep() const
00481 {
00482 gboolean b;
00483 gst_message_parse_step_start(object<GstMessage>(), NULL, NULL, NULL, NULL, NULL, &b);
00484 return b;
00485 }
00486
00487
00488
00489 QosMessagePtr QosMessage::create(const ObjectPtr & source, bool live, quint64 runningTime,
00490 quint64 streamTime, quint64 timestamp, quint64 duration)
00491 {
00492 GstMessage *m = gst_message_new_qos(source, live, runningTime, streamTime, timestamp, duration);
00493 return QosMessagePtr::wrap(m, false);
00494 }
00495
00496 bool QosMessage::live() const
00497 {
00498 gboolean l;
00499 gst_message_parse_qos(object<GstMessage>(), &l, NULL, NULL, NULL, NULL);
00500 return l;
00501 }
00502
00503 quint64 QosMessage::runningTime() const
00504 {
00505 guint64 t;
00506 gst_message_parse_qos(object<GstMessage>(), NULL, &t, NULL, NULL, NULL);
00507 return t;
00508 }
00509
00510 quint64 QosMessage::streamTime() const
00511 {
00512 guint64 t;
00513 gst_message_parse_qos(object<GstMessage>(), NULL, NULL, &t, NULL, NULL);
00514 return t;
00515 }
00516
00517 quint64 QosMessage::timestamp() const
00518 {
00519 guint64 t;
00520 gst_message_parse_qos(object<GstMessage>(), NULL, NULL, NULL, &t, NULL);
00521 return t;
00522 }
00523
00524 quint64 QosMessage::duration() const
00525 {
00526 guint64 t;
00527 gst_message_parse_qos(object<GstMessage>(), NULL, NULL, NULL, NULL, &t);
00528 return t;
00529 }
00530
00531 qint64 QosMessage::jitter() const
00532 {
00533 gint64 j;
00534 gst_message_parse_qos_values(object<GstMessage>(), &j, NULL, NULL);
00535 return j;
00536 }
00537
00538 double QosMessage::proportion() const
00539 {
00540 double d;
00541 gst_message_parse_qos_values(object<GstMessage>(), NULL, &d, NULL);
00542 return d;
00543 }
00544
00545 int QosMessage::quality() const
00546 {
00547 gint q;
00548 gst_message_parse_qos_values(object<GstMessage>(), NULL, NULL, &q);
00549 return q;
00550 }
00551
00552 void QosMessage::setValues(qint64 jitter, double proportion, int quality)
00553 {
00554 gst_message_set_qos_values(object<GstMessage>(), jitter, proportion, quality);
00555 }
00556
00557 Format QosMessage::format() const
00558 {
00559 GstFormat f;
00560 gst_message_parse_qos_stats(object<GstMessage>(), &f, NULL, NULL);
00561 return static_cast<Format>(f);
00562 }
00563
00564 quint64 QosMessage::processed() const
00565 {
00566 guint64 p;
00567 gst_message_parse_qos_stats(object<GstMessage>(), NULL, &p, NULL);
00568 return p;
00569 }
00570
00571 quint64 QosMessage::dropped() const
00572 {
00573 guint64 p;
00574 gst_message_parse_qos_stats(object<GstMessage>(), NULL, NULL, &p);
00575 return p;
00576 }
00577
00578 void QosMessage::setStats(Format format, quint64 processed, quint64 dropped)
00579 {
00580 gst_message_set_qos_stats(object<GstMessage>(), static_cast<GstFormat>(format), processed,
00581 dropped);
00582 }
00583
00584 }