1 ///////////////////////////////////////////////////////////////////////////////
5 //---------------------------------------------------------------------------//
6 // Copyright: Andreas Eversberg //
10 ///////////////////////////////////////////////////////////////////////////////
13 #include <sys/types.h>
24 H323_chan::H323_chan(const PString &token, BOOL isEncoding) : PIndirectChannel()
27 // d_isEncoding = isEncoding;
29 PDEBUG(DEBUG_H323, "H323 channel constuctor of channel (%scoding)\n", (isEncoding)?"en":"de");
38 H323_chan::~H323_chan(void)
41 PDEBUG(DEBUG_H323, "H323 channel destuctor\n");
48 BOOL H323_chan::Close(void)
50 PDEBUG(DEBUG_H323, "H323 channel Close\n");
59 BOOL H323_chan::IsOpen(void) const
61 PDEBUG(DEBUG_H323, "H323 channel IsOpen\n");
70 BOOL H323_chan::Read(void *buf, PINDEX len)
74 const unsigned char *token_string = d_token;
80 // cout << "H323 channel Read " << nr_words << " words" << endl;
83 if (!(port = (class H323Port *)find_port_with_token((char *)token_string)))
85 PERROR("H323 channel Read() cannot find port with token %s\n", token_string);
91 nr_words = port->read_audio((unsigned char *)buf, nr_words, 0);
98 PDEBUG(DEBUG_H323, "H323 channel Read(%s) sending to h323 the first time\n", token_string);
104 elapsed += nr_words*125;
105 if (elapsed > (diff.GetMilliSeconds()*1000))
106 usleep(elapsed - (diff.GetMilliSeconds()*1000));
108 lastReadCount = 2 * nr_words;
117 BOOL H323_chan::Write(const void *buf, PINDEX len)
120 class H323Port *port;
121 const unsigned char *token_string = d_token;
124 unsigned char *data_temp;
125 unsigned long length_temp;
126 struct message *message;
130 // cout << "H323 channel Write " << nr_words << " words" << endl;
133 if (!(port = (class H323Port *)find_port_with_token((char *)token_string)))
135 PERROR("H323 channel Write() cannot find port with token %s\n", token_string);
143 data_temp = (unsigned char *)buf;
146 message = message_create(port->p_serial, ACTIVE_EPOINT(port->p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA);
147 message->param.data.len = (length_temp>sizeof(message->param.data.data))?sizeof(message->param.data.data):length_temp;
148 memcpy(message->param.data.data, data_temp, message->param.data.len);
149 message->param.data.compressed = 0;
150 /* { // testin with law data
152 while (i<message->param.data.len)
154 ((unsigned char *)message->param.data.data)[i] = audio_s16_to_law[((signed short*)data_temp)[i] & 0xffff];
158 message->param.data.len = message->param.data.len/2;
159 message->param.data.compressed = 1;
161 message->param.data.port_type = port->p_type;
162 message->param.data.port_id = port->p_serial;
163 message_put(message);
164 if (length_temp <= sizeof(message->param.data.data))
166 data_temp += sizeof(message->param.data.data);
167 length_temp -= sizeof(message->param.data.data);
175 PDEBUG(DEBUG_H323, "H323 channel Write(%s) receiving from h323 the first time\n", token_string);
181 elapsed += nr_words*125;
182 if (elapsed > (diff.GetMilliSeconds()*1000))
183 usleep(elapsed - (diff.GetMilliSeconds()*1000));
185 lastWriteCount = 2 * nr_words;