Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / tunerserver.C
blob5caf6861d32f4af32c121d25eb08fd7be2e154e3
1 #include <arpa/inet.h>
2 #include "devicedvbinput.inc"
3 #include <errno.h>
4 #include <netdb.h>
5 #include <netinet/in.h>
6 #include <sys/socket.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "renderfarm.inc"
10 #include "renderfarmclient.h"
11 #include "tunerserver.h"
12 #include <unistd.h>
17 TunerServer::TunerServer(RenderFarmClientThread *client)
19         this->client = client;
20         device_number = 0;
21         port = 0;
22         audio_pid = 0;
23         video_pid = 0;
24         channel = 0;
25         table = 0;
26         is_busy = 0;
27         temp = 0;
28         temp_allocated = 0;
29         connection_closed = 0;
33 TunerServer::~TunerServer()
35         delete [] temp;
40 void TunerServer::main_loop()
42         int error = 0;
44 // Send status
45         if(is_busy)
46         {
47                 error = client->write_int64(1);
48                 return;
49         }
50         else
51         {
52                 error = client->write_int64(0);
53         }
55         is_busy = 1;
56         while(!error)
57         {
58                 error = 0;
62                 int64_t command = client->read_int64(&error);
67 // Assume read error was connection closing.
68                 if(error) break;
70 //printf("TunerServerThread::run 1 command=%d\n", command);
72                 switch(command)
73                 {
74                         case NETTUNE_SIGNAL:
75                         {
76                                 int current_power = 0;
77                                 int current_lock = 0;
78                                 error = get_signal_strength(&current_power, &current_lock);
79                                 error = client->write_int64(error);
80                                 if(!error)
81                                         error = client->write_int64(current_power);
82                                 if(!error)
83                                         error = client->write_int64(current_lock);
84                                 break;
85                         }
87                         case NETTUNE_SET_TABLE:
88                                 table = client->read_int64(&error);
89                                 break;
91                         case NETTUNE_SET_CHANNEL:
92                                 channel = client->read_int64(&error);
93                                 break;
95                         case NETTUNE_SET_AUDIO_PID:
96                                 audio_pid = client->read_int64(&error);
97                                 break;
99                         case NETTUNE_SET_VIDEO_PID:
100                                 video_pid = client->read_int64(&error);
101                                 break;
103                         case NETTUNE_READ:
104                         {
105 // Get requested size
106                                 int size = client->read_int64(&error);
107                                 if(temp_allocated < size)
108                                 {
109                                         delete [] temp;
110                                         temp = new unsigned char[size];
111                                         temp_allocated = size;
112                                 }
114 // Get number of bytes read and buffer
115                                 int bytes_read = read_data(temp, size);
116                                 error = client->write_int64(bytes_read);
117                                 if(!error)
118                                         error = client->write_socket((char*)temp, bytes_read);
119                                 break;
120                         }
122                         case NETTUNE_OPEN:
123                         {
124                                 printf("TunerServerThread::run audio_pid=0x%x video_pid=0x%x table=%d channel=%d\n",
125                                         audio_pid,
126                                         video_pid,
127                                         table,
128                                         channel);
129                                 error = open_tuner();
130                                 error = client->write_int64(error);
131                                 break;
132                         }
135                         case NETTUNE_CLOSE:
136                                 error = 1;
137                                 break;
138                 }
139         }
141         printf("TunerServerThread::run: connection closed\n");
143         close_tuner();
144         is_busy = 0;
147 int TunerServer::get_channel()
149         return channel;
152 int TunerServer::get_table()
154         return table;
157 int TunerServer::get_audio_pid()
159         return audio_pid;
162 int TunerServer::get_video_pid()
164         return video_pid;
167 int TunerServer::get_device_number()
169         return device_number;
173 int TunerServer::open_tuner()
175         return 1;
178 int TunerServer::close_tuner()
180         return 1;
184 int TunerServer::get_signal_strength(int *current_power, int *current_lock)
186         return 1;
189 int TunerServer::read_data(unsigned char *data, int size)
191         return 0;
198 //      Local Variables:
199 //      mode: C++
200 //      c-file-style: "linux"
201 //      End: