mp_msg: print messages to stdout, statusline to stderr
[mplayer.git] / libmpcodecs / vd_dmo.c
blobe300edd3718147e976b3d7d057be4d2ef5a3f3c7
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 "config.h"
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
25 #include "mp_msg.h"
27 #include "vd_internal.h"
29 #include "loader/dmo/DMO_VideoDecoder.h"
31 static const vd_info_t info = {
32 "DMO video codecs",
33 "dmo",
34 "A'rpi",
35 "based on http://avifile.sf.net",
36 "win32 codecs"
39 LIBVD_EXTERN(dmo)
41 struct context {
42 void *decoder;
43 uint8_t *buffer;
44 int stride;
47 // to set/get/query special features/parameters
48 static int control(sh_video_t *sh,int cmd,void* arg,...){
49 return CONTROL_UNKNOWN;
52 // init driver
53 static int init(sh_video_t *sh){
54 unsigned int out_fmt=sh->codec->outfmt[0];
55 struct context *ctx;
56 void *decoder;
57 if(!(decoder=DMO_VideoDecoder_Open(sh->codec->dll,&sh->codec->guid, sh->bih, 0, 0))){
58 mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"ERROR: Could not open required DirectShow codec %s.\n",sh->codec->dll);
59 mp_tmsg(MSGT_DECVIDEO,MSGL_HINT,"You need to upgrade/install the binary codecs package.\nGo to http://www.mplayerhq.hu/dload.html\n");
60 return 0;
62 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,out_fmt)) return 0;
63 // mpcodecs_config_vo can change the format
64 out_fmt=sh->codec->outfmt[sh->outfmtidx];
65 sh->context = ctx = calloc(1, sizeof(*ctx));
66 ctx->decoder = decoder;
67 switch(out_fmt){
68 case IMGFMT_YUY2:
69 case IMGFMT_UYVY:
70 DMO_VideoDecoder_SetDestFmt(ctx->decoder,16,out_fmt);break; // packed YUV
71 case IMGFMT_YV12:
72 case IMGFMT_I420:
73 case IMGFMT_IYUV:
74 DMO_VideoDecoder_SetDestFmt(ctx->decoder,12,out_fmt);break; // planar YUV
75 case IMGFMT_YVU9:
76 DMO_VideoDecoder_SetDestFmt(ctx->decoder,9,out_fmt);break;
77 case IMGFMT_RGB24:
78 case IMGFMT_BGR24:
79 if (sh->disp_w & 3)
81 ctx->stride = ((sh->disp_w * 3) + 3) & ~3;
82 ctx->buffer = av_malloc(ctx->stride * sh->disp_h);
84 default:
85 DMO_VideoDecoder_SetDestFmt(ctx->decoder,out_fmt&255,0); // RGB/BGR
87 DMO_VideoDecoder_StartInternal(ctx->decoder);
88 mp_tmsg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DMO video codec init OK.\n");
89 return 1;
92 // uninit driver
93 static void uninit(sh_video_t *sh){
94 struct context *ctx = sh->context;
95 DMO_VideoDecoder_Destroy(ctx->decoder);
96 av_free(ctx->buffer);
97 free(ctx);
98 sh->context = NULL;
101 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
103 // decode a frame
104 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
105 struct context *ctx = sh->context;
106 uint8_t *buffer = ctx->buffer;
107 int type = ctx->buffer ? MP_IMGTYPE_EXPORT : MP_IMGTYPE_TEMP;
108 mp_image_t* mpi;
109 if(len<=0) return NULL; // skipped frame
111 if(flags&3){
112 // framedrop:
113 DMO_VideoDecoder_DecodeInternal(ctx->decoder, data, len, 0, 0);
114 return NULL;
117 mpi=mpcodecs_get_image(sh, type, MP_IMGFLAG_COMMON_PLANE,
118 sh->disp_w, sh->disp_h);
119 if (buffer) {
120 mpi->planes[0] = buffer;
121 mpi->stride[0] = ctx->stride;
122 } else {
123 buffer = mpi->planes[0];
126 if(!mpi){ // temporary!
127 mp_tmsg(MSGT_DECVIDEO,MSGL_WARN,"[VD_DMO] Couldn't allocate image for cinepak codec.\n");
128 return NULL;
131 DMO_VideoDecoder_DecodeInternal(ctx->decoder, data, len, 1, buffer);
133 return mpi;