view libavcodec/utils.c @ 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
line source
1 /*
2 * utils for libavcodec
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 /**
24 * @file
25 * utils.
26 */
28 /* needed for mkstemp() */
29 #define _XOPEN_SOURCE 600
31 #include "avcodec.h"
32 #include "dsputil.h"
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <limits.h>
37 #include <float.h>
38 //#undef NDEBUG
39 #include <assert.h>
41 #include <fcntl.h>
43 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
44 {
45 if(min_size < *size)
46 return ptr;
48 *size= FFMAX(17*min_size/16 + 32, min_size);
50 ptr= av_realloc(ptr, *size);
51 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
52 *size= 0;
54 return ptr;
55 }
57 void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size)
58 {
59 void **p = ptr;
60 if (min_size < *size)
61 return;
62 *size= FFMAX(17*min_size/16 + 32, min_size);
63 av_free(*p);
64 *p = av_malloc(*size);
65 if (!*p) *size = 0;
66 }