• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "dcamera_session_callback.h"
17 
18 #include "dcamera_event_cmd.h"
19 #include "dcamera_utils_tools.h"
20 #include "distributed_camera_constants.h"
21 #include "distributed_hardware_log.h"
22 #include "metadata_utils.h"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
DCameraSessionCallback(const std::shared_ptr<StateCallback> & callback)26 DCameraSessionCallback::DCameraSessionCallback(const std::shared_ptr<StateCallback>& callback) : callback_(callback)
27 {
28 }
29 
OnError(int32_t errorCode)30 void DCameraSessionCallback::OnError(int32_t errorCode)
31 {
32     DHLOGE("DCameraSessionCallback::OnError, errorCode: %d", errorCode);
33     if (callback_ == nullptr) {
34         DHLOGE("DCameraSessionCallback::OnError StateCallback is null");
35         return;
36     }
37 
38     std::shared_ptr<DCameraEvent> event = std::make_shared<DCameraEvent>();
39     event->eventType_ = DCAMERA_MESSAGE;
40     event->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR;
41     callback_->OnStateChanged(event);
42 }
43 
OnFocusState(FocusState state)44 void DCameraSessionCallback::OnFocusState(FocusState state)
45 {
46     DHLOGI("DCameraSessionCallback::OnFocusState, state: %d", state);
47     if (callback_ == nullptr) {
48         DHLOGE("DCameraSessionCallback::OnFocusState StateCallback is null");
49         return;
50     }
51 
52     auto iter = focusStateMap_.find(state);
53     if (iter == focusStateMap_.end()) {
54         DHLOGE("DCameraSessionCallback::OnFocusState focusStateMap find %d state failed", state);
55         return;
56     }
57 
58     int32_t itemCapacity = 10;
59     int32_t dataCapacity = 100;
60     int32_t dataCount = 1;
61     uint8_t focusState = iter->second;
62     std::shared_ptr<Camera::CameraMetadata> cameraMetadata =
63         std::make_shared<Camera::CameraMetadata>(itemCapacity, dataCapacity);
64     if (!cameraMetadata->addEntry(OHOS_CONTROL_FOCUS_STATE, &focusState, dataCount)) {
65         DHLOGE("DCameraSessionCallback::OnFocusState cameraMetadata add entry failed");
66         return;
67     }
68 
69     std::string abilityString = Camera::MetadataUtils::EncodeToString(cameraMetadata);
70     std::string encodeString = Base64Encode(reinterpret_cast<const unsigned char *>(abilityString.c_str()),
71         abilityString.length());
72 
73     std::shared_ptr<DCameraSettings> dcSetting = std::make_shared<DCameraSettings>();
74     dcSetting->type_ = DCSettingsType::METADATA_RESULT;
75     dcSetting->value_ = encodeString;
76     std::vector<std::shared_ptr<DCameraSettings>> settings;
77     settings.push_back(dcSetting);
78 }
79 } // namespace DistributedHardware
80 } // namespace OHOS