1 /* 2 * Copyright (c) 2023-2023 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 OHOS_CAMERA_DPS_VIDEO_JOB_QUEUE_H 17 #define OHOS_CAMERA_DPS_VIDEO_JOB_QUEUE_H 18 19 #include "deferred_video_job.h" 20 21 namespace OHOS { 22 namespace CameraStandard { 23 namespace DeferredProcessing { 24 constexpr uint32_t DEFAULT = 0; 25 class VideoJobQueue { 26 public: 27 typedef std::function<bool(DeferredVideoJobPtr, DeferredVideoJobPtr)> Comparator; 28 explicit VideoJobQueue(Comparator comp); 29 ~VideoJobQueue(); 30 31 bool Contains(DeferredVideoJobPtr obj) const; 32 DeferredVideoJobPtr Peek() const; 33 void Push(DeferredVideoJobPtr obj); 34 DeferredVideoJobPtr Pop(); 35 void Remove(DeferredVideoJobPtr obj); 36 void Update(DeferredVideoJobPtr obj); 37 std::vector<DeferredVideoJobPtr> GetAllElements() const; 38 void Clear(); 39 IsEmpty()40 inline bool IsEmpty() 41 { 42 return size_ == DEFAULT; 43 } 44 GetSize()45 inline int32_t GetSize() 46 { 47 DP_DEBUG_LOG("entered, size is %{public}d", size_); 48 return size_; 49 } 50 51 private: 52 void HeapInsert(uint32_t index); 53 void Heapify(uint32_t index); 54 void Swap(uint32_t x, uint32_t y); 55 56 uint32_t size_ {0}; 57 Comparator comp_; 58 std::vector<DeferredVideoJobPtr> heap_ {}; 59 std::unordered_map<DeferredVideoJobPtr, uint32_t> indexMap_ {}; 60 }; 61 } // namespace DeferredProcessing 62 } // namespace CameraStandard 63 } // namespace OHOS 64 #endif // OHOS_CAMERA_DPS_VIDEO_JOB_QUEUE_H