2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2003-08-03 12:09:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_msg.h"
|
2003-08-03 12:09:58 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2003-08-03 12:09:58 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/memcpy_pic.h"
|
2003-08-03 12:09:58 +00:00
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
int state;
|
|
|
|
long long in;
|
|
|
|
long long out;
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
struct vf_detc_pts_buf ptsbuf;
|
|
|
|
int last_frame_duration;
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
struct mp_image *buffer;
|
2003-08-03 12:09:58 +00:00
|
|
|
};
|
|
|
|
|
2012-12-26 20:31:56 +00:00
|
|
|
static void copy_pic_field(struct mp_image *dmpi, struct mp_image *mpi, int f)
|
|
|
|
{
|
|
|
|
for (int p = 0; p < dmpi->num_planes; p++) {
|
|
|
|
my_memcpy_pic(dmpi->planes[p] + dmpi->stride[p] * f,
|
|
|
|
mpi->planes[p] + mpi->stride[p] * f,
|
|
|
|
mpi->plane_w[p], mpi->plane_h[p] / 2,
|
|
|
|
dmpi->stride[p] * 2, mpi->stride[p] * 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
static int filter(struct vf_instance *vf, struct mp_image *mpi)
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
{
|
2003-08-18 14:49:06 +00:00
|
|
|
int flags = mpi->fields;
|
2003-08-03 12:09:58 +00:00
|
|
|
int state = vf->priv->state;
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
struct vf_priv_s *p = vf->priv;
|
2003-08-03 12:09:58 +00:00
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
if (!p->buffer || p->buffer->w != mpi->w || p->buffer->h != mpi->h ||
|
|
|
|
p->buffer->imgfmt != mpi->imgfmt)
|
|
|
|
{
|
|
|
|
mp_image_unrefp(&p->buffer);
|
|
|
|
p->buffer = mp_image_alloc(mpi->imgfmt, mpi->w, mpi->h);
|
|
|
|
talloc_steal(vf, p->buffer);
|
|
|
|
}
|
|
|
|
mp_image_copy_attributes(p->buffer, mpi);
|
|
|
|
|
|
|
|
struct mp_image *dmpi = p->buffer;
|
2003-08-03 12:09:58 +00:00
|
|
|
|
|
|
|
vf->priv->in++;
|
|
|
|
|
|
|
|
if ((state == 0 &&
|
2003-08-18 14:49:06 +00:00
|
|
|
!(flags & MP_IMGFIELD_TOP_FIRST)) ||
|
2003-08-03 12:09:58 +00:00
|
|
|
(state == 1 &&
|
2003-08-18 14:49:06 +00:00
|
|
|
flags & MP_IMGFIELD_TOP_FIRST)) {
|
2003-08-03 12:09:58 +00:00
|
|
|
mp_msg(MSGT_VFILTER, MSGL_WARN,
|
2003-08-18 14:49:06 +00:00
|
|
|
"softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n",
|
2003-08-03 12:09:58 +00:00
|
|
|
state,
|
2003-08-18 14:49:06 +00:00
|
|
|
(flags & MP_IMGFIELD_TOP_FIRST) != 0,
|
|
|
|
(flags & MP_IMGFIELD_REPEAT_FIRST) != 0);
|
|
|
|
state ^= 1;
|
|
|
|
}
|
2003-08-03 12:09:58 +00:00
|
|
|
|
|
|
|
if (state == 0) {
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
struct mp_image *new = mp_image_new_ref(mpi);
|
|
|
|
new->pts = vf_softpulldown_adjust_pts(&vf->priv->ptsbuf, mpi->pts, 0, 0, vf->priv->last_frame_duration);
|
|
|
|
vf_add_output_frame(vf, new);
|
2003-08-03 12:09:58 +00:00
|
|
|
vf->priv->out++;
|
2003-08-18 14:49:06 +00:00
|
|
|
if (flags & MP_IMGFIELD_REPEAT_FIRST) {
|
2012-12-26 20:31:56 +00:00
|
|
|
copy_pic_field(dmpi, mpi, 0);
|
2003-08-03 12:09:58 +00:00
|
|
|
state=1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-12-26 20:31:56 +00:00
|
|
|
copy_pic_field(dmpi, mpi, 1);
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
struct mp_image *new = mp_image_new_ref(mpi);
|
|
|
|
new->pts = vf_softpulldown_adjust_pts(&vf->priv->ptsbuf, mpi->pts, 0, 0, vf->priv->last_frame_duration);
|
|
|
|
vf_add_output_frame(vf, new);
|
2003-08-03 12:09:58 +00:00
|
|
|
vf->priv->out++;
|
2003-08-18 14:49:06 +00:00
|
|
|
if (flags & MP_IMGFIELD_REPEAT_FIRST) {
|
2013-07-22 22:45:23 +00:00
|
|
|
struct mp_image *new2 = mp_image_new_ref(mpi);
|
|
|
|
new2->pts = vf_softpulldown_adjust_pts(&vf->priv->ptsbuf, mpi->pts, 0, 0, 3);
|
|
|
|
vf_add_output_frame(vf, new2);
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
vf->priv->out++;
|
|
|
|
vf->priv->state=0;
|
2003-08-03 12:09:58 +00:00
|
|
|
} else {
|
2012-12-26 20:31:56 +00:00
|
|
|
copy_pic_field(dmpi, mpi, 0);
|
2003-08-03 12:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vf->priv->state = state;
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
if (flags & MP_IMGFIELD_REPEAT_FIRST)
|
|
|
|
vf->priv->last_frame_duration = 3;
|
|
|
|
else
|
|
|
|
vf->priv->last_frame_duration = 2;
|
2003-08-03 12:09:58 +00:00
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
talloc_free(mpi);
|
|
|
|
|
|
|
|
return 0;
|
2003-08-03 12:09:58 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 02:03:40 +00:00
|
|
|
static int control(vf_instance_t *vf, int request, void *data)
|
|
|
|
{
|
|
|
|
switch (request) {
|
|
|
|
case VFCTRL_SEEK_RESET:
|
|
|
|
vf_detc_init_pts_buf(&vf->priv->ptsbuf);
|
2013-12-07 18:33:38 +00:00
|
|
|
return CONTROL_OK;
|
2013-01-20 02:03:40 +00:00
|
|
|
}
|
2013-12-07 18:33:38 +00:00
|
|
|
return CONTROL_UNKNOWN;
|
2013-01-20 02:03:40 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void uninit(struct vf_instance *vf)
|
2003-08-03 12:09:58 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
|
|
|
|
free(vf->priv);
|
|
|
|
}
|
|
|
|
|
2012-12-26 20:31:56 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
|
|
|
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt);
|
|
|
|
if (!(desc.flags & MP_IMGFLAG_YUV_P))
|
|
|
|
return 0;
|
|
|
|
if (desc.plane_bits != 8)
|
|
|
|
return 0;
|
|
|
|
return vf_next_query_format(vf, fmt);
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:01:38 +00:00
|
|
|
static int vf_open(vf_instance_t *vf)
|
2003-08-03 12:09:58 +00:00
|
|
|
{
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
vf->filter_ext = filter;
|
2013-01-20 02:03:40 +00:00
|
|
|
vf->control = control;
|
2012-10-26 18:05:30 +00:00
|
|
|
vf->uninit = uninit;
|
2012-12-26 20:31:56 +00:00
|
|
|
vf->query_format = query_format;
|
2012-10-26 18:05:30 +00:00
|
|
|
vf->priv = calloc(1, sizeof(struct vf_priv_s));
|
2012-11-10 20:28:47 +00:00
|
|
|
vf->priv->last_frame_duration = 2;
|
|
|
|
vf_detc_init_pts_buf(&vf->priv->ptsbuf);
|
2012-10-26 18:05:30 +00:00
|
|
|
return 1;
|
2003-08-03 12:09:58 +00:00
|
|
|
}
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_softpulldown = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "mpeg2 soft 3:2 pulldown",
|
|
|
|
.name = "softpulldown",
|
|
|
|
.open = vf_open,
|
2003-08-03 12:09:58 +00:00
|
|
|
};
|