vf_softpulldown.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #include "libvo/fastmemcpy.h"
  27. struct vf_priv_s {
  28. int state;
  29. long long in;
  30. long long out;
  31. };
  32. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
  33. {
  34. mp_image_t *dmpi;
  35. int ret = 0;
  36. int flags = mpi->fields;
  37. int state = vf->priv->state;
  38. dmpi = vf_get_image(vf->next, mpi->imgfmt,
  39. MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
  40. MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
  41. vf->priv->in++;
  42. if ((state == 0 &&
  43. !(flags & MP_IMGFIELD_TOP_FIRST)) ||
  44. (state == 1 &&
  45. flags & MP_IMGFIELD_TOP_FIRST)) {
  46. mp_msg(MSGT_VFILTER, MSGL_WARN,
  47. "softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n",
  48. state,
  49. (flags & MP_IMGFIELD_TOP_FIRST) != 0,
  50. (flags & MP_IMGFIELD_REPEAT_FIRST) != 0);
  51. state ^= 1;
  52. }
  53. if (state == 0) {
  54. ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
  55. vf->priv->out++;
  56. if (flags & MP_IMGFIELD_REPEAT_FIRST) {
  57. my_memcpy_pic(dmpi->planes[0],
  58. mpi->planes[0], mpi->w, mpi->h/2,
  59. dmpi->stride[0]*2, mpi->stride[0]*2);
  60. if (mpi->flags & MP_IMGFLAG_PLANAR) {
  61. my_memcpy_pic(dmpi->planes[1],
  62. mpi->planes[1],
  63. mpi->chroma_width,
  64. mpi->chroma_height/2,
  65. dmpi->stride[1]*2,
  66. mpi->stride[1]*2);
  67. my_memcpy_pic(dmpi->planes[2],
  68. mpi->planes[2],
  69. mpi->chroma_width,
  70. mpi->chroma_height/2,
  71. dmpi->stride[2]*2,
  72. mpi->stride[2]*2);
  73. }
  74. state=1;
  75. }
  76. } else {
  77. my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
  78. mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
  79. dmpi->stride[0]*2, mpi->stride[0]*2);
  80. if (mpi->flags & MP_IMGFLAG_PLANAR) {
  81. my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
  82. mpi->planes[1]+mpi->stride[1],
  83. mpi->chroma_width, mpi->chroma_height/2,
  84. dmpi->stride[1]*2, mpi->stride[1]*2);
  85. my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
  86. mpi->planes[2]+mpi->stride[2],
  87. mpi->chroma_width, mpi->chroma_height/2,
  88. dmpi->stride[2]*2, mpi->stride[2]*2);
  89. }
  90. ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
  91. vf->priv->out++;
  92. if (flags & MP_IMGFIELD_REPEAT_FIRST) {
  93. ret |= vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
  94. vf->priv->out++;
  95. state=0;
  96. } else {
  97. my_memcpy_pic(dmpi->planes[0],
  98. mpi->planes[0], mpi->w, mpi->h/2,
  99. dmpi->stride[0]*2, mpi->stride[0]*2);
  100. if (mpi->flags & MP_IMGFLAG_PLANAR) {
  101. my_memcpy_pic(dmpi->planes[1],
  102. mpi->planes[1],
  103. mpi->chroma_width,
  104. mpi->chroma_height/2,
  105. dmpi->stride[1]*2,
  106. mpi->stride[1]*2);
  107. my_memcpy_pic(dmpi->planes[2],
  108. mpi->planes[2],
  109. mpi->chroma_width,
  110. mpi->chroma_height/2,
  111. dmpi->stride[2]*2,
  112. mpi->stride[2]*2);
  113. }
  114. }
  115. }
  116. vf->priv->state = state;
  117. return ret;
  118. }
  119. static int config(struct vf_instance *vf,
  120. int width, int height, int d_width, int d_height,
  121. unsigned int flags, unsigned int outfmt)
  122. {
  123. return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
  124. }
  125. static void uninit(struct vf_instance *vf)
  126. {
  127. mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
  128. free(vf->priv);
  129. }
  130. static int vf_open(vf_instance_t *vf, char *args)
  131. {
  132. struct vf_priv_s *p;
  133. vf->config = config;
  134. vf->put_image = put_image;
  135. vf->uninit = uninit;
  136. vf->default_reqs = VFCAP_ACCEPT_STRIDE;
  137. vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
  138. vf->priv->state = 0;
  139. return 1;
  140. }
  141. const vf_info_t vf_info_softpulldown = {
  142. "mpeg2 soft 3:2 pulldown",
  143. "softpulldown",
  144. "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
  145. "",
  146. vf_open,
  147. NULL
  148. };