Fix compilation after FFmpeg r22565.
[mplayer/glamo.git] / libmpcodecs / vd_dmo.c
blob6866aa202b642dc9bcf49e4043c1a26289397c68
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 #if HAVE_MALLOC_H
22 #include <malloc.h>
23 #endif
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
28 #include "mp_msg.h"
29 #include "help_mp.h"
31 #include "vd_internal.h"
33 #include "loader/dmo/DMO_VideoDecoder.h"
35 static const vd_info_t info = {
36 "DMO video codecs",
37 "dmo",
38 "A'rpi",
39 "based on http://avifile.sf.net",
40 "win32 codecs"
43 LIBVD_EXTERN(dmo)
45 struct context {
46 void *decoder;
47 uint8_t *buffer;
48 int stride;
51 // to set/get/query special features/parameters
52 static int control(sh_video_t *sh,int cmd,void* arg,...){
53 return CONTROL_UNKNOWN;
56 // init driver
57 static int init(sh_video_t *sh){
58 unsigned int out_fmt=sh->codec->outfmt[0];
59 struct context *ctx;
60 void *decoder;
61 if(!(decoder=DMO_VideoDecoder_Open(sh->codec->dll,&sh->codec->guid, sh->bih, 0, 0))){
62 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
63 mp_msg(MSGT_DECVIDEO,MSGL_HINT,MSGTR_DownloadCodecPackage);
64 return 0;
66 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,out_fmt)) return 0;
67 // mpcodecs_config_vo can change the format
68 out_fmt=sh->codec->outfmt[sh->outfmtidx];
69 sh->context = ctx = calloc(1, sizeof(*ctx));
70 ctx->decoder = decoder;
71 switch(out_fmt){
72 case IMGFMT_YUY2:
73 case IMGFMT_UYVY:
74 DMO_VideoDecoder_SetDestFmt(ctx->decoder,16,out_fmt);break; // packed YUV
75 case IMGFMT_YV12:
76 case IMGFMT_I420:
77 case IMGFMT_IYUV:
78 DMO_VideoDecoder_SetDestFmt(ctx->decoder,12,out_fmt);break; // planar YUV
79 case IMGFMT_YVU9:
80 DMO_VideoDecoder_SetDestFmt(ctx->decoder,9,out_fmt);break;
81 case IMGFMT_RGB24:
82 case IMGFMT_BGR24:
83 if (sh->disp_w & 3)
85 ctx->stride = ((sh->disp_w * 3) + 3) & ~3;
86 ctx->buffer = memalign(64, ctx->stride * sh->disp_h);
88 default:
89 DMO_VideoDecoder_SetDestFmt(ctx->decoder,out_fmt&255,0); // RGB/BGR
91 DMO_VideoDecoder_StartInternal(ctx->decoder);
92 mp_msg(MSGT_DECVIDEO,MSGL_V,MSGTR_DMOInitOK);
93 return 1;
96 // uninit driver
97 static void uninit(sh_video_t *sh){
98 struct context *ctx = sh->context;
99 DMO_VideoDecoder_Destroy(ctx->decoder);
100 free(ctx);
101 sh->context = NULL;
104 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
106 // decode a frame
107 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
108 struct context *ctx = sh->context;
109 uint8_t *buffer = ctx->buffer;
110 int type = ctx->buffer ? MP_IMGTYPE_EXPORT : MP_IMGTYPE_TEMP;
111 mp_image_t* mpi;
112 if(len<=0) return NULL; // skipped frame
114 if(flags&3){
115 // framedrop:
116 DMO_VideoDecoder_DecodeInternal(ctx->decoder, data, len, 0, 0);
117 return NULL;
120 mpi=mpcodecs_get_image(sh, type, MP_IMGFLAG_COMMON_PLANE,
121 sh->disp_w, sh->disp_h);
122 if (buffer) {
123 mpi->planes[0] = buffer;
124 mpi->stride[0] = ctx->stride;
125 } else {
126 buffer = mpi->planes[0];
129 if(!mpi){ // temporary!
130 mp_msg(MSGT_DECVIDEO,MSGL_WARN,MSGTR_MPCODECS_CouldntAllocateImageForCinepakCodec);
131 return NULL;
134 DMO_VideoDecoder_DecodeInternal(ctx->decoder, data, len, 1, buffer);
136 return mpi;