diff options
-rw-r--r-- | src/QGst/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/QGst/ClockTime | 1 | ||||
-rw-r--r-- | src/QGst/buffer.h | 1 | ||||
-rw-r--r-- | src/QGst/bus.h | 1 | ||||
-rw-r--r-- | src/QGst/clock.cpp | 18 | ||||
-rw-r--r-- | src/QGst/clock.h | 6 | ||||
-rw-r--r-- | src/QGst/clocktime.cpp | 41 | ||||
-rw-r--r-- | src/QGst/clocktime.h | 64 | ||||
-rw-r--r-- | src/QGst/element.h | 1 | ||||
-rw-r--r-- | src/QGst/event.h | 1 | ||||
-rw-r--r-- | src/QGst/global.h | 8 | ||||
-rw-r--r-- | src/QGst/query.h | 1 | ||||
-rw-r--r-- | tests/auto/clocktest.cpp | 20 | ||||
-rw-r--r-- | tests/auto/eventtest.cpp | 6 | ||||
-rw-r--r-- | tests/auto/querytest.cpp | 4 |
15 files changed, 130 insertions, 45 deletions
diff --git a/src/QGst/CMakeLists.txt b/src/QGst/CMakeLists.txt index 5f51d5a..021c50b 100644 --- a/src/QGst/CMakeLists.txt +++ b/src/QGst/CMakeLists.txt @@ -27,6 +27,7 @@ set(QtGStreamer_SRCS clock.cpp buffer.cpp event.cpp + clocktime.cpp ${CMAKE_CURRENT_BINARY_DIR}/gen.cpp ) @@ -68,6 +69,7 @@ set(QtGStreamer_INSTALLED_HEADERS clock.h Clock buffer.h Buffer event.h Event + clocktime.h ClockTime Ui/global.h Ui/videowidget.h Ui/VideoWidget diff --git a/src/QGst/ClockTime b/src/QGst/ClockTime new file mode 100644 index 0000000..e612274 --- /dev/null +++ b/src/QGst/ClockTime @@ -0,0 +1 @@ +#include "clocktime.h" diff --git a/src/QGst/buffer.h b/src/QGst/buffer.h index cb9aa7c..9f3959f 100644 --- a/src/QGst/buffer.h +++ b/src/QGst/buffer.h @@ -19,6 +19,7 @@ #define QGST_BUFFER_H #include "miniobject.h" +#include "clocktime.h" namespace QGst { diff --git a/src/QGst/bus.h b/src/QGst/bus.h index 375a348..ec4e683 100644 --- a/src/QGst/bus.h +++ b/src/QGst/bus.h @@ -18,6 +18,7 @@ #define QGST_BUS_H #include "object.h" +#include "clocktime.h" namespace QGst { diff --git a/src/QGst/clock.cpp b/src/QGst/clock.cpp index 682b230..848f94b 100644 --- a/src/QGst/clock.cpp +++ b/src/QGst/clock.cpp @@ -42,23 +42,7 @@ ClockTime Clock::resolution() const QTime Clock::time() const { - return Clock::timeFromClockTime(clockTime()); -} - -QTime Clock::timeFromClockTime(ClockTime clocktime) -{ - ClockTime asSeconds = GST_TIME_AS_SECONDS(clocktime); - ClockTime h = (asSeconds / 3600) % 24; - ClockTime min = (asSeconds / 60) % 60; - ClockTime sec = asSeconds % 60; - ClockTime msec = GST_TIME_AS_MSECONDS(clocktime) % 1000; - return QTime(h, min, sec, msec); -} - -ClockTime Clock::clockTimeFromTime(const QTime & time) -{ - return (time.hour()*3600*1000000000LL) + (time.minute()*60*1000000000LL) - + (time.second()*1000000000LL) + (time.msec()*1000000LL); + return clockTime().toTime(); } } diff --git a/src/QGst/clock.h b/src/QGst/clock.h index f530d24..c6a3734 100644 --- a/src/QGst/clock.h +++ b/src/QGst/clock.h @@ -19,8 +19,7 @@ #define QGST_CLOCK_H #include "object.h" - -class QTime; +#include "clocktime.h" namespace QGst { @@ -36,9 +35,6 @@ public: ClockTime resolution() const; ClockTime clockTime() const; QTime time() const; - - static QTime timeFromClockTime(ClockTime clocktime); - static ClockTime clockTimeFromTime(const QTime & time); }; } diff --git a/src/QGst/clocktime.cpp b/src/QGst/clocktime.cpp new file mode 100644 index 0000000..3b23ee8 --- /dev/null +++ b/src/QGst/clocktime.cpp @@ -0,0 +1,41 @@ +/* + Copyright (C) 2010 Collabora Multimedia. + @author Mauricio Piacentini <mauricio.piacentini@collabora.co.uk> + + 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 <http://www.gnu.org/licenses/>. +*/ +#include "clocktime.h" + +#include <QtCore/QTime> +#include <gst/gstclock.h> + +namespace QGst { + +QTime ClockTime::toTime() const +{ + ClockTime asSeconds = GST_TIME_AS_SECONDS(m_clocktime); + ClockTime h = (asSeconds / 3600) % 24; + ClockTime min = (asSeconds / 60) % 60; + ClockTime sec = asSeconds % 60; + ClockTime msec = GST_TIME_AS_MSECONDS(m_clocktime) % 1000; + return QTime(h, min, sec, msec); +} + +ClockTime ClockTime::fromTime(const QTime & time) +{ + return (time.hour()*3600*Q_UINT64_C(1000000000)) + (time.minute()*60*Q_UINT64_C(1000000000)) + + (time.second()*Q_UINT64_C(1000000000)) + (time.msec()*Q_UINT64_C(1000000)); +} + +} //namespace QGst diff --git a/src/QGst/clocktime.h b/src/QGst/clocktime.h new file mode 100644 index 0000000..2858a21 --- /dev/null +++ b/src/QGst/clocktime.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2011 Collabora Ltd. <info@collabora.co.uk> + @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk> + + 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 <http://www.gnu.org/licenses/>. +*/ +#ifndef QGST_CLOCKTIME_H +#define QGST_CLOCKTIME_H + +#include "global.h" +class QTime; + +namespace QGst { + +/*! \relates ClockTime + * A datatype to hold a time difference, measured in nanoseconds + */ +typedef qint64 ClockTimeDiff; + + +/*! \headerfile clocktime.h <QGst/ClockTime> + * \brief A datatype to hold a time, measured in nanoseconds + * + * This is a thin wrapper around a GstClockTime, which is actually a quint64. + */ +class QTGSTREAMER_EXPORT ClockTime +{ +public: + /*! Represents an invalid time. \sa isValid() */ + static const quint64 None = -1; + + inline ClockTime(quint64 t = None) : m_clocktime(t) {} + inline operator quint64() const { return m_clocktime; } + + /*! Returns true if this ClockTime is valid, i.e. it is not equal to ClockTime::None */ + inline bool isValid() const { return m_clocktime != None; } + + /*! This method allows you to convert this ClockTime to a QTime. + * Be careful, as the conversion will lose some precision. ClockTime + * holds nanoseconds, while QTime is only able to hold milliseconds. + */ + QTime toTime() const; + + /*! Creates a ClockTime from a QTime */ + static ClockTime fromTime(const QTime & time); + +private: + quint64 m_clocktime; +}; + +} //namspace QGst + +#endif // QGST_CLOCKTIME_H diff --git a/src/QGst/element.h b/src/QGst/element.h index 0b6a9fc..069ee95 100644 --- a/src/QGst/element.h +++ b/src/QGst/element.h @@ -19,6 +19,7 @@ #include "object.h" #include "caps.h" +#include "clocktime.h" namespace QGst { diff --git a/src/QGst/event.h b/src/QGst/event.h index 3896f4d..085ca9c 100644 --- a/src/QGst/event.h +++ b/src/QGst/event.h @@ -20,6 +20,7 @@ #include "miniobject.h" #include "structure.h" +#include "clocktime.h" namespace QGst { diff --git a/src/QGst/global.h b/src/QGst/global.h index 5e76e6f..9abdc29 100644 --- a/src/QGst/global.h +++ b/src/QGst/global.h @@ -146,12 +146,4 @@ QGST_WRAPPER_DECLARATION(XOverlay) }; \ } -namespace QGst { - /*! A datatype to hold a time, measured in nanoseconds */ - typedef quint64 ClockTime; - - /*! A datatype to hold a time difference, measured in nanoseconds */ - typedef qint64 ClockTimeDiff; -} - #endif diff --git a/src/QGst/query.h b/src/QGst/query.h index 5569975..d85bf85 100644 --- a/src/QGst/query.h +++ b/src/QGst/query.h @@ -20,6 +20,7 @@ #include "miniobject.h" #include "structure.h" +#include "clocktime.h" class QUrl; diff --git a/tests/auto/clocktest.cpp b/tests/auto/clocktest.cpp index 3cabc47..fac49d2 100644 --- a/tests/auto/clocktest.cpp +++ b/tests/auto/clocktest.cpp @@ -42,26 +42,26 @@ void ClockTest::systemTest() void ClockTest::timeFromClockTimeTest() { - QCOMPARE(QGst::Clock::timeFromClockTime(3600 * 1000 * 1000000LL).toString(), + QCOMPARE(QGst::ClockTime(3600 * 1000 * Q_UINT64_C(1000000)).toTime().toString(), QString("01:00:00")); // 1 hour - QCOMPARE(QGst::Clock::timeFromClockTime(4000 * 1000 * 1000000LL).toString(), + QCOMPARE(QGst::ClockTime(4000 * 1000 * Q_UINT64_C(1000000)).toTime().toString(), QString("01:06:40")); - QCOMPARE(QGst::Clock::timeFromClockTime(50001 * 1000 * 1000000LL).toString(), + QCOMPARE(QGst::ClockTime(50001 * 1000 * Q_UINT64_C(1000000)).toTime().toString(), QString("13:53:21")); - QCOMPARE(QGst::Clock::timeFromClockTime(120000 * 1000 * 1000000LL).toString(), + QCOMPARE(QGst::ClockTime(120000 * 1000 * Q_UINT64_C(1000000)).toTime().toString(), QString("09:20:00")); // wraps } void ClockTest::clockTimeFromTimeTest() { - QCOMPARE(static_cast<quint64>(QGst::Clock::clockTimeFromTime(QTime(1, 0))), - static_cast<quint64>(3600 * 1000 * 1000000LL)); // 1 hour + QCOMPARE(static_cast<quint64>(QGst::ClockTime::fromTime(QTime(1, 0))), + static_cast<quint64>(3600 * 1000 * Q_UINT64_C(1000000))); // 1 hour - QCOMPARE(static_cast<quint64>(QGst::Clock::clockTimeFromTime(QTime(1, 6, 40))), - static_cast<quint64>(4000 * 1000 * 1000000LL)); + QCOMPARE(static_cast<quint64>(QGst::ClockTime::fromTime(QTime(1, 6, 40))), + static_cast<quint64>(4000 * 1000 * Q_UINT64_C(1000000))); - QCOMPARE(static_cast<quint64>(QGst::Clock::clockTimeFromTime(QTime(13, 53, 21, 15))), - static_cast<quint64>((50001 * 1000 +15) * 1000000LL)); + QCOMPARE(static_cast<quint64>(QGst::ClockTime::fromTime(QTime(13, 53, 21, 15))), + static_cast<quint64>((50001 * 1000 +15) * Q_UINT64_C(1000000))); } diff --git a/tests/auto/eventtest.cpp b/tests/auto/eventtest.cpp index 5509eee..d36e3c0 100644 --- a/tests/auto/eventtest.cpp +++ b/tests/auto/eventtest.cpp @@ -134,8 +134,8 @@ void EventTest::qosTest() QCOMPARE(evt->typeName(), QString("qos")); QCOMPARE(evt->proportion(), 123.4); - QCOMPARE(evt->diff(), static_cast<qint64>(23455)); - QCOMPARE(evt->timestamp(), static_cast<quint64>(98765432)); + QCOMPARE(evt->diff(), QGst::ClockTimeDiff(23455)); + QCOMPARE(evt->timestamp(), QGst::ClockTime(98765432)); }; void EventTest::seekTest() @@ -174,7 +174,7 @@ void EventTest::latencyTest() QVERIFY(evt->type()==QGst::EventLatency); QCOMPARE(evt->typeName(), QString("latency")); - QCOMPARE(evt->latency(), static_cast<quint64>(43210)); + QCOMPARE(evt->latency(), QGst::ClockTime(43210)); }; void EventTest::stepTest() diff --git a/tests/auto/querytest.cpp b/tests/auto/querytest.cpp index 3fec8d0..d9edb89 100644 --- a/tests/auto/querytest.cpp +++ b/tests/auto/querytest.cpp @@ -79,8 +79,8 @@ void QueryTest::latencyTest() query->setValues(true, 10000, 100000); QVERIFY(query->hasLive()); - QCOMPARE(query->minimumLatency(), static_cast<quint64>(10000)); - QCOMPARE(query->maximumLatency(), static_cast<quint64>(100000)); + QCOMPARE(query->minimumLatency(), QGst::ClockTime(10000)); + QCOMPARE(query->maximumLatency(), QGst::ClockTime(100000)); } void QueryTest::seekingTest() |