/[rdesktop]/jpeg/rdesktop/trunk/rdpsnd_libao.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 /jpeg/rdesktop/trunk/rdpsnd_libao.c

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

revision 1290 by stargo, Sun Oct 1 22:30:34 2006 UTC revision 1475 by jsorg71, Fri Jul 11 03:51:23 2008 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Sound Channel Process Functions - libao-driver     Sound Channel Process Functions - libao-driver
4     Copyright (C) Matthew Chapman 2003     Copyright (C) Matthew Chapman 2003-2008
5     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
6     Copyright (C) Michael Gernoth mike@zerfleddert.de 2005-2006     Copyright (C) Michael Gernoth mike@zerfleddert.de 2005-2008
7    
8     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 29  Line 29 
29  #include <ao/ao.h>  #include <ao/ao.h>
30  #include <sys/time.h>  #include <sys/time.h>
31    
32  #define WAVEOUTLEN      1024  #define WAVEOUTLEN      16
33    
34  static ao_device *o_device = NULL;  static ao_device *o_device = NULL;
35  static int default_driver;  static int default_driver;
36  static BOOL reopened;  static RD_BOOL reopened;
37  static char *libao_device = NULL;  static char *libao_device = NULL;
38    
39  BOOL  void libao_play(void);
40    
41    void
42    libao_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv)
43    {
44            /* We need to be called rather often... */
45            if (o_device != NULL && !rdpsnd_queue_empty())
46                    FD_SET(0, wfds);
47    }
48    
49    void
50    libao_check_fds(fd_set * rfds, fd_set * wfds)
51    {
52            if (o_device == NULL)
53                    return;
54    
55            if (!rdpsnd_queue_empty())
56                    libao_play();
57    }
58    
59    RD_BOOL
60  libao_open(void)  libao_open(void)
61  {  {
62          ao_sample_format format;          ao_sample_format format;
# Line 64  libao_open(void) Line 84  libao_open(void)
84                  return False;                  return False;
85          }          }
86    
         g_dsp_fd = 0;  
         rdpsnd_queue_init();  
   
87          reopened = True;          reopened = True;
88    
89          return True;          return True;
# Line 78  libao_close(void) Line 95  libao_close(void)
95          /* Ack all remaining packets */          /* Ack all remaining packets */
96          while (!rdpsnd_queue_empty())          while (!rdpsnd_queue_empty())
97          {          {
98                  rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick,                  rdpsnd_queue_next(0);
                                        rdpsnd_queue_current_packet()->index);  
                 rdpsnd_queue_next();  
99          }          }
100    
101          if (o_device != NULL)          if (o_device != NULL)
102                  ao_close(o_device);                  ao_close(o_device);
103    
104            o_device = NULL;
105    
106          ao_shutdown();          ao_shutdown();
107  }  }
108    
109  BOOL  RD_BOOL
110  libao_set_format(WAVEFORMATEX * pwfx)  libao_set_format(RD_WAVEFORMATEX * pwfx)
111  {  {
112          ao_sample_format format;          ao_sample_format format;
113    
# Line 137  libao_play(void) Line 154  libao_play(void)
154                  prev_us = tv.tv_usec;                  prev_us = tv.tv_usec;
155          }          }
156    
157            /* We shouldn't be called if the queue is empty, but still */
158          if (rdpsnd_queue_empty())          if (rdpsnd_queue_empty())
         {  
                 g_dsp_busy = 0;  
159                  return;                  return;
         }  
160    
161          packet = rdpsnd_queue_current_packet();          packet = rdpsnd_queue_current_packet();
162          out = &packet->s;          out = &packet->s;
# Line 161  libao_play(void) Line 176  libao_play(void)
176    
177          if ((out->p == out->end) || duration > next_tick - packet->tick + 500)          if ((out->p == out->end) || duration > next_tick - packet->tick + 500)
178          {          {
179                    unsigned int delay_us;
180    
181                  prev_s = tv.tv_sec;                  prev_s = tv.tv_sec;
182                  prev_us = tv.tv_usec;                  prev_us = tv.tv_usec;
183    
# Line 171  libao_play(void) Line 188  libao_play(void)
188                                 (packet->tick + duration) % 65536, next_tick % 65536));                                 (packet->tick + duration) % 65536, next_tick % 65536));
189                  }                  }
190    
191                  rdpsnd_send_completion(((packet->tick + duration) % 65536), packet->index);                  delay_us = ((out->size / 4) * (1000000 / 44100));
                 rdpsnd_queue_next();  
         }  
192    
193          g_dsp_busy = 1;                  rdpsnd_queue_next(delay_us);
194          return;          }
195  }  }
196    
197  struct audio_driver *  struct audio_driver *
198  libao_register(char *options)  libao_register(char *options)
199  {  {
200          static struct audio_driver libao_driver;          static struct audio_driver libao_driver;
         struct ao_info *libao_info;  
         static char description[101];  
201    
202          libao_driver.wave_out_write = rdpsnd_queue_write;          memset(&libao_driver, 0, sizeof(libao_driver));
203    
204            libao_driver.name = "libao";
205            libao_driver.description = "libao output driver, default device: system dependent";
206    
207            libao_driver.add_fds = libao_add_fds;
208            libao_driver.check_fds = libao_check_fds;
209    
210          libao_driver.wave_out_open = libao_open;          libao_driver.wave_out_open = libao_open;
211          libao_driver.wave_out_close = libao_close;          libao_driver.wave_out_close = libao_close;
212          libao_driver.wave_out_format_supported = rdpsnd_dsp_resample_supported;          libao_driver.wave_out_format_supported = rdpsnd_dsp_resample_supported;
213          libao_driver.wave_out_set_format = libao_set_format;          libao_driver.wave_out_set_format = libao_set_format;
214          libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set;          libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set;
215          libao_driver.wave_out_play = libao_play;  
         libao_driver.name = xstrdup("libao");  
         libao_driver.description = description;  
216          libao_driver.need_byteswap_on_be = 1;          libao_driver.need_byteswap_on_be = 1;
217          libao_driver.need_resampling = 1;          libao_driver.need_resampling = 1;
         libao_driver.next = NULL;  
   
         ao_initialize();  
   
         libao_info = ao_driver_info(ao_default_driver_id());  
   
         if (libao_info)  
         {  
                 snprintf(description, 100, "libao output driver, default device: %s",  
                          libao_info->short_name);  
         }  
         else  
         {  
                 snprintf(description, 100, "libao output driver, default device: none");  
         }  
   
         ao_shutdown();  
218    
219          if (options)          if (options)
220          {          {

Legend:
Removed from v.1290  
changed lines
  Added in v.1475

  ViewVC Help
Powered by ViewVC 1.1.26