/[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 1256 by stargo, Sun Sep 17 11:42:22 2006 UTC revision 1344 by ossman_, Wed Dec 6 13:59:43 2006 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     Sound Channel Process Functions
4       Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
5     Copyright (C) Matthew Chapman 2003     Copyright (C) Matthew Chapman 2003
6     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
7    
# Line 19  Line 20 
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */  */
22    
23    #include <assert.h>
24    
25  #include "rdesktop.h"  #include "rdesktop.h"
26  #include "rdpsnd.h"  #include "rdpsnd.h"
27    #include "rdpsnd_dsp.h"
28    
29  #define RDPSND_CLOSE            1  #define RDPSND_CLOSE            1
30  #define RDPSND_WRITE            2  #define RDPSND_WRITE            2
31  #define RDPSND_SET_VOLUME       3  #define RDPSND_SET_VOLUME       3
32  #define RDPSND_UNKNOWN4         4  #define RDPSND_UNKNOWN4         4
33  #define RDPSND_COMPLETION       5  #define RDPSND_COMPLETION       5
34  #define RDPSND_SERVERTICK       6  #define RDPSND_PING                     6
35  #define RDPSND_NEGOTIATE        7  #define RDPSND_NEGOTIATE        7
36    
37  #define MAX_FORMATS             10  #define MAX_FORMATS             10
# Line 44  static BOOL device_open; Line 48  static BOOL device_open;
48  static WAVEFORMATEX formats[MAX_FORMATS];  static WAVEFORMATEX formats[MAX_FORMATS];
49  static unsigned int format_count;  static unsigned int format_count;
50  static unsigned int current_format;  static unsigned int current_format;
51  unsigned int queue_hi, queue_lo;  unsigned int queue_hi, queue_lo, queue_pending;
52  struct audio_packet packet_queue[MAX_QUEUE];  struct audio_packet packet_queue[MAX_QUEUE];
53    
54    static uint8 packet_opcode;
55    static struct stream packet;
56    
57  void (*wave_out_play) (void);  void (*wave_out_play) (void);
58    
59    static void rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index);
60    static void rdpsnd_queue_init(void);
61    static void rdpsnd_queue_complete_pending(void);
62    static long rdpsnd_queue_next_completion(void);
63    
64  static STREAM  static STREAM
65  rdpsnd_init_packet(uint16 type, uint16 size)  rdpsnd_init_packet(uint16 type, uint16 size)
66  {  {
# Line 63  rdpsnd_init_packet(uint16 type, uint16 s Line 75  rdpsnd_init_packet(uint16 type, uint16 s
75  static void  static void
76  rdpsnd_send(STREAM s)  rdpsnd_send(STREAM s)
77  {  {
 #ifdef RDPSND_DEBUG  
         printf("RDPSND send:\n");  
         hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8);  
 #endif  
   
78          channel_send(s, rdpsnd_channel);          channel_send(s, rdpsnd_channel);
79  }  }
80    
81  void  static void
82  rdpsnd_send_completion(uint16 tick, uint8 packet_index)  rdpsnd_send_completion(uint16 tick, uint8 packet_index)
83  {  {
84          STREAM s;          STREAM s;
# Line 82  rdpsnd_send_completion(uint16 tick, uint Line 89  rdpsnd_send_completion(uint16 tick, uint
89          out_uint8(s, 0);          out_uint8(s, 0);
90          s_mark_end(s);          s_mark_end(s);
91          rdpsnd_send(s);          rdpsnd_send(s);
92    
93            DEBUG_SOUND(("RDPSND: -> RDPSND_COMPLETION(tick: %u, index: %u)\n",
94                         (unsigned) tick, (unsigned) packet_index));
95  }  }
96    
97  static void  static void
98  rdpsnd_process_negotiate(STREAM in)  rdpsnd_process_negotiate(STREAM in)
99  {  {
100          unsigned int in_format_count, i;          uint16 in_format_count, i;
101            uint8 pad;
102            uint16 version;
103          WAVEFORMATEX *format;          WAVEFORMATEX *format;
104          STREAM out;          STREAM out;
105          BOOL device_available = False;          BOOL device_available = False;
106          int readcnt;          int readcnt;
107          int discardcnt;          int discardcnt;
108    
109          in_uint8s(in, 14);      /* flags, volume, pitch, UDP port */          in_uint8s(in, 14);      /* initial bytes not valid from server */
110          in_uint16_le(in, in_format_count);          in_uint16_le(in, in_format_count);
111          in_uint8s(in, 4);       /* pad, status, pad */          in_uint8(in, pad);
112            in_uint16_le(in, version);
113            in_uint8s(in, 1);       /* padding */
114    
115            DEBUG_SOUND(("RDPSND: RDPSND_NEGOTIATE(formats: %d, pad: 0x%02x, version: %x)\n",
116                         (int) in_format_count, (unsigned) pad, (unsigned) version));
117    
118          if (current_driver->wave_out_open())          if (current_driver->wave_out_open())
119          {          {
# Line 147  rdpsnd_process_negotiate(STREAM in) Line 164  rdpsnd_process_negotiate(STREAM in)
164          out_uint16(out, 0);     /* UDP port */          out_uint16(out, 0);     /* UDP port */
165    
166          out_uint16_le(out, format_count);          out_uint16_le(out, format_count);
167          out_uint8(out, 0x95);   /* pad? */          out_uint8(out, 0);      /* padding */
168          out_uint16_le(out, 2);  /* status */          out_uint16_le(out, 2);  /* version */
169          out_uint8(out, 0x77);   /* pad? */          out_uint8(out, 0);      /* padding */
170    
171          for (i = 0; i < format_count; i++)          for (i = 0; i < format_count; i++)
172          {          {
# Line 164  rdpsnd_process_negotiate(STREAM in) Line 181  rdpsnd_process_negotiate(STREAM in)
181          }          }
182    
183          s_mark_end(out);          s_mark_end(out);
184    
185            DEBUG_SOUND(("RDPSND: -> RDPSND_NEGOTIATE(formats: %d)\n", (int) format_count));
186    
187          rdpsnd_send(out);          rdpsnd_send(out);
188  }  }
189    
190  static void  static void
191  rdpsnd_process_servertick(STREAM in)  rdpsnd_process_ping(STREAM in)
192  {  {
193          uint16 tick1, tick2;          uint16 tick;
194          STREAM out;          STREAM out;
195    
196          /* in_uint8s(in, 4); unknown */          in_uint16_le(in, tick);
197          in_uint16_le(in, tick1);  
198          in_uint16_le(in, tick2);          DEBUG_SOUND(("RDPSND: RDPSND_PING(tick: 0x%04x)\n", (unsigned) tick));
199    
200          out = rdpsnd_init_packet(RDPSND_SERVERTICK | 0x2300, 4);          out = rdpsnd_init_packet(RDPSND_PING | 0x2300, 4);
201          out_uint16_le(out, tick1);          out_uint16_le(out, tick);
202          out_uint16_le(out, tick2);          out_uint16_le(out, 0);
203          s_mark_end(out);          s_mark_end(out);
204          rdpsnd_send(out);          rdpsnd_send(out);
205    
206            DEBUG_SOUND(("RDPSND: -> (tick: 0x%04x)\n", (unsigned) tick));
207  }  }
208    
209  static void  static void
210  rdpsnd_process(STREAM s)  rdpsnd_process_packet(uint8 opcode, STREAM s)
211  {  {
212          uint8 type;          uint16 vol_left, vol_right;
         uint16 datalen;  
         uint32 volume;  
213          static uint16 tick, format;          static uint16 tick, format;
214          static uint8 packet_index;          static uint8 packet_index;
         static BOOL awaiting_data_packet;  
215    
216  #ifdef RDPSND_DEBUG          switch (opcode)
         printf("RDPSND recv:\n");  
         hexdump(s->p, s->end - s->p);  
 #endif  
   
         if (awaiting_data_packet)  
217          {          {
218                  if (format >= MAX_FORMATS)                  case RDPSND_WRITE:
219                  {                          in_uint16_le(s, tick);
220                          error("RDPSND: Invalid format index\n");                          in_uint16_le(s, format);
221                          return;                          in_uint8(s, packet_index);
222                  }                          in_uint8s(s, 3);
223                            DEBUG_SOUND(("RDPSND: RDPSND_WRITE(tick: %u, format: %u, index: %u, data: %u bytes)\n", (unsigned) tick, (unsigned) format, (unsigned) packet_index, (unsigned) s->size - 8));
224    
225                  if (!device_open || (format != current_format))                          if (format >= MAX_FORMATS)
                 {  
                         if (!device_open && !current_driver->wave_out_open())  
226                          {                          {
227                                  rdpsnd_send_completion(tick, packet_index);                                  error("RDPSND: Invalid format index\n");
228                                  return;                                  break;
229                          }                          }
230                          if (!current_driver->wave_out_set_format(&formats[format]))  
231                            if (!device_open || (format != current_format))
232                          {                          {
233                                  rdpsnd_send_completion(tick, packet_index);                                  if (!device_open && !current_driver->wave_out_open())
234                                  current_driver->wave_out_close();                                  {
235                                  device_open = False;                                          rdpsnd_send_completion(tick, packet_index);
236                                  return;                                          break;
237                                    }
238                                    if (!current_driver->wave_out_set_format(&formats[format]))
239                                    {
240                                            rdpsnd_send_completion(tick, packet_index);
241                                            current_driver->wave_out_close();
242                                            device_open = False;
243                                            break;
244                                    }
245                                    device_open = True;
246                                    current_format = format;
247                          }                          }
                         device_open = True;  
                         current_format = format;  
                 }  
   
                 current_driver->wave_out_write(s, tick, packet_index);  
                 awaiting_data_packet = False;  
                 return;  
         }  
248    
249          in_uint8(s, type);                          rdpsnd_queue_write(rdpsnd_dsp_process
250          in_uint8s(s, 1);        /* unknown? */                                             (s->p, s->end - s->p, current_driver,
251          in_uint16_le(s, datalen);                                              &formats[current_format]), tick, packet_index);
252                            return;
         switch (type)  
         {  
                 case RDPSND_WRITE:  
                         in_uint16_le(s, tick);  
                         in_uint16_le(s, format);  
                         in_uint8(s, packet_index);  
                         awaiting_data_packet = True;  
253                          break;                          break;
254                  case RDPSND_CLOSE:                  case RDPSND_CLOSE:
255                            DEBUG_SOUND(("RDPSND: RDPSND_CLOSE()\n"));
256                          current_driver->wave_out_close();                          current_driver->wave_out_close();
257                          device_open = False;                          device_open = False;
258                          break;                          break;
259                  case RDPSND_NEGOTIATE:                  case RDPSND_NEGOTIATE:
260                          rdpsnd_process_negotiate(s);                          rdpsnd_process_negotiate(s);
261                          break;                          break;
262                  case RDPSND_SERVERTICK:                  case RDPSND_PING:
263                          rdpsnd_process_servertick(s);                          rdpsnd_process_ping(s);
264                          break;                          break;
265                  case RDPSND_SET_VOLUME:                  case RDPSND_SET_VOLUME:
266                          in_uint32(s, volume);                          in_uint16_le(s, vol_left);
267                            in_uint16_le(s, vol_right);
268                            DEBUG_SOUND(("RDPSND: RDPSND_VOLUME(left: 0x%04x (%u %%), right: 0x%04x (%u %%))\n", (unsigned) vol_left, (unsigned) vol_left / 655, (unsigned) vol_right, (unsigned) vol_right / 655));
269                          if (device_open)                          if (device_open)
270                          {                                  current_driver->wave_out_volume(vol_left, vol_right);
                                 current_driver->wave_out_volume((volume & 0xffff),  
                                                                 (volume & 0xffff0000) >> 16);  
                         }  
271                          break;                          break;
272                  default:                  default:
273                          unimpl("RDPSND packet type %d\n", type);                          unimpl("RDPSND packet type %x\n", opcode);
274                          break;                          break;
275          }          }
276  }  }
277    
278  BOOL  static void
279  rdpsnd_init(void)  rdpsnd_process(STREAM s)
280  {  {
281          rdpsnd_channel =          uint16 len;
282                  channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,  
283                                   rdpsnd_process);          while (!s_check_end(s))
284            {
285                    /* New packet */
286                    if (packet.size == 0)
287                    {
288                            if ((s->end - s->p) < 4)
289                            {
290                                    error("RDPSND: Split at packet header. Things will go south from here...\n");
291                                    return;
292                            }
293                            in_uint8(s, packet_opcode);
294                            in_uint8s(s, 1);        /* Padding */
295                            in_uint16_le(s, len);
296    
297                            DEBUG_SOUND(("RDPSND: == Opcode %x Length: %d ==\n",
298                                         (int) packet_opcode, (int) len));
299    
300                            packet.p = packet.data;
301                            packet.end = packet.data + len;
302                            packet.size = len;
303                    }
304                    else
305                    {
306                            len = MIN(s->end - s->p, packet.end - packet.p);
307    
308          return (rdpsnd_channel != NULL);                          /* Microsoft's server is so broken it's not even funny... */
309                            if (packet_opcode == RDPSND_WRITE)
310                            {
311                                    if ((packet.p - packet.data) < 12)
312                                            len = MIN(len, 12 - (packet.p - packet.data));
313                                    else if ((packet.p - packet.data) == 12)
314                                    {
315                                            DEBUG_SOUND(("RDPSND: Eating 4 bytes of %d bytes...\n",
316                                                         len));
317                                            in_uint8s(s, 4);
318                                            len -= 4;
319                                    }
320                            }
321    
322                            in_uint8a(s, packet.p, len);
323                            packet.p += len;
324                    }
325    
326                    /* Packet fully assembled */
327                    if (packet.p == packet.end)
328                    {
329                            packet.p = packet.data;
330                            rdpsnd_process_packet(packet_opcode, &packet);
331                            packet.size = 0;
332                    }
333            }
334  }  }
335    
336  BOOL  static BOOL
337  rdpsnd_auto_open(void)  rdpsnd_auto_open(void)
338  {  {
339          current_driver = drivers;          static BOOL failed = False;
340          while (current_driver != NULL)  
341            if (!failed)
342          {          {
343                  DEBUG(("trying %s...\n", current_driver->name));                  struct audio_driver *auto_driver = current_driver;
344                  if (current_driver->wave_out_open())  
345                    current_driver = drivers;
346                    while (current_driver != NULL)
347                  {                  {
348                          DEBUG(("selected %s\n", current_driver->name));                          DEBUG(("trying %s...\n", current_driver->name));
349                          return True;                          if (current_driver->wave_out_open())
350                            {
351                                    DEBUG(("selected %s\n", current_driver->name));
352                                    return True;
353                            }
354                            g_dsp_fd = 0;
355                            current_driver = current_driver->next;
356                  }                  }
                 g_dsp_fd = 0;  
                 current_driver = current_driver->next;  
         }  
357    
358          warning("no working audio-driver found\n");                  warning("no working audio-driver found\n");
359                    failed = True;
360                    current_driver = auto_driver;
361            }
362    
363          return False;          return False;
364  }  }
365    
366  void  static void
367  rdpsnd_register_drivers(char *options)  rdpsnd_register_drivers(char *options)
368  {  {
369          struct audio_driver **reg;          struct audio_driver **reg;
# Line 307  rdpsnd_register_drivers(char *options) Line 373  rdpsnd_register_drivers(char *options)
373          reg = &drivers;          reg = &drivers;
374  #if defined(RDPSND_ALSA)  #if defined(RDPSND_ALSA)
375          *reg = alsa_register(options);          *reg = alsa_register(options);
376          reg = &((*reg)->next);          assert(*reg);
 #endif  
 #if defined(RDPSND_OSS)  
         *reg = oss_register(options);  
377          reg = &((*reg)->next);          reg = &((*reg)->next);
378  #endif  #endif
379  #if defined(RDPSND_SUN)  #if defined(RDPSND_SUN)
380          *reg = sun_register(options);          *reg = sun_register(options);
381            assert(*reg);
382            reg = &((*reg)->next);
383    #endif
384    #if defined(RDPSND_OSS)
385            *reg = oss_register(options);
386            assert(*reg);
387          reg = &((*reg)->next);          reg = &((*reg)->next);
388  #endif  #endif
389  #if defined(RDPSND_SGI)  #if defined(RDPSND_SGI)
390          *reg = sgi_register(options);          *reg = sgi_register(options);
391            assert(*reg);
392          reg = &((*reg)->next);          reg = &((*reg)->next);
393  #endif  #endif
394  #if defined(RDPSND_LIBAO)  #if defined(RDPSND_LIBAO)
395          *reg = libao_register(options);          *reg = libao_register(options);
396            assert(*reg);
397          reg = &((*reg)->next);          reg = &((*reg)->next);
398  #endif  #endif
399            *reg = NULL;
400  }  }
401    
402  BOOL  BOOL
403  rdpsnd_select_driver(char *driver, char *options)  rdpsnd_init(char *optarg)
404  {  {
405          static struct audio_driver auto_driver;          static struct audio_driver auto_driver;
406          struct audio_driver *pos;          struct audio_driver *pos;
407            char *driver = NULL, *options = NULL;
408    
409          drivers = NULL;          drivers = NULL;
410    
411            packet.data = xmalloc(65536);
412            packet.p = packet.end = packet.data;
413            packet.size = 0;
414    
415            rdpsnd_channel =
416                    channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
417                                     rdpsnd_process);
418    
419            if (rdpsnd_channel == NULL)
420            {
421                    error("channel_register\n");
422                    return False;
423            }
424    
425            rdpsnd_queue_init();
426    
427            if (optarg != NULL && strlen(optarg) > 0)
428            {
429                    driver = options = optarg;
430    
431                    while (*options != '\0' && *options != ':')
432                            options++;
433    
434                    if (*options == ':')
435                    {
436                            *options = '\0';
437                            options++;
438                    }
439    
440                    if (*options == '\0')
441                            options = NULL;
442            }
443    
444          rdpsnd_register_drivers(options);          rdpsnd_register_drivers(options);
445    
446          if (!driver)          if (!driver)
# Line 372  rdpsnd_show_help(void) Line 479  rdpsnd_show_help(void)
479          }          }
480  }  }
481    
482  inline void  void
483  rdpsnd_play(void)  rdpsnd_play(void)
484  {  {
485          current_driver->wave_out_play();          current_driver->wave_out_play();
486  }  }
487    
488  void  void
489    rdpsnd_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv)
490    {
491            long next_pending;
492    
493            if (g_dsp_busy)
494            {
495                    FD_SET(g_dsp_fd, wfds);
496                    *n = (g_dsp_fd > *n) ? g_dsp_fd : *n;
497            }
498    
499            next_pending = rdpsnd_queue_next_completion();
500            if (next_pending >= 0)
501            {
502                    long cur_timeout;
503    
504                    cur_timeout = tv->tv_sec * 1000000 + tv->tv_usec;
505                    if (cur_timeout > next_pending)
506                    {
507                            tv->tv_sec = next_pending / 1000000;
508                            tv->tv_usec = next_pending % 1000000;
509                    }
510            }
511    }
512    
513    void
514    rdpsnd_check_fds(fd_set * rfds, fd_set * wfds)
515    {
516            rdpsnd_queue_complete_pending();
517    
518            if (g_dsp_busy && FD_ISSET(g_dsp_fd, wfds))
519                    rdpsnd_play();
520    }
521    
522    static void
523  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)  rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)
524  {  {
525          struct audio_packet *packet = &packet_queue[queue_hi];          struct audio_packet *packet = &packet_queue[queue_hi];
526          unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE;          unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE;
527    
528          if (next_hi == queue_lo)          if (next_hi == queue_pending)
529          {          {
530                  error("No space to queue audio packet\n");                  error("No space to queue audio packet\n");
531                  return;                  return;
# Line 395  rdpsnd_queue_write(STREAM s, uint16 tick Line 536  rdpsnd_queue_write(STREAM s, uint16 tick
536          packet->s = *s;          packet->s = *s;
537          packet->tick = tick;          packet->tick = tick;
538          packet->index = index;          packet->index = index;
         packet->s.p += 4;  
539    
540          /* we steal the data buffer from s, give it a new one */          gettimeofday(&packet->arrive_tv, NULL);
         s->data = malloc(s->size);  
541    
542          if (!g_dsp_busy)          if (!g_dsp_busy)
543                  current_driver->wave_out_play();                  current_driver->wave_out_play();
544  }  }
545    
546  inline struct audio_packet *  struct audio_packet *
547  rdpsnd_queue_current_packet(void)  rdpsnd_queue_current_packet(void)
548  {  {
549          return &packet_queue[queue_lo];          return &packet_queue[queue_lo];
550  }  }
551    
552  inline BOOL  BOOL
553  rdpsnd_queue_empty(void)  rdpsnd_queue_empty(void)
554  {  {
555          return (queue_lo == queue_hi);          return (queue_lo == queue_hi);
556  }  }
557    
558  inline void  static void
559  rdpsnd_queue_init(void)  rdpsnd_queue_init(void)
560  {  {
561          queue_lo = queue_hi = 0;          queue_pending = queue_lo = queue_hi = 0;
562  }  }
563    
564  inline void  void
565  rdpsnd_queue_next(void)  rdpsnd_queue_next(unsigned long completed_in_us)
566  {  {
567          free(packet_queue[queue_lo].s.data);          struct audio_packet *packet;
568    
569            assert(!rdpsnd_queue_empty());
570    
571            packet = &packet_queue[queue_lo];
572    
573            gettimeofday(&packet->completion_tv, NULL);
574    
575            packet->completion_tv.tv_usec += completed_in_us;
576            packet->completion_tv.tv_sec += packet->completion_tv.tv_usec / 1000000;
577            packet->completion_tv.tv_usec %= 1000000;
578    
579          queue_lo = (queue_lo + 1) % MAX_QUEUE;          queue_lo = (queue_lo + 1) % MAX_QUEUE;
580    
581            rdpsnd_queue_complete_pending();
582  }  }
583    
584  inline int  int
585  rdpsnd_queue_next_tick(void)  rdpsnd_queue_next_tick(void)
586  {  {
587          if (((queue_lo + 1) % MAX_QUEUE) != queue_hi)          if (((queue_lo + 1) % MAX_QUEUE) != queue_hi)
# Line 441  rdpsnd_queue_next_tick(void) Line 593  rdpsnd_queue_next_tick(void)
593                  return (packet_queue[queue_lo].tick + 65535) % 65536;                  return (packet_queue[queue_lo].tick + 65535) % 65536;
594          }          }
595  }  }
596    
597    static void
598    rdpsnd_queue_complete_pending(void)
599    {
600            struct timeval now;
601            long elapsed;
602            struct audio_packet *packet;
603    
604            gettimeofday(&now, NULL);
605    
606            while (queue_pending != queue_lo)
607            {
608                    packet = &packet_queue[queue_pending];
609    
610                    if (now.tv_sec < packet->completion_tv.tv_sec)
611                            break;
612    
613                    if ((now.tv_sec == packet->completion_tv.tv_sec) &&
614                        (now.tv_usec < packet->completion_tv.tv_usec))
615                            break;
616    
617                    elapsed = (packet->completion_tv.tv_sec - packet->arrive_tv.tv_sec) * 1000000 +
618                            (packet->completion_tv.tv_usec - packet->arrive_tv.tv_usec);
619                    elapsed /= 1000;
620    
621                    xfree(packet->s.data);
622                    rdpsnd_send_completion((packet->tick + elapsed) % 65536, packet->index);
623                    queue_pending = (queue_pending + 1) % MAX_QUEUE;
624            }
625    }
626    
627    static long
628    rdpsnd_queue_next_completion(void)
629    {
630            struct audio_packet *packet;
631            long remaining;
632            struct timeval now;
633    
634            if (queue_pending == queue_lo)
635                    return -1;
636    
637            gettimeofday(&now, NULL);
638    
639            packet = &packet_queue[queue_pending];
640    
641            remaining = (packet->completion_tv.tv_sec - now.tv_sec) * 1000000 +
642                    (packet->completion_tv.tv_usec - now.tv_usec);
643    
644            if (remaining < 0)
645                    return 0;
646    
647            return remaining;
648    }

Legend:
Removed from v.1256  
changed lines
  Added in v.1344

  ViewVC Help
Powered by ViewVC 1.1.26