1 /* 2 * Copyright (c) 2024-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 16 #ifndef CAMERA_FRAMEWORK_DRAIN_MANAGER_H 17 #define CAMERA_FRAMEWORK_DRAIN_MANAGER_H 18 19 #include <vector> 20 #include <unordered_map> 21 #include <functional> 22 #include "frame_record.h" 23 #include <refbase.h> 24 25 namespace OHOS { 26 namespace CameraStandard { 27 class DrainImageCallback : public RefBase { 28 public: 29 ~DrainImageCallback() = default; 30 virtual void OnDrainImage(sptr<FrameRecord> frame) = 0; 31 virtual void OnDrainImageFinish(bool isFinished) = 0; 32 }; 33 34 class DrainImageManager : public RefBase { 35 private: 36 sptr<DrainImageCallback> drainImageCallback; 37 std::function<void()> drainFinishCallback; 38 39 public: 40 int drainCount; 41 std::mutex drainImageLock_; DrainImageManager(sptr<DrainImageCallback> callback,int count)42 DrainImageManager(sptr<DrainImageCallback> callback, int count) : drainImageCallback(callback), drainCount(count) {} DrainImage(sptr<FrameRecord> frame)43 void DrainImage(sptr<FrameRecord> frame) 44 { 45 if (drainCount <= 0) { 46 return; 47 } 48 drainImageCallback->OnDrainImage(frame); 49 drainCount--; 50 if (drainCount == 0) { 51 DrainFinish(true); 52 } 53 } 54 DrainFinish(bool isFinished)55 void DrainFinish(bool isFinished) 56 { 57 drainImageCallback->OnDrainImageFinish(isFinished); 58 } 59 }; 60 } // CameraStandard 61 } // OHOS 62 #endif //CAMERA_FRAMEWORK_DRAIN_MANAGER_H 63