• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef OH_VEF_RENDER_QUEUE_H
17 #define OH_VEF_RENDER_QUEUE_H
18 
19 #include <list>
20 #include "render/graphics/base/queue/RenderQueueItf.h"
21 
22 namespace OHOS {
23 namespace Media {
24 template <typename T> class RenderFifoQueue : public RenderQueueItf<T> {
25 public:
26     typedef std::list<T> list_t;
27 
28     ~RenderFifoQueue() = default;
29 
GetSize()30     size_t GetSize() override
31     {
32         return list_.size();
33     }
34 
Push(const T & data)35     bool Push(const T& data) override
36     {
37         list_.emplace_back(data);
38         return true;
39     }
40 
Pop(T & result)41     bool Pop(T& result) override
42     {
43         if (list_.size() == 0) {
44             return false;
45         }
46         result = list_.front();
47         list_.pop_front();
48         return true;
49     }
50 
PopWithCallBack(T & result,std::function<void (T &)> & callback)51     bool PopWithCallBack(T& result, std::function<void(T&)>& callback) override
52     {
53         if (list_.size() == 0) {
54             return false;
55         }
56         result = list_.front();
57         list_.pop_front();
58         callback(result);
59         return true;
60     }
61 
Find(const T & result)62     T Find(const T& result) override
63     {
64         for (typename list_t::iterator it = list_.begin(); it != list_.end(); ++it) {
65             if (GetTag(*it) == GetTag(result)) {
66                 return *it;
67             }
68         }
69         return nullptr;
70     }
71 
Front(T & result)72     bool Front(T& result) override
73     {
74         if (list_.size() == 0) {
75             return false;
76         }
77         result = list_.front();
78         return true;
79     }
80 
Back(T & result)81     bool Back(T& result) override
82     {
83         if (list_.size() == 0) {
84             return false;
85         }
86         result = list_.back();
87         return true;
88     }
89 
RemoveAll()90     void RemoveAll() override
91     {
92         list_.clear();
93     }
94 
Remove(const std::function<bool (T &)> & checkFunc)95     void Remove(const std::function<bool(T&)>& checkFunc) override
96     {
97         list_.remove_if(checkFunc);
98     }
99 
100 private:
101     list_t list_;
102 };
103 }
104 }
105 
106 #endif