1 /*
2  * Copyright (c) 2024-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 "session/aperture_video_session.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "camera_device_ability_items.h"
22 #include "camera_log.h"
23 #include "capture_session.h"
24 #include "metadata_common_utils.h"
25 
26 namespace OHOS {
27 namespace CameraStandard {
ApertureVideoSession(sptr<ICaptureSession> & captureSession)28 ApertureVideoSession::ApertureVideoSession(sptr<ICaptureSession>& captureSession) : CaptureSession(captureSession) {}
29 
CanAddOutput(sptr<CaptureOutput> & output)30 bool ApertureVideoSession::CanAddOutput(sptr<CaptureOutput>& output)
31 {
32     MEDIA_DEBUG_LOG("Enter Into ApertureVideoSession::CanAddOutput");
33     CHECK_ERROR_RETURN_RET_LOG(!IsSessionConfiged() || output == nullptr, false,
34         "ApertureVideoSession::CanAddOutput operation is not allowed!");
35     CHECK_ERROR_RETURN_RET_LOG(output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO, false,
36         "ApertureVideoSession::CanAddOutput add photo output is not allowed!");
37     return CaptureSession::CanAddOutput(output);
38 }
39 
CommitConfig()40 int32_t ApertureVideoSession::CommitConfig()
41 {
42     int32_t ret = CaptureSession::CommitConfig();
43     CHECK_ERROR_RETURN_RET(ret != CameraErrorCode::SUCCESS, ret);
44 
45     auto ability = GetMetadata();
46     auto item = GetMetadataItem(ability->get(), OHOS_ABILITY_VIDEO_STABILIZATION_MODES);
47     // Not support stabilization, return success.
48     CHECK_ERROR_RETURN_RET(item == nullptr || item->count == 0, CameraErrorCode::SUCCESS);
49     bool isSupportAuto = false;
50     for (uint32_t i = 0; i < item->count; i++) {
51         if (static_cast<camera_video_stabilization_mode>(item->data.u8[i]) == OHOS_CAMERA_VIDEO_STABILIZATION_AUTO) {
52             isSupportAuto = true;
53         }
54     }
55     // Not support OHOS_CONTROL_VIDEO_STABILIZATION_MODE, return success.
56     CHECK_ERROR_RETURN_RET(!isSupportAuto, CameraErrorCode::SUCCESS);
57 
58     bool updateStabilizationAutoResult = false;
59     LockForControl();
60     uint8_t autoStabilization = OHOS_CAMERA_VIDEO_STABILIZATION_AUTO;
61     updateStabilizationAutoResult =
62         AddOrUpdateMetadata(changedMetadata_->get(), OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &autoStabilization, 1);
63     UnlockForControl();
64     CHECK_ERROR_RETURN_RET_LOG(!updateStabilizationAutoResult, CameraErrorCode::SERVICE_FATL_ERROR,
65         "ApertureVideoSession::CommitConfig add STABILIZATION fail");
66     return CameraErrorCode::SUCCESS;
67 }
68 } // namespace CameraStandard
69 } // namespace OHOS