3 * Copyright (c) 2001 Fabrice Bellard.
4 * Copyright (c) 2003 Michel Bardiaux for the av_log API
5 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 av_mallocz (unsigned int size)
39 ptr = av_malloc (size);
42 memset (ptr, 0, size);
47 av_strdup (const char *s)
53 ptr = av_malloc (len);
61 * realloc which does nothing if the block is large enough
64 av_fast_realloc (void *ptr, unsigned int *size, unsigned int min_size)
69 *size = 17 * min_size / 16 + 32;
71 return av_realloc (ptr, *size);
75 static unsigned int last_static = 0;
76 static unsigned int allocated_static = 0;
77 static void **array_static = NULL;
80 * allocation of static arrays - do not use for normal allocation.
83 av_mallocz_static (unsigned int size)
85 void *ptr = av_mallocz (size);
89 av_fast_realloc (array_static, &allocated_static,
90 sizeof (void *) * (last_static + 1));
91 array_static[last_static++] = ptr;
98 * free all static arrays and reset pointers to 0.
101 av_free_static (void)
103 while (last_static) {
104 av_freep (&array_static[--last_static]);
106 av_freep (&array_static);
110 * Frees memory and sets the pointer to NULL.
111 * @param arg pointer to the pointer which should be freed
116 void **ptr = (void **) arg;
123 avcodec_get_context_defaults (AVCodecContext * s)
125 memset (s, 0, sizeof (AVCodecContext));
127 s->frame_rate_base = 1;
132 * allocates a AVCodecContext and set it to defaults.
133 * this can be deallocated by simply calling free()
136 avcodec_alloc_context (void)
138 AVCodecContext *avctx = av_malloc (sizeof (AVCodecContext));
143 avcodec_get_context_defaults (avctx);
148 /* must be called before any other functions */
152 static int inited = 0;
158 dsputil_static_init ();