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