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