comparison libmpcodecs/vf.c @ 5507:d0d029fda134

video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
author arpi
date Sat, 06 Apr 2002 22:05:01 +0000
parents
children 53ce50ac2ce2
comparison
equal deleted inserted replaced
5506:b8b6fcb5062a 5507:d0d029fda134
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "../config.h"
6 #include "../mp_msg.h"
7
8 #include "../libvo/img_format.h"
9 #include "../mp_image.h"
10 #include "vf.h"
11
12 extern vf_info_t vf_info_vo;
13 extern vf_info_t vf_info_crop;
14 extern vf_info_t vf_info_expand;
15
16 char** vo_plugin_args=(char**) NULL;
17
18 // list of available filters:
19 static vf_info_t* filter_list[]={
20 &vf_info_crop,
21 &vf_info_expand,
22 // &vf_info_zoom,
23 // &vf_info_osd,
24 &vf_info_vo,
25 NULL
26 };
27
28 //============================================================================
29
30 // mpi stuff:
31
32 mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h){
33 mp_image_t* mpi=NULL;
34 int w2=w; //(mp_imgflag&MP_IMGFLAG_ACCEPT_STRIDE)?((w+15)&(~15)):w;
35 // Note: we should call libvo first to check if it supports direct rendering
36 // and if not, then fallback to software buffers:
37 switch(mp_imgtype){
38 case MP_IMGTYPE_EXPORT:
39 if(!vf->imgctx.export_images[0]) vf->imgctx.export_images[0]=new_mp_image(w2,h);
40 mpi=vf->imgctx.export_images[0];
41 break;
42 case MP_IMGTYPE_STATIC:
43 if(!vf->imgctx.static_images[0]) vf->imgctx.static_images[0]=new_mp_image(w2,h);
44 mpi=vf->imgctx.static_images[0];
45 break;
46 case MP_IMGTYPE_TEMP:
47 if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h);
48 mpi=vf->imgctx.temp_images[0];
49 break;
50 case MP_IMGTYPE_IPB:
51 if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame:
52 if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h);
53 mpi=vf->imgctx.temp_images[0];
54 break;
55 }
56 case MP_IMGTYPE_IP:
57 if(!vf->imgctx.static_images[vf->imgctx.static_idx]) vf->imgctx.static_images[vf->imgctx.static_idx]=new_mp_image(w2,h);
58 mpi=vf->imgctx.static_images[vf->imgctx.static_idx];
59 vf->imgctx.static_idx^=1;
60 break;
61 }
62 if(mpi){
63 mpi->type=mp_imgtype;
64 mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT);
65 mpi->flags|=mp_imgflag&(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH|MP_IMGFLAG_ALIGNED_STRIDE|MP_IMGFLAG_DRAW_CALLBACK);
66 if(!vf->draw_slice) mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
67 if((mpi->width!=w2 || mpi->height!=h) && !(mpi->flags&MP_IMGFLAG_DIRECT)){
68 mpi->width=w2;
69 mpi->height=h;
70 if(mpi->flags&MP_IMGFLAG_ALLOCATED){
71 // need to re-allocate buffer memory:
72 free(mpi->planes[0]);
73 mpi->flags&=~MP_IMGFLAG_ALLOCATED;
74 }
75 }
76 if(!mpi->bpp) mp_image_setfmt(mpi,outfmt);
77 if(!(mpi->flags&MP_IMGFLAG_ALLOCATED) && mpi->type>MP_IMGTYPE_EXPORT){
78
79 // check libvo first!
80 if(vf->get_image) vf->get_image(vf,mpi);
81
82 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
83 // non-direct and not yet allocaed image. allocate it!
84 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*mpi->height/8);
85 if(mpi->flags&MP_IMGFLAG_PLANAR){
86 // YV12/I420. feel free to add other planar formats here...
87 if(!mpi->stride[0]) mpi->stride[0]=mpi->width;
88 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->width/2;
89 if(mpi->flags&MP_IMGFLAG_SWAPPED){
90 // I420/IYUV (Y,U,V)
91 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
92 mpi->planes[2]=mpi->planes[1]+(mpi->width>>1)*(mpi->height>>1);
93 } else {
94 // YV12,YVU9 (Y,V,U)
95 mpi->planes[2]=mpi->planes[0]+mpi->width*mpi->height;
96 mpi->planes[1]=mpi->planes[2]+(mpi->width>>1)*(mpi->height>>1);
97 }
98 } else {
99 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8;
100 }
101 mpi->flags|=MP_IMGFLAG_ALLOCATED;
102 }
103 }
104 if(!(mpi->flags&MP_IMGFLAG_TYPE_DISPLAYED)){
105 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"*** [%s] %s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n",
106 vf->info->name,
107 (mpi->type==MP_IMGTYPE_EXPORT)?"Exporting":
108 ((mpi->flags&MP_IMGFLAG_DIRECT)?"Direct Rendering":"Allocating"),
109 mpi->width,mpi->height,mpi->bpp,
110 (mpi->flags&MP_IMGFLAG_YUV)?"YUV":"RGB",
111 (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed",
112 mpi->bpp*mpi->width*mpi->height/8);
113 mpi->flags|=MP_IMGFLAG_TYPE_DISPLAYED;
114 }
115
116 }
117 return mpi;
118 }
119
120 //============================================================================
121
122 vf_instance_t* vf_open_filter(vf_instance_t* next, char *name, char *args){
123 vf_instance_t* vf;
124 int i;
125 for(i=0;;i++){
126 if(!filter_list[i]){
127 mp_msg(MSGT_VFILTER,MSGL_ERR,"Couldn't find video filter '%s'\n",name);
128 return NULL; // no such filter!
129 }
130 if(!strcmp(filter_list[i]->name,name)) break;
131 }
132 vf=malloc(sizeof(vf_instance_t));
133 memset(vf,0,sizeof(vf_instance_t));
134 vf->info=filter_list[i];
135 vf->next=next;
136 vf->config=vf_next_config;
137 vf->control=vf_next_control;
138 vf->query_format=vf_next_query_format;
139 vf->put_image=vf_next_put_image;
140 vf->uninit=vf_next_uninit;
141 if(vf->info->open(vf,args)>0) return vf; // Success!
142 free(vf);
143 mp_msg(MSGT_VFILTER,MSGL_ERR,"Couldn't open video filter '%s'\n",name);
144 return NULL;
145 }
146
147 //============================================================================
148
149 int vf_next_config(struct vf_instance_s* vf,
150 int width, int height, int d_width, int d_height,
151 unsigned int flags, unsigned int outfmt){
152 return vf->next->config(vf->next,width,height,d_width,d_height,flags,outfmt);
153 }
154
155 int vf_next_control(struct vf_instance_s* vf, int request, void* data){
156 return vf->next->control(vf->next,request,data);
157 }
158
159 int vf_next_query_format(struct vf_instance_s* vf, unsigned int fmt){
160 return vf->next->query_format(vf->next,fmt);
161 }
162
163 void vf_next_put_image(struct vf_instance_s* vf,mp_image_t *mpi){
164 return vf->next->put_image(vf->next,mpi);
165 }
166
167 void vf_next_uninit(struct vf_instance_s* vf){
168 return vf->next->uninit(vf->next);
169 }
170
171 //============================================================================
172
173 vf_instance_t* append_filters(vf_instance_t* last){
174 vf_instance_t* vf;
175 if(!vo_plugin_args) return last;
176 while(*vo_plugin_args){
177 char* name=strdup(*vo_plugin_args);
178 char* args=strchr(name,'=');
179 if(args){args[0]=0;++args;}
180 mp_msg(MSGT_VFILTER,MSGL_INFO,"Opening video filter '%s' with args '%s'...\n",name,args);
181 vf=vf_open_filter(last,name,args);
182 if(vf) last=vf;
183 free(name);
184 ++vo_plugin_args;
185 }
186 return last;
187 }
188
189 //============================================================================
190