8326
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <unistd.h>
|
|
4
|
|
5 #include "config.h"
|
|
6 #include "mp_msg.h"
|
|
7 #include "help_mp.h"
|
|
8
|
|
9 #ifdef USE_DIRECTSHOW
|
|
10
|
|
11 #include "ad_internal.h"
|
|
12
|
|
13 static ad_info_t info =
|
|
14 {
|
8327
|
15 "Win32/DMO decoders",
|
8326
|
16 "dmo",
|
|
17 "A'rpi",
|
|
18 "avifile.sf.net",
|
|
19 ""
|
|
20 };
|
|
21
|
|
22 LIBAD_EXTERN(dmo)
|
|
23
|
|
24 #include "dmo/DMO_AudioDecoder.h"
|
|
25
|
|
26 static int init(sh_audio_t *sh)
|
|
27 {
|
|
28 return 1;
|
|
29 }
|
|
30
|
|
31 extern int audio_output_channels;
|
|
32
|
|
33 static int preinit(sh_audio_t *sh_audio)
|
|
34 {
|
|
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)))
|
|
39 {
|
|
40 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
|
|
41 return 0;
|
|
42 }
|
|
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->audio_in_minsize=4*sh_audio->wf->nBlockAlign;
|
|
47 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
|
|
48 sh_audio->audio_out_minsize=4*16384;
|
|
49 sh_audio->context = ds_adec;
|
|
50 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DMO audio codec init OK!\n");
|
|
51 return 1;
|
|
52 }
|
|
53
|
|
54 static void uninit(sh_audio_t *sh)
|
|
55 {
|
|
56 DMO_AudioDecoder* ds_adec = sh->context;
|
|
57 DMO_AudioDecoder_Destroy(ds_adec);
|
|
58 }
|
|
59
|
|
60 static int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
|
|
61 {
|
|
62 int skip;
|
|
63 switch(cmd)
|
|
64 {
|
|
65 case ADCTRL_SKIP_FRAME:
|
|
66 skip=sh_audio->wf->nBlockAlign;
|
|
67 if(skip<16){
|
|
68 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
|
|
69 if(skip<16) skip=16;
|
|
70 }
|
|
71 demux_read_data(sh_audio->ds,NULL,skip);
|
|
72 return CONTROL_TRUE;
|
|
73 }
|
|
74 return CONTROL_UNKNOWN;
|
|
75 }
|
|
76
|
|
77 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
|
|
78 {
|
|
79 DMO_AudioDecoder* ds_adec = sh_audio->context;
|
|
80 // int len=-1;
|
|
81 int size_in=0;
|
|
82 int size_out=0;
|
|
83 int srcsize=DMO_AudioDecoder_GetSrcSize(ds_adec, maxlen);
|
|
84 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DMO says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
|
|
85 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
|
|
86 if(sh_audio->a_in_buffer_len<srcsize){
|
|
87 sh_audio->a_in_buffer_len+=
|
|
88 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
|
|
89 srcsize-sh_audio->a_in_buffer_len);
|
|
90 }
|
|
91 DMO_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
|
|
92 buf,maxlen, &size_in,&size_out);
|
|
93 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));
|
|
94 if(size_in>=sh_audio->a_in_buffer_len){
|
|
95 sh_audio->a_in_buffer_len=0;
|
|
96 } else {
|
|
97 sh_audio->a_in_buffer_len-=size_in;
|
|
98 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
|
|
99 }
|
|
100 // len=size_out;
|
|
101 return size_out;
|
|
102 }
|
|
103 #endif
|