Update to MPlayer SVN rev 30827 and FFmpeg SVN rev 22201.
[vaapi:challenzhous-mplayer.git] / libmpcodecs / vd_dshow.c
1 /*
2  * This file is part of MPlayer.
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <stdarg.h>
22
23 #include "config.h"
24
25 #include "mp_msg.h"
26 #include "help_mp.h"
27
28 #include "vd_internal.h"
29
30 #include "loader/dshow/DS_VideoDecoder.h"
31
32 static const vd_info_t info = {
33         "DirectShow video codecs",
34         "dshow",
35         "A'rpi",
36         "based on http://avifile.sf.net",
37         "win32 codecs"
38 };
39
40 LIBVD_EXTERN(dshow)
41
42 // to set/get/query special features/parameters
43 static int control(sh_video_t *sh,int cmd,void* arg,...){
44     switch(cmd){
45     case VDCTRL_QUERY_MAX_PP_LEVEL:
46         return 4;
47     case VDCTRL_SET_PP_LEVEL:
48         if(!sh->context) return CONTROL_ERROR;
49         DS_VideoDecoder_SetValue(sh->context,"Quality",*((int*)arg));
50         return CONTROL_OK;
51
52     case VDCTRL_SET_EQUALIZER: {
53         va_list ap;
54         int value;
55         va_start(ap, arg);
56         value=va_arg(ap, int);
57         va_end(ap);
58         if(DS_VideoDecoder_SetValue(sh->context,arg,50+value/2)==0)
59             return CONTROL_OK;
60         return CONTROL_FALSE;
61     }
62
63     }
64     return CONTROL_UNKNOWN;
65 }
66
67 // init driver
68 static int init(sh_video_t *sh){
69     unsigned int out_fmt=sh->codec->outfmt[0];
70
71     /* Hack for VSSH codec: new dll can't decode old files
72      * In my samples old files have no extradata, so use that info
73      * to decide what dll should be used (here and in vd_vfw).
74      */
75     if (!strcmp(sh->codec->dll, "vsshdsd.dll") && (sh->bih->biSize == 40))
76       return 0;
77
78     if(!(sh->context=DS_VideoDecoder_Open(sh->codec->dll,&sh->codec->guid, sh->bih, 0, 0))){
79         mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
80         mp_msg(MSGT_DECVIDEO,MSGL_HINT,MSGTR_DownloadCodecPackage);
81         return 0;
82     }
83     if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,out_fmt)) return 0;
84     // mpcodecs_config_vo can change the format
85     out_fmt=sh->codec->outfmt[sh->outfmtidx];
86     switch(out_fmt){
87     case IMGFMT_YUY2:
88     case IMGFMT_UYVY:
89         DS_VideoDecoder_SetDestFmt(sh->context,16,out_fmt);break; // packed YUV
90     case IMGFMT_YV12:
91     case IMGFMT_I420:
92     case IMGFMT_IYUV:
93         DS_VideoDecoder_SetDestFmt(sh->context,12,out_fmt);break; // planar YUV
94     case IMGFMT_YVU9:
95         DS_VideoDecoder_SetDestFmt(sh->context,9,out_fmt);break;
96     default:
97         DS_VideoDecoder_SetDestFmt(sh->context,out_fmt&255,0);    // RGB/BGR
98     }
99     DS_SetAttr_DivX("Quality",divx_quality);
100     DS_VideoDecoder_StartInternal(sh->context);
101     mp_msg(MSGT_DECVIDEO,MSGL_V,MSGTR_DShowInitOK);
102     return 1;
103 }
104
105 // uninit driver
106 static void uninit(sh_video_t *sh){
107     DS_VideoDecoder_Destroy(sh->context);
108 }
109
110 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
111
112 // decode a frame
113 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
114     mp_image_t* mpi;
115     if(len<=0) return NULL; // skipped frame
116
117     if(flags&3){
118         // framedrop:
119         DS_VideoDecoder_DecodeInternal(sh->context, data, len, 0, 0);
120         return NULL;
121     }
122
123     mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_COMMON_PLANE,
124         sh->disp_w, sh->disp_h);
125
126     if(!mpi){   // temporary!
127         mp_msg(MSGT_DECVIDEO,MSGL_WARN,MSGTR_MPCODECS_CouldntAllocateImageForCinepakCodec);
128         return NULL;
129     }
130
131     DS_VideoDecoder_DecodeInternal(sh->context, data, len, 0, mpi->planes[0]);
132
133     return mpi;
134 }