annotate libmpdemux/tvi_bsdbt848.c @ 5873:74cbaabeaa33

realtime yv12->mpeg1 with libavcodec qscale=1
author arpi
date Sat, 27 Apr 2002 23:34:44 +0000
parents 02576893af2a
children d4307620912d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5081
7473fca49ca0 initial
alex
parents:
diff changeset
1 /*
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
2 (C)2002 Charles R. Henrich (henrich@msu.edu)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
3 *BSD (hopefully, requires working driver!) BrookTree capture support.
5081
7473fca49ca0 initial
alex
parents:
diff changeset
4
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
5 Still in (active) development!
5081
7473fca49ca0 initial
alex
parents:
diff changeset
6
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
7 v1.1 Mar 13 2002 Fully functional, need to move ring buffer to
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
8 the kernel driver.
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
9 v1.0 Feb 19 2002 First Release, need to add support for changing
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
10 audio parameters.
5081
7473fca49ca0 initial
alex
parents:
diff changeset
11 */
7473fca49ca0 initial
alex
parents:
diff changeset
12
7473fca49ca0 initial
alex
parents:
diff changeset
13 #include "config.h"
7473fca49ca0 initial
alex
parents:
diff changeset
14
7473fca49ca0 initial
alex
parents:
diff changeset
15 #if defined(USE_TV) && defined(HAVE_TV_BSDBT848)
7473fca49ca0 initial
alex
parents:
diff changeset
16
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
17 #define RINGSIZE 8
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
18 #define FRAGSIZE 4096 /* (2^12 see SETFRAGSIZE below) */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
19
5081
7473fca49ca0 initial
alex
parents:
diff changeset
20 #define TRUE (1==1)
7473fca49ca0 initial
alex
parents:
diff changeset
21 #define FALSE (1==0)
7473fca49ca0 initial
alex
parents:
diff changeset
22
7473fca49ca0 initial
alex
parents:
diff changeset
23 #define PAL_WIDTH 768
7473fca49ca0 initial
alex
parents:
diff changeset
24 #define PAL_HEIGHT 576
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
25 #define PAL_FPS 25
5081
7473fca49ca0 initial
alex
parents:
diff changeset
26
7473fca49ca0 initial
alex
parents:
diff changeset
27 #define NTSC_WIDTH 640
7473fca49ca0 initial
alex
parents:
diff changeset
28 #define NTSC_HEIGHT 480
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
29 #define NTSC_FPS 30
5081
7473fca49ca0 initial
alex
parents:
diff changeset
30
7473fca49ca0 initial
alex
parents:
diff changeset
31 #include <stdio.h>
7473fca49ca0 initial
alex
parents:
diff changeset
32 #include <stdlib.h>
7473fca49ca0 initial
alex
parents:
diff changeset
33 #include <unistd.h>
7473fca49ca0 initial
alex
parents:
diff changeset
34 #include <fcntl.h>
7473fca49ca0 initial
alex
parents:
diff changeset
35 #include <sys/types.h>
7473fca49ca0 initial
alex
parents:
diff changeset
36 #include <sys/mman.h>
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
37 #include <sys/filio.h>
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
38 #include <sys/time.h>
5081
7473fca49ca0 initial
alex
parents:
diff changeset
39 #include <signal.h>
7473fca49ca0 initial
alex
parents:
diff changeset
40 #include <string.h>
7473fca49ca0 initial
alex
parents:
diff changeset
41
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5572
diff changeset
42 #ifdef __NetBSD__
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5572
diff changeset
43 #include <dev/ic/bt8xx.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5572
diff changeset
44 #else
5081
7473fca49ca0 initial
alex
parents:
diff changeset
45 #include <machine/ioctl_meteor.h>
7473fca49ca0 initial
alex
parents:
diff changeset
46 #include <machine/ioctl_bt848.h>
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5572
diff changeset
47 #endif
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
48
5142
7fc559dbc607 BSD compatibility fix by Steven M. Schultz
alex
parents: 5081
diff changeset
49 #ifdef HAVE_SYS_SOUNDCARD_H
7fc559dbc607 BSD compatibility fix by Steven M. Schultz
alex
parents: 5081
diff changeset
50 #include <sys/soundcard.h>
7fc559dbc607 BSD compatibility fix by Steven M. Schultz
alex
parents: 5081
diff changeset
51 #else
5081
7473fca49ca0 initial
alex
parents:
diff changeset
52 #include <machine/soundcard.h>
5142
7fc559dbc607 BSD compatibility fix by Steven M. Schultz
alex
parents: 5081
diff changeset
53 #endif
5081
7473fca49ca0 initial
alex
parents:
diff changeset
54
7473fca49ca0 initial
alex
parents:
diff changeset
55 #include "../libvo/img_format.h"
7473fca49ca0 initial
alex
parents:
diff changeset
56 #include "tv.h"
7473fca49ca0 initial
alex
parents:
diff changeset
57
7473fca49ca0 initial
alex
parents:
diff changeset
58 /* information about this file */
7473fca49ca0 initial
alex
parents:
diff changeset
59 static tvi_info_t info = {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
60 "Brooktree848 Support",
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
61 "bsdbt848",
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
62 "Charles Henrich",
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
63 "in development"
5081
7473fca49ca0 initial
alex
parents:
diff changeset
64 };
7473fca49ca0 initial
alex
parents:
diff changeset
65
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
66 typedef struct {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
67 int dirty;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
68 double timestamp;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
69 char *buf;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
70 } RBFRAME;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
71
5081
7473fca49ca0 initial
alex
parents:
diff changeset
72 /* private data's */
7473fca49ca0 initial
alex
parents:
diff changeset
73 typedef struct {
7473fca49ca0 initial
alex
parents:
diff changeset
74
7473fca49ca0 initial
alex
parents:
diff changeset
75 /* Audio */
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
76 char *dspdev;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
77 int dspready;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
78 int dspfd;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
79 int dspsamplesize;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
80 int dspstereo;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
81 int dspspeed;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
82 int dspfmt;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
83 int dspframesize;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
84 int dsprate;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
85 long long dspbytesread;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
86
7473fca49ca0 initial
alex
parents:
diff changeset
87 /* Video */
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
88 char *btdev;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
89 int videoready;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
90 int btfd;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
91 int source;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
92 int maxfps;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
93 int fps;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
94 int iformat;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
95 int maxheight;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
96 int maxwidth;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
97 struct meteor_geomet geom;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
98 struct meteor_capframe capframe;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
99
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
100 /* Frame Buffer */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
101
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
102 int framebufsize;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
103 float timestamp;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
104 int curpaintframe;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
105 int curbufframe;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
106 unsigned char *livebuf;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
107 RBFRAME framebuf[RINGSIZE];
5081
7473fca49ca0 initial
alex
parents:
diff changeset
108
7473fca49ca0 initial
alex
parents:
diff changeset
109 /* Inputs */
7473fca49ca0 initial
alex
parents:
diff changeset
110
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
111 int input;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
112
7473fca49ca0 initial
alex
parents:
diff changeset
113 /* Tuner */
7473fca49ca0 initial
alex
parents:
diff changeset
114
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
115 char *tunerdev;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
116 int tunerfd;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
117 int tunerready;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
118 u_long tunerfreq;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
119 struct bktr_chnlset cset;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
120
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
121 /* Other */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
122
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
123 int immediatemode;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
124 double starttime;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
125
7473fca49ca0 initial
alex
parents:
diff changeset
126 } priv_t;
7473fca49ca0 initial
alex
parents:
diff changeset
127
7473fca49ca0 initial
alex
parents:
diff changeset
128 #include "tvi_def.h"
7473fca49ca0 initial
alex
parents:
diff changeset
129
7473fca49ca0 initial
alex
parents:
diff changeset
130 static priv_t *G_private=NULL;
7473fca49ca0 initial
alex
parents:
diff changeset
131
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
132 static int getinput(int innumber);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
133
7473fca49ca0 initial
alex
parents:
diff changeset
134 static void processframe(int signal)
7473fca49ca0 initial
alex
parents:
diff changeset
135 {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
136 struct timeval curtime;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
137
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
138 if(G_private->immediatemode == TRUE) return;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
139
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
140 gettimeofday(&curtime, NULL);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
141
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
142 if(G_private->framebuf[G_private->curpaintframe].dirty == TRUE)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
143 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
144 memcpy(G_private->framebuf[G_private->curpaintframe].buf,
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
145 G_private->livebuf, G_private->framebufsize);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
146
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
147 G_private->framebuf[G_private->curpaintframe].dirty = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
148
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
149 G_private->framebuf[G_private->curpaintframe].timestamp =
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
150 curtime.tv_sec + curtime.tv_usec*.000001;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
151
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
152 G_private->curpaintframe++;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
153
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
154 if(G_private->curpaintframe >= RINGSIZE) G_private->curpaintframe = 0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
155 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
156
7473fca49ca0 initial
alex
parents:
diff changeset
157 return;
7473fca49ca0 initial
alex
parents:
diff changeset
158 }
7473fca49ca0 initial
alex
parents:
diff changeset
159
7473fca49ca0 initial
alex
parents:
diff changeset
160 /* handler creator - entry point ! */
7473fca49ca0 initial
alex
parents:
diff changeset
161 tvi_handle_t *tvi_init_bsdbt848(char *device)
7473fca49ca0 initial
alex
parents:
diff changeset
162 {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
163 return(new_handle());
5081
7473fca49ca0 initial
alex
parents:
diff changeset
164 }
7473fca49ca0 initial
alex
parents:
diff changeset
165
7473fca49ca0 initial
alex
parents:
diff changeset
166 static int control(priv_t *priv, int cmd, void *arg)
7473fca49ca0 initial
alex
parents:
diff changeset
167 {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
168 switch(cmd)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
169 {
5081
7473fca49ca0 initial
alex
parents:
diff changeset
170
7473fca49ca0 initial
alex
parents:
diff changeset
171 /* Tuner Controls */
7473fca49ca0 initial
alex
parents:
diff changeset
172
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
173 case TVI_CONTROL_IS_TUNER:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
174 if(priv->tunerready == FALSE) return TVI_CONTROL_FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
175 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
176
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
177 case TVI_CONTROL_TUN_GET_FREQ:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
178 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
179 if(ioctl(priv->tunerfd, TVTUNER_GETFREQ, &priv->tunerfreq) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
180 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
181 perror("GETFREQ:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
182 return(TVI_CONTROL_FALSE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
183 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
184
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
185 (int)*(void **)arg = priv->tunerfreq;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
186 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
187 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
188
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
189 case TVI_CONTROL_TUN_SET_FREQ:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
190 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
191 priv->tunerfreq = (int)*(void **)arg;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
192
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
193 if(ioctl(priv->tunerfd, TVTUNER_SETFREQ, &priv->tunerfreq) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
194 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
195 perror("SETFREQ:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
196 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
197 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
198
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
199 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
200 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
201
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
202 case TVI_CONTROL_TUN_GET_TUNER:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
203 case TVI_CONTROL_TUN_SET_TUNER:
5081
7473fca49ca0 initial
alex
parents:
diff changeset
204
7473fca49ca0 initial
alex
parents:
diff changeset
205 /* Inputs */
7473fca49ca0 initial
alex
parents:
diff changeset
206
7473fca49ca0 initial
alex
parents:
diff changeset
207 case TVI_CONTROL_SPC_GET_INPUT:
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
208 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
209 if(ioctl(priv->btfd, METEORGINPUT, &priv->input) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
210 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
211 perror("GINPUT:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
212 return(TVI_CONTROL_FALSE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
213 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
214
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
215 (int)*(void **)arg = priv->input;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
216 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
217 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
218
5081
7473fca49ca0 initial
alex
parents:
diff changeset
219 case TVI_CONTROL_SPC_SET_INPUT:
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
220 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
221 priv->input = getinput((int)*(void **)arg);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
222
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
223 if(ioctl(priv->btfd, METEORSINPUT, &priv->input) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
224 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
225 perror("tunerfreq:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
226 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
227 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
228
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
229 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
230 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
231
7473fca49ca0 initial
alex
parents:
diff changeset
232 /* Audio Controls */
7473fca49ca0 initial
alex
parents:
diff changeset
233
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
234 case TVI_CONTROL_IS_AUDIO:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
235 if(priv->dspready == FALSE) return TVI_CONTROL_FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
236 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
237
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
238 case TVI_CONTROL_AUD_GET_FORMAT:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
239 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
240 (int)*(void **)arg = AFMT_S16_LE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
241 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
242 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
243 case TVI_CONTROL_AUD_GET_CHANNELS:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
244 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
245 (int)*(void **)arg = 2;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
246 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
247 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
248 case TVI_CONTROL_AUD_SET_SAMPLERATE:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
249 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
250 int dspspeed = (int)*(void **)arg;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
251
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
252 if(ioctl(priv->dspfd, SNDCTL_DSP_SPEED, &dspspeed) == -1)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
253 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
254 perror("invalidaudiorate");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
255 return(TVI_CONTROL_FALSE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
256 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
257
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
258 priv->dspspeed = dspspeed;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
259
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
260 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
261 priv->fps * (priv->dspstereo+1);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
262 priv->dsprate = priv->dspspeed * priv->dspsamplesize/8*
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
263 (priv->dspstereo+1);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
264
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
265 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
266 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
267 case TVI_CONTROL_AUD_GET_SAMPLERATE:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
268 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
269 (int)*(void **)arg = priv->dspspeed;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
270 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
271 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
272 case TVI_CONTROL_AUD_GET_SAMPLESIZE:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
273 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
274 (int)*(void **)arg = priv->dspsamplesize/8;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
275 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
276 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
277
7473fca49ca0 initial
alex
parents:
diff changeset
278 /* Video Controls */
7473fca49ca0 initial
alex
parents:
diff changeset
279
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
280 case TVI_CONTROL_IS_VIDEO:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
281 if(priv->videoready == FALSE) return TVI_CONTROL_FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
282 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
283
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
284 case TVI_CONTROL_TUN_SET_NORM:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
285 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
286 int req_mode = (int)*(void **)arg;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
287
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
288 priv->iformat = METEOR_FMT_AUTOMODE;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
289
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
290 if(req_mode == TV_NORM_PAL)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
291 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
292 priv->iformat = METEOR_FMT_PAL;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
293 priv->maxheight = PAL_HEIGHT;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
294 priv->maxwidth = PAL_WIDTH;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
295 priv->maxfps = PAL_FPS;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
296 priv->fps = PAL_FPS;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
297
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
298 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
299
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
300 if(priv->geom.rows > priv->maxheight)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
301 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
302 priv->geom.rows = priv->maxheight;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
303 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
304
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
305 if(priv->geom.columns > priv->maxwidth)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
306 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
307 priv->geom.columns = priv->maxwidth;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
308 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
309 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
310
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
311 if(req_mode == TV_NORM_NTSC)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
312 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
313 priv->iformat = METEOR_FMT_NTSC;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
314 priv->maxheight = NTSC_HEIGHT;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
315 priv->maxwidth = NTSC_WIDTH;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
316 priv->maxfps = NTSC_FPS;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
317 priv->fps = NTSC_FPS;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
318
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
319 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
320 priv->fps * (priv->dspstereo+1);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
321 priv->dsprate = priv->dspspeed * priv->dspsamplesize/8 *
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
322 (priv->dspstereo+1);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
323
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
324 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
325
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
326 if(priv->geom.rows > priv->maxheight)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
327 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
328 priv->geom.rows = priv->maxheight;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
329 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
330
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
331 if(priv->geom.columns > priv->maxwidth)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
332 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
333 priv->geom.columns = priv->maxwidth;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
334 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
335 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
336
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
337 if(req_mode == TV_NORM_SECAM) priv->iformat = METEOR_FMT_SECAM;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
338
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
339 if(ioctl(priv->btfd, METEORSFMT, &priv->iformat) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
340 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
341 perror("format:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
342 return(TVI_CONTROL_FALSE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
343 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
344
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
345 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
346 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
347 perror("geo:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
348 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
349 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
350
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
351 if(ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
352 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
353 perror("fps:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
354 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
355 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
356
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
357 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
358 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
359
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
360 case TVI_CONTROL_VID_GET_FORMAT:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
361 (int)*(void **)arg = IMGFMT_UYVY;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
362 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
363
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
364 case TVI_CONTROL_VID_SET_FORMAT:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
365 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
366 int req_fmt = (int)*(void **)arg;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
367
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
368 if(req_fmt != IMGFMT_UYVY) return(TVI_CONTROL_FALSE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
369
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
370 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
371 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
372 case TVI_CONTROL_VID_SET_WIDTH:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
373 priv->geom.columns = (int)*(void **)arg;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
374
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
375 if(priv->geom.columns > priv->maxwidth)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
376 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
377 priv->geom.columns = priv->maxwidth;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
378 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
379
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
380 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
381 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
382 perror("width:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
383 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
384 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
385
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
386 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
387
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
388 case TVI_CONTROL_VID_GET_WIDTH:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
389 (int)*(void **)arg = priv->geom.columns;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
390 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
391
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
392 case TVI_CONTROL_VID_SET_HEIGHT:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
393 priv->geom.rows = (int)*(void **)arg;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
394
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
395 if(priv->geom.rows > priv->maxheight)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
396 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
397 priv->geom.rows = priv->maxheight;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
398 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
399
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
400 if(priv->geom.rows <= priv->maxheight / 2)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
401 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
402 priv->geom.oformat |= METEOR_GEO_EVEN_ONLY;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
403 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
404
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
405 if(ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
406 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
407 perror("height:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
408 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
409 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
410
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
411 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
412
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
413 case TVI_CONTROL_VID_GET_HEIGHT:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
414 (int)*(void **)arg = priv->geom.rows;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
415 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
416
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
417 case TVI_CONTROL_VID_GET_FPS:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
418 (int)*(void **)arg = (int)priv->fps;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
419 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
420
7473fca49ca0 initial
alex
parents:
diff changeset
421 /*
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
422 case TVI_CONTROL_VID_SET_FPS:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
423 priv->fps = (int)*(void **)arg;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
424
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
425 if(priv->fps > priv->maxfps) priv->fps = priv->maxfps;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
426
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
427 if(ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
428 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
429 perror("fps:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
430 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
431 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
432
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
433 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
434 */
7473fca49ca0 initial
alex
parents:
diff changeset
435
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
436 case TVI_CONTROL_VID_CHK_WIDTH:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
437 case TVI_CONTROL_VID_CHK_HEIGHT:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
438 return(TVI_CONTROL_TRUE);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
439
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
440 case TVI_CONTROL_IMMEDIATE:
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
441 priv->immediatemode = TRUE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
442 return(TVI_CONTROL_TRUE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
443 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
444
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
445 return(TVI_CONTROL_UNKNOWN);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
446 }
7473fca49ca0 initial
alex
parents:
diff changeset
447
7473fca49ca0 initial
alex
parents:
diff changeset
448 static int init(priv_t *priv)
7473fca49ca0 initial
alex
parents:
diff changeset
449 {
7473fca49ca0 initial
alex
parents:
diff changeset
450 int marg;
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
451 int count;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
452
7473fca49ca0 initial
alex
parents:
diff changeset
453 G_private = priv; /* Oooh, sick */
7473fca49ca0 initial
alex
parents:
diff changeset
454
7473fca49ca0 initial
alex
parents:
diff changeset
455 /* Video Configuration */
7473fca49ca0 initial
alex
parents:
diff changeset
456
7473fca49ca0 initial
alex
parents:
diff changeset
457 priv->videoready = TRUE;
7473fca49ca0 initial
alex
parents:
diff changeset
458 priv->btdev = strdup("/dev/bktr0");
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
459 priv->immediatemode = FALSE;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
460 priv->iformat = METEOR_FMT_PAL;
7473fca49ca0 initial
alex
parents:
diff changeset
461 priv->maxheight = PAL_HEIGHT;
7473fca49ca0 initial
alex
parents:
diff changeset
462 priv->maxwidth = PAL_WIDTH;
7473fca49ca0 initial
alex
parents:
diff changeset
463 priv->maxfps = PAL_FPS;
7473fca49ca0 initial
alex
parents:
diff changeset
464 priv->source = METEOR_INPUT_DEV0;
7473fca49ca0 initial
alex
parents:
diff changeset
465 priv->fps = priv->maxfps;
7473fca49ca0 initial
alex
parents:
diff changeset
466
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
467 priv->starttime=0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
468 priv->curpaintframe=0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
469 priv->curbufframe=0;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
470
7473fca49ca0 initial
alex
parents:
diff changeset
471 priv->geom.columns = priv->maxwidth;
7473fca49ca0 initial
alex
parents:
diff changeset
472 priv->geom.rows = priv->maxheight;
7473fca49ca0 initial
alex
parents:
diff changeset
473 priv->geom.frames = 1;
7473fca49ca0 initial
alex
parents:
diff changeset
474 priv->geom.oformat = METEOR_GEO_YUV_PACKED;
7473fca49ca0 initial
alex
parents:
diff changeset
475
7473fca49ca0 initial
alex
parents:
diff changeset
476 priv->btfd = open(priv->btdev, O_RDONLY);
7473fca49ca0 initial
alex
parents:
diff changeset
477
7473fca49ca0 initial
alex
parents:
diff changeset
478 if(priv->btfd < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
479 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
480 perror("bktr open");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
481 priv->videoready = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
482 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
483
7473fca49ca0 initial
alex
parents:
diff changeset
484 if(priv->videoready == TRUE &&
7473fca49ca0 initial
alex
parents:
diff changeset
485 ioctl(priv->btfd, METEORSFMT, &priv->iformat) < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
486 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
487 perror("FMT:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
488 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
489
7473fca49ca0 initial
alex
parents:
diff changeset
490 if(priv->videoready == TRUE &&
7473fca49ca0 initial
alex
parents:
diff changeset
491 ioctl(priv->btfd, METEORSINPUT, &priv->source) < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
492 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
493 perror("SINPUT:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
494 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
495
7473fca49ca0 initial
alex
parents:
diff changeset
496 if(priv->videoready == TRUE &&
7473fca49ca0 initial
alex
parents:
diff changeset
497 ioctl(priv->btfd, METEORSFPS, &priv->fps) < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
498 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
499 perror("SFPS:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
500 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
501
7473fca49ca0 initial
alex
parents:
diff changeset
502 if(priv->videoready == TRUE &&
7473fca49ca0 initial
alex
parents:
diff changeset
503 ioctl(priv->btfd, METEORSETGEO, &priv->geom) < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
504 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
505 perror("SGEO:ioctl");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
506 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
507
7473fca49ca0 initial
alex
parents:
diff changeset
508 if(priv->videoready == TRUE)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
509 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
510 priv->framebufsize = (priv->geom.columns * priv->geom.rows * 2);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
511
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
512 priv->livebuf = (u_char *)mmap((caddr_t)0, priv->framebufsize, PROT_READ,
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
513 MAP_SHARED, priv->btfd, (off_t)0);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
514
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
515 if(priv->livebuf == (u_char *) MAP_FAILED)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
516 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
517 perror("mmap");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
518 priv->videoready = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
519 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
520
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
521 for(count=0;count<RINGSIZE;count++)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
522 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
523 priv->framebuf[count].buf = malloc(priv->framebufsize);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
524
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
525 if(priv->framebuf[count].buf == NULL)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
526 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
527 perror("framebufmalloc");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
528 priv->videoready = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
529 break;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
530 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
531
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
532 priv->framebuf[count].dirty = TRUE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
533 priv->framebuf[count].timestamp = 0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
534 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
535 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
536
7473fca49ca0 initial
alex
parents:
diff changeset
537 /* Tuner Configuration */
7473fca49ca0 initial
alex
parents:
diff changeset
538
7473fca49ca0 initial
alex
parents:
diff changeset
539 priv->tunerdev = strdup("/dev/tuner0");
7473fca49ca0 initial
alex
parents:
diff changeset
540 priv->tunerready = TRUE;
7473fca49ca0 initial
alex
parents:
diff changeset
541
7473fca49ca0 initial
alex
parents:
diff changeset
542 priv->tunerfd = open(priv->tunerdev, O_RDONLY);
7473fca49ca0 initial
alex
parents:
diff changeset
543
7473fca49ca0 initial
alex
parents:
diff changeset
544 if(priv->tunerfd < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
545 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
546 perror("tune open");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
547 priv->tunerready = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
548 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
549
7473fca49ca0 initial
alex
parents:
diff changeset
550 /* Audio Configuration */
7473fca49ca0 initial
alex
parents:
diff changeset
551
7473fca49ca0 initial
alex
parents:
diff changeset
552 priv->dspready = TRUE;
7473fca49ca0 initial
alex
parents:
diff changeset
553 priv->dspdev = strdup("/dev/dsp");
7473fca49ca0 initial
alex
parents:
diff changeset
554 priv->dspsamplesize = 16;
7473fca49ca0 initial
alex
parents:
diff changeset
555 priv->dspstereo = 1;
7473fca49ca0 initial
alex
parents:
diff changeset
556 priv->dspspeed = 44100;
7473fca49ca0 initial
alex
parents:
diff changeset
557 priv->dspfmt = AFMT_S16_LE;
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
558 priv->dspbytesread = 0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
559 priv->dsprate = priv->dspspeed * priv->dspsamplesize/8*(priv->dspstereo+1);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
560 priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/priv->fps *
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
561 (priv->dspstereo+1);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
562
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
563 if((priv->dspfd = open ("/dev/dsp", O_RDONLY, 0)) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
564 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
565 perror("/dev/dsp open");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
566 priv->dspready = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
567 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
568
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
569 marg = (256 << 16) | 12;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
570
7473fca49ca0 initial
alex
parents:
diff changeset
571 if (ioctl(priv->dspfd, SNDCTL_DSP_SETFRAGMENT, &marg ) < 0 )
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
572 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
573 perror("setfrag");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
574 priv->dspready = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
575 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
576
7473fca49ca0 initial
alex
parents:
diff changeset
577 if((priv->dspready == TRUE) &&
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
578 ((ioctl(priv->dspfd, SNDCTL_DSP_SAMPLESIZE, &priv->dspsamplesize) == -1) ||
5081
7473fca49ca0 initial
alex
parents:
diff changeset
579 (ioctl(priv->dspfd, SNDCTL_DSP_STEREO, &priv->dspstereo) == -1) ||
7473fca49ca0 initial
alex
parents:
diff changeset
580 (ioctl(priv->dspfd, SNDCTL_DSP_SPEED, &priv->dspspeed) == -1) ||
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
581 (ioctl(priv->dspfd, SNDCTL_DSP_SETFMT, &priv->dspfmt) == -1)))
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
582 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
583 perror ("configuration of /dev/dsp failed");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
584 close(priv->dspfd);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
585 priv->dspready = FALSE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
586 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
587
7473fca49ca0 initial
alex
parents:
diff changeset
588 return(1);
7473fca49ca0 initial
alex
parents:
diff changeset
589 }
7473fca49ca0 initial
alex
parents:
diff changeset
590
7473fca49ca0 initial
alex
parents:
diff changeset
591 /* that's the real start, we'got the format parameters (checked with control) */
7473fca49ca0 initial
alex
parents:
diff changeset
592 static int start(priv_t *priv)
7473fca49ca0 initial
alex
parents:
diff changeset
593 {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
594 int tmp;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
595 struct timeval curtime;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
596 int marg;
7473fca49ca0 initial
alex
parents:
diff changeset
597
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
598 fprintf(stderr,"START\n");
5081
7473fca49ca0 initial
alex
parents:
diff changeset
599 if(priv->videoready == FALSE) return(0);
7473fca49ca0 initial
alex
parents:
diff changeset
600
7473fca49ca0 initial
alex
parents:
diff changeset
601 signal(SIGUSR1, processframe);
7473fca49ca0 initial
alex
parents:
diff changeset
602 signal(SIGALRM, processframe);
7473fca49ca0 initial
alex
parents:
diff changeset
603
7473fca49ca0 initial
alex
parents:
diff changeset
604 marg = SIGUSR1;
7473fca49ca0 initial
alex
parents:
diff changeset
605
7473fca49ca0 initial
alex
parents:
diff changeset
606 if(ioctl(priv->btfd, METEORSSIGNAL, &marg) < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
607 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
608 perror("METEORSSIGNAL failed");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
609 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
610 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
611
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
612 read(priv->dspfd, &tmp, 2);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
613
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
614 gettimeofday(&curtime, NULL);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
615
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
616 priv->starttime = curtime.tv_sec + (curtime.tv_usec *.000001);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
617
7473fca49ca0 initial
alex
parents:
diff changeset
618 marg = METEOR_CAP_CONTINOUS;
7473fca49ca0 initial
alex
parents:
diff changeset
619
7473fca49ca0 initial
alex
parents:
diff changeset
620 if(ioctl(priv->btfd, METEORCAPTUR, &marg) < 0)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
621 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
622 perror("METEORCAPTUR failed");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
623 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
624 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
625
7473fca49ca0 initial
alex
parents:
diff changeset
626 return(1);
7473fca49ca0 initial
alex
parents:
diff changeset
627 }
7473fca49ca0 initial
alex
parents:
diff changeset
628
7473fca49ca0 initial
alex
parents:
diff changeset
629 static int uninit(priv_t *priv)
7473fca49ca0 initial
alex
parents:
diff changeset
630 {
7473fca49ca0 initial
alex
parents:
diff changeset
631 int marg;
7473fca49ca0 initial
alex
parents:
diff changeset
632
7473fca49ca0 initial
alex
parents:
diff changeset
633 if(priv->videoready == FALSE) return(0);
7473fca49ca0 initial
alex
parents:
diff changeset
634
7473fca49ca0 initial
alex
parents:
diff changeset
635 marg = METEOR_SIG_MODE_MASK;
7473fca49ca0 initial
alex
parents:
diff changeset
636
7473fca49ca0 initial
alex
parents:
diff changeset
637 if(ioctl( priv->btfd, METEORSSIGNAL, &marg) < 0 )
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
638 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
639 perror("METEORSSIGNAL");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
640 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
641 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
642
7473fca49ca0 initial
alex
parents:
diff changeset
643 marg = METEOR_CAP_STOP_CONT;
7473fca49ca0 initial
alex
parents:
diff changeset
644
7473fca49ca0 initial
alex
parents:
diff changeset
645 if(ioctl(priv->btfd, METEORCAPTUR, &marg) < 0 )
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
646 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
647 perror("METEORCAPTUR STOP");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
648 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
649 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
650
7473fca49ca0 initial
alex
parents:
diff changeset
651 close(priv->btfd);
7473fca49ca0 initial
alex
parents:
diff changeset
652 close(priv->dspfd);
7473fca49ca0 initial
alex
parents:
diff changeset
653
7473fca49ca0 initial
alex
parents:
diff changeset
654 priv->dspfd = -1;
7473fca49ca0 initial
alex
parents:
diff changeset
655 priv->btfd = -1;
7473fca49ca0 initial
alex
parents:
diff changeset
656
7473fca49ca0 initial
alex
parents:
diff changeset
657 priv->dspready = priv->videoready = FALSE;
7473fca49ca0 initial
alex
parents:
diff changeset
658
7473fca49ca0 initial
alex
parents:
diff changeset
659 return(1);
7473fca49ca0 initial
alex
parents:
diff changeset
660 }
7473fca49ca0 initial
alex
parents:
diff changeset
661
7473fca49ca0 initial
alex
parents:
diff changeset
662
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
663 static double grabimmediate_video_frame(priv_t *priv, char *buffer, int len)
5081
7473fca49ca0 initial
alex
parents:
diff changeset
664 {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
665 struct timeval curtime;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
666 sigset_t sa_mask;
7473fca49ca0 initial
alex
parents:
diff changeset
667
7473fca49ca0 initial
alex
parents:
diff changeset
668 if(priv->videoready == FALSE) return(0);
7473fca49ca0 initial
alex
parents:
diff changeset
669
7473fca49ca0 initial
alex
parents:
diff changeset
670 alarm(1);
7473fca49ca0 initial
alex
parents:
diff changeset
671 sigfillset(&sa_mask);
7473fca49ca0 initial
alex
parents:
diff changeset
672 sigdelset(&sa_mask,SIGINT);
7473fca49ca0 initial
alex
parents:
diff changeset
673 sigdelset(&sa_mask,SIGUSR1);
7473fca49ca0 initial
alex
parents:
diff changeset
674 sigdelset(&sa_mask,SIGALRM);
7473fca49ca0 initial
alex
parents:
diff changeset
675 sigsuspend(&sa_mask);
7473fca49ca0 initial
alex
parents:
diff changeset
676 alarm(0);
7473fca49ca0 initial
alex
parents:
diff changeset
677
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
678 memcpy(buffer, priv->livebuf, len);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
679
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
680 /* PTS = 0, show the frame NOW, this routine is only used in playback mode
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
681 without audio capture .. */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
682
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
683 return(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
684 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
685
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
686 static double grab_video_frame(priv_t *priv, char *buffer, int len)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
687 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
688 struct timeval curtime;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
689 double timestamp=0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
690 sigset_t sa_mask;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
691
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
692 if(priv->videoready == FALSE) return(0);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
693
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
694 if(priv->immediatemode == TRUE)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
695 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
696 return grabimmediate_video_frame(priv, buffer, len);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
697 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
698
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
699 while(priv->framebuf[priv->curbufframe].dirty == TRUE)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
700 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
701 alarm(1);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
702 sigemptyset(&sa_mask);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
703 sigsuspend(&sa_mask);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
704 alarm(0);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
705 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
706
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
707 memcpy(buffer, priv->framebuf[priv->curbufframe].buf, len);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
708 timestamp = priv->framebuf[priv->curbufframe].timestamp;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
709 priv->framebuf[priv->curbufframe].dirty = TRUE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
710
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
711 priv->curbufframe++;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
712 if(priv->curbufframe >= RINGSIZE) priv->curbufframe = 0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
713
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
714 return(timestamp-priv->starttime);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
715 }
7473fca49ca0 initial
alex
parents:
diff changeset
716
7473fca49ca0 initial
alex
parents:
diff changeset
717 static int get_video_framesize(priv_t *priv)
7473fca49ca0 initial
alex
parents:
diff changeset
718 {
7473fca49ca0 initial
alex
parents:
diff changeset
719 return(priv->geom.columns*priv->geom.rows*16/8);
7473fca49ca0 initial
alex
parents:
diff changeset
720 }
7473fca49ca0 initial
alex
parents:
diff changeset
721
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
722 static double grab_audio_frame(priv_t *priv, char *buffer, int len)
5081
7473fca49ca0 initial
alex
parents:
diff changeset
723 {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
724 struct timeval curtime;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
725 double curpts;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
726 double timeskew;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
727 int bytesavail;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
728 int bytesread;
7473fca49ca0 initial
alex
parents:
diff changeset
729 int ret;
7473fca49ca0 initial
alex
parents:
diff changeset
730
7473fca49ca0 initial
alex
parents:
diff changeset
731 if(priv->dspready == FALSE) return 0;
7473fca49ca0 initial
alex
parents:
diff changeset
732
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
733 gettimeofday(&curtime, NULL);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
734
5081
7473fca49ca0 initial
alex
parents:
diff changeset
735 /* Get exactly one frame of audio, which forces video sync to audio.. */
7473fca49ca0 initial
alex
parents:
diff changeset
736
7473fca49ca0 initial
alex
parents:
diff changeset
737 bytesread=read(priv->dspfd, buffer, len);
7473fca49ca0 initial
alex
parents:
diff changeset
738
7473fca49ca0 initial
alex
parents:
diff changeset
739 while(bytesread < len)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
740 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
741 ret=read(priv->dspfd, &buffer[bytesread], len-bytesread);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
742
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
743 if(ret == -1)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
744 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
745 perror("Audio read failed!");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
746 return 0;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
747 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
748
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
749 bytesread+=ret;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
750 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
751
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
752 priv->dspbytesread += bytesread;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
753
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
754 curpts = curtime.tv_sec + curtime.tv_usec * .000001;
5081
7473fca49ca0 initial
alex
parents:
diff changeset
755
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
756 timeskew = priv->dspbytesread * 1.0 / priv->dsprate - (curpts-priv->starttime);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
757
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
758 if(timeskew > .125/priv->fps)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
759 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
760 priv->starttime -= timeskew;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
761 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
762 else
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
763 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
764 if(timeskew < -.125/priv->fps)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
765 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
766 priv->starttime -= timeskew;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
767 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
768 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
769
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
770 return(priv->dspbytesread * 1.0 / priv->dsprate);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
771 }
7473fca49ca0 initial
alex
parents:
diff changeset
772
7473fca49ca0 initial
alex
parents:
diff changeset
773 static int get_audio_framesize(priv_t *priv)
7473fca49ca0 initial
alex
parents:
diff changeset
774 {
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
775 int bytesavail;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
776
5081
7473fca49ca0 initial
alex
parents:
diff changeset
777 if(priv->dspready == FALSE) return 0;
7473fca49ca0 initial
alex
parents:
diff changeset
778
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
779 if(ioctl(priv->dspfd, FIONREAD, &bytesavail) < 0)
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
780 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
781 perror("FIONREAD");
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
782 return(TVI_CONTROL_FALSE);
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
783 }
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
784
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
785 /* When mencoder wants audio data, it wants data..
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
786 it wont go do anything else until it gets it :( */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
787
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
788 if(bytesavail == 0) return FRAGSIZE;
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
789
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
790 return(bytesavail);
5081
7473fca49ca0 initial
alex
parents:
diff changeset
791 }
7473fca49ca0 initial
alex
parents:
diff changeset
792
7473fca49ca0 initial
alex
parents:
diff changeset
793 static int getinput(int innumber)
7473fca49ca0 initial
alex
parents:
diff changeset
794 {
7473fca49ca0 initial
alex
parents:
diff changeset
795 switch(innumber)
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
796 {
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
797 case 0: return METEOR_INPUT_DEV0; /* RCA */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
798 case 1: return METEOR_INPUT_DEV1; /* Tuner */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
799 case 2: return METEOR_INPUT_DEV2; /* In 1 */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
800 case 3: return METEOR_INPUT_DEV3; /* In 2 */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
801 case 4: return METEOR_INPUT_DEV_RGB; /* RGB */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
802 case 5: return METEOR_INPUT_DEV_SVIDEO; /* SVid */
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5142
diff changeset
803 }
5081
7473fca49ca0 initial
alex
parents:
diff changeset
804
7473fca49ca0 initial
alex
parents:
diff changeset
805 return 0;
7473fca49ca0 initial
alex
parents:
diff changeset
806 }
7473fca49ca0 initial
alex
parents:
diff changeset
807
7473fca49ca0 initial
alex
parents:
diff changeset
808 #endif /* USE_TV */