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

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

revision 559 by stargo, Thu Dec 11 12:25:38 2003 UTC revision 1255 by stargo, Sun Sep 17 11:04:50 2006 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Sound Channel Process Functions - Sun     Sound Channel Process Functions - Sun
4     Copyright (C) Matthew Chapman 2003     Copyright (C) Matthew Chapman 2003
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 2003     Copyright (C) Michael Gernoth mike@zerfleddert.de 2003-2006
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 21  Line 21 
21  */  */
22    
23  #include "rdesktop.h"  #include "rdesktop.h"
24    #include "rdpsnd.h"
25  #include <unistd.h>  #include <unistd.h>
26  #include <fcntl.h>  #include <fcntl.h>
27  #include <errno.h>  #include <errno.h>
28  #include <sys/ioctl.h>  #include <sys/ioctl.h>
29  #include <sys/audioio.h>  #include <sys/audioio.h>
30    
31  #define MAX_QUEUE       10  #if (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
32    #include <stropts.h>
33    #endif
34    
35    #define DEFAULTDEVICE   "/dev/audio"
36    
 int g_dsp_fd;  
 BOOL g_dsp_busy = False;  
37  static BOOL g_reopened;  static BOOL g_reopened;
38  static BOOL g_swapaudio;  static BOOL g_swapaudio;
39  static short g_samplewidth;  static short g_samplewidth;
40    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;  
41    
42  BOOL  BOOL
43  wave_out_open(void)  sun_open(void)
44  {  {
         char *dsp_dev = getenv("AUDIODEV");  
   
         if (dsp_dev == NULL)  
         {  
                 dsp_dev = "/dev/audio";  
         }  
   
45          if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1)          if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1)
46          {          {
47                  perror(dsp_dev);                  perror(dsp_dev);
# Line 62  wave_out_open(void) Line 51  wave_out_open(void)
51          /* Non-blocking so that user interface is responsive */          /* Non-blocking so that user interface is responsive */
52          fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK);          fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK);
53    
54          queue_lo = queue_hi = 0;          rdpsnd_queue_init();
55          g_reopened = True;          g_reopened = True;
56    
57          return True;          return True;
58  }  }
59    
60  void  void
61  wave_out_close(void)  sun_close(void)
62  {  {
63          /* Ack all remaining packets */          /* Ack all remaining packets */
64          while (queue_lo != queue_hi)          while (!rdpsnd_queue_empty())
65          {          {
66                  rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);                  rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick,
67                  free(packet_queue[queue_lo].s.data);                                         rdpsnd_queue_current_packet()->index);
68                  queue_lo = (queue_lo + 1) % MAX_QUEUE;                  rdpsnd_queue_next();
69          }          }
70    
71  #if defined I_FLUSH && defined FLUSHW  #if defined I_FLUSH && defined FLUSHW
72          /* Flush the audiobuffer */          /* Flush the audiobuffer */
73          ioctl(g_dsp_fd, I_FLUSH, FLUSHW);          ioctl(g_dsp_fd, I_FLUSH, FLUSHW);
74  #endif  #endif
75    #if defined AUDIO_FLUSH
76            ioctl(g_dsp_fd, AUDIO_FLUSH, NULL);
77    #endif
78          close(g_dsp_fd);          close(g_dsp_fd);
79  }  }
80    
81  BOOL  BOOL
82  wave_out_format_supported(WAVEFORMATEX * pwfx)  sun_format_supported(WAVEFORMATEX * pwfx)
83  {  {
84          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
85                  return False;                  return False;
# Line 100  wave_out_format_supported(WAVEFORMATEX * Line 92  wave_out_format_supported(WAVEFORMATEX *
92  }  }
93    
94  BOOL  BOOL
95  wave_out_set_format(WAVEFORMATEX * pwfx)  sun_set_format(WAVEFORMATEX * pwfx)
96  {  {
97          audio_info_t info;          audio_info_t info;
         int test = 1;  
98    
99          ioctl(g_dsp_fd, AUDIO_DRAIN, 0);          ioctl(g_dsp_fd, AUDIO_DRAIN, 0);
100          g_swapaudio = False;          g_swapaudio = False;
# Line 118  wave_out_set_format(WAVEFORMATEX * pwfx) Line 109  wave_out_set_format(WAVEFORMATEX * pwfx)
109          {          {
110                  info.play.encoding = AUDIO_ENCODING_LINEAR;                  info.play.encoding = AUDIO_ENCODING_LINEAR;
111                  /* Do we need to swap the 16bit values? (Are we BigEndian) */                  /* Do we need to swap the 16bit values? (Are we BigEndian) */
112                  g_swapaudio = !(*(uint8 *) (&test));  #ifdef B_ENDIAN
113                    g_swapaudio = 1;
114    #else
115                    g_swapaudio = 0;
116    #endif
117          }          }
118    
119          g_samplewidth = pwfx->wBitsPerSample / 8;          g_samplewidth = pwfx->wBitsPerSample / 8;
# Line 151  wave_out_set_format(WAVEFORMATEX * pwfx) Line 146  wave_out_set_format(WAVEFORMATEX * pwfx)
146  }  }
147    
148  void  void
149  wave_out_volume(uint16 left, uint16 right)  sun_volume(uint16 left, uint16 right)
150  {  {
151          audio_info_t info;          audio_info_t info;
152          uint balance;          uint balance;
153          uint volume;          uint volume;
154    
155          if (ioctl(g_dsp_fd, AUDIO_GETINFO, &info) == -1)          AUDIO_INITINFO(&info);
         {  
                 perror("AUDIO_GETINFO");  
                 return;  
         }  
156    
157          volume = (left > right) ? left : right;          volume = (left > right) ? left : right;
158    
# Line 187  wave_out_volume(uint16 left, uint16 righ Line 178  wave_out_volume(uint16 left, uint16 righ
178  }  }
179    
180  void  void
181  wave_out_write(STREAM s, uint16 tick, uint8 index)  sun_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 = malloc(s->size);  
   
         if (!g_dsp_busy)  
                 wave_out_play();  
 }  
   
 void  
 wave_out_play(void)  
182  {  {
183          struct audio_packet *packet;          struct audio_packet *packet;
184          audio_info_t info;          audio_info_t info;
# Line 237  wave_out_play(void) Line 202  wave_out_play(void)
202                          g_reopened = False;                          g_reopened = False;
203                  }                  }
204    
205                  if (queue_lo == queue_hi)                  if (rdpsnd_queue_empty())
206                  {                  {
207                          g_dsp_busy = 0;                          g_dsp_busy = 0;
208                          return;                          return;
209                  }                  }
210    
211                  packet = &packet_queue[queue_lo];                  packet = rdpsnd_queue_current_packet();
212                  out = &packet->s;                  out = &packet->s;
213    
214                  /* Swap the current packet, but only once */                  /* Swap the current packet, but only once */
# Line 291  wave_out_play(void) Line 256  wave_out_play(void)
256                          if (info.play.samples >= samplecnt + ((numsamples * 7) / 10))                          if (info.play.samples >= samplecnt + ((numsamples * 7) / 10))
257                          {                          {
258                                  samplecnt += numsamples;                                  samplecnt += numsamples;
259                                  rdpsnd_send_completion(packet->tick, packet->index);                                  /* We need to add 50 to tell windows that time has passed while
260                                  free(out->data);                                   * playing this packet */
261                                  queue_lo = (queue_lo + 1) % MAX_QUEUE;                                  rdpsnd_send_completion(packet->tick + 50, packet->index);
262                                    rdpsnd_queue_next();
263                                  swapped = False;                                  swapped = False;
264                                  sentcompletion = True;                                  sentcompletion = True;
265                          }                          }
# Line 305  wave_out_play(void) Line 271  wave_out_play(void)
271                  }                  }
272          }          }
273  }  }
274    
275    static struct audio_driver sun_driver = {
276          wave_out_write:rdpsnd_queue_write,
277          wave_out_open:sun_open,
278          wave_out_close:sun_close,
279          wave_out_format_supported:sun_format_supported,
280          wave_out_set_format:sun_set_format,
281          wave_out_volume:sun_volume,
282          wave_out_play:sun_play,
283          name:"sun",
284          description:"SUN/BSD output driver, default device: " DEFAULTDEVICE " or $AUDIODEV",
285          next:NULL,
286    };
287    
288    struct audio_driver *
289    sun_register(char *options)
290    {
291            if (options)
292            {
293                    dsp_dev = xstrdup(options);
294            }
295            else
296            {
297                    dsp_dev = getenv("AUDIODEV");
298    
299                    if (dsp_dev == NULL)
300                    {
301                            dsp_dev = xstrdup(DEFAULTDEVICE);
302                    }
303            }
304    
305            return &sun_driver;
306    }

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

  ViewVC Help
Powered by ViewVC 1.1.26