Coverage Report

Created: 2025-07-23 08:18

/src/openh264/codec/common/inc/WelsList.h
Line
Count
Source (jump to first uncovered line)
1
/*!
2
 * \copy
3
 *     Copyright (c)  2009-2015, Cisco Systems
4
 *     All rights reserved.
5
 *
6
 *     Redistribution and use in source and binary forms, with or without
7
 *     modification, are permitted provided that the following conditions
8
 *     are met:
9
 *
10
 *        * Redistributions of source code must retain the above copyright
11
 *          notice, this list of conditions and the following disclaimer.
12
 *
13
 *        * Redistributions in binary form must reproduce the above copyright
14
 *          notice, this list of conditions and the following disclaimer in
15
 *          the documentation and/or other materials provided with the
16
 *          distribution.
17
 *
18
 *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
 *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
 *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21
 *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
 *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
 *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
 *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
 *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28
 *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
 *     POSSIBILITY OF SUCH DAMAGE.
30
 *
31
 *
32
 * \file    WelsList
33
 *
34
 * \brief   for the list function needed in ThreadPool
35
 *
36
 * \date    9/27/2015 Created
37
 *
38
 *************************************************************************************
39
 */
40
41
42
#ifndef _WELS_LIST_H_
43
#define _WELS_LIST_H_
44
45
#include "typedefs.h"
46
#include <stdlib.h>
47
48
namespace WelsCommon {
49
50
template<typename TNodeType>
51
struct SNode {
52
  TNodeType* pPointer;
53
  SNode* pPrevNode;
54
  SNode* pNextNode;
55
};
56
57
template<typename TNodeType>
58
class CWelsList {
59
 public:
60
0
  CWelsList() {
61
0
    m_iCurrentNodeCount = 0;
62
0
    m_iMaxNodeCount = 50;
63
64
0
    m_pCurrentList = NULL;
65
0
    m_pFirst = NULL;
66
0
    m_pCurrent = NULL;
67
0
    m_pLast = NULL;
68
0
  };
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::CWelsList()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::CWelsList()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::CWelsList()
69
0
  ~CWelsList() {
70
0
    if (m_pCurrentList) {
71
0
      free (m_pCurrentList);
72
0
      m_pCurrentList = NULL;
73
0
    }
74
75
0
    m_pCurrentList = NULL;
76
0
    m_pFirst = NULL;
77
0
    m_pCurrent = NULL;
78
0
    m_pLast = NULL;
79
0
  };
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::~CWelsList()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::~CWelsList()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::~CWelsList()
80
81
0
  int32_t size() {
82
0
    return m_iCurrentNodeCount;
83
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::size()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::size()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::size()
84
85
0
  bool push_back (TNodeType* pNode) {
86
0
    if (!pNode) {
87
0
      return false;
88
0
    }
89
90
0
    if (NULL == m_pCurrentList) {
91
0
      m_pCurrentList = static_cast<SNode<TNodeType>*> (malloc (m_iMaxNodeCount * sizeof (SNode<TNodeType>)));
92
0
      if (NULL == m_pCurrentList) {
93
0
        return false;
94
0
      } else {
95
0
        ResetStorage();
96
0
      }
97
0
    }
98
99
0
    if (NULL == m_pCurrent) {
100
0
      if (!ExpandList()) {
101
0
        return false;
102
0
      }
103
0
    }
104
105
0
    m_pCurrent->pPointer = pNode;
106
0
    m_pCurrent = m_pCurrent->pNextNode;
107
0
    m_iCurrentNodeCount++;
108
109
0
    return true;
110
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::push_back(WelsEnc::CWelsBaseTask*)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::push_back(WelsCommon::CWelsTaskThread*)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::push_back(WelsCommon::IWelsTask*)
111
112
0
  TNodeType* begin() {
113
0
    if (m_pFirst) {
114
0
      return m_pFirst->pPointer;
115
0
    }
116
0
    return NULL;
117
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::begin()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::begin()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::begin()
118
119
0
  void pop_front() {
120
0
    if (m_iCurrentNodeCount == 0) {
121
0
      return;
122
0
    }
123
124
0
    SNode<TNodeType>* pTemp = m_pFirst;
125
126
0
    m_pFirst = m_pFirst->pNextNode;
127
0
    m_pFirst->pPrevNode = NULL;
128
129
0
    CleanOneNode (pTemp);
130
131
0
    m_pLast->pNextNode = pTemp;
132
0
    pTemp->pPrevNode = m_pLast;
133
0
    m_pLast = pTemp;
134
135
0
    if (NULL == m_pCurrent)
136
0
      m_pCurrent = m_pLast;
137
138
0
    m_iCurrentNodeCount --;
139
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::pop_front()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::pop_front()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::pop_front()
140
141
0
  bool erase (TNodeType* pNode) {
142
0
    if (0 == m_iCurrentNodeCount) {
143
0
      return false;
144
0
    }
145
146
0
    SNode<TNodeType>* pTemp = m_pFirst;
147
0
    do {
148
0
      if (pNode == pTemp->pPointer) {
149
0
        if (pTemp->pPrevNode) {
150
0
          pTemp->pPrevNode->pNextNode = pTemp->pNextNode;
151
0
        } else {
152
0
          m_pFirst = pTemp->pNextNode;
153
0
        }
154
155
0
        if (pTemp->pNextNode) {
156
0
          pTemp->pNextNode->pPrevNode = pTemp->pPrevNode;
157
0
        }
158
159
0
        CleanOneNode (pTemp);
160
0
        m_iCurrentNodeCount --;
161
162
0
        m_pLast->pNextNode = pTemp;
163
0
        pTemp->pPrevNode = m_pLast;
164
0
        m_pLast = pTemp;
165
166
0
        return true;
167
0
      }
168
169
0
      pTemp = pTemp->pNextNode;
170
171
0
    } while (pTemp && pTemp->pPointer);
172
0
    return false;
173
0
  }
174
175
0
  bool findNode (TNodeType* pNodeTarget) {
176
0
    if ((m_iCurrentNodeCount > 0) && pNodeTarget) {
177
0
      SNode<TNodeType>* pNode = m_pFirst;
178
0
      while (pNode) {
179
0
        if (pNode->pPointer == pNodeTarget) {
180
0
          return true;
181
0
        }
182
0
        pNode = pNode->pNextNode;
183
0
      }
184
0
    }
185
0
    return false;
186
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::findNode(WelsEnc::CWelsBaseTask*)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::findNode(WelsCommon::CWelsTaskThread*)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::findNode(WelsCommon::IWelsTask*)
187
188
0
  TNodeType* getNode (int iNodeIdx) {
189
0
    if ((iNodeIdx > m_iCurrentNodeCount - 1) || (0 == m_iCurrentNodeCount)) {
190
0
      return NULL;
191
0
    }
192
0
    SNode<TNodeType>* pNode = m_pFirst;
193
0
    for (int i = 0; i < iNodeIdx; i++) {
194
0
      if (pNode->pNextNode) {
195
0
        pNode = pNode->pNextNode;
196
0
      } else {
197
0
        return NULL;
198
0
      }
199
0
    }
200
0
    return pNode->pPointer;
201
0
  }
202
203
 private:
204
0
  bool ExpandList() {
205
0
    SNode<TNodeType>* tmpCurrentList = static_cast<SNode<TNodeType>*> (malloc (m_iMaxNodeCount * 2 * sizeof (
206
0
                                         SNode<TNodeType>)));
207
0
    if (tmpCurrentList == NULL) {
208
0
      return false;
209
0
    }
210
0
    InitStorage (tmpCurrentList, (m_iMaxNodeCount * 2) - 1);
211
212
0
    SNode<TNodeType>* pTemp = m_pFirst;
213
0
    for (int i = 0; ((i < m_iMaxNodeCount) && pTemp); i++) {
214
0
      tmpCurrentList[i].pPointer = pTemp->pPointer;
215
0
      pTemp = pTemp->pNextNode;
216
0
    }
217
218
0
    free (m_pCurrentList);
219
0
    m_pCurrentList = tmpCurrentList;
220
0
    m_iCurrentNodeCount = m_iMaxNodeCount;
221
0
    m_iMaxNodeCount = m_iMaxNodeCount * 2;
222
0
    m_pFirst = & (m_pCurrentList[0]);
223
0
    m_pLast = & (m_pCurrentList[m_iMaxNodeCount - 1]);
224
0
    m_pCurrent = & (m_pCurrentList[m_iCurrentNodeCount]);
225
0
    return true;
226
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::ExpandList()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::ExpandList()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::ExpandList()
227
228
0
  void InitStorage (SNode<TNodeType>* pList, const int32_t iMaxIndex) {
229
0
    pList[0].pPrevNode = NULL;
230
0
    pList[0].pPointer = NULL;
231
0
    pList[0].pNextNode = & (pList[1]);
232
0
    for (int i = 1; i < iMaxIndex; i++) {
233
0
      pList[i].pPrevNode = & (pList[i - 1]);
234
0
      pList[i].pPointer = NULL;
235
0
      pList[i].pNextNode = & (pList[i + 1]);
236
0
    }
237
0
    pList[iMaxIndex].pPrevNode = & (pList[iMaxIndex - 1]);
238
0
    pList[iMaxIndex].pPointer = NULL;
239
0
    pList[iMaxIndex].pNextNode = NULL;
240
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::InitStorage(WelsCommon::SNode<WelsEnc::CWelsBaseTask>*, int)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::InitStorage(WelsCommon::SNode<WelsCommon::CWelsTaskThread>*, int)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::InitStorage(WelsCommon::SNode<WelsCommon::IWelsTask>*, int)
241
242
243
0
  void CleanOneNode (SNode<TNodeType>* pSNode) {
244
0
    pSNode->pPointer = NULL;
245
0
    pSNode->pPrevNode = NULL;
246
0
    pSNode->pNextNode = NULL;
247
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::CleanOneNode(WelsCommon::SNode<WelsEnc::CWelsBaseTask>*)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::CleanOneNode(WelsCommon::SNode<WelsCommon::CWelsTaskThread>*)
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::CleanOneNode(WelsCommon::SNode<WelsCommon::IWelsTask>*)
248
249
0
  void ResetStorage() {
250
0
    InitStorage (m_pCurrentList, m_iMaxNodeCount - 1);
251
0
    m_pCurrent = m_pCurrentList;
252
0
    m_pFirst = & (m_pCurrentList[0]);
253
0
    m_pLast = & (m_pCurrentList[m_iMaxNodeCount - 1]);
254
0
  }
Unexecuted instantiation: WelsCommon::CWelsList<WelsEnc::CWelsBaseTask>::ResetStorage()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::CWelsTaskThread>::ResetStorage()
Unexecuted instantiation: WelsCommon::CWelsList<WelsCommon::IWelsTask>::ResetStorage()
255
256
 private:
257
  int32_t m_iCurrentNodeCount;
258
  int32_t m_iMaxNodeCount;
259
  SNode<TNodeType>* m_pCurrentList;
260
  SNode<TNodeType>* m_pFirst;
261
  SNode<TNodeType>* m_pLast;
262
  SNode<TNodeType>* m_pCurrent;
263
};
264
265
template<typename TNodeType>
266
class CWelsNonDuplicatedList : public CWelsList<TNodeType> {
267
 public:
268
0
  bool push_back (TNodeType* pNode) {
269
0
    if (0 != this->size()) {
270
0
      if ((NULL != pNode) && (this->findNode (pNode))) {      //not checking NULL for easier testing
271
0
        return false;
272
0
      }
273
0
    }
274
275
0
    return CWelsList<TNodeType>::push_back (pNode);
276
0
  }
Unexecuted instantiation: WelsCommon::CWelsNonDuplicatedList<WelsEnc::CWelsBaseTask>::push_back(WelsEnc::CWelsBaseTask*)
Unexecuted instantiation: WelsCommon::CWelsNonDuplicatedList<WelsCommon::CWelsTaskThread>::push_back(WelsCommon::CWelsTaskThread*)
Unexecuted instantiation: WelsCommon::CWelsNonDuplicatedList<WelsCommon::IWelsTask>::push_back(WelsCommon::IWelsTask*)
277
278
};
279
280
281
}
282
283
284
#endif
285
286
287