configure: Simplify fribidi check - console output is not necessary
[mplayer/glamo.git] / libmpcodecs / ad_dshow.c
blob8fb94660a46efb3f34958a10e080aac39b5164de
1 /*
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.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
23 #include "config.h"
24 #include "mp_msg.h"
26 #include "ad_internal.h"
28 static const ad_info_t info =
30 "Win32/DirectShow decoders",
31 "dshow",
32 "Nick Kurshev",
33 "avifile.sf.net",
37 LIBAD_EXTERN(dshow)
39 #include "loader/dshow/DS_AudioDecoder.h"
41 static int init(sh_audio_t *sh)
43 return 1;
46 static int preinit(sh_audio_t *sh_audio)
48 DS_AudioDecoder* ds_adec;
49 if(!(ds_adec=DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)))
51 mp_tmsg(MSGT_DECAUDIO,MSGL_ERR,"ERROR: Could not open required DirectShow codec %s.\n",sh_audio->codec->dll);
52 return 0;
54 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
55 sh_audio->channels=sh_audio->wf->nChannels;
56 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
57 sh_audio->samplesize=2;
58 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign;
59 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
60 sh_audio->audio_out_minsize=16384;
61 sh_audio->context = ds_adec;
62 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DShow audio codec init OK!\n");
63 return 1;
66 static void uninit(sh_audio_t *sh)
68 DS_AudioDecoder* ds_adec = sh->context;
69 DS_AudioDecoder_Destroy(ds_adec);
72 static int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
74 int skip;
75 switch(cmd)
77 case ADCTRL_SKIP_FRAME:
78 skip=sh_audio->wf->nBlockAlign;
79 if(skip<16){
80 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
81 if(skip<16) skip=16;
83 demux_read_data(sh_audio->ds,NULL,skip);
84 return CONTROL_TRUE;
86 return CONTROL_UNKNOWN;
89 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
91 DS_AudioDecoder* ds_adec = sh_audio->context;
92 // int len=-1;
93 int size_in=0;
94 int size_out=0;
95 int srcsize=DS_AudioDecoder_GetSrcSize(ds_adec, maxlen);
96 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
97 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
98 if(sh_audio->a_in_buffer_len<srcsize){
99 sh_audio->a_in_buffer_len+=
100 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
101 srcsize-sh_audio->a_in_buffer_len);
103 DS_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
104 buf,maxlen, &size_in,&size_out);
105 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));
106 if(size_in>=sh_audio->a_in_buffer_len){
107 sh_audio->a_in_buffer_len=0;
108 } else {
109 sh_audio->a_in_buffer_len-=size_in;
110 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
112 // len=size_out;
113 return size_out;