libavfilter/libmpcodecs/vf_harddup.c
Go to the documentation of this file.
00001 /*
00002  * This file is part of MPlayer.
00003  *
00004  * MPlayer is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * MPlayer is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 
00023 #include "config.h"
00024 #include "mp_msg.h"
00025 
00026 #include "img_format.h"
00027 #include "mp_image.h"
00028 #include "vf.h"
00029 
00030 struct vf_priv_s {
00031     mp_image_t *last_mpi;
00032 };
00033 
00034 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
00035 {
00036     mp_image_t *dmpi;
00037 
00038     vf->priv->last_mpi = mpi;
00039 
00040     dmpi = vf_get_image(vf->next, mpi->imgfmt,
00041         MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height);
00042 
00043     dmpi->planes[0] = mpi->planes[0];
00044     dmpi->stride[0] = mpi->stride[0];
00045     if (dmpi->flags&MP_IMGFLAG_PLANAR) {
00046         dmpi->planes[1] = mpi->planes[1];
00047         dmpi->stride[1] = mpi->stride[1];
00048         dmpi->planes[2] = mpi->planes[2];
00049         dmpi->stride[2] = mpi->stride[2];
00050     }
00051 
00052     return vf_next_put_image(vf, dmpi, pts);
00053 }
00054 
00055 static int control(struct vf_instance *vf, int request, void* data)
00056 {
00057     switch (request) {
00058     case VFCTRL_DUPLICATE_FRAME:
00059         if (!vf->priv->last_mpi) break;
00060         // This is a huge hack. We assume nothing
00061         // has been called earlier in the filter chain
00062         // since the last put_image. This is reasonable
00063         // because we're handling a duplicate frame!
00064         if (put_image(vf, vf->priv->last_mpi, MP_NOPTS_VALUE))
00065             return CONTROL_TRUE;
00066         break;
00067     }
00068     return vf_next_control(vf, request, data);
00069 }
00070 
00071 static void uninit(struct vf_instance *vf)
00072 {
00073     free(vf->priv);
00074 }
00075 
00076 static int vf_open(vf_instance_t *vf, char *args)
00077 {
00078     vf->put_image = put_image;
00079     vf->control = control;
00080     vf->uninit = uninit;
00081     vf->priv = calloc(1, sizeof(struct vf_priv_s));
00082     return 1;
00083 }
00084 
00085 const vf_info_t vf_info_harddup = {
00086     "resubmit duplicate frames for encoding",
00087     "harddup",
00088     "Rich Felker",
00089     "",
00090     vf_open,
00091     NULL
00092 };