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.
38 #include "img_format.h"
42 #include "libvo/fastmemcpy.h"
43 #include "libavutil/mem.h"
45 extern const vf_info_t vf_info_vo
;
46 extern const vf_info_t vf_info_rectangle
;
47 extern const vf_info_t vf_info_bmovl
;
48 extern const vf_info_t vf_info_crop
;
49 extern const vf_info_t vf_info_expand
;
50 extern const vf_info_t vf_info_pp
;
51 extern const vf_info_t vf_info_scale
;
52 extern const vf_info_t vf_info_format
;
53 extern const vf_info_t vf_info_noformat
;
54 extern const vf_info_t vf_info_flip
;
55 extern const vf_info_t vf_info_rgb2bgr
;
56 extern const vf_info_t vf_info_rotate
;
57 extern const vf_info_t vf_info_mirror
;
58 extern const vf_info_t vf_info_palette
;
59 extern const vf_info_t vf_info_lavc
;
60 extern const vf_info_t vf_info_zrmjpeg
;
61 extern const vf_info_t vf_info_dvbscale
;
62 extern const vf_info_t vf_info_cropdetect
;
63 extern const vf_info_t vf_info_test
;
64 extern const vf_info_t vf_info_noise
;
65 extern const vf_info_t vf_info_yvu9
;
66 extern const vf_info_t vf_info_lavcdeint
;
67 extern const vf_info_t vf_info_eq
;
68 extern const vf_info_t vf_info_eq2
;
69 extern const vf_info_t vf_info_gradfun
;
70 extern const vf_info_t vf_info_halfpack
;
71 extern const vf_info_t vf_info_dint
;
72 extern const vf_info_t vf_info_1bpp
;
73 extern const vf_info_t vf_info_2xsai
;
74 extern const vf_info_t vf_info_unsharp
;
75 extern const vf_info_t vf_info_swapuv
;
76 extern const vf_info_t vf_info_il
;
77 extern const vf_info_t vf_info_fil
;
78 extern const vf_info_t vf_info_boxblur
;
79 extern const vf_info_t vf_info_sab
;
80 extern const vf_info_t vf_info_smartblur
;
81 extern const vf_info_t vf_info_perspective
;
82 extern const vf_info_t vf_info_down3dright
;
83 extern const vf_info_t vf_info_field
;
84 extern const vf_info_t vf_info_denoise3d
;
85 extern const vf_info_t vf_info_hqdn3d
;
86 extern const vf_info_t vf_info_detc
;
87 extern const vf_info_t vf_info_telecine
;
88 extern const vf_info_t vf_info_tinterlace
;
89 extern const vf_info_t vf_info_tfields
;
90 extern const vf_info_t vf_info_ivtc
;
91 extern const vf_info_t vf_info_ilpack
;
92 extern const vf_info_t vf_info_dsize
;
93 extern const vf_info_t vf_info_decimate
;
94 extern const vf_info_t vf_info_softpulldown
;
95 extern const vf_info_t vf_info_pullup
;
96 extern const vf_info_t vf_info_filmdint
;
97 extern const vf_info_t vf_info_framestep
;
98 extern const vf_info_t vf_info_tile
;
99 extern const vf_info_t vf_info_delogo
;
100 extern const vf_info_t vf_info_remove_logo
;
101 extern const vf_info_t vf_info_hue
;
102 extern const vf_info_t vf_info_spp
;
103 extern const vf_info_t vf_info_uspp
;
104 extern const vf_info_t vf_info_fspp
;
105 extern const vf_info_t vf_info_pp7
;
106 extern const vf_info_t vf_info_yuvcsp
;
107 extern const vf_info_t vf_info_kerndeint
;
108 extern const vf_info_t vf_info_rgbtest
;
109 extern const vf_info_t vf_info_qp
;
110 extern const vf_info_t vf_info_phase
;
111 extern const vf_info_t vf_info_divtc
;
112 extern const vf_info_t vf_info_harddup
;
113 extern const vf_info_t vf_info_softskip
;
114 extern const vf_info_t vf_info_screenshot
;
115 extern const vf_info_t vf_info_ass
;
116 extern const vf_info_t vf_info_mcdeint
;
117 extern const vf_info_t vf_info_yadif
;
118 extern const vf_info_t vf_info_blackframe
;
119 extern const vf_info_t vf_info_geq
;
120 extern const vf_info_t vf_info_ow
;
121 extern const vf_info_t vf_info_fixpts
;
123 // list of available filters:
124 static const vf_info_t
* const filter_list
[]={
126 #ifdef HAVE_POSIX_SELECT
131 #ifdef CONFIG_LIBPOSTPROC
145 #ifdef CONFIG_LIBAVCODEC
172 &vf_info_perspective
,
173 &vf_info_down3dright
,
185 &vf_info_softpulldown
,
191 &vf_info_remove_logo
,
193 #ifdef CONFIG_LIBAVCODEC_A
219 m_obj_settings_t
* vf_settings
= NULL
;
220 const m_obj_list_t vf_obj_list
= {
222 M_ST_OFF(vf_info_t
,name
),
223 M_ST_OFF(vf_info_t
,info
),
224 M_ST_OFF(vf_info_t
,opts
)
227 //============================================================================
230 void vf_mpi_clear(mp_image_t
* mpi
,int x0
,int y0
,int w
,int h
){
232 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
234 if(x0
==0 && w
==mpi
->width
){
236 memset(mpi
->planes
[0]+mpi
->stride
[0]*y0
,0,mpi
->stride
[0]*h
);
237 memset(mpi
->planes
[1]+mpi
->stride
[1]*(y0
>>mpi
->chroma_y_shift
),128,mpi
->stride
[1]*(h
>>mpi
->chroma_y_shift
));
238 memset(mpi
->planes
[2]+mpi
->stride
[2]*(y0
>>mpi
->chroma_y_shift
),128,mpi
->stride
[2]*(h
>>mpi
->chroma_y_shift
));
240 for(y
=y0
;y
<y0
+h
;y
+=2){
241 memset(mpi
->planes
[0]+x0
+mpi
->stride
[0]*y
,0,w
);
242 memset(mpi
->planes
[0]+x0
+mpi
->stride
[0]*(y
+1),0,w
);
243 memset(mpi
->planes
[1]+(x0
>>mpi
->chroma_x_shift
)+mpi
->stride
[1]*(y
>>mpi
->chroma_y_shift
),128,(w
>>mpi
->chroma_x_shift
));
244 memset(mpi
->planes
[2]+(x0
>>mpi
->chroma_x_shift
)+mpi
->stride
[2]*(y
>>mpi
->chroma_y_shift
),128,(w
>>mpi
->chroma_x_shift
));
249 for(y
=y0
;y
<y0
+h
;y
++){
250 unsigned char* dst
=mpi
->planes
[0]+mpi
->stride
[0]*y
+(mpi
->bpp
>>3)*x0
;
251 if(mpi
->flags
&MP_IMGFLAG_YUV
){
252 unsigned int* p
=(unsigned int*) dst
;
253 int size
=(mpi
->bpp
>>3)*w
/4;
256 #define CLEAR_PACKEDYUV_PATTERN 0x00800080
257 #define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x80008000
259 #define CLEAR_PACKEDYUV_PATTERN 0x80008000
260 #define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x00800080
262 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
){
263 for(i
=0;i
<size
-3;i
+=4) p
[i
]=p
[i
+1]=p
[i
+2]=p
[i
+3]=CLEAR_PACKEDYUV_PATTERN_SWAPPED
;
264 for(;i
<size
;i
++) p
[i
]=CLEAR_PACKEDYUV_PATTERN_SWAPPED
;
266 for(i
=0;i
<size
-3;i
+=4) p
[i
]=p
[i
+1]=p
[i
+2]=p
[i
+3]=CLEAR_PACKEDYUV_PATTERN
;
267 for(;i
<size
;i
++) p
[i
]=CLEAR_PACKEDYUV_PATTERN
;
270 memset(dst
,0,(mpi
->bpp
>>3)*w
);
274 mp_image_t
* vf_get_image(vf_instance_t
* vf
, unsigned int outfmt
, int mp_imgtype
, int mp_imgflag
, int w
, int h
){
275 mp_image_t
* mpi
=NULL
;
277 int number
= mp_imgtype
>> 16;
280 assert(w
== -1 || w
>= vf
->w
);
281 assert(h
== -1 || h
>= vf
->h
);
286 // fprintf(stderr, "get_image: %d:%d, vf: %d:%d\n", w,h,vf->w,vf->h);
288 if (w
== -1) w
= vf
->w
;
289 if (h
== -1) h
= vf
->h
;
291 w2
=(mp_imgflag
&MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE
)?((w
+15)&(~15)):w
;
293 if(vf
->put_image
==vf_next_put_image
){
294 // passthru mode, if the filter uses the fallback/default put_image() code
295 return vf_get_image(vf
->next
,outfmt
,mp_imgtype
,mp_imgflag
,w
,h
);
298 // Note: we should call libvo first to check if it supports direct rendering
299 // and if not, then fallback to software buffers:
300 switch(mp_imgtype
& 0xff){
301 case MP_IMGTYPE_EXPORT
:
302 if(!vf
->imgctx
.export_images
[0]) vf
->imgctx
.export_images
[0]=new_mp_image(w2
,h
);
303 mpi
=vf
->imgctx
.export_images
[0];
305 case MP_IMGTYPE_STATIC
:
306 if(!vf
->imgctx
.static_images
[0]) vf
->imgctx
.static_images
[0]=new_mp_image(w2
,h
);
307 mpi
=vf
->imgctx
.static_images
[0];
309 case MP_IMGTYPE_TEMP
:
310 if(!vf
->imgctx
.temp_images
[0]) vf
->imgctx
.temp_images
[0]=new_mp_image(w2
,h
);
311 mpi
=vf
->imgctx
.temp_images
[0];
314 if(!(mp_imgflag
&MP_IMGFLAG_READABLE
)){ // B frame:
315 if(!vf
->imgctx
.temp_images
[0]) vf
->imgctx
.temp_images
[0]=new_mp_image(w2
,h
);
316 mpi
=vf
->imgctx
.temp_images
[0];
320 if(!vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
]) vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
]=new_mp_image(w2
,h
);
321 mpi
=vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
];
322 vf
->imgctx
.static_idx
^=1;
324 case MP_IMGTYPE_NUMBERED
:
327 for (i
= 0; i
< NUM_NUMBERED_MPI
; i
++)
328 if (!vf
->imgctx
.numbered_images
[i
] || !vf
->imgctx
.numbered_images
[i
]->usage_count
)
332 if (number
< 0 || number
>= NUM_NUMBERED_MPI
) return NULL
;
333 if (!vf
->imgctx
.numbered_images
[number
]) vf
->imgctx
.numbered_images
[number
] = new_mp_image(w2
,h
);
334 mpi
= vf
->imgctx
.numbered_images
[number
];
335 mpi
->number
= number
;
339 mpi
->type
=mp_imgtype
;
340 mpi
->w
=vf
->w
; mpi
->h
=vf
->h
;
341 // keep buffer allocation status & color flags only:
342 // mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT);
343 mpi
->flags
&=MP_IMGFLAG_ALLOCATED
|MP_IMGFLAG_TYPE_DISPLAYED
|MP_IMGFLAGMASK_COLORS
;
344 // accept restrictions, draw_slice and palette flags only:
345 mpi
->flags
|=mp_imgflag
&(MP_IMGFLAGMASK_RESTRICTIONS
|MP_IMGFLAG_DRAW_CALLBACK
|MP_IMGFLAG_RGB_PALETTE
);
346 if(!vf
->draw_slice
) mpi
->flags
&=~MP_IMGFLAG_DRAW_CALLBACK
;
347 if(mpi
->width
!=w2
|| mpi
->height
!=h
){
348 // printf("vf.c: MPI parameters changed! %dx%d -> %dx%d \n", mpi->width,mpi->height,w2,h);
349 if(mpi
->flags
&MP_IMGFLAG_ALLOCATED
){
350 if(mpi
->width
<w2
|| mpi
->height
<h
){
351 // need to re-allocate buffer memory:
352 av_free(mpi
->planes
[0]);
353 mpi
->flags
&=~MP_IMGFLAG_ALLOCATED
;
354 mp_msg(MSGT_VFILTER
,MSGL_V
,"vf.c: have to REALLOCATE buffer memory :(\n");
358 mpi
->width
=w2
; mpi
->chroma_width
=(w2
+ (1<<mpi
->chroma_x_shift
) - 1)>>mpi
->chroma_x_shift
;
359 mpi
->height
=h
; mpi
->chroma_height
=(h
+ (1<<mpi
->chroma_y_shift
) - 1)>>mpi
->chroma_y_shift
;
362 if(!mpi
->bpp
) mp_image_setfmt(mpi
,outfmt
);
363 if(!(mpi
->flags
&MP_IMGFLAG_ALLOCATED
) && mpi
->type
>MP_IMGTYPE_EXPORT
){
365 // check libvo first!
366 if(vf
->get_image
) vf
->get_image(vf
,mpi
);
368 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
369 // non-direct and not yet allocated image. allocate it!
370 if (!mpi
->bpp
) { // no way we can allocate this
371 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
,
372 "vf_get_image: Tried to allocate a format that can not be allocated!\n");
376 // check if codec prefer aligned stride:
377 if(mp_imgflag
&MP_IMGFLAG_PREFER_ALIGNED_STRIDE
){
378 int align
=(mpi
->flags
&MP_IMGFLAG_PLANAR
&&
379 mpi
->flags
&MP_IMGFLAG_YUV
) ?
380 (8<<mpi
->chroma_x_shift
)-1 : 15; // -- maybe FIXME
381 w2
=((w
+align
)&(~align
));
383 // we have to change width... check if we CAN co it:
384 int flags
=vf
->query_format(vf
,outfmt
); // should not fail
385 if(!(flags
&3)) mp_msg(MSGT_DECVIDEO
,MSGL_WARN
,"??? vf_get_image{vf->query_format(outfmt)} failed!\n");
386 // printf("query -> 0x%X \n",flags);
387 if(flags
&VFCAP_ACCEPT_STRIDE
){
389 mpi
->chroma_width
=(w2
+ (1<<mpi
->chroma_x_shift
) - 1)>>mpi
->chroma_x_shift
;
394 mp_image_alloc_planes(mpi
);
395 // printf("clearing img!\n");
396 vf_mpi_clear(mpi
,0,0,mpi
->width
,mpi
->height
);
399 if(mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
)
400 if(vf
->start_slice
) vf
->start_slice(vf
,mpi
);
401 if(!(mpi
->flags
&MP_IMGFLAG_TYPE_DISPLAYED
)){
402 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"*** [%s] %s%s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n",
404 (mpi
->type
==MP_IMGTYPE_EXPORT
)?"Exporting":
405 ((mpi
->flags
&MP_IMGFLAG_DIRECT
)?"Direct Rendering":"Allocating"),
406 (mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
)?" (slices)":"",
407 mpi
->width
,mpi
->height
,mpi
->bpp
,
408 (mpi
->flags
&MP_IMGFLAG_YUV
)?"YUV":((mpi
->flags
&MP_IMGFLAG_SWAPPED
)?"BGR":"RGB"),
409 (mpi
->flags
&MP_IMGFLAG_PLANAR
)?"planar":"packed",
410 mpi
->bpp
*mpi
->width
*mpi
->height
/8);
411 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"(imgfmt: %x, planes: %p,%p,%p strides: %d,%d,%d, chroma: %dx%d, shift: h:%d,v:%d)\n",
412 mpi
->imgfmt
, mpi
->planes
[0], mpi
->planes
[1], mpi
->planes
[2],
413 mpi
->stride
[0], mpi
->stride
[1], mpi
->stride
[2],
414 mpi
->chroma_width
, mpi
->chroma_height
, mpi
->chroma_x_shift
, mpi
->chroma_y_shift
);
415 mpi
->flags
|=MP_IMGFLAG_TYPE_DISPLAYED
;
421 // printf("\rVF_MPI: %p %p %p %d %d %d \n",
422 // mpi->planes[0],mpi->planes[1],mpi->planes[2],
423 // mpi->stride[0],mpi->stride[1],mpi->stride[2]);
427 //============================================================================
429 // By default vf doesn't accept MPEGPES
430 static int vf_default_query_format(struct vf_instance
*vf
, unsigned int fmt
){
431 if(fmt
== IMGFMT_MPEGPES
) return 0;
432 return vf_next_query_format(vf
,fmt
);
435 vf_instance_t
* vf_open_plugin(const vf_info_t
* const* filter_list
, vf_instance_t
* next
, const char *name
, char **args
){
440 mp_msg(MSGT_VFILTER
,MSGL_ERR
,MSGTR_CouldNotFindVideoFilter
,name
);
441 return NULL
; // no such filter!
443 if(!strcmp(filter_list
[i
]->name
,name
)) break;
445 vf
=malloc(sizeof(vf_instance_t
));
446 memset(vf
,0,sizeof(vf_instance_t
));
447 vf
->info
=filter_list
[i
];
449 vf
->config
=vf_next_config
;
450 vf
->control
=vf_next_control
;
451 vf
->query_format
=vf_default_query_format
;
452 vf
->put_image
=vf_next_put_image
;
453 vf
->default_caps
=VFCAP_ACCEPT_STRIDE
;
455 if(vf
->info
->opts
) { // vf_vo get some special argument
456 const m_struct_t
* st
= vf
->info
->opts
;
457 void* vf_priv
= m_struct_alloc(st
);
459 for(n
= 0 ; args
&& args
[2*n
] ; n
++)
460 m_struct_set(st
,vf_priv
,args
[2*n
],args
[2*n
+1]);
463 } else // Otherwise we should have the '_oldargs_'
464 if(args
&& !strcmp(args
[0],"_oldargs_"))
465 args
= (char**)args
[1];
468 if(vf
->info
->vf_open(vf
,(char*)args
)>0) return vf
; // Success!
470 mp_msg(MSGT_VFILTER
,MSGL_ERR
,MSGTR_CouldNotOpenVideoFilter
,name
);
474 vf_instance_t
* vf_open_filter(vf_instance_t
* next
, const char *name
, char **args
){
475 if(args
&& strcmp(args
[0],"_oldargs_")) {
477 for(i
= 0 ; args
&& args
[2*i
] ; i
++)
478 l
+= 1 + strlen(args
[2*i
]) + 1 + strlen(args
[2*i
+1]);
483 p
+= sprintf(str
,"%s",name
);
484 for(i
= 0 ; args
&& args
[2*i
] ; i
++)
485 p
+= sprintf(p
," %s=%s",args
[2*i
],args
[2*i
+1]);
486 mp_msg(MSGT_VFILTER
,MSGL_INFO
,MSGTR_OpeningVideoFilter
"[%s]\n",str
);
488 } else if(strcmp(name
,"vo")) {
489 if(args
&& strcmp(args
[0],"_oldargs_") == 0)
490 mp_msg(MSGT_VFILTER
,MSGL_INFO
,MSGTR_OpeningVideoFilter
491 "[%s=%s]\n", name
,args
[1]);
493 mp_msg(MSGT_VFILTER
,MSGL_INFO
,MSGTR_OpeningVideoFilter
496 return vf_open_plugin(filter_list
,next
,name
,args
);
500 * \brief adds a filter before the last one (which should be the vo filter).
501 * \param vf start of the filter chain.
502 * \param name name of the filter to add.
503 * \param args argument list for the filter.
504 * \return pointer to the filter instance that was created.
506 vf_instance_t
* vf_add_before_vo(vf_instance_t
**vf
, char *name
, char **args
) {
507 vf_instance_t
*vo
, *prev
= NULL
, *new;
508 // Find the last filter (should be vf_vo)
509 for (vo
= *vf
; vo
->next
; vo
= vo
->next
)
511 new = vf_open_filter(vo
, name
, args
);
519 //============================================================================
521 unsigned int vf_match_csp(vf_instance_t
** vfp
,const unsigned int* list
,unsigned int preferred
){
522 vf_instance_t
* vf
=*vfp
;
523 const unsigned int* p
;
526 if((p
=list
)) while(*p
){
527 ret
=vf
->query_format(vf
,*p
);
528 mp_msg(MSGT_VFILTER
,MSGL_V
,"[%s] query(%s) -> %d\n",vf
->info
->name
,vo_format_name(*p
),ret
&3);
529 if(ret
&2){ best
=*p
; break;} // no conversion -> bingo!
530 if(ret
&1 && !best
) best
=*p
; // best with conversion
533 if(best
) return best
; // bingo, they have common csp!
534 // ok, then try with scale:
535 if(vf
->info
== &vf_info_scale
) return 0; // avoid infinite recursion!
536 vf
=vf_open_filter(vf
,"scale",NULL
);
537 if(!vf
) return 0; // failed to init "scale"
538 // try the preferred csp first:
539 if(preferred
&& vf
->query_format(vf
,preferred
)) best
=preferred
; else
540 // try the list again, now with "scaler" :
541 if((p
=list
)) while(*p
){
542 ret
=vf
->query_format(vf
,*p
);
543 mp_msg(MSGT_VFILTER
,MSGL_V
,"[%s] query(%s) -> %d\n",vf
->info
->name
,vo_format_name(*p
),ret
&3);
544 if(ret
&2){ best
=*p
; break;} // no conversion -> bingo!
545 if(ret
&1 && !best
) best
=*p
; // best with conversion
548 if(best
) *vfp
=vf
; // else uninit vf !FIXME!
552 void vf_clone_mpi_attributes(mp_image_t
* dst
, mp_image_t
* src
){
553 dst
->pict_type
= src
->pict_type
;
554 dst
->fields
= src
->fields
;
555 dst
->qscale_type
= src
->qscale_type
;
556 if(dst
->width
== src
->width
&& dst
->height
== src
->height
){
557 dst
->qstride
= src
->qstride
;
558 dst
->qscale
= src
->qscale
;
562 void vf_queue_frame(vf_instance_t
*vf
, int (*func
)(vf_instance_t
*))
564 vf
->continue_buffered_image
= func
;
567 // Output the next buffered image (if any) from the filter chain.
568 // The queue could be kept as a simple stack/list instead avoiding the
569 // looping here, but there's currently no good context variable where
570 // that could be stored so this was easier to implement.
572 int vf_output_queued_frame(vf_instance_t
*vf
)
576 vf_instance_t
*current
;
577 vf_instance_t
*last
=NULL
;
578 int (*tmp
)(vf_instance_t
*);
579 for (current
= vf
; current
; current
= current
->next
)
580 if (current
->continue_buffered_image
)
584 tmp
= last
->continue_buffered_image
;
585 last
->continue_buffered_image
= NULL
;
588 vf
->control(vf
, VFCTRL_DRAW_OSD
, NULL
);
590 vf
->control(vf
, VFCTRL_DRAW_EOSD
, NULL
);
600 * \brief Video config() function wrapper
602 * Blocks config() calls with different size or format for filters
603 * with VFCAP_CONSTANT
605 * First call is redirected to vf->config.
607 * In following calls, it verifies that the configuration parameters
608 * are unchanged, and returns either success or error.
611 int vf_config_wrapper(struct vf_instance
*vf
,
612 int width
, int height
, int d_width
, int d_height
,
613 unsigned int flags
, unsigned int outfmt
)
616 if ((vf
->default_caps
&VFCAP_CONSTANT
) && vf
->fmt
.have_configured
) {
617 if ((vf
->fmt
.orig_width
!= width
)
618 || (vf
->fmt
.orig_height
!= height
)
619 || (vf
->fmt
.orig_fmt
!= outfmt
)) {
620 mp_msg(MSGT_VFILTER
,MSGL_ERR
,MSGTR_ResolutionDoesntMatch
);
625 vf
->fmt
.have_configured
= 1;
626 vf
->fmt
.orig_height
= height
;
627 vf
->fmt
.orig_width
= width
;
628 vf
->fmt
.orig_fmt
= outfmt
;
629 r
= vf
->config(vf
, width
, height
, d_width
, d_height
, flags
, outfmt
);
630 if (!r
) vf
->fmt
.have_configured
= 0;
634 int vf_next_config(struct vf_instance
*vf
,
635 int width
, int height
, int d_width
, int d_height
,
636 unsigned int voflags
, unsigned int outfmt
){
638 int flags
=vf
->next
->query_format(vf
->next
,outfmt
);
640 // hmm. colorspace mismatch!!!
641 // let's insert the 'scale' filter, it does the job for us:
643 if(vf
->next
->info
==&vf_info_scale
) return 0; // scale->scale
644 vf2
=vf_open_filter(vf
->next
,"scale",NULL
);
645 if(!vf2
) return 0; // shouldn't happen!
647 flags
=vf
->next
->query_format(vf
->next
,outfmt
);
649 mp_msg(MSGT_VFILTER
,MSGL_ERR
,MSGTR_CannotFindColorspace
);
653 mp_msg(MSGT_VFILTER
,MSGL_V
,"REQ: flags=0x%X req=0x%X \n",flags
,vf
->default_reqs
);
654 miss
=vf
->default_reqs
- (flags
&vf
->default_reqs
);
655 if(miss
&VFCAP_ACCEPT_STRIDE
){
656 // vf requires stride support but vf->next doesn't support it!
657 // let's insert the 'expand' filter, it does the job for us:
658 vf_instance_t
* vf2
=vf_open_filter(vf
->next
,"expand",NULL
);
659 if(!vf2
) return 0; // shouldn't happen!
662 vf
->next
->w
= width
; vf
->next
->h
= height
;
663 return vf_config_wrapper(vf
->next
,width
,height
,d_width
,d_height
,voflags
,outfmt
);
666 int vf_next_control(struct vf_instance
*vf
, int request
, void* data
){
667 return vf
->next
->control(vf
->next
,request
,data
);
670 void vf_extra_flip(struct vf_instance
*vf
) {
671 vf_next_control(vf
, VFCTRL_DRAW_OSD
, NULL
);
673 vf_next_control(vf
, VFCTRL_DRAW_EOSD
, NULL
);
675 vf_next_control(vf
, VFCTRL_FLIP_PAGE
, NULL
);
678 int vf_next_query_format(struct vf_instance
*vf
, unsigned int fmt
){
679 int flags
=vf
->next
->query_format(vf
->next
,fmt
);
680 if(flags
) flags
|=vf
->default_caps
;
684 int vf_next_put_image(struct vf_instance
*vf
,mp_image_t
*mpi
, double pts
){
685 return vf
->next
->put_image(vf
->next
,mpi
, pts
);
688 void vf_next_draw_slice(struct vf_instance
*vf
,unsigned char** src
, int * stride
,int w
, int h
, int x
, int y
){
689 if (vf
->next
->draw_slice
) {
690 vf
->next
->draw_slice(vf
->next
,src
,stride
,w
,h
,x
,y
);
694 mp_msg(MSGT_VFILTER
,MSGL_ERR
,"draw_slice: dmpi not stored by vf_%s\n", vf
->info
->name
);
697 if (!(vf
->dmpi
->flags
& MP_IMGFLAG_PLANAR
)) {
698 memcpy_pic(vf
->dmpi
->planes
[0]+y
*vf
->dmpi
->stride
[0]+vf
->dmpi
->bpp
/8*x
,
699 src
[0], vf
->dmpi
->bpp
/8*w
, h
, vf
->dmpi
->stride
[0], stride
[0]);
702 memcpy_pic(vf
->dmpi
->planes
[0]+y
*vf
->dmpi
->stride
[0]+x
, src
[0],
703 w
, h
, vf
->dmpi
->stride
[0], stride
[0]);
704 memcpy_pic(vf
->dmpi
->planes
[1]+(y
>>vf
->dmpi
->chroma_y_shift
)*vf
->dmpi
->stride
[1]+(x
>>vf
->dmpi
->chroma_x_shift
),
705 src
[1], w
>>vf
->dmpi
->chroma_x_shift
, h
>>vf
->dmpi
->chroma_y_shift
, vf
->dmpi
->stride
[1], stride
[1]);
706 memcpy_pic(vf
->dmpi
->planes
[2]+(y
>>vf
->dmpi
->chroma_y_shift
)*vf
->dmpi
->stride
[2]+(x
>>vf
->dmpi
->chroma_x_shift
),
707 src
[2], w
>>vf
->dmpi
->chroma_x_shift
, h
>>vf
->dmpi
->chroma_y_shift
, vf
->dmpi
->stride
[2], stride
[2]);
710 //============================================================================
712 vf_instance_t
* append_filters(vf_instance_t
* last
){
717 // We want to add them in the 'right order'
718 for(i
= 0 ; vf_settings
[i
].name
; i
++)
720 for(i
-- ; i
>= 0 ; i
--) {
721 //printf("Open filter %s\n",vf_settings[i].name);
722 vf
= vf_open_filter(last
,vf_settings
[i
].name
,vf_settings
[i
].attribs
);
729 //============================================================================
731 void vf_uninit_filter(vf_instance_t
* vf
){
732 if(vf
->uninit
) vf
->uninit(vf
);
733 free_mp_image(vf
->imgctx
.static_images
[0]);
734 free_mp_image(vf
->imgctx
.static_images
[1]);
735 free_mp_image(vf
->imgctx
.temp_images
[0]);
736 free_mp_image(vf
->imgctx
.export_images
[0]);
740 void vf_uninit_filter_chain(vf_instance_t
* vf
){
742 vf_instance_t
* next
=vf
->next
;
743 vf_uninit_filter(vf
);