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.
34 #include "img_format.h"
38 #include "libvo/fastmemcpy.h"
39 #include "libavutil/mem.h"
41 extern const vf_info_t vf_info_vo
;
42 extern const vf_info_t vf_info_rectangle
;
43 extern const vf_info_t vf_info_bmovl
;
44 extern const vf_info_t vf_info_crop
;
45 extern const vf_info_t vf_info_expand
;
46 extern const vf_info_t vf_info_pp
;
47 extern const vf_info_t vf_info_scale
;
48 extern const vf_info_t vf_info_format
;
49 extern const vf_info_t vf_info_noformat
;
50 extern const vf_info_t vf_info_flip
;
51 extern const vf_info_t vf_info_rotate
;
52 extern const vf_info_t vf_info_mirror
;
53 extern const vf_info_t vf_info_palette
;
54 extern const vf_info_t vf_info_lavc
;
55 extern const vf_info_t vf_info_dvbscale
;
56 extern const vf_info_t vf_info_cropdetect
;
57 extern const vf_info_t vf_info_test
;
58 extern const vf_info_t vf_info_noise
;
59 extern const vf_info_t vf_info_yvu9
;
60 extern const vf_info_t vf_info_lavcdeint
;
61 extern const vf_info_t vf_info_eq
;
62 extern const vf_info_t vf_info_eq2
;
63 extern const vf_info_t vf_info_gradfun
;
64 extern const vf_info_t vf_info_halfpack
;
65 extern const vf_info_t vf_info_dint
;
66 extern const vf_info_t vf_info_1bpp
;
67 extern const vf_info_t vf_info_2xsai
;
68 extern const vf_info_t vf_info_unsharp
;
69 extern const vf_info_t vf_info_swapuv
;
70 extern const vf_info_t vf_info_il
;
71 extern const vf_info_t vf_info_fil
;
72 extern const vf_info_t vf_info_boxblur
;
73 extern const vf_info_t vf_info_sab
;
74 extern const vf_info_t vf_info_smartblur
;
75 extern const vf_info_t vf_info_perspective
;
76 extern const vf_info_t vf_info_down3dright
;
77 extern const vf_info_t vf_info_field
;
78 extern const vf_info_t vf_info_denoise3d
;
79 extern const vf_info_t vf_info_hqdn3d
;
80 extern const vf_info_t vf_info_detc
;
81 extern const vf_info_t vf_info_telecine
;
82 extern const vf_info_t vf_info_tinterlace
;
83 extern const vf_info_t vf_info_tfields
;
84 extern const vf_info_t vf_info_ivtc
;
85 extern const vf_info_t vf_info_ilpack
;
86 extern const vf_info_t vf_info_dsize
;
87 extern const vf_info_t vf_info_decimate
;
88 extern const vf_info_t vf_info_softpulldown
;
89 extern const vf_info_t vf_info_pullup
;
90 extern const vf_info_t vf_info_filmdint
;
91 extern const vf_info_t vf_info_framestep
;
92 extern const vf_info_t vf_info_tile
;
93 extern const vf_info_t vf_info_delogo
;
94 extern const vf_info_t vf_info_remove_logo
;
95 extern const vf_info_t vf_info_hue
;
96 extern const vf_info_t vf_info_spp
;
97 extern const vf_info_t vf_info_uspp
;
98 extern const vf_info_t vf_info_fspp
;
99 extern const vf_info_t vf_info_pp7
;
100 extern const vf_info_t vf_info_yuvcsp
;
101 extern const vf_info_t vf_info_kerndeint
;
102 extern const vf_info_t vf_info_rgbtest
;
103 extern const vf_info_t vf_info_qp
;
104 extern const vf_info_t vf_info_phase
;
105 extern const vf_info_t vf_info_divtc
;
106 extern const vf_info_t vf_info_harddup
;
107 extern const vf_info_t vf_info_softskip
;
108 extern const vf_info_t vf_info_screenshot
;
109 extern const vf_info_t vf_info_ass
;
110 extern const vf_info_t vf_info_mcdeint
;
111 extern const vf_info_t vf_info_yadif
;
112 extern const vf_info_t vf_info_blackframe
;
113 extern const vf_info_t vf_info_geq
;
114 extern const vf_info_t vf_info_ow
;
115 extern const vf_info_t vf_info_fixpts
;
116 extern const vf_info_t vf_info_stereo3d
;
118 // list of available filters:
119 static const vf_info_t
*const filter_list
[] = {
121 #ifdef HAVE_POSIX_SELECT
137 #ifdef CONFIG_LIBPOSTPROC
165 &vf_info_perspective
,
166 &vf_info_down3dright
,
178 &vf_info_softpulldown
,
184 &vf_info_remove_logo
,
186 #ifdef CONFIG_FFMPEG_INTERNALS
211 const m_obj_list_t vf_obj_list
= {
212 (void **)filter_list
,
213 M_ST_OFF(vf_info_t
, name
),
214 M_ST_OFF(vf_info_t
, info
),
215 M_ST_OFF(vf_info_t
, opts
)
218 //============================================================================
221 void vf_mpi_clear(mp_image_t
*mpi
, int x0
, int y0
, int w
, int h
)
224 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
227 if (x0
== 0 && w
== mpi
->width
) {
229 memset(mpi
->planes
[0] + mpi
->stride
[0] * y0
, 0, mpi
->stride
[0] * h
);
230 memset(mpi
->planes
[1] + mpi
->stride
[1] *(y0
>> mpi
->chroma_y_shift
),
231 128, mpi
->stride
[1] * (h
>> mpi
->chroma_y_shift
));
232 memset(mpi
->planes
[2] + mpi
->stride
[2] *(y0
>> mpi
->chroma_y_shift
),
233 128, mpi
->stride
[2] * (h
>> mpi
->chroma_y_shift
));
235 for (y
= y0
; y
< y0
+ h
; y
+= 2) {
236 memset(mpi
->planes
[0] + x0
+ mpi
->stride
[0] * y
, 0, w
);
237 memset(mpi
->planes
[0] + x0
+ mpi
->stride
[0] * (y
+ 1), 0, w
);
238 memset(mpi
->planes
[1] + (x0
>> mpi
->chroma_x_shift
) +
239 mpi
->stride
[1] * (y
>> mpi
->chroma_y_shift
),
240 128, (w
>> mpi
->chroma_x_shift
));
241 memset(mpi
->planes
[2] + (x0
>> mpi
->chroma_x_shift
) +
242 mpi
->stride
[2] * (y
>> mpi
->chroma_y_shift
),
243 128, (w
>> mpi
->chroma_x_shift
));
248 for (y
= y0
; y
< y0
+ h
; y
++) {
249 unsigned char *dst
= mpi
->planes
[0] + mpi
->stride
[0] * y
+
250 (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)
264 p
[i
] = p
[i
+ 1] = p
[i
+ 2] = p
[i
+ 3] = CLEAR_PACKEDYUV_PATTERN_SWAPPED
;
265 for (; i
< size
; i
++)
266 p
[i
] = CLEAR_PACKEDYUV_PATTERN_SWAPPED
;
268 for (i
= 0; i
< size
- 3; i
+= 4)
269 p
[i
] = p
[i
+ 1] = p
[i
+ 2] = p
[i
+ 3] = CLEAR_PACKEDYUV_PATTERN
;
270 for (; i
< size
; i
++)
271 p
[i
] = CLEAR_PACKEDYUV_PATTERN
;
274 memset(dst
, 0, (mpi
->bpp
>> 3) * w
);
278 mp_image_t
*vf_get_image(vf_instance_t
*vf
, unsigned int outfmt
,
279 int mp_imgtype
, int mp_imgflag
, int w
, int h
)
281 mp_image_t
*mpi
= NULL
;
283 int number
= mp_imgtype
>> 16;
285 assert(w
== -1 || w
>= vf
->w
);
286 assert(h
== -1 || h
>= vf
->h
);
295 w2
= (mp_imgflag
& MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE
) ?
296 ((w
+ 15) & (~15)) : w
;
298 if (vf
->put_image
== vf_next_put_image
) {
299 // passthru mode, if the filter uses the fallback/default put_image()
300 return vf_get_image(vf
->next
, outfmt
, mp_imgtype
, mp_imgflag
, w
, h
);
303 // Note: we should call libvo first to check if it supports direct rendering
304 // and if not, then fallback to software buffers:
305 switch (mp_imgtype
& 0xff) {
306 case MP_IMGTYPE_EXPORT
:
307 if (!vf
->imgctx
.export_images
[0])
308 vf
->imgctx
.export_images
[0] = new_mp_image(w2
, h
);
309 mpi
= vf
->imgctx
.export_images
[0];
311 case MP_IMGTYPE_STATIC
:
312 if (!vf
->imgctx
.static_images
[0])
313 vf
->imgctx
.static_images
[0] = new_mp_image(w2
, h
);
314 mpi
= vf
->imgctx
.static_images
[0];
316 case MP_IMGTYPE_TEMP
:
317 if (!vf
->imgctx
.temp_images
[0])
318 vf
->imgctx
.temp_images
[0] = new_mp_image(w2
, h
);
319 mpi
= vf
->imgctx
.temp_images
[0];
322 if (!(mp_imgflag
& MP_IMGFLAG_READABLE
)) { // B frame:
323 if (!vf
->imgctx
.temp_images
[0])
324 vf
->imgctx
.temp_images
[0] = new_mp_image(w2
, h
);
325 mpi
= vf
->imgctx
.temp_images
[0];
329 if (!vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
])
330 vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
] = new_mp_image(w2
, h
);
331 mpi
= vf
->imgctx
.static_images
[vf
->imgctx
.static_idx
];
332 vf
->imgctx
.static_idx
^= 1;
334 case MP_IMGTYPE_NUMBERED
:
337 for (i
= 0; i
< NUM_NUMBERED_MPI
; i
++)
338 if (!vf
->imgctx
.numbered_images
[i
] ||
339 !vf
->imgctx
.numbered_images
[i
]->usage_count
)
343 if (number
< 0 || number
>= NUM_NUMBERED_MPI
)
345 if (!vf
->imgctx
.numbered_images
[number
])
346 vf
->imgctx
.numbered_images
[number
] = new_mp_image(w2
, h
);
347 mpi
= vf
->imgctx
.numbered_images
[number
];
348 mpi
->number
= number
;
352 mpi
->type
= mp_imgtype
;
355 // keep buffer allocation status & color flags only:
356 mpi
->flags
&= MP_IMGFLAG_ALLOCATED
| MP_IMGFLAG_TYPE_DISPLAYED
|
357 MP_IMGFLAGMASK_COLORS
;
358 // accept restrictions, draw_slice and palette flags only:
359 mpi
->flags
|= mp_imgflag
& (MP_IMGFLAGMASK_RESTRICTIONS
|
360 MP_IMGFLAG_DRAW_CALLBACK
| MP_IMGFLAG_RGB_PALETTE
);
362 mpi
->flags
&= ~MP_IMGFLAG_DRAW_CALLBACK
;
363 if (mpi
->width
!= w2
|| mpi
->height
!= h
) {
364 if (mpi
->flags
& MP_IMGFLAG_ALLOCATED
) {
365 if (mpi
->width
< w2
|| mpi
->height
< h
) {
366 // need to re-allocate buffer memory:
367 av_free(mpi
->planes
[0]);
368 mpi
->flags
&= ~MP_IMGFLAG_ALLOCATED
;
369 mp_msg(MSGT_VFILTER
, MSGL_V
,
370 "vf.c: have to REALLOCATE buffer memory :(\n");
374 mpi
->chroma_width
= (w2
+ (1 << mpi
->chroma_x_shift
) - 1) >>
377 mpi
->chroma_height
= (h
+ (1 << mpi
->chroma_y_shift
) - 1) >>
381 mp_image_setfmt(mpi
, outfmt
);
382 if (!(mpi
->flags
& MP_IMGFLAG_ALLOCATED
) &&
383 mpi
->type
> MP_IMGTYPE_EXPORT
) {
384 // check libvo first!
386 vf
->get_image(vf
, mpi
);
388 if (!(mpi
->flags
& MP_IMGFLAG_DIRECT
)) {
389 // non-direct and not yet allocated image. allocate it!
390 if (!mpi
->bpp
) { // no way we can allocate this
391 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
,
392 "vf_get_image: Tried to allocate a format that "
393 "can not be allocated!\n");
397 // check if codec prefer aligned stride:
398 if (mp_imgflag
& MP_IMGFLAG_PREFER_ALIGNED_STRIDE
) {
399 int align
= (mpi
->flags
& MP_IMGFLAG_PLANAR
&&
400 mpi
->flags
& MP_IMGFLAG_YUV
) ?
401 (8 << mpi
->chroma_x_shift
) - 1 : 15; // OK?
402 w2
= ((w
+ align
) & (~align
));
403 if (mpi
->width
!= w2
) {
404 // we have to change width... check if we CAN co it:
405 int flags
= vf
->query_format(vf
, outfmt
);
407 if (!(flags
& (VFCAP_CSP_SUPPORTED
|
408 VFCAP_CSP_SUPPORTED_BY_HW
)))
409 mp_msg(MSGT_DECVIDEO
, MSGL_WARN
,
410 "??? vf_get_image{vf->query_format(outfmt)} "
412 if (flags
& VFCAP_ACCEPT_STRIDE
) {
415 (w2
+ (1 << mpi
->chroma_x_shift
) - 1) >>
421 mp_image_alloc_planes(mpi
);
422 vf_mpi_clear(mpi
, 0, 0, mpi
->width
, mpi
->height
);
425 if (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
)
427 vf
->start_slice(vf
, mpi
);
428 if (!(mpi
->flags
& MP_IMGFLAG_TYPE_DISPLAYED
)) {
429 mp_msg(MSGT_DECVIDEO
, MSGL_V
,
430 "*** [%s] %s%s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n",
432 (mpi
->type
== MP_IMGTYPE_EXPORT
) ? "Exporting" :
433 ((mpi
->flags
& MP_IMGFLAG_DIRECT
) ?
434 "Direct Rendering" : "Allocating"),
435 (mpi
->flags
& MP_IMGFLAG_DRAW_CALLBACK
) ? " (slices)" : "",
436 mpi
->width
, mpi
->height
, mpi
->bpp
,
437 (mpi
->flags
& MP_IMGFLAG_YUV
) ? "YUV" :
438 ((mpi
->flags
& MP_IMGFLAG_SWAPPED
) ? "BGR" : "RGB"),
439 (mpi
->flags
& MP_IMGFLAG_PLANAR
) ? "planar" : "packed",
440 mpi
->bpp
* mpi
->width
* mpi
->height
/ 8);
441 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "(imgfmt: %x, planes: %p,%p,%p "
442 "strides: %d,%d,%d, chroma: %dx%d, shift: h:%d,v:%d)\n",
443 mpi
->imgfmt
, mpi
->planes
[0], mpi
->planes
[1], mpi
->planes
[2],
444 mpi
->stride
[0], mpi
->stride
[1], mpi
->stride
[2],
445 mpi
->chroma_width
, mpi
->chroma_height
,
446 mpi
->chroma_x_shift
, mpi
->chroma_y_shift
);
447 mpi
->flags
|= MP_IMGFLAG_TYPE_DISPLAYED
;
455 //============================================================================
457 // By default vf doesn't accept MPEGPES
458 static int vf_default_query_format(struct vf_instance
*vf
, unsigned int fmt
)
460 if (fmt
== IMGFMT_MPEGPES
)
462 return vf_next_query_format(vf
, fmt
);
465 struct vf_instance
*vf_open_plugin_noerr(struct MPOpts
*opts
,
466 const vf_info_t
*const *filter_list
,
467 vf_instance_t
*next
, const char *name
,
468 char **args
, int *retcode
)
473 if (!filter_list
[i
]) {
474 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
,
475 "Couldn't find video filter '%s'.\n", name
);
476 return NULL
; // no such filter!
478 if (!strcmp(filter_list
[i
]->name
, name
))
481 vf
= calloc(1, sizeof *vf
);
483 vf
->info
= filter_list
[i
];
485 vf
->config
= vf_next_config
;
486 vf
->control
= vf_next_control
;
487 vf
->query_format
= vf_default_query_format
;
488 vf
->put_image
= vf_next_put_image
;
489 vf
->default_caps
= VFCAP_ACCEPT_STRIDE
;
490 vf
->default_reqs
= 0;
491 if (vf
->info
->opts
) { // vf_vo get some special argument
492 const m_struct_t
*st
= vf
->info
->opts
;
493 void *vf_priv
= m_struct_alloc(st
);
495 for (n
= 0; args
&& args
[2 * n
]; n
++)
496 m_struct_set(st
, vf_priv
, args
[2 * n
], bstr(args
[2 * n
+ 1]));
499 } else // Otherwise we should have the '_oldargs_'
500 if (args
&& !strcmp(args
[0], "_oldargs_"))
501 args
= (char **)args
[1];
504 *retcode
= vf
->info
->vf_open(vf
, (char *)args
);
511 struct vf_instance
*vf_open_plugin(struct MPOpts
*opts
,
512 const vf_info_t
*const *filter_list
,
513 vf_instance_t
*next
, const char *name
,
516 struct vf_instance
*vf
= vf_open_plugin_noerr(opts
, filter_list
, next
,
517 name
, args
, &(int){0});
519 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
, "Couldn't open video filter '%s'.\n",
524 vf_instance_t
*vf_open_filter(struct MPOpts
*opts
, vf_instance_t
*next
,
525 const char *name
, char **args
)
527 if (args
&& strcmp(args
[0], "_oldargs_")) {
529 for (i
= 0; args
&& args
[2 * i
]; i
++)
530 l
+= 1 + strlen(args
[2 * i
]) + 1 + strlen(args
[2 * i
+ 1]);
535 p
+= sprintf(str
, "%s", name
);
536 for (i
= 0; args
&& args
[2 * i
]; i
++)
537 p
+= sprintf(p
, " %s=%s", args
[2 * i
], args
[2 * i
+ 1]);
538 mp_msg(MSGT_VFILTER
, MSGL_INFO
, "%s[%s]\n",
539 mp_gtext("Opening video filter: "), str
);
541 } else if (strcmp(name
, "vo")) {
542 if (args
&& strcmp(args
[0], "_oldargs_") == 0)
543 mp_msg(MSGT_VFILTER
, MSGL_INFO
, "%s[%s=%s]\n",
544 mp_gtext("Opening video filter: "), name
, args
[1]);
546 mp_msg(MSGT_VFILTER
, MSGL_INFO
, "%s[%s]\n",
547 mp_gtext("Opening video filter: "), name
);
549 return vf_open_plugin(opts
, filter_list
, next
, name
, args
);
553 * \brief adds a filter before the last one (which should be the vo filter).
554 * \param vf start of the filter chain.
555 * \param name name of the filter to add.
556 * \param args argument list for the filter.
557 * \return pointer to the filter instance that was created.
559 vf_instance_t
*vf_add_before_vo(vf_instance_t
**vf
, char *name
, char **args
)
561 struct MPOpts
*opts
= (*vf
)->opts
;
562 vf_instance_t
*vo
, *prev
= NULL
, *new;
563 // Find the last filter (should be vf_vo)
564 for (vo
= *vf
; vo
->next
; vo
= vo
->next
)
566 new = vf_open_filter(opts
, vo
, name
, args
);
574 //============================================================================
576 unsigned int vf_match_csp(vf_instance_t
**vfp
, const unsigned int *list
,
577 unsigned int preferred
)
579 vf_instance_t
*vf
= *vfp
;
580 struct MPOpts
*opts
= vf
->opts
;
581 const unsigned int *p
;
582 unsigned int best
= 0;
586 ret
= vf
->query_format(vf
, *p
);
587 mp_msg(MSGT_VFILTER
, MSGL_V
, "[%s] query(%s) -> %x\n",
588 vf
->info
->name
, vo_format_name(*p
), ret
);
589 if (ret
& VFCAP_CSP_SUPPORTED_BY_HW
) {
593 if (ret
& VFCAP_CSP_SUPPORTED
&& !best
)
598 return best
; // bingo, they have common csp!
599 // ok, then try with scale:
600 if (vf
->info
== &vf_info_scale
)
601 return 0; // avoid infinite recursion!
602 vf
= vf_open_filter(opts
, vf
, "scale", NULL
);
604 return 0; // failed to init "scale"
605 // try the preferred csp first:
606 if (preferred
&& vf
->query_format(vf
, preferred
))
609 // try the list again, now with "scaler" :
612 ret
= vf
->query_format(vf
, *p
);
613 mp_msg(MSGT_VFILTER
, MSGL_V
, "[%s] query(%s) -> %x\n",
614 vf
->info
->name
, vo_format_name(*p
), ret
);
615 if (ret
& VFCAP_CSP_SUPPORTED_BY_HW
) {
619 if (ret
& VFCAP_CSP_SUPPORTED
&& !best
)
624 *vfp
= vf
; // else uninit vf !FIXME!
628 void vf_clone_mpi_attributes(mp_image_t
*dst
, mp_image_t
*src
)
630 dst
->pict_type
= src
->pict_type
;
631 dst
->fields
= src
->fields
;
632 dst
->qscale_type
= src
->qscale_type
;
633 if (dst
->width
== src
->width
&& dst
->height
== src
->height
) {
634 dst
->qstride
= src
->qstride
;
635 dst
->qscale
= src
->qscale
;
639 void vf_queue_frame(vf_instance_t
*vf
, int (*func
)(vf_instance_t
*))
641 vf
->continue_buffered_image
= func
;
644 // Output the next buffered image (if any) from the filter chain.
645 // The queue could be kept as a simple stack/list instead avoiding the
646 // looping here, but there's currently no good context variable where
647 // that could be stored so this was easier to implement.
649 int vf_output_queued_frame(vf_instance_t
*vf
)
653 vf_instance_t
*current
;
654 vf_instance_t
*last
= NULL
;
655 int (*tmp
)(vf_instance_t
*);
656 for (current
= vf
; current
; current
= current
->next
)
657 if (current
->continue_buffered_image
)
661 tmp
= last
->continue_buffered_image
;
662 last
->continue_buffered_image
= NULL
;
671 * \brief Video config() function wrapper
673 * Blocks config() calls with different size or format for filters
674 * with VFCAP_CONSTANT
676 * First call is redirected to vf->config.
678 * In following calls, it verifies that the configuration parameters
679 * are unchanged, and returns either success or error.
682 int vf_config_wrapper(struct vf_instance
*vf
,
683 int width
, int height
, int d_width
, int d_height
,
684 unsigned int flags
, unsigned int outfmt
)
687 if ((vf
->default_caps
& VFCAP_CONSTANT
) && vf
->fmt
.have_configured
) {
688 if ((vf
->fmt
.orig_width
!= width
)
689 || (vf
->fmt
.orig_height
!= height
)
690 || (vf
->fmt
.orig_fmt
!= outfmt
)) {
691 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
, "\nNew video file has different "
692 "resolution or colorspace than the previous one.\n");
697 vf
->fmt
.have_configured
= 1;
698 vf
->fmt
.orig_height
= height
;
699 vf
->fmt
.orig_width
= width
;
700 vf
->fmt
.orig_fmt
= outfmt
;
701 r
= vf
->config(vf
, width
, height
, d_width
, d_height
, flags
, outfmt
);
703 vf
->fmt
.have_configured
= 0;
707 int vf_next_config(struct vf_instance
*vf
,
708 int width
, int height
, int d_width
, int d_height
,
709 unsigned int voflags
, unsigned int outfmt
)
711 struct MPOpts
*opts
= vf
->opts
;
713 int flags
= vf
->next
->query_format(vf
->next
, outfmt
);
715 // hmm. colorspace mismatch!!!
716 // let's insert the 'scale' filter, it does the job for us:
718 if (vf
->next
->info
== &vf_info_scale
)
719 return 0; // scale->scale
720 vf2
= vf_open_filter(opts
, vf
->next
, "scale", NULL
);
722 return 0; // shouldn't happen!
724 flags
= vf
->next
->query_format(vf
->next
, outfmt
);
726 mp_tmsg(MSGT_VFILTER
, MSGL_ERR
, "Cannot find matching colorspace, "
727 "even by inserting 'scale' :(\n");
731 mp_msg(MSGT_VFILTER
, MSGL_V
, "REQ: flags=0x%X req=0x%X \n",
732 flags
, vf
->default_reqs
);
733 miss
= vf
->default_reqs
- (flags
& vf
->default_reqs
);
734 if (miss
& VFCAP_ACCEPT_STRIDE
) {
735 // vf requires stride support but vf->next doesn't support it!
736 // let's insert the 'expand' filter, it does the job for us:
737 vf_instance_t
*vf2
= vf_open_filter(opts
, vf
->next
, "expand", NULL
);
739 return 0; // shouldn't happen!
743 vf
->next
->h
= height
;
744 return vf_config_wrapper(vf
->next
, width
, height
, d_width
, d_height
,
748 int vf_next_control(struct vf_instance
*vf
, int request
, void *data
)
750 return vf
->next
->control(vf
->next
, request
, data
);
753 int vf_next_query_format(struct vf_instance
*vf
, unsigned int fmt
)
755 int flags
= vf
->next
->query_format(vf
->next
, fmt
);
757 flags
|= vf
->default_caps
;
761 int vf_next_put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
)
763 return vf
->next
->put_image(vf
->next
, mpi
, pts
);
766 void vf_next_draw_slice(struct vf_instance
*vf
, unsigned char **src
,
767 int *stride
, int w
, int h
, int x
, int y
)
769 if (vf
->next
->draw_slice
) {
770 vf
->next
->draw_slice(vf
->next
, src
, stride
, w
, h
, x
, y
);
774 mp_msg(MSGT_VFILTER
, MSGL_ERR
,
775 "draw_slice: dmpi not stored by vf_%s\n", vf
->info
->name
);
778 if (!(vf
->dmpi
->flags
& MP_IMGFLAG_PLANAR
)) {
779 memcpy_pic(vf
->dmpi
->planes
[0] + y
* vf
->dmpi
->stride
[0] +
780 vf
->dmpi
->bpp
/ 8 * x
,
781 src
[0], vf
->dmpi
->bpp
/ 8 * w
, h
, vf
->dmpi
->stride
[0],
785 memcpy_pic(vf
->dmpi
->planes
[0] + y
* vf
->dmpi
->stride
[0] + x
, src
[0],
786 w
, h
, vf
->dmpi
->stride
[0], stride
[0]);
787 memcpy_pic(vf
->dmpi
->planes
[1]
788 + (y
>> vf
->dmpi
->chroma_y_shift
) * vf
->dmpi
->stride
[1]
789 + (x
>> vf
->dmpi
->chroma_x_shift
),
790 src
[1], w
>> vf
->dmpi
->chroma_x_shift
,
791 h
>> vf
->dmpi
->chroma_y_shift
, vf
->dmpi
->stride
[1], stride
[1]);
792 memcpy_pic(vf
->dmpi
->planes
[2]
793 + (y
>> vf
->dmpi
->chroma_y_shift
) * vf
->dmpi
->stride
[2]
794 + (x
>> vf
->dmpi
->chroma_x_shift
),
795 src
[2], w
>> vf
->dmpi
->chroma_x_shift
,
796 h
>> vf
->dmpi
->chroma_y_shift
, vf
->dmpi
->stride
[2], stride
[2]);
799 //============================================================================
801 vf_instance_t
*append_filters(vf_instance_t
*last
,
802 struct m_obj_settings
*vf_settings
)
804 struct MPOpts
*opts
= last
->opts
;
809 // We want to add them in the 'right order'
810 for (i
= 0; vf_settings
[i
].name
; i
++)
812 for (i
--; i
>= 0; i
--) {
813 //printf("Open filter %s\n",vf_settings[i].name);
814 vf
= vf_open_filter(opts
, last
, vf_settings
[i
].name
,
815 vf_settings
[i
].attribs
);
823 //============================================================================
825 void vf_uninit_filter(vf_instance_t
*vf
)
829 free_mp_image(vf
->imgctx
.static_images
[0]);
830 free_mp_image(vf
->imgctx
.static_images
[1]);
831 free_mp_image(vf
->imgctx
.temp_images
[0]);
832 free_mp_image(vf
->imgctx
.export_images
[0]);
833 for (int i
= 0; i
< NUM_NUMBERED_MPI
; i
++)
834 free_mp_image(vf
->imgctx
.numbered_images
[i
]);
838 void vf_uninit_filter_chain(vf_instance_t
*vf
)
841 vf_instance_t
*next
= vf
->next
;
842 vf_uninit_filter(vf
);
847 void vf_detc_init_pts_buf(struct vf_detc_pts_buf
*p
)
849 p
->inpts_prev
= MP_NOPTS_VALUE
;
850 p
->outpts_prev
= MP_NOPTS_VALUE
;
854 static double vf_detc_adjust_pts_internal(struct vf_detc_pts_buf
*p
,
855 double pts
, bool reset_pattern
,
856 bool skip_frame
, double delta
,
857 double boundfactor_minus
,
858 double increasefactor
,
859 double boundfactor_plus
)
863 if (pts
== MP_NOPTS_VALUE
)
867 if (p
->inpts_prev
== MP_NOPTS_VALUE
)
869 else if (pts
== p
->inpts_prev
)
870 delta
= p
->lastdelta
;
872 delta
= pts
- p
->inpts_prev
;
875 p
->lastdelta
= delta
;
878 return MP_NOPTS_VALUE
;
880 /* detect bogus deltas and then passthru pts (possibly caused by seeking,
882 if (p
->outpts_prev
== MP_NOPTS_VALUE
|| reset_pattern
|| delta
<= 0.0 ||
886 // turn 5 frames into 4
887 newpts
= p
->outpts_prev
+ delta
* increasefactor
;
889 // bound to input pts in a sensible way; these numbers come because we
890 // map frames the following way when ivtc'ing:
891 // 0/30 -> 0/24 diff=0
892 // 1/30 -> 1/24 diff=1/120
894 // 3/30 -> 2/24 diff=-1/60
895 // 4/30 -> 3/24 diff=-1/120
896 if (newpts
< pts
- delta
* boundfactor_minus
)
897 newpts
= pts
- delta
* boundfactor_minus
;
898 if (newpts
> pts
+ delta
* boundfactor_plus
)
899 newpts
= pts
+ delta
* boundfactor_plus
;
900 if (newpts
< p
->outpts_prev
)
901 newpts
= p
->outpts_prev
; // damage control
903 p
->outpts_prev
= newpts
;
908 double vf_detc_adjust_pts(struct vf_detc_pts_buf
*p
, double pts
,
909 bool reset_pattern
, bool skip_frame
)
911 // standard telecine (see above)
912 return vf_detc_adjust_pts_internal(p
, pts
, reset_pattern
, skip_frame
,
916 double vf_softpulldown_adjust_pts(struct vf_detc_pts_buf
*p
, double pts
,
917 bool reset_pattern
, bool skip_frame
,
918 int last_frame_duration
)
920 // for the softpulldown filter we get:
924 // 7/60 -> 3/30, 4/30
925 return vf_detc_adjust_pts_internal(p
, pts
, reset_pattern
, skip_frame
,
926 0, 1.0 / last_frame_duration
,
927 2.0 / last_frame_duration
,
928 1.0 / last_frame_duration
);