trunk 20080912
[gitenigma.git] / lib / driver / streamwd.cpp
blob9bab1d240c9aed305b5ff1d6b61dfd90cb7bf676
1 #include <lib/driver/streamwd.h>
2 #include <config.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include <sys/ioctl.h>
9 #if HAVE_DVB_API_VERSION < 3
10 #include "ost/video.h"
11 #else
12 #include "linux/dvb/video.h"
13 #endif
15 #include <dbox/event.h>
17 #include <lib/base/eerror.h>
18 #include <lib/driver/eavswitch.h>
19 #include <lib/dvb/edvb.h>
20 #include <lib/dvb/decoder.h>
21 #include <lib/system/info.h>
22 #include <lib/system/init.h>
23 #include <lib/system/init_num.h>
24 #include <lib/system/econfig.h>
26 #define EVENT_DEVICE "/dev/dbox/event0"
28 #ifndef EVENT_FRATE_CHANGE
29 #define EVENT_FRATE_CHANGE 64 /* framerate has changed */
30 #endif
32 eStreamWatchdog *eStreamWatchdog::instance;
34 eStreamWatchdog::eStreamWatchdog()
36 sn=0;
37 handle=open( EVENT_DEVICE, O_RDONLY | O_NONBLOCK );
39 if (handle<0)
41 eDebug("failed to open %s", EVENT_DEVICE);
42 sn=0;
44 else
46 if ( ioctl(handle, EVENT_SET_FILTER, EVENT_ARATIO_CHANGE | EVENT_VCR_CHANGED | EVENT_FRATE_CHANGE ) < 0 )
48 perror("ioctl");
49 close(handle);
51 else
53 sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
54 CONNECT(sn->activated, eStreamWatchdog::check);
58 if (!instance)
59 instance=this;
60 isanamorph=0;
63 eStreamWatchdog *eStreamWatchdog::getInstance()
65 return instance;
68 void eStreamWatchdog::check(int)
70 struct event_t event;
71 int eventSize = sizeof (event);
72 int status;
73 while ( (status = read(handle, &event, eventSize)) == eventSize )
75 if (event.event & (EVENT_ARATIO_CHANGE|EVENT_FRATE_CHANGE|EVENT_VCR_CHANGED))
76 reloadSettings();
80 #define FP_IOCTL_GET_VCR 7
82 int eStreamWatchdog::getVCRActivity()
84 int val;
85 int fp = open("/dev/dbox/fp0",O_RDWR);
87 ioctl(fp, FP_IOCTL_GET_VCR, &val);
89 close(fp);
91 return val;
94 void eStreamWatchdog::reloadSettings(int override_aspect)
96 static int prevVcrSlbVlt=-1;
97 int VcrSlbVlt = getVCRActivity();
98 if (eAVSwitch::getInstance()->getInput() && VcrSlbVlt && VcrSlbVlt != prevVcrSlbVlt) // VCR selected
100 prevVcrSlbVlt=VcrSlbVlt;
101 // Loop through VCR Slowblanking values to TV Slowblanking
102 if ( eSystemInfo::getInstance()->getHwType() >= eSystemInfo::DM7000 )
103 eAVSwitch::getInstance()->setTVPin8(VcrSlbVlt==2?12:6);
104 return;
107 FILE *bitstream=fopen("/proc/bus/bitstream", "rt");
108 int frate=0;
109 if (bitstream)
111 char buffer[100];
112 int aspect=0;
113 while (fgets(buffer, 100, bitstream))
115 if (!strncmp(buffer, "A_RATIO: ", 9))
116 aspect=atoi(buffer+9);
117 if (!strncmp(buffer, "F_RATE: ", 8))
118 frate=atoi(buffer+8);
120 fclose(bitstream);
121 if (override_aspect != -1)
122 aspect = override_aspect;
123 switch (aspect)
125 case 1:
126 case 2:
127 default:
128 isanamorph=0;
129 break;
130 case 3:
131 case 4:
132 isanamorph=1;
135 /*emit*/ AspectRatioChanged(isanamorph);
137 int videoDisplayFormat=VIDEO_LETTER_BOX;
138 int doanamorph=0;
139 unsigned int pin8; // Letterbox
140 eConfig::getInstance()->getKey("/elitedvb/video/pin8", pin8);
141 switch (pin8)
143 case 0:
144 doanamorph=0;
145 videoDisplayFormat=isanamorph?VIDEO_LETTER_BOX:VIDEO_PAN_SCAN;
146 break;
147 case 1:
148 doanamorph=0;
149 videoDisplayFormat=VIDEO_PAN_SCAN;
150 break;
151 case 2:
152 doanamorph=isanamorph;
153 videoDisplayFormat=isanamorph?VIDEO_CENTER_CUT_OUT:VIDEO_PAN_SCAN;
154 break;
155 case 3:
156 doanamorph=1;
157 videoDisplayFormat=VIDEO_CENTER_CUT_OUT;
158 break;
160 eAVSwitch::getInstance()->setVideoFormat( videoDisplayFormat );
161 eAVSwitch::getInstance()->setAspectRatio(doanamorph?r169:r43);
163 switch (frate)
165 case 1:
166 case 2:
167 case 3:
168 case 6:
169 eAVSwitch::getInstance()->setVSystem(vsPAL);
170 break;
171 case 4:
172 case 5:
173 case 7:
174 case 8:
175 eAVSwitch::getInstance()->setVSystem(vsNTSC);
176 break;
178 unsigned int auto_vcr_switching=1;
179 eConfig::getInstance()->getKey("/elitedvb/video/vcr_switching", auto_vcr_switching );
180 if ( auto_vcr_switching && VcrSlbVlt != prevVcrSlbVlt )
182 prevVcrSlbVlt=VcrSlbVlt;
183 /*emit*/VCRActivityChanged( VcrSlbVlt );
187 int eStreamWatchdog::isAnamorph()
189 return isanamorph;
192 eStreamWatchdog::~eStreamWatchdog()
194 if (instance==this)
195 instance=0;
197 if (handle>=0)
198 close(handle);
200 if (sn)
201 delete sn;
204 eAutoInitP0<eStreamWatchdog> eStreamWatchdog_init(eAutoInitNumbers::dvb-1, "stream watchdog");