1 /* 2 * Copyright 2015 Rockchip Electronics Co. LTD 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __MPP_MEM_H__ 18 #define __MPP_MEM_H__ 19 20 #include <stdlib.h> 21 22 #include "rk_type.h" 23 #include "mpp_err.h" 24 25 #define mpp_malloc_with_caller(type, count, caller) \ 26 (type*)mpp_osal_malloc(caller, sizeof(type) * (count)) 27 28 #define mpp_malloc(type, count) \ 29 (type*)mpp_osal_malloc(__FUNCTION__, sizeof(type) * (count)) 30 31 #define mpp_malloc_size(type, size) \ 32 (type*)mpp_osal_malloc(__FUNCTION__, size) 33 34 #define mpp_calloc_size(type, size) \ 35 (type*)mpp_osal_calloc(__FUNCTION__, size) 36 37 #define mpp_calloc(type, count) \ 38 (type*)mpp_osal_calloc(__FUNCTION__, sizeof(type) * (count)) 39 40 #define mpp_realloc(ptr, type, count) \ 41 (type*)mpp_osal_realloc(__FUNCTION__, ptr, sizeof(type) * (count)) 42 43 #define mpp_free(ptr) \ 44 mpp_osal_free(__FUNCTION__, ptr) 45 46 #define MPP_FREE(ptr) do { if(ptr) mpp_free(ptr); ptr = NULL; } while (0) 47 #define MPP_FCLOSE(fp) do { if(fp) fclose(fp); fp = NULL; } while (0) 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 void *mpp_osal_malloc(const char *caller, size_t size); 54 void *mpp_osal_calloc(const char *caller, size_t size); 55 void *mpp_osal_realloc(const char *caller, void *ptr, size_t size); 56 void mpp_osal_free(const char *caller, void *ptr); 57 58 void mpp_show_mem_status(); 59 RK_U32 mpp_mem_total_now(); 60 RK_U32 mpp_mem_total_max(); 61 62 /* 63 * mpp memory usage snapshot tool 64 * 65 * usage: 66 * call mpp_mem_get_snapshot on context init get one snapshot 67 * call mpp_mem_get_snapshot on context deinit get another snapshot 68 * call mpp_mem_diff_snapshot to show the difference between these two snapshot 69 * call mpp_mem_put_snapshot twice to release these two snapshot 70 */ 71 typedef void* MppMemSnapshot; 72 73 MPP_RET mpp_mem_get_snapshot(MppMemSnapshot *hnd); 74 MPP_RET mpp_mem_put_snapshot(MppMemSnapshot *hnd); 75 MPP_RET mpp_mem_squash_snapshot(MppMemSnapshot hnd0, MppMemSnapshot hnd1); 76 77 #ifdef __cplusplus 78 } 79 #endif 80 81 #endif /*__MPP_MEM_H__*/ 82 83