Move amigaos CFLAG settings to amigaos section at the beginning of configure.
[mplayer/glamo.git] / libmpcodecs / ad_dmo.c
blobd1133667c39333016c56146625568cbcdf2bb6e2
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 #include "ad_internal.h"
10 #include "libaf/reorder_ch.h"
12 static ad_info_t info =
14 "Win32/DMO decoders",
15 "dmo",
16 "A'rpi",
17 "avifile.sf.net",
21 LIBAD_EXTERN(dmo)
23 #include "loader/dmo/DMO_AudioDecoder.h"
25 static int init(sh_audio_t *sh)
27 return 1;
30 static int preinit(sh_audio_t *sh_audio)
32 DMO_AudioDecoder* ds_adec;
33 int chans=(audio_output_channels==sh_audio->wf->nChannels) ?
34 audio_output_channels : (sh_audio->wf->nChannels>=2 ? 2 : 1);
35 if(!(ds_adec=DMO_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf,chans)))
37 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
38 return 0;
40 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
41 sh_audio->channels=chans;
42 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
43 sh_audio->samplesize=2;
44 sh_audio->audio_in_minsize=4*sh_audio->wf->nBlockAlign;
45 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
46 sh_audio->audio_out_minsize=4*16384;
47 sh_audio->context = ds_adec;
48 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DMO audio codec init OK!\n");
49 return 1;
52 static void uninit(sh_audio_t *sh)
54 DMO_AudioDecoder* ds_adec = sh->context;
55 DMO_AudioDecoder_Destroy(ds_adec);
58 static int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
60 int skip;
61 switch(cmd)
63 case ADCTRL_SKIP_FRAME:
64 skip=sh_audio->wf->nBlockAlign;
65 if(skip<16){
66 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
67 if(skip<16) skip=16;
69 demux_read_data(sh_audio->ds,NULL,skip);
70 return CONTROL_TRUE;
72 return CONTROL_UNKNOWN;
75 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
77 DMO_AudioDecoder* ds_adec = sh_audio->context;
78 // int len=-1;
79 int size_in=0;
80 int size_out=0;
81 int srcsize=DMO_AudioDecoder_GetSrcSize(ds_adec, maxlen);
82 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DMO says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
83 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
84 if(sh_audio->a_in_buffer_len<srcsize){
85 sh_audio->a_in_buffer_len+=
86 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
87 srcsize-sh_audio->a_in_buffer_len);
89 DMO_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
90 buf,maxlen, &size_in,&size_out);
91 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));
92 if(size_in>=sh_audio->a_in_buffer_len){
93 sh_audio->a_in_buffer_len=0;
94 } else {
95 sh_audio->a_in_buffer_len-=size_in;
96 memmove(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
98 if (size_out > 0 && sh_audio->channels >= 5) {
99 reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
100 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
101 sh_audio->channels,
102 size_out / sh_audio->samplesize,
103 sh_audio->samplesize);
105 // len=size_out;
106 return size_out;