Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
diff libavutil/mem.h @ 2:897f711a7157
rearrange to work with autoconf
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 25 Sep 2012 15:55:33 +0200 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libavutil/mem.h Tue Sep 25 15:55:33 2012 +0200 1.3 @@ -0,0 +1,143 @@ 1.4 +/* 1.5 + * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> 1.6 + * 1.7 + * This file is part of FFmpeg. 1.8 + * 1.9 + * FFmpeg is free software; you can redistribute it and/or 1.10 + * modify it under the terms of the GNU Lesser General Public 1.11 + * License as published by the Free Software Foundation; either 1.12 + * version 2.1 of the License, or (at your option) any later version. 1.13 + * 1.14 + * FFmpeg is distributed in the hope that it will be useful, 1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.17 + * Lesser General Public License for more details. 1.18 + * 1.19 + * You should have received a copy of the GNU Lesser General Public 1.20 + * License along with FFmpeg; if not, write to the Free Software 1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1.22 + */ 1.23 + 1.24 +/** 1.25 + * @file 1.26 + * memory handling functions 1.27 + */ 1.28 + 1.29 +#ifndef AVUTIL_MEM_H 1.30 +#define AVUTIL_MEM_H 1.31 + 1.32 +#include "attributes.h" 1.33 +#include "config.h" 1.34 + 1.35 +#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v 1.36 +#define DECLARE_ALIGNED_16(t,v) t __attribute__ ((aligned (16))) v 1.37 +#define DECLARE_ASM_CONST(n,t,v) static const t __attribute__((used)) __attribute__ ((aligned (n))) v 1.38 + 1.39 +#if AV_GCC_VERSION_AT_LEAST(3,1) 1.40 + #define av_malloc_attrib __attribute__((__malloc__)) 1.41 +#else 1.42 + #define av_malloc_attrib 1.43 +#endif 1.44 + 1.45 +/** 1.46 + * Allocates a block of size bytes with alignment suitable for all 1.47 + * memory accesses (including vectors if available on the CPU). 1.48 + * @param size Size in bytes for the memory block to be allocated. 1.49 + * @return Pointer to the allocated block, NULL if the block cannot 1.50 + * be allocated. 1.51 + * @see av_mallocz() 1.52 + */ 1.53 +void *av_malloc(unsigned int size) av_malloc_attrib; 1.54 + 1.55 +/** 1.56 + * Allocates or reallocates a block of memory. 1.57 + * If ptr is NULL and size > 0, allocates a new block. If 1.58 + * size is zero, frees the memory block pointed to by ptr. 1.59 + * @param size Size in bytes for the memory block to be allocated or 1.60 + * reallocated. 1.61 + * @param ptr Pointer to a memory block already allocated with 1.62 + * av_malloc(z)() or av_realloc() or NULL. 1.63 + * @return Pointer to a newly reallocated block or NULL if the block 1.64 + * cannot be reallocated or the function is used to free the memory block. 1.65 + * @see av_fast_realloc() 1.66 + */ 1.67 +void *av_realloc(void *ptr, unsigned int size); 1.68 + 1.69 +/** 1.70 + * Reallocates the given block if it is not large enough, otherwise it 1.71 + * does nothing. 1.72 + * 1.73 + * @see av_realloc 1.74 + */ 1.75 +void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size); 1.76 + 1.77 +/** 1.78 + * Allocates a buffer, reusing the given one if large enough. 1.79 + * 1.80 + * Contrary to av_fast_realloc the current buffer contents might not be 1.81 + * preserved and on error the old buffer is freed, thus no special 1.82 + * handling to avoid memleaks is necessary. 1.83 + * 1.84 + * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer 1.85 + * @param size size of the buffer *ptr points to 1.86 + * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and 1.87 + * *size 0 if an error occurred. 1.88 + */ 1.89 +void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size); 1.90 + 1.91 +/** 1.92 + * Frees a memory block which has been allocated with av_malloc(z)() or 1.93 + * av_realloc(). 1.94 + * @param ptr Pointer to the memory block which should be freed. 1.95 + * @note ptr = NULL is explicitly allowed. 1.96 + * @note It is recommended that you use av_freep() instead. 1.97 + * @see av_freep() 1.98 + */ 1.99 + 1.100 +void av_free(void *ptr); 1.101 + 1.102 +/** 1.103 + * Allocates a block of size bytes with alignment suitable for all 1.104 + * memory accesses (including vectors if available on the CPU) and 1.105 + * zeroes all the bytes of the block. 1.106 + * @param size Size in bytes for the memory block to be allocated. 1.107 + * @return Pointer to the allocated block, NULL if it cannot be allocated. 1.108 + * @see av_malloc() 1.109 + */ 1.110 +void *av_mallocz(unsigned int size) av_malloc_attrib; 1.111 + 1.112 +/** 1.113 + * Duplicates the string s. 1.114 + * @param s string to be duplicated 1.115 + * @return Pointer to a newly allocated string containing a 1.116 + * copy of s or NULL if the string cannot be allocated. 1.117 + */ 1.118 +char *av_strdup(const char *s) av_malloc_attrib; 1.119 + 1.120 +/** 1.121 + * Frees a memory block which has been allocated with av_malloc(z)() or 1.122 + * av_realloc() and set the pointer pointing to it to NULL. 1.123 + * @param ptr Pointer to the pointer to the memory block which should 1.124 + * be freed. 1.125 + * @see av_free() 1.126 + */ 1.127 +void av_freep(void *ptr); 1.128 + 1.129 + 1.130 +static av_always_inline uint32_t pack16to32(int a, int b){ 1.131 +#if HAVE_BIGENDIAN 1.132 + return (b&0xFFFF) + (a<<16); 1.133 +#else 1.134 + return (a&0xFFFF) + (b<<16); 1.135 +#endif 1.136 +} 1.137 + 1.138 +static av_always_inline uint16_t pack8to16(int a, int b){ 1.139 +#if HAVE_BIGENDIAN 1.140 + return (b&0xFF) + (a<<8); 1.141 +#else 1.142 + return (a&0xFF) + (b<<8); 1.143 +#endif 1.144 +} 1.145 + 1.146 +#endif /* AVUTIL_MEM_H */
