Annotation of /trunk/linterm_tools/fw_builder/bootsplash/fbmngplay.c
Parent Directory | Revision Log
Revision 658 -
(hide annotations)
(download)
Mon Jan 14 16:57:24 2008 UTC (16 years, 4 months ago) by niro
File MIME type: text/plain
File size: 4989 byte(s)
Mon Jan 14 16:57:24 2008 UTC (16 years, 4 months ago) by niro
File MIME type: text/plain
File size: 4989 byte(s)
initial import
1 | niro | 658 | /* |
2 | * fbmngplay - fb console MNG player. | ||
3 | * (c) 2001-2002 by Stefan Reinauer, <stepan@suse.de> | ||
4 | * | ||
5 | * This program is based on mngplay, written and (C) by | ||
6 | * Ralph Giles <giles@ashlu.bc.ca> | ||
7 | * | ||
8 | * This program my be redistributed under the terms of the | ||
9 | * GNU General Public Licence, version 2, or at your preference, | ||
10 | * any later version. | ||
11 | */ | ||
12 | |||
13 | #include <unistd.h> | ||
14 | #include <fcntl.h> | ||
15 | #include <getopt.h> | ||
16 | #include <sys/mman.h> | ||
17 | #include <sys/ioctl.h> | ||
18 | #include <linux/fb.h> | ||
19 | #include <signal.h> | ||
20 | |||
21 | #include "fbmngplay.h" | ||
22 | #include "messages.h" | ||
23 | #include "console.h" | ||
24 | #include "mng.h" | ||
25 | |||
26 | volatile int run = 1; | ||
27 | int verbose = 0; | ||
28 | int buffered = 0; | ||
29 | int waitsignal = 0; | ||
30 | int delta = 16; | ||
31 | int sconly = 0; | ||
32 | |||
33 | /* | ||
34 | * Signal handlers | ||
35 | */ | ||
36 | |||
37 | void sigint_handler(int sig) | ||
38 | { | ||
39 | if (waitsignal) | ||
40 | return; | ||
41 | run = 2; | ||
42 | } | ||
43 | |||
44 | void sigterm_handler(int sig) | ||
45 | { | ||
46 | if (waitsignal) | ||
47 | return; | ||
48 | restore_area(); | ||
49 | run = 0; | ||
50 | } | ||
51 | |||
52 | void sigusr1_handler(int sig) | ||
53 | { | ||
54 | signal(SIGUSR1, SIG_IGN); | ||
55 | run = 0; | ||
56 | } | ||
57 | |||
58 | /* | ||
59 | * Main loop | ||
60 | */ | ||
61 | |||
62 | int main(int argc, char *argv[]) | ||
63 | { | ||
64 | int fbdev, c, option_index; | ||
65 | unsigned int alpha; | ||
66 | struct fb_var_screeninfo var; | ||
67 | struct fb_fix_screeninfo fix; | ||
68 | |||
69 | /* Check which console we're running on */ | ||
70 | init_consoles(); | ||
71 | |||
72 | /* allocate our stream data structure */ | ||
73 | mng = (mngstuff *) calloc(1, sizeof(*mng)); | ||
74 | if (mng == NULL) { | ||
75 | fprintf(stderr, "could not allocate stream structure.\n"); | ||
76 | exit(0); | ||
77 | } | ||
78 | |||
79 | alpha = 100; | ||
80 | mng->alpha = 100; | ||
81 | mng->fbx = 15; | ||
82 | mng->fby = 15; | ||
83 | mng->background = NULL; | ||
84 | |||
85 | while (1) { | ||
86 | static struct option long_options[] = { | ||
87 | {"help", 0, 0, 'h'}, | ||
88 | {"verbose", 0, 0, 'v'}, | ||
89 | {"alpha", 1, 0, 'a'}, | ||
90 | {"buffered", 0, 0, 'b'}, | ||
91 | {"signal", 0, 0, 's'}, | ||
92 | {"delta", 0, 0, 'd'}, | ||
93 | {"version", 0, 0, 'V'}, | ||
94 | {"start-console", 0, 0, 'S'}, | ||
95 | {"console", 1, 0, 'c'}, | ||
96 | {0, 0, 0, 0} | ||
97 | }; | ||
98 | |||
99 | c = getopt_long(argc, argv, "a:x:y:bh?vsd:VSc:", | ||
100 | long_options, &option_index); | ||
101 | |||
102 | if (c == -1) | ||
103 | break; | ||
104 | |||
105 | switch (c) { | ||
106 | case 'a': | ||
107 | alpha = atoi(optarg); | ||
108 | if (alpha > 100) | ||
109 | alpha = 100; | ||
110 | mng->alpha = alpha; | ||
111 | break; | ||
112 | case 'x': | ||
113 | mng->fbx = atoi(optarg); | ||
114 | break; | ||
115 | case 'y': | ||
116 | mng->fby = atoi(optarg); | ||
117 | break; | ||
118 | case 'd': | ||
119 | delta = atoi(optarg); | ||
120 | break; | ||
121 | case '?': | ||
122 | case 'h': | ||
123 | usage(argv[0]); | ||
124 | exit(0); | ||
125 | case 'v': | ||
126 | verbose = 1; | ||
127 | break; | ||
128 | case 's': | ||
129 | waitsignal = 1; | ||
130 | break; | ||
131 | case 'b': | ||
132 | buffered = 1; | ||
133 | break; | ||
134 | case 'V': | ||
135 | version(); | ||
136 | exit(0); | ||
137 | case 'c': | ||
138 | start_console = atoi(optarg) - 1; | ||
139 | case 'S': | ||
140 | sconly = 1; | ||
141 | break; | ||
142 | default: | ||
143 | break; | ||
144 | } | ||
145 | } | ||
146 | #if 0 | ||
147 | if (!output && optind >= argc) { | ||
148 | #else | ||
149 | if (optind >= argc) { | ||
150 | #endif | ||
151 | printf("Which files do you want to play?\n"); | ||
152 | exit(0); | ||
153 | } | ||
154 | |||
155 | /* Initialize framebuffer */ | ||
156 | fbdev = open("/dev/fb0", O_RDWR); | ||
157 | if (fbdev < 0) { | ||
158 | fprintf(stderr, "error while opening framebuffer.\n"); | ||
159 | exit(fbdev); | ||
160 | } | ||
161 | |||
162 | ioctl(fbdev, FBIOGET_VSCREENINFO, &var); | ||
163 | mng->fbwidth = var.xres; | ||
164 | mng->fbheight = var.yres; | ||
165 | mng->fbbpp = var.bits_per_pixel; | ||
166 | |||
167 | mng->fbredo = var.red.offset; | ||
168 | mng->fbgreeno = var.green.offset; | ||
169 | mng->fbblueo = var.blue.offset; | ||
170 | mng->fbredl = var.red.length; | ||
171 | mng->fbgreenl = var.green.length; | ||
172 | mng->fbbluel = var.blue.length; | ||
173 | |||
174 | /* Display might have a line length unequal | ||
175 | * the visible line. | ||
176 | */ | ||
177 | ioctl(fbdev, FBIOGET_FSCREENINFO, &fix); | ||
178 | mng->fbrow = fix.line_length; | ||
179 | |||
180 | mng->display = | ||
181 | mmap(NULL, mng->fbrow * mng->fbheight, | ||
182 | PROT_WRITE | PROT_READ, MAP_SHARED, fbdev, 0); | ||
183 | #if 0 | ||
184 | if (output) | ||
185 | prepare_output(); | ||
186 | #endif | ||
187 | /* arrange to call the shutdown routine before we exit */ | ||
188 | atexit(&cleanup); | ||
189 | |||
190 | while (optind < argc) { | ||
191 | /* leftover arguements are filenames. */ | ||
192 | mng->filename = argv[optind++]; | ||
193 | |||
194 | /* set up the mng decoder for our stream */ | ||
195 | mng->mng = | ||
196 | mng_initialize(mng, mngalloc, mngfree, MNG_NULL); | ||
197 | if (mng->mng == MNG_NULL) { | ||
198 | fprintf(stderr, "could not initialize libmng.\n"); | ||
199 | exit(1); | ||
200 | } | ||
201 | |||
202 | /* set the callbacks */ | ||
203 | mng_setcb_errorproc(mng->mng, mngerror); | ||
204 | mng_setcb_openstream(mng->mng, mngopenstream); | ||
205 | mng_setcb_closestream(mng->mng, mngclosestream); | ||
206 | mng_setcb_readdata(mng->mng, mngreadstream); | ||
207 | mng_setcb_gettickcount(mng->mng, mnggetticks); | ||
208 | mng_setcb_settimer(mng->mng, mngsettimer); | ||
209 | mng_setcb_processheader(mng->mng, mngprocessheader); | ||
210 | mng_setcb_getcanvasline(mng->mng, mnggetcanvasline); | ||
211 | mng_setcb_refresh(mng->mng, mngrefresh); | ||
212 | |||
213 | signal(SIGINT, sigint_handler); | ||
214 | signal(SIGTERM, sigterm_handler); | ||
215 | |||
216 | mng_readdisplay(mng->mng); | ||
217 | |||
218 | /* loop though the frames */ | ||
219 | while (mng->delay && run) { | ||
220 | usleep(mng->delay * 1000); | ||
221 | mng->delay = 0; | ||
222 | mng_display_resume(mng->mng); | ||
223 | if (run == 2) { | ||
224 | if (mng->alpha == 0) | ||
225 | run = 0; | ||
226 | mng->alpha -= delta; | ||
227 | if (mng->alpha < 0) | ||
228 | mng->alpha = 0; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | if (waitsignal && optind < argc) { | ||
233 | signal(SIGUSR1, sigusr1_handler); | ||
234 | run = 1; | ||
235 | while (run) { | ||
236 | sleep(2); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | memset(mng->copybuffer, 0, 4 * mng->width * mng->height); | ||
241 | run = 1; | ||
242 | mng->alpha = alpha; | ||
243 | if (optind == argc) { /* last file */ | ||
244 | restore_area(); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | /* cleanup and quit */ | ||
249 | return mngquit(mng->mng); | ||
250 | } |