Commit | Line | Data |
---|---|---|
72b9787e JB |
1 | /***************************************************************************** |
2 | * Copyright (C) 2013 x265 project | |
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; | |
29 | ||
30 | void PicList::pushFront(Frame& curFrame) | |
31 | { | |
32 | X265_CHECK(!curFrame.m_next && !curFrame.m_prev, "piclist: picture already in list\n"); // ensure frame is not in a list | |
33 | curFrame.m_next = m_start; | |
34 | curFrame.m_prev = NULL; | |
35 | ||
36 | if (m_count) | |
37 | { | |
38 | m_start->m_prev = &curFrame; | |
39 | m_start = &curFrame; | |
40 | } | |
41 | else | |
42 | { | |
43 | m_start = m_end = &curFrame; | |
44 | } | |
45 | m_count++; | |
46 | } | |
47 | ||
48 | void PicList::pushBack(Frame& curFrame) | |
49 | { | |
50 | X265_CHECK(!curFrame.m_next && !curFrame.m_prev, "piclist: picture already in list\n"); // ensure frame is not in a list | |
51 | curFrame.m_next = NULL; | |
52 | curFrame.m_prev = m_end; | |
53 | ||
54 | if (m_count) | |
55 | { | |
56 | m_end->m_next = &curFrame; | |
57 | m_end = &curFrame; | |
58 | } | |
59 | else | |
60 | { | |
61 | m_start = m_end = &curFrame; | |
62 | } | |
63 | m_count++; | |
64 | } | |
65 | ||
66 | Frame *PicList::popFront() | |
67 | { | |
68 | if (m_start) | |
69 | { | |
70 | Frame *temp = m_start; | |
71 | m_count--; | |
72 | ||
73 | if (m_count) | |
74 | { | |
75 | m_start = m_start->m_next; | |
76 | m_start->m_prev = NULL; | |
77 | } | |
78 | else | |
79 | { | |
80 | m_start = m_end = NULL; | |
81 | } | |
82 | temp->m_next = temp->m_prev = NULL; | |
83 | return temp; | |
84 | } | |
85 | else | |
86 | return NULL; | |
87 | } | |
88 | ||
89 | Frame* PicList::getPOC(int poc) | |
90 | { | |
91 | Frame *curFrame = m_start; | |
92 | while (curFrame && curFrame->m_poc != poc) | |
93 | curFrame = curFrame->m_next; | |
94 | return curFrame; | |
95 | } | |
96 | ||
97 | Frame *PicList::popBack() | |
98 | { | |
99 | if (m_end) | |
100 | { | |
101 | Frame* temp = m_end; | |
102 | m_count--; | |
103 | ||
104 | if (m_count) | |
105 | { | |
106 | m_end = m_end->m_prev; | |
107 | m_end->m_next = NULL; | |
108 | } | |
109 | else | |
110 | { | |
111 | m_start = m_end = NULL; | |
112 | } | |
113 | temp->m_next = temp->m_prev = NULL; | |
114 | return temp; | |
115 | } | |
116 | else | |
117 | return NULL; | |
118 | } | |
119 | ||
120 | void PicList::remove(Frame& curFrame) | |
121 | { | |
122 | #if _DEBUG | |
123 | Frame *tmp = m_start; | |
124 | while (tmp && tmp != &curFrame) | |
125 | { | |
126 | tmp = tmp->m_next; | |
127 | } | |
128 | ||
129 | X265_CHECK(tmp == &curFrame, "piclist: pic being removed was not in list\n"); // verify pic is in this list | |
130 | #endif | |
131 | ||
132 | m_count--; | |
133 | if (m_count) | |
134 | { | |
135 | if (m_start == &curFrame) | |
136 | m_start = curFrame.m_next; | |
137 | if (m_end == &curFrame) | |
138 | m_end = curFrame.m_prev; | |
139 | ||
140 | if (curFrame.m_next) | |
141 | curFrame.m_next->m_prev = curFrame.m_prev; | |
142 | if (curFrame.m_prev) | |
143 | curFrame.m_prev->m_next = curFrame.m_next; | |
144 | } | |
145 | else | |
146 | { | |
147 | m_start = m_end = NULL; | |
148 | } | |
149 | ||
150 | curFrame.m_next = curFrame.m_prev = NULL; | |
151 | } |