1 /* 2 * Copyright (c) 2021 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 <mutex> 21 #include "device_manager_adapter.h" 22 #include "utils.h" 23 #include "camera.h" 24 #include "source_node.h" 25 #include "RockchipRga.h" 26 #include "RgaUtils.h" 27 #include "RgaApi.h" 28 #include "rk_mpi.h" 29 #include "mpp_env.h" 30 #include "mpp_mem.h" 31 #include "mpp_log.h" 32 #include "mpp_common.h" 33 extern "C" { 34 #include "mpi_enc_utils.h" 35 } 36 37 38 namespace OHOS::Camera { 39 class RKCodecNode : public NodeBase { 40 public: 41 RKCodecNode(const std::string& name, const std::string& type, const std::string &cameraId); 42 ~RKCodecNode() override; 43 RetCode Start(const int32_t streamId) override; 44 RetCode Stop(const int32_t streamId) override; 45 void DeliverBuffer(std::shared_ptr<IBuffer>& buffer) override; 46 virtual RetCode Capture(const int32_t streamId, const int32_t captureId) override; 47 RetCode CancelCapture(const int32_t streamId) override; 48 RetCode Flush(const int32_t streamId); 49 RetCode ConfigJpegOrientation(common_metadata_header_t* data); 50 RetCode ConfigJpegQuality(common_metadata_header_t* data); 51 RetCode Config(const int32_t streamId, const CaptureMeta& meta) override; 52 private: 53 void encodeJpegToMemory(unsigned char* image, int width, int height, 54 const char* comment, unsigned long* jpegSize, unsigned char** jpegBuf); 55 int findStartCode(unsigned char *data, size_t dataSz); 56 void SerchIFps(unsigned char* buf, size_t bufSize, std::shared_ptr<IBuffer>& buffer); 57 void Yuv420ToRGBA8888(std::shared_ptr<IBuffer>& buffer); 58 void Yuv420ToJpeg(std::shared_ptr<IBuffer>& buffer); 59 void Yuv420ToH264(std::shared_ptr<IBuffer>& buffer); 60 61 static uint32_t previewWidth_; 62 static uint32_t previewHeight_; 63 void* halCtx_ = nullptr; 64 int mppStatus_ = 0; 65 uint32_t jpegRotation_; 66 uint32_t jpegQuality_; 67 std::mutex hal_mpp; 68 }; 69 } // namespace OHOS::Camera 70 #endif 71