annotate libmpcodecs/vf_fixpts.c @ 32797:18d7da3834d0

ffxandpcm works fine with the native avi demuxer.
author cehoyos
date Fri, 11 Feb 2011 12:39:46 +0000
parents ccf4905a8ca6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30807
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
1 /*
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
2 * This file is part of MPlayer.
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
3 *
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
7 * (at your option) any later version.
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
8 *
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
12 * GNU General Public License for more details.
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
13 *
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License along
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
17 */
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
18
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
19 #include <stdio.h>
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
20 #include <stdlib.h>
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
21 #include <string.h>
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
22 #include <inttypes.h>
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
23
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
24 #include "config.h"
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
25 #include "mp_msg.h"
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
26 #include "help_mp.h"
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
27
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
28 #include "img_format.h"
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
29 #include "mp_image.h"
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
30 #include "vf.h"
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
31
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
32 struct vf_priv_s {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
33 double current;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
34 double step;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
35 int autostart;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
36 int autostep;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
37 unsigned have_step:1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
38 unsigned print:1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
39 };
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
40
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
41 static int put_image(vf_instance_t *vf, mp_image_t *src, double pts)
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
42 {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
43 struct vf_priv_s *p = vf->priv;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
44
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
45 if (p->print) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
46 if (pts == MP_NOPTS_VALUE)
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
47 mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: undef\n");
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
48 else
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
49 mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: %f\n", pts);
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
50 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
51 if (pts != MP_NOPTS_VALUE && p->autostart != 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
52 p->current = pts;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
53 if (p->autostart > 0)
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
54 p->autostart--;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
55 } else if (pts != MP_NOPTS_VALUE && p->autostep > 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
56 p->step = pts - p->current;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
57 p->current = pts;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
58 p->autostep--;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
59 p->have_step = 1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
60 } else if (p->have_step) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
61 p->current += p->step;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
62 pts = p->current;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
63 } else {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
64 pts = MP_NOPTS_VALUE;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
65 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
66 return vf_next_put_image(vf, src, pts);
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
67 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
68
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
69 static void uninit(vf_instance_t *vf)
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
70 {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
71 free(vf->priv);
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
72 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
73
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
74 static int parse_args(struct vf_priv_s *p, const char *args)
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
75 {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
76 int pos;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
77 double num, denom = 1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
78 int iarg;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
79
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
80 while (*args != 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
81 pos = 0;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
82 if (sscanf(args, "print%n", &pos) == 0 && pos > 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
83 p->print = 1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
84 } else if (sscanf(args, "fps=%lf%n/%lf%n", &num, &pos, &denom, &pos) >=
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
85 1 && pos > 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
86 p->step = denom / num;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
87 p->have_step = 1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
88 } else if (sscanf(args, "start=%lf%n", &num, &pos) >= 1 && pos > 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
89 p->current = num;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
90 } else if (sscanf(args, "autostart=%d%n", &iarg, &pos) == 1 && pos > 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
91 p->autostart = iarg;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
92 } else if (sscanf(args, "autofps=%d%n", &iarg, &pos) == 1 && pos > 0) {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
93 p->autostep = iarg;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
94 } else {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
95 mp_msg(MSGT_VFILTER, MSGL_FATAL,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
96 "fixpts: unknown suboption: %s\n", args);
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
97 return 0;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
98 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
99 args += pos;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
100 if (*args == ':')
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
101 args++;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
102 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
103 return 1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
104 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
105
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
106 static int open(vf_instance_t *vf, char *args)
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
107 {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
108 struct vf_priv_s *p;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
109 struct vf_priv_s ptmp = {
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
110 .current = 0,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
111 .step = 0,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
112 .autostart = 0,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
113 .autostep = 0,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
114 .have_step = 0,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
115 .print = 0,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
116 };
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
117
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
118 if (!parse_args(&ptmp, args == NULL ? "" : args))
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
119 return 0;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
120
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
121 vf->put_image = put_image;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
122 vf->uninit = uninit;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
123 vf->priv = p = malloc(sizeof(struct vf_priv_s));
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
124 *p = ptmp;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
125 p->current = -p->step;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
126
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
127 return 1;
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
128 }
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
129
32034
ccf4905a8ca6 Mark vf_info_t declaration for the fixpts filter as const.
diego
parents: 30807
diff changeset
130 const vf_info_t vf_info_fixpts = {
30807
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
131 "Fix presentation timestamps",
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
132 "fixpts",
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
133 "Nicolas George",
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
134 "",
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
135 &open,
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
136 NULL
82dd2fbdb772 Enable ASS/SSA subtitle support in mencoder
greg
parents:
diff changeset
137 };