1 /*
2 * Copyright (c) 2021-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 "filter_factory.h"
17
18 namespace OHOS {
19 namespace Media {
Instance()20 FilterFactory& FilterFactory::Instance()
21 {
22 static FilterFactory instance;
23 return instance;
24 }
25
Init()26 void FilterFactory::Init()
27 {
28 }
29
RegisterGenerator(const std::string & name,const InstanceGenerator & generator)30 void FilterFactory::RegisterGenerator(const std::string& name, const InstanceGenerator& generator)
31 {
32 auto result = generators.emplace(name, generator);
33 if (!result.second) {
34 result.first->second = generator;
35 }
36 }
37
CreateFilter(const std::string & filterName,const std::string & aliasName)38 std::shared_ptr<Pipeline::Filter> FilterFactory::CreateFilter(const std::string& filterName,
39 const std::string& aliasName)
40 {
41 auto it = generators.find(filterName);
42 if (it != generators.end()) {
43 return it->second(aliasName);
44 }
45 return nullptr;
46 }
47 } // namespace Media
48 } // namespace OHOS
49