Пример #1
0
void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval)
{
    // Handle normalized intervals only
    if(!interval.isNormal())
        return;

    for (int i = 0; i < intervals.count(); i++) {
        QMediaTimeInterval r = intervals[i];

        if (r.e < interval.s) {
            // Before the removal interval
            continue;
        } else if (interval.e < r.s) {
            // After the removal interval - stop here
            break;
        } else if (r.s < interval.s && interval.e < r.e) {
            // Split case - a single range has a chunk removed
            intervals[i].e = interval.s -1;
            addInterval(QMediaTimeInterval(interval.e + 1, r.e));
            break;
        } else if (r.s < interval.s) {
            // Trimming Tail Case
            intervals[i].e = interval.s - 1;
        } else if (interval.e < r.e) {
            // Trimming Head Case - we can stop after this
            intervals[i].s = interval.e + 1;
            break;
        } else {
            // Complete coverage case
            intervals.removeAt(i);
            --i;
        }
    }
}
Пример #2
0
void QMediaTimeRangePrivate::addInterval(const QMediaTimeInterval &interval)
{
    // Handle normalized intervals only
    if(!interval.isNormal())
        return;

    // Find a place to insert the interval
    int i;
    for (i = 0; i < intervals.count(); i++) {
        // Insert before this element
        if(interval.s < intervals[i].s) {
            intervals.insert(i, interval);
            break;
        }
    }

    // Interval needs to be added to the end of the list
    if (i == intervals.count())
        intervals.append(interval);

    // Do we need to correct the element before us?
    if(i > 0 && intervals[i - 1].e >= interval.s - 1)
        i--;

    // Merge trailing ranges
    while (i < intervals.count() - 1
          && intervals[i].e >= intervals[i + 1].s - 1) {
        intervals[i].e = qMax(intervals[i].e, intervals[i + 1].e);
        intervals.removeAt(i + 1);
    }
}
void tst_QMediaTimeRange::testIntervalNormalize()
{
    QMediaTimeInterval x(20, 10);

    QVERIFY(!x.isNormal());
    QVERIFY(x.start() == 20);
    QVERIFY(x.end() == 10);

    QMediaTimeInterval y = x.normalized();

    QVERIFY(y.isNormal());
    QVERIFY(y.start() == 10);
    QVERIFY(y.end() == 20);
    QVERIFY(x != y);
}
void tst_QMediaTimeRange::testIntervalCtor()
{
    //Default Ctor for Time Interval
    /* create an instance for the time interval and verify the default cases */
    QMediaTimeInterval tInter;
    QVERIFY(tInter.isNormal());
    QVERIFY(tInter.start() == 0);
    QVERIFY(tInter.end() == 0);

    // (qint, qint) Ctor time interval
    /* create an instace of QMediaTimeInterval passing start and end times and verify the all possible scenario's*/
    QMediaTimeInterval time(20,50);
    QVERIFY(time.isNormal());
    QVERIFY(time.start() == 20);
    QVERIFY(time.end() == 50);

    // Copy Ctor Time interval
    QMediaTimeInterval other(time);
    QVERIFY(other.isNormal() == time.isNormal());
    QVERIFY(other.start() == time.start());
    QVERIFY(other.end() == time.end());
    QVERIFY(other.contains(20) == time.contains(20));
    QVERIFY(other == time);
}
Пример #5
0
QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeInterval &interval)
    : QSharedData()
{
    if(interval.isNormal())
        intervals << interval;
}