/[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 1263 by stargo, Sun Sep 17 18:08:51 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->
230                            wave_out_write(rdpsnd_dsp_process
231                                           (s, current_driver, &formats[current_format]), tick,
232                                           packet_index);
233                  awaiting_data_packet = False;                  awaiting_data_packet = False;
234                  return;                  return;
235          }          }
# Line 239  rdpsnd_process(STREAM s) Line 247  rdpsnd_process(STREAM s)
247                          awaiting_data_packet = True;                          awaiting_data_packet = True;
248                          break;                          break;
249                  case RDPSND_CLOSE:                  case RDPSND_CLOSE:
250                          wave_out_close();                          current_driver->wave_out_close();
251                          device_open = False;                          device_open = False;
252                          break;                          break;
253                  case RDPSND_NEGOTIATE:                  case RDPSND_NEGOTIATE:
# Line 252  rdpsnd_process(STREAM s) Line 260  rdpsnd_process(STREAM s)
260                          in_uint32(s, volume);                          in_uint32(s, volume);
261                          if (device_open)                          if (device_open)
262                          {                          {
263                                  wave_out_volume((volume & 0xffff), (volume & 0xffff0000) >> 16);                                  current_driver->wave_out_volume((volume & 0xffff),
264                                                                    (volume & 0xffff0000) >> 16);
265                          }                          }
266                          break;                          break;
267                  default:                  default:
# Line 271  rdpsnd_init(void) Line 280  rdpsnd_init(void)
280          return (rdpsnd_channel != NULL);          return (rdpsnd_channel != NULL);
281  }  }
282    
283    BOOL
284    rdpsnd_auto_open(void)
285    {
286            current_driver = drivers;
287            while (current_driver != NULL)
288            {
289                    DEBUG(("trying %s...\n", current_driver->name));
290                    if (current_driver->wave_out_open())
291                    {
292                            DEBUG(("selected %s\n", current_driver->name));
293                            return True;
294                    }
295                    g_dsp_fd = 0;
296                    current_driver = current_driver->next;
297            }
298    
299            warning("no working audio-driver found\n");
300    
301            return False;
302    }
303    
304    void
305    rdpsnd_register_drivers(char *options)
306    {
307            struct audio_driver **reg;
308    
309            /* The order of registrations define the probe-order
310               when opening the device for the first time */
311            reg = &drivers;
312    #if defined(RDPSND_ALSA)
313            *reg = alsa_register(options);
314            reg = &((*reg)->next);
315    #endif
316    #if defined(RDPSND_OSS)
317            *reg = oss_register(options);
318            reg = &((*reg)->next);
319    #endif
320    #if defined(RDPSND_SUN)
321            *reg = sun_register(options);
322            reg = &((*reg)->next);
323    #endif
324    #if defined(RDPSND_SGI)
325            *reg = sgi_register(options);
326            reg = &((*reg)->next);
327    #endif
328    #if defined(RDPSND_LIBAO)
329            *reg = libao_register(options);
330            reg = &((*reg)->next);
331    #endif
332    }
333    
334    BOOL
335    rdpsnd_select_driver(char *driver, char *options)
336    {
337            static struct audio_driver auto_driver;
338            struct audio_driver *pos;
339    
340            drivers = NULL;
341            rdpsnd_register_drivers(options);
342    
343            if (!driver)
344            {
345                    auto_driver.wave_out_open = &rdpsnd_auto_open;
346                    current_driver = &auto_driver;
347                    return True;
348            }
349    
350            pos = drivers;
351            while (pos != NULL)
352            {
353                    if (!strcmp(pos->name, driver))
354                    {
355                            DEBUG(("selected %s\n", pos->name));
356                            current_driver = pos;
357                            return True;
358                    }
359                    pos = pos->next;
360            }
361            return False;
362    }
363    
364    void
365    rdpsnd_show_help(void)
366    {
367            struct audio_driver *pos;
368    
369            rdpsnd_register_drivers(NULL);
370    
371            pos = drivers;
372            while (pos != NULL)
373            {
374                    fprintf(stderr, "                     %s:\t%s\n", pos->name, pos->description);
375                    pos = pos->next;
376            }
377    }
378    
379    inline void
380    rdpsnd_play(void)
381    {
382            current_driver->wave_out_play();
383    }
384    
385  void  void
386  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)
387  {  {
# Line 288  rdpsnd_queue_write(STREAM s, uint16 tick Line 399  rdpsnd_queue_write(STREAM s, uint16 tick
399          packet->s = *s;          packet->s = *s;
400          packet->tick = tick;          packet->tick = tick;
401          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);  
402    
403          if (!g_dsp_busy)          if (!g_dsp_busy)
404                  wave_out_play();                  current_driver->wave_out_play();
405  }  }
406    
407  inline struct audio_packet *  inline struct audio_packet *
# Line 318  rdpsnd_queue_init(void) Line 425  rdpsnd_queue_init(void)
425  inline void  inline void
426  rdpsnd_queue_next(void)  rdpsnd_queue_next(void)
427  {  {
428          free(packet_queue[queue_lo].s.data);          xfree(packet_queue[queue_lo].s.data);
429          queue_lo = (queue_lo + 1) % MAX_QUEUE;          queue_lo = (queue_lo + 1) % MAX_QUEUE;
430  }  }
431    

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

  ViewVC Help
Powered by ViewVC 1.1.26