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.
31 #include "img_format.h"
35 #include "libvo/fastmemcpy.h"
36 #include "libavutil/mem.h"
38 extern const vf_info_t vf_info_vo
;
39 extern const vf_info_t vf_info_rectangle
;
40 extern const vf_info_t vf_info_bmovl
;
41 extern const vf_info_t vf_info_crop
;
42 extern const vf_info_t vf_info_expand
;
43 extern const vf_info_t vf_info_pp
;
44 extern const vf_info_t vf_info_scale
;
45 extern const vf_info_t vf_info_format
;
46 extern const vf_info_t vf_info_noformat
;
47 extern const vf_info_t vf_info_flip
;
48 extern const vf_info_t vf_info_rotate
;
49 extern const vf_info_t vf_info_mirror
;
50 extern const vf_info_t vf_info_palette
;
51 extern const vf_info_t vf_info_lavc
;
52 extern const vf_info_t vf_info_dvbscale
;
53 extern const vf_info_t vf_info_cropdetect
;
54 extern const vf_info_t vf_info_test
;
55 extern const vf_info_t vf_info_noise
;
56 extern const vf_info_t vf_info_yvu9
;
57 extern const vf_info_t vf_info_lavcdeint
;
58 extern const vf_info_t vf_info_eq
;
59 extern const vf_info_t vf_info_eq2
;
60 extern const vf_info_t vf_info_gradfun
;
61 extern const vf_info_t vf_info_halfpack
;
62 extern const vf_info_t vf_info_dint
;
63 extern const vf_info_t vf_info_1bpp
;
64 extern const vf_info_t vf_info_2xsai
;
65 extern const vf_info_t vf_info_unsharp
;
66 extern const vf_info_t vf_info_swapuv
;
67 extern const vf_info_t vf_info_il
;
68 extern const vf_info_t vf_info_fil
;
69 extern const vf_info_t vf_info_boxblur
;
70 extern const vf_info_t vf_info_sab
;
71 extern const vf_info_t vf_info_smartblur
;
72 extern const vf_info_t vf_info_perspective
;
73 extern const vf_info_t vf_info_down3dright
;
74 extern const vf_info_t vf_info_field
;
75 extern const vf_info_t vf_info_denoise3d
;
76 extern const vf_info_t vf_info_hqdn3d
;
77 extern const vf_info_t vf_info_detc
;
78 extern const vf_info_t vf_info_telecine
;
79 extern const vf_info_t vf_info_tinterlace
;
80 extern const vf_info_t vf_info_tfields
;
81 extern const vf_info_t vf_info_ivtc
;
82 extern const vf_info_t vf_info_ilpack
;
83 extern const vf_info_t vf_info_dsize
;
84 extern const vf_info_t vf_info_decimate
;
85 extern const vf_info_t vf_info_softpulldown
;
86 extern const vf_info_t vf_info_pullup
;
87 extern const vf_info_t vf_info_filmdint
;
88 extern const vf_info_t vf_info_framestep
;
89 extern const vf_info_t vf_info_tile
;
90 extern const vf_info_t vf_info_delogo
;
91 extern const vf_info_t vf_info_remove_logo
;
92 extern const vf_info_t vf_info_hue
;
93 extern const vf_info_t vf_info_uspp
;
94 extern const vf_info_t vf_info_fspp
;
95 extern const vf_info_t vf_info_pp7
;
96 extern const vf_info_t vf_info_yuvcsp
;
97 extern const vf_info_t vf_info_kerndeint
;
98 extern const vf_info_t vf_info_rgbtest
;
99 extern const vf_info_t vf_info_qp
;
100 extern const vf_info_t vf_info_phase
;
101 extern const vf_info_t vf_info_divtc
;
102 extern const vf_info_t vf_info_harddup
;
103 extern const vf_info_t vf_info_softskip
;
104 extern const vf_info_t vf_info_screenshot
;
105 extern const vf_info_t vf_info_ass
;
106 extern const vf_info_t vf_info_yadif
;
107 extern const vf_info_t vf_info_blackframe
;
108 extern const vf_info_t vf_info_geq
;
109 extern const vf_info_t vf_info_ow
;
110 extern const vf_info_t vf_info_fixpts
;
111 extern const vf_info_t vf_info_stereo3d
;
113 // list of available filters:
114 static const vf_info_t
*const filter_list
[] = {
116 #ifdef HAVE_POSIX_SELECT
132 #ifdef CONFIG_LIBPOSTPROC
160 &vf_info_perspective
,
161 &vf_info_down3dright
,
173 &vf_info_softpulldown
,
179 &vf_info_remove_logo
,
202 const m_obj_list_t vf_obj_list
= {
203 (void **)filter_list
,
204 M_ST_OFF(vf_info_t
, name
),
205 M_ST_OFF(vf_info_t
, info
),
206 M_ST_OFF(vf_info_t
, opts
)
209 //============================================================================
212 void vf_mpi_clear(mp_image_t
*mpi
, int x0
, int y0
, int w
, int h
)
215 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
218 if (x0
== 0 && w
== mpi
->width
) {
220 memset(mpi
->planes
[0] + mpi
->stride
[0] * y0
, 0, mpi
->stride
[0] * h
);
221 memset(mpi
->planes
[1] + mpi
->stride
[1] *(y0
>> mpi
->chroma_y_shift
),
222 128, mpi
->stride
[1] * (h
>> mpi
->chroma_y_shift
));
223 memset(mpi
->planes
[2] + mpi
->stride
[2] *(y0
>> mpi
->chroma_y_shift
),
224 128, mpi
->stride
[2] * (h
>> mpi
->chroma_y_shift
));
226 for (y
= y0
; y
< y0
+ h
; y
+= 2) {
227 memset(mpi
->planes
[0] + x0
+ mpi
->stride
[0] * y
, 0, w
);
228 memset(mpi
->planes
[0] + x0
+ mpi
->stride
[0] * (y
+ 1), 0, w
);
229 memset(mpi
->planes
[1] + (x0
>> mpi
->chroma_x_shift
) +
230 mpi
->stride
[1] * (y
>> mpi
->chroma_y_shift
),
231 128, (w
>> mpi
->chroma_x_shift
));
232 memset(mpi
->planes
[2] + (x0
>> mpi
->chroma_x_shift
) +
233 mpi
->stride
[2] * (y
>> mpi
->chroma_y_shift
),
234 128, (w
>> mpi
->chroma_x_shift
));
239 for (y
= y0
; y
< y0
+ h
; y
++) {
240 unsigned char *dst
= mpi
->planes
[0] + mpi
->stride
[0] * y
+
241 (mpi
->bpp
>> 3) * x0
;
242 if (mpi
->flags
& MP_IMGFLAG_YUV
) {
243 unsigned int *p
= (unsigned int *) dst
;
244 int size
= (mpi
->bpp
>> 3) * w
/ 4;
247 #define CLEAR_PACKEDYUV_PATTERN 0x00800080
248 #define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x80008000
250 #define CLEAR_PACKEDYUV_PATTERN 0x80008000
251 #define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x00800080
253 if (mpi
->flags
& MP_IMGFLAG_SWAPPED
) {
254 for (i
= 0; i
< size
- 3; i
+= 4)
255 p
[i
] = p
[i
+ 1] = p
[i
+ 2] = p
[i
+ 3] = CLEAR_PACKEDYUV_PATTERN_SWAPPED
;
256 for (; i
< size
; i
++)
257 p
[i
] = CLEAR_PACKEDYUV_PATTERN_SWAPPED
;
259 for (i
= 0; i
< size
- 3; i
+= 4)
260 p
[i
] = p
[i
+ 1] = p
[i
+ 2] = p
[i
+ 3] = CLEAR_PACKEDYUV_PATTERN
;
261 for (; i
< size
; i
++)
262 p
[i
] = CLEAR_PACKEDYUV_PATTERN
;
265 memset(dst
, 0, (mpi
->bpp
>> 3) * w
);
269 mp_image_t
*vf_get_image(vf_instance_t
*vf
, unsigned int outfmt
,
270 int mp_imgtype
, int mp_imgflag
, int w
, int h
)
272 mp_image_t
*mpi
= NULL
;
274 int number
= mp_imgtype
>> 16;
276 assert(w
== -1 || w
>= vf
->w
);
277 assert(h
== -1 || h
>= vf
->h
);
286 w2
= (mp_imgflag
& MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE
) ?
287 ((w
+ 15) & (~15)) : w
;
289 if (vf
->put_image
== vf_next_put_image
) {
290 // passthru mode, if the filter uses the fallback/default put_image()
291 return vf_get_image(vf
->next
, outfmt
, mp_imgtype
, mp_imgflag
, w
, h
);
294 // Note: we should call libvo first to check if it supports direct rendering
295 // and if not, then fallback to software buffers:
296 switch (mp_imgtype
& 0xff) {
297 case MP_IMGTYPE_EXPORT
:
298 if (!vf
->imgctx
.export_images
[0])
299 vf
->imgctx
.export_images
[0] = new_mp_image(w2
, h
);
300 mpi
= vf
->imgctx
.export_images
[0];
302 case MP_IMGTYPE_STATIC
:
303 if (!vf
->imgctx
.static_images
[0])
304 vf
->imgctx
.static_images
[0] = new_mp_image(w2
, h
);
305 mpi
= vf
->imgctx
.static_images
[0];
307 case MP_IMGTYPE_TEMP
:
308 if (!vf
->imgctx
.temp_images
[0])
309 vf
->imgctx
.temp_images
[0] = new_mp_image(w2
, h
);
310 mpi
= vf
->imgctx
.temp_images
[0];
313 if (!(mp_imgflag
& MP_IMGFLAG_READABLE
)) { // B frame:
314 if (!vf
->imgctx
.temp_images
[0])
315 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
])
321 vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
] = new_mp_image(w2
, h
);
322 mpi
= vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
];
323 vf
->imgctx
.static_idx
^= 1;
325 case MP_IMGTYPE_NUMBERED
:
328 for (i
= 0; i
< NUM_NUMBERED_MPI
; i
++)
329 if (!vf
->imgctx
.numbered_images
[i
] ||
330 !vf
->imgctx
.numbered_images
[i
]->usage_count
)
334 if (number
< 0 || number
>= NUM_NUMBERED_MPI
)
336 if (!vf
->imgctx
.numbered_images
[number
])
337 vf
->imgctx
.numbered_images
[number
] = new_mp_image(w2
, h
);
338 mpi
= vf
->imgctx
.numbered_images
[number
];
339 mpi
->number
= number
;
343 mpi
->type
= mp_imgtype
;
346 // keep buffer allocation status & color flags only:
347 mpi
->flags
&= MP_IMGFLAG_ALLOCATED
| MP_IMGFLAG_TYPE_DISPLAYED
|
348 MP_IMGFLAGMASK_COLORS
;
349 // accept restrictions, draw_slice and palette flags only:
350 mpi
->flags
|= mp_imgflag
& (MP_IMGFLAGMASK_RESTRICTIONS
|
351 MP_IMGFLAG_DRAW_CALLBACK
| MP_IMGFLAG_RGB_PALETTE
);
353 mpi
->flags
&= ~MP_IMGFLAG_DRAW_CALLBACK
;
354 if (mpi
->width
!= w2
|| mpi
->height
!= h
) {
355 if (mpi
->flags
& MP_IMGFLAG_ALLOCATED
) {
356 if (mpi
->width
< w2
|| mpi
->height
< h
) {
357 // need to re-allocate buffer memory:
358 av_free(mpi
->planes
[0]);
359 mpi
->flags
&= ~MP_IMGFLAG_ALLOCATED
;
360 mp_msg(MSGT_VFILTER
, MSGL_V
,
361 "vf.c: have to REALLOCATE buffer memory :(\n");
365 mpi
->chroma_width
= (w2
+ (1 << mpi
->chroma_x_shift
) - 1) >>
368 mpi
->chroma_height
= (h
+ (1 << mpi
->chroma_y_shift
) - 1) >>
372 mp_image_setfmt(mpi
, outfmt
);
373 if (!(mpi
->flags
& MP_IMGFLAG_ALLOCATED
) &&
374 mpi
->type
> MP_IMGTYPE_EXPORT
) {
375 // check libvo first!
377 vf
->get_image(vf
, mpi
);
379 if (!(mpi
->flags
& MP_IMGFLAG_DIRECT
)) {
380 // non-direct and not yet allocated image. allocate it!
381 if (!mpi
->bpp
) { // no way we can allocate this
382 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
,
383 "vf_get_image: Tried to allocate a format that "
384 "can not be allocated!\n");
388 // check if codec prefer aligned stride:
389 if (mp_imgflag
& MP_IMGFLAG_PREFER_ALIGNED_STRIDE
) {
390 int align
= (mpi
->flags
& MP_IMGFLAG_PLANAR
&&
391 mpi
->flags
& MP_IMGFLAG_YUV
) ?
392 (8 << mpi
->chroma_x_shift
) - 1 : 15; // OK?
393 w2
= ((w
+ align
) & (~align
));
394 if (mpi
->width
!= w2
) {
395 // we have to change width... check if we CAN co it:
396 int flags
= vf
->query_format(vf
, outfmt
);
398 if (!(flags
& (VFCAP_CSP_SUPPORTED
|
399 VFCAP_CSP_SUPPORTED_BY_HW
)))
400 mp_msg(MSGT_DECVIDEO
, MSGL_WARN
,
401 "??? vf_get_image{vf->query_format(outfmt)} "
403 if (flags
& VFCAP_ACCEPT_STRIDE
) {
406 (w2
+ (1 << mpi
->chroma_x_shift
) - 1) >>
412 mp_image_alloc_planes(mpi
);
413 vf_mpi_clear(mpi
, 0, 0, mpi
->width
, mpi
->height
);
416 if (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)
418 vf
->start_slice(vf
, mpi
);
419 if (!(mpi
->flags
& MP_IMGFLAG_TYPE_DISPLAYED
)) {
420 mp_msg(MSGT_DECVIDEO
, MSGL_V
,
421 "*** [%s] %s%s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n",
423 (mpi
->type
== MP_IMGTYPE_EXPORT
) ? "Exporting" :
424 ((mpi
->flags
& MP_IMGFLAG_DIRECT
) ?
425 "Direct Rendering" : "Allocating"),
426 (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
) ? " (slices)" : "",
427 mpi
->width
, mpi
->height
, mpi
->bpp
,
428 (mpi
->flags
& MP_IMGFLAG_YUV
) ? "YUV" :
429 ((mpi
->flags
& MP_IMGFLAG_SWAPPED
) ? "BGR" : "RGB"),
430 (mpi
->flags
& MP_IMGFLAG_PLANAR
) ? "planar" : "packed",
431 mpi
->bpp
* mpi
->width
* mpi
->height
/ 8);
432 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "(imgfmt: %x, planes: %p,%p,%p "
433 "strides: %d,%d,%d, chroma: %dx%d, shift: h:%d,v:%d)\n",
434 mpi
->imgfmt
, mpi
->planes
[0], mpi
->planes
[1], mpi
->planes
[2],
435 mpi
->stride
[0], mpi
->stride
[1], mpi
->stride
[2],
436 mpi
->chroma_width
, mpi
->chroma_height
,
437 mpi
->chroma_x_shift
, mpi
->chroma_y_shift
);
438 mpi
->flags
|= MP_IMGFLAG_TYPE_DISPLAYED
;
446 //============================================================================
448 // By default vf doesn't accept MPEGPES
449 static int vf_default_query_format(struct vf_instance
*vf
, unsigned int fmt
)
451 if (fmt
== IMGFMT_MPEGPES
)
453 return vf_next_query_format(vf
, fmt
);
456 struct vf_instance
*vf_open_plugin_noerr(struct MPOpts
*opts
,
457 const vf_info_t
*const *filter_list
,
458 vf_instance_t
*next
, const char *name
,
459 char **args
, int *retcode
)
464 if (!filter_list
[i
]) {
465 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
,
466 "Couldn't find video filter '%s'.\n", name
);
467 return NULL
; // no such filter!
469 if (!strcmp(filter_list
[i
]->name
, name
))
472 vf
= calloc(1, sizeof *vf
);
474 vf
->info
= filter_list
[i
];
476 vf
->config
= vf_next_config
;
477 vf
->control
= vf_next_control
;
478 vf
->query_format
= vf_default_query_format
;
479 vf
->put_image
= vf_next_put_image
;
480 vf
->default_caps
= VFCAP_ACCEPT_STRIDE
;
481 vf
->default_reqs
= 0;
482 if (vf
->info
->opts
) { // vf_vo get some special argument
483 const m_struct_t
*st
= vf
->info
->opts
;
484 void *vf_priv
= m_struct_alloc(st
);
486 for (n
= 0; args
&& args
[2 * n
]; n
++)
487 m_struct_set(st
, vf_priv
, args
[2 * n
], bstr(args
[2 * n
+ 1]));
490 } else // Otherwise we should have the '_oldargs_'
491 if (args
&& !strcmp(args
[0], "_oldargs_"))
492 args
= (char **)args
[1];
495 *retcode
= vf
->info
->vf_open(vf
, (char *)args
);
502 struct vf_instance
*vf_open_plugin(struct MPOpts
*opts
,
503 const vf_info_t
*const *filter_list
,
504 vf_instance_t
*next
, const char *name
,
507 struct vf_instance
*vf
= vf_open_plugin_noerr(opts
, filter_list
, next
,
508 name
, args
, &(int){0});
510 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
, "Couldn't open video filter '%s'.\n",
515 vf_instance_t
*vf_open_filter(struct MPOpts
*opts
, vf_instance_t
*next
,
516 const char *name
, char **args
)
518 if (args
&& strcmp(args
[0], "_oldargs_")) {
520 for (i
= 0; args
&& args
[2 * i
]; i
++)
521 l
+= 1 + strlen(args
[2 * i
]) + 1 + strlen(args
[2 * i
+ 1]);
526 p
+= sprintf(str
, "%s", name
);
527 for (i
= 0; args
&& args
[2 * i
]; i
++)
528 p
+= sprintf(p
, " %s=%s", args
[2 * i
], args
[2 * i
+ 1]);
529 mp_msg(MSGT_VFILTER
, MSGL_INFO
, "%s[%s]\n",
530 mp_gtext("Opening video filter: "), str
);
532 } else if (strcmp(name
, "vo")) {
533 if (args
&& strcmp(args
[0], "_oldargs_") == 0)
534 mp_msg(MSGT_VFILTER
, MSGL_INFO
, "%s[%s=%s]\n",
535 mp_gtext("Opening video filter: "), name
, args
[1]);
537 mp_msg(MSGT_VFILTER
, MSGL_INFO
, "%s[%s]\n",
538 mp_gtext("Opening video filter: "), name
);
540 return vf_open_plugin(opts
, filter_list
, next
, name
, args
);
544 * \brief adds a filter before the last one (which should be the vo filter).
545 * \param vf start of the filter chain.
546 * \param name name of the filter to add.
547 * \param args argument list for the filter.
548 * \return pointer to the filter instance that was created.
550 vf_instance_t
*vf_add_before_vo(vf_instance_t
**vf
, char *name
, char **args
)
552 struct MPOpts
*opts
= (*vf
)->opts
;
553 vf_instance_t
*vo
, *prev
= NULL
, *new;
554 // Find the last filter (should be vf_vo)
555 for (vo
= *vf
; vo
->next
; vo
= vo
->next
)
557 new = vf_open_filter(opts
, vo
, name
, args
);
565 //============================================================================
567 unsigned int vf_match_csp(vf_instance_t
**vfp
, const unsigned int *list
,
568 unsigned int preferred
)
570 vf_instance_t
*vf
= *vfp
;
571 struct MPOpts
*opts
= vf
->opts
;
572 const unsigned int *p
;
573 unsigned int best
= 0;
577 ret
= vf
->query_format(vf
, *p
);
578 mp_msg(MSGT_VFILTER
, MSGL_V
, "[%s] query(%s) -> %x\n",
579 vf
->info
->name
, vo_format_name(*p
), ret
);
580 if (ret
& VFCAP_CSP_SUPPORTED_BY_HW
) {
584 if (ret
& VFCAP_CSP_SUPPORTED
&& !best
)
589 return best
; // bingo, they have common csp!
590 // ok, then try with scale:
591 if (vf
->info
== &vf_info_scale
)
592 return 0; // avoid infinite recursion!
593 vf
= vf_open_filter(opts
, vf
, "scale", NULL
);
595 return 0; // failed to init "scale"
596 // try the preferred csp first:
597 if (preferred
&& vf
->query_format(vf
, preferred
))
600 // try the list again, now with "scaler" :
603 ret
= vf
->query_format(vf
, *p
);
604 mp_msg(MSGT_VFILTER
, MSGL_V
, "[%s] query(%s) -> %x\n",
605 vf
->info
->name
, vo_format_name(*p
), ret
);
606 if (ret
& VFCAP_CSP_SUPPORTED_BY_HW
) {
610 if (ret
& VFCAP_CSP_SUPPORTED
&& !best
)
615 *vfp
= vf
; // else uninit vf !FIXME!
619 void vf_clone_mpi_attributes(mp_image_t
*dst
, mp_image_t
*src
)
621 dst
->pict_type
= src
->pict_type
;
622 dst
->fields
= src
->fields
;
623 dst
->qscale_type
= src
->qscale_type
;
624 if (dst
->width
== src
->width
&& dst
->height
== src
->height
) {
625 dst
->qstride
= src
->qstride
;
626 dst
->qscale
= src
->qscale
;
630 void vf_queue_frame(vf_instance_t
*vf
, int (*func
)(vf_instance_t
*))
632 vf
->continue_buffered_image
= func
;
635 // Output the next buffered image (if any) from the filter chain.
636 // The queue could be kept as a simple stack/list instead avoiding the
637 // looping here, but there's currently no good context variable where
638 // that could be stored so this was easier to implement.
640 int vf_output_queued_frame(vf_instance_t
*vf
)
644 vf_instance_t
*current
;
645 vf_instance_t
*last
= NULL
;
646 int (*tmp
)(vf_instance_t
*);
647 for (current
= vf
; current
; current
= current
->next
)
648 if (current
->continue_buffered_image
)
652 tmp
= last
->continue_buffered_image
;
653 last
->continue_buffered_image
= NULL
;
662 * \brief Video config() function wrapper
664 * Blocks config() calls with different size or format for filters
665 * with VFCAP_CONSTANT
667 * First call is redirected to vf->config.
669 * In following calls, it verifies that the configuration parameters
670 * are unchanged, and returns either success or error.
673 int vf_config_wrapper(struct vf_instance
*vf
,
674 int width
, int height
, int d_width
, int d_height
,
675 unsigned int flags
, unsigned int outfmt
)
678 if ((vf
->default_caps
& VFCAP_CONSTANT
) && vf
->fmt
.have_configured
) {
679 if ((vf
->fmt
.orig_width
!= width
)
680 || (vf
->fmt
.orig_height
!= height
)
681 || (vf
->fmt
.orig_fmt
!= outfmt
)) {
682 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
, "\nNew video file has different "
683 "resolution or colorspace than the previous one.\n");
688 vf
->fmt
.have_configured
= 1;
689 vf
->fmt
.orig_height
= height
;
690 vf
->fmt
.orig_width
= width
;
691 vf
->fmt
.orig_fmt
= outfmt
;
692 r
= vf
->config(vf
, width
, height
, d_width
, d_height
, flags
, outfmt
);
694 vf
->fmt
.have_configured
= 0;
698 int vf_next_config(struct vf_instance
*vf
,
699 int width
, int height
, int d_width
, int d_height
,
700 unsigned int voflags
, unsigned int outfmt
)
702 struct MPOpts
*opts
= vf
->opts
;
704 int flags
= vf
->next
->query_format(vf
->next
, outfmt
);
706 // hmm. colorspace mismatch!!!
707 // let's insert the 'scale' filter, it does the job for us:
709 if (vf
->next
->info
== &vf_info_scale
)
710 return 0; // scale->scale
711 vf2
= vf_open_filter(opts
, vf
->next
, "scale", NULL
);
713 return 0; // shouldn't happen!
715 flags
= vf
->next
->query_format(vf
->next
, outfmt
);
717 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
, "Cannot find matching colorspace, "
718 "even by inserting 'scale' :(\n");
722 mp_msg(MSGT_VFILTER
, MSGL_V
, "REQ: flags=0x%X req=0x%X \n",
723 flags
, vf
->default_reqs
);
724 miss
= vf
->default_reqs
- (flags
& vf
->default_reqs
);
725 if (miss
& VFCAP_ACCEPT_STRIDE
) {
726 // vf requires stride support but vf->next doesn't support it!
727 // let's insert the 'expand' filter, it does the job for us:
728 vf_instance_t
*vf2
= vf_open_filter(opts
, vf
->next
, "expand", NULL
);
730 return 0; // shouldn't happen!
734 vf
->next
->h
= height
;
735 return vf_config_wrapper(vf
->next
, width
, height
, d_width
, d_height
,
739 int vf_next_control(struct vf_instance
*vf
, int request
, void *data
)
741 return vf
->next
->control(vf
->next
, request
, data
);
744 int vf_next_query_format(struct vf_instance
*vf
, unsigned int fmt
)
746 int flags
= vf
->next
->query_format(vf
->next
, fmt
);
748 flags
|= vf
->default_caps
;
752 int vf_next_put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
)
754 return vf
->next
->put_image(vf
->next
, mpi
, pts
);
757 void vf_next_draw_slice(struct vf_instance
*vf
, unsigned char **src
,
758 int *stride
, int w
, int h
, int x
, int y
)
760 if (vf
->next
->draw_slice
) {
761 vf
->next
->draw_slice(vf
->next
, src
, stride
, w
, h
, x
, y
);
765 mp_msg(MSGT_VFILTER
, MSGL_ERR
,
766 "draw_slice: dmpi not stored by vf_%s\n", vf
->info
->name
);
769 if (!(vf
->dmpi
->flags
& MP_IMGFLAG_PLANAR
)) {
770 memcpy_pic(vf
->dmpi
->planes
[0] + y
* vf
->dmpi
->stride
[0] +
771 vf
->dmpi
->bpp
/ 8 * x
,
772 src
[0], vf
->dmpi
->bpp
/ 8 * w
, h
, vf
->dmpi
->stride
[0],
776 memcpy_pic(vf
->dmpi
->planes
[0] + y
* vf
->dmpi
->stride
[0] + x
, src
[0],
777 w
, h
, vf
->dmpi
->stride
[0], stride
[0]);
778 memcpy_pic(vf
->dmpi
->planes
[1]
779 + (y
>> vf
->dmpi
->chroma_y_shift
) * vf
->dmpi
->stride
[1]
780 + (x
>> vf
->dmpi
->chroma_x_shift
),
781 src
[1], w
>> vf
->dmpi
->chroma_x_shift
,
782 h
>> vf
->dmpi
->chroma_y_shift
, vf
->dmpi
->stride
[1], stride
[1]);
783 memcpy_pic(vf
->dmpi
->planes
[2]
784 + (y
>> vf
->dmpi
->chroma_y_shift
) * vf
->dmpi
->stride
[2]
785 + (x
>> vf
->dmpi
->chroma_x_shift
),
786 src
[2], w
>> vf
->dmpi
->chroma_x_shift
,
787 h
>> vf
->dmpi
->chroma_y_shift
, vf
->dmpi
->stride
[2], stride
[2]);
790 //============================================================================
792 vf_instance_t
*append_filters(vf_instance_t
*last
,
793 struct m_obj_settings
*vf_settings
)
795 struct MPOpts
*opts
= last
->opts
;
800 // We want to add them in the 'right order'
801 for (i
= 0; vf_settings
[i
].name
; i
++)
803 for (i
--; i
>= 0; i
--) {
804 //printf("Open filter %s\n",vf_settings[i].name);
805 vf
= vf_open_filter(opts
, last
, vf_settings
[i
].name
,
806 vf_settings
[i
].attribs
);
814 //============================================================================
816 void vf_uninit_filter(vf_instance_t
*vf
)
820 free_mp_image(vf
->imgctx
.static_images
[0]);
821 free_mp_image(vf
->imgctx
.static_images
[1]);
822 free_mp_image(vf
->imgctx
.temp_images
[0]);
823 free_mp_image(vf
->imgctx
.export_images
[0]);
824 for (int i
= 0; i
< NUM_NUMBERED_MPI
; i
++)
825 free_mp_image(vf
->imgctx
.numbered_images
[i
]);
829 void vf_uninit_filter_chain(vf_instance_t
*vf
)
832 vf_instance_t
*next
= vf
->next
;
833 vf_uninit_filter(vf
);
838 void vf_detc_init_pts_buf(struct vf_detc_pts_buf
*p
)
840 p
->inpts_prev
= MP_NOPTS_VALUE
;
841 p
->outpts_prev
= MP_NOPTS_VALUE
;
845 static double vf_detc_adjust_pts_internal(struct vf_detc_pts_buf
*p
,
846 double pts
, bool reset_pattern
,
847 bool skip_frame
, double delta
,
848 double boundfactor_minus
,
849 double increasefactor
,
850 double boundfactor_plus
)
854 if (pts
== MP_NOPTS_VALUE
)
858 if (p
->inpts_prev
== MP_NOPTS_VALUE
)
860 else if (pts
== p
->inpts_prev
)
861 delta
= p
->lastdelta
;
863 delta
= pts
- p
->inpts_prev
;
866 p
->lastdelta
= delta
;
869 return MP_NOPTS_VALUE
;
871 /* detect bogus deltas and then passthru pts (possibly caused by seeking,
873 if (p
->outpts_prev
== MP_NOPTS_VALUE
|| reset_pattern
|| delta
<= 0.0 ||
877 // turn 5 frames into 4
878 newpts
= p
->outpts_prev
+ delta
* increasefactor
;
880 // bound to input pts in a sensible way; these numbers come because we
881 // map frames the following way when ivtc'ing:
882 // 0/30 -> 0/24 diff=0
883 // 1/30 -> 1/24 diff=1/120
885 // 3/30 -> 2/24 diff=-1/60
886 // 4/30 -> 3/24 diff=-1/120
887 if (newpts
< pts
- delta
* boundfactor_minus
)
888 newpts
= pts
- delta
* boundfactor_minus
;
889 if (newpts
> pts
+ delta
* boundfactor_plus
)
890 newpts
= pts
+ delta
* boundfactor_plus
;
891 if (newpts
< p
->outpts_prev
)
892 newpts
= p
->outpts_prev
; // damage control
894 p
->outpts_prev
= newpts
;
899 double vf_detc_adjust_pts(struct vf_detc_pts_buf
*p
, double pts
,
900 bool reset_pattern
, bool skip_frame
)
902 // standard telecine (see above)
903 return vf_detc_adjust_pts_internal(p
, pts
, reset_pattern
, skip_frame
,
907 double vf_softpulldown_adjust_pts(struct vf_detc_pts_buf
*p
, double pts
,
908 bool reset_pattern
, bool skip_frame
,
909 int last_frame_duration
)
911 // for the softpulldown filter we get:
915 // 7/60 -> 3/30, 4/30
916 return vf_detc_adjust_pts_internal(p
, pts
, reset_pattern
, skip_frame
,
917 0, 1.0 / last_frame_duration
,
918 2.0 / last_frame_duration
,
919 1.0 / last_frame_duration
);