summaryrefslogtreecommitdiffstats
path: root/dec_audio.c
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-01-17 01:11:21 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-01-17 01:11:21 +0000
commit777f684d5ca0ce90509d77e2068ca0a311dd72e5 (patch)
tree94c41ccf4d403cca30ea9fd3272c4e166e4c6f12 /dec_audio.c
parent46674e633cedab14c34ef34197a5b1b9cf2f993d (diff)
downloadmpv-777f684d5ca0ce90509d77e2068ca0a311dd72e5.tar.bz2
mpv-777f684d5ca0ce90509d77e2068ca0a311dd72e5.tar.xz
libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4209 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'dec_audio.c')
-rw-r--r--dec_audio.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/dec_audio.c b/dec_audio.c
index f1f3dfa905..9e78ef075f 100644
--- a/dec_audio.c
+++ b/dec_audio.c
@@ -101,9 +101,14 @@ typedef struct ov_struct_st {
#ifdef USE_LIBMAD
#include <mad.h>
+
+#define MAD_SINGLE_BUFFER_SIZE 8192
+#define MAD_TOTAL_BUFFER_SIZE ((MAD_SINGLE_BUFFER_SIZE)*3)
+
static struct mad_stream mad_stream;
static struct mad_frame mad_frame;
static struct mad_synth mad_synth;
+static char* mad_in_buffer = 0; /* base pointer of buffer */
// ensure buffer is filled with some data
static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int length)
@@ -117,14 +122,19 @@ static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int
static void mad_postprocess_buffer(sh_audio_t* sh_audio, struct mad_stream* ms)
{
+ /* rotate buffer while possible, in order to reduce the overhead of endless memcpy */
int delta = (unsigned char*)ms->next_frame - (unsigned char *)sh_audio->a_in_buffer;
- if(delta != 0) {
+ if((unsigned long)(sh_audio->a_in_buffer) - (unsigned long)mad_in_buffer <
+ (MAD_TOTAL_BUFFER_SIZE - MAD_SINGLE_BUFFER_SIZE - delta)) {
+ sh_audio->a_in_buffer += delta;
+ sh_audio->a_in_buffer_len -= delta;
+ } else {
+ sh_audio->a_in_buffer = mad_in_buffer;
sh_audio->a_in_buffer_len -= delta;
memcpy(sh_audio->a_in_buffer, ms->next_frame, sh_audio->a_in_buffer_len);
}
}
-
static inline
signed short mad_scale(mad_fixed_t sample)
{
@@ -449,9 +459,9 @@ case AFM_FFMPEG:
case AFM_MAD:
printf(__FILE__ ":%d:mad: setting minimum outputsize\n", __LINE__);
sh_audio->audio_out_minsize=4608;
- if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
+ if(sh_audio->audio_in_minsize<MAD_SINGLE_BUFFER_SIZE) sh_audio->audio_in_minsize=MAD_SINGLE_BUFFER_SIZE;
sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
- sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
+ mad_in_buffer = sh_audio->a_in_buffer = malloc(MAD_TOTAL_BUFFER_SIZE);
sh_audio->a_in_buffer_len=0;
break;
#endif