Example #1
0
  /**
   * Read screen and store result in native buffer.
   *
   * @param dim dimension of the video
   * @return true if success, false otherwise
   */
  private ByteBuffer readScreenNative(Dimension dim) {
    int size = dim.width * dim.height * 4 + FFmpeg.FF_INPUT_BUFFER_PADDING_SIZE;
    ByteBuffer data = byteBufferPool.getBuffer(size);

    data.setLength(size);

    /* get desktop screen via native grabber */
    boolean b;

    try {
      b =
          desktopInteract.captureScreen(
              displayIndex, x, y, dim.width, dim.height, data.getPtr(), data.getLength());
    } catch (Throwable t) {
      if (t instanceof ThreadDeath) {
        throw (ThreadDeath) t;
      } else {
        b = false;
        //                logger.error("Failed to grab screen!", t);
      }
    }
    if (!b) {
      data.free();
      data = null;
    }
    return data;
  }
  /**
   * Fills the time buffer with the formatted time.
   *
   * @param date current time in milliseconds
   */
  private void fillTime(long date) throws IOException {
    synchronized (_timeBuffer) {
      if (date / 1000 == _lastTime / 1000) return;

      if (_timeFormatSecondOffset >= 0 && date / 3600000 == _lastTime / 3600000) {
        byte[] bBuf = _timeBuffer.getBuffer();

        int min = (int) (date / 60000 % 60);
        int sec = (int) (date / 1000 % 60);

        bBuf[_timeFormatMinuteOffset + 0] = (byte) ('0' + min / 10);
        bBuf[_timeFormatMinuteOffset + 1] = (byte) ('0' + min % 10);

        bBuf[_timeFormatSecondOffset + 0] = (byte) ('0' + sec / 10);
        bBuf[_timeFormatSecondOffset + 1] = (byte) ('0' + sec % 10);

        _lastTime = date;

        return;
      }

      _timeCharBuffer.clear();
      QDate.formatLocal(_timeCharBuffer, date, _timeFormat);

      if (_timeFormatSecondOffset >= 0) {
        _timeFormatSecondOffset = _timeCharBuffer.lastIndexOf(':') + 1;
        _timeFormatMinuteOffset = _timeFormatSecondOffset - 3;
      }

      char[] cBuf = _timeCharBuffer.getBuffer();
      int length = _timeCharBuffer.getLength();

      _timeBuffer.setLength(length);
      byte[] bBuf = _timeBuffer.getBuffer();

      for (int i = length - 1; i >= 0; i--) bBuf[i] = (byte) cBuf[i];
    }

    _lastTime = date;
  }