mixer: fix lowering hw volume while muted
[mplayer.git] / libmpcodecs / vf_fixpts.c
blob507c41c660af9dad7f8ae1cc0c133439808f01f4
1 /*
2 * This file is part of MPlayer.
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.
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.
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.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
24 #include "config.h"
25 #include "mp_msg.h"
27 #include "img_format.h"
28 #include "mp_image.h"
29 #include "vf.h"
31 struct vf_priv_s {
32 double current;
33 double step;
34 int autostart;
35 int autostep;
36 unsigned have_step:1;
37 unsigned print:1;
40 static int put_image(vf_instance_t *vf, mp_image_t *src, double pts)
42 struct vf_priv_s *p = vf->priv;
44 if (p->print) {
45 if (pts == MP_NOPTS_VALUE)
46 mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: undef\n");
47 else
48 mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: %f\n", pts);
50 if (pts != MP_NOPTS_VALUE && p->autostart != 0) {
51 p->current = pts;
52 if (p->autostart > 0)
53 p->autostart--;
54 } else if (pts != MP_NOPTS_VALUE && p->autostep > 0) {
55 p->step = pts - p->current;
56 p->current = pts;
57 p->autostep--;
58 p->have_step = 1;
59 } else if (p->have_step) {
60 p->current += p->step;
61 pts = p->current;
62 } else {
63 pts = MP_NOPTS_VALUE;
65 return vf_next_put_image(vf, src, pts);
68 static void uninit(vf_instance_t *vf)
70 free(vf->priv);
73 static int parse_args(struct vf_priv_s *p, const char *args)
75 int pos;
76 double num, denom = 1;
77 int iarg;
79 while (*args != 0) {
80 pos = 0;
81 if (sscanf(args, "print%n", &pos) == 0 && pos > 0) {
82 p->print = 1;
83 } else if (sscanf(args, "fps=%lf%n/%lf%n", &num, &pos, &denom, &pos) >=
84 1 && pos > 0) {
85 p->step = denom / num;
86 p->have_step = 1;
87 } else if (sscanf(args, "start=%lf%n", &num, &pos) >= 1 && pos > 0) {
88 p->current = num;
89 } else if (sscanf(args, "autostart=%d%n", &iarg, &pos) == 1 && pos > 0) {
90 p->autostart = iarg;
91 } else if (sscanf(args, "autofps=%d%n", &iarg, &pos) == 1 && pos > 0) {
92 p->autostep = iarg;
93 } else {
94 mp_msg(MSGT_VFILTER, MSGL_FATAL,
95 "fixpts: unknown suboption: %s\n", args);
96 return 0;
98 args += pos;
99 if (*args == ':')
100 args++;
102 return 1;
105 static int open(vf_instance_t *vf, char *args)
107 struct vf_priv_s *p;
108 struct vf_priv_s ptmp = {
109 .current = 0,
110 .step = 0,
111 .autostart = 0,
112 .autostep = 0,
113 .have_step = 0,
114 .print = 0,
117 if (!parse_args(&ptmp, args == NULL ? "" : args))
118 return 0;
120 vf->put_image = put_image;
121 vf->uninit = uninit;
122 vf->priv = p = malloc(sizeof(struct vf_priv_s));
123 *p = ptmp;
124 p->current = -p->step;
126 return 1;
129 const vf_info_t vf_info_fixpts = {
130 "Fix presentation timestamps",
131 "fixpts",
132 "Nicolas George",
134 &open,
135 NULL