1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "gst_utils.h"
17 #include "string_ex.h"
18 #include "media_errors.h"
19 #include "media_log.h"
20 #include "time_perf.h"
21
22 namespace {
23 [[maybe_unused]] constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "GstUtils"};
24 }
25
26 namespace OHOS {
27 namespace Media {
MatchElementByMeta(const GstElement & elem,const std::string_view & metaKey,const std::vector<std::string_view> & expectedMetaFields)28 bool MatchElementByMeta(
29 const GstElement &elem, const std::string_view &metaKey, const std::vector<std::string_view> &expectedMetaFields)
30 {
31 const gchar *metadata = gst_element_get_metadata(const_cast<GstElement *>(&elem), metaKey.data());
32 if (metadata == nullptr) {
33 return false;
34 }
35
36 std::vector<std::string> klassDesc;
37 SplitStr(metadata, "/", klassDesc, false, true);
38
39 size_t matchCnt = 0;
40 for (auto &expectedField : expectedMetaFields) {
41 for (auto &item : klassDesc) {
42 if (item.compare(expectedField) == 0) {
43 matchCnt += 1;
44 break;
45 }
46 }
47 }
48
49 return matchCnt == expectedMetaFields.size();
50 }
51 } // namespace Media
52 } // namespace OHOS