void Control::setValue(const any &value, bool update) { MarControlPtr & control = m_atomic->systemControl(); if (m_runner->isRunning()) m_runner->enqueue_control_value( control, value, update ); else set_control_value( control, value, update ); }
void RunnerThread::process_requests() { Event *event; while( m_shared->request_queue.pop(event) ) { //cout << "MarSystemThread: popped event: type=" << event->type << endl; switch (event->type) { case SetControl: { SetControlEvent* request = static_cast<SetControlEvent*>(event); //cout << "MarSystemThread: setting control: " << request->control->getName() << endl; set_control_value( request->control, request->value ); break; } case SetControlValue: { SetControlValueEvent* request = static_cast<SetControlValueEvent*>(event); //cout << "MarSystemThread: setting control value: " << request->path << endl; MarControlPtr control = m_system->getControl(request->path); if (control.isInvalid()) { MRSERR("Marsyas::Thread::System:: Can not set control - invalid path: " << request->path); } else set_control_value(control, request->value ); break; } case SetControls: { SetControlsEvent *request = static_cast<SetControlsEvent*>(event); for( const auto & mapping : request->control_values ) { const bool do_not_update = false; //cout << "MarSystemThread: setting staged control: " << mapping.first->getName() << endl; // FIXME: evil const_cast: MarControlPtr & settable_control = const_cast<MarControlPtr &>(mapping.first); set_control_value(settable_control, mapping.second, do_not_update); } m_system->update(); break; } default: MRSERR("Marsyas::Thread::System:: unsupported event type: " << event->type); } event->setProcessed(); } }
/* * Set a new value on a v4l2 integer64 control */ JNIEXPORT void JNICALL Java_au_edu_jcu_v4l4j_Control_doSetLongValue(JNIEnv *e, jobject t, jlong object, jint id, jlong jvalue){ int ret; dprint(LOG_CALLS, "[CALL] Entering %s\n",__PRETTY_FUNCTION__); struct v4l4j_device *d = (struct v4l4j_device *) (uintptr_t) object; dprint(LOG_LIBVIDEO, "[LIBVIDEO] Calling set_control_value(dev: %s, ctrl name:%s, val: %lld)\n", d->vdev->file,d->vdev->control->controls[id].v4l2_ctrl->name, (unsigned long long)jvalue); ret = set_control_value(d->vdev, d->vdev->control->controls[id].v4l2_ctrl, &jvalue, 0); if(ret != 0) { if(ret == LIBVIDEO_ERR_OUT_OF_RANGE){ THROW_EXCEPTION(e, INVALID_VAL_EXCP, "Invalid value for long control %s : value out of range", d->vdev->control->controls[id].v4l2_ctrl->name); } else if(ret == LIBVIDEO_ERR_STREAMING){ THROW_EXCEPTION(e, CTRL_EXCP, "Cannot set value for long control '%s' while streaming", d->vdev->control->controls[id].v4l2_ctrl->name); } else { THROW_EXCEPTION(e, CTRL_EXCP, "Error setting current value for long control '%s'", d->vdev->control->controls[id].v4l2_ctrl->name); } } }
/* Reads the first few bytes of "sock" socket and decides what to do (send webcam stream or list of controls) * In the latter case (list of controls), more bytes are parsed to see whether we should also set a new value to one * of the controls */ int get_action(int sock, struct video_device *d) { int c, ctrl_index = 0, value = 0, ret = ACTION_CAPTURE; char *buf, *sptr, *fptr; struct control_list *l = get_control_list(d); XMALLOC(buf, char *, INPUT_BLOCK_SIZE); c = read(sock, buf, INPUT_BLOCK_SIZE - 1); buf[c] = '\0'; if(strstr(buf, "webcam") != NULL) { ret = ACTION_CAPTURE; info(LOG_INFO, "going for capture\n"); } else if (strstr(buf, "list") != NULL){ ret = ACTION_LIST; if((sptr = strstr(buf, "?")) != NULL) { fptr = strstr(sptr, " HTTP"); *fptr = '\0'; if(sscanf(++sptr, "val=%6d&%3d=update", &value, &ctrl_index) == 2) { //catch the jpeg control setting if(ctrl_index==-1) { info(LOG_INFO, "Setting JPEG quality to %d\n", value); if((1 <= value) && (value <= 100)) jpeg_quality=value; else info(LOG_ERR, "Invalid jpeg quality value %d\n", value); } else if(ctrl_index==-2) { //catch the frame ratio control info(LOG_INFO, "Setting frame ratio to %d\n", value); if((1 <= value) && (value <= 25)) { requested_fps = value; set_fps(requested_fps); } else info(LOG_ERR, "Invalid frame rate %d\n", value); } else { assert(ctrl_index < l->count); info(LOG_INFO, "Setting %s to %d\n", l->controls[ctrl_index].v4l2_ctrl->name, value); set_control_value(d, l->controls[ctrl_index].v4l2_ctrl, &value); info(LOG_INFO, "New value: %d\n", value); } } else info(LOG_ERR, "Error parsing URL. Unable to set new value\n"); } } XFREE(buf); release_control_list(d); return ret; }
/* * Set a new value on a v4l2 control */ JNIEXPORT jint JNICALL Java_au_edu_jcu_v4l4j_Control_doSetValue(JNIEnv *e, jobject t, jlong object, jint id, jint value){ int ret, v = value; dprint(LOG_CALLS, "[CALL] Entering %s\n",__PRETTY_FUNCTION__); struct v4l4j_device *d = (struct v4l4j_device *) (uintptr_t) object; dprint(LOG_LIBVIDEO, "[LIBVIDEO] Calling set_control_value(dev: %s, ctrl name:%s, val: %d)\n", d->vdev->file,d->vdev->control->controls[id].v4l2_ctrl->name,value); ret = set_control_value(d->vdev, d->vdev->control->controls[id].v4l2_ctrl, &v, 0); if(ret != 0) { if(ret == LIBVIDEO_ERR_OUT_OF_RANGE){ THROW_EXCEPTION(e, INVALID_VAL_EXCP, "Invalid value %d for control '%s': value out of range", value, d->vdev->control->controls[id].v4l2_ctrl->name); } else if(ret == LIBVIDEO_ERR_STREAMING){ THROW_EXCEPTION(e, CTRL_EXCP, "Cannot set value for control '%s' while streaming", d->vdev->control->controls[id].v4l2_ctrl->name); } else { THROW_EXCEPTION(e, CTRL_EXCP, "Error setting current value for control '%s'", d->vdev->control->controls[id].v4l2_ctrl->name); } return 0; } dprint(LOG_V4L4J, "[V4L4J] set_control_value(dev: %s, ctrl name:%s) desired = %d - set to: %d\n", d->vdev->file, d->vdev->control->controls[id].v4l2_ctrl->name, value, v); return v; }
/* * Set a new value on a v4l2 string control */ JNIEXPORT void JNICALL Java_au_edu_jcu_v4l4j_Control_doSetStringValue(JNIEnv *e, jobject t, jlong object, jint id, jstring jvalue){ int ret; char *copy; int size; dprint(LOG_CALLS, "[CALL] Entering %s\n",__PRETTY_FUNCTION__); struct v4l4j_device *d = (struct v4l4j_device *) (uintptr_t) object; const char * value = (*e)->GetStringUTFChars(e, jvalue, 0); if (value == NULL) { // OOM exception already thrown dprint(LOG_V4L4J, " error getting string\n"); return; } // copy the java string value in case it gets modified by the driver copy = strdup(value); if (copy == NULL) { dprint(LOG_V4L4J, "Error copying string value\n"); THROW_EXCEPTION(e, CTRL_EXCP, "Error copying new string value"); return; } (*e)->ReleaseStringUTFChars(e, jvalue, value); size = strlen(copy) + 1; dprint(LOG_LIBVIDEO, "[LIBVIDEO] Calling set_control_value(dev: %s, ctrl name:%s, val: %s - byte size: %d)\n", d->vdev->file,d->vdev->control->controls[id].v4l2_ctrl->name, copy, size); ret = set_control_value(d->vdev, d->vdev->control->controls[id].v4l2_ctrl, copy, size); free(copy); if(ret != 0) { if(ret == LIBVIDEO_ERR_OUT_OF_RANGE){ THROW_EXCEPTION(e, INVALID_VAL_EXCP, "Invalid value for string control %s : value out of range", d->vdev->control->controls[id].v4l2_ctrl->name); } else if(ret == LIBVIDEO_ERR_STREAMING){ THROW_EXCEPTION(e, CTRL_EXCP, "Cannot set value for string control '%s' while streaming", d->vdev->control->controls[id].v4l2_ctrl->name); } else { THROW_EXCEPTION(e, CTRL_EXCP, "Error setting current value for string control '%s'", d->vdev->control->controls[id].v4l2_ctrl->name); } } }