Commit | Line | Data |
---|---|---|
72b9787e JB |
1 | /***************************************************************************** |
2 | * Copyright (C) 2013 x265 project | |
3 | * | |
4 | * Authors: Steve Borho <steve@borho.org> | |
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 | #ifndef X265_WAVEFRONT_H | |
25 | #define X265_WAVEFRONT_H | |
26 | ||
27 | #include "common.h" | |
28 | #include "threadpool.h" | |
29 | ||
30 | namespace x265 { | |
31 | // x265 private namespace | |
32 | ||
33 | // Generic wave-front scheduler, manages busy-state of CU rows as a priority | |
34 | // queue (higher CU rows have priority over lower rows) | |
35 | // | |
36 | // Derived classes must implement ProcessRow(). | |
37 | class WaveFront : public JobProvider | |
38 | { | |
39 | private: | |
40 | ||
41 | // bitmaps of rows queued for processing, uses atomic intrinsics | |
42 | ||
43 | // Dependencies are categorized as internal and external. Internal dependencies | |
44 | // are caused by neighbor block availability. External dependencies are generally | |
45 | // reference frame reconstructed pixels being available. | |
b53f7c52 JB |
46 | uint32_t volatile *m_internalDependencyBitmap; |
47 | uint32_t volatile *m_externalDependencyBitmap; | |
72b9787e JB |
48 | |
49 | // number of words in the bitmap | |
50 | int m_numWords; | |
51 | ||
52 | int m_numRows; | |
53 | ||
54 | public: | |
55 | ||
56 | WaveFront(ThreadPool *pool) | |
57 | : JobProvider(pool) | |
58 | , m_internalDependencyBitmap(0) | |
59 | , m_externalDependencyBitmap(0) | |
60 | {} | |
61 | ||
62 | virtual ~WaveFront(); | |
63 | ||
64 | // If returns false, the frame must be encoded in series. | |
65 | bool init(int numRows); | |
66 | ||
67 | // Enqueue a row to be processed (mark its internal dependencies as resolved). | |
68 | // A worker thread will later call processRow(row). | |
69 | // This provider must be enqueued in the pool before enqueuing a row | |
70 | void enqueueRow(int row); | |
71 | ||
72 | // Mark a row as no longer having internal dependencies resolved. Returns | |
73 | // true if bit clear was successful, false otherwise. | |
74 | bool dequeueRow(int row); | |
75 | ||
76 | // Mark the row's external dependencies as being resolved | |
77 | void enableRow(int row); | |
78 | ||
79 | // Mark all row external dependencies as being resolved. Some wavefront | |
80 | // implementations (lookahead, for instance) have no recon pixel dependencies. | |
81 | void enableAllRows(); | |
82 | ||
83 | // Mark all rows as having external dependencies which must be | |
84 | // resolved before each row may proceed. | |
85 | void clearEnabledRowMask(); | |
86 | ||
87 | // WaveFront's implementation of JobProvider::findJob. Consults | |
88 | // m_queuedBitmap and calls ProcessRow(row) for lowest numbered queued row | |
89 | // or returns false | |
90 | bool findJob(int threadId); | |
91 | ||
92 | // Start or resume encode processing of this row, must be implemented by | |
93 | // derived classes. | |
94 | virtual void processRow(int row, int threadId) = 0; | |
72b9787e JB |
95 | }; |
96 | } // end namespace x265 | |
97 | ||
98 | #endif // ifndef X265_WAVEFRONT_H |