Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
comparison libavutil/mem.h @ 9:ea1ba68cf0ed
update to match api changes + add sscc produced source
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 05 Jun 2013 14:43:26 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7c7214f400e2 |
|---|---|
| 1 /* | |
| 2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | |
| 3 * | |
| 4 * This file is part of FFmpeg. | |
| 5 * | |
| 6 * FFmpeg is free software; you can redistribute it and/or | |
| 7 * modify it under the terms of the GNU Lesser General Public | |
| 8 * License as published by the Free Software Foundation; either | |
| 9 * version 2.1 of the License, or (at your option) any later version. | |
| 10 * | |
| 11 * FFmpeg is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 * Lesser General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU Lesser General Public | |
| 17 * License along with FFmpeg; if not, write to the Free Software | |
| 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 19 */ | |
| 20 | |
| 21 /** | |
| 22 * @file | |
| 23 * memory handling functions | |
| 24 */ | |
| 25 | |
| 26 #ifndef AVUTIL_MEM_H | |
| 27 #define AVUTIL_MEM_H | |
| 28 | |
| 29 #include "attributes.h" | |
| 30 #include "config.h" | |
| 31 | |
| 32 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v | |
| 33 #define DECLARE_ALIGNED_16(t,v) t __attribute__ ((aligned (16))) v | |
| 34 #define DECLARE_ASM_CONST(n,t,v) static const t __attribute__((used)) __attribute__ ((aligned (n))) v | |
| 35 | |
| 36 #if AV_GCC_VERSION_AT_LEAST(3,1) | |
| 37 #define av_malloc_attrib __attribute__((__malloc__)) | |
| 38 #else | |
| 39 #define av_malloc_attrib | |
| 40 #endif | |
| 41 | |
| 42 /** | |
| 43 * Allocates a block of size bytes with alignment suitable for all | |
| 44 * memory accesses (including vectors if available on the CPU). | |
| 45 * @param size Size in bytes for the memory block to be allocated. | |
| 46 * @return Pointer to the allocated block, NULL if the block cannot | |
| 47 * be allocated. | |
| 48 * @see av_mallocz() | |
| 49 */ | |
| 50 void *av_malloc(unsigned int size) av_malloc_attrib; | |
| 51 | |
| 52 /** | |
| 53 * Allocates or reallocates a block of memory. | |
| 54 * If ptr is NULL and size > 0, allocates a new block. If | |
| 55 * size is zero, frees the memory block pointed to by ptr. | |
| 56 * @param size Size in bytes for the memory block to be allocated or | |
| 57 * reallocated. | |
| 58 * @param ptr Pointer to a memory block already allocated with | |
| 59 * av_malloc(z)() or av_realloc() or NULL. | |
| 60 * @return Pointer to a newly reallocated block or NULL if the block | |
| 61 * cannot be reallocated or the function is used to free the memory block. | |
| 62 * @see av_fast_realloc() | |
| 63 */ | |
| 64 void *av_realloc(void *ptr, unsigned int size); | |
| 65 | |
| 66 /** | |
| 67 * Reallocates the given block if it is not large enough, otherwise it | |
| 68 * does nothing. | |
| 69 * | |
| 70 * @see av_realloc | |
| 71 */ | |
| 72 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size); | |
| 73 | |
| 74 /** | |
| 75 * Allocates a buffer, reusing the given one if large enough. | |
| 76 * | |
| 77 * Contrary to av_fast_realloc the current buffer contents might not be | |
| 78 * preserved and on error the old buffer is freed, thus no special | |
| 79 * handling to avoid memleaks is necessary. | |
| 80 * | |
| 81 * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer | |
| 82 * @param size size of the buffer *ptr points to | |
| 83 * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and | |
| 84 * *size 0 if an error occurred. | |
| 85 */ | |
| 86 void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size); | |
| 87 | |
| 88 /** | |
| 89 * Frees a memory block which has been allocated with av_malloc(z)() or | |
| 90 * av_realloc(). | |
| 91 * @param ptr Pointer to the memory block which should be freed. | |
| 92 * @note ptr = NULL is explicitly allowed. | |
| 93 * @note It is recommended that you use av_freep() instead. | |
| 94 * @see av_freep() | |
| 95 */ | |
| 96 | |
| 97 void av_free(void *ptr); | |
| 98 | |
| 99 /** | |
| 100 * Allocates a block of size bytes with alignment suitable for all | |
| 101 * memory accesses (including vectors if available on the CPU) and | |
| 102 * zeroes all the bytes of the block. | |
| 103 * @param size Size in bytes for the memory block to be allocated. | |
| 104 * @return Pointer to the allocated block, NULL if it cannot be allocated. | |
| 105 * @see av_malloc() | |
| 106 */ | |
| 107 void *av_mallocz(unsigned int size) av_malloc_attrib; | |
| 108 | |
| 109 /** | |
| 110 * Duplicates the string s. | |
| 111 * @param s string to be duplicated | |
| 112 * @return Pointer to a newly allocated string containing a | |
| 113 * copy of s or NULL if the string cannot be allocated. | |
| 114 */ | |
| 115 char *av_strdup(const char *s) av_malloc_attrib; | |
| 116 | |
| 117 /** | |
| 118 * Frees a memory block which has been allocated with av_malloc(z)() or | |
| 119 * av_realloc() and set the pointer pointing to it to NULL. | |
| 120 * @param ptr Pointer to the pointer to the memory block which should | |
| 121 * be freed. | |
| 122 * @see av_free() | |
| 123 */ | |
| 124 void av_freep(void *ptr); | |
| 125 | |
| 126 | |
| 127 static av_always_inline uint32_t pack16to32(int a, int b){ | |
| 128 #if HAVE_BIGENDIAN | |
| 129 return (b&0xFFFF) + (a<<16); | |
| 130 #else | |
| 131 return (a&0xFFFF) + (b<<16); | |
| 132 #endif | |
| 133 } | |
| 134 | |
| 135 static av_always_inline uint16_t pack8to16(int a, int b){ | |
| 136 #if HAVE_BIGENDIAN | |
| 137 return (b&0xFF) + (a<<8); | |
| 138 #else | |
| 139 return (a&0xFF) + (b<<8); | |
| 140 #endif | |
| 141 } | |
| 142 | |
| 143 #endif /* AVUTIL_MEM_H */ |
