9 #include "ad_internal.h"
11 static ad_info_t info
=
13 "Win32/DirectShow decoders",
22 #include "loader/dshow/DS_AudioDecoder.h"
24 static int init(sh_audio_t
*sh
)
29 static int preinit(sh_audio_t
*sh_audio
)
31 DS_AudioDecoder
* ds_adec
;
32 if(!(ds_adec
=DS_AudioDecoder_Open(sh_audio
->codec
->dll
,&sh_audio
->codec
->guid
,sh_audio
->wf
)))
34 mp_msg(MSGT_DECAUDIO
,MSGL_ERR
,MSGTR_MissingDLLcodec
,sh_audio
->codec
->dll
);
37 sh_audio
->i_bps
=sh_audio
->wf
->nAvgBytesPerSec
;
38 sh_audio
->channels
=sh_audio
->wf
->nChannels
;
39 sh_audio
->samplerate
=sh_audio
->wf
->nSamplesPerSec
;
40 sh_audio
->samplesize
=2;
41 sh_audio
->audio_in_minsize
=2*sh_audio
->wf
->nBlockAlign
;
42 if(sh_audio
->audio_in_minsize
<8192) sh_audio
->audio_in_minsize
=8192;
43 sh_audio
->audio_out_minsize
=16384;
44 sh_audio
->context
= ds_adec
;
45 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"INFO: Win32/DShow audio codec init OK!\n");
49 static void uninit(sh_audio_t
*sh
)
51 DS_AudioDecoder
* ds_adec
= sh
->context
;
52 DS_AudioDecoder_Destroy(ds_adec
);
55 static int control(sh_audio_t
*sh_audio
,int cmd
,void* arg
, ...)
60 case ADCTRL_SKIP_FRAME
:
61 skip
=sh_audio
->wf
->nBlockAlign
;
63 skip
=(sh_audio
->wf
->nAvgBytesPerSec
/16)&(~7);
66 demux_read_data(sh_audio
->ds
,NULL
,skip
);
69 return CONTROL_UNKNOWN
;
72 static int decode_audio(sh_audio_t
*sh_audio
,unsigned char *buf
,int minlen
,int maxlen
)
74 DS_AudioDecoder
* ds_adec
= sh_audio
->context
;
78 int srcsize
=DS_AudioDecoder_GetSrcSize(ds_adec
, maxlen
);
79 mp_msg(MSGT_DECAUDIO
,MSGL_DBG3
,"DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize
,sh_audio
->a_in_buffer_size
,maxlen
);
80 if(srcsize
>sh_audio
->a_in_buffer_size
) srcsize
=sh_audio
->a_in_buffer_size
; // !!!!!!
81 if(sh_audio
->a_in_buffer_len
<srcsize
){
82 sh_audio
->a_in_buffer_len
+=
83 demux_read_data(sh_audio
->ds
,&sh_audio
->a_in_buffer
[sh_audio
->a_in_buffer_len
],
84 srcsize
-sh_audio
->a_in_buffer_len
);
86 DS_AudioDecoder_Convert(ds_adec
, sh_audio
->a_in_buffer
,sh_audio
->a_in_buffer_len
,
87 buf
,maxlen
, &size_in
,&size_out
);
88 mp_dbg(MSGT_DECAUDIO
,MSGL_DBG2
,"DShow: 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
));
89 if(size_in
>=sh_audio
->a_in_buffer_len
){
90 sh_audio
->a_in_buffer_len
=0;
92 sh_audio
->a_in_buffer_len
-=size_in
;
93 memcpy(sh_audio
->a_in_buffer
,&sh_audio
->a_in_buffer
[size_in
],sh_audio
->a_in_buffer_len
);