vf_fixpts.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <inttypes.h>
  22. #include "config.h"
  23. #include "mp_msg.h"
  24. #include "help_mp.h"
  25. #include "img_format.h"
  26. #include "mp_image.h"
  27. #include "vf.h"
  28. struct vf_priv_s {
  29. double current;
  30. double step;
  31. int autostart;
  32. int autostep;
  33. unsigned have_step:1;
  34. unsigned print:1;
  35. };
  36. static int put_image(vf_instance_t *vf, mp_image_t *src, double pts)
  37. {
  38. struct vf_priv_s *p = vf->priv;
  39. if (p->print) {
  40. if (pts == MP_NOPTS_VALUE)
  41. mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: undef\n");
  42. else
  43. mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: %f\n", pts);
  44. }
  45. if (pts != MP_NOPTS_VALUE && p->autostart != 0) {
  46. p->current = pts;
  47. if (p->autostart > 0)
  48. p->autostart--;
  49. } else if (pts != MP_NOPTS_VALUE && p->autostep > 0) {
  50. p->step = pts - p->current;
  51. p->current = pts;
  52. p->autostep--;
  53. p->have_step = 1;
  54. } else if (p->have_step) {
  55. p->current += p->step;
  56. pts = p->current;
  57. } else {
  58. pts = MP_NOPTS_VALUE;
  59. }
  60. return vf_next_put_image(vf, src, pts);
  61. }
  62. static void uninit(vf_instance_t *vf)
  63. {
  64. free(vf->priv);
  65. }
  66. static int parse_args(struct vf_priv_s *p, const char *args)
  67. {
  68. int pos;
  69. double num, denom = 1;
  70. int iarg;
  71. while (*args != 0) {
  72. pos = 0;
  73. if (sscanf(args, "print%n", &pos) == 0 && pos > 0) {
  74. p->print = 1;
  75. } else if (sscanf(args, "fps=%lf%n/%lf%n", &num, &pos, &denom, &pos) >=
  76. 1 && pos > 0) {
  77. p->step = denom / num;
  78. p->have_step = 1;
  79. } else if (sscanf(args, "start=%lf%n", &num, &pos) >= 1 && pos > 0) {
  80. p->current = num;
  81. } else if (sscanf(args, "autostart=%d%n", &iarg, &pos) == 1 && pos > 0) {
  82. p->autostart = iarg;
  83. } else if (sscanf(args, "autofps=%d%n", &iarg, &pos) == 1 && pos > 0) {
  84. p->autostep = iarg;
  85. } else {
  86. mp_msg(MSGT_VFILTER, MSGL_FATAL,
  87. "fixpts: unknown suboption: %s\n", args);
  88. return 0;
  89. }
  90. args += pos;
  91. if (*args == ':')
  92. args++;
  93. }
  94. return 1;
  95. }
  96. static int open(vf_instance_t *vf, char *args)
  97. {
  98. struct vf_priv_s *p;
  99. struct vf_priv_s ptmp = {
  100. .current = 0,
  101. .step = 0,
  102. .autostart = 0,
  103. .autostep = 0,
  104. .have_step = 0,
  105. .print = 0,
  106. };
  107. if (!parse_args(&ptmp, args == NULL ? "" : args))
  108. return 0;
  109. vf->put_image = put_image;
  110. vf->uninit = uninit;
  111. vf->priv = p = malloc(sizeof(struct vf_priv_s));
  112. *p = ptmp;
  113. p->current = -p->step;
  114. return 1;
  115. }
  116. const vf_info_t vf_info_fixpts = {
  117. "Fix presentation timestamps",
  118. "fixpts",
  119. "Nicolas George",
  120. "",
  121. &open,
  122. NULL
  123. };