/[rdesktop]/sourceforge.net/rdesktop/trunk/rdpsnd.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/rdesktop/trunk/rdpsnd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1341 by ossman_, Wed Dec 6 13:18:36 2006 UTC revision 1342 by ossman_, Wed Dec 6 13:29:42 2006 UTC
# Line 50  static unsigned int current_format; Line 50  static unsigned int current_format;
50  unsigned int queue_hi, queue_lo, queue_pending;  unsigned int queue_hi, queue_lo, queue_pending;
51  struct audio_packet packet_queue[MAX_QUEUE];  struct audio_packet packet_queue[MAX_QUEUE];
52    
53    static uint8 packet_opcode;
54    static struct stream packet;
55    
56  void (*wave_out_play) (void);  void (*wave_out_play) (void);
57    
58  static void rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index);  static void rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index);
# Line 195  rdpsnd_process_ping(STREAM in) Line 198  rdpsnd_process_ping(STREAM in)
198  }  }
199    
200  static void  static void
201  rdpsnd_process(STREAM s)  rdpsnd_process_packet(uint8 opcode, STREAM s)
202  {  {
         uint8 type;  
         uint16 datalen;  
203          uint16 vol_left, vol_right;          uint16 vol_left, vol_right;
204          static uint16 tick, format;          static uint16 tick, format;
205          static uint8 packet_index;          static uint8 packet_index;
         static BOOL awaiting_data_packet;  
         static unsigned char missing_bytes[4] = { 0, 0, 0, 0 };  
206    
207  #ifdef RDPSND_DEBUG  #ifdef RDPSND_DEBUG
208          printf("RDPSND recv:\n");          printf("RDPSND recv:\n");
209          hexdump(s->p, s->end - s->p);          hexdump(s->p, s->end - s->p);
210  #endif  #endif
211    
212          if (awaiting_data_packet)          switch (opcode)
213          {          {
214                  if (format >= MAX_FORMATS)                  case RDPSND_WRITE:
215                  {                          in_uint16_le(s, tick);
216                          error("RDPSND: Invalid format index\n");                          in_uint16_le(s, format);
217                          return;                          in_uint8(s, packet_index);
218                  }                          in_uint8s(s, 3);
219    
220                  if (!device_open || (format != current_format))                          if (format >= MAX_FORMATS)
                 {  
                         if (!device_open && !current_driver->wave_out_open())  
221                          {                          {
222                                  rdpsnd_send_completion(tick, packet_index);                                  error("RDPSND: Invalid format index\n");
223                                  return;                                  break;
224                          }                          }
225                          if (!current_driver->wave_out_set_format(&formats[format]))  
226                            if (!device_open || (format != current_format))
227                          {                          {
228                                  rdpsnd_send_completion(tick, packet_index);                                  if (!device_open && !current_driver->wave_out_open())
229                                  current_driver->wave_out_close();                                  {
230                                  device_open = False;                                          rdpsnd_send_completion(tick, packet_index);
231                                  return;                                          break;
232                                    }
233                                    if (!current_driver->wave_out_set_format(&formats[format]))
234                                    {
235                                            rdpsnd_send_completion(tick, packet_index);
236                                            current_driver->wave_out_close();
237                                            device_open = False;
238                                            break;
239                                    }
240                                    device_open = True;
241                                    current_format = format;
242                          }                          }
                         device_open = True;  
                         current_format = format;  
                 }  
   
                 /* Insert the 4 missing bytes retrieved from last RDPSND_WRITE */  
                 memcpy(s->data, missing_bytes, 4);  
   
                 rdpsnd_queue_write(rdpsnd_dsp_process  
                                    (s, current_driver, &formats[current_format]), tick,  
                                    packet_index);  
                 awaiting_data_packet = False;  
                 return;  
         }  
243    
244          in_uint8(s, type);                          rdpsnd_queue_write(rdpsnd_dsp_process
245          in_uint8s(s, 1);        /* unknown? */                                             (s->p, s->end - s->p, current_driver,
246          in_uint16_le(s, datalen);                                              &formats[current_format]), tick, packet_index);
247                            return;
         switch (type)  
         {  
                 case RDPSND_WRITE:  
                         in_uint16_le(s, tick);  
                         in_uint16_le(s, format);  
                         in_uint8(s, packet_index);  
                         /* Here are our lost bytes, but why? */  
                         memcpy(missing_bytes, s->end - 4, 4);  
                         awaiting_data_packet = True;  
248                          break;                          break;
249                  case RDPSND_CLOSE:                  case RDPSND_CLOSE:
250                          current_driver->wave_out_close();                          current_driver->wave_out_close();
# Line 277  rdpsnd_process(STREAM s) Line 263  rdpsnd_process(STREAM s)
263                                  current_driver->wave_out_volume(vol_left, vol_right);                                  current_driver->wave_out_volume(vol_left, vol_right);
264                          break;                          break;
265                  default:                  default:
266                          unimpl("RDPSND packet type %d\n", type);                          unimpl("RDPSND packet type %x\n", opcode);
267                          break;                          break;
268          }          }
269  }  }
270    
271    static void
272    rdpsnd_process(STREAM s)
273    {
274            uint16 len;
275    
276            while (!s_check_end(s))
277            {
278                    /* New packet */
279                    if (packet.size == 0)
280                    {
281                            if ((s->end - s->p) < 4)
282                            {
283                                    error("RDPSND: Split at packet header. Things will go south from here...\n");
284                                    return;
285                            }
286                            in_uint8(s, packet_opcode);
287                            in_uint8s(s, 1);        /* Padding */
288                            in_uint16_le(s, len);
289    
290                            packet.p = packet.data;
291                            packet.end = packet.data + len;
292                            packet.size = len;
293                    }
294                    else
295                    {
296                            len = MIN(s->end - s->p, packet.end - packet.p);
297    
298                            /* Microsoft's server is so broken it's not even funny... */
299                            if (packet_opcode == RDPSND_WRITE)
300                            {
301                                    if ((packet.p - packet.data) < 12)
302                                            len = MIN(len, 12 - (packet.p - packet.data));
303                                    else if ((packet.p - packet.data) == 12)
304                                    {
305                                            in_uint8s(s, 4);
306                                            len -= 4;
307                                    }
308                            }
309    
310                            in_uint8a(s, packet.p, len);
311                            packet.p += len;
312                    }
313    
314                    /* Packet fully assembled */
315                    if (packet.p == packet.end)
316                    {
317                            packet.p = packet.data;
318                            rdpsnd_process_packet(packet_opcode, &packet);
319                            packet.size = 0;
320                    }
321            }
322    }
323    
324  static BOOL  static BOOL
325  rdpsnd_auto_open(void)  rdpsnd_auto_open(void)
326  {  {
# Line 357  rdpsnd_init(char *optarg) Line 396  rdpsnd_init(char *optarg)
396    
397          drivers = NULL;          drivers = NULL;
398    
399            packet.data = xmalloc(65536);
400            packet.p = packet.end = packet.data;
401            packet.size = 0;
402    
403          rdpsnd_channel =          rdpsnd_channel =
404                  channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,                  channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
405                                   rdpsnd_process);                                   rdpsnd_process);

Legend:
Removed from v.1341  
changed lines
  Added in v.1342

  ViewVC Help
Powered by ViewVC 1.1.26