• 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 #include "image_receiver_manager.h"
16 namespace OHOS {
17 namespace Media {
18 using namespace OHOS::HiviewDFX;
19 using namespace std;
SaveImageReceiver(shared_ptr<ImageReceiver> imageReceiver)20 string ImageReceiverManager::SaveImageReceiver(shared_ptr<ImageReceiver> imageReceiver)
21 {
22     string id = "1";
23 
24     if (getImageReceiverByKeyId(id) != nullptr) {
25         mapReceiver_.erase(id);
26     }
27 
28     mapReceiver_.insert(pair<string, shared_ptr<ImageReceiver>>(id, imageReceiver));
29     return id;
30 }
getSurfaceByKeyId(string keyId)31 sptr<Surface> ImageReceiverManager::getSurfaceByKeyId(string keyId)
32 {
33     map<string, shared_ptr<ImageReceiver>>::iterator iter;
34     shared_ptr<ImageReceiver> imageReceiver = nullptr;
35     iter = mapReceiver_.find(keyId);
36     if (iter != mapReceiver_.end()) {
37         imageReceiver = iter->second;
38     }
39     return imageReceiver->GetReceiverSurface();
40 }
getImageReceiverByKeyId(string keyId)41 shared_ptr<ImageReceiver> ImageReceiverManager::getImageReceiverByKeyId(string keyId)
42 {
43     map<string, shared_ptr<ImageReceiver>>::iterator iter;
44     shared_ptr<ImageReceiver> imageReceiver = nullptr;
45     iter = mapReceiver_.find(keyId);
46     if (iter != mapReceiver_.end()) {
47         imageReceiver = iter->second;
48     }
49     return imageReceiver;
50 }
51 } // namespace Media
52 } // namespace OHOS
53