• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 namespace {
22     [[maybe_unused]] constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "GstUtils"};
23 }
24 
25 namespace OHOS {
26 namespace Media {
MatchElementByMeta(const GstElement & elem,const std::string_view & metaKey,const std::vector<std::string_view> & expectedMetaFields)27 bool MatchElementByMeta(
28     const GstElement &elem, const std::string_view &metaKey, const std::vector<std::string_view> &expectedMetaFields)
29 {
30     const gchar *metadata = gst_element_get_metadata(const_cast<GstElement *>(&elem), metaKey.data());
31     CHECK_AND_RETURN_RET_LOG(metadata != nullptr, false, "failed to gst_element_get_metadata");
32 
33     std::vector<std::string> klassDesc;
34     SplitStr(metadata, "/", klassDesc, false, true);
35 
36     size_t matchCnt = 0;
37     for (auto &expectedField : expectedMetaFields) {
38         for (auto &item : klassDesc) {
39             if (item.compare(expectedField) == 0) {
40                 matchCnt += 1;
41                 break;
42             }
43         }
44     }
45 
46     return matchCnt == expectedMetaFields.size();
47 }
48 } // namespace Media
49 } // namespace OHOS