Package com.limelight.binding.audio

Source Code of com.limelight.binding.audio.SoundBuffer

package com.limelight.binding.audio;

import java.nio.ByteBuffer;
import java.util.LinkedList;

import com.limelight.nvstream.av.ByteBufferDescriptor;

public class SoundBuffer {
 
  private LinkedList<ByteBufferDescriptor> bufferList;
  private int maxBuffers;
 
  public SoundBuffer(int maxBuffers) {
    this.bufferList = new LinkedList<ByteBufferDescriptor>();
    this.maxBuffers = maxBuffers;
  }
 
  public void queue(ByteBufferDescriptor buff) {
    if (bufferList.size() > maxBuffers) {
      bufferList.removeFirst();
    }
   
    bufferList.addLast(buff);
  }
 
  public int size() {
    int size = 0;
    for (ByteBufferDescriptor desc : bufferList) {
      size += desc.length;
    }
    return size;
  }
 
  public int fill(byte[] data, int offset, int length) {
    int filled = 0;
   
    ByteBuffer bb = ByteBuffer.wrap(data);
    bb.position(offset);
    while (length > 0 && !bufferList.isEmpty()) {
      ByteBufferDescriptor buff = bufferList.getFirst();
     
      if (buff.length > length) {
        break;
      }
     
      bb.put(buff.data, buff.offset, buff.length);
      length -= buff.length;
      filled += buff.length;
     
      bufferList.removeFirst();
    }
   
    return filled;
  }
}
TOP

Related Classes of com.limelight.binding.audio.SoundBuffer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.