annotate sub/eosd.c @ 32460:d80bbc5868de

Move eosd.[ch] to the sub directory. Remove a duplicate include of eosd.h.
author cigaes
date Wed, 27 Oct 2010 17:03:26 +0000
parents
children bc43cf7638e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32460
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
1 /*
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
2 * Extended On Screen Display
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
3 * Copyright (C) 2010 Nicolas George
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
4 *
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
5 * This file is part of MPlayer.
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
6 *
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
7 * MPlayer is free software; you can redistribute it and/or modify
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
10 * (at your option) any later version.
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
11 *
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
12 * MPlayer is distributed in the hope that it will be useful,
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
15 * GNU General Public License for more details.
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
16 *
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License along
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
20 */
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
21
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
22 #include "mpcommon.h"
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
23 #include "libmpcodecs/vf.h"
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
24 #include "libvo/video_out.h"
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
25 #include "libvo/sub.h"
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
26 #include "ass_mp.h"
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
27 #include "sub/eosd.h"
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
28
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
29 static struct mp_eosd_source *sources;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
30 static struct mp_eosd_settings settings;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
31 static struct mp_eosd_image *image_pool;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
32
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
33 void eosd_init(vf_instance_t *vf)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
34 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
35 vf->control(vf, VFCTRL_INIT_EOSD, NULL);
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
36 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
37
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
38 void eosd_register(struct mp_eosd_source *src)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
39 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
40 struct mp_eosd_source *p, **prev = &sources;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
41 for (p = sources; p && p->z_index < src->z_index; p = p->priv_next)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
42 prev = &p->priv_next;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
43 src->priv_next = p;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
44 *prev = src;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
45 src->initialized = 0;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
46 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
47
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
48 int eosd_registered(struct mp_eosd_source *source)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
49 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
50 struct mp_eosd_source *p;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
51 for (p = sources; p; p = p->priv_next)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
52 if (p == source)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
53 return 1;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
54 return 0;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
55 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
56
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
57 void eosd_configure(struct mp_eosd_settings *res)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
58 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
59 if (res->w != settings.w ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
60 res->h != settings.h ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
61 res->srcw != settings.srcw ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
62 res->srch != settings.srch ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
63 res->mt != settings.mt ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
64 res->mt != settings.mb ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
65 res->mt != settings.ml ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
66 res->mt != settings.mr ||
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
67 res->unscaled != settings.unscaled) {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
68 settings = *res;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
69 settings.changed = 1;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
70 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
71 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
72
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
73 void eosd_render_frame(double ts, struct mp_eosd_image_list *images)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
74 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
75 struct mp_eosd_source *src;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
76 int changed = 0;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
77 for (src = sources; src; src = src->priv_next) {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
78 if (src->update)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
79 src->update(src, &settings, ts);
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
80 changed |= src->changed;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
81 src->changed = 0;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
82 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
83 settings.changed = 0;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
84 images->first_source = sources;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
85 images->changed = changed;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
86 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
87
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
88 void eosd_uninit(void)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
89 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
90 struct mp_eosd_source *src;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
91 for (src = sources; src; src = src->priv_next) {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
92 // TODO: maybe only call if src->initialized is set.
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
93 if (src->uninit)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
94 src->uninit(src);
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
95 src->initialized = 0;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
96 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
97 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
98
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
99 struct mp_eosd_image *eosd_image_alloc(void)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
100 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
101 struct mp_eosd_image *r;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
102 if (!image_pool) {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
103 const unsigned n_alloc = 127; /* arbitrary */
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
104 unsigned i;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
105 image_pool = calloc(n_alloc, sizeof(*image_pool));
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
106 for (i = 0; i < n_alloc - 1; i++)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
107 image_pool[i].next = image_pool + i + 1;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
108 image_pool[i].next = NULL;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
109 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
110 r = image_pool;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
111 image_pool = image_pool->next;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
112 return r;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
113 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
114
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
115 void eosd_image_free(struct mp_eosd_image *image)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
116 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
117 image->next = image_pool;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
118 image_pool = image;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
119 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
120
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
121 void eosd_image_append(struct mp_eosd_source *source,
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
122 struct mp_eosd_image *image)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
123 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
124 image->next = NULL;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
125 *source->images_tail = image;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
126 source->images_tail = &image->next;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
127 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
128
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
129 void eosd_image_remove(struct mp_eosd_source *source,
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
130 struct mp_eosd_image *image,
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
131 struct mp_eosd_image **prev)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
132 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
133 *prev = image->next;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
134 if (!*prev)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
135 source->images_tail = prev;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
136 eosd_image_free(image);
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
137 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
138
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
139 void eosd_image_remove_all(struct mp_eosd_source *source)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
140 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
141 struct mp_eosd_image *image;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
142
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
143 while (source->images) {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
144 image = source->images;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
145 source->images = source->images->next;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
146 eosd_image_free(image);
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
147 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
148 source->images_tail = &source->images;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
149 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
150
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
151 static void next_image_in_sources(struct mp_eosd_image_list *images,
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
152 struct mp_eosd_source *src)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
153 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
154 images->source = src;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
155 while (images->source && !images->source->images)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
156 images->source = images->source->priv_next;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
157 images->image = images->source ? images->source->images : NULL;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
158 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
159
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
160 struct mp_eosd_image *eosd_image_first(struct mp_eosd_image_list *images)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
161 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
162 next_image_in_sources(images, images->first_source);
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
163 return images->image;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
164 }
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
165
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
166 struct mp_eosd_image *eosd_image_next(struct mp_eosd_image_list *images)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
167 {
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
168 images->image = images->image->next;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
169 if (!images->image)
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
170 next_image_in_sources(images, images->source->priv_next);
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
171 return images->image;
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents:
diff changeset
172 }