/[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 1254 by stargo, Sun Sep 17 10:32:18 2006 UTC revision 1272 by stargo, Thu Sep 21 19:00:11 2006 UTC
# Line 21  Line 21 
21    
22  #include "rdesktop.h"  #include "rdesktop.h"
23  #include "rdpsnd.h"  #include "rdpsnd.h"
24    #include "rdpsnd_dsp.h"
25    
26  #define RDPSND_CLOSE            1  #define RDPSND_CLOSE            1
27  #define RDPSND_WRITE            2  #define RDPSND_WRITE            2
# Line 37  BOOL g_dsp_busy = False; Line 38  BOOL g_dsp_busy = False;
38  int g_dsp_fd;  int g_dsp_fd;
39    
40  static VCHANNEL *rdpsnd_channel;  static VCHANNEL *rdpsnd_channel;
41    static struct audio_driver *drivers = NULL;
42    struct audio_driver *current_driver = NULL;
43    
44  static BOOL device_open;  static BOOL device_open;
45  static WAVEFORMATEX formats[MAX_FORMATS];  static WAVEFORMATEX formats[MAX_FORMATS];
46  static unsigned int format_count;  static unsigned int format_count;
47  static unsigned int current_format;  static unsigned int current_format;
48  static unsigned int queue_hi, queue_lo;  unsigned int queue_hi, queue_lo;
49  static struct audio_packet packet_queue[MAX_QUEUE];  struct audio_packet packet_queue[MAX_QUEUE];
50    
51    void (*wave_out_play) (void);
52    
53  static STREAM  static STREAM
54  rdpsnd_init_packet(uint16 type, uint16 size)  rdpsnd_init_packet(uint16 type, uint16 size)
# Line 94  rdpsnd_process_negotiate(STREAM in) Line 99  rdpsnd_process_negotiate(STREAM in)
99          in_uint16_le(in, in_format_count);          in_uint16_le(in, in_format_count);
100          in_uint8s(in, 4);       /* pad, status, pad */          in_uint8s(in, 4);       /* pad, status, pad */
101    
102          if (wave_out_open())          if (current_driver->wave_out_open())
103          {          {
104                  wave_out_close();                  current_driver->wave_out_close();
105                  device_available = True;                  device_available = True;
106          }          }
107    
# Line 127  rdpsnd_process_negotiate(STREAM in) Line 132  rdpsnd_process_negotiate(STREAM in)
132                          in_uint8a(in, format->cb, readcnt);                          in_uint8a(in, format->cb, readcnt);
133                          in_uint8s(in, discardcnt);                          in_uint8s(in, discardcnt);
134    
135                          if (device_available && wave_out_format_supported(format))                          if (device_available && current_driver->wave_out_format_supported(format))
136                          {                          {
137                                  format_count++;                                  format_count++;
138                                  if (format_count == MAX_FORMATS)                                  if (format_count == MAX_FORMATS)
# Line 189  rdpsnd_process(STREAM s) Line 194  rdpsnd_process(STREAM s)
194          static uint16 tick, format;          static uint16 tick, format;
195          static uint8 packet_index;          static uint8 packet_index;
196          static BOOL awaiting_data_packet;          static BOOL awaiting_data_packet;
197            static unsigned char missing_bytes[4] = { 0, 0, 0, 0 };
198    
199  #ifdef RDPSND_DEBUG  #ifdef RDPSND_DEBUG
200          printf("RDPSND recv:\n");          printf("RDPSND recv:\n");
# Line 205  rdpsnd_process(STREAM s) Line 211  rdpsnd_process(STREAM s)
211    
212                  if (!device_open || (format != current_format))                  if (!device_open || (format != current_format))
213                  {                  {
214                          if (!device_open && !wave_out_open())                          if (!device_open && !current_driver->wave_out_open())
215                          {                          {
216                                  rdpsnd_send_completion(tick, packet_index);                                  rdpsnd_send_completion(tick, packet_index);
217                                  return;                                  return;
218                          }                          }
219                          if (!wave_out_set_format(&formats[format]))                          if (!current_driver->wave_out_set_format(&formats[format]))
220                          {                          {
221                                  rdpsnd_send_completion(tick, packet_index);                                  rdpsnd_send_completion(tick, packet_index);
222                                  wave_out_close();                                  current_driver->wave_out_close();
223                                  device_open = False;                                  device_open = False;
224                                  return;                                  return;
225                          }                          }
# Line 221  rdpsnd_process(STREAM s) Line 227  rdpsnd_process(STREAM s)
227                          current_format = format;                          current_format = format;
228                  }                  }
229    
230                  rdpsnd_queue_write(s, tick, packet_index);                  /* Insert the 4 missing bytes retrieved from last RDPSND_WRITE */
231                    memcpy(s->data, missing_bytes, 4);
232    
233                    current_driver->
234                            wave_out_write(rdpsnd_dsp_process
235                                           (s, current_driver, &formats[current_format]), tick,
236                                           packet_index);
237                  awaiting_data_packet = False;                  awaiting_data_packet = False;
238                  return;                  return;
239          }          }
# Line 236  rdpsnd_process(STREAM s) Line 248  rdpsnd_process(STREAM s)
248                          in_uint16_le(s, tick);                          in_uint16_le(s, tick);
249                          in_uint16_le(s, format);                          in_uint16_le(s, format);
250                          in_uint8(s, packet_index);                          in_uint8(s, packet_index);
251                            /* Here are our lost bytes, but why? */
252                            memcpy(missing_bytes, s->end - 4, 4);
253                          awaiting_data_packet = True;                          awaiting_data_packet = True;
254                          break;                          break;
255                  case RDPSND_CLOSE:                  case RDPSND_CLOSE:
256                          wave_out_close();                          current_driver->wave_out_close();
257                          device_open = False;                          device_open = False;
258                          break;                          break;
259                  case RDPSND_NEGOTIATE:                  case RDPSND_NEGOTIATE:
# Line 252  rdpsnd_process(STREAM s) Line 266  rdpsnd_process(STREAM s)
266                          in_uint32(s, volume);                          in_uint32(s, volume);
267                          if (device_open)                          if (device_open)
268                          {                          {
269                                  wave_out_volume((volume & 0xffff), (volume & 0xffff0000) >> 16);                                  current_driver->wave_out_volume((volume & 0xffff),
270                                                                    (volume & 0xffff0000) >> 16);
271                          }                          }
272                          break;                          break;
273                  default:                  default:
# Line 262  rdpsnd_process(STREAM s) Line 277  rdpsnd_process(STREAM s)
277  }  }
278    
279  BOOL  BOOL
280  rdpsnd_init(void)  rdpsnd_auto_open(void)
281    {
282            static BOOL failed = False;
283    
284            if (!failed)
285            {
286                    struct audio_driver *auto_driver = current_driver;
287    
288                    current_driver = drivers;
289                    while (current_driver != NULL)
290                    {
291                            DEBUG(("trying %s...\n", current_driver->name));
292                            if (current_driver->wave_out_open())
293                            {
294                                    DEBUG(("selected %s\n", current_driver->name));
295                                    return True;
296                            }
297                            g_dsp_fd = 0;
298                            current_driver = current_driver->next;
299                    }
300    
301                    warning("no working audio-driver found\n");
302                    failed = True;
303                    current_driver = auto_driver;
304            }
305    
306            return False;
307    }
308    
309    void
310    rdpsnd_register_drivers(char *options)
311    {
312            struct audio_driver **reg;
313    
314            /* The order of registrations define the probe-order
315               when opening the device for the first time */
316            reg = &drivers;
317    #if defined(RDPSND_ALSA)
318            *reg = alsa_register(options);
319            reg = &((*reg)->next);
320    #endif
321    #if defined(RDPSND_SUN)
322            *reg = sun_register(options);
323            reg = &((*reg)->next);
324    #endif
325    #if defined(RDPSND_OSS)
326            *reg = oss_register(options);
327            reg = &((*reg)->next);
328    #endif
329    #if defined(RDPSND_SGI)
330            *reg = sgi_register(options);
331            reg = &((*reg)->next);
332    #endif
333    #if defined(RDPSND_LIBAO)
334            *reg = libao_register(options);
335            reg = &((*reg)->next);
336    #endif
337    }
338    
339    BOOL
340    rdpsnd_init(char *optarg)
341  {  {
342            static struct audio_driver auto_driver;
343            struct audio_driver *pos;
344            char *driver = NULL, *options = NULL;
345    
346            drivers = NULL;
347    
348          rdpsnd_channel =          rdpsnd_channel =
349                  channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,                  channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
350                                   rdpsnd_process);                                   rdpsnd_process);
351    
352          return (rdpsnd_channel != NULL);          if (rdpsnd_channel == NULL)
353            {
354                    error("channel_register\n");
355                    return False;
356            }
357    
358            if (optarg != NULL && strlen(optarg) > 0)
359            {
360                    driver = options = optarg;
361    
362                    while (*options != '\0' && *options != ':')
363                            options++;
364    
365                    if (*options == ':')
366                    {
367                            *options = '\0';
368                            options++;
369                    }
370    
371                    if (*options == '\0')
372                            options = NULL;
373            }
374    
375            rdpsnd_register_drivers(options);
376    
377            if (!driver)
378            {
379                    auto_driver.wave_out_open = &rdpsnd_auto_open;
380                    current_driver = &auto_driver;
381                    return True;
382            }
383    
384            pos = drivers;
385            while (pos != NULL)
386            {
387                    if (!strcmp(pos->name, driver))
388                    {
389                            DEBUG(("selected %s\n", pos->name));
390                            current_driver = pos;
391                            return True;
392                    }
393                    pos = pos->next;
394            }
395            return False;
396    }
397    
398    void
399    rdpsnd_show_help(void)
400    {
401            struct audio_driver *pos;
402    
403            rdpsnd_register_drivers(NULL);
404    
405            pos = drivers;
406            while (pos != NULL)
407            {
408                    fprintf(stderr, "                     %s:\t%s\n", pos->name, pos->description);
409                    pos = pos->next;
410            }
411    }
412    
413    inline void
414    rdpsnd_play(void)
415    {
416            current_driver->wave_out_play();
417  }  }
418    
419  void  void
# Line 288  rdpsnd_queue_write(STREAM s, uint16 tick Line 433  rdpsnd_queue_write(STREAM s, uint16 tick
433          packet->s = *s;          packet->s = *s;
434          packet->tick = tick;          packet->tick = tick;
435          packet->index = index;          packet->index = index;
         packet->s.p += 4;  
   
         /* we steal the data buffer from s, give it a new one */  
         s->data = malloc(s->size);  
436    
437          if (!g_dsp_busy)          if (!g_dsp_busy)
438                  wave_out_play();                  current_driver->wave_out_play();
439  }  }
440    
441  inline struct audio_packet *  inline struct audio_packet *
# Line 318  rdpsnd_queue_init(void) Line 459  rdpsnd_queue_init(void)
459  inline void  inline void
460  rdpsnd_queue_next(void)  rdpsnd_queue_next(void)
461  {  {
462          free(packet_queue[queue_lo].s.data);          xfree(packet_queue[queue_lo].s.data);
463          queue_lo = (queue_lo + 1) % MAX_QUEUE;          queue_lo = (queue_lo + 1) % MAX_QUEUE;
464  }  }
465    

Legend:
Removed from v.1254  
changed lines
  Added in v.1272

  ViewVC Help
Powered by ViewVC 1.1.26