/* [implicit_jscontext] void getCamera ([optional] in jsval aOptions, in nsICameraGetCameraCallback onSuccess, [optional] in nsICameraErrorCallback onError); */
NS_IMETHODIMP
nsDOMCameraManager::GetCamera(const JS::Value& aOptions, nsICameraGetCameraCallback* onSuccess, nsICameraErrorCallback* onError, JSContext* cx)
{
  NS_ENSURE_TRUE(onSuccess, NS_ERROR_INVALID_ARG);

  uint32_t cameraId = 0;  // back (or forward-facing) camera by default
  CameraSelector selector;

  nsresult rv = selector.Init(cx, &aOptions);
  NS_ENSURE_SUCCESS(rv, rv);

  if (selector.camera.EqualsASCII("front")) {
    cameraId = 1;
  }

  // reuse the same camera thread to conserve resources
  if (!mCameraThread) {
    rv = NS_NewThread(getter_AddRefs(mCameraThread));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);

  // Creating this object will trigger the onSuccess handler
  nsCOMPtr<nsDOMCameraControl> cameraControl = new nsDOMCameraControl(cameraId, mCameraThread, onSuccess, onError, mWindowId);

  Register(cameraControl);
  return NS_OK;
}
/* [implicit_jscontext] void getCamera ([optional] in jsval aOptions, in nsICameraGetCameraCallback onSuccess, [optional] in nsICameraErrorCallback onError); */
NS_IMETHODIMP
nsDOMCameraManager::GetCamera(const JS::Value& aOptions, nsICameraGetCameraCallback* onSuccess, nsICameraErrorCallback* onError, JSContext* cx)
{
  NS_ENSURE_TRUE(onSuccess, NS_ERROR_INVALID_ARG);

  PRUint32 cameraId = 0;  // back (or forward-facing) camera by default
  CameraSelector selector;

  nsresult rv = selector.Init(cx, &aOptions);
  NS_ENSURE_SUCCESS(rv, rv);

  if (selector.camera.EqualsASCII("front")) {
    cameraId = 1;
  }

  // reuse the same camera thread to conserve resources
  if (!mCameraThread) {
    rv = NS_NewThread(getter_AddRefs(mCameraThread));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  DOM_CAMERA_LOGI("%s:%d\n", __func__, __LINE__);

  nsCOMPtr<nsIRunnable> getCameraTask = new GetCameraTask(cameraId, onSuccess, onError, mCameraThread);
  mCameraThread->Dispatch(getCameraTask, NS_DISPATCH_NORMAL);

  return NS_OK;
}
Esempio n. 3
0
int main (int argc, char * argv[] )
#endif
{
    int ans = 0;
    int camera_id = -1;
    bool camid_user_specified = false;
    VisionPipeLine::working_mode_t working_mode = VisionPipeLine::MODE_KEYBOARD; 
    bool opt_show_help = false;
    int pos = 1;

    // create the calibration result folder if it isn't existed.
    std::string config_path;
    config_path = getPlatformConfigPrefix();
    config_path += FILEPATH_LOC_CALIB_FOLDER;
    mkdir(config_path.c_str(), 0755);

    g_config_mgr.loadConfigFromFile();
    g_config_bundle.load();

    camera_id = g_config_bundle.default_cam_id;

    while (pos < argc) {
        char * current_opt = argv[pos];

        if (strcmp(current_opt, "-h") == 0 || strcmp(current_opt, "--help") == 0 ) {
            opt_show_help = true;
        } else if (strcmp(current_opt, "-m") == 0 ) {
            const char * modestr = argv[++pos];
            if (strcmp(modestr, "sketch") == 0) {
                working_mode = VisionPipeLine::MODE_SKETCHPAD;
            }  else if (strcmp(modestr, "calib") == 0) {
                working_mode = VisionPipeLine::MODE_CALIBRATION;
            }
        }  else {
            camera_id = atoi(argv[pos]);
            camid_user_specified = true;
        }
        ++pos;
    }

    if (opt_show_help) {
        show_help(argc, argv);
        return 0;
    }

    CameraSelector camsel;
    camsel.setPredefinedCamera(camera_id, camid_user_specified);

    camera_id = camsel.doModal();
    if (camera_id == -1) return 0;

  

    if (!dev_connect(camera_id)) {
        printf("error, cannot connect to the device. \n");
        return -2;
    }


    UpdateChecker::GetInstance()->sendQueryRequest(IsTargetProductPresent()?RELEASE_VENDOR_TYPE:"3rd", RELEASE_PRODUCT_TYPE, RELEASE_VERSION_INFO);
   

    

    g_config_bundle.default_cam_id = camera_id;
    
    // flush config
    g_config_bundle.flush();
    g_config_mgr.flushConfigFile();

    VisionPipeLine pipeline(cam_input);

    if (pipeline.init()) {
        pipeline.setWorkingMode(working_mode);

        std::string updateurl;
        bool update_checked = false;
        while(pipeline.heartBeat() && !checkPlatformExitFlag()) {
            if (UpdateChecker::GetInstance()->isResponseReady() && !update_checked) {
                update_checked = true;
                if (UpdateChecker::GetInstance()->getResponseUrl(updateurl)) {
                    pipeline.setUpgradeAvailable(updateurl);
                }
            }
        }
         
        
    }

    dev_disconnect();
    return ans;
}