/src/x265/source/common/piclist.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Gopu Govindaswamy <gopu@multicorewareinc.com> |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
19 | | * |
20 | | * This program is also available under a commercial proprietary license. |
21 | | * For more information, contact us at license @ x265.com. |
22 | | *****************************************************************************/ |
23 | | |
24 | | #include "common.h" |
25 | | #include "piclist.h" |
26 | | #include "frame.h" |
27 | | |
28 | | using namespace X265_NS; |
29 | | |
30 | | void PicList::pushFront(Frame& curFrame) |
31 | 0 | { |
32 | 0 | X265_CHECK(!curFrame.m_next && !curFrame.m_prev, "piclist: picture already in list\n"); // ensure frame is not in a list |
33 | 0 | curFrame.m_next = m_start; |
34 | 0 | curFrame.m_prev = NULL; |
35 | |
|
36 | 0 | if (m_count) |
37 | 0 | { |
38 | 0 | m_start->m_prev = &curFrame; |
39 | 0 | m_start = &curFrame; |
40 | 0 | } |
41 | 0 | else |
42 | 0 | { |
43 | 0 | m_start = m_end = &curFrame; |
44 | 0 | } |
45 | 0 | m_count++; |
46 | 0 | } |
47 | | |
48 | | void PicList::pushBack(Frame& curFrame) |
49 | 0 | { |
50 | 0 | X265_CHECK(!curFrame.m_next && !curFrame.m_prev, "piclist: picture already in list\n"); // ensure frame is not in a list |
51 | 0 | curFrame.m_next = NULL; |
52 | 0 | curFrame.m_prev = m_end; |
53 | |
|
54 | 0 | if (m_count) |
55 | 0 | { |
56 | 0 | m_end->m_next = &curFrame; |
57 | 0 | m_end = &curFrame; |
58 | 0 | } |
59 | 0 | else |
60 | 0 | { |
61 | 0 | m_start = m_end = &curFrame; |
62 | 0 | } |
63 | 0 | m_count++; |
64 | 0 | } |
65 | | |
66 | | Frame *PicList::popFront() |
67 | 0 | { |
68 | 0 | if (m_start) |
69 | 0 | { |
70 | 0 | Frame *temp = m_start; |
71 | 0 | m_count--; |
72 | |
|
73 | 0 | if (m_count) |
74 | 0 | { |
75 | 0 | m_start = m_start->m_next; |
76 | 0 | m_start->m_prev = NULL; |
77 | 0 | } |
78 | 0 | else |
79 | 0 | { |
80 | 0 | m_start = m_end = NULL; |
81 | 0 | } |
82 | 0 | temp->m_next = temp->m_prev = NULL; |
83 | 0 | return temp; |
84 | 0 | } |
85 | 0 | else |
86 | 0 | return NULL; |
87 | 0 | } |
88 | | |
89 | | Frame* PicList::getPOC(int poc) |
90 | 0 | { |
91 | 0 | Frame *curFrame = m_start; |
92 | 0 | while (curFrame && curFrame->m_poc != poc) |
93 | 0 | curFrame = curFrame->m_next; |
94 | 0 | return curFrame; |
95 | 0 | } |
96 | | |
97 | | Frame *PicList::popBack() |
98 | 0 | { |
99 | 0 | if (m_end) |
100 | 0 | { |
101 | 0 | Frame* temp = m_end; |
102 | 0 | m_count--; |
103 | |
|
104 | 0 | if (m_count) |
105 | 0 | { |
106 | 0 | m_end = m_end->m_prev; |
107 | 0 | m_end->m_next = NULL; |
108 | 0 | } |
109 | 0 | else |
110 | 0 | { |
111 | 0 | m_start = m_end = NULL; |
112 | 0 | } |
113 | 0 | temp->m_next = temp->m_prev = NULL; |
114 | 0 | return temp; |
115 | 0 | } |
116 | 0 | else |
117 | 0 | return NULL; |
118 | 0 | } |
119 | | |
120 | | Frame* PicList::getCurFrame(void) |
121 | 0 | { |
122 | 0 | Frame *curFrame = m_start; |
123 | 0 | if (curFrame != NULL) |
124 | 0 | return curFrame; |
125 | 0 | else |
126 | 0 | return NULL; |
127 | 0 | } |
128 | | |
129 | | void PicList::remove(Frame& curFrame) |
130 | 0 | { |
131 | | #if _DEBUG |
132 | | Frame *tmp = m_start; |
133 | | while (tmp && tmp != &curFrame) |
134 | | { |
135 | | tmp = tmp->m_next; |
136 | | } |
137 | | |
138 | | X265_CHECK(tmp == &curFrame, "piclist: pic being removed was not in list\n"); // verify pic is in this list |
139 | | #endif |
140 | |
|
141 | 0 | m_count--; |
142 | 0 | if (m_count) |
143 | 0 | { |
144 | 0 | if (m_start == &curFrame) |
145 | 0 | m_start = curFrame.m_next; |
146 | 0 | if (m_end == &curFrame) |
147 | 0 | m_end = curFrame.m_prev; |
148 | |
|
149 | 0 | if (curFrame.m_next) |
150 | 0 | curFrame.m_next->m_prev = curFrame.m_prev; |
151 | 0 | if (curFrame.m_prev) |
152 | 0 | curFrame.m_prev->m_next = curFrame.m_next; |
153 | 0 | } |
154 | 0 | else |
155 | 0 | { |
156 | 0 | m_start = m_end = NULL; |
157 | 0 | } |
158 | |
|
159 | 0 | curFrame.m_next = curFrame.m_prev = NULL; |
160 | 0 | } |