/* Copyright (C) 2010 Collabora Multimedia. @author Mauricio Piacentini This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "event.h" #include "message.h" #include "object.h" #include #include namespace QGst { EventPtr Event::create(EventType type, const Structure & structure) { GstStructure *s = structure.isValid() ? gst_structure_copy(structure) : NULL; return EventPtr::wrap(gst_event_new_custom(static_cast(type), s), false); } ObjectPtr Event::source() const { return ObjectPtr::wrap(GST_EVENT_SRC(object())); } quint64 Event::timestamp() const { return object()->timestamp; } EventType Event::type() const { return static_cast(GST_EVENT_TYPE(object())); } QString Event::typeName() const { return QString::fromUtf8(GST_EVENT_TYPE_NAME(object())); } StructurePtr Event::internalStructure() { return StructurePtr(new SharedStructure(object()->structure)); } const StructurePtr Event::internalStructure() const { return StructurePtr(new SharedStructure(object()->structure)); } quint32 Event::sequenceNumber() const { return gst_event_get_seqnum(object()); } void Event::setSequenceNumber(quint32 num) { gst_event_set_seqnum(object(), num); } EventPtr Event::copy() const { return EventPtr::wrap(gst_event_copy(object()), false); } //******************************************************** FlushStartEventPtr FlushStartEvent::create() { return FlushStartEventPtr::wrap(gst_event_new_flush_start(), false); } //******************************************************** FlushStopEventPtr FlushStopEvent::create() { return FlushStopEventPtr::wrap(gst_event_new_flush_stop(), false); } //******************************************************** EosEventPtr EosEvent::create() { return EosEventPtr::wrap(gst_event_new_eos(), false); } //******************************************************** NewSegmentEventPtr NewSegmentEvent::create(bool update, double rate, double appliedRate, Format format, qint64 start, qint64 stop, qint64 position) { GstEvent * e = gst_event_new_new_segment_full(update, rate, appliedRate, static_cast(format), start, stop, position); return NewSegmentEventPtr::wrap(e, false); } bool NewSegmentEvent::isUpdate() const { gboolean u; gst_event_parse_new_segment_full(object(), &u, NULL, NULL, NULL, NULL, NULL, NULL); return u; } double NewSegmentEvent::rate() const { double r; gst_event_parse_new_segment_full(object(), NULL, &r, NULL, NULL, NULL, NULL, NULL); return r; } double NewSegmentEvent::appliedRate() const { double r; gst_event_parse_new_segment_full(object(), NULL, NULL, &r, NULL, NULL, NULL, NULL); return r; } Format NewSegmentEvent::format() const { GstFormat f; gst_event_parse_new_segment_full(object(), NULL, NULL, NULL, &f, NULL, NULL, NULL); return static_cast(f); } qint64 NewSegmentEvent::start() const { gint64 s; gst_event_parse_new_segment_full(object(), NULL, NULL, NULL, NULL, &s, NULL, NULL); return s; } qint64 NewSegmentEvent::stop() const { gint64 s; gst_event_parse_new_segment_full(object(), NULL, NULL, NULL, NULL, NULL, &s, NULL); return s; } qint64 NewSegmentEvent::position() const { gint64 p; gst_event_parse_new_segment_full(object(), NULL, NULL, NULL, NULL, NULL, NULL, &p); return p; } //******************************************************** BufferSizeEventPtr BufferSizeEvent::create(Format format, qint64 minSize, qint64 maxSize, bool isAsync) { GstEvent * e = gst_event_new_buffer_size(static_cast(format), minSize, maxSize, isAsync); return BufferSizeEventPtr::wrap(e, false); } Format BufferSizeEvent::format() const { GstFormat f; gst_event_parse_buffer_size(object(), &f, NULL, NULL, NULL); return static_cast(f); } qint64 BufferSizeEvent::minSize() const { gint64 s; gst_event_parse_buffer_size(object(), NULL, &s, NULL, NULL); return s; } qint64 BufferSizeEvent::maxSize() const { gint64 s; gst_event_parse_buffer_size(object(), NULL, NULL, &s, NULL); return s; } bool BufferSizeEvent::isAsync() const { gboolean u; gst_event_parse_buffer_size(object(), NULL, NULL, NULL, &u); return u; } //******************************************************** SinkMessageEventPtr SinkMessageEvent::create(const MessagePtr & msg) { GstEvent * e = gst_event_new_sink_message(msg); return SinkMessageEventPtr::wrap(e, false); } MessagePtr SinkMessageEvent::message() const { GstMessage * msg; gst_event_parse_sink_message(object(), &msg); //Wrap message (refcount was already increased), will unref() when MessagePtr is destroyed return MessagePtr::wrap(msg, false); } //******************************************************** QosEventPtr QosEvent::create(double proportion, ClockTimeDiff diff, ClockTime timeStamp) { GstEvent * e = gst_event_new_qos(proportion, diff, static_cast(timeStamp)); return QosEventPtr::wrap(e, false); } double QosEvent::proportion() const { double d; gst_event_parse_qos(object(), &d, NULL, NULL); return d; } ClockTimeDiff QosEvent::diff() const { GstClockTimeDiff c; gst_event_parse_qos(object(), NULL, &c, NULL); return c; } ClockTime QosEvent::timestamp() const { GstClockTime c; gst_event_parse_qos(object(), NULL, NULL, &c); return c; } //******************************************************** SeekEventPtr SeekEvent::create(double rate, Format format, SeekFlags flags, SeekType startType, qint64 start, SeekType stopType, qint64 stop) { GstEvent * e = gst_event_new_seek(rate, static_cast(format), static_cast(static_cast(flags)), static_cast(startType), start, static_cast(stopType), stop ); return SeekEventPtr::wrap(e, false); } double SeekEvent::rate() const { double d; gst_event_parse_seek(object(), &d, NULL, NULL, NULL, NULL, NULL, NULL); return d; } Format SeekEvent::format() const { GstFormat f; gst_event_parse_seek(object(), NULL, &f, NULL, NULL, NULL, NULL, NULL); return static_cast(f); } SeekFlags SeekEvent::flags() const { GstSeekFlags f; gst_event_parse_seek(object(), NULL, NULL, &f, NULL, NULL, NULL, NULL); return static_cast(f); } SeekType SeekEvent::startType() const { GstSeekType t; gst_event_parse_seek(object(), NULL, NULL, NULL, &t, NULL, NULL, NULL); return static_cast(t); } qint64 SeekEvent::start() const { gint64 s; gst_event_parse_seek(object(), NULL, NULL, NULL, NULL, &s, NULL, NULL); return s; } SeekType SeekEvent::stopType() const { GstSeekType t; gst_event_parse_seek(object(), NULL, NULL, NULL, NULL, NULL, &t, NULL); return static_cast(t); } qint64 SeekEvent::stop() const { gint64 s; gst_event_parse_seek(object(), NULL, NULL, NULL, NULL, NULL, NULL, &s); return s; } //******************************************************** NavigationEventPtr NavigationEvent::create(const Structure & structure) { GstStructure * s = structure.isValid() ? gst_structure_copy(structure) : NULL; GstEvent * e = gst_event_new_navigation(s); return NavigationEventPtr::wrap(e, false); } //******************************************************** LatencyEventPtr LatencyEvent::create(ClockTime latency) { GstEvent * e = gst_event_new_latency(latency); return LatencyEventPtr::wrap(e, false); } ClockTime LatencyEvent::latency() const { GstClockTime c; gst_event_parse_latency(object(), &c); return c; } //******************************************************** StepEventPtr StepEvent::create(Format format, quint64 amount, double rate, bool flush, bool intermediate) { GstEvent * e = gst_event_new_step(static_cast(format), amount, rate, flush, intermediate); return StepEventPtr::wrap(e, false); } Format StepEvent::format() const { GstFormat f; gst_event_parse_step(object(), &f, NULL, NULL, NULL, NULL); return static_cast(f); } quint64 StepEvent::amount() const { guint64 a; gst_event_parse_step(object(), NULL, &a, NULL, NULL, NULL); return a; } double StepEvent::rate() const { double d; gst_event_parse_step(object(), NULL, NULL, &d, NULL, NULL); return d; } bool StepEvent::flush() const { gboolean f; gst_event_parse_step(object(), NULL, NULL, NULL, &f, NULL); return f; } bool StepEvent::intermediate() const { gboolean i; gst_event_parse_step(object(), NULL, NULL, NULL, NULL, &i); return i; } QDebug operator<<(QDebug debug, EventType type) { debug.nospace() << gst_event_type_get_name(static_cast(type)); return debug.space(); } QDebug operator<<(QDebug debug, const EventPtr & event) { debug.nospace() << "QGst::Event(Type: " << event->type() << ")"; return debug.space(); } } //namespace QGst