• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 /*****************************************************************************/
22 /* File Includes                                                             */
23 /*****************************************************************************/
24 
25 /* System include files */
26 
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <assert.h>
30 #include <string.h>
31 /* User include files */
32 
33 #include "ih264_typedefs.h"
34 #include "ih264_defs.h"
35 #include "iv2.h"
36 #include "ive2.h"
37 #include "ih264e.h"
38 #include "app.h"
39 
40 /*****************************************************************************/
41 /* Constant Macros                                                           */
42 /*****************************************************************************/
43 
44 
45 /*****************************************************************************/
46 /*  Macros                                                                   */
47 /*****************************************************************************/
48 
49 
50 /*****************************************************************************/
51 /*  Function Declarations                                                    */
52 /*****************************************************************************/
53 
write_recon(FILE * fp,iv_raw_buf_t * ps_raw_buf)54 IV_STATUS_T write_recon(FILE *fp, iv_raw_buf_t *ps_raw_buf)
55 {
56     WORD32 bytes;
57     WORD32 wd, ht;
58     UWORD8 *pu1_buf;
59     WORD32 i;
60     WORD32 comp;
61     WORD32 num_comp;
62 
63     num_comp = 2;
64     if(IV_YUV_420P == ps_raw_buf->e_color_fmt)
65         num_comp = 3;
66 
67     for(comp = 0; comp < num_comp; comp++)
68     {
69         wd = ps_raw_buf->au4_wd[comp];
70         ht = ps_raw_buf->au4_ht[comp];
71         pu1_buf = ps_raw_buf->apv_bufs[comp];
72         for(i = 0; i < ht; i++)
73         {
74             bytes = fwrite(pu1_buf, sizeof(UWORD8), wd, fp);
75             if(bytes != wd)
76             {
77                 return(IV_FAIL);
78             }
79             pu1_buf += wd;
80         }
81     }
82 
83     fflush(fp);
84     return IV_SUCCESS;
85 }
allocate_recon(app_ctxt_t * ps_app_ctxt)86 void allocate_recon(app_ctxt_t *ps_app_ctxt)
87 {
88 
89     WORD32 num_bufs;
90     WORD32 pic_size;
91     WORD32 luma_size;
92     WORD32 chroma_size;
93     WORD32 i;
94     UWORD8 *pu1_buf;
95 
96     num_bufs = DEFAULT_NUM_RECON_BUFS;
97 
98     /* Size of buffer for YUV420/420SP */
99     luma_size = ps_app_ctxt->u4_max_wd * ps_app_ctxt->u4_max_ht;
100     chroma_size = (luma_size) / 4;
101     pic_size = luma_size + chroma_size * 2;
102 
103 
104     for(i = 0; i < num_bufs; i++)
105     {
106         pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, pic_size);
107         if(NULL == pu1_buf)
108         {
109             CHAR ac_error[STRLENGTH];
110             sprintf(ac_error, "Allocation failed for recon buffer of size %d\n",
111                     pic_size);
112             codec_exit(ac_error);
113         }
114         ps_app_ctxt->as_recon_buf[i].pu1_buf = pu1_buf;
115         ps_app_ctxt->as_recon_buf[i].u4_buf_size = pic_size;
116         ps_app_ctxt->as_recon_buf[i].u4_is_free = 1;
117     }
118 
119     if(ps_app_ctxt->u4_psnr_enable)
120     {
121         pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, pic_size);
122         if(NULL == pu1_buf)
123         {
124             CHAR ac_error[STRLENGTH];
125             sprintf(ac_error, "Allocation failed for recon buffer of size %d\n",
126                     pic_size);
127             codec_exit(ac_error);
128         }
129         ps_app_ctxt->pu1_psnr_buf = pu1_buf;
130         ps_app_ctxt->u4_psnr_buf_size = pic_size;
131     }
132     return;
133 }
134 
free_recon(app_ctxt_t * ps_app_ctxt)135 void free_recon(app_ctxt_t *ps_app_ctxt)
136 {
137 
138     WORD32 num_bufs;
139     WORD32 i;
140 
141     num_bufs = DEFAULT_NUM_RECON_BUFS;
142 
143     for(i = 0; i < num_bufs; i++)
144     {
145         ih264a_aligned_free(ps_app_ctxt->as_recon_buf[i].pu1_buf);
146     }
147 
148     if(ps_app_ctxt->u4_psnr_enable)
149     {
150         ih264a_aligned_free(ps_app_ctxt->pu1_psnr_buf);
151 
152     }
153     return;
154 }
155 
156 
157 
init_raw_buf_descr(app_ctxt_t * ps_app_ctxt,iv_raw_buf_t * ps_raw_buf,UWORD8 * pu1_buf,IV_COLOR_FORMAT_T e_color_fmt)158 void init_raw_buf_descr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_raw_buf, UWORD8 *pu1_buf, IV_COLOR_FORMAT_T e_color_fmt)
159 {
160     WORD32 luma_size;
161     WORD32 chroma_size;
162 
163     /* All the pointers and dimensions are initialized here
164      * to support change in resolution from the application */
165     luma_size = ps_app_ctxt->u4_max_wd * ps_app_ctxt->u4_max_ht;
166     chroma_size = (luma_size) / 4;
167 
168     ps_raw_buf->apv_bufs[0] = pu1_buf;
169     pu1_buf += luma_size;
170 
171     ps_raw_buf->apv_bufs[1] = pu1_buf;
172     pu1_buf += chroma_size;
173 
174     ps_raw_buf->apv_bufs[2] = NULL;
175     if(IV_YUV_420P == e_color_fmt)
176     {
177         ps_raw_buf->apv_bufs[2] = pu1_buf;
178     }
179 
180     ps_raw_buf->e_color_fmt = e_color_fmt;
181     ps_raw_buf->au4_wd[0] =  ps_app_ctxt->u4_wd;
182     ps_raw_buf->au4_ht[0] =  ps_app_ctxt->u4_ht;
183     ps_raw_buf->au4_strd[0] =  ps_app_ctxt->u4_wd;
184 
185     /* Initialize for 420SP */
186     {
187         ps_raw_buf->au4_wd[1] =  ps_app_ctxt->u4_wd;
188         ps_raw_buf->au4_wd[2] =  0;
189 
190         ps_raw_buf->au4_ht[1] =  ps_app_ctxt->u4_ht / 2;
191         ps_raw_buf->au4_ht[2] =  0;
192 
193         ps_raw_buf->au4_strd[1] =  ps_app_ctxt->u4_wd;
194         ps_raw_buf->au4_strd[2] =  0;
195     }
196 
197     if(IV_YUV_420P == e_color_fmt)
198     {
199         ps_raw_buf->au4_wd[1] =  ps_app_ctxt->u4_wd / 2;
200         ps_raw_buf->au4_wd[2] =  ps_app_ctxt->u4_wd / 2;
201 
202         ps_raw_buf->au4_ht[1] =  ps_app_ctxt->u4_ht / 2;
203         ps_raw_buf->au4_ht[2] =  ps_app_ctxt->u4_ht / 2;
204 
205         ps_raw_buf->au4_strd[1] =  ps_app_ctxt->u4_wd / 2;
206         ps_raw_buf->au4_strd[2] =  ps_app_ctxt->u4_wd / 2;
207     }
208     /* If stride is not initialized, then use width as stride */
209     if(0 == ps_raw_buf->au4_strd[0])
210     {
211         ps_raw_buf->au4_strd[0] = ps_raw_buf->au4_wd[0];
212         ps_raw_buf->au4_strd[1] = ps_raw_buf->au4_wd[1];
213         ps_raw_buf->au4_strd[2] = ps_raw_buf->au4_wd[2];
214     }
215 
216     ps_raw_buf->u4_size = sizeof(iv_raw_buf_t);
217     return;
218 }
219 
220 
221