blob: edfc9beb9a964d2f1a09bb4e2abc772e2ed3e097 [file] [log] [blame]
Songyue Han130053e2024-04-25 22:04:38 +00001/*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "CodecCapabilitiesUtils"
19#include <utils/Log.h>
20
21#include <algorithm>
22#include <cmath>
Songyue Han73d6d112024-06-05 17:39:06 +000023#include <regex>
Songyue Han130053e2024-04-25 22:04:38 +000024#include <string>
25#include <vector>
26
27#include <media/CodecCapabilitiesUtils.h>
28
29#include <media/stagefright/foundation/AUtils.h>
30
31namespace android {
32
Songyue Han73d6d112024-06-05 17:39:06 +000033std::optional<Range<int>> ParseIntRange(const std::string &str) {
34 if (str.empty()) {
35 ALOGW("could not parse empty integer range");
36 return std::nullopt;
37 }
38 int lower, upper;
39 std::regex regex("([0-9]+)-([0-9]+)");
40 std::smatch match;
41 if (std::regex_match(str, match, regex)) {
42 lower = std::atoi(match[1].str().c_str());
43 upper = std::atoi(match[2].str().c_str());
44 } else if (std::atoi(str.c_str()) != 0) {
45 lower = upper = std::atoi(str.c_str());
46 } else {
47 ALOGW("could not parse integer range: %s", str.c_str());
48 return std::nullopt;
49 }
50 return std::make_optional<Range<int>>(lower, upper);
51}
52
Songyue Han130053e2024-04-25 22:04:38 +000053} // namespace android