fix
[mplayer/glamo.git] / libmpcodecs / ad_dmo.c
bloba9053caa130425c82f37be4ec6423b14deb7f754
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 #include "config.h"
6 #include "mp_msg.h"
7 #include "help_mp.h"
9 #ifdef USE_DIRECTSHOW
11 #include "ad_internal.h"
13 static ad_info_t info =
15 "Win32/DMO decoders",
16 "dmo",
17 "A'rpi",
18 "avifile.sf.net",
22 LIBAD_EXTERN(dmo)
24 #include "dmo/DMO_AudioDecoder.h"
26 static int init(sh_audio_t *sh)
28 return 1;
31 extern int audio_output_channels;
33 static int preinit(sh_audio_t *sh_audio)
35 DMO_AudioDecoder* ds_adec;
36 int chans=(audio_output_channels==sh_audio->wf->nChannels) ?
37 audio_output_channels : (sh_audio->wf->nChannels>=2 ? 2 : 1);
38 if(!(ds_adec=DMO_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf,chans)))
40 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
41 return 0;
43 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
44 sh_audio->channels=chans;
45 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
46 sh_audio->samplesize=2;
47 sh_audio->audio_in_minsize=4*sh_audio->wf->nBlockAlign;
48 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
49 sh_audio->audio_out_minsize=4*16384;
50 sh_audio->context = ds_adec;
51 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DMO audio codec init OK!\n");
52 return 1;
55 static void uninit(sh_audio_t *sh)
57 DMO_AudioDecoder* ds_adec = sh->context;
58 DMO_AudioDecoder_Destroy(ds_adec);
61 static int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
63 int skip;
64 switch(cmd)
66 case ADCTRL_SKIP_FRAME:
67 skip=sh_audio->wf->nBlockAlign;
68 if(skip<16){
69 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
70 if(skip<16) skip=16;
72 demux_read_data(sh_audio->ds,NULL,skip);
73 return CONTROL_TRUE;
75 return CONTROL_UNKNOWN;
78 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
80 DMO_AudioDecoder* ds_adec = sh_audio->context;
81 // int len=-1;
82 int size_in=0;
83 int size_out=0;
84 int srcsize=DMO_AudioDecoder_GetSrcSize(ds_adec, maxlen);
85 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DMO says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
86 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
87 if(sh_audio->a_in_buffer_len<srcsize){
88 sh_audio->a_in_buffer_len+=
89 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
90 srcsize-sh_audio->a_in_buffer_len);
92 DMO_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
93 buf,maxlen, &size_in,&size_out);
94 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"DMO: audio %d -> %d converted (in_buf_len=%d of %d) %d\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size,ds_tell_pts(sh_audio->ds));
95 if(size_in>=sh_audio->a_in_buffer_len){
96 sh_audio->a_in_buffer_len=0;
97 } else {
98 sh_audio->a_in_buffer_len-=size_in;
99 memmove(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
101 // len=size_out;
102 return size_out;
104 #endif