Commit | Line | Data |
---|---|---|
72b9787e JB |
1 | /***************************************************************************** |
2 | * Copyright (C) 2013 x265 project | |
3 | * | |
4 | * Author: 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 | #include "common.h" | |
25 | #include "frame.h" | |
26 | #include "picyuv.h" | |
27 | #include "framedata.h" | |
28 | ||
29 | using namespace x265; | |
30 | ||
31 | Frame::Frame() | |
32 | { | |
33 | m_bChromaExtended = false; | |
34 | m_reconRowCount.set(0); | |
35 | m_countRefEncoders = 0; | |
36 | m_encData = NULL; | |
b53f7c52 | 37 | m_reconPic = NULL; |
72b9787e JB |
38 | m_next = NULL; |
39 | m_prev = NULL; | |
40 | memset(&m_lowres, 0, sizeof(m_lowres)); | |
41 | } | |
42 | ||
43 | bool Frame::create(x265_param *param) | |
44 | { | |
b53f7c52 | 45 | m_fencPic = new PicYuv; |
72b9787e | 46 | |
b53f7c52 JB |
47 | return m_fencPic->create(param->sourceWidth, param->sourceHeight, param->internalCsp) && |
48 | m_lowres.create(m_fencPic, param->bframes, !!param->rc.aqMode); | |
72b9787e JB |
49 | } |
50 | ||
51 | bool Frame::allocEncodeData(x265_param *param, const SPS& sps) | |
52 | { | |
53 | m_encData = new FrameData; | |
b53f7c52 JB |
54 | m_reconPic = new PicYuv; |
55 | m_encData->m_reconPic = m_reconPic; | |
56 | bool ok = m_encData->create(param, sps) && m_reconPic->create(param->sourceWidth, param->sourceHeight, param->internalCsp); | |
72b9787e JB |
57 | if (ok) |
58 | { | |
59 | /* initialize right border of m_reconpicYuv as SAO may read beyond the | |
60 | * end of the picture accessing uninitialized pixels */ | |
61 | int maxHeight = sps.numCuInHeight * g_maxCUSize; | |
b53f7c52 JB |
62 | memset(m_reconPic->m_picOrg[0], 0, m_reconPic->m_stride * maxHeight); |
63 | memset(m_reconPic->m_picOrg[1], 0, m_reconPic->m_strideC * (maxHeight >> m_reconPic->m_vChromaShift)); | |
64 | memset(m_reconPic->m_picOrg[2], 0, m_reconPic->m_strideC * (maxHeight >> m_reconPic->m_vChromaShift)); | |
72b9787e JB |
65 | } |
66 | return ok; | |
67 | } | |
68 | ||
69 | /* prepare to re-use a FrameData instance to encode a new picture */ | |
70 | void Frame::reinit(const SPS& sps) | |
71 | { | |
72 | m_bChromaExtended = false; | |
b53f7c52 | 73 | m_reconPic = m_encData->m_reconPic; |
72b9787e JB |
74 | m_encData->reinit(sps); |
75 | } | |
76 | ||
77 | void Frame::destroy() | |
78 | { | |
79 | if (m_encData) | |
80 | { | |
81 | m_encData->destroy(); | |
82 | delete m_encData; | |
83 | m_encData = NULL; | |
84 | } | |
85 | ||
b53f7c52 | 86 | if (m_fencPic) |
72b9787e | 87 | { |
b53f7c52 JB |
88 | m_fencPic->destroy(); |
89 | delete m_fencPic; | |
90 | m_fencPic = NULL; | |
72b9787e JB |
91 | } |
92 | ||
b53f7c52 | 93 | if (m_reconPic) |
72b9787e | 94 | { |
b53f7c52 JB |
95 | m_reconPic->destroy(); |
96 | delete m_reconPic; | |
97 | m_reconPic = NULL; | |
72b9787e JB |
98 | } |
99 | ||
100 | m_lowres.destroy(); | |
101 | } |