• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
29     : CaptureSessionForSys(captureSession) {}
30 
CanAddOutput(sptr<CaptureOutput> & output)31 bool ApertureVideoSession::CanAddOutput(sptr<CaptureOutput>& output)
32 {
33     MEDIA_DEBUG_LOG("Enter Into ApertureVideoSession::CanAddOutput");
34     CHECK_RETURN_RET_ELOG(!IsSessionConfiged() || output == nullptr, false,
35         "ApertureVideoSession::CanAddOutput operation is not allowed!");
36     CHECK_RETURN_RET_ELOG(output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO, false,
37         "ApertureVideoSession::CanAddOutput add photo output is not allowed!");
38     return CaptureSession::CanAddOutput(output);
39 }
40 
CommitConfig()41 int32_t ApertureVideoSession::CommitConfig()
42 {
43     int32_t ret = CaptureSession::CommitConfig();
44     CHECK_RETURN_RET(ret != CameraErrorCode::SUCCESS, ret);
45 
46     auto ability = GetMetadata();
47     auto item = GetMetadataItem(ability->get(), OHOS_ABILITY_VIDEO_STABILIZATION_MODES);
48     // Not support stabilization, return success.
49     CHECK_RETURN_RET(item == nullptr || item->count == 0, CameraErrorCode::SUCCESS);
50     bool isSupportAuto = false;
51     for (uint32_t i = 0; i < item->count; i++) {
52         if (static_cast<camera_video_stabilization_mode>(item->data.u8[i]) == OHOS_CAMERA_VIDEO_STABILIZATION_AUTO) {
53             isSupportAuto = true;
54         }
55     }
56     // Not support OHOS_CONTROL_VIDEO_STABILIZATION_MODE, return success.
57     CHECK_RETURN_RET(!isSupportAuto, CameraErrorCode::SUCCESS);
58 
59     bool updateStabilizationAutoResult = false;
60     LockForControl();
61     uint8_t autoStabilization = OHOS_CAMERA_VIDEO_STABILIZATION_AUTO;
62     updateStabilizationAutoResult =
63         AddOrUpdateMetadata(changedMetadata_->get(), OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &autoStabilization, 1);
64     UnlockForControl();
65     CHECK_RETURN_RET_ELOG(!updateStabilizationAutoResult, CameraErrorCode::SERVICE_FATL_ERROR,
66         "ApertureVideoSession::CommitConfig add STABILIZATION fail");
67         return CameraErrorCode::SUCCESS;
68 }
69 } // namespace CameraStandard
70 } // namespace OHOS