workaround for ub16 compiler problem
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / tunerserver.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include <arpa/inet.h>
23 #include "devicedvbinput.inc"
24 #include <errno.h>
25 #include <netdb.h>
26 #include <netinet/in.h>
27 #include <sys/socket.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "renderfarm.inc"
31 #include "renderfarmclient.h"
32 #include "tunerserver.h"
33 #include <unistd.h>
34
35
36
37
38 TunerServer::TunerServer(RenderFarmClientThread *client)
39 {
40         this->client = client;
41         device_number = 0;
42         port = 0;
43         audio_pid = 0;
44         video_pid = 0;
45         channel = 0;
46         table = 0;
47         is_busy = 0;
48         temp = 0;
49         temp_allocated = 0;
50         connection_closed = 0;
51 }
52
53
54 TunerServer::~TunerServer()
55 {
56         delete [] temp;
57 }
58
59
60
61 void TunerServer::main_loop()
62 {
63         int error = 0;
64
65 // Send status
66         if(is_busy)
67         {
68                 error = client->write_int64(1);
69                 return;
70         }
71         else
72         {
73                 error = client->write_int64(0);
74         }
75
76         is_busy = 1;
77         while(!error)
78         {
79                 error = 0;
80
81
82
83                 int64_t command = client->read_int64(&error);
84
85
86
87
88 // Assume read error was connection closing.
89                 if(error) break;
90
91 //printf("TunerServerThread::run 1 command=%d\n", command);
92
93                 switch(command)
94                 {
95                         case NETTUNE_SIGNAL:
96                         {
97                                 int current_power = 0;
98                                 int current_lock = 0;
99                                 error = get_signal_strength(&current_power, &current_lock);
100                                 error = client->write_int64(error);
101                                 if(!error)
102                                         error = client->write_int64(current_power);
103                                 if(!error)
104                                         error = client->write_int64(current_lock);
105                                 break;
106                         }
107
108                         case NETTUNE_SET_TABLE:
109                                 table = client->read_int64(&error);
110                                 break;
111
112                         case NETTUNE_SET_CHANNEL:
113                                 channel = client->read_int64(&error);
114                                 break;
115
116                         case NETTUNE_SET_AUDIO_PID:
117                                 audio_pid = client->read_int64(&error);
118                                 break;
119
120                         case NETTUNE_SET_VIDEO_PID:
121                                 video_pid = client->read_int64(&error);
122                                 break;
123
124                         case NETTUNE_READ:
125                         {
126 // Get requested size
127                                 int size = client->read_int64(&error);
128                                 if(temp_allocated < size)
129                                 {
130                                         delete [] temp;
131                                         temp = new unsigned char[size];
132                                         temp_allocated = size;
133                                 }
134
135 // Get number of bytes read and buffer
136                                 int bytes_read = read_data(temp, size);
137                                 error = client->write_int64(bytes_read);
138                                 if(!error)
139                                         error = client->write_socket((char*)temp, bytes_read);
140                                 break;
141                         }
142
143                         case NETTUNE_OPEN:
144                         {
145                                 printf("TunerServerThread::run audio_pid=0x%x video_pid=0x%x table=%d channel=%d\n",
146                                         audio_pid,
147                                         video_pid,
148                                         table,
149                                         channel);
150                                 error = open_tuner();
151                                 error = client->write_int64(error);
152                                 break;
153                         }
154
155
156                         case NETTUNE_CLOSE:
157                                 error = 1;
158                                 break;
159                 }
160         }
161
162         printf("TunerServerThread::run: connection closed\n");
163
164         close_tuner();
165         is_busy = 0;
166 }
167
168 int TunerServer::get_channel()
169 {
170         return channel;
171 }
172
173 int TunerServer::get_table()
174 {
175         return table;
176 }
177
178 int TunerServer::get_audio_pid()
179 {
180         return audio_pid;
181 }
182
183 int TunerServer::get_video_pid()
184 {
185         return video_pid;
186 }
187
188 int TunerServer::get_device_number()
189 {
190         return device_number;
191 }
192
193
194 int TunerServer::open_tuner()
195 {
196         return 1;
197 }
198
199 int TunerServer::close_tuner()
200 {
201         return 1;
202 }
203
204
205 int TunerServer::get_signal_strength(int *current_power, int *current_lock)
206 {
207         return 1;
208 }
209
210 int TunerServer::read_data(unsigned char *data, int size)
211 {
212         return 0;
213 }
214
215
216
217