• 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 "hstream_metadata.h"
17 
18 #include "camera_util.h"
19 #include "camera_log.h"
20 #include "metadata_utils.h"
21 
22 namespace OHOS {
23 namespace CameraStandard {
HStreamMetadata(sptr<OHOS::IBufferProducer> producer,int32_t format)24 HStreamMetadata::HStreamMetadata(sptr<OHOS::IBufferProducer> producer, int32_t format)
25     : HStreamCommon(StreamType::METADATA, producer, format, 0, 0)
26 {}
27 
~HStreamMetadata()28 HStreamMetadata::~HStreamMetadata()
29 {}
30 
LinkInput(sptr<IStreamOperator> streamOperator,std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility,int32_t streamId)31 int32_t HStreamMetadata::LinkInput(sptr<IStreamOperator> streamOperator,
32                                    std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility, int32_t streamId)
33 {
34     if (streamOperator == nullptr || cameraAbility == nullptr) {
35         MEDIA_ERR_LOG("HStreamMetadata::LinkInput streamOperator is null");
36         return CAMERA_INVALID_ARG;
37     }
38     streamId_ = streamId;
39     streamOperator_ = streamOperator;
40     cameraAbility_ = cameraAbility;
41     return CAMERA_OK;
42 }
43 
SetStreamInfo(StreamInfo & streamInfo)44 void HStreamMetadata::SetStreamInfo(StreamInfo &streamInfo)
45 {
46     HStreamCommon::SetStreamInfo(streamInfo);
47     streamInfo.intent_ = ANALYZE;
48 }
49 
Start()50 int32_t HStreamMetadata::Start()
51 {
52     CAMERA_SYNC_TRACE;
53 
54     if (streamOperator_ == nullptr) {
55         return CAMERA_INVALID_STATE;
56     }
57     if (curCaptureID_ != 0) {
58         MEDIA_ERR_LOG("HStreamMetadata::Start, Already started with captureID: %{public}d", curCaptureID_);
59         return CAMERA_INVALID_STATE;
60     }
61     int32_t ret = AllocateCaptureId(curCaptureID_);
62     if (ret != CAMERA_OK) {
63         MEDIA_ERR_LOG("HStreamMetadata::Start Failed to allocate a captureId");
64         return ret;
65     }
66     std::vector<uint8_t> ability;
67     OHOS::Camera::MetadataUtils::ConvertMetadataToVec(cameraAbility_, ability);
68     CaptureInfo captureInfo;
69     captureInfo.streamIds_ = {streamId_};
70     captureInfo.captureSetting_ = ability;
71     captureInfo.enableShutterCallback_ = false;
72     MEDIA_INFO_LOG("HStreamMetadata::Start Starting with capture ID: %{public}d", curCaptureID_);
73     CamRetCode rc = (CamRetCode)(streamOperator_->Capture(curCaptureID_, captureInfo, true));
74     if (rc != HDI::Camera::V1_0::NO_ERROR) {
75         ReleaseCaptureId(curCaptureID_);
76         curCaptureID_ = 0;
77         MEDIA_ERR_LOG("HStreamMetadata::Start Failed with error Code:%{public}d", rc);
78         ret = HdiToServiceError(rc);
79     }
80     return ret;
81 }
82 
Stop()83 int32_t HStreamMetadata::Stop()
84 {
85     CAMERA_SYNC_TRACE;
86 
87     if (streamOperator_ == nullptr) {
88         return CAMERA_INVALID_STATE;
89     }
90     if (curCaptureID_ == 0) {
91         MEDIA_ERR_LOG("HStreamMetadata::Stop, Stream not started yet");
92         return CAMERA_INVALID_STATE;
93     }
94     int32_t ret = CAMERA_OK;
95     CamRetCode rc = (CamRetCode)(streamOperator_->CancelCapture(curCaptureID_));
96     if (rc != HDI::Camera::V1_0::NO_ERROR) {
97         MEDIA_ERR_LOG("HStreamMetadata::Stop Failed with errorCode:%{public}d, curCaptureID_: %{public}d",
98                       rc, curCaptureID_);
99         ret = HdiToServiceError(rc);
100     }
101     ReleaseCaptureId(curCaptureID_);
102     curCaptureID_ = 0;
103     return ret;
104 }
105 
Release()106 int32_t HStreamMetadata::Release()
107 {
108     return HStreamCommon::Release();
109 }
110 
DumpStreamInfo(std::string & dumpString)111 void HStreamMetadata::DumpStreamInfo(std::string& dumpString)
112 {
113     dumpString += "metadata stream:\n";
114     HStreamCommon::DumpStreamInfo(dumpString);
115 }
116 } // namespace Standard
117 } // namespace OHOS
118