xref: /aosp_15_r20/external/libavc/common/ih264_dpb_mgr.c (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker  *
3*495ae853SAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
4*495ae853SAndroid Build Coastguard Worker  *
5*495ae853SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*495ae853SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*495ae853SAndroid Build Coastguard Worker  * You may obtain a copy of the License at:
8*495ae853SAndroid Build Coastguard Worker  *
9*495ae853SAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
10*495ae853SAndroid Build Coastguard Worker  *
11*495ae853SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*495ae853SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*495ae853SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*495ae853SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*495ae853SAndroid Build Coastguard Worker  * limitations under the License.
16*495ae853SAndroid Build Coastguard Worker  *
17*495ae853SAndroid Build Coastguard Worker  *****************************************************************************
18*495ae853SAndroid Build Coastguard Worker  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*495ae853SAndroid Build Coastguard Worker */
20*495ae853SAndroid Build Coastguard Worker 
21*495ae853SAndroid Build Coastguard Worker /**
22*495ae853SAndroid Build Coastguard Worker *******************************************************************************
23*495ae853SAndroid Build Coastguard Worker * @file
24*495ae853SAndroid Build Coastguard Worker *  ih264_dpb_mgr.c
25*495ae853SAndroid Build Coastguard Worker *
26*495ae853SAndroid Build Coastguard Worker * @brief
27*495ae853SAndroid Build Coastguard Worker *  Function definitions used for decoded picture buffer management
28*495ae853SAndroid Build Coastguard Worker *
29*495ae853SAndroid Build Coastguard Worker * @author
30*495ae853SAndroid Build Coastguard Worker *  ittiam
31*495ae853SAndroid Build Coastguard Worker *
32*495ae853SAndroid Build Coastguard Worker * @par List of Functions:
33*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_init
34*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_sort_short_term_fields_by_frame_num
35*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_sort_short_term_fields_by_poc_l0
36*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_sort_short_term_fields_by_poc_l1
37*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_sort_long_term_fields_by_frame_idx
38*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_alternate_ref_fields
39*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_insert_ref_field
40*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_insert_ref_frame
41*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_count_ref_frames
42*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_delete_ref_frame
43*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_delete_long_ref_fields_max_frame_idx
44*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_delete_short_ref_frame
45*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_delete_all_ref_frames
46*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_reset
47*495ae853SAndroid Build Coastguard Worker *  - ih264_dpb_mgr_release_pics
48*495ae853SAndroid Build Coastguard Worker *
49*495ae853SAndroid Build Coastguard Worker * @remarks
50*495ae853SAndroid Build Coastguard Worker *  none
51*495ae853SAndroid Build Coastguard Worker *
52*495ae853SAndroid Build Coastguard Worker *******************************************************************************
53*495ae853SAndroid Build Coastguard Worker */
54*495ae853SAndroid Build Coastguard Worker 
55*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
56*495ae853SAndroid Build Coastguard Worker /* File Includes                                                             */
57*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
58*495ae853SAndroid Build Coastguard Worker 
59*495ae853SAndroid Build Coastguard Worker /* System Include Files */
60*495ae853SAndroid Build Coastguard Worker #include <stdio.h>
61*495ae853SAndroid Build Coastguard Worker #include <stdlib.h>
62*495ae853SAndroid Build Coastguard Worker #include <assert.h>
63*495ae853SAndroid Build Coastguard Worker 
64*495ae853SAndroid Build Coastguard Worker /* User Include Files */
65*495ae853SAndroid Build Coastguard Worker #include "ih264_typedefs.h"
66*495ae853SAndroid Build Coastguard Worker #include "ih264_debug.h"
67*495ae853SAndroid Build Coastguard Worker #include "ih264_macros.h"
68*495ae853SAndroid Build Coastguard Worker #include "ih264_error.h"
69*495ae853SAndroid Build Coastguard Worker #include "ih264_defs.h"
70*495ae853SAndroid Build Coastguard Worker #include "ih264_structs.h"
71*495ae853SAndroid Build Coastguard Worker #include "ih264_buf_mgr.h"
72*495ae853SAndroid Build Coastguard Worker #include "ih264_dpb_mgr.h"
73*495ae853SAndroid Build Coastguard Worker 
74*495ae853SAndroid Build Coastguard Worker 
75*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
76*495ae853SAndroid Build Coastguard Worker /* Function Definitions                                                      */
77*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
78*495ae853SAndroid Build Coastguard Worker 
79*495ae853SAndroid Build Coastguard Worker /**
80*495ae853SAndroid Build Coastguard Worker *******************************************************************************
81*495ae853SAndroid Build Coastguard Worker *
82*495ae853SAndroid Build Coastguard Worker * @brief DPB manager initializer
83*495ae853SAndroid Build Coastguard Worker *
84*495ae853SAndroid Build Coastguard Worker * @par Description Initialises the DPB manager structure
85*495ae853SAndroid Build Coastguard Worker *
86*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
87*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
88*495ae853SAndroid Build Coastguard Worker *
89*495ae853SAndroid Build Coastguard Worker * @returns
90*495ae853SAndroid Build Coastguard Worker *
91*495ae853SAndroid Build Coastguard Worker * @remarks
92*495ae853SAndroid Build Coastguard Worker *
93*495ae853SAndroid Build Coastguard Worker *******************************************************************************
94*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_init(dpb_mgr_t * ps_dpb_mgr)95*495ae853SAndroid Build Coastguard Worker void ih264_dpb_mgr_init(dpb_mgr_t *ps_dpb_mgr)
96*495ae853SAndroid Build Coastguard Worker {
97*495ae853SAndroid Build Coastguard Worker     UWORD32 i;
98*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_info = ps_dpb_mgr->as_dpb_info;
99*495ae853SAndroid Build Coastguard Worker 
100*495ae853SAndroid Build Coastguard Worker     for(i = 0; i < MAX_DPB_BUFS; i++)
101*495ae853SAndroid Build Coastguard Worker     {
102*495ae853SAndroid Build Coastguard Worker         ps_dpb_info[i].ps_prev_dpb = NULL;
103*495ae853SAndroid Build Coastguard Worker         ps_dpb_info[i].ps_pic_buf = NULL;
104*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->as_top_field_pics[i].i4_used_as_ref = INVALID;
105*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->as_bottom_field_pics[i].i4_used_as_ref = INVALID;
106*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->as_top_field_pics[i].i1_field_type = INVALID;
107*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->as_bottom_field_pics[i].i1_field_type = INVALID;
108*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->as_top_field_pics[i].i4_long_term_frame_idx = -1;
109*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->as_bottom_field_pics[i].i4_long_term_frame_idx = -1;
110*495ae853SAndroid Build Coastguard Worker     }
111*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->u1_num_short_term_ref_bufs = 0;
112*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->u1_num_long_term_ref_bufs = 0;
113*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->ps_dpb_short_term_head = NULL;
114*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->ps_dpb_long_term_head = NULL;
115*495ae853SAndroid Build Coastguard Worker }
116*495ae853SAndroid Build Coastguard Worker 
117*495ae853SAndroid Build Coastguard Worker /**
118*495ae853SAndroid Build Coastguard Worker *******************************************************************************
119*495ae853SAndroid Build Coastguard Worker *
120*495ae853SAndroid Build Coastguard Worker * @brief
121*495ae853SAndroid Build Coastguard Worker *  Function to sort short term pics by frame_num.
122*495ae853SAndroid Build Coastguard Worker *
123*495ae853SAndroid Build Coastguard Worker * @par Description:
124*495ae853SAndroid Build Coastguard Worker *  Sorts short term fields by frame_num. For 2 fields having same frame_num,
125*495ae853SAndroid Build Coastguard Worker *  orders them based on requested first field type.
126*495ae853SAndroid Build Coastguard Worker *
127*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
128*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
129*495ae853SAndroid Build Coastguard Worker *
130*495ae853SAndroid Build Coastguard Worker * @param[in] curr_frame_num
131*495ae853SAndroid Build Coastguard Worker *  frame_num of the current pic
132*495ae853SAndroid Build Coastguard Worker *
133*495ae853SAndroid Build Coastguard Worker * @param[in] first_field_type
134*495ae853SAndroid Build Coastguard Worker *  For complementary fields, required first field
135*495ae853SAndroid Build Coastguard Worker *
136*495ae853SAndroid Build Coastguard Worker * @param[in] max_frame_num
137*495ae853SAndroid Build Coastguard Worker *  Maximum frame_num allowed
138*495ae853SAndroid Build Coastguard Worker *
139*495ae853SAndroid Build Coastguard Worker * @returns
140*495ae853SAndroid Build Coastguard Worker *
141*495ae853SAndroid Build Coastguard Worker * @remarks
142*495ae853SAndroid Build Coastguard Worker *
143*495ae853SAndroid Build Coastguard Worker *
144*495ae853SAndroid Build Coastguard Worker *******************************************************************************
145*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_sort_short_term_fields_by_frame_num(dpb_mgr_t * ps_dpb_mgr,WORD32 curr_frame_num,WORD32 first_field_type,WORD32 max_frame_num)146*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_sort_short_term_fields_by_frame_num(dpb_mgr_t *ps_dpb_mgr,
147*495ae853SAndroid Build Coastguard Worker                                                          WORD32 curr_frame_num,
148*495ae853SAndroid Build Coastguard Worker                                                          WORD32 first_field_type,
149*495ae853SAndroid Build Coastguard Worker                                                          WORD32 max_frame_num)
150*495ae853SAndroid Build Coastguard Worker {
151*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node1 = ps_dpb_mgr->ps_dpb_short_term_head;
152*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node2;
153*495ae853SAndroid Build Coastguard Worker     WORD32 frame_num_node1;
154*495ae853SAndroid Build Coastguard Worker     WORD32 frame_num_node2;
155*495ae853SAndroid Build Coastguard Worker     pic_buf_t *ps_pic_buf;
156*495ae853SAndroid Build Coastguard Worker 
157*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node1 == NULL)
158*495ae853SAndroid Build Coastguard Worker         return -1;
159*495ae853SAndroid Build Coastguard Worker 
160*495ae853SAndroid Build Coastguard Worker     for (; ps_dpb_node1 != NULL; ps_dpb_node1 = ps_dpb_node1->ps_prev_dpb)
161*495ae853SAndroid Build Coastguard Worker     {
162*495ae853SAndroid Build Coastguard Worker         for (ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb; ps_dpb_node2 != NULL; ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb)
163*495ae853SAndroid Build Coastguard Worker         {
164*495ae853SAndroid Build Coastguard Worker             frame_num_node1 = ps_dpb_node1->ps_pic_buf->i4_frame_num;
165*495ae853SAndroid Build Coastguard Worker             frame_num_node2 = ps_dpb_node2->ps_pic_buf->i4_frame_num;
166*495ae853SAndroid Build Coastguard Worker 
167*495ae853SAndroid Build Coastguard Worker             if(frame_num_node1 > curr_frame_num)
168*495ae853SAndroid Build Coastguard Worker                 frame_num_node1 = frame_num_node1 - max_frame_num;
169*495ae853SAndroid Build Coastguard Worker             if(frame_num_node2 > curr_frame_num)
170*495ae853SAndroid Build Coastguard Worker                 frame_num_node2 = frame_num_node2 - max_frame_num;
171*495ae853SAndroid Build Coastguard Worker 
172*495ae853SAndroid Build Coastguard Worker             if(frame_num_node1 < frame_num_node2)
173*495ae853SAndroid Build Coastguard Worker             {
174*495ae853SAndroid Build Coastguard Worker                 ps_pic_buf = ps_dpb_node1->ps_pic_buf;
175*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node1->ps_pic_buf = ps_dpb_node2->ps_pic_buf;
176*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node2->ps_pic_buf = ps_pic_buf;
177*495ae853SAndroid Build Coastguard Worker             }
178*495ae853SAndroid Build Coastguard Worker         }
179*495ae853SAndroid Build Coastguard Worker     }
180*495ae853SAndroid Build Coastguard Worker 
181*495ae853SAndroid Build Coastguard Worker     /**
182*495ae853SAndroid Build Coastguard Worker      * For frames and complementary field pairs,
183*495ae853SAndroid Build Coastguard Worker      * ensure first_field_type appears first in the list
184*495ae853SAndroid Build Coastguard Worker      */
185*495ae853SAndroid Build Coastguard Worker     ps_dpb_node1 = ps_dpb_mgr->ps_dpb_short_term_head;
186*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
187*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_node2 != NULL)
188*495ae853SAndroid Build Coastguard Worker     {
189*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node1 = ps_dpb_node1->ps_pic_buf;
190*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node2 = ps_dpb_node2->ps_pic_buf;
191*495ae853SAndroid Build Coastguard Worker         frame_num_node1 = ps_pic_node1->i4_frame_num;
192*495ae853SAndroid Build Coastguard Worker         frame_num_node2 = ps_pic_node2->i4_frame_num;
193*495ae853SAndroid Build Coastguard Worker         if(frame_num_node1 == frame_num_node2)
194*495ae853SAndroid Build Coastguard Worker         {
195*495ae853SAndroid Build Coastguard Worker             ASSERT(ps_pic_node1->i1_field_type != ps_pic_node2->i1_field_type);
196*495ae853SAndroid Build Coastguard Worker             if(ps_pic_node1->i1_field_type != first_field_type)
197*495ae853SAndroid Build Coastguard Worker             {
198*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node1->ps_pic_buf = ps_pic_node2;
199*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node2->ps_pic_buf = ps_pic_node1;
200*495ae853SAndroid Build Coastguard Worker             }
201*495ae853SAndroid Build Coastguard Worker         }
202*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1 = ps_dpb_node2;
203*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb;
204*495ae853SAndroid Build Coastguard Worker     }
205*495ae853SAndroid Build Coastguard Worker     return 0;
206*495ae853SAndroid Build Coastguard Worker }
207*495ae853SAndroid Build Coastguard Worker 
208*495ae853SAndroid Build Coastguard Worker /**
209*495ae853SAndroid Build Coastguard Worker *******************************************************************************
210*495ae853SAndroid Build Coastguard Worker *
211*495ae853SAndroid Build Coastguard Worker * @brief
212*495ae853SAndroid Build Coastguard Worker *  Function to sort sort term pics by poc for list 0.
213*495ae853SAndroid Build Coastguard Worker *
214*495ae853SAndroid Build Coastguard Worker * @par Description:
215*495ae853SAndroid Build Coastguard Worker *  Orders all the pocs less than current poc in the descending order.
216*495ae853SAndroid Build Coastguard Worker *  Then orders all the pocs greater than current poc in the ascending order.
217*495ae853SAndroid Build Coastguard Worker *
218*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
219*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
220*495ae853SAndroid Build Coastguard Worker *
221*495ae853SAndroid Build Coastguard Worker * @param[in] curr_poc
222*495ae853SAndroid Build Coastguard Worker *  Poc of the current pic
223*495ae853SAndroid Build Coastguard Worker *
224*495ae853SAndroid Build Coastguard Worker * @param[in] first_field_type
225*495ae853SAndroid Build Coastguard Worker *  For complementary fields, required first field
226*495ae853SAndroid Build Coastguard Worker *
227*495ae853SAndroid Build Coastguard Worker * @returns
228*495ae853SAndroid Build Coastguard Worker *
229*495ae853SAndroid Build Coastguard Worker * @remarks
230*495ae853SAndroid Build Coastguard Worker *
231*495ae853SAndroid Build Coastguard Worker *******************************************************************************
232*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_sort_short_term_fields_by_poc_l0(dpb_mgr_t * ps_dpb_mgr,WORD32 curr_poc,WORD32 first_field_type)233*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_sort_short_term_fields_by_poc_l0(dpb_mgr_t *ps_dpb_mgr,
234*495ae853SAndroid Build Coastguard Worker                                                       WORD32 curr_poc,
235*495ae853SAndroid Build Coastguard Worker                                                       WORD32 first_field_type)
236*495ae853SAndroid Build Coastguard Worker {
237*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node1 = ps_dpb_mgr->ps_dpb_short_term_head;
238*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node2;
239*495ae853SAndroid Build Coastguard Worker     WORD32 poc_node1;
240*495ae853SAndroid Build Coastguard Worker     WORD32 poc_node2;
241*495ae853SAndroid Build Coastguard Worker     WORD32 frame_num_node1;
242*495ae853SAndroid Build Coastguard Worker     WORD32 frame_num_node2;
243*495ae853SAndroid Build Coastguard Worker     pic_buf_t *ps_pic_buf;
244*495ae853SAndroid Build Coastguard Worker 
245*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node1 == NULL)
246*495ae853SAndroid Build Coastguard Worker         return -1;
247*495ae853SAndroid Build Coastguard Worker 
248*495ae853SAndroid Build Coastguard Worker     /**
249*495ae853SAndroid Build Coastguard Worker      * Sort the fields by poc.
250*495ae853SAndroid Build Coastguard Worker      * All POCs less than current poc are first placed in the descending order.
251*495ae853SAndroid Build Coastguard Worker      * Then all POCs greater than current poc are placed in the ascending order.
252*495ae853SAndroid Build Coastguard Worker      */
253*495ae853SAndroid Build Coastguard Worker     for (; ps_dpb_node1 != NULL; ps_dpb_node1 = ps_dpb_node1->ps_prev_dpb)
254*495ae853SAndroid Build Coastguard Worker     {
255*495ae853SAndroid Build Coastguard Worker         for (ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb; ps_dpb_node2 != NULL; ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb)
256*495ae853SAndroid Build Coastguard Worker         {
257*495ae853SAndroid Build Coastguard Worker             poc_node1 = ps_dpb_node1->ps_pic_buf->i4_abs_poc;
258*495ae853SAndroid Build Coastguard Worker             poc_node2 = ps_dpb_node2->ps_pic_buf->i4_abs_poc;
259*495ae853SAndroid Build Coastguard Worker             ASSERT(poc_node1 != curr_poc);
260*495ae853SAndroid Build Coastguard Worker             ASSERT(poc_node2 != curr_poc);
261*495ae853SAndroid Build Coastguard Worker             if(((poc_node1 < curr_poc) && (poc_node2 > curr_poc)) ||
262*495ae853SAndroid Build Coastguard Worker                     ((poc_node1 < curr_poc) && (poc_node2 < curr_poc) && (poc_node1 > poc_node2)) ||
263*495ae853SAndroid Build Coastguard Worker                     ((poc_node1 > curr_poc) && (poc_node2 > curr_poc) && (poc_node1 < poc_node2)))
264*495ae853SAndroid Build Coastguard Worker                     continue;
265*495ae853SAndroid Build Coastguard Worker 
266*495ae853SAndroid Build Coastguard Worker             ps_pic_buf = ps_dpb_node1->ps_pic_buf;
267*495ae853SAndroid Build Coastguard Worker             ps_dpb_node1->ps_pic_buf = ps_dpb_node2->ps_pic_buf;
268*495ae853SAndroid Build Coastguard Worker             ps_dpb_node2->ps_pic_buf = ps_pic_buf;
269*495ae853SAndroid Build Coastguard Worker         }
270*495ae853SAndroid Build Coastguard Worker     }
271*495ae853SAndroid Build Coastguard Worker 
272*495ae853SAndroid Build Coastguard Worker     ps_dpb_node1 = ps_dpb_mgr->ps_dpb_short_term_head;
273*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
274*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_node2 != NULL)
275*495ae853SAndroid Build Coastguard Worker     {
276*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node1 = ps_dpb_node1->ps_pic_buf;
277*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node2 = ps_dpb_node2->ps_pic_buf;
278*495ae853SAndroid Build Coastguard Worker         frame_num_node1 = ps_pic_node1->i4_frame_num;
279*495ae853SAndroid Build Coastguard Worker         frame_num_node2 = ps_pic_node2->i4_frame_num;
280*495ae853SAndroid Build Coastguard Worker         if(frame_num_node1 == frame_num_node2)
281*495ae853SAndroid Build Coastguard Worker         {
282*495ae853SAndroid Build Coastguard Worker             ASSERT(ps_pic_node1->i1_field_type != ps_pic_node2->i1_field_type);
283*495ae853SAndroid Build Coastguard Worker             if(ps_pic_node1->i1_field_type != first_field_type)
284*495ae853SAndroid Build Coastguard Worker             {
285*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node1->ps_pic_buf = ps_pic_node2;
286*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node2->ps_pic_buf = ps_pic_node1;
287*495ae853SAndroid Build Coastguard Worker             }
288*495ae853SAndroid Build Coastguard Worker         }
289*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1 = ps_dpb_node2;
290*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb;
291*495ae853SAndroid Build Coastguard Worker     }
292*495ae853SAndroid Build Coastguard Worker     return 0;
293*495ae853SAndroid Build Coastguard Worker }
294*495ae853SAndroid Build Coastguard Worker 
295*495ae853SAndroid Build Coastguard Worker /**
296*495ae853SAndroid Build Coastguard Worker *******************************************************************************
297*495ae853SAndroid Build Coastguard Worker *
298*495ae853SAndroid Build Coastguard Worker * @brief
299*495ae853SAndroid Build Coastguard Worker *  Function to sort sort term pics by poc for list 1.
300*495ae853SAndroid Build Coastguard Worker *
301*495ae853SAndroid Build Coastguard Worker * @par Description:
302*495ae853SAndroid Build Coastguard Worker *  Orders all the pocs greater than current poc in the ascending order.
303*495ae853SAndroid Build Coastguard Worker *  Then rrders all the pocs less than current poc in the descending order.
304*495ae853SAndroid Build Coastguard Worker *
305*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
306*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
307*495ae853SAndroid Build Coastguard Worker *
308*495ae853SAndroid Build Coastguard Worker * @param[in] curr_poc
309*495ae853SAndroid Build Coastguard Worker *  Poc of the current pic
310*495ae853SAndroid Build Coastguard Worker *
311*495ae853SAndroid Build Coastguard Worker * @param[in] first_field_type
312*495ae853SAndroid Build Coastguard Worker *  For complementary fields, required first field
313*495ae853SAndroid Build Coastguard Worker *
314*495ae853SAndroid Build Coastguard Worker * @returns
315*495ae853SAndroid Build Coastguard Worker *
316*495ae853SAndroid Build Coastguard Worker * @remarks
317*495ae853SAndroid Build Coastguard Worker *
318*495ae853SAndroid Build Coastguard Worker *
319*495ae853SAndroid Build Coastguard Worker *******************************************************************************
320*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_sort_short_term_fields_by_poc_l1(dpb_mgr_t * ps_dpb_mgr,WORD32 curr_poc,WORD32 first_field_type)321*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_sort_short_term_fields_by_poc_l1(dpb_mgr_t *ps_dpb_mgr,
322*495ae853SAndroid Build Coastguard Worker                                                       WORD32 curr_poc,
323*495ae853SAndroid Build Coastguard Worker                                                       WORD32 first_field_type)
324*495ae853SAndroid Build Coastguard Worker {
325*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node1 = ps_dpb_mgr->ps_dpb_short_term_head;
326*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node2;
327*495ae853SAndroid Build Coastguard Worker     WORD32 poc_node1;
328*495ae853SAndroid Build Coastguard Worker     WORD32 poc_node2;
329*495ae853SAndroid Build Coastguard Worker     WORD32 frame_num_node1;
330*495ae853SAndroid Build Coastguard Worker     WORD32 frame_num_node2;
331*495ae853SAndroid Build Coastguard Worker     pic_buf_t *ps_pic_buf;
332*495ae853SAndroid Build Coastguard Worker 
333*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node1 == NULL)
334*495ae853SAndroid Build Coastguard Worker         return -1;
335*495ae853SAndroid Build Coastguard Worker 
336*495ae853SAndroid Build Coastguard Worker     /**
337*495ae853SAndroid Build Coastguard Worker      * Sort the fields by poc.
338*495ae853SAndroid Build Coastguard Worker      * All POCs greater than current poc are first placed in the ascending order.
339*495ae853SAndroid Build Coastguard Worker      * Then all POCs less than current poc are placed in the decending order.
340*495ae853SAndroid Build Coastguard Worker      */
341*495ae853SAndroid Build Coastguard Worker     for (; ps_dpb_node1 != NULL; ps_dpb_node1 = ps_dpb_node1->ps_prev_dpb)
342*495ae853SAndroid Build Coastguard Worker     {
343*495ae853SAndroid Build Coastguard Worker         for (ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb; ps_dpb_node2 != NULL; ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb)
344*495ae853SAndroid Build Coastguard Worker         {
345*495ae853SAndroid Build Coastguard Worker             poc_node1 = ps_dpb_node1->ps_pic_buf->i4_abs_poc;
346*495ae853SAndroid Build Coastguard Worker             poc_node2 = ps_dpb_node2->ps_pic_buf->i4_abs_poc;
347*495ae853SAndroid Build Coastguard Worker             ASSERT(poc_node1 != curr_poc);
348*495ae853SAndroid Build Coastguard Worker             ASSERT(poc_node2 != curr_poc);
349*495ae853SAndroid Build Coastguard Worker             if(((poc_node1 > curr_poc) && (poc_node2 < curr_poc)) ||
350*495ae853SAndroid Build Coastguard Worker                     ((poc_node1 < curr_poc) && (poc_node2 < curr_poc) && (poc_node1 > poc_node2)) ||
351*495ae853SAndroid Build Coastguard Worker                     ((poc_node1 > curr_poc) && (poc_node2 > curr_poc) && (poc_node1 < poc_node2)))
352*495ae853SAndroid Build Coastguard Worker                     continue;
353*495ae853SAndroid Build Coastguard Worker 
354*495ae853SAndroid Build Coastguard Worker             ps_pic_buf = ps_dpb_node1->ps_pic_buf;
355*495ae853SAndroid Build Coastguard Worker             ps_dpb_node1->ps_pic_buf = ps_dpb_node2->ps_pic_buf;
356*495ae853SAndroid Build Coastguard Worker             ps_dpb_node2->ps_pic_buf = ps_pic_buf;
357*495ae853SAndroid Build Coastguard Worker         }
358*495ae853SAndroid Build Coastguard Worker     }
359*495ae853SAndroid Build Coastguard Worker 
360*495ae853SAndroid Build Coastguard Worker     ps_dpb_node1 = ps_dpb_mgr->ps_dpb_short_term_head;
361*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
362*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_node2 != NULL)
363*495ae853SAndroid Build Coastguard Worker     {
364*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node1 = ps_dpb_node1->ps_pic_buf;
365*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node2 = ps_dpb_node2->ps_pic_buf;
366*495ae853SAndroid Build Coastguard Worker         frame_num_node1 = ps_pic_node1->i4_frame_num;
367*495ae853SAndroid Build Coastguard Worker         frame_num_node2 = ps_pic_node2->i4_frame_num;
368*495ae853SAndroid Build Coastguard Worker         if(frame_num_node1 == frame_num_node2)
369*495ae853SAndroid Build Coastguard Worker         {
370*495ae853SAndroid Build Coastguard Worker             ASSERT(ps_pic_node1->i1_field_type != ps_pic_node2->i1_field_type);
371*495ae853SAndroid Build Coastguard Worker             if(ps_pic_node1->i1_field_type != first_field_type)
372*495ae853SAndroid Build Coastguard Worker             {
373*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node1->ps_pic_buf = ps_pic_node2;
374*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node2->ps_pic_buf = ps_pic_node1;
375*495ae853SAndroid Build Coastguard Worker             }
376*495ae853SAndroid Build Coastguard Worker         }
377*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1 = ps_dpb_node2;
378*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb;
379*495ae853SAndroid Build Coastguard Worker     }
380*495ae853SAndroid Build Coastguard Worker     return 0;
381*495ae853SAndroid Build Coastguard Worker }
382*495ae853SAndroid Build Coastguard Worker 
383*495ae853SAndroid Build Coastguard Worker /**
384*495ae853SAndroid Build Coastguard Worker *******************************************************************************
385*495ae853SAndroid Build Coastguard Worker *
386*495ae853SAndroid Build Coastguard Worker * @brief
387*495ae853SAndroid Build Coastguard Worker *  Function to sort long term pics by long term frame idx.
388*495ae853SAndroid Build Coastguard Worker *
389*495ae853SAndroid Build Coastguard Worker * @par Description:
390*495ae853SAndroid Build Coastguard Worker *  Sorts long term fields by long term frame idx. For 2 fields
391*495ae853SAndroid Build Coastguard Worker *  having same frame_num, orders them based on requested first field type.
392*495ae853SAndroid Build Coastguard Worker *
393*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
394*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
395*495ae853SAndroid Build Coastguard Worker *
396*495ae853SAndroid Build Coastguard Worker * @param[in] first_field_type
397*495ae853SAndroid Build Coastguard Worker *  For complementary fields, required first field
398*495ae853SAndroid Build Coastguard Worker *
399*495ae853SAndroid Build Coastguard Worker * @returns
400*495ae853SAndroid Build Coastguard Worker *
401*495ae853SAndroid Build Coastguard Worker * @remarks
402*495ae853SAndroid Build Coastguard Worker *
403*495ae853SAndroid Build Coastguard Worker *******************************************************************************
404*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_sort_long_term_fields_by_frame_idx(dpb_mgr_t * ps_dpb_mgr,WORD32 first_field_type)405*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_sort_long_term_fields_by_frame_idx(dpb_mgr_t *ps_dpb_mgr,
406*495ae853SAndroid Build Coastguard Worker                                                         WORD32 first_field_type)
407*495ae853SAndroid Build Coastguard Worker {
408*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node1 = ps_dpb_mgr->ps_dpb_long_term_head;
409*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node2;
410*495ae853SAndroid Build Coastguard Worker     WORD32 frame_idx_node1;
411*495ae853SAndroid Build Coastguard Worker     WORD32 frame_idx_node2;
412*495ae853SAndroid Build Coastguard Worker     pic_buf_t *ps_pic_buf;
413*495ae853SAndroid Build Coastguard Worker 
414*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node1 == NULL)
415*495ae853SAndroid Build Coastguard Worker         return -1;
416*495ae853SAndroid Build Coastguard Worker 
417*495ae853SAndroid Build Coastguard Worker     /* Sort the fields by frame idx */
418*495ae853SAndroid Build Coastguard Worker     for (; ps_dpb_node1 != NULL; ps_dpb_node1 = ps_dpb_node1->ps_prev_dpb)
419*495ae853SAndroid Build Coastguard Worker     {
420*495ae853SAndroid Build Coastguard Worker         for (ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb; ps_dpb_node2 != NULL; ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb)
421*495ae853SAndroid Build Coastguard Worker         {
422*495ae853SAndroid Build Coastguard Worker             frame_idx_node1 = ps_dpb_node1->ps_pic_buf->i4_long_term_frame_idx;
423*495ae853SAndroid Build Coastguard Worker             frame_idx_node2 = ps_dpb_node2->ps_pic_buf->i4_long_term_frame_idx;
424*495ae853SAndroid Build Coastguard Worker 
425*495ae853SAndroid Build Coastguard Worker             if(frame_idx_node1 > frame_idx_node2)
426*495ae853SAndroid Build Coastguard Worker             {
427*495ae853SAndroid Build Coastguard Worker                 ps_pic_buf = ps_dpb_node1->ps_pic_buf;
428*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node1->ps_pic_buf = ps_dpb_node2->ps_pic_buf;
429*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node2->ps_pic_buf = ps_pic_buf;
430*495ae853SAndroid Build Coastguard Worker             }
431*495ae853SAndroid Build Coastguard Worker         }
432*495ae853SAndroid Build Coastguard Worker     }
433*495ae853SAndroid Build Coastguard Worker 
434*495ae853SAndroid Build Coastguard Worker     /**
435*495ae853SAndroid Build Coastguard Worker      * For frames and complementary field pairs,
436*495ae853SAndroid Build Coastguard Worker      * ensure first_field_type appears first in the list
437*495ae853SAndroid Build Coastguard Worker      */
438*495ae853SAndroid Build Coastguard Worker     ps_dpb_node1 = ps_dpb_mgr->ps_dpb_long_term_head;
439*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
440*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_node2 != NULL)
441*495ae853SAndroid Build Coastguard Worker     {
442*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node1 = ps_dpb_node1->ps_pic_buf;
443*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node2 = ps_dpb_node2->ps_pic_buf;
444*495ae853SAndroid Build Coastguard Worker         frame_idx_node1 = ps_pic_node1->i4_long_term_frame_idx;
445*495ae853SAndroid Build Coastguard Worker         frame_idx_node2 = ps_pic_node2->i4_long_term_frame_idx;
446*495ae853SAndroid Build Coastguard Worker         if(frame_idx_node1 == frame_idx_node2)
447*495ae853SAndroid Build Coastguard Worker         {
448*495ae853SAndroid Build Coastguard Worker             ASSERT(ps_pic_node1->i1_field_type != ps_pic_node2->i1_field_type);
449*495ae853SAndroid Build Coastguard Worker             if(ps_pic_node1->i1_field_type != first_field_type)
450*495ae853SAndroid Build Coastguard Worker             {
451*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node1->ps_pic_buf = ps_pic_node2;
452*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node2->ps_pic_buf = ps_pic_node1;
453*495ae853SAndroid Build Coastguard Worker             }
454*495ae853SAndroid Build Coastguard Worker         }
455*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1 = ps_dpb_node2;
456*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2 = ps_dpb_node2->ps_prev_dpb;
457*495ae853SAndroid Build Coastguard Worker     }
458*495ae853SAndroid Build Coastguard Worker     return 0;
459*495ae853SAndroid Build Coastguard Worker }
460*495ae853SAndroid Build Coastguard Worker 
461*495ae853SAndroid Build Coastguard Worker /**
462*495ae853SAndroid Build Coastguard Worker *******************************************************************************
463*495ae853SAndroid Build Coastguard Worker *
464*495ae853SAndroid Build Coastguard Worker * @brief
465*495ae853SAndroid Build Coastguard Worker *  Function to alternate fields.
466*495ae853SAndroid Build Coastguard Worker *
467*495ae853SAndroid Build Coastguard Worker * @par Description:
468*495ae853SAndroid Build Coastguard Worker *  In the ordered list of fields, alternate fields starting with
469*495ae853SAndroid Build Coastguard Worker *  first_field_type
470*495ae853SAndroid Build Coastguard Worker *
471*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
472*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
473*495ae853SAndroid Build Coastguard Worker *
474*495ae853SAndroid Build Coastguard Worker * @param[in] reference_type
475*495ae853SAndroid Build Coastguard Worker *  This is used to select between short-term and long-term linked list.
476*495ae853SAndroid Build Coastguard Worker *
477*495ae853SAndroid Build Coastguard Worker * @param[in] first_field_type
478*495ae853SAndroid Build Coastguard Worker *  For complementary fields, required first field
479*495ae853SAndroid Build Coastguard Worker *
480*495ae853SAndroid Build Coastguard Worker * @returns
481*495ae853SAndroid Build Coastguard Worker *
482*495ae853SAndroid Build Coastguard Worker * @remarks
483*495ae853SAndroid Build Coastguard Worker *
484*495ae853SAndroid Build Coastguard Worker *******************************************************************************
485*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_alternate_ref_fields(dpb_mgr_t * ps_dpb_mgr,WORD32 reference_type,WORD32 first_field_type)486*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_alternate_ref_fields(dpb_mgr_t *ps_dpb_mgr,
487*495ae853SAndroid Build Coastguard Worker                                           WORD32 reference_type,
488*495ae853SAndroid Build Coastguard Worker                                           WORD32 first_field_type)
489*495ae853SAndroid Build Coastguard Worker {
490*495ae853SAndroid Build Coastguard Worker     dpb_info_t s_dpb_head;
491*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_head;
492*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node1;
493*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node2;
494*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node3;
495*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node4;
496*495ae853SAndroid Build Coastguard Worker     WORD32 expected_field;
497*495ae853SAndroid Build Coastguard Worker 
498*495ae853SAndroid Build Coastguard Worker     expected_field = first_field_type;
499*495ae853SAndroid Build Coastguard Worker 
500*495ae853SAndroid Build Coastguard Worker     ps_dpb_head = &s_dpb_head;
501*495ae853SAndroid Build Coastguard Worker 
502*495ae853SAndroid Build Coastguard Worker     ps_dpb_head->ps_prev_dpb = (reference_type == SHORT_TERM_REF) ?
503*495ae853SAndroid Build Coastguard Worker             ps_dpb_mgr->ps_dpb_short_term_head:
504*495ae853SAndroid Build Coastguard Worker             ps_dpb_mgr->ps_dpb_long_term_head;
505*495ae853SAndroid Build Coastguard Worker 
506*495ae853SAndroid Build Coastguard Worker     ps_dpb_node1 = ps_dpb_head;
507*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
508*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_node2 != NULL)
509*495ae853SAndroid Build Coastguard Worker     {
510*495ae853SAndroid Build Coastguard Worker         pic_buf_t *ps_pic_node2 = ps_dpb_node2->ps_pic_buf;
511*495ae853SAndroid Build Coastguard Worker         if(ps_pic_node2->i1_field_type != expected_field)
512*495ae853SAndroid Build Coastguard Worker         {
513*495ae853SAndroid Build Coastguard Worker             /*
514*495ae853SAndroid Build Coastguard Worker              * If it is not expected field, loop over the node till
515*495ae853SAndroid Build Coastguard Worker              * the expected field.
516*495ae853SAndroid Build Coastguard Worker              */
517*495ae853SAndroid Build Coastguard Worker             ps_dpb_node3 = ps_dpb_node2;
518*495ae853SAndroid Build Coastguard Worker             ps_dpb_node4 = ps_dpb_node2->ps_prev_dpb;
519*495ae853SAndroid Build Coastguard Worker             while((ps_dpb_node4 != NULL) &&
520*495ae853SAndroid Build Coastguard Worker                     (ps_dpb_node4->ps_pic_buf->i1_field_type != expected_field))
521*495ae853SAndroid Build Coastguard Worker             {
522*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node3 = ps_dpb_node4;
523*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node4 = ps_dpb_node4->ps_prev_dpb;
524*495ae853SAndroid Build Coastguard Worker             }
525*495ae853SAndroid Build Coastguard Worker             if(ps_dpb_node4 != NULL)
526*495ae853SAndroid Build Coastguard Worker             {
527*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node1->ps_prev_dpb = ps_dpb_node4;
528*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node3->ps_prev_dpb = ps_dpb_node4->ps_prev_dpb;
529*495ae853SAndroid Build Coastguard Worker                 ps_dpb_node4->ps_prev_dpb = ps_dpb_node2;
530*495ae853SAndroid Build Coastguard Worker             }
531*495ae853SAndroid Build Coastguard Worker             else
532*495ae853SAndroid Build Coastguard Worker             {
533*495ae853SAndroid Build Coastguard Worker                 /* node4 null means we have reached the end */
534*495ae853SAndroid Build Coastguard Worker                 break;
535*495ae853SAndroid Build Coastguard Worker             }
536*495ae853SAndroid Build Coastguard Worker         }
537*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1 = ps_dpb_node1->ps_prev_dpb;
538*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
539*495ae853SAndroid Build Coastguard Worker         expected_field = (ps_dpb_node1->ps_pic_buf->i1_field_type == TOP_FIELD)?
540*495ae853SAndroid Build Coastguard Worker                             BOTTOM_FIELD:TOP_FIELD;
541*495ae853SAndroid Build Coastguard Worker     }
542*495ae853SAndroid Build Coastguard Worker 
543*495ae853SAndroid Build Coastguard Worker     if(reference_type == SHORT_TERM_REF)
544*495ae853SAndroid Build Coastguard Worker     {
545*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->ps_dpb_short_term_head = ps_dpb_head->ps_prev_dpb;
546*495ae853SAndroid Build Coastguard Worker     }
547*495ae853SAndroid Build Coastguard Worker     else
548*495ae853SAndroid Build Coastguard Worker     {
549*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->ps_dpb_long_term_head = ps_dpb_head->ps_prev_dpb;
550*495ae853SAndroid Build Coastguard Worker     }
551*495ae853SAndroid Build Coastguard Worker 
552*495ae853SAndroid Build Coastguard Worker     return 0;
553*495ae853SAndroid Build Coastguard Worker }
554*495ae853SAndroid Build Coastguard Worker 
555*495ae853SAndroid Build Coastguard Worker /**
556*495ae853SAndroid Build Coastguard Worker *******************************************************************************
557*495ae853SAndroid Build Coastguard Worker *
558*495ae853SAndroid Build Coastguard Worker * @brief
559*495ae853SAndroid Build Coastguard Worker *  Add a ref field to short-term or long-term linked list.
560*495ae853SAndroid Build Coastguard Worker *
561*495ae853SAndroid Build Coastguard Worker * @par Description:
562*495ae853SAndroid Build Coastguard Worker *  This function adds a ref field to either short-term or long-term linked
563*495ae853SAndroid Build Coastguard Worker *  list. It picks up memory for the link from the array of dpb_info in
564*495ae853SAndroid Build Coastguard Worker *  dpb_mgr. The field is added to the beginning of the linked list and the
565*495ae853SAndroid Build Coastguard Worker *  head is set the the field.
566*495ae853SAndroid Build Coastguard Worker *
567*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
568*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
569*495ae853SAndroid Build Coastguard Worker *
570*495ae853SAndroid Build Coastguard Worker * @param[in] ps_pic_buf
571*495ae853SAndroid Build Coastguard Worker *  Pic buf structure for the field being added.
572*495ae853SAndroid Build Coastguard Worker *
573*495ae853SAndroid Build Coastguard Worker * @param[in] reference_type
574*495ae853SAndroid Build Coastguard Worker *  This is used to select between short-term and long-term linked list.
575*495ae853SAndroid Build Coastguard Worker *
576*495ae853SAndroid Build Coastguard Worker * @param[in] frame_num
577*495ae853SAndroid Build Coastguard Worker *  frame_num for the field.
578*495ae853SAndroid Build Coastguard Worker *
579*495ae853SAndroid Build Coastguard Worker * @param[in] long_term_frame_idx
580*495ae853SAndroid Build Coastguard Worker *  If the ref being added is long-term, long_term_frame_idx of the field.
581*495ae853SAndroid Build Coastguard Worker *  Otherwise invalid.
582*495ae853SAndroid Build Coastguard Worker *
583*495ae853SAndroid Build Coastguard Worker * @returns
584*495ae853SAndroid Build Coastguard Worker *
585*495ae853SAndroid Build Coastguard Worker * @remarks
586*495ae853SAndroid Build Coastguard Worker *
587*495ae853SAndroid Build Coastguard Worker *******************************************************************************
588*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_insert_ref_field(dpb_mgr_t * ps_dpb_mgr,pic_buf_t * ps_pic_buf,WORD32 reference_type,UWORD32 frame_num,WORD32 long_term_frame_idx)589*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_insert_ref_field(dpb_mgr_t *ps_dpb_mgr,
590*495ae853SAndroid Build Coastguard Worker                                     pic_buf_t *ps_pic_buf,
591*495ae853SAndroid Build Coastguard Worker                                     WORD32 reference_type,
592*495ae853SAndroid Build Coastguard Worker                                     UWORD32 frame_num,
593*495ae853SAndroid Build Coastguard Worker                                     WORD32 long_term_frame_idx)
594*495ae853SAndroid Build Coastguard Worker {
595*495ae853SAndroid Build Coastguard Worker     WORD32 i;
596*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_info;
597*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_head;
598*495ae853SAndroid Build Coastguard Worker 
599*495ae853SAndroid Build Coastguard Worker     ps_dpb_info = ps_dpb_mgr->as_dpb_info;
600*495ae853SAndroid Build Coastguard Worker 
601*495ae853SAndroid Build Coastguard Worker     /* Return error if buffer is already present in the DPB */
602*495ae853SAndroid Build Coastguard Worker     for(i = 0; i < MAX_DPB_BUFS; i++)
603*495ae853SAndroid Build Coastguard Worker     {
604*495ae853SAndroid Build Coastguard Worker         if( (ps_dpb_info[i].ps_pic_buf == ps_pic_buf)
605*495ae853SAndroid Build Coastguard Worker                         && (ps_dpb_info[i].ps_pic_buf->i4_used_as_ref == reference_type) )
606*495ae853SAndroid Build Coastguard Worker         {
607*495ae853SAndroid Build Coastguard Worker             return (-1);
608*495ae853SAndroid Build Coastguard Worker         }
609*495ae853SAndroid Build Coastguard Worker     }
610*495ae853SAndroid Build Coastguard Worker 
611*495ae853SAndroid Build Coastguard Worker     /* Find an unused DPB location */
612*495ae853SAndroid Build Coastguard Worker     for(i = 0; i < MAX_DPB_BUFS; i++)
613*495ae853SAndroid Build Coastguard Worker     {
614*495ae853SAndroid Build Coastguard Worker         if(NULL == ps_dpb_info[i].ps_pic_buf)
615*495ae853SAndroid Build Coastguard Worker         {
616*495ae853SAndroid Build Coastguard Worker             break;
617*495ae853SAndroid Build Coastguard Worker         }
618*495ae853SAndroid Build Coastguard Worker     }
619*495ae853SAndroid Build Coastguard Worker     if(i == MAX_DPB_BUFS)
620*495ae853SAndroid Build Coastguard Worker     {
621*495ae853SAndroid Build Coastguard Worker         return (-1);
622*495ae853SAndroid Build Coastguard Worker     }
623*495ae853SAndroid Build Coastguard Worker 
624*495ae853SAndroid Build Coastguard Worker     ps_dpb_head = (reference_type == SHORT_TERM_REF)
625*495ae853SAndroid Build Coastguard Worker                     ?ps_dpb_mgr->ps_dpb_short_term_head
626*495ae853SAndroid Build Coastguard Worker                     :ps_dpb_mgr->ps_dpb_long_term_head;
627*495ae853SAndroid Build Coastguard Worker 
628*495ae853SAndroid Build Coastguard Worker     if(reference_type == SHORT_TERM_REF)
629*495ae853SAndroid Build Coastguard Worker         long_term_frame_idx = -1;
630*495ae853SAndroid Build Coastguard Worker 
631*495ae853SAndroid Build Coastguard Worker     /* Create DPB info */
632*495ae853SAndroid Build Coastguard Worker     ps_dpb_info[i].ps_pic_buf = ps_pic_buf;
633*495ae853SAndroid Build Coastguard Worker     ps_dpb_info[i].ps_prev_dpb = ps_dpb_head;
634*495ae853SAndroid Build Coastguard Worker     ps_dpb_info[i].ps_pic_buf->i4_used_as_ref = reference_type;
635*495ae853SAndroid Build Coastguard Worker     ps_dpb_info[i].ps_pic_buf->i4_frame_num = frame_num;
636*495ae853SAndroid Build Coastguard Worker     ps_dpb_info[i].ps_pic_buf->i4_long_term_frame_idx = long_term_frame_idx;
637*495ae853SAndroid Build Coastguard Worker 
638*495ae853SAndroid Build Coastguard Worker     /* update the head node of linked list to point to the current picture */
639*495ae853SAndroid Build Coastguard Worker     if(reference_type == SHORT_TERM_REF)
640*495ae853SAndroid Build Coastguard Worker     {
641*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->ps_dpb_short_term_head = ps_dpb_info + i;
642*495ae853SAndroid Build Coastguard Worker 
643*495ae853SAndroid Build Coastguard Worker         /* Increment Short term buffer count */
644*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->u1_num_short_term_ref_bufs++;
645*495ae853SAndroid Build Coastguard Worker 
646*495ae853SAndroid Build Coastguard Worker     }
647*495ae853SAndroid Build Coastguard Worker     else
648*495ae853SAndroid Build Coastguard Worker     {
649*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->ps_dpb_long_term_head = ps_dpb_info + i;
650*495ae853SAndroid Build Coastguard Worker 
651*495ae853SAndroid Build Coastguard Worker         /* Increment Long term buffer count */
652*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->u1_num_long_term_ref_bufs++;
653*495ae853SAndroid Build Coastguard Worker     }
654*495ae853SAndroid Build Coastguard Worker 
655*495ae853SAndroid Build Coastguard Worker     return 0;
656*495ae853SAndroid Build Coastguard Worker }
657*495ae853SAndroid Build Coastguard Worker 
658*495ae853SAndroid Build Coastguard Worker /**
659*495ae853SAndroid Build Coastguard Worker *******************************************************************************
660*495ae853SAndroid Build Coastguard Worker *
661*495ae853SAndroid Build Coastguard Worker * @brief
662*495ae853SAndroid Build Coastguard Worker *  Add a ref frame to short-term or long-term linked list.
663*495ae853SAndroid Build Coastguard Worker *
664*495ae853SAndroid Build Coastguard Worker * @par Description:
665*495ae853SAndroid Build Coastguard Worker *  This function adds a ref frame to either short-term or long-term linked
666*495ae853SAndroid Build Coastguard Worker *  list. Internally it calls add ref field twice to add top and bottom field.
667*495ae853SAndroid Build Coastguard Worker *
668*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
669*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
670*495ae853SAndroid Build Coastguard Worker *
671*495ae853SAndroid Build Coastguard Worker * @param[in] ps_pic_buf
672*495ae853SAndroid Build Coastguard Worker *  Pic buf structure for the field being added.
673*495ae853SAndroid Build Coastguard Worker *
674*495ae853SAndroid Build Coastguard Worker * @param[in] reference_type
675*495ae853SAndroid Build Coastguard Worker *  This is used to select between short-term and long-term linked list.
676*495ae853SAndroid Build Coastguard Worker *
677*495ae853SAndroid Build Coastguard Worker * @param[in] frame_num
678*495ae853SAndroid Build Coastguard Worker *  frame_num for the field.
679*495ae853SAndroid Build Coastguard Worker *
680*495ae853SAndroid Build Coastguard Worker * @param[in] long_term_frame_idx
681*495ae853SAndroid Build Coastguard Worker *  If the ref being added is long-term, long_term_frame_idx of the field.
682*495ae853SAndroid Build Coastguard Worker *  Otherwise invalid.
683*495ae853SAndroid Build Coastguard Worker *
684*495ae853SAndroid Build Coastguard Worker * @returns
685*495ae853SAndroid Build Coastguard Worker *
686*495ae853SAndroid Build Coastguard Worker * @remarks
687*495ae853SAndroid Build Coastguard Worker *
688*495ae853SAndroid Build Coastguard Worker *******************************************************************************
689*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_insert_ref_frame(dpb_mgr_t * ps_dpb_mgr,pic_buf_t * ps_pic_buf,WORD32 reference_type,UWORD32 frame_num,WORD32 long_term_frame_idx)690*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_insert_ref_frame(dpb_mgr_t *ps_dpb_mgr,
691*495ae853SAndroid Build Coastguard Worker                                       pic_buf_t *ps_pic_buf,
692*495ae853SAndroid Build Coastguard Worker                                       WORD32 reference_type,
693*495ae853SAndroid Build Coastguard Worker                                       UWORD32 frame_num,
694*495ae853SAndroid Build Coastguard Worker                                       WORD32 long_term_frame_idx)
695*495ae853SAndroid Build Coastguard Worker {
696*495ae853SAndroid Build Coastguard Worker     WORD32 buf_id;
697*495ae853SAndroid Build Coastguard Worker     pic_buf_t *ps_pic_top;
698*495ae853SAndroid Build Coastguard Worker     pic_buf_t *ps_pic_bottom;
699*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
700*495ae853SAndroid Build Coastguard Worker 
701*495ae853SAndroid Build Coastguard Worker     /*
702*495ae853SAndroid Build Coastguard Worker      * For a frame, since the ps_pic_buf passed to this function is that of top field
703*495ae853SAndroid Build Coastguard Worker      * obtain bottom field using buf_id.
704*495ae853SAndroid Build Coastguard Worker      */
705*495ae853SAndroid Build Coastguard Worker     ps_pic_top = ps_pic_buf;
706*495ae853SAndroid Build Coastguard Worker     buf_id = ps_pic_top->i4_buf_id;
707*495ae853SAndroid Build Coastguard Worker     ps_pic_bottom = &ps_dpb_mgr->as_bottom_field_pics[buf_id];
708*495ae853SAndroid Build Coastguard Worker 
709*495ae853SAndroid Build Coastguard Worker     /* Insert top field */
710*495ae853SAndroid Build Coastguard Worker     ret = ih264_dpb_mgr_insert_ref_field(ps_dpb_mgr,
711*495ae853SAndroid Build Coastguard Worker                                        ps_pic_top,
712*495ae853SAndroid Build Coastguard Worker                                        reference_type,
713*495ae853SAndroid Build Coastguard Worker                                        frame_num,
714*495ae853SAndroid Build Coastguard Worker                                        long_term_frame_idx);
715*495ae853SAndroid Build Coastguard Worker 
716*495ae853SAndroid Build Coastguard Worker     if(ret != 0)
717*495ae853SAndroid Build Coastguard Worker         return ret;
718*495ae853SAndroid Build Coastguard Worker 
719*495ae853SAndroid Build Coastguard Worker     /* Insert bottom field */
720*495ae853SAndroid Build Coastguard Worker     ret = ih264_dpb_mgr_insert_ref_field(ps_dpb_mgr,
721*495ae853SAndroid Build Coastguard Worker                                        ps_pic_bottom,
722*495ae853SAndroid Build Coastguard Worker                                        reference_type,
723*495ae853SAndroid Build Coastguard Worker                                        frame_num,
724*495ae853SAndroid Build Coastguard Worker                                        long_term_frame_idx);
725*495ae853SAndroid Build Coastguard Worker 
726*495ae853SAndroid Build Coastguard Worker     if(ret != 0)
727*495ae853SAndroid Build Coastguard Worker         return ret;
728*495ae853SAndroid Build Coastguard Worker 
729*495ae853SAndroid Build Coastguard Worker     return ret;
730*495ae853SAndroid Build Coastguard Worker }
731*495ae853SAndroid Build Coastguard Worker 
732*495ae853SAndroid Build Coastguard Worker /**
733*495ae853SAndroid Build Coastguard Worker *******************************************************************************
734*495ae853SAndroid Build Coastguard Worker *
735*495ae853SAndroid Build Coastguard Worker * @brief
736*495ae853SAndroid Build Coastguard Worker *  Returns the number of ref frames in both the linked list.
737*495ae853SAndroid Build Coastguard Worker *
738*495ae853SAndroid Build Coastguard Worker * @par Description:
739*495ae853SAndroid Build Coastguard Worker *  Returns the count of number of frames, number of complementary field pairs
740*495ae853SAndroid Build Coastguard Worker *  and number of unpaired fields.
741*495ae853SAndroid Build Coastguard Worker *
742*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
743*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
744*495ae853SAndroid Build Coastguard Worker *
745*495ae853SAndroid Build Coastguard Worker * @param[in] curr_frame_num
746*495ae853SAndroid Build Coastguard Worker *  frame_num for the field.
747*495ae853SAndroid Build Coastguard Worker *
748*495ae853SAndroid Build Coastguard Worker * @param[in] max_frame_num
749*495ae853SAndroid Build Coastguard Worker *  Maximum frame_num allowed
750*495ae853SAndroid Build Coastguard Worker *
751*495ae853SAndroid Build Coastguard Worker * @returns
752*495ae853SAndroid Build Coastguard Worker *
753*495ae853SAndroid Build Coastguard Worker * @remarks
754*495ae853SAndroid Build Coastguard Worker *
755*495ae853SAndroid Build Coastguard Worker *******************************************************************************
756*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_count_ref_frames(dpb_mgr_t * ps_dpb_mgr,WORD32 curr_frame_num,WORD32 max_frame_num)757*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_count_ref_frames(dpb_mgr_t *ps_dpb_mgr,
758*495ae853SAndroid Build Coastguard Worker                                       WORD32 curr_frame_num,
759*495ae853SAndroid Build Coastguard Worker                                       WORD32 max_frame_num)
760*495ae853SAndroid Build Coastguard Worker {
761*495ae853SAndroid Build Coastguard Worker     WORD32 numShortTerm = 0;
762*495ae853SAndroid Build Coastguard Worker     WORD32 numLongTerm = 0;
763*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node;
764*495ae853SAndroid Build Coastguard Worker     WORD32 frame_num;
765*495ae853SAndroid Build Coastguard Worker     WORD32 prev_frame_num;
766*495ae853SAndroid Build Coastguard Worker 
767*495ae853SAndroid Build Coastguard Worker     /*
768*495ae853SAndroid Build Coastguard Worker      * Compute the number of short-term frames/complementary field pairs/
769*495ae853SAndroid Build Coastguard Worker      * unpaired fields
770*495ae853SAndroid Build Coastguard Worker      */
771*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_mgr->ps_dpb_short_term_head != NULL)
772*495ae853SAndroid Build Coastguard Worker     {
773*495ae853SAndroid Build Coastguard Worker         /* Sort the short-term list by frame_num */
774*495ae853SAndroid Build Coastguard Worker         ih264_dpb_mgr_sort_short_term_fields_by_frame_num(ps_dpb_mgr,
775*495ae853SAndroid Build Coastguard Worker                                                         curr_frame_num,
776*495ae853SAndroid Build Coastguard Worker                                                         TOP_FIELD,
777*495ae853SAndroid Build Coastguard Worker                                                         max_frame_num);
778*495ae853SAndroid Build Coastguard Worker 
779*495ae853SAndroid Build Coastguard Worker         ps_dpb_node = ps_dpb_mgr->ps_dpb_short_term_head;
780*495ae853SAndroid Build Coastguard Worker         if(ps_dpb_node != NULL)
781*495ae853SAndroid Build Coastguard Worker         {
782*495ae853SAndroid Build Coastguard Worker             numShortTerm++;
783*495ae853SAndroid Build Coastguard Worker             prev_frame_num = ps_dpb_node->ps_pic_buf->i4_frame_num;
784*495ae853SAndroid Build Coastguard Worker             ps_dpb_node = ps_dpb_node->ps_prev_dpb;
785*495ae853SAndroid Build Coastguard Worker         }
786*495ae853SAndroid Build Coastguard Worker 
787*495ae853SAndroid Build Coastguard Worker         while(ps_dpb_node != NULL)
788*495ae853SAndroid Build Coastguard Worker         {
789*495ae853SAndroid Build Coastguard Worker             frame_num = ps_dpb_node->ps_pic_buf->i4_frame_num;
790*495ae853SAndroid Build Coastguard Worker             if(frame_num != prev_frame_num)
791*495ae853SAndroid Build Coastguard Worker                 numShortTerm++;
792*495ae853SAndroid Build Coastguard Worker             prev_frame_num = ps_dpb_node->ps_pic_buf->i4_frame_num;
793*495ae853SAndroid Build Coastguard Worker             ps_dpb_node = ps_dpb_node->ps_prev_dpb;
794*495ae853SAndroid Build Coastguard Worker         }
795*495ae853SAndroid Build Coastguard Worker     }
796*495ae853SAndroid Build Coastguard Worker 
797*495ae853SAndroid Build Coastguard Worker     /*
798*495ae853SAndroid Build Coastguard Worker      * Compute the number of long-term frames/complementary field pairs/
799*495ae853SAndroid Build Coastguard Worker      * unpaired fields
800*495ae853SAndroid Build Coastguard Worker      */
801*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_mgr->ps_dpb_long_term_head != NULL)
802*495ae853SAndroid Build Coastguard Worker     {
803*495ae853SAndroid Build Coastguard Worker         ih264_dpb_mgr_sort_long_term_fields_by_frame_idx(ps_dpb_mgr,
804*495ae853SAndroid Build Coastguard Worker                                                         TOP_FIELD);
805*495ae853SAndroid Build Coastguard Worker 
806*495ae853SAndroid Build Coastguard Worker         ps_dpb_node = ps_dpb_mgr->ps_dpb_long_term_head;
807*495ae853SAndroid Build Coastguard Worker         if(ps_dpb_node != NULL)
808*495ae853SAndroid Build Coastguard Worker         {
809*495ae853SAndroid Build Coastguard Worker             numLongTerm++;
810*495ae853SAndroid Build Coastguard Worker             prev_frame_num = ps_dpb_node->ps_pic_buf->i4_frame_num;
811*495ae853SAndroid Build Coastguard Worker             ps_dpb_node = ps_dpb_node->ps_prev_dpb;
812*495ae853SAndroid Build Coastguard Worker         }
813*495ae853SAndroid Build Coastguard Worker 
814*495ae853SAndroid Build Coastguard Worker         while(ps_dpb_node != NULL)
815*495ae853SAndroid Build Coastguard Worker         {
816*495ae853SAndroid Build Coastguard Worker             frame_num = ps_dpb_node->ps_pic_buf->i4_frame_num;
817*495ae853SAndroid Build Coastguard Worker             if(frame_num != prev_frame_num)
818*495ae853SAndroid Build Coastguard Worker                 numLongTerm++;
819*495ae853SAndroid Build Coastguard Worker             prev_frame_num = ps_dpb_node->ps_pic_buf->i4_frame_num;
820*495ae853SAndroid Build Coastguard Worker             ps_dpb_node = ps_dpb_node->ps_prev_dpb;
821*495ae853SAndroid Build Coastguard Worker         }
822*495ae853SAndroid Build Coastguard Worker     }
823*495ae853SAndroid Build Coastguard Worker     return (numShortTerm + numLongTerm);
824*495ae853SAndroid Build Coastguard Worker }
825*495ae853SAndroid Build Coastguard Worker 
826*495ae853SAndroid Build Coastguard Worker /**
827*495ae853SAndroid Build Coastguard Worker *******************************************************************************
828*495ae853SAndroid Build Coastguard Worker *
829*495ae853SAndroid Build Coastguard Worker * @brief
830*495ae853SAndroid Build Coastguard Worker *  Deletes the ref frame at the end of the linked list.
831*495ae853SAndroid Build Coastguard Worker *
832*495ae853SAndroid Build Coastguard Worker * @par Description:
833*495ae853SAndroid Build Coastguard Worker *  Deletes the ref frame at the end of the linked list. For unpaired fields,
834*495ae853SAndroid Build Coastguard Worker *  it deletes just the last node. For frame or complementary field pair, it
835*495ae853SAndroid Build Coastguard Worker *  deletes the last two nodes.
836*495ae853SAndroid Build Coastguard Worker *
837*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
838*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
839*495ae853SAndroid Build Coastguard Worker *
840*495ae853SAndroid Build Coastguard Worker * @param[in] reference_type
841*495ae853SAndroid Build Coastguard Worker *  This is used to select between short-term and long-term linked list.
842*495ae853SAndroid Build Coastguard Worker *
843*495ae853SAndroid Build Coastguard Worker * @returns
844*495ae853SAndroid Build Coastguard Worker *
845*495ae853SAndroid Build Coastguard Worker * @remarks
846*495ae853SAndroid Build Coastguard Worker *
847*495ae853SAndroid Build Coastguard Worker *******************************************************************************
848*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_delete_ref_frame(dpb_mgr_t * ps_dpb_mgr,WORD32 reference_type)849*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_delete_ref_frame(dpb_mgr_t *ps_dpb_mgr,
850*495ae853SAndroid Build Coastguard Worker                                       WORD32 reference_type)
851*495ae853SAndroid Build Coastguard Worker {
852*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node1;
853*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node2;
854*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node3;
855*495ae853SAndroid Build Coastguard Worker 
856*495ae853SAndroid Build Coastguard Worker     /*
857*495ae853SAndroid Build Coastguard Worker      * Assumption: The nodes sorted for frame num.
858*495ae853SAndroid Build Coastguard Worker      */
859*495ae853SAndroid Build Coastguard Worker     /* Select bw short-term and long-term list. */
860*495ae853SAndroid Build Coastguard Worker     ps_dpb_node1 = (reference_type == SHORT_TERM_REF)
861*495ae853SAndroid Build Coastguard Worker                     ?ps_dpb_mgr->ps_dpb_short_term_head
862*495ae853SAndroid Build Coastguard Worker                     :ps_dpb_mgr->ps_dpb_long_term_head;
863*495ae853SAndroid Build Coastguard Worker     /* If null, no entries in the list. Hence return. */
864*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node1 == NULL)
865*495ae853SAndroid Build Coastguard Worker         return 0;
866*495ae853SAndroid Build Coastguard Worker 
867*495ae853SAndroid Build Coastguard Worker     /* If only one node in the list, set as unsed for refer and return. */
868*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node1->ps_prev_dpb == NULL)
869*495ae853SAndroid Build Coastguard Worker     {
870*495ae853SAndroid Build Coastguard Worker         /* Set the picture as unused for reference */
871*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1->ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
872*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1->ps_pic_buf = NULL;
873*495ae853SAndroid Build Coastguard Worker 
874*495ae853SAndroid Build Coastguard Worker         if(reference_type == SHORT_TERM_REF)
875*495ae853SAndroid Build Coastguard Worker         {
876*495ae853SAndroid Build Coastguard Worker             ps_dpb_mgr->ps_dpb_short_term_head = NULL;
877*495ae853SAndroid Build Coastguard Worker 
878*495ae853SAndroid Build Coastguard Worker             /* Increment Short term buffer count */
879*495ae853SAndroid Build Coastguard Worker             ps_dpb_mgr->u1_num_short_term_ref_bufs = 0;
880*495ae853SAndroid Build Coastguard Worker 
881*495ae853SAndroid Build Coastguard Worker         }
882*495ae853SAndroid Build Coastguard Worker         else
883*495ae853SAndroid Build Coastguard Worker         {
884*495ae853SAndroid Build Coastguard Worker             ps_dpb_mgr->ps_dpb_long_term_head = NULL;
885*495ae853SAndroid Build Coastguard Worker 
886*495ae853SAndroid Build Coastguard Worker             /* Increment Long term buffer count */
887*495ae853SAndroid Build Coastguard Worker             ps_dpb_mgr->u1_num_long_term_ref_bufs = 0;
888*495ae853SAndroid Build Coastguard Worker 
889*495ae853SAndroid Build Coastguard Worker         }
890*495ae853SAndroid Build Coastguard Worker         return 0;
891*495ae853SAndroid Build Coastguard Worker     }
892*495ae853SAndroid Build Coastguard Worker 
893*495ae853SAndroid Build Coastguard Worker     /**
894*495ae853SAndroid Build Coastguard Worker      * If there are only 2 nodes in the list, set second node as unused for reference.
895*495ae853SAndroid Build Coastguard Worker      * If the frame_num of second node and first node is same, set first node also as
896*495ae853SAndroid Build Coastguard Worker      * unused for reference and set the corresponding head to NULL.
897*495ae853SAndroid Build Coastguard Worker      */
898*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
899*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node2->ps_prev_dpb == NULL)
900*495ae853SAndroid Build Coastguard Worker     {
901*495ae853SAndroid Build Coastguard Worker         /* Set the picture as unused for reference */
902*495ae853SAndroid Build Coastguard Worker         if(ps_dpb_node2->ps_pic_buf->i4_frame_num == ps_dpb_node1->ps_pic_buf->i4_frame_num)
903*495ae853SAndroid Build Coastguard Worker         {
904*495ae853SAndroid Build Coastguard Worker             /* Set the picture as unused for reference */
905*495ae853SAndroid Build Coastguard Worker             ps_dpb_node1->ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
906*495ae853SAndroid Build Coastguard Worker             ps_dpb_node1->ps_pic_buf = NULL;
907*495ae853SAndroid Build Coastguard Worker             if(reference_type == SHORT_TERM_REF)
908*495ae853SAndroid Build Coastguard Worker             {
909*495ae853SAndroid Build Coastguard Worker                 ps_dpb_mgr->ps_dpb_short_term_head = NULL;
910*495ae853SAndroid Build Coastguard Worker 
911*495ae853SAndroid Build Coastguard Worker                 /* Increment Short term buffer count */
912*495ae853SAndroid Build Coastguard Worker                 ps_dpb_mgr->u1_num_short_term_ref_bufs = 0;
913*495ae853SAndroid Build Coastguard Worker 
914*495ae853SAndroid Build Coastguard Worker             }
915*495ae853SAndroid Build Coastguard Worker             else
916*495ae853SAndroid Build Coastguard Worker             {
917*495ae853SAndroid Build Coastguard Worker                 ps_dpb_mgr->ps_dpb_long_term_head = NULL;
918*495ae853SAndroid Build Coastguard Worker 
919*495ae853SAndroid Build Coastguard Worker                 /* Increment Long term buffer count */
920*495ae853SAndroid Build Coastguard Worker                 ps_dpb_mgr->u1_num_long_term_ref_bufs = 0;
921*495ae853SAndroid Build Coastguard Worker 
922*495ae853SAndroid Build Coastguard Worker             }
923*495ae853SAndroid Build Coastguard Worker 
924*495ae853SAndroid Build Coastguard Worker         }
925*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2->ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
926*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2->ps_pic_buf = NULL;
927*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1->ps_prev_dpb = NULL;
928*495ae853SAndroid Build Coastguard Worker         return 0;
929*495ae853SAndroid Build Coastguard Worker     }
930*495ae853SAndroid Build Coastguard Worker     /*
931*495ae853SAndroid Build Coastguard Worker      * If there are more than 2 nodes, run a loop to get the last 3 nodes.
932*495ae853SAndroid Build Coastguard Worker      */
933*495ae853SAndroid Build Coastguard Worker     ps_dpb_node3 = ps_dpb_node2->ps_prev_dpb;
934*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_node3->ps_prev_dpb != NULL)
935*495ae853SAndroid Build Coastguard Worker     {
936*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1 = ps_dpb_node2;
937*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2 = ps_dpb_node3;
938*495ae853SAndroid Build Coastguard Worker         ps_dpb_node3 = ps_dpb_node3->ps_prev_dpb;
939*495ae853SAndroid Build Coastguard Worker     }
940*495ae853SAndroid Build Coastguard Worker     /*
941*495ae853SAndroid Build Coastguard Worker      * If node 2 and node 3 frame_nums are same, set node 2 also as unsed for
942*495ae853SAndroid Build Coastguard Worker      * reference and del reference from node1.
943*495ae853SAndroid Build Coastguard Worker      */
944*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node2->ps_pic_buf->i4_frame_num == ps_dpb_node3->ps_pic_buf->i4_frame_num)
945*495ae853SAndroid Build Coastguard Worker     {
946*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2->ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
947*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2->ps_pic_buf = NULL;
948*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1->ps_prev_dpb = NULL;
949*495ae853SAndroid Build Coastguard Worker 
950*495ae853SAndroid Build Coastguard Worker     }
951*495ae853SAndroid Build Coastguard Worker     /* Set the third node as unused for reference */
952*495ae853SAndroid Build Coastguard Worker     ps_dpb_node3->ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
953*495ae853SAndroid Build Coastguard Worker     ps_dpb_node3->ps_pic_buf = NULL;
954*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2->ps_prev_dpb = NULL;
955*495ae853SAndroid Build Coastguard Worker 
956*495ae853SAndroid Build Coastguard Worker     return 0;
957*495ae853SAndroid Build Coastguard Worker }
958*495ae853SAndroid Build Coastguard Worker 
959*495ae853SAndroid Build Coastguard Worker /**
960*495ae853SAndroid Build Coastguard Worker *******************************************************************************
961*495ae853SAndroid Build Coastguard Worker *
962*495ae853SAndroid Build Coastguard Worker * @brief
963*495ae853SAndroid Build Coastguard Worker *  Delete long-term ref fields above max frame idx.
964*495ae853SAndroid Build Coastguard Worker *
965*495ae853SAndroid Build Coastguard Worker * @par Description:
966*495ae853SAndroid Build Coastguard Worker *  Deletes all the long-term ref fields having idx greater than max_frame_idx
967*495ae853SAndroid Build Coastguard Worker *
968*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
969*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
970*495ae853SAndroid Build Coastguard Worker *
971*495ae853SAndroid Build Coastguard Worker * @param[in] max_frame_idx
972*495ae853SAndroid Build Coastguard Worker *  Max long-term frame idx allowed.
973*495ae853SAndroid Build Coastguard Worker *
974*495ae853SAndroid Build Coastguard Worker * @returns
975*495ae853SAndroid Build Coastguard Worker *
976*495ae853SAndroid Build Coastguard Worker * @remarks
977*495ae853SAndroid Build Coastguard Worker *
978*495ae853SAndroid Build Coastguard Worker *******************************************************************************
979*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_delete_long_ref_fields_max_frame_idx(dpb_mgr_t * ps_dpb_mgr,WORD32 max_frame_idx)980*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_delete_long_ref_fields_max_frame_idx(dpb_mgr_t *ps_dpb_mgr,
981*495ae853SAndroid Build Coastguard Worker                                                           WORD32 max_frame_idx)
982*495ae853SAndroid Build Coastguard Worker {
983*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node1;
984*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_node2;
985*495ae853SAndroid Build Coastguard Worker 
986*495ae853SAndroid Build Coastguard Worker     /*
987*495ae853SAndroid Build Coastguard Worker      * Loop until there is node which isn't to be deleted is encountered.
988*495ae853SAndroid Build Coastguard Worker      */
989*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_mgr->ps_dpb_long_term_head != NULL)
990*495ae853SAndroid Build Coastguard Worker     {
991*495ae853SAndroid Build Coastguard Worker         if(ps_dpb_mgr->ps_dpb_long_term_head->ps_pic_buf->i4_long_term_frame_idx
992*495ae853SAndroid Build Coastguard Worker                         <= max_frame_idx)
993*495ae853SAndroid Build Coastguard Worker         {
994*495ae853SAndroid Build Coastguard Worker             break;
995*495ae853SAndroid Build Coastguard Worker         }
996*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->ps_dpb_long_term_head->ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
997*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->ps_dpb_long_term_head->ps_pic_buf = NULL;
998*495ae853SAndroid Build Coastguard Worker         ps_dpb_mgr->ps_dpb_long_term_head = ps_dpb_mgr->ps_dpb_long_term_head->ps_prev_dpb;
999*495ae853SAndroid Build Coastguard Worker     }
1000*495ae853SAndroid Build Coastguard Worker 
1001*495ae853SAndroid Build Coastguard Worker     ps_dpb_node1 = ps_dpb_mgr->ps_dpb_long_term_head;
1002*495ae853SAndroid Build Coastguard Worker     if(ps_dpb_node1 == NULL)
1003*495ae853SAndroid Build Coastguard Worker         return 0;
1004*495ae853SAndroid Build Coastguard Worker     /*
1005*495ae853SAndroid Build Coastguard Worker      * With the node that isn't to be deleted as head, loop until the end.
1006*495ae853SAndroid Build Coastguard Worker      */
1007*495ae853SAndroid Build Coastguard Worker     ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
1008*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_node2 != NULL)
1009*495ae853SAndroid Build Coastguard Worker     {
1010*495ae853SAndroid Build Coastguard Worker         if(ps_dpb_node2->ps_pic_buf->i4_long_term_frame_idx > max_frame_idx)
1011*495ae853SAndroid Build Coastguard Worker         {
1012*495ae853SAndroid Build Coastguard Worker             ps_dpb_node2->ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
1013*495ae853SAndroid Build Coastguard Worker             ps_dpb_node2->ps_pic_buf = NULL;
1014*495ae853SAndroid Build Coastguard Worker             ps_dpb_node1->ps_prev_dpb = ps_dpb_node2->ps_prev_dpb;
1015*495ae853SAndroid Build Coastguard Worker         }
1016*495ae853SAndroid Build Coastguard Worker         ps_dpb_node1 = ps_dpb_node1->ps_prev_dpb;
1017*495ae853SAndroid Build Coastguard Worker         if(ps_dpb_node1 == NULL)
1018*495ae853SAndroid Build Coastguard Worker             break;
1019*495ae853SAndroid Build Coastguard Worker         ps_dpb_node2 = ps_dpb_node1->ps_prev_dpb;
1020*495ae853SAndroid Build Coastguard Worker     }
1021*495ae853SAndroid Build Coastguard Worker     return 0;
1022*495ae853SAndroid Build Coastguard Worker }
1023*495ae853SAndroid Build Coastguard Worker 
1024*495ae853SAndroid Build Coastguard Worker /**
1025*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1026*495ae853SAndroid Build Coastguard Worker *
1027*495ae853SAndroid Build Coastguard Worker * @brief
1028*495ae853SAndroid Build Coastguard Worker *  Deletes the short-term with least frame_num
1029*495ae853SAndroid Build Coastguard Worker *
1030*495ae853SAndroid Build Coastguard Worker * @par Description:
1031*495ae853SAndroid Build Coastguard Worker *  Deletes the short-term with least frame_num. It sorts the function the
1032*495ae853SAndroid Build Coastguard Worker *  short-term linked list by frame-num and the function that deletes the last
1033*495ae853SAndroid Build Coastguard Worker *  frame in the linked list.
1034*495ae853SAndroid Build Coastguard Worker *
1035*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
1036*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
1037*495ae853SAndroid Build Coastguard Worker *
1038*495ae853SAndroid Build Coastguard Worker * @param[in] curr_frame_num
1039*495ae853SAndroid Build Coastguard Worker *  frame_num of the current pic
1040*495ae853SAndroid Build Coastguard Worker *
1041*495ae853SAndroid Build Coastguard Worker * @param[in] max_frame_num
1042*495ae853SAndroid Build Coastguard Worker *  Maximum frame_num allowed
1043*495ae853SAndroid Build Coastguard Worker *
1044*495ae853SAndroid Build Coastguard Worker * @returns
1045*495ae853SAndroid Build Coastguard Worker *
1046*495ae853SAndroid Build Coastguard Worker * @remarks
1047*495ae853SAndroid Build Coastguard Worker *
1048*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1049*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_delete_short_ref_frame(dpb_mgr_t * ps_dpb_mgr,WORD32 curr_frame_num,WORD32 max_frame_num)1050*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_delete_short_ref_frame(dpb_mgr_t *ps_dpb_mgr,
1051*495ae853SAndroid Build Coastguard Worker                                             WORD32 curr_frame_num,
1052*495ae853SAndroid Build Coastguard Worker                                             WORD32 max_frame_num)
1053*495ae853SAndroid Build Coastguard Worker {
1054*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
1055*495ae853SAndroid Build Coastguard Worker 
1056*495ae853SAndroid Build Coastguard Worker     /* Sort the short-term list by frame_num */
1057*495ae853SAndroid Build Coastguard Worker     ret = ih264_dpb_mgr_sort_short_term_fields_by_frame_num(ps_dpb_mgr,
1058*495ae853SAndroid Build Coastguard Worker                                                           curr_frame_num,
1059*495ae853SAndroid Build Coastguard Worker                                                           TOP_FIELD,
1060*495ae853SAndroid Build Coastguard Worker                                                           max_frame_num);
1061*495ae853SAndroid Build Coastguard Worker 
1062*495ae853SAndroid Build Coastguard Worker     /* Delete the last reference frame or field */
1063*495ae853SAndroid Build Coastguard Worker     ret = ih264_dpb_mgr_delete_ref_frame(ps_dpb_mgr,SHORT_TERM_REF);
1064*495ae853SAndroid Build Coastguard Worker 
1065*495ae853SAndroid Build Coastguard Worker     if(ret != 0)
1066*495ae853SAndroid Build Coastguard Worker     {
1067*495ae853SAndroid Build Coastguard Worker         ASSERT(0);
1068*495ae853SAndroid Build Coastguard Worker     }
1069*495ae853SAndroid Build Coastguard Worker 
1070*495ae853SAndroid Build Coastguard Worker     return ret;
1071*495ae853SAndroid Build Coastguard Worker }
1072*495ae853SAndroid Build Coastguard Worker 
1073*495ae853SAndroid Build Coastguard Worker /**
1074*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1075*495ae853SAndroid Build Coastguard Worker *
1076*495ae853SAndroid Build Coastguard Worker * @brief
1077*495ae853SAndroid Build Coastguard Worker *  Deletes all the ref frames.
1078*495ae853SAndroid Build Coastguard Worker *
1079*495ae853SAndroid Build Coastguard Worker * @par Description:
1080*495ae853SAndroid Build Coastguard Worker *  Deletes all of the ref frames/fields in the short-term and long-term linked
1081*495ae853SAndroid Build Coastguard Worker *  list.
1082*495ae853SAndroid Build Coastguard Worker *
1083*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
1084*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
1085*495ae853SAndroid Build Coastguard Worker *
1086*495ae853SAndroid Build Coastguard Worker * @returns
1087*495ae853SAndroid Build Coastguard Worker *
1088*495ae853SAndroid Build Coastguard Worker * @remarks
1089*495ae853SAndroid Build Coastguard Worker *
1090*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1091*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_delete_all_ref_frames(dpb_mgr_t * ps_dpb_mgr)1092*495ae853SAndroid Build Coastguard Worker WORD32 ih264_dpb_mgr_delete_all_ref_frames(dpb_mgr_t *ps_dpb_mgr)
1093*495ae853SAndroid Build Coastguard Worker {
1094*495ae853SAndroid Build Coastguard Worker     /* Loop over short-term linked list. */
1095*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_mgr->ps_dpb_short_term_head != NULL)
1096*495ae853SAndroid Build Coastguard Worker     {
1097*495ae853SAndroid Build Coastguard Worker         ih264_dpb_mgr_delete_ref_frame(ps_dpb_mgr,SHORT_TERM_REF);
1098*495ae853SAndroid Build Coastguard Worker     }
1099*495ae853SAndroid Build Coastguard Worker 
1100*495ae853SAndroid Build Coastguard Worker     /* Loop over long-term linked list. */
1101*495ae853SAndroid Build Coastguard Worker     while(ps_dpb_mgr->ps_dpb_long_term_head != NULL)
1102*495ae853SAndroid Build Coastguard Worker     {
1103*495ae853SAndroid Build Coastguard Worker         ih264_dpb_mgr_delete_ref_frame(ps_dpb_mgr,LONG_TERM_REF);
1104*495ae853SAndroid Build Coastguard Worker     }
1105*495ae853SAndroid Build Coastguard Worker     return 0;
1106*495ae853SAndroid Build Coastguard Worker }
1107*495ae853SAndroid Build Coastguard Worker 
1108*495ae853SAndroid Build Coastguard Worker /**
1109*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1110*495ae853SAndroid Build Coastguard Worker *
1111*495ae853SAndroid Build Coastguard Worker * @brief
1112*495ae853SAndroid Build Coastguard Worker *  deletes all pictures from DPB and reset dpb
1113*495ae853SAndroid Build Coastguard Worker *
1114*495ae853SAndroid Build Coastguard Worker * @par Description:
1115*495ae853SAndroid Build Coastguard Worker *  deletes all pictures from DPB and reset dpb
1116*495ae853SAndroid Build Coastguard Worker *
1117*495ae853SAndroid Build Coastguard Worker * @param[in] ps_dpb_mgr
1118*495ae853SAndroid Build Coastguard Worker *  Pointer to the DPB manager structure
1119*495ae853SAndroid Build Coastguard Worker *
1120*495ae853SAndroid Build Coastguard Worker * @param[in] ps_buf_mgr
1121*495ae853SAndroid Build Coastguard Worker *  Pointer to buffer manager structure
1122*495ae853SAndroid Build Coastguard Worker *
1123*495ae853SAndroid Build Coastguard Worker * @returns
1124*495ae853SAndroid Build Coastguard Worker *
1125*495ae853SAndroid Build Coastguard Worker * @remarks
1126*495ae853SAndroid Build Coastguard Worker *
1127*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1128*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_reset(dpb_mgr_t * ps_dpb_mgr,buf_mgr_t * ps_buf_mgr)1129*495ae853SAndroid Build Coastguard Worker void ih264_dpb_mgr_reset(dpb_mgr_t *ps_dpb_mgr, buf_mgr_t *ps_buf_mgr)
1130*495ae853SAndroid Build Coastguard Worker {
1131*495ae853SAndroid Build Coastguard Worker     WORD32 i;
1132*495ae853SAndroid Build Coastguard Worker     dpb_info_t *ps_dpb_info;
1133*495ae853SAndroid Build Coastguard Worker 
1134*495ae853SAndroid Build Coastguard Worker     ASSERT(0);
1135*495ae853SAndroid Build Coastguard Worker     ps_dpb_info = ps_dpb_mgr->as_dpb_info;
1136*495ae853SAndroid Build Coastguard Worker     for(i = 0; i < MAX_DPB_BUFS; i++)
1137*495ae853SAndroid Build Coastguard Worker     {
1138*495ae853SAndroid Build Coastguard Worker         if(ps_dpb_info[i].ps_pic_buf->i4_used_as_ref)
1139*495ae853SAndroid Build Coastguard Worker         {
1140*495ae853SAndroid Build Coastguard Worker             ps_dpb_info[i].ps_pic_buf->i4_used_as_ref = UNUSED_FOR_REF;
1141*495ae853SAndroid Build Coastguard Worker             ps_dpb_info[i].ps_prev_dpb = NULL;
1142*495ae853SAndroid Build Coastguard Worker             // Release physical buffer
1143*495ae853SAndroid Build Coastguard Worker             ih264_buf_mgr_release(ps_buf_mgr, ps_dpb_info[i].ps_pic_buf->i4_buf_id,
1144*495ae853SAndroid Build Coastguard Worker                                   BUF_MGR_REF);
1145*495ae853SAndroid Build Coastguard Worker 
1146*495ae853SAndroid Build Coastguard Worker             ps_dpb_info[i].ps_pic_buf = NULL;
1147*495ae853SAndroid Build Coastguard Worker         }
1148*495ae853SAndroid Build Coastguard Worker     }
1149*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->u1_num_short_term_ref_bufs = 0;
1150*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->u1_num_long_term_ref_bufs  = 0;
1151*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->ps_dpb_short_term_head = NULL;
1152*495ae853SAndroid Build Coastguard Worker     ps_dpb_mgr->ps_dpb_long_term_head  = NULL;
1153*495ae853SAndroid Build Coastguard Worker }
1154*495ae853SAndroid Build Coastguard Worker 
1155*495ae853SAndroid Build Coastguard Worker /**
1156*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1157*495ae853SAndroid Build Coastguard Worker *
1158*495ae853SAndroid Build Coastguard Worker * @brief
1159*495ae853SAndroid Build Coastguard Worker *  deletes all pictures from DPB
1160*495ae853SAndroid Build Coastguard Worker *
1161*495ae853SAndroid Build Coastguard Worker * @par Description:
1162*495ae853SAndroid Build Coastguard Worker *  Deletes all pictures present in the DPB manager
1163*495ae853SAndroid Build Coastguard Worker *
1164*495ae853SAndroid Build Coastguard Worker * @param[in] ps_buf_mgr
1165*495ae853SAndroid Build Coastguard Worker *  Pointer to buffer manager structure
1166*495ae853SAndroid Build Coastguard Worker *
1167*495ae853SAndroid Build Coastguard Worker * @param[in] u1_disp_bufs
1168*495ae853SAndroid Build Coastguard Worker *  Number of buffers to be deleted
1169*495ae853SAndroid Build Coastguard Worker *
1170*495ae853SAndroid Build Coastguard Worker * @returns
1171*495ae853SAndroid Build Coastguard Worker *
1172*495ae853SAndroid Build Coastguard Worker * @remarks
1173*495ae853SAndroid Build Coastguard Worker *
1174*495ae853SAndroid Build Coastguard Worker *******************************************************************************
1175*495ae853SAndroid Build Coastguard Worker */
ih264_dpb_mgr_release_pics(buf_mgr_t * ps_buf_mgr,UWORD8 u1_disp_bufs)1176*495ae853SAndroid Build Coastguard Worker void ih264_dpb_mgr_release_pics(buf_mgr_t *ps_buf_mgr, UWORD8 u1_disp_bufs)
1177*495ae853SAndroid Build Coastguard Worker {
1178*495ae853SAndroid Build Coastguard Worker     WORD8 i;
1179*495ae853SAndroid Build Coastguard Worker     UWORD32 buf_status;
1180*495ae853SAndroid Build Coastguard Worker 
1181*495ae853SAndroid Build Coastguard Worker     ASSERT(0);
1182*495ae853SAndroid Build Coastguard Worker     for(i = 0; i < u1_disp_bufs; i++)
1183*495ae853SAndroid Build Coastguard Worker     {
1184*495ae853SAndroid Build Coastguard Worker         buf_status = ih264_buf_mgr_get_status(ps_buf_mgr, i);
1185*495ae853SAndroid Build Coastguard Worker         if(0 != buf_status)
1186*495ae853SAndroid Build Coastguard Worker         {
1187*495ae853SAndroid Build Coastguard Worker             ih264_buf_mgr_release((buf_mgr_t *)ps_buf_mgr, i, BUF_MGR_REF);
1188*495ae853SAndroid Build Coastguard Worker         }
1189*495ae853SAndroid Build Coastguard Worker     }
1190*495ae853SAndroid Build Coastguard Worker }
1191