/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpsnd_oss.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_oss.c

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

revision 1247 by stargo, Wed Jul 12 09:57:05 2006 UTC revision 1260 by stargo, Sun Sep 17 15:25:10 2006 UTC
# Line 28  Line 28 
28  #endif  #endif
29    
30  #include "rdesktop.h"  #include "rdesktop.h"
31    #include "rdpsnd.h"
32  #include <unistd.h>  #include <unistd.h>
33  #include <fcntl.h>  #include <fcntl.h>
34  #include <errno.h>  #include <errno.h>
# Line 35  Line 36 
36  #include <sys/ioctl.h>  #include <sys/ioctl.h>
37  #include <sys/soundcard.h>  #include <sys/soundcard.h>
38    
39    #define DEFAULTDEVICE   "/dev/dsp"
40  #define MAX_LEN         512  #define MAX_LEN         512
 #define MAX_QUEUE       10  
41    
 int g_dsp_fd;  
 BOOL g_dsp_busy = False;  
42  static int snd_rate;  static int snd_rate;
43  static short samplewidth;  static short samplewidth;
44    static char *dsp_dev;
 static struct audio_packet  
 {  
         struct stream s;  
         uint16 tick;  
         uint8 index;  
 } packet_queue[MAX_QUEUE];  
 static unsigned int queue_hi, queue_lo;  
45    
46  BOOL  BOOL
47  wave_out_open(void)  oss_open(void)
48  {  {
         char *dsp_dev = getenv("AUDIODEV");  
   
         if (dsp_dev == NULL)  
         {  
                 dsp_dev = xstrdup("/dev/dsp");  
         }  
   
49          if ((g_dsp_fd = open(dsp_dev, O_WRONLY)) == -1)          if ((g_dsp_fd = open(dsp_dev, O_WRONLY)) == -1)
50          {          {
51                  perror(dsp_dev);                  perror(dsp_dev);
# Line 71  wave_out_open(void) Line 56  wave_out_open(void)
56  }  }
57    
58  void  void
59  wave_out_close(void)  oss_close(void)
60  {  {
61          close(g_dsp_fd);          close(g_dsp_fd);
62  }  }
63    
64  BOOL  BOOL
65  wave_out_format_supported(WAVEFORMATEX * pwfx)  oss_format_supported(WAVEFORMATEX * pwfx)
66  {  {
67          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
68                  return False;                  return False;
# Line 90  wave_out_format_supported(WAVEFORMATEX * Line 75  wave_out_format_supported(WAVEFORMATEX *
75  }  }
76    
77  BOOL  BOOL
78  wave_out_set_format(WAVEFORMATEX * pwfx)  oss_set_format(WAVEFORMATEX * pwfx)
79  {  {
80          int stereo, format, fragments;          int stereo, format, fragments;
81          static BOOL driver_broken = False;          static BOOL driver_broken = False;
# Line 166  wave_out_set_format(WAVEFORMATEX * pwfx) Line 151  wave_out_set_format(WAVEFORMATEX * pwfx)
151  }  }
152    
153  void  void
154  wave_out_volume(uint16 left, uint16 right)  oss_volume(uint16 left, uint16 right)
155  {  {
156          static BOOL use_dev_mixer = False;          static BOOL use_dev_mixer = False;
157          uint32 volume;          uint32 volume;
# Line 201  wave_out_volume(uint16 left, uint16 righ Line 186  wave_out_volume(uint16 left, uint16 righ
186  }  }
187    
188  void  void
189  wave_out_write(STREAM s, uint16 tick, uint8 index)  oss_play(void)
 {  
         struct audio_packet *packet = &packet_queue[queue_hi];  
         unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE;  
   
         if (next_hi == queue_lo)  
         {  
                 error("No space to queue audio packet\n");  
                 return;  
         }  
   
         queue_hi = next_hi;  
   
         packet->s = *s;  
         packet->tick = tick;  
         packet->index = index;  
         packet->s.p += 4;  
   
         /* we steal the data buffer from s, give it a new one */  
         s->data = (uint8 *) malloc(s->size);  
   
         if (!g_dsp_busy)  
                 wave_out_play();  
 }  
   
 void  
 wave_out_play(void)  
190  {  {
191          struct audio_packet *packet;          struct audio_packet *packet;
192          ssize_t len;          ssize_t len;
# Line 237  wave_out_play(void) Line 196  wave_out_play(void)
196          static BOOL started = False;          static BOOL started = False;
197          struct timeval tv;          struct timeval tv;
198    
199          if (queue_lo == queue_hi)          if (rdpsnd_queue_empty())
200          {          {
201                  g_dsp_busy = 0;                  g_dsp_busy = 0;
202                  return;                  return;
203          }          }
204    
205          packet = &packet_queue[queue_lo];          packet = rdpsnd_queue_current_packet();
206          out = &packet->s;          out = &packet->s;
207    
208          if (!started)          if (!started)
# Line 277  wave_out_play(void) Line 236  wave_out_play(void)
236    
237                  if (elapsed >= (duration * 85) / 100)                  if (elapsed >= (duration * 85) / 100)
238                  {                  {
239                          rdpsnd_send_completion(packet->tick, packet->index);                          /* We need to add 50 to tell windows that time has passed while
240                          free(out->data);                           * playing this packet */
241                          queue_lo = (queue_lo + 1) % MAX_QUEUE;                          rdpsnd_send_completion(packet->tick + 50, packet->index);
242                            rdpsnd_queue_next();
243                          started = False;                          started = False;
244                  }                  }
245                  else                  else
# Line 291  wave_out_play(void) Line 251  wave_out_play(void)
251          g_dsp_busy = 1;          g_dsp_busy = 1;
252          return;          return;
253  }  }
254    
255    struct audio_driver *
256    oss_register(char *options)
257    {
258            static struct audio_driver oss_driver;
259    
260            oss_driver.wave_out_write = rdpsnd_queue_write;
261            oss_driver.wave_out_open = oss_open;
262            oss_driver.wave_out_close = oss_close;
263            oss_driver.wave_out_format_supported = oss_format_supported;
264            oss_driver.wave_out_set_format = oss_set_format;
265            oss_driver.wave_out_volume = oss_volume;
266            oss_driver.wave_out_play = oss_play;
267            oss_driver.name = xstrdup("oss");
268            oss_driver.description =
269                    xstrdup("OSS output driver, default device: " DEFAULTDEVICE " or $AUDIODEV");
270            oss_driver.need_byteswap_on_be = 0;
271            oss_driver.next = NULL;
272    
273            if (options)
274            {
275                    dsp_dev = xstrdup(options);
276            }
277            else
278            {
279                    dsp_dev = getenv("AUDIODEV");
280    
281                    if (dsp_dev == NULL)
282                    {
283                            dsp_dev = xstrdup(DEFAULTDEVICE);
284                    }
285            }
286    
287            return &oss_driver;
288    }

Legend:
Removed from v.1247  
changed lines
  Added in v.1260

  ViewVC Help
Powered by ViewVC 1.1.26