2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "ad_internal.h"
28 #include "libaf/reorder_ch.h"
30 static const ad_info_t info
=
41 #include "loader/dmo/DMO_AudioDecoder.h"
43 static int init(sh_audio_t
*sh
)
48 static int preinit(sh_audio_t
*sh_audio
)
50 struct MPOpts
*opts
= sh_audio
->opts
;
51 DMO_AudioDecoder
* ds_adec
;
52 int chans
=(opts
->audio_output_channels
==sh_audio
->wf
->nChannels
) ?
53 opts
->audio_output_channels
: (sh_audio
->wf
->nChannels
>=2 ? 2 : 1);
54 if(!(ds_adec
=DMO_AudioDecoder_Open(sh_audio
->codec
->dll
,&sh_audio
->codec
->guid
,sh_audio
->wf
,chans
)))
56 mp_tmsg(MSGT_DECAUDIO
,MSGL_ERR
,"ERROR: Could not open required DirectShow codec %s.\n",sh_audio
->codec
->dll
);
59 sh_audio
->i_bps
=sh_audio
->wf
->nAvgBytesPerSec
;
60 sh_audio
->channels
=chans
;
61 sh_audio
->samplerate
=sh_audio
->wf
->nSamplesPerSec
;
62 sh_audio
->samplesize
=2;
63 sh_audio
->audio_in_minsize
=4*sh_audio
->wf
->nBlockAlign
;
64 if(sh_audio
->audio_in_minsize
<8192) sh_audio
->audio_in_minsize
=8192;
65 sh_audio
->audio_out_minsize
=4*16384;
66 sh_audio
->context
= ds_adec
;
67 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"INFO: Win32/DMO audio codec init OK!\n");
71 static void uninit(sh_audio_t
*sh
)
73 DMO_AudioDecoder
* ds_adec
= sh
->context
;
74 DMO_AudioDecoder_Destroy(ds_adec
);
77 static int control(sh_audio_t
*sh_audio
,int cmd
,void* arg
, ...)
82 case ADCTRL_SKIP_FRAME
:
83 skip
=sh_audio
->wf
->nBlockAlign
;
85 skip
=(sh_audio
->wf
->nAvgBytesPerSec
/16)&(~7);
88 demux_read_data(sh_audio
->ds
,NULL
,skip
);
91 return CONTROL_UNKNOWN
;
94 static int decode_audio(sh_audio_t
*sh_audio
,unsigned char *buf
,int minlen
,int maxlen
)
96 DMO_AudioDecoder
* ds_adec
= sh_audio
->context
;
100 int srcsize
=DMO_AudioDecoder_GetSrcSize(ds_adec
, maxlen
);
101 mp_msg(MSGT_DECAUDIO
,MSGL_DBG3
,"DMO says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize
,sh_audio
->a_in_buffer_size
,maxlen
);
102 if(srcsize
>sh_audio
->a_in_buffer_size
) srcsize
=sh_audio
->a_in_buffer_size
; // !!!!!!
103 if(sh_audio
->a_in_buffer_len
<srcsize
){
104 sh_audio
->a_in_buffer_len
+=
105 demux_read_data(sh_audio
->ds
,&sh_audio
->a_in_buffer
[sh_audio
->a_in_buffer_len
],
106 srcsize
-sh_audio
->a_in_buffer_len
);
108 DMO_AudioDecoder_Convert(ds_adec
, sh_audio
->a_in_buffer
,sh_audio
->a_in_buffer_len
,
109 buf
,maxlen
, &size_in
,&size_out
);
110 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
));
111 if(size_in
>=sh_audio
->a_in_buffer_len
){
112 sh_audio
->a_in_buffer_len
=0;
114 sh_audio
->a_in_buffer_len
-=size_in
;
115 memmove(sh_audio
->a_in_buffer
,&sh_audio
->a_in_buffer
[size_in
],sh_audio
->a_in_buffer_len
);
117 if (size_out
> 0 && sh_audio
->channels
>= 5) {
118 reorder_channel_nch(buf
, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT
,
119 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT
,
121 size_out
/ sh_audio
->samplesize
,
122 sh_audio
->samplesize
);