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

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

revision 1253 by stargo, Wed Feb 8 12:10:41 2006 UTC revision 1254 by stargo, Sun Sep 17 10:32:18 2006 UTC
# Line 20  Line 20 
20  */  */
21    
22  #include "rdesktop.h"  #include "rdesktop.h"
23    #include "rdpsnd.h"
24    
25  #define RDPSND_CLOSE            1  #define RDPSND_CLOSE            1
26  #define RDPSND_WRITE            2  #define RDPSND_WRITE            2
# Line 30  Line 31 
31  #define RDPSND_NEGOTIATE        7  #define RDPSND_NEGOTIATE        7
32    
33  #define MAX_FORMATS             10  #define MAX_FORMATS             10
34    #define MAX_QUEUE               10
35    
36    BOOL g_dsp_busy = False;
37    int g_dsp_fd;
38    
39  static VCHANNEL *rdpsnd_channel;  static VCHANNEL *rdpsnd_channel;
40    
# Line 37  static BOOL device_open; Line 42  static BOOL device_open;
42  static WAVEFORMATEX formats[MAX_FORMATS];  static WAVEFORMATEX formats[MAX_FORMATS];
43  static unsigned int format_count;  static unsigned int format_count;
44  static unsigned int current_format;  static unsigned int current_format;
45    static unsigned int queue_hi, queue_lo;
46    static struct audio_packet packet_queue[MAX_QUEUE];
47    
48  static STREAM  static STREAM
49  rdpsnd_init_packet(uint16 type, uint16 size)  rdpsnd_init_packet(uint16 type, uint16 size)
# Line 66  rdpsnd_send_completion(uint16 tick, uint Line 73  rdpsnd_send_completion(uint16 tick, uint
73          STREAM s;          STREAM s;
74    
75          s = rdpsnd_init_packet(RDPSND_COMPLETION, 4);          s = rdpsnd_init_packet(RDPSND_COMPLETION, 4);
76          out_uint16_le(s, tick + 50);          out_uint16_le(s, tick);
77          out_uint8(s, packet_index);          out_uint8(s, packet_index);
78          out_uint8(s, 0);          out_uint8(s, 0);
79          s_mark_end(s);          s_mark_end(s);
# Line 214  rdpsnd_process(STREAM s) Line 221  rdpsnd_process(STREAM s)
221                          current_format = format;                          current_format = format;
222                  }                  }
223    
224                  wave_out_write(s, tick, packet_index);                  rdpsnd_queue_write(s, tick, packet_index);
225                  awaiting_data_packet = False;                  awaiting_data_packet = False;
226                  return;                  return;
227          }          }
# Line 260  rdpsnd_init(void) Line 267  rdpsnd_init(void)
267          rdpsnd_channel =          rdpsnd_channel =
268                  channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,                  channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
269                                   rdpsnd_process);                                   rdpsnd_process);
270    
271          return (rdpsnd_channel != NULL);          return (rdpsnd_channel != NULL);
272  }  }
273    
274    void
275    rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index)
276    {
277            struct audio_packet *packet = &packet_queue[queue_hi];
278            unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE;
279    
280            if (next_hi == queue_lo)
281            {
282                    error("No space to queue audio packet\n");
283                    return;
284            }
285    
286            queue_hi = next_hi;
287    
288            packet->s = *s;
289            packet->tick = tick;
290            packet->index = index;
291            packet->s.p += 4;
292    
293            /* we steal the data buffer from s, give it a new one */
294            s->data = malloc(s->size);
295    
296            if (!g_dsp_busy)
297                    wave_out_play();
298    }
299    
300    inline struct audio_packet *
301    rdpsnd_queue_current_packet(void)
302    {
303            return &packet_queue[queue_lo];
304    }
305    
306    inline BOOL
307    rdpsnd_queue_empty(void)
308    {
309            return (queue_lo == queue_hi);
310    }
311    
312    inline void
313    rdpsnd_queue_init(void)
314    {
315            queue_lo = queue_hi = 0;
316    }
317    
318    inline void
319    rdpsnd_queue_next(void)
320    {
321            free(packet_queue[queue_lo].s.data);
322            queue_lo = (queue_lo + 1) % MAX_QUEUE;
323    }
324    
325    inline int
326    rdpsnd_queue_next_tick(void)
327    {
328            if (((queue_lo + 1) % MAX_QUEUE) != queue_hi)
329            {
330                    return packet_queue[(queue_lo + 1) % MAX_QUEUE].tick;
331            }
332            else
333            {
334                    return (packet_queue[queue_lo].tick + 65535) % 65536;
335            }
336    }

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

  ViewVC Help
Powered by ViewVC 1.1.26