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 "effect.h"
17 #include "effect_log.h"
18
19 namespace OHOS {
20 namespace Media {
21 namespace Effect {
AddEFilter(const std::shared_ptr<EFilter> & efilter)22 void Effect::AddEFilter(const std::shared_ptr<EFilter> &efilter)
23 {
24 efilters_.emplace_back(efilter);
25 }
26
InsertEFilter(const std::shared_ptr<EFilter> & efilter,uint32_t index)27 ErrorCode Effect::InsertEFilter(const std::shared_ptr<EFilter> &efilter, uint32_t index)
28 {
29 if (index > static_cast<uint32_t>(efilters_.size())) {
30 EFFECT_LOGE("index is invalid! index=%{public}d, efilterSize=%{public}zu", index, efilters_.size());
31 return ErrorCode::ERR_INVALID_INDEX;
32 }
33 efilters_.emplace(efilters_.begin() + index, efilter);
34 return ErrorCode::SUCCESS;
35 }
36
RemoveEFilter(const std::shared_ptr<EFilter> & efilter)37 void Effect::RemoveEFilter(const std::shared_ptr<EFilter> &efilter)
38 {
39 for (auto it = efilters_.begin(); it != efilters_.end();) {
40 if (*it == efilter) {
41 it = efilters_.erase(it);
42 } else {
43 ++it;
44 }
45 }
46 }
47
RemoveEFilter(uint32_t index)48 ErrorCode Effect::RemoveEFilter(uint32_t index)
49 {
50 CHECK_AND_RETURN_RET_LOG(index < static_cast<uint32_t>(efilters_.size()), ErrorCode::ERR_INVALID_INDEX,
51 "RemoveEFilter: index is invalid! index=%{public}d, efilterSize=%{public}zu", index, efilters_.size());
52
53 efilters_.erase(efilters_.begin() + index);
54 return ErrorCode::SUCCESS;
55 }
56
ReplaceEFilter(const std::shared_ptr<EFilter> & efilter,uint32_t index)57 ErrorCode Effect::ReplaceEFilter(const std::shared_ptr<EFilter> &efilter, uint32_t index)
58 {
59 CHECK_AND_RETURN_RET_LOG(index < static_cast<uint32_t>(efilters_.size()), ErrorCode::ERR_INVALID_INDEX,
60 "ReplaceEFilter: index is invalid! index=%{public}d, efilterSize=%{public}zu", index, efilters_.size());
61 efilters_[index] = efilter;
62 return ErrorCode::SUCCESS;
63 }
64 } // namespace Effect
65 } // namespace Media
66 } // namespace OHOS