vf_harddup.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * This file is part of MPlayer.
  3. *
  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.
  8. *
  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.
  13. *
  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.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "config.h"
  22. #include "mp_msg.h"
  23. #include "img_format.h"
  24. #include "mp_image.h"
  25. #include "vf.h"
  26. struct vf_priv_s {
  27. mp_image_t *last_mpi;
  28. };
  29. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
  30. {
  31. mp_image_t *dmpi;
  32. vf->priv->last_mpi = mpi;
  33. dmpi = vf_get_image(vf->next, mpi->imgfmt,
  34. MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height);
  35. dmpi->planes[0] = mpi->planes[0];
  36. dmpi->stride[0] = mpi->stride[0];
  37. if (dmpi->flags&MP_IMGFLAG_PLANAR) {
  38. dmpi->planes[1] = mpi->planes[1];
  39. dmpi->stride[1] = mpi->stride[1];
  40. dmpi->planes[2] = mpi->planes[2];
  41. dmpi->stride[2] = mpi->stride[2];
  42. }
  43. return vf_next_put_image(vf, dmpi, pts);
  44. }
  45. static int control(struct vf_instance *vf, int request, void* data)
  46. {
  47. switch (request) {
  48. case VFCTRL_DUPLICATE_FRAME:
  49. if (!vf->priv->last_mpi) break;
  50. // This is a huge hack. We assume nothing
  51. // has been called earlier in the filter chain
  52. // since the last put_image. This is reasonable
  53. // because we're handling a duplicate frame!
  54. if (put_image(vf, vf->priv->last_mpi, MP_NOPTS_VALUE))
  55. return CONTROL_TRUE;
  56. break;
  57. }
  58. return vf_next_control(vf, request, data);
  59. }
  60. static void uninit(struct vf_instance *vf)
  61. {
  62. free(vf->priv);
  63. }
  64. static int vf_open(vf_instance_t *vf, char *args)
  65. {
  66. vf->put_image = put_image;
  67. vf->control = control;
  68. vf->uninit = uninit;
  69. vf->priv = calloc(1, sizeof(struct vf_priv_s));
  70. return 1;
  71. }
  72. const vf_info_t vf_info_harddup = {
  73. "resubmit duplicate frames for encoding",
  74. "harddup",
  75. "Rich Felker",
  76. "",
  77. vf_open,
  78. NULL
  79. };