1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong DID 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 #ifndef HDI_JPEG_DECODER_H 16 #define HDI_JPEG_DECODER_H 17 #include <atomic> 18 #include <cinttypes> 19 #include <codec_jpeg_vdi.h> 20 #include <memory> 21 #include <mutex> 22 #include <thread> 23 #include <vector> 24 #include "hdi_mpp_mpi.h" 25 namespace OHOS { 26 namespace VDI { 27 namespace JPEG { 28 class CodecJpegDecoder { 29 public: 30 explicit CodecJpegDecoder(); 31 32 ~CodecJpegDecoder(); 33 34 int32_t Init(); 35 36 void DeInit(); 37 38 int32_t DeCode(BufferHandle *buffer, BufferHandle *outBuffer, const struct CodecJpegDecInfo &decInfo, 39 CodecJpegCallbackHwi *callback); 40 41 private: 42 void ResetMppBuffer(); 43 44 bool PrePare(bool isDecoder = true); 45 AlignUp(uint32_t val,uint32_t align)46 inline uint32_t AlignUp(uint32_t val, uint32_t align) 47 { 48 return (val + align - 1) & (~(align - 1)); 49 } 50 OnEvent(int32_t result)51 inline void OnEvent(int32_t result) 52 { 53 std::lock_guard<std::mutex> lk(mutex_); 54 if (callback_ && callback_->OnEvent) { 55 callback_->OnEvent(result); 56 } 57 } 58 59 MPP_RET SendData(const struct CodecJpegDecInfo &decInfo, int32_t fd, BufferHandle *outHandle); 60 61 MPP_RET InitPacketBuffer(const struct CodecJpegDecInfo &decInfo, int32_t fd, MppBuffer &pktBuf); 62 63 MPP_RET MppTaskProcess(); 64 65 MPP_RET GetFrame(); 66 67 void DumpOutFile(); 68 69 void DumpInFile(char *data, int32_t size); 70 71 bool SetFormat(int32_t format); 72 73 private: 74 uint32_t width_; 75 uint32_t height_; 76 MppFrameFormat format_; 77 MppCtx mppCtx_; 78 MppApi *mpi_; 79 static RKMppApi *mppApi_; 80 MppBufferGroup memGroup_; 81 MppPacket packet_; 82 MppFrame frame_; 83 CodecJpegCallbackHwi *callback_; 84 std::atomic<bool> running_; 85 std::mutex mutex_; 86 std::shared_ptr<std::thread> threadTask_; 87 }; 88 } // namespace JPEG 89 } // namespace VDI 90 } // namespace OHOS 91 #endif // HDI_JPEG_DECODER_H 92