input: sleep in event loop even if there are no input fds
[mplayer.git] / libmpcodecs / vd_dshow.c
blob7e8fe35ce0c5849834cde78a837baa6696ef3085
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 <stdarg.h>
23 #include "config.h"
25 #include "mp_msg.h"
27 #include "vd_internal.h"
29 #include "loader/dshow/DS_VideoDecoder.h"
31 static const vd_info_t info = {
32 "DirectShow video codecs",
33 "dshow",
34 "A'rpi",
35 "based on http://avifile.sf.net",
36 "win32 codecs"
39 LIBVD_EXTERN(dshow)
41 // to set/get/query special features/parameters
42 static int control(sh_video_t *sh,int cmd,void* arg,...){
43 switch(cmd){
44 case VDCTRL_QUERY_MAX_PP_LEVEL:
45 return 4;
46 case VDCTRL_SET_PP_LEVEL:
47 if(!sh->context) return CONTROL_ERROR;
48 DS_VideoDecoder_SetValue(sh->context,"Quality",*((int*)arg));
49 return CONTROL_OK;
51 case VDCTRL_SET_EQUALIZER: {
52 va_list ap;
53 int value;
54 va_start(ap, arg);
55 value=va_arg(ap, int);
56 va_end(ap);
57 if(DS_VideoDecoder_SetValue(sh->context,arg,50+value/2)==0)
58 return CONTROL_OK;
59 return CONTROL_FALSE;
63 return CONTROL_UNKNOWN;
66 // init driver
67 static int init(sh_video_t *sh){
68 unsigned int out_fmt=sh->codec->outfmt[0];
70 /* Hack for VSSH codec: new dll can't decode old files
71 * In my samples old files have no extradata, so use that info
72 * to decide what dll should be used (here and in vd_vfw).
74 if (!strcmp(sh->codec->dll, "vsshdsd.dll") && (sh->bih->biSize == 40))
75 return 0;
77 if(!(sh->context=DS_VideoDecoder_Open(sh->codec->dll,&sh->codec->guid, sh->bih, 0, 0))){
78 mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"ERROR: Could not open required DirectShow codec %s.\n",sh->codec->dll);
79 mp_tmsg(MSGT_DECVIDEO,MSGL_HINT,"You need to upgrade/install the binary codecs package.\nGo to http://www.mplayerhq.hu/dload.html\n");
80 return 0;
82 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,out_fmt)) return 0;
83 // mpcodecs_config_vo can change the format
84 out_fmt=sh->codec->outfmt[sh->outfmtidx];
85 switch(out_fmt){
86 case IMGFMT_YUY2:
87 case IMGFMT_UYVY:
88 DS_VideoDecoder_SetDestFmt(sh->context,16,out_fmt);break; // packed YUV
89 case IMGFMT_YV12:
90 case IMGFMT_I420:
91 case IMGFMT_IYUV:
92 DS_VideoDecoder_SetDestFmt(sh->context,12,out_fmt);break; // planar YUV
93 case IMGFMT_YVU9:
94 DS_VideoDecoder_SetDestFmt(sh->context,9,out_fmt);break;
95 default:
96 DS_VideoDecoder_SetDestFmt(sh->context,out_fmt&255,0); // RGB/BGR
98 DS_SetAttr_DivX("Quality",divx_quality);
99 DS_VideoDecoder_StartInternal(sh->context);
100 mp_tmsg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DShow video codec init OK.\n");
101 return 1;
104 // uninit driver
105 static void uninit(sh_video_t *sh){
106 DS_VideoDecoder_Destroy(sh->context);
109 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
111 // decode a frame
112 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
113 mp_image_t* mpi;
114 if(len<=0) return NULL; // skipped frame
116 if(flags&3){
117 // framedrop:
118 DS_VideoDecoder_DecodeInternal(sh->context, data, len, 0, 0);
119 return NULL;
122 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_COMMON_PLANE,
123 sh->disp_w, sh->disp_h);
125 if(!mpi){ // temporary!
126 mp_tmsg(MSGT_DECVIDEO,MSGL_WARN,"[VD_DMO] Couldn't allocate image for cinepak codec.\n");
127 return NULL;
130 DS_VideoDecoder_DecodeInternal(sh->context, data, len, 0, mpi->planes[0]);
132 return mpi;