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 #define PEAK_WINDOW_SIZE 8
44 /*****************************************************************************/
45 /* Macros */
46 /*****************************************************************************/
47 /*****************************************************************************/
48 /* Function Declarations */
49 /*****************************************************************************/
write_output(FILE * fp,UWORD8 * pu1_buf,WORD32 num_bytes)50 IV_STATUS_T write_output(FILE *fp, UWORD8 *pu1_buf, WORD32 num_bytes)
51 {
52 WORD32 bytes;
53
54 bytes = fwrite(pu1_buf, sizeof(UWORD8), num_bytes, fp);
55 if(bytes != num_bytes)
56 return IV_FAIL;
57 fflush(fp);
58
59 return IV_SUCCESS;
60 }
61
allocate_output(app_ctxt_t * ps_app_ctxt)62 void allocate_output(app_ctxt_t *ps_app_ctxt)
63 {
64
65 WORD32 num_bufs;
66 WORD32 i;
67 UWORD8 *pu1_buf;
68 WORD32 buf_size;
69 num_bufs = MAX(DEFAULT_NUM_OUTPUT_BUFS, ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_out_bufs);
70 num_bufs = MIN(DEFAULT_MAX_OUTPUT_BUFS, num_bufs);
71
72 buf_size = ps_app_ctxt->s_get_buf_info_op.s_ive_op.au4_min_out_buf_size[0];
73 /* Memset the output buffer array to set is_free to 0 */
74 memset(ps_app_ctxt->as_output_buf, 0, sizeof(output_buf_t) * DEFAULT_MAX_OUTPUT_BUFS);
75
76 for(i = 0; i < num_bufs; i++)
77 {
78 pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, buf_size);
79 if(NULL == pu1_buf)
80 {
81 CHAR ac_error[STRLENGTH];
82 sprintf(ac_error, "Allocation failed for output buffer of size %d\n",
83 buf_size);
84 codec_exit(ac_error);
85 }
86 ps_app_ctxt->as_output_buf[i].pu1_buf = pu1_buf;
87 ps_app_ctxt->as_output_buf[i].u4_buf_size = buf_size;
88 ps_app_ctxt->as_output_buf[i].u4_is_free = 1;
89
90 }
91 return;
92 }
93
free_output(app_ctxt_t * ps_app_ctxt)94 void free_output(app_ctxt_t *ps_app_ctxt)
95 {
96
97 WORD32 num_bufs;
98 WORD32 i;
99
100 num_bufs = MAX(DEFAULT_NUM_OUTPUT_BUFS, ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_out_bufs);
101 num_bufs = MIN(DEFAULT_MAX_OUTPUT_BUFS, num_bufs);
102 for(i = 0; i < num_bufs; i++)
103 {
104
105 ih264a_aligned_free(ps_app_ctxt->as_output_buf[i].pu1_buf);
106 }
107 return;
108 }
109
110