Exemplo n.º 1
0
static void output_callback(void *opaque, int avail)
{
    USBAudioState *s = opaque;
    uint8_t *data;

    for (;;) {
        if (avail < USBAUDIO_PACKET_SIZE) {
            return;
        }
        data = streambuf_get(&s->out.buf);
        if (!data) {
            return;
        }
        AUD_write(s->out.voice, data, USBAUDIO_PACKET_SIZE);
        avail -= USBAUDIO_PACKET_SIZE;
    }
}
Exemplo n.º 2
0
/* Read a crypted packet from the stream. 
 * The buffer is dynamically allocated, so
 * calling function has to free it.
 */
static int32 read_packet(u_char **buffer, struct stream_buf *dbuf)
{
   int32 length, mod;
   
   /* Read packet length and calculate modulus */
   if (streambuf_read(dbuf, (u_char *)&length, 4, STREAM_ATOMIC) == -EINVALID)
      return -EINVALID;
   length = ntohl(length);   
   mod = 8 - (length % 8);

   /* Allocate the buffer and read the whole packet 
    * SAFE_CALLOC is not good to handle errors.    
    */
   *buffer = (u_char *)malloc(length + mod + 4);
   if (*buffer == NULL)
      return -EINVALID;
      
   if (streambuf_get(dbuf, *buffer, length + mod + 4, STREAM_ATOMIC) == -EINVALID) {
      SAFE_FREE(*buffer);
      return -EINVALID;
   }
      
   return ESUCCESS;
}