Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qmediatimerange.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/qdebug.h>
5
6#include "qmediatimerange.h"
7
9
106{
107public:
110
111 QList<QMediaTimeRange::Interval> intervals;
112
113 void addInterval(const QMediaTimeRange::Interval &interval);
114 void removeInterval(const QMediaTimeRange::Interval &interval);
115};
116
118
120{
121 if (interval.isNormal())
122 intervals << interval;
123}
124
126{
127 // Handle normalized intervals only
128 if (!interval.isNormal())
129 return;
130
131 // Find a place to insert the interval
132 int i;
133 for (i = 0; i < intervals.size(); i++) {
134 // Insert before this element
135 if(interval.s < intervals[i].s) {
136 intervals.insert(i, interval);
137 break;
138 }
139 }
140
141 // Interval needs to be added to the end of the list
142 if (i == intervals.size())
143 intervals.append(interval);
144
145 // Do we need to correct the element before us?
146 if (i > 0 && intervals[i - 1].e >= interval.s - 1)
147 i--;
148
149 // Merge trailing ranges
150 while (i < intervals.size() - 1
151 && intervals[i].e >= intervals[i + 1].s - 1) {
152 intervals[i].e = qMax(intervals[i].e, intervals[i + 1].e);
153 intervals.removeAt(i + 1);
154 }
155}
156
158{
159 // Handle normalized intervals only
160 if (!interval.isNormal())
161 return;
162
163 for (int i = 0; i < intervals.size(); i++) {
165
166 if (r.e < interval.s) {
167 // Before the removal interval
168 continue;
169 } else if (interval.e < r.s) {
170 // After the removal interval - stop here
171 break;
172 } else if (r.s < interval.s && interval.e < r.e) {
173 // Split case - a single range has a chunk removed
174 intervals[i].e = interval.s -1;
175 addInterval(QMediaTimeRange::Interval(interval.e + 1, r.e));
176 break;
177 } else if (r.s < interval.s) {
178 // Trimming Tail Case
179 intervals[i].e = interval.s - 1;
180 } else if (interval.e < r.e) {
181 // Trimming Head Case - we can stop after this
182 intervals[i].s = interval.e + 1;
183 break;
184 } else {
185 // Complete coverage case
187 --i;
188 }
189 }
190}
191
224
238
251
256
274
279
290{
291 d = new QMediaTimeRangePrivate(interval);
292 return *this;
293}
294
303{
304 if (!d->intervals.isEmpty())
305 return d->intervals[0].start();
306
307 return 0;
308}
309
318{
319 if (!d->intervals.isEmpty())
320 return d->intervals[d->intervals.size() - 1].end();
321
322 return 0;
323}
324
338
353{
354 detach();
355 d->addInterval(interval);
356}
357
364{
365 detach();
366 const auto intervals = range.intervals();
367 for (const Interval &i : intervals) {
368 d->addInterval(i);
369 }
370}
371
385
403{
404 detach();
405 d->removeInterval(interval);
406}
407
414{
415 detach();
416 const auto intervals = range.intervals();
417 for (const Interval &i : intervals) {
418 d->removeInterval(i);
419 }
420}
421
430
435{
436 addInterval(interval);
437 return *this;
438}
439
448
453{
454 removeInterval(interval);
455 return *this;
456}
457
466{
467 detach();
468 d->intervals.clear();
469}
470
475{
476 d.detach();
477}
478
484QList<QMediaTimeRange::Interval> QMediaTimeRange::intervals() const
485{
486 return d->intervals;
487}
488
497{
498 return d->intervals.isEmpty();
499}
500
508{
509 return (d->intervals.size() <= 1);
510}
511
518{
519 for (int i = 0; i < d->intervals.size(); i++) {
520 if (d->intervals[i].contains(time))
521 return true;
522
523 if (time < d->intervals[i].start())
524 break;
525 }
526
527 return false;
528}
529
556#ifndef QT_NO_DEBUG_STREAM
558{
559 QDebugStateSaver saver(dbg);
560 dbg.nospace();
561 dbg << "QMediaTimeRange::Interval( " << interval.start() << ", " << interval.end() << " )";
562 return dbg;
563}
564
566{
567 QDebugStateSaver saver(dbg);
568 dbg.nospace();
569 dbg << "QMediaTimeRange( ";
570 const auto intervals = range.intervals();
571 for (const auto &interval : intervals)
572 dbg << '(' << interval.start() << ", " << interval.end() << ") ";
573 dbg.space();
574 dbg << ')';
575 return dbg;
576}
577#endif
578
\inmodule QtCore
\inmodule QtCore
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
void removeAt(qsizetype i)
Definition qlist.h:590
iterator insert(qsizetype i, parameter_type t)
Definition qlist.h:488
iterator end()
Definition qlist.h:626
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
QList< QMediaTimeRange::Interval > intervals
void removeInterval(const QMediaTimeRange::Interval &interval)
QMediaTimeRangePrivate()=default
void addInterval(const QMediaTimeRange::Interval &interval)
The QMediaTimeRange class represents a set of zero or more disjoint time intervals.
QMediaTimeRange & operator=(const QMediaTimeRange &) noexcept
Takes a copy of the other time range and returns itself.
bool contains(qint64 time) const
Returns true if the specified time lies within the time range.
void removeInterval(qint64 start, qint64 end)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void removeTimeRange(const QMediaTimeRange &)
Removes each of the intervals in range from this time range.
qint64 earliestTime() const
Returns the earliest time within the time range.
qint64 latestTime() const
Returns the latest time within the time range.
QMediaTimeRange & operator-=(const QMediaTimeRange &)
Removes each interval in other from the time range and returns the result.
~QMediaTimeRange()
Destructor.
bool isContinuous() const
Returns true if the time range consists of a continuous interval.
void addTimeRange(const QMediaTimeRange &)
Adds each of the intervals in range to this time range.
bool isEmpty() const
Returns true if there are no intervals within the time range.
QMediaTimeRange & operator+=(const QMediaTimeRange &)
Adds each interval in other to the time range and returns the result.
QList< QMediaTimeRange::Interval > intervals() const
Returns the list of intervals covered by this time range.
void addInterval(qint64 start, qint64 end)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QMediaTimeRange()
Constructs an empty time range.
void clear()
Removes all intervals from the time range.
\inmodule QtCore
Definition qshareddata.h:19
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QMediaTimeRange::Interval &interval)
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLboolean r
[2]
GLuint GLuint end
GLsizei range
GLuint start
static const int Interval
#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
long long qint64
Definition qtypes.h:60
QSharedPointer< T > other(t)
[5]
bool contains(const AT &t) const noexcept
Definition qlist.h:45
The QMediaTimeRange::Interval class represents a time interval with integer precision.
constexpr qint64 end() const noexcept
Returns the end time of the interval.
constexpr bool isNormal() const noexcept
Returns true if this time interval is normal.
constexpr qint64 start() const noexcept
Returns the start time of the interval.