trunk 20080912
[gitenigma.git] / boot / showlogo / showlogo.cpp
blob4af1d7df7eaaca943161ec779f07311bfe8ae077
1 /*
2 * $Id: showlogo.cpp,v 1.6 2008/05/11 14:22:17 seife Exp $
4 * (C) 2005 by digi_casi <digi_casi@tuxbox.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <config.h>
22 #if HAVE_DVB_API_VERSION < 3
23 #include <ost/dmx.h>
24 #include <ost/video.h>
25 #include <ost/audio.h>
26 #define VIDEO_DEV "/dev/dvb/card0/video0"
27 #define AUDIO_DEV "/dev/dvb/card0/audio0"
28 #define DEMUX_DEV "/dev/dvb/card0/demux0"
29 #else
30 #include <linux/dvb/dmx.h>
31 #include <linux/dvb/video.h>
32 #include <linux/dvb/audio.h>
33 #define VIDEO_DEV "/dev/dvb/adapter0/video0"
34 #define AUDIO_DEV "/dev/dvb/adapter0/audio0"
35 #define DEMUX_DEV "/dev/dvb/adapter0/demux0"
36 #define audioStatus audio_status
37 #define videoStatus video_status
38 #define pesType pes_type
39 #define playState play_state
40 #define audioStreamSource_t audio_stream_source_t
41 #define videoStreamSource_t video_stream_source_t
42 #define streamSource stream_source
43 #define dmxPesFilterParams dmx_pes_filter_params
44 #endif
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <unistd.h>
49 #include <fcntl.h>
50 #include <memory.h>
51 #include <sys/ioctl.h>
52 #include <sys/wait.h>
53 #include <signal.h>
54 #include <errno.h>
55 #include <lib/base/estring.h>
56 #include <lib/driver/eavswitch.h>
57 #include <dbox/avs_core.h>
59 // #define OLD_VBI
61 #undef strcpy
62 #undef strcmp
63 #undef strlen
64 #undef strncmp
66 #ifdef OLD_VBI // oldvbi header
67 #include <dbox/avia_gt_vbi.h>
68 #endif
70 // Non DVB API Functions and ioctls
72 #define VIDEO_FLUSH_CLIP_BUFFER 0
73 #define VIDEO_GET_PTS _IOR('o', 1, unsigned int*)
74 #define VIDEO_SET_AUTOFLUSH _IOW('o', 2, int)
75 #define VIDEO_CLEAR_SCREEN 3
76 #define VIDEO_SET_FASTZAP _IOW('o', 4, int)
78 #define SAAIOGREG 1 /* read registers */
79 #define SAAIOSINP 2 /* input control */
80 #define SAAIOSOUT 3 /* output control */
81 #define SAAIOSENC 4 /* set encoder (pal/ntsc) */
82 #define SAAIOSMODE 5 /* set mode (rgb/fbas/svideo/component) */
83 #define SAAIOSWSS 10 /* set wide screen signaling data */
85 #define SAA_MODE_RGB 0
86 #define SAA_MODE_FBAS 1
87 #define SAA_MODE_SVIDEO 2
88 #define SAA_MODE_COMPONENT 3
90 #define LOGO "/root/platform/kernel/bild"
92 int getKey(eString findkey)
94 int res = 1;
95 FILE *f = fopen("/var/tuxbox/config/enigma/config", "r");
96 if (f)
98 char buffer[1024];
99 while (1)
101 if (!fgets(buffer, 1024, f))
102 break;
103 if (strlen(buffer) < 4)
104 break;
105 if (buffer[0] == 'u')
107 eString b = eString(buffer);
108 b = b.right(b.length() - 2);
109 unsigned int pos = b.find("=");
110 eString key = b.left(pos);
111 if (key == findkey)
113 printf("found key = %s\n", key.c_str());
114 eString result = b.right(b.length() - pos - 1);
115 res = atoi(result.c_str());
116 break;
120 fclose(f);
122 printf("returning %d\n", res);
123 return res;
126 int setColorFormat(eAVColorFormat c)
128 printf("setting color format %d\n", c);
129 int saafd = open("/dev/dbox/saa0", O_RDWR);
130 int avsfd = open("/dev/dbox/avs0", O_RDWR);
131 int arg=0;
132 switch (c)
134 case cfNull:
135 return -1;
136 default:
137 case cfCVBS:
138 arg=SAA_MODE_FBAS;
139 break;
140 case cfRGB:
141 arg=SAA_MODE_RGB;
142 break;
143 case cfYC:
144 arg=SAA_MODE_SVIDEO;
145 break;
146 case cfYPbPr:
147 arg=SAA_MODE_COMPONENT;
148 break;
150 int fblk = ((c == cfRGB) || (c == cfYPbPr)) ? 1 : 0;
151 ioctl(saafd, SAAIOSMODE, &arg);
152 ioctl(avsfd, AVSIOSFBLK, &fblk);
153 close(saafd);
154 close(avsfd);
155 return 0;
158 void displayIFrame(const char *frame, int len)
160 int fdv = open("/dev/video", O_WRONLY);
161 if (fdv > 0)
163 int fdvideo = open(VIDEO_DEV, O_RDWR);
164 ioctl(fdvideo, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY );
165 ioctl(fdvideo, VIDEO_CLEAR_BUFFER);
166 ioctl(fdvideo, VIDEO_PLAY);
168 for (int i = 0; i < 2; i++)
169 write(fdv, frame, len);
171 unsigned char buf[128];
172 memset(&buf, 0, 128);
173 write(fdv, &buf, 128);
175 ioctl(fdv, VIDEO_SET_AUTOFLUSH, 0);
176 ioctl(fdvideo, VIDEO_SET_BLANK, 0);
177 close(fdvideo);
178 ioctl(fdv, VIDEO_SET_AUTOFLUSH, 1);
180 close(fdv);
184 void displayIFrameFromFile(const char *filename)
186 int file = open(filename, O_RDONLY);
187 if (file > 0)
189 int size = lseek(file, 0, SEEK_END);
190 lseek(file, 0, SEEK_SET);
191 if (size > 0)
193 char *buffer = new char[size];
194 read(file, buffer, size);
195 displayIFrame(buffer, size);
196 delete[] buffer;
198 close(file);
202 int main(int argc, char **argv)
204 char *logo = (argc < 2) ? strdup(LOGO) : argv[1];
205 int colorformat = getKey("/elitedvb/video/colorformat");
206 setColorFormat((eAVColorFormat)colorformat);
207 displayIFrameFromFile(logo);
208 return EXIT_SUCCESS;