History

Initial Commit

Ethan Hugg committed 12 years ago

Commit 70e5e621 parent bd509b2308 files · +97095 −-5Browse files

Showing the changes to codec/decoder/core/src/pic_queue.cpp (1 of 308 files). Show all

Unified · Split

codec/decoder/core/src/pic_queue.cpp+166−0
@@ -0,0 +1,166 @@
1/*!
2 * \copy
3 * Copyright (c) 2009-2013, 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 pic_queue.c
33 *
34 * \brief Recycled piture queue implementation
35 *
36 * \date 03/13/2009 Created
37 *
38 *************************************************************************************
39 */
40#include <string.h>
41#include "pic_queue.h"
42#include "wels_const.h"
43#include "utils.h"
44#include "macros.h"
45#include "decoder_context.h"
46#include "codec_def.h"
47#include "mem_align.h"
48
49namespace WelsDec {
50
51void_t FreePicture( PPicture pPic );
52
53
54///////////////////////////////////Recycled queue management for pictures///////////////////////////////////
55/* ______________________________________
56 -->| P0 | P1 | P2 | P3 | P4 | .. | Pn-1 |-->
57 --------------------------------------
58 *
59 * How does it work?
60 * node <- next; ++ next;
61 *
62*/
63
64
65
66PPicture AllocPicture( PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight )
67{
68 PPicture pPic = NULL;
69 int32_t iPicWidth = 0;
70 int32_t iPicHeight= 0;
71
72 int32_t iPicChromaWidth = 0;
73 int32_t iPicChromaHeight = 0;
74 int32_t iLumaSize = 0;
75 int32_t iChromaSize = 0;
76
77 pPic = (PPicture) WelsMalloc( sizeof(SPicture), "PPicture" );
78 WELS_VERIFY_RETURN_IF( NULL, NULL == pPic );
79
80 memset(pPic, 0, sizeof(SPicture) );
81
82 iPicWidth = WELS_ALIGN(kiPicWidth + (PADDING_LENGTH<<1), PICTURE_RESOLUTION_ALIGNMENT);
83 iPicHeight = WELS_ALIGN(kiPicHeight + (PADDING_LENGTH<<1), PICTURE_RESOLUTION_ALIGNMENT);
84 iPicChromaWidth = iPicWidth >> 1;
85 iPicChromaHeight = iPicHeight >> 1;
86
87 iLumaSize = iPicWidth * iPicHeight;
88 iChromaSize = iPicChromaWidth * iPicChromaHeight;
89 if(pCtx->iDecoderMode == SW_MODE)
90 {
91 pPic->pBuffer[0] = static_cast<uint8_t*> (WelsMalloc( iLumaSize /* luma */
92 + (iChromaSize << 1) /* Cb,Cr */, "_pic->buffer[0]" ) );
93
94 WELS_VERIFY_RETURN_PROC_IF( NULL, NULL == pPic->pBuffer[0], FreePicture(pPic) );
95 pPic->iLinesize[0] = iPicWidth;
96 pPic->iLinesize[1] = pPic->iLinesize[2] = iPicChromaWidth;
97 pPic->pBuffer[1] = pPic->pBuffer[0] + iLumaSize;
98 pPic->pBuffer[2] = pPic->pBuffer[1] + iChromaSize;
99 pPic->pData[0] = pPic->pBuffer[0] + (1+pPic->iLinesize[0]) * PADDING_LENGTH;
100 pPic->pData[1] = pPic->pBuffer[1] + /*WELS_ALIGN*/( ((1+pPic->iLinesize[1]) * PADDING_LENGTH) >> 1 );
101 pPic->pData[2] = pPic->pBuffer[2] + /*WELS_ALIGN*/( ((1+pPic->iLinesize[2]) * PADDING_LENGTH) >> 1 );
102 }
103
104
105
106 pPic->iPlanes = 3; // yv12 in default
107 pPic->iWidthInPixel = kiPicWidth;
108 pPic->iHeightInPixel= kiPicHeight;
109 pPic->iFrameNum = -1;
110 pPic->bAvailableFlag= true;
111
112 return pPic;
113}
114
115void_t FreePicture( PPicture pPic )
116{
117 if ( NULL != pPic )
118 {
119
120 if ( pPic->pBuffer[0] )
121 {
122 WelsFree( pPic->pBuffer[0], "pPic->pBuffer[0]" );
123 }
124
125 WelsFree( pPic, "pPic" );
126
127 pPic = NULL;
128 }
129}
130PPicture PrefetchPic( PPicBuff pPicBuf )
131{
132 int32_t iPicIdx = 0;
133 PPicture pPic = NULL;
134
135 if (pPicBuf->iCapacity == 0)
136 {
137 return NULL;
138 }
139
140 for ( iPicIdx = pPicBuf->iCurrentIdx+1; iPicIdx<pPicBuf->iCapacity ;++iPicIdx)
141 {
142 if (pPicBuf->ppPic[iPicIdx] !=NULL && pPicBuf->ppPic[iPicIdx]->bAvailableFlag && !pPicBuf->ppPic[iPicIdx]->bUsedAsRef)
143 {
144 pPic = pPicBuf->ppPic[iPicIdx];
145 break;
146 }
147 }
148 if (pPic !=NULL)
149 {
150 pPicBuf->iCurrentIdx = iPicIdx;
151 return pPic;
152 }
153 for ( iPicIdx = 0 ; iPicIdx<pPicBuf->iCurrentIdx ;++iPicIdx)
154 {
155 if (pPicBuf->ppPic[iPicIdx] !=NULL && pPicBuf->ppPic[iPicIdx]->bAvailableFlag && !pPicBuf->ppPic[iPicIdx]->bUsedAsRef)
156 {
157 pPic = pPicBuf->ppPic[iPicIdx];
158 break;
159 }
160 }
161
162 pPicBuf->iCurrentIdx = iPicIdx;
163 return pPic;
164}
165
166} // namespace WelsDec

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t