/[rdesktop]/sourceforge.net/trunk/rdesktop/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/trunk/rdesktop/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 1258 by stargo, Sun Sep 17 14:41:16 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 205  rdpsnd_process(STREAM s) Line 210  rdpsnd_process(STREAM s)
210    
211                  if (!device_open || (format != current_format))                  if (!device_open || (format != current_format))
212                  {                  {
213                          if (!device_open && !wave_out_open())                          if (!device_open && !current_driver->wave_out_open())
214                          {                          {
215                                  rdpsnd_send_completion(tick, packet_index);                                  rdpsnd_send_completion(tick, packet_index);
216                                  return;                                  return;
217                          }                          }
218                          if (!wave_out_set_format(&formats[format]))                          if (!current_driver->wave_out_set_format(&formats[format]))
219                          {                          {
220                                  rdpsnd_send_completion(tick, packet_index);                                  rdpsnd_send_completion(tick, packet_index);
221                                  wave_out_close();                                  current_driver->wave_out_close();
222                                  device_open = False;                                  device_open = False;
223                                  return;                                  return;
224                          }                          }
# Line 221  rdpsnd_process(STREAM s) Line 226  rdpsnd_process(STREAM s)
226                          current_format = format;                          current_format = format;
227                  }                  }
228    
229                  rdpsnd_queue_write(s, tick, packet_index);                  current_driver->wave_out_write(s, tick, packet_index);
230                  awaiting_data_packet = False;                  awaiting_data_packet = False;
231                  return;                  return;
232          }          }
# Line 239  rdpsnd_process(STREAM s) Line 244  rdpsnd_process(STREAM s)
244                          awaiting_data_packet = True;                          awaiting_data_packet = True;
245                          break;                          break;
246                  case RDPSND_CLOSE:                  case RDPSND_CLOSE:
247                          wave_out_close();                          current_driver->wave_out_close();
248                          device_open = False;                          device_open = False;
249                          break;                          break;
250                  case RDPSND_NEGOTIATE:                  case RDPSND_NEGOTIATE:
# Line 252  rdpsnd_process(STREAM s) Line 257  rdpsnd_process(STREAM s)
257                          in_uint32(s, volume);                          in_uint32(s, volume);
258                          if (device_open)                          if (device_open)
259                          {                          {
260                                  wave_out_volume((volume & 0xffff), (volume & 0xffff0000) >> 16);                                  current_driver->wave_out_volume((volume & 0xffff),
261                                                                    (volume & 0xffff0000) >> 16);
262                          }                          }
263                          break;                          break;
264                  default:                  default:
# Line 271  rdpsnd_init(void) Line 277  rdpsnd_init(void)
277          return (rdpsnd_channel != NULL);          return (rdpsnd_channel != NULL);
278  }  }
279    
280    BOOL
281    rdpsnd_auto_open(void)
282    {
283            current_driver = drivers;
284            while (current_driver != NULL)
285            {
286                    DEBUG(("trying %s...\n", current_driver->name));
287                    if (current_driver->wave_out_open())
288                    {
289                            DEBUG(("selected %s\n", current_driver->name));
290                            return True;
291                    }
292                    g_dsp_fd = 0;
293                    current_driver = current_driver->next;
294            }
295    
296            warning("no working audio-driver found\n");
297    
298            return False;
299    }
300    
301    void
302    rdpsnd_register_drivers(char *options)
303    {
304            struct audio_driver **reg;
305    
306            /* The order of registrations define the probe-order
307               when opening the device for the first time */
308            reg = &drivers;
309    #if defined(RDPSND_ALSA)
310            *reg = alsa_register(options);
311            reg = &((*reg)->next);
312    #endif
313    #if defined(RDPSND_OSS)
314            *reg = oss_register(options);
315            reg = &((*reg)->next);
316    #endif
317    #if defined(RDPSND_SUN)
318            *reg = sun_register(options);
319            reg = &((*reg)->next);
320    #endif
321    #if defined(RDPSND_SGI)
322            *reg = sgi_register(options);
323            reg = &((*reg)->next);
324    #endif
325    #if defined(RDPSND_LIBAO)
326            *reg = libao_register(options);
327            reg = &((*reg)->next);
328    #endif
329    }
330    
331    BOOL
332    rdpsnd_select_driver(char *driver, char *options)
333    {
334            static struct audio_driver auto_driver;
335            struct audio_driver *pos;
336    
337            drivers = NULL;
338            rdpsnd_register_drivers(options);
339    
340            if (!driver)
341            {
342                    auto_driver.wave_out_open = &rdpsnd_auto_open;
343                    current_driver = &auto_driver;
344                    return True;
345            }
346    
347            pos = drivers;
348            while (pos != NULL)
349            {
350                    if (!strcmp(pos->name, driver))
351                    {
352                            DEBUG(("selected %s\n", pos->name));
353                            current_driver = pos;
354                            return True;
355                    }
356                    pos = pos->next;
357            }
358            return False;
359    }
360    
361    void
362    rdpsnd_show_help(void)
363    {
364            struct audio_driver *pos;
365    
366            rdpsnd_register_drivers(NULL);
367    
368            pos = drivers;
369            while (pos != NULL)
370            {
371                    fprintf(stderr, "                     %s:\t%s\n", pos->name, pos->description);
372                    pos = pos->next;
373            }
374    }
375    
376    inline void
377    rdpsnd_play(void)
378    {
379            current_driver->wave_out_play();
380    }
381    
382  void  void
383  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)
384  {  {
# Line 286  rdpsnd_queue_write(STREAM s, uint16 tick Line 394  rdpsnd_queue_write(STREAM s, uint16 tick
394          queue_hi = next_hi;          queue_hi = next_hi;
395    
396          packet->s = *s;          packet->s = *s;
397            packet->s.data =
398                    rdpsnd_dsp_process(s->data, s->size, current_driver, &formats[current_format]);
399            packet->s.p = packet->s.data + 4;
400            packet->s.end = packet->s.data + s->size;
401          packet->tick = tick;          packet->tick = tick;
402          packet->index = index;          packet->index = index;
         packet->s.p += 4;  
403    
404    #if 0                           /* Handled by DSP */
405          /* we steal the data buffer from s, give it a new one */          /* we steal the data buffer from s, give it a new one */
406          s->data = malloc(s->size);          s->data = xmalloc(s->size);
407    #endif
408    
409          if (!g_dsp_busy)          if (!g_dsp_busy)
410                  wave_out_play();                  current_driver->wave_out_play();
411  }  }
412    
413  inline struct audio_packet *  inline struct audio_packet *
# Line 318  rdpsnd_queue_init(void) Line 431  rdpsnd_queue_init(void)
431  inline void  inline void
432  rdpsnd_queue_next(void)  rdpsnd_queue_next(void)
433  {  {
434          free(packet_queue[queue_lo].s.data);          xfree(packet_queue[queue_lo].s.data);
435          queue_lo = (queue_lo + 1) % MAX_QUEUE;          queue_lo = (queue_lo + 1) % MAX_QUEUE;
436  }  }
437    

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

  ViewVC Help
Powered by ViewVC 1.1.26