1 /*
2 * Copyright (C) 2024 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 "media_log.h"
17 #include "data_center/effect/effect.h"
18 #include "data_center/effect/effect_factory.h"
19 #include "data_center/effect/effect_image_effect.h"
20
21 namespace OHOS {
22 namespace Media {
23
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_VIDEOEDITOR, "DataCenter"};
26 }
27
28 std::atomic<uint64_t> EffectFactory::id_ = 1;
29
CreateEffect(const std::string & description)30 std::shared_ptr<Effect> EffectFactory::CreateEffect(const std::string& description)
31 {
32 EffectType type = ParseEffectType(description);
33 std::shared_ptr<Effect> result = nullptr;
34 switch (type) {
35 case EffectType::IMAGE_EFFECT: {
36 auto effect = std::make_shared<EffectImageEffect>(id_.fetch_add(1), description);
37 auto err = effect->Init();
38 if (err != VEFError::ERR_OK) {
39 MEDIA_LOGE("init effect[%{public}" PRIu64 "] failed, error: %{public}d",
40 effect->GetId(), err);
41 } else {
42 result = effect;
43 MEDIA_LOGI("init effect[%{public}" PRIu64 "] success.", effect->GetId());
44 }
45 }
46 break;
47 default:
48 MEDIA_LOGE("unsupported effect type: %{public}u", type);
49 break;
50 }
51 return result;
52 }
53
ParseEffectType(const std::string & description)54 EffectType EffectFactory::ParseEffectType(const std::string& description)
55 {
56 if (description.empty()) {
57 MEDIA_LOGE("effect desc is empty.");
58 return EffectType::UNKNOWN;
59 }
60 // currently, only IMAGE_EFFECT is supported.
61 return EffectType::IMAGE_EFFECT;
62 }
63
64 } // namespace Media
65 } // namespace OHOS