1 /*
2 * glob.c
3 *
4 * Global state data for the TV app.
5 *
6 * (C) 1997 Randall Hopper
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 2.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29
30 /* ******************** Include Files ************** */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <sys/types.h>
36 #include <sys/ipc.h>
37 #include <sys/shm.h>
38 #include "tvdefines.h"
39 #include "tvtypes.h"
40 #include "glob.h"
41
42 /* ******************** Global variables ************** */
43
44 TV_GLOB G_glob;
45 int G_debug = 0;
46 TV_BOOL G_in_x_error = FALSE;
47
48 /* ******************** Local defines ************** */
49 /* ******************** Forward declarations ************** */
50 /* ******************** Private variables ************** */
51 /* ******************** Function Definitions ************** */
52
TVGLOBDestroyImage()53 static void TVGLOBDestroyImage()
54 {
55 TV_DISPLAY *d = &G_glob.display;
56
57 /* Clean up shared memory on the way out */
58 if (( d->ximage.ximg != NULL ) && d->ximage.is_shm ) {
59 shmdt ( d->ximage.shm_info.shmaddr );
60 shmctl( d->ximage.shm_info.shmid, IPC_RMID, 0 );
61 }
62 }
63
64
TVGLOBInitXImage(TV_XIMAGE * i)65 void TVGLOBInitXImage( TV_XIMAGE *i )
66 {
67 i->ximg = NULL;
68
69 atexit( TVGLOBDestroyImage );
70 }
71
72
TVGLOBInitDisplay(TV_GLOB * p,Display * display,int screen,Widget shell_wgt)73 void TVGLOBInitDisplay(
74 TV_GLOB *p,
75 Display *display,
76 int screen,
77 Widget shell_wgt )
78 {
79 XtAppContext app_context = XtWidgetToApplicationContext( shell_wgt );
80
81 p->display.enabled = True;
82 p->display.zoom_on = False;
83 p->display.freeze_on = False;
84 p->display.aspect_lock = False;
85 p->display.cap_mode = TV_CAPTURE_CONTINUOUS;
86 p->display.geom = p->capture.geom;
87 p->display.geom.x = 10;
88 p->display.geom.y = 10;
89
90 memcpy( &p->display.refresh_geom, &p->display.geom,
91 sizeof(p->display.refresh_geom) );
92
93 p->display.unzoomed.geom = p->capture.geom;
94 p->display.unzoomed.mode = -1;
95 p->display.unzoomed.viewp_x = -1;
96 p->display.unzoomed.viewp_y = -1;
97 p->display.pix_geom.Bpp = 0;
98
99 p->display.image.buf = NULL;
100 p->display.image.geom.w = 0;
101 p->display.image.geom.h = 0;
102
103 p->display.colormap = NULL;
104
105 p->display.app_context = app_context;
106 p->display.shell_wgt = shell_wgt;
107 p->display.video_wgt = NULL;
108 p->display.win = None;
109 p->display.win_visibility = VisibilityFullyObscured;
110
111 TVGLOBInitXImage( &p->display.ximage );
112 p->display.ximage_use_for_expose = FALSE;
113
114 p->display.gc = NULL;
115 p->display.waiting_for_resize = FALSE;
116
117 TVANNOTInit( &p->display.annot, display, screen, app_context );
118
119 p->display.cursor_dozeoff_enabled = FALSE;
120 p->display.cursor_timer_set = FALSE;
121 }
122
TVGLOBInitPrefs(TV_PREFS * p)123 void TVGLOBInitPrefs( TV_PREFS *p )
124 {
125 p->cable_station = NULL;
126 p->ant_station = NULL;
127 p->cable_num_stations = 0;
128 p->ant_num_stations = 0;
129
130 p->ant_freq_set = 1;
131 p->cable_freq_set = 1;
132 p->tuner_mode = TV_TUNER_MODE_ANTENNA;
133 p->afc_mode = TRUE;
134
135 p->last_chan = 3; /* -1 = use last_freq */
136 p->last_freq = 0.0;
137 }
138
139
TVGLOBInitDisk(TV_GLOB * p)140 void TVGLOBInitDisk( TV_GLOB *p )
141 {
142 p->disk.contin_save = False;
143 p->disk.fn_freeze_base[0] = '\0';
144 p->disk.fn_video_base[0] = '\0';
145 p->disk.fn_audio_base[0] = '\0';
146 p->disk.freeze_fmt = TV_STILL_FMT_PPM;
147 p->disk.freeze_use_suffix = FALSE;
148 p->disk.freeze_next_suffix = -1;
149 p->disk.audio.file_fmt = TV_AUDIO_FILE_FMT_AIFF;
150 p->disk.audio.sample_fmt = TV_AUDIO_SAMPLE_FMT_LIN_S16_LE;
151 p->disk.audio.stereo = TRUE;
152 p->disk.audio.sample_rate = 44100;
153 p->disk.video.capture_on = FALSE;
154 p->disk.video.icap_fmt = TV_ICAP_FMT_RGB16;
155 p->disk.video.target = TV_VIDEO_TARGET_MPEG;
156 p->disk.video.geom.w = p->capture.width_max / 2;
157 p->disk.video.geom.h = p->capture.height_max / 2;
158 p->disk.video.fps = p->capture.fps_max;
159 p->disk.video.cleanup_temp = TRUE;
160 p->disk.video.cap_audio = TRUE;
161 }
162
163
TVGLOBInitPrinter(TV_GLOB * p)164 void TVGLOBInitPrinter( TV_GLOB *p )
165 {
166 strcpy( p->printer.queue_name, "ps" ); /* FIXME */
167 }
168
169
TVGLOBInit(Display * display,int screen,Widget shell)170 void TVGLOBInit( Display *display, int screen, Widget shell )
171 {
172 memset( &G_glob, '\0', sizeof( G_glob ) );
173
174 TVCAPTUREInit ( &G_glob.capture );
175 TVGLOBInitDisplay( &G_glob, display, screen, shell );
176 TVGLOBInitPrefs ( &G_glob.prefs );
177 TVGLOBInitDisk ( &G_glob );
178 TVAUDIOInit ( &G_glob.audio );
179 TVSCREENInit ( &G_glob.x, display, screen );
180 TVGLOBInitDisk ( &G_glob );
181 TVGLOBInitPrinter( &G_glob );
182 }
183
184