Silence permanent warning messages when decoding H264 over rtsp with
[mplayer.git] / libmpcodecs / ad_dshow.c
blobe88ed0c2fa3b818c861e8fe82ef39f81c4f638ba
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"
25 #include "help_mp.h"
27 #include "ad_internal.h"
29 static const ad_info_t info =
31 "Win32/DirectShow decoders",
32 "dshow",
33 "Nick Kurshev",
34 "avifile.sf.net",
38 LIBAD_EXTERN(dshow)
40 #include "loader/dshow/DS_AudioDecoder.h"
42 static int init(sh_audio_t *sh)
44 return 1;
47 static int preinit(sh_audio_t *sh_audio)
49 DS_AudioDecoder* ds_adec;
50 if(!(ds_adec=DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)))
52 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
53 return 0;
55 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
56 sh_audio->channels=sh_audio->wf->nChannels;
57 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
58 sh_audio->samplesize=2;
59 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign;
60 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
61 sh_audio->audio_out_minsize=16384;
62 sh_audio->context = ds_adec;
63 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DShow audio codec init OK!\n");
64 return 1;
67 static void uninit(sh_audio_t *sh)
69 DS_AudioDecoder* ds_adec = sh->context;
70 DS_AudioDecoder_Destroy(ds_adec);
73 static int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
75 int skip;
76 switch(cmd)
78 case ADCTRL_SKIP_FRAME:
79 skip=sh_audio->wf->nBlockAlign;
80 if(skip<16){
81 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
82 if(skip<16) skip=16;
84 demux_read_data(sh_audio->ds,NULL,skip);
85 return CONTROL_TRUE;
87 return CONTROL_UNKNOWN;
90 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
92 DS_AudioDecoder* ds_adec = sh_audio->context;
93 // int len=-1;
94 int size_in=0;
95 int size_out=0;
96 int srcsize=DS_AudioDecoder_GetSrcSize(ds_adec, maxlen);
97 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
98 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
99 if(sh_audio->a_in_buffer_len<srcsize){
100 sh_audio->a_in_buffer_len+=
101 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
102 srcsize-sh_audio->a_in_buffer_len);
104 DS_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
105 buf,maxlen, &size_in,&size_out);
106 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));
107 if(size_in>=sh_audio->a_in_buffer_len){
108 sh_audio->a_in_buffer_len=0;
109 } else {
110 sh_audio->a_in_buffer_len-=size_in;
111 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
113 // len=size_out;
114 return size_out;