00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <inttypes.h>
00023
00024 #include "config.h"
00025 #include "mp_msg.h"
00026 #include "help_mp.h"
00027
00028 #include "img_format.h"
00029 #include "mp_image.h"
00030 #include "vf.h"
00031
00032 struct vf_priv_s {
00033 double current;
00034 double step;
00035 int autostart;
00036 int autostep;
00037 unsigned have_step:1;
00038 unsigned print:1;
00039 };
00040
00041 static int put_image(vf_instance_t *vf, mp_image_t *src, double pts)
00042 {
00043 struct vf_priv_s *p = vf->priv;
00044
00045 if (p->print) {
00046 if (pts == MP_NOPTS_VALUE)
00047 mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: undef\n");
00048 else
00049 mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: %f\n", pts);
00050 }
00051 if (pts != MP_NOPTS_VALUE && p->autostart != 0) {
00052 p->current = pts;
00053 if (p->autostart > 0)
00054 p->autostart--;
00055 } else if (pts != MP_NOPTS_VALUE && p->autostep > 0) {
00056 p->step = pts - p->current;
00057 p->current = pts;
00058 p->autostep--;
00059 p->have_step = 1;
00060 } else if (p->have_step) {
00061 p->current += p->step;
00062 pts = p->current;
00063 } else {
00064 pts = MP_NOPTS_VALUE;
00065 }
00066 return vf_next_put_image(vf, src, pts);
00067 }
00068
00069 static void uninit(vf_instance_t *vf)
00070 {
00071 free(vf->priv);
00072 }
00073
00074 static int parse_args(struct vf_priv_s *p, const char *args)
00075 {
00076 int pos;
00077 double num, denom = 1;
00078 int iarg;
00079
00080 while (*args != 0) {
00081 pos = 0;
00082 if (sscanf(args, "print%n", &pos) == 0 && pos > 0) {
00083 p->print = 1;
00084 } else if (sscanf(args, "fps=%lf%n/%lf%n", &num, &pos, &denom, &pos) >=
00085 1 && pos > 0) {
00086 p->step = denom / num;
00087 p->have_step = 1;
00088 } else if (sscanf(args, "start=%lf%n", &num, &pos) >= 1 && pos > 0) {
00089 p->current = num;
00090 } else if (sscanf(args, "autostart=%d%n", &iarg, &pos) == 1 && pos > 0) {
00091 p->autostart = iarg;
00092 } else if (sscanf(args, "autofps=%d%n", &iarg, &pos) == 1 && pos > 0) {
00093 p->autostep = iarg;
00094 } else {
00095 mp_msg(MSGT_VFILTER, MSGL_FATAL,
00096 "fixpts: unknown suboption: %s\n", args);
00097 return 0;
00098 }
00099 args += pos;
00100 if (*args == ':')
00101 args++;
00102 }
00103 return 1;
00104 }
00105
00106 static int open(vf_instance_t *vf, char *args)
00107 {
00108 struct vf_priv_s *p;
00109 struct vf_priv_s ptmp = {
00110 .current = 0,
00111 .step = 0,
00112 .autostart = 0,
00113 .autostep = 0,
00114 .have_step = 0,
00115 .print = 0,
00116 };
00117
00118 if (!parse_args(&ptmp, args == NULL ? "" : args))
00119 return 0;
00120
00121 vf->put_image = put_image;
00122 vf->uninit = uninit;
00123 vf->priv = p = malloc(sizeof(struct vf_priv_s));
00124 *p = ptmp;
00125 p->current = -p->step;
00126
00127 return 1;
00128 }
00129
00130 const vf_info_t vf_info_fixpts = {
00131 "Fix presentation timestamps",
00132 "fixpts",
00133 "Nicolas George",
00134 "",
00135 &open,
00136 NULL
00137 };