diff options
-rw-r--r-- | src/liba52/parse.c | 11 | ||||
-rw-r--r-- | src/liba52/xine_decoder.c | 10 | ||||
-rw-r--r-- | src/libmpeg2/decode.c | 19 | ||||
-rw-r--r-- | src/xine-engine/xine.c | 5 | ||||
-rw-r--r-- | src/xine-utils/utils.c | 62 | ||||
-rw-r--r-- | src/xine-utils/xineutils.h | 12 |
6 files changed, 94 insertions, 25 deletions
diff --git a/src/liba52/parse.c b/src/liba52/parse.c index 7a361e375..e92474761 100644 --- a/src/liba52/parse.c +++ b/src/liba52/parse.c @@ -29,14 +29,7 @@ #include "a52_internal.h" #include "bitstream.h" #include "tables.h" - -#ifdef HAVE_MEMALIGN -/* some systems have memalign() but no declaration for it */ -void * memalign (size_t align, size_t size); -#else -/* assume malloc alignment is sufficient */ -#define memalign(align,size) malloc (size) -#endif +#include "xineutils.h" static sample_t q_1[2]; static sample_t q_2[2]; @@ -54,7 +47,7 @@ sample_t * a52_init (uint32_t mm_accel) imdct_init (mm_accel); - samples = memalign (16, 256 * 12 * sizeof (sample_t)); + samples = xine_xmalloc_aligned (16, 256 * 12 * sizeof (sample_t)); if (samples == NULL) return NULL; diff --git a/src/liba52/xine_decoder.c b/src/liba52/xine_decoder.c index ffad6f2f6..a9b4f5b75 100644 --- a/src/liba52/xine_decoder.c +++ b/src/liba52/xine_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.c,v 1.9 2001/11/17 14:26:38 f1rmb Exp $ + * $Id: xine_decoder.c,v 1.10 2001/11/17 22:40:01 miguelfreitas Exp $ * * stuff needed to turn liba52 into a xine decoder plugin */ @@ -95,7 +95,8 @@ void a52dec_init (audio_decoder_t *this_gen, ao_instance_t *audio_out) { this->pts = 0; this->last_pts = 0; - this->samples = a52_init (xine_mm_accel()); + if( !this->samples ) + this->samples = a52_init (xine_mm_accel()); /* * find out if this driver supports a52 output @@ -454,6 +455,11 @@ void a52dec_close (audio_decoder_t *this_gen) { if (this->output_open) this->audio_out->close (this->audio_out); + if( this->samples ) { + xine_free_aligned( this->samples ); + this->samples = NULL; + } + this->output_open = 0; #ifdef DEBUG_A52 diff --git a/src/libmpeg2/decode.c b/src/libmpeg2/decode.c index 0e84ccbaa..703b269e5 100644 --- a/src/libmpeg2/decode.c +++ b/src/libmpeg2/decode.c @@ -50,8 +50,10 @@ void mpeg2_init (mpeg2dec_t * mpeg2dec, motion_comp_init (); } - mpeg2dec->chunk_buffer = xine_xmalloc_aligned (16, BUFFER_SIZE + 4); - mpeg2dec->picture = xine_xmalloc_aligned (16, sizeof (picture_t)); + if( !mpeg2dec->chunk_buffer ) + mpeg2dec->chunk_buffer = xine_xmalloc_aligned (16, BUFFER_SIZE + 4); + if( !mpeg2dec->picture ) + mpeg2dec->picture = xine_xmalloc_aligned (16, sizeof (picture_t)); mpeg2dec->shift = 0xffffff00; mpeg2dec->is_sequence_needed = 1; @@ -414,10 +416,15 @@ void mpeg2_close (mpeg2dec_t * mpeg2dec) picture->backward_reference_frame->free (picture->backward_reference_frame); } - /* FIXME - free (mpeg2dec->chunk_buffer); - free (mpeg2dec->picture); - */ + if ( mpeg2dec->chunk_buffer ) { + xine_free_aligned (mpeg2dec->chunk_buffer); + mpeg2dec->chunk_buffer = NULL; + } + + if ( mpeg2dec->picture ) { + xine_free_aligned (mpeg2dec->picture); + mpeg2dec->picture = NULL; + } } void mpeg2_find_sequence_header (mpeg2dec_t * mpeg2dec, diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index bd8273c44..70eaadf45 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine.c,v 1.74 2001/11/17 14:26:39 f1rmb Exp $ + * $Id: xine.c,v 1.75 2001/11/17 22:40:01 miguelfreitas Exp $ * * top-level xine functions * @@ -394,6 +394,9 @@ xine_t *xine_init (vo_driver_t *vo, /* probe for optimized memcpy or config setting */ xine_probe_fast_memcpy(config); + /* initialize aligned mem allocator */ + xine_init_mem_aligned(); + /* * init locks */ diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index 30670b109..3fe910b15 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: utils.c,v 1.2 2001/11/17 14:26:39 f1rmb Exp $ + * $Id: utils.c,v 1.3 2001/11/17 22:40:01 miguelfreitas Exp $ * */ #define _POSIX_PTHREAD_SEMANTICS 1 /* for 5-arg getpwuid_r on solaris */ @@ -34,6 +34,7 @@ #include <pwd.h> #include <time.h> #include <sys/types.h> +#include <pthread.h> #ifndef __GNUC__ #define __FUNCTION__ __func__ @@ -57,20 +58,69 @@ void *xine_xmalloc(size_t size) { return ptr; } +typedef struct mem_aligned_s { + struct mem_aligned_s *next; + void *ptr; + void *aligned_ptr; +} mem_aligned_t; + +static mem_aligned_t *mem_aligned; +static pthread_mutex_t mem_aligned_mutex; + /* * */ void *xine_xmalloc_aligned (size_t alignment, size_t size) { - char *pMem; - - pMem = xine_xmalloc (size+alignment); - + char *pMem, *ptr; + mem_aligned_t *reg; + + ptr = pMem = xine_xmalloc (size+alignment); + while ((int) pMem % alignment) pMem++; - + + pthread_mutex_lock (&mem_aligned_mutex); + reg = malloc( sizeof(mem_aligned_t) ); + reg->next = mem_aligned; + reg->ptr = ptr; + reg->aligned_ptr = pMem; + mem_aligned = reg; + pthread_mutex_unlock (&mem_aligned_mutex); + return pMem; } + +void xine_free_aligned( void *p ) { + mem_aligned_t *reg, *last; + + pthread_mutex_lock (&mem_aligned_mutex); + + last = NULL; + reg = mem_aligned; + while( reg != NULL ) { + if ( reg->aligned_ptr == p ) { + free( reg->ptr ); + if( last ) + last->next = reg->next; + else + mem_aligned = reg->next; + free( reg ); + pthread_mutex_unlock (&mem_aligned_mutex); + return; + } + last = reg; + reg = reg->next; + } + pthread_mutex_unlock (&mem_aligned_mutex); +} + + +void xine_init_mem_aligned(void) { + mem_aligned = NULL; + pthread_mutex_init (&mem_aligned_mutex, NULL); +} + /* * */ diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index eadd17f34..e181ea1aa 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xineutils.h,v 1.1 2001/11/17 14:26:39 f1rmb Exp $ + * $Id: xineutils.h,v 1.2 2001/11/17 22:40:01 miguelfreitas Exp $ * */ #ifndef XINEUTILS_H @@ -616,6 +616,16 @@ void *xine_xmalloc(size_t size); */ void *xine_xmalloc_aligned(size_t alignment, size_t size); +/* + * Free memory allocated with the above function + */ +void *xine_free_aligned(void *p); + +/* + * Initialize aligned memory allocator + */ +void xine_init_mem_aligned(void); + /* * Get user home directory. */ |