• 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_common.h"
17 
18 #include "camera_util.h"
19 #include "camera_log.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
HStreamCommon(StreamType streamType,sptr<OHOS::IBufferProducer> producer,int32_t format,int32_t width,int32_t height)23 HStreamCommon::HStreamCommon(StreamType streamType, sptr<OHOS::IBufferProducer> producer,
24                              int32_t format, int32_t width, int32_t height)
25 {
26     streamId_ = 0;
27     curCaptureID_ = 0;
28     isReleaseStream_ = false;
29     streamOperator_ = nullptr;
30     cameraAbility_ = nullptr;
31     producer_ = producer;
32     width_ = width;
33     height_ = height;
34     format_ = format;
35     streamType_ = streamType;
36 }
37 
~HStreamCommon()38 HStreamCommon::~HStreamCommon()
39 {}
40 
SetReleaseStream(bool isReleaseStream)41 int32_t HStreamCommon::SetReleaseStream(bool isReleaseStream)
42 {
43     isReleaseStream_ = isReleaseStream;
44     return CAMERA_OK;
45 }
46 
IsReleaseStream()47 bool HStreamCommon::IsReleaseStream()
48 {
49     return isReleaseStream_;
50 }
51 
GetStreamId()52 int32_t HStreamCommon::GetStreamId()
53 {
54     return streamId_;
55 }
56 
GetStreamType()57 StreamType HStreamCommon::GetStreamType()
58 {
59     return streamType_;
60 }
61 
LinkInput(sptr<IStreamOperator> streamOperator,std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility,int32_t streamId)62 int32_t HStreamCommon::LinkInput(sptr<IStreamOperator> streamOperator,
63                                  std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility, int32_t streamId)
64 {
65     if (streamOperator == nullptr || cameraAbility == nullptr) {
66         MEDIA_ERR_LOG("HStreamCommon::LinkInput streamOperator is null");
67         return CAMERA_INVALID_ARG;
68     }
69     if (!IsValidSize(cameraAbility, format_, width_, height_)) {
70         return CAMERA_INVALID_SESSION_CFG;
71     }
72     streamId_ = streamId;
73     streamOperator_ = streamOperator;
74     cameraAbility_ = cameraAbility;
75     return CAMERA_OK;
76 }
77 
SetStreamInfo(StreamInfo & streamInfo)78 void HStreamCommon::SetStreamInfo(StreamInfo &streamInfo)
79 {
80     int32_t pixelFormat = PIXEL_FMT_YCRCB_420_SP;
81     auto it = g_cameraToPixelFormat.find(format_);
82     if (it != g_cameraToPixelFormat.end()) {
83         pixelFormat = it->second;
84     } else {
85         MEDIA_ERR_LOG("HStreamCommon::SetStreamInfo find format error, pixelFormat use default format");
86     }
87     MEDIA_INFO_LOG("HStreamCommon::SetStreamInfo pixelFormat is %{public}d", pixelFormat);
88     streamInfo.streamId_ = streamId_;
89     streamInfo.width_ = width_;
90     streamInfo.height_ = height_;
91     streamInfo.format_ = pixelFormat;
92     streamInfo.minFrameDuration_ = 0;
93     streamInfo.tunneledMode_ = true;
94     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer_);
95     streamInfo.dataspace_ = CAMERA_COLOR_SPACE;
96 }
97 
Release()98 int32_t HStreamCommon::Release()
99 {
100     streamId_ = 0;
101     curCaptureID_ = 0;
102     streamOperator_ = nullptr;
103     cameraAbility_ = nullptr;
104     producer_ = nullptr;
105     return CAMERA_OK;
106 }
107 
DumpStreamInfo(std::string & dumpString)108 void HStreamCommon::DumpStreamInfo(std::string& dumpString)
109 {
110     StreamInfo curStreamInfo;
111     SetStreamInfo(curStreamInfo);
112     dumpString += "release status:[" + std::to_string(isReleaseStream_) + "]:\n";
113     dumpString += "stream info: \n";
114     std::string bufferProducerId = "    Buffer producer Id:[";
115     if (curStreamInfo.bufferQueue_ && curStreamInfo.bufferQueue_->producer_) {
116         bufferProducerId += std::to_string(curStreamInfo.bufferQueue_->producer_->GetUniqueId());
117     } else {
118         bufferProducerId += "empty";
119     }
120     dumpString += bufferProducerId;
121     dumpString += "]    stream Id:[" + std::to_string(curStreamInfo.streamId_);
122     std::map<int, std::string>::const_iterator iter =
123         g_cameraFormat.find(format_);
124     if (iter != g_cameraFormat.end()) {
125         dumpString += "]    format:[" + iter->second;
126     }
127     dumpString += "]    width:[" + std::to_string(curStreamInfo.width_);
128     dumpString += "]    height:[" + std::to_string(curStreamInfo.height_);
129     dumpString += "]    dataspace:[" + std::to_string(curStreamInfo.dataspace_);
130     dumpString += "]    StreamType:[" + std::to_string(curStreamInfo.intent_);
131     dumpString += "]    TunnelMode:[" + std::to_string(curStreamInfo.tunneledMode_);
132     dumpString += "]    Encoding Type:[" + std::to_string(curStreamInfo.encodeType_) + "]:\n";
133     if (curStreamInfo.bufferQueue_) {
134         delete curStreamInfo.bufferQueue_;
135     }
136 }
137 } // namespace CameraStandard
138 } // namespace OHOS
139