/[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 1255 by stargo, Sun Sep 17 11:04:50 2006 UTC
# Line 37  BOOL g_dsp_busy = False; Line 37  BOOL g_dsp_busy = False;
37  int g_dsp_fd;  int g_dsp_fd;
38    
39  static VCHANNEL *rdpsnd_channel;  static VCHANNEL *rdpsnd_channel;
40    static struct audio_driver *drivers = NULL;
41    static struct audio_driver *current_driver = NULL;
42    
43  static BOOL device_open;  static BOOL device_open;
44  static WAVEFORMATEX formats[MAX_FORMATS];  static WAVEFORMATEX formats[MAX_FORMATS];
# Line 45  static unsigned int current_format; Line 47  static unsigned int current_format;
47  static unsigned int queue_hi, queue_lo;  static unsigned int queue_hi, queue_lo;
48  static struct audio_packet packet_queue[MAX_QUEUE];  static struct audio_packet packet_queue[MAX_QUEUE];
49    
50    void (*wave_out_play) (void);
51    
52  static STREAM  static STREAM
53  rdpsnd_init_packet(uint16 type, uint16 size)  rdpsnd_init_packet(uint16 type, uint16 size)
54  {  {
# Line 94  rdpsnd_process_negotiate(STREAM in) Line 98  rdpsnd_process_negotiate(STREAM in)
98          in_uint16_le(in, in_format_count);          in_uint16_le(in, in_format_count);
99          in_uint8s(in, 4);       /* pad, status, pad */          in_uint8s(in, 4);       /* pad, status, pad */
100    
101          if (wave_out_open())          if (current_driver->wave_out_open())
102          {          {
103                  wave_out_close();                  current_driver->wave_out_close();
104                  device_available = True;                  device_available = True;
105          }          }
106    
# Line 127  rdpsnd_process_negotiate(STREAM in) Line 131  rdpsnd_process_negotiate(STREAM in)
131                          in_uint8a(in, format->cb, readcnt);                          in_uint8a(in, format->cb, readcnt);
132                          in_uint8s(in, discardcnt);                          in_uint8s(in, discardcnt);
133    
134                          if (device_available && wave_out_format_supported(format))                          if (device_available && current_driver->wave_out_format_supported(format))
135                          {                          {
136                                  format_count++;                                  format_count++;
137                                  if (format_count == MAX_FORMATS)                                  if (format_count == MAX_FORMATS)
# Line 205  rdpsnd_process(STREAM s) Line 209  rdpsnd_process(STREAM s)
209    
210                  if (!device_open || (format != current_format))                  if (!device_open || (format != current_format))
211                  {                  {
212                          if (!device_open && !wave_out_open())                          if (!device_open && !current_driver->wave_out_open())
213                          {                          {
214                                  rdpsnd_send_completion(tick, packet_index);                                  rdpsnd_send_completion(tick, packet_index);
215                                  return;                                  return;
216                          }                          }
217                          if (!wave_out_set_format(&formats[format]))                          if (!current_driver->wave_out_set_format(&formats[format]))
218                          {                          {
219                                  rdpsnd_send_completion(tick, packet_index);                                  rdpsnd_send_completion(tick, packet_index);
220                                  wave_out_close();                                  current_driver->wave_out_close();
221                                  device_open = False;                                  device_open = False;
222                                  return;                                  return;
223                          }                          }
# Line 221  rdpsnd_process(STREAM s) Line 225  rdpsnd_process(STREAM s)
225                          current_format = format;                          current_format = format;
226                  }                  }
227    
228                  rdpsnd_queue_write(s, tick, packet_index);                  current_driver->wave_out_write(s, tick, packet_index);
229                  awaiting_data_packet = False;                  awaiting_data_packet = False;
230                  return;                  return;
231          }          }
# Line 239  rdpsnd_process(STREAM s) Line 243  rdpsnd_process(STREAM s)
243                          awaiting_data_packet = True;                          awaiting_data_packet = True;
244                          break;                          break;
245                  case RDPSND_CLOSE:                  case RDPSND_CLOSE:
246                          wave_out_close();                          current_driver->wave_out_close();
247                          device_open = False;                          device_open = False;
248                          break;                          break;
249                  case RDPSND_NEGOTIATE:                  case RDPSND_NEGOTIATE:
# Line 252  rdpsnd_process(STREAM s) Line 256  rdpsnd_process(STREAM s)
256                          in_uint32(s, volume);                          in_uint32(s, volume);
257                          if (device_open)                          if (device_open)
258                          {                          {
259                                  wave_out_volume((volume & 0xffff), (volume & 0xffff0000) >> 16);                                  current_driver->wave_out_volume((volume & 0xffff),
260                                                                    (volume & 0xffff0000) >> 16);
261                          }                          }
262                          break;                          break;
263                  default:                  default:
# Line 271  rdpsnd_init(void) Line 276  rdpsnd_init(void)
276          return (rdpsnd_channel != NULL);          return (rdpsnd_channel != NULL);
277  }  }
278    
279    BOOL
280    rdpsnd_auto_open(void)
281    {
282            current_driver = drivers;
283            while (current_driver != NULL)
284            {
285                    DEBUG(("trying %s...\n", current_driver->name));
286                    if (current_driver->wave_out_open())
287                    {
288                            DEBUG(("selected %s\n", current_driver->name));
289                            return True;
290                    }
291                    g_dsp_fd = 0;
292                    current_driver = current_driver->next;
293            }
294    
295            warning("no working audio-driver found\n");
296    
297            return False;
298    }
299    
300    void
301    rdpsnd_register_drivers(char *options)
302    {
303            struct audio_driver **reg;
304    
305            /* The order of registrations define the probe-order
306               when opening the device for the first time */
307            reg = &drivers;
308    #if defined(RDPSND_ALSA)
309            *reg = alsa_register(options);
310            reg = &((*reg)->next);
311    #endif
312    #if defined(RDPSND_OSS)
313            *reg = oss_register(options);
314            reg = &((*reg)->next);
315    #endif
316    #if defined(RDPSND_SUN)
317            *reg = sun_register(options);
318            reg = &((*reg)->next);
319    #endif
320    #if defined(RDPSND_SGI)
321            *reg = sgi_register(options);
322            reg = &((*reg)->next);
323    #endif
324    #if defined(RDPSND_LIBAO)
325            *reg = libao_register(options);
326            reg = &((*reg)->next);
327    #endif
328    }
329    
330    BOOL
331    rdpsnd_select_driver(char *driver, char *options)
332    {
333            static struct audio_driver auto_driver;
334            struct audio_driver *pos;
335    
336            drivers = NULL;
337            rdpsnd_register_drivers(options);
338    
339            if (!driver)
340            {
341                    auto_driver.wave_out_open = &rdpsnd_auto_open;
342                    current_driver = &auto_driver;
343                    return True;
344            }
345    
346            pos = drivers;
347            while (pos != NULL)
348            {
349                    if (!strcmp(pos->name, driver))
350                    {
351                            DEBUG(("selected %s\n", pos->name));
352                            current_driver = pos;
353                            return True;
354                    }
355                    pos = pos->next;
356            }
357            return False;
358    }
359    
360    void
361    rdpsnd_show_help(void)
362    {
363            struct audio_driver *pos;
364    
365            rdpsnd_register_drivers(NULL);
366    
367            pos = drivers;
368            while (pos != NULL)
369            {
370                    fprintf(stderr, "                     %s:\t%s\n", pos->name, pos->description);
371                    pos = pos->next;
372            }
373    }
374    
375    inline void
376    rdpsnd_play(void)
377    {
378            current_driver->wave_out_play();
379    }
380    
381  void  void
382  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)
383  {  {
# Line 294  rdpsnd_queue_write(STREAM s, uint16 tick Line 401  rdpsnd_queue_write(STREAM s, uint16 tick
401          s->data = malloc(s->size);          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 *

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

  ViewVC Help
Powered by ViewVC 1.1.26