@Override
  public StorageResponse read(Unpacker unpacker, StorageResponse response, boolean required)
      throws IOException {
    ValueType type = unpacker.getNextType();

    if (type == ValueType.MAP) {
      MapValue mapValue = (MapValue) unpacker.readValue();

      return new FileMetaResponse(
          mapValue.get(ValueFactory.createRawValue("attributes")).toString(),
          mapValue.get(ValueFactory.createRawValue("key")).toString(),
          mapValue.get(ValueFactory.createRawValue("size")).asIntegerValue().getLong(),
          mapValue.get(ValueFactory.createRawValue("timestamp_ms")).asIntegerValue().getLong());
    } else if (type == ValueType.RAW) {
      return new DataResponse(unpacker.readByteArray());
    } else if (type == ValueType.ARRAY) {
      ArrayValue arrayValue = (ArrayValue) unpacker.readValue();

      StorageErrorType storageErrorType =
          StorageErrorType.byOrdinal(arrayValue.get(1).asIntegerValue().getInt());
      throw new StorageResponseError(STORAGE_SERVICE_NAME, storageErrorType);
    } else {
      throw new IllegalArgumentException("Can't parse storage response");
    }
  }
Ejemplo n.º 2
0
  public void processFrame(CameraEvents.Frame frameEvent) {
    if (service.getActivityMode() != ActivityEvent.Mode.WARP) return;
    if (mode == Mode.SAMPLEWARPPLANE || mode == Mode.SAMPLEWARPGLASS) {
      synchronized (this) {
        if (!isSetup) setupMatrices();
        if (captureSample) {
          captureSample = false;
          Log.d(TAG, "Warp: Capturing Sample");
          Mat frame = frameEvent.getCameraFrame().getRGB();
          byte[] frameJPEG = frameEvent.getCameraFrame().getJPEG();
          if (sampleBGR == null
              || sampleBGR.height() != frame.height()
              || sampleBGR.width() != frame.width())
            sampleBGR = new Mat(frame.rows(), frame.cols(), CvType.CV_8UC3);
          Imgproc.cvtColor(frame, sampleBGR, Imgproc.COLOR_RGB2BGR);
          useSample = true;
          // TODO: Specialize it for this group/device
          com.dappervision.wearscript.Utils.eventBusPost(
              new SendEvent("warpsample", "", ValueFactory.createRawValue(frameJPEG)));
        }
      }
    }

    if (busy) return;
    synchronized (this) {
      busy = true;
      if (!isSetup) setupMatrices();
      if (mode == Mode.CAM2GLASS) {
        Mat inputBGR;
        Mat frame = frameEvent.getCameraFrame().getRGB();
        if (frameBGR == null
            || frameBGR.height() != frame.height()
            || frameBGR.width() != frame.width())
          frameBGR = new Mat(frame.rows(), frame.cols(), CvType.CV_8UC3);
        Mat hSmallToGlassMat = getHSmallToGlassMat(frame.rows(), frame.cols());
        if (hSmallToGlassMat == null) {
          Log.w(TAG, "Warp: Bad size");
          busy = false;
          return;
        }
        Imgproc.cvtColor(frame, frameBGR, Imgproc.COLOR_RGB2BGR);
        inputBGR = frameBGR;
        Imgproc.warpPerspective(
            inputBGR, frameWarp, hSmallToGlassMat, new Size(frameWarp.width(), frameWarp.height()));
        drawFrame(frameWarp);
      }
      busy = false;
    }
  }