1 /*
2  * Copyright (c) 2023 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  *     http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software
8  * distributed under the License is distributed on an "AS IS" BASIS,
9  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  * See the License for the specific language governing permissions and
11  * limitations under the License.
12  */
13 
14 #ifndef HOS_CAMERA_RKCODEC_NODE_H
15 #define HOS_CAMERA_RKCODEC_NODE_H
16 
17 #include <vector>
18 #include <condition_variable>
19 #include <ctime>
20 #include "device_manager_adapter.h"
21 #include "utils.h"
22 #include "camera.h"
23 #include "source_node.h"
24 #include "node_utils.h"
25 
26 namespace OHOS::Camera {
27 class CodecNode : public NodeBase {
28 public:
29     CodecNode(const std::string& name, const std::string& type, const std::string &cameraId);
30     ~CodecNode() override;
31     RetCode Start(const int32_t streamId) override;
32     RetCode Stop(const int32_t streamId) override;
33     void DeliverBuffer(std::shared_ptr<IBuffer>& buffer) override;
34     virtual RetCode Capture(const int32_t streamId, const int32_t captureId) override;
35     RetCode CancelCapture(const int32_t streamId) override;
36     RetCode Flush(const int32_t streamId);
37     RetCode ConfigJpegOrientation(common_metadata_header_t* data);
38     RetCode ConfigJpegQuality(common_metadata_header_t* data);
39     RetCode Config(const int32_t streamId, const CaptureMeta& meta) override;
40 private:
41     struct JpegData {
42         int width;
43         int height;
44     };
45     void EncodeJpegToMemory(uint8_t* image, JpegData jpegData,
46             const char* comment, unsigned long* jpegSize, uint8_t** jpegBuf);
47 
48     void Yuv422ToJpeg(std::shared_ptr<IBuffer>& buffer);
49 
50     uint32_t jpegRotation_;
51     uint32_t jpegQuality_;
52 };
53 } // namespace OHOS::Camera
54 #endif
55