2 * This file is part of QMAFW
4 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights
7 * Contact: Visa Smolander <visa.smolander@nokia.com>
9 * This software, including documentation, is protected by copyright controlled
10 * by Nokia Corporation. All rights are reserved. Copying, including
11 * reproducing, storing, adapting or translating, any or all of this material
12 * requires the prior written consent of Nokia Corporation. This material also
13 * contains confidential information which may not be disclosed to others
14 * without the prior written consent of Nokia.
18 #include "ut_MafwGstRendererSeeker.h"
22 Q_DECLARE_METATYPE(QList<qint64>);
24 extern gint64 g_currentPosition;
25 extern gint64 g_duration;
26 extern gint64 g_seekRequested;
27 extern gint g_seeksCalled;
29 void Ut_MafwGstRendererSeeker::initTestCase()
34 void Ut_MafwGstRendererSeeker::cleanupTestCase()
38 void Ut_MafwGstRendererSeeker::init()
40 m_seeker = mafw_gst_renderer_seeker_new();
41 mafw_gst_renderer_seeker_set_pipeline(m_seeker, (GstElement*)(313));
44 void Ut_MafwGstRendererSeeker::cleanup()
46 mafw_gst_renderer_seeker_free(m_seeker);
48 g_currentPosition = -1;
56 void Ut_MafwGstRendererSeeker::testSeekSuccess()
58 QFETCH(qint64, startPosition);
59 QFETCH(qint64, seekTo);
60 QFETCH(qint64, seekGoesTo);
61 QFETCH(qint64, mediaDuration);
63 g_duration = mediaDuration;
64 g_currentPosition = startPosition;
66 mafw_gst_renderer_seeker_seek_to(m_seeker, seekTo);
67 QCOMPARE(g_seekRequested, seekTo);
69 g_currentPosition = seekGoesTo;
71 gint64 newSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
73 // only one seek operation should be called when successful
74 QCOMPARE(g_seeksCalled, 1);
75 QCOMPARE(newSeekPos, -1ll);
78 void Ut_MafwGstRendererSeeker::testSeekSuccess_data()
80 QTest::addColumn<qint64>("startPosition");
81 QTest::addColumn<qint64>("seekTo");
82 QTest::addColumn<qint64>("seekGoesTo");
83 QTest::addColumn<qint64>("mediaDuration");
85 QTest::newRow("1") << 0ll << 20ll << 21ll << 30ll;
86 QTest::newRow("1a") << 0ll << 19ll << 21ll << 30ll;
87 QTest::newRow("2") << 5ll << 1ll << 2ll << 10ll;
88 QTest::newRow("3") << 100ll << 150ll << 119ll << 120ll;
90 //intentionally messed values
91 QTest::newRow("weird1") << 4ll << 1ll << 1ll << 2ll;
92 QTest::newRow("weird2") << -13ll << 13ll << 12ll << 0ll;
93 QTest::newRow("weird2") << 10ll << 5ll << 4ll << 1ll;
97 void Ut_MafwGstRendererSeeker::testSeekFails()
99 QFETCH(qint64, startPosition);
100 QFETCH(qint64, seekTo);
101 QFETCH(QList<qint64>, processedSeekRequests);
102 QFETCH(QList<qint64>, seekGoesTo);
103 QFETCH(qint64, mediaDuration);
105 g_duration = mediaDuration;
106 g_currentPosition = startPosition;
108 mafw_gst_renderer_seeker_seek_to(m_seeker, seekTo);
109 QCOMPARE(g_seekRequested, seekTo);
111 qint64 newSeekPos = 0;
116 g_currentPosition = seekGoesTo.at(i);
117 newSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
119 if( newSeekPos == -1 )
124 QCOMPARE(newSeekPos, processedSeekRequests.at(i));
125 QCOMPARE(g_seekRequested, processedSeekRequests.at(i));
129 qint64 lastSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
130 QCOMPARE( lastSeekPos, -1ll);
131 QCOMPARE( g_seeksCalled, seekGoesTo.size());
134 void Ut_MafwGstRendererSeeker::testSeekFails_data()
136 QTest::addColumn<qint64>("startPosition");
137 QTest::addColumn<qint64>("seekTo");
138 QTest::addColumn<QList<qint64> >("processedSeekRequests");
139 QTest::addColumn<QList<qint64> >("seekGoesTo");
140 QTest::addColumn<qint64>("mediaDuration");
142 QTest::newRow("Second seek is close enough")
143 << 0ll // position where seeking start
144 << 20ll // the seek request
145 << (QList<qint64>() << 30 ) // list of processed seek request affected by the seekGoesTo list
146 << (QList<qint64>() << 1 << 31 ) // list of resulting seeks to gst_element_seek()
147 << 35ll; //affects when seek processing should stop
149 QTest::newRow("Fourth seek forward required")
150 << 5ll // position where seeking start
151 << 20ll // the seek request
152 << (QList<qint64>() << 30 << 40 << 50 ) // list of processed seek request affected by the seekGoesTo list
153 << (QList<qint64>() << 1 << 2 << 6 << 15 ) // list of resulting positions after calling gst_element_seek()
154 << 70ll; //affects when seek processing should stop
156 // backward seeks assume that key_frame seeks will always seek at least to the requested position most likely earlier
157 // such backward seeks that would not reach at least the required position succeed anyway
158 QTest::newRow("backward seek fails")
159 << 20ll // position where seeking start
160 << 10ll // the seek request
161 << (QList<qint64>() ) // list of processed seek request affected by the seekGoesTo list
162 << (QList<qint64>() << 0 ) // list of resulting positions after calling gst_element_seek()
163 << 70ll; //affects when seek processing should stop
165 QTest::newRow("backward seek fails 2")
166 << 20ll // position where seeking start
167 << 10ll // the seek request
168 << (QList<qint64>() ) // list of processed seek request affected by the seekGoesTo list
169 << (QList<qint64>() << 15 ) // list of resulting positions after calling gst_element_seek()
170 << 70ll; //affects when seek processing should stop
172 QTest::newRow("Seek over media duration cancelled when processing")
173 << 5ll // position where seeking start
174 << 20ll // the seek request
175 << (QList<qint64>()) // list of processed seek request affected by the seekGoesTo list
176 << (QList<qint64>() << 5 ) // list of resulting positions after calling gst_element_seek()
177 << 25ll; //affects when seek processing should stop
179 QTest::newRow("Test accuracy, first fails just by an inch")
180 << 5ll // position where seeking start
181 << 20ll // the seek request
182 << (QList<qint64>() << 30) // list of processed seek request affected by the seekGoesTo list
183 << (QList<qint64>() << 6 << 7) // list of resulting positions after calling gst_element_seek()
184 << 35ll; //affects when seek processing should stop
186 QTest::newRow("Test accuracy 1, first fails just by an inch")
187 << 5ll // position where seeking start
188 << 20ll // the seek request
189 << (QList<qint64>() << 30) // list of processed seek request affected by the seekGoesTo list
190 << (QList<qint64>() << 6 << 7) // list of resulting seeks to gst_element_seek()
191 << 35ll; //affects when seek processing should stop
196 QTEST_MAIN(Ut_MafwGstRendererSeeker)