4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include <arpa/inet.h>
23 #include "devicedvbinput.inc"
26 #include <netinet/in.h>
27 #include <sys/socket.h>
30 #include "renderfarm.inc"
31 #include "renderfarmclient.h"
32 #include "tunerserver.h"
38 TunerServer::TunerServer(RenderFarmClientThread *client)
40 this->client = client;
50 connection_closed = 0;
54 TunerServer::~TunerServer()
61 void TunerServer::main_loop()
68 error = client->write_int64(1);
73 error = client->write_int64(0);
83 int64_t command = client->read_int64(&error);
88 // Assume read error was connection closing.
91 //printf("TunerServerThread::run 1 command=%d\n", command);
97 int current_power = 0;
99 error = get_signal_strength(¤t_power, ¤t_lock);
100 error = client->write_int64(error);
102 error = client->write_int64(current_power);
104 error = client->write_int64(current_lock);
108 case NETTUNE_SET_TABLE:
109 table = client->read_int64(&error);
112 case NETTUNE_SET_CHANNEL:
113 channel = client->read_int64(&error);
116 case NETTUNE_SET_AUDIO_PID:
117 audio_pid = client->read_int64(&error);
120 case NETTUNE_SET_VIDEO_PID:
121 video_pid = client->read_int64(&error);
126 // Get requested size
127 int size = client->read_int64(&error);
128 if(temp_allocated < size)
131 temp = new unsigned char[size];
132 temp_allocated = size;
135 // Get number of bytes read and buffer
136 int bytes_read = read_data(temp, size);
137 error = client->write_int64(bytes_read);
139 error = client->write_socket((char*)temp, bytes_read);
145 printf("TunerServerThread::run audio_pid=0x%x video_pid=0x%x table=%d channel=%d\n",
150 error = open_tuner();
151 error = client->write_int64(error);
162 printf("TunerServerThread::run: connection closed\n");
168 int TunerServer::get_channel()
173 int TunerServer::get_table()
178 int TunerServer::get_audio_pid()
183 int TunerServer::get_video_pid()
188 int TunerServer::get_device_number()
190 return device_number;
194 int TunerServer::open_tuner()
199 int TunerServer::close_tuner()
205 int TunerServer::get_signal_strength(int *current_power, int *current_lock)
210 int TunerServer::read_data(unsigned char *data, int size)