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