1 /* 2 * Copyright (c) 2024 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 #ifndef IMAGE_RECEIVER_IMPL_H 16 #define IMAGE_RECEIVER_IMPL_H 17 18 #include "cj_image_utils.h" 19 #include "ffi_remote_data.h" 20 #include "image_impl.h" 21 #include "image_receiver.h" 22 #include "image_receiver_manager.h" 23 24 namespace OHOS { 25 namespace Media { 26 class ImageReceiverImpl : public OHOS::FFI::FFIData { 27 DECL_TYPE(ImageReceiverImpl, OHOS::FFI::FFIData) 28 public: 29 explicit ImageReceiverImpl(std::shared_ptr<ImageReceiver> imageReceiver); 30 static int64_t CreateImageReceiver(int32_t width, int32_t height, int32_t format, int32_t capacity); 31 uint32_t GetSize(CSize* ret); 32 uint32_t GetCapacity(int32_t* ret); 33 uint32_t GetFormat(int32_t* ret); 34 char* GetReceivingSurfaceId(); 35 sptr<ImageImpl> ReadNextImage(); 36 sptr<ImageImpl> ReadLatestImage(); 37 void Release(); 38 uint32_t CjOn(std::string name, std::function<void()> callBack); 39 40 private: 41 std::shared_ptr<ImageReceiver> imageReceiver_; 42 }; 43 44 class CjImageReceiverAvaliableListener : public SurfaceBufferAvaliableListener { 45 public: ~CjImageReceiverAvaliableListener()46 ~CjImageReceiverAvaliableListener() override 47 { 48 callBack = nullptr; 49 } OnSurfaceBufferAvaliable()50 void OnSurfaceBufferAvaliable() override 51 { 52 if (callBack != nullptr) { 53 callBack(); 54 } 55 } 56 std::string name; 57 std::function<void()> callBack = nullptr; 58 }; 59 } // namespace Media 60 } // namespace OHOS 61 62 #endif