• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "image_creator_manager.h"
17 namespace OHOS {
18 namespace Media {
19 using namespace OHOS::HiviewDFX;
20 using namespace std;
SaveImageCreator(shared_ptr<ImageCreator> imageCreator)21 string ImageCreatorManager::SaveImageCreator(shared_ptr<ImageCreator> imageCreator)
22 {
23     string id = "1";
24 
25     if (GetImageCreatorByKeyId(id) != nullptr) {
26         mapCreator_.erase(id);
27     }
28 
29     mapCreator_.insert(pair<string, shared_ptr<ImageCreator>>(id, imageCreator));
30     return id;
31 }
GetSurfaceByKeyId(string keyId)32 sptr<Surface> ImageCreatorManager::GetSurfaceByKeyId(string keyId)
33 {
34     map<string, shared_ptr<ImageCreator>>::iterator iter;
35     shared_ptr<ImageCreator> imageCreator = nullptr;
36     iter = mapCreator_.find(keyId);
37     if (iter != mapCreator_.end()) {
38         imageCreator = iter->second;
39     }
40     if (imageCreator == nullptr) {
41         return nullptr;
42     }
43     return imageCreator->GetCreatorSurface();
44 }
GetImageCreatorByKeyId(string keyId)45 shared_ptr<ImageCreator> ImageCreatorManager::GetImageCreatorByKeyId(string keyId)
46 {
47     map<string, shared_ptr<ImageCreator>>::iterator iter;
48     shared_ptr<ImageCreator> imageCreator = nullptr;
49     iter = mapCreator_.find(keyId);
50     if (iter != mapCreator_.end()) {
51         imageCreator = iter->second;
52     }
53     return imageCreator;
54 }
55 } // namespace Media
56 } // namespace OHOS
57