예제 #1
0
  public ByteBuffer LockBuffer(IntegerPointer pBytesAvailable) {
    if (m_pBuffer == null) {
      return null;
    }

    if (m_bBufferLocked) return null;

    m_bBufferLocked = true;

    if (pBytesAvailable != null) pBytesAvailable.value = GetBufferBytesAvailable();

    pBufferPointer.reset(m_pBuffer, m_nBufferTail);
    return pBufferPointer;
  }
예제 #2
0
  public int AddDataFromInputSource(InputSource pInputSource, int nMaxBytes) throws IOException {
    // error check the parameters
    if (pInputSource == null) throw new JMACException("Bad Parameters");

    // initialize
    int pBytesAdded = 0;
    int nBytesRead = 0;

    // lock the buffer
    m_nAddDataFromInputSourceBytesAvailavle.value = 0;
    ByteBuffer pBuffer = LockBuffer(m_nAddDataFromInputSourceBytesAvailavle);

    // calculate the 'ideal' number of bytes
    int nIdealBytes = m_spAPECompressCreate.GetFullFrameBytes() - (m_nBufferTail - m_nBufferHead);
    System.out.println(nIdealBytes);
    if (nIdealBytes > 0) {
      // get the data
      int nBytesToAdd = m_nAddDataFromInputSourceBytesAvailavle.value;

      if (nMaxBytes > 0) {
        if (nBytesToAdd > nMaxBytes) nBytesToAdd = nMaxBytes;
      }

      if (nBytesToAdd > nIdealBytes) nBytesToAdd = nIdealBytes;

      // always make requests along block boundaries
      while ((nBytesToAdd % m_wfeInput.nBlockAlign) != 0) nBytesToAdd--;

      int nBlocksToAdd = nBytesToAdd / m_wfeInput.nBlockAlign;

      // get data
      int nBlocksAdded = pInputSource.GetData(pBuffer, nBlocksToAdd);
      nBytesRead = (nBlocksAdded * m_wfeInput.nBlockAlign);

      // store the bytes read
      pBytesAdded = nBytesRead;
    }

    // unlock the data and process
    UnlockBuffer(nBytesRead, true);

    return pBytesAdded;
  }
예제 #3
0
  public void AddData(byte[] pData, int nBytes) throws IOException {
    int nBytesDone = 0;

    while (nBytesDone < nBytes) {
      // lock the buffer
      m_nAddDataBytesAvailable.value = 0;
      ByteBuffer pBuffer = LockBuffer(m_nAddDataBytesAvailable);
      if (pBuffer == null || m_nAddDataBytesAvailable.value <= 0)
        throw new JMACException("Error Undefined");

      // calculate how many bytes to copy and add that much to the buffer
      int nBytesToProcess = Math.min(m_nAddDataBytesAvailable.value, nBytes - nBytesDone);
      pBuffer.append(pData, nBytesDone, nBytesToProcess);

      // unlock the buffer (fail if not successful)
      UnlockBuffer(nBytesToProcess);

      // update our progress
      nBytesDone += nBytesToProcess;
    }
  }