Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e79f70eb authored by Songyue Han's avatar Songyue Han Committed by Automerger Merge Worker
Browse files

Merge "Native CodecCapabilities: Check if newly created ranges are valid." into main am: 30be0ba9

parents fbf1b7a8 30be0ba9
Loading
Loading
Loading
Loading
+26 −8
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedWidthsFor(int32_t h
        ALOGE("unsupported height");
        return std::nullopt;
    }
    const int32_t heightInBlocks = divUp(height, mBlockHeight);

    const int32_t heightInBlocks = divUp(height, mBlockHeight);
    // constrain by block count and by block aspect ratio
    const int32_t minWidthInBlocks = std::max(
            divUp(mBlockCountRange.lower(), heightInBlocks),
@@ -94,6 +94,10 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedWidthsFor(int32_t h
            (int32_t)std::ceil(mAspectRatioRange.lower().asDouble()
                    * height),
            (int32_t)(mAspectRatioRange.upper().asDouble() * height));
    if (range.empty()) {
        return std::nullopt;
    }

    return range;
}

@@ -104,8 +108,8 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedHeightsFor(int32_t
        ALOGE("unsupported width");
        return std::nullopt;
    }
    const int32_t widthInBlocks = divUp(width, mBlockWidth);

    const int32_t widthInBlocks = divUp(width, mBlockWidth);
    // constrain by block count and by block aspect ratio
    const int32_t minHeightInBlocks = std::max(
            divUp(mBlockCountRange.lower(), widthInBlocks),
@@ -129,6 +133,10 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedHeightsFor(int32_t
            (int32_t)std::ceil(width /
                    mAspectRatioRange.upper().asDouble()),
            (int32_t)(width / mAspectRatioRange.lower().asDouble()));
    if (range.empty()) {
        return std::nullopt;
    }

    return range;
}

@@ -142,12 +150,15 @@ std::optional<Range<double>> VideoCapabilities::getSupportedFrameRatesFor(

    const int32_t blockCount =
            divUp(width, mBlockWidth) * divUp(height, mBlockHeight);

    return std::make_optional(Range(
    Range<double> result = Range(
            std::max(mBlocksPerSecondRange.lower() / (double) blockCount,
                (double) mFrameRateRange.lower()),
            std::min(mBlocksPerSecondRange.upper() / (double) blockCount,
                (double) mFrameRateRange.upper())));
                (double) mFrameRateRange.upper()));
    if (result.empty()) {
        return std::nullopt;
    }
    return result;
}

int32_t VideoCapabilities::getBlockCount(int32_t width, int32_t height) const {
@@ -613,9 +624,16 @@ std::optional<std::pair<Range<int32_t>, Range<int32_t>>> VideoCapabilities
        return std::nullopt;
    }

    return std::make_optional(std::pair(
            Range(range.value().first.getWidth(), range.value().second.getWidth()),
            Range(range.value().first.getHeight(), range.value().second.getHeight())));
    Range<int32_t> widthRange
            = Range(range.value().first.getWidth(), range.value().second.getWidth());
    Range<int32_t> heightRange
            = Range(range.value().first.getHeight(), range.value().second.getHeight());
    if (widthRange.empty() || heightRange.empty()) {
        ALOGW("could not parse size range: %s", str.c_str());
        return std::nullopt;
    }

    return std::make_optional(std::pair(widthRange, heightRange));
}

// static
+3 −5
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ struct Range {
            Range<T> result = Range<T>(std::max(lower_, range.lower_),
                    std::min(upper_, range.upper_));
            if (result.empty()) {
                ALOGE("Failed to intersect 2 ranges as they are disjoint");
                ALOGV("Failed to intersect 2 ranges as they are disjoint");
            }
            return result;
        }
@@ -124,12 +124,10 @@ struct Range {
     * @param lower a non-{@code null} {@code T} reference
     * @param upper a non-{@code null} {@code T} reference
     * @return the intersection of this range and the other range
     *
     * @throws NullPointerException if {@code lower} or {@code upper} was {@code null}
     * @throws IllegalArgumentException if the ranges are disjoint.
     */
    Range<T> intersect(T lower, T upper) {
        return Range(std::max(lower_, lower), std::min(upper_, upper));
        Range<T> range = Range<T>(lower, upper);
        return this->intersect(range);
    }

    /**