Merge remote branch 'mplayer/master'
[mplayer/glamo.git] / libmpcodecs / vf_harddup.c
blob94fbcc256325ee5ffed63547232fc331b251b973
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "config.h"
6 #include "mp_msg.h"
8 #include "img_format.h"
9 #include "mp_image.h"
10 #include "vf.h"
12 struct vf_priv_s {
13 mp_image_t *last_mpi;
16 static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts)
18 mp_image_t *dmpi;
20 vf->priv->last_mpi = mpi;
22 dmpi = vf_get_image(vf->next, mpi->imgfmt,
23 MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height);
25 dmpi->planes[0] = mpi->planes[0];
26 dmpi->stride[0] = mpi->stride[0];
27 if (dmpi->flags&MP_IMGFLAG_PLANAR) {
28 dmpi->planes[1] = mpi->planes[1];
29 dmpi->stride[1] = mpi->stride[1];
30 dmpi->planes[2] = mpi->planes[2];
31 dmpi->stride[2] = mpi->stride[2];
34 return vf_next_put_image(vf, dmpi, pts);
37 static int control(struct vf_instance* vf, int request, void* data)
39 switch (request) {
40 case VFCTRL_DUPLICATE_FRAME:
41 if (!vf->priv->last_mpi) break;
42 // This is a huge hack. We assume nothing
43 // has been called earlier in the filter chain
44 // since the last put_image. This is reasonable
45 // because we're handling a duplicate frame!
46 if (put_image(vf, vf->priv->last_mpi, MP_NOPTS_VALUE))
47 return CONTROL_TRUE;
48 break;
50 return vf_next_control(vf, request, data);
53 static void uninit(struct vf_instance* vf)
55 free(vf->priv);
58 static int open(vf_instance_t *vf, char* args)
60 vf->put_image = put_image;
61 vf->control = control;
62 vf->uninit = uninit;
63 vf->priv = calloc(1, sizeof(struct vf_priv_s));
64 return 1;
67 const vf_info_t vf_info_harddup = {
68 "resubmit duplicate frames for encoding",
69 "harddup",
70 "Rich Felker",
71 "",
72 open,
73 NULL