3 #include "channelinfo.h"
5 #include "cwindowgui.h"
9 #include "mwindowgui.h"
11 #include "playbackengine.h"
12 #include "playtransport.h"
14 #include "recordgui.h"
15 #include "recordmonitor.h"
16 #include "remotecontrol.h"
21 #include <linux/input.h>
23 WinTV::WinTV(MWindow *mwindow, int ifd)
25 this->mwindow = mwindow;
29 memset(ev, 0, sizeof(*ev));
45 ioctl(ifd, EVIOCGRAB, 0);
49 if( running() && !done ) {
58 ioctl(ifd, EVIOCGRAB, 1);
63 int WinTV::open_usb_input(int vendor, int product, int &version)
66 const char *dev_input = "/dev/input";
67 DIR *dir = opendir(dev_input);
68 if( !dir ) return ret;
71 struct input_id dev_id;
72 while( (dp = readdir64(dir)) != 0 ) {
73 char *fn = dp->d_name;
74 if( !strcmp(fn, ".") || !strcmp(fn, "..") ) continue;
75 char path[PATH_MAX]; struct stat st;
76 snprintf(path, PATH_MAX, "%s/%s", dev_input, fn);
77 if( stat(path, &st) < 0 ) continue;
78 if( !S_ISCHR(st.st_mode) ) continue;
79 int fd = open(path, O_RDONLY);
80 if( fd < 0 ) continue;
81 if( !ioctl(fd, EVIOCGID, &dev_id) ) {
82 if( dev_id.bustype == BUS_USB &&
83 dev_id.vendor == vendor &&
84 dev_id.product == product ) {
85 version = dev_id.version;
96 WinTV *WinTV::probe(MWindow *mwindow)
99 int ifd = open_usb_input(0x2040, 0x826d, ver);
100 if( ifd < 0 ) return 0;
101 printf("detected hauppauge WinTV Model 1657, ver=0x%04x\n", ver);
102 return new WinTV(mwindow, ifd);
109 int ret = read(ifd, ev, sizeof(*ev));
111 if( ret != sizeof(*ev) ) {
112 if( ret < 0 ) { perror("read event"); break; }
113 fprintf(stderr, "bad read: %d\n", ret);
120 int WinTV::check_menu_keys(int code)
128 Record *record = mwindow->gui->record;
129 if( !record->running() )
132 record->record_gui->interrupt_thread->start(0);
136 mwindow->gui->channel_info->toggle_scan();
140 RemoteControl *remote_control = mwindow->gui->remote_control;
141 if( !remote_control->deactivate() )
142 remote_control->activate();
150 void WinTV::handle_event()
154 if( !ev->value ) break;
155 this->last_code = this->code;
156 this->code = ev->code;
157 if( check_menu_keys(code) ) break;
158 RemoteHandler *handler = mwindow->gui->remote_control->handler;
160 handler->process_key(ev->code);
166 time_t t = ev->time.tv_sec;
167 struct tm *tp = localtime(&t);
168 printf("wintv event: %4d/%02d/%02d %02d:%02d:%02d.%03d = (%d, %d, 0x%x)\n",
169 tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday,
170 tp->tm_hour, tp->tm_min, tp->tm_sec,
171 (int)ev->time.tv_usec/1000, ev->type, ev->code, ev->value);
177 int WinTVCWindowHandler::wintv_process_code(int code)
179 MWindow *mwindow = wintv->mwindow;
180 EDL *edl = mwindow->edl;
182 PlayTransport *transport = mwindow->gui->mbuttons->transport;
183 if( !transport->get_edl() ) return 0;
184 PlaybackEngine *engine = transport->engine;
185 double position = engine->get_tracking_position();
186 double length = edl->tracks->total_length();
187 int next_command = -1;
192 // select window tile config = BACK 1,2,3
193 case WTV_1: case WTV_2: case WTV_3:
194 if( mwindow->wintv->last_code == WTV_BACK ) {
195 RemoteGUI *rgui = mwindow->gui->cwindow_remote_handler->gui;
196 rgui->tile_windows(code - WTV_1);
199 // select asset program config = TEXT 1,2,3,4,5,6
200 case WTV_4: case WTV_5: case WTV_6:
201 if( mwindow->wintv->last_code == WTV_TEXT ) {
202 mwindow->select_asset(code - WTV_1, 1);
205 // select position in 10 percent units
206 case WTV_7: case WTV_8: case WTV_9:
208 position = length * (code - WTV_0)/10.0;
210 // jump +- 10/60 secs
211 case WTV_LT: position -= 10.0; break;
212 case WTV_UP: position += 60.0; break;
213 case WTV_RT: position += 10.0; break;
214 case WTV_DN: position -= 60.0; break;
215 case WTV_BACK: return 1;
217 CWindowCanvas *canvas = mwindow->cwindow->gui->canvas;
218 int on = canvas->get_fullscreen() ? 0 : 1;
219 canvas->Canvas::set_fullscreen(on, 0);
221 case WTV_VOLUP: return 1;
222 case WTV_VOLDN: return 1;
223 case WTV_CH_UP: return 1;
224 case WTV_CH_DN: return 1;
225 case WTV_TEXT: return 1;
226 case WTV_CC: return 1;
227 case WTV_BOX: return 1;
228 case WTV_START: next_command = SLOW_REWIND; break;
229 case WTV_REV: next_command = FAST_REWIND; break;
230 case WTV_STOP: next_command = STOP; break;
231 case WTV_PLAY: next_command = NORMAL_FWD; break;
232 case WTV_FWD: next_command = FAST_FWD; break;
233 case WTV_END: next_command = SLOW_FWD; break;
234 case WTV_MUTE: return 1;
236 printf("wintv cwindow: unknown code: %04x\n", code);
240 if( next_command < 0 ) {
241 if( position < 0 ) position = 0;
242 transport->change_position(position);
245 transport->handle_transport(next_command);
249 int WinTVCWindowHandler::process_key(int key)
251 return wintv_process_code(key);
254 int WinTVRecordHandler::process_key(int key)
256 Record *record = wintv->mwindow->gui->record;
257 return record->wintv_process_code(key);
261 WinTVRecordHandler::WinTVRecordHandler(WinTV *wintv, RemoteControl *remote_control)
262 : RemoteHandler(remote_control->gui, GREEN)
267 WinTVCWindowHandler::WinTVCWindowHandler(WinTV *wintv, RemoteControl *remote_control)
268 : RemoteHandler(remote_control->gui, BLUE)