annotate libmpeg2/alloc.c @ 10094:5730f6098f98

theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
author arpi
date Sun, 11 May 2003 18:26:48 +0000
parents 89b48bc6c441
children 2c0b6ec77d39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
1 /*
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
2 * alloc.c
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
5 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
7 * See http://libmpeg2.sourceforge.net/ for updates.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
8 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
9 * mpeg2dec is free software; you can redistribute it and/or modify
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
12 * (at your option) any later version.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
13 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
14 * mpeg2dec is distributed in the hope that it will be useful,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
17 * GNU General Public License for more details.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
18 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
22 */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
23
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
24 #include "config.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
25
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
26 #include <stdlib.h>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
27 #include <inttypes.h>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
28
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
29 #include "mpeg2.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
30 #include "mpeg2_internal.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
31
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
32 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
33 /* some systems have memalign() but no declaration for it */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
34 void * memalign (size_t align, size_t size);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
35 #endif
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
36
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
37 void * (* mpeg2_malloc_hook) (int size, int reason) = NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
38 int (* mpeg2_free_hook) (void * buf) = NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
39
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
40 void * mpeg2_malloc (int size, int reason)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
41 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
42 char * buf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
43
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
44 if (mpeg2_malloc_hook) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
45 buf = (char *) mpeg2_malloc_hook (size, reason);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
46 if (buf)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
47 return buf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
48 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
49
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
50 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
51 return memalign (16, size);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
52 #else
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
53 buf = (char *) malloc (size + 15 + sizeof (void **));
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
54 if (buf) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
55 char * align_buf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
56
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
57 align_buf = buf + 15 + sizeof (void **);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
58 align_buf -= (long)align_buf & 15;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
59 *(((void **)align_buf) - 1) = buf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
60 return align_buf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
61 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
62 return NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
63 #endif
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
64 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
65
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
66 void mpeg2_free (void * buf)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
67 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
68 if (mpeg2_free_hook && mpeg2_free_hook (buf))
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
69 return;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
70
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
71 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
72 free (buf);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
73 #else
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
74 free (*(((void **)buf) - 1));
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
75 #endif
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
76 }