Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable delay between two scans #95

Merged
merged 2 commits into from
Mar 27, 2016
Merged

Conversation

JauernigIT
Copy link

I added a scanDelay property to the Quagga config, so there is a configurable delay between two scans. It's used with a timeout in the onmessage function. I needed this functionality in my scenario, where the processor load had to be lowered (and where we don't need realtime processing).

@serratus
Copy link
Owner

Hi Matthias, thanks for the proposal. Having the timeout directly in the onmessage solves only half of the problems. I propose totally different approach:

  1. Instead of scanDelay I propose an option called frequency which defines the desired scan-frequency in scans per second.
  2. The scheduler should be placed outside of the worker, directly in the frame function where it is currently called via requestAnimFrame. In my opinion, this is a much better place for scheduling, because all the other work like capturing the video-frame is also delayed.

I just tried something like this and it worked like a charm:

function startContinousUpdate() {
    var next = null,
        delay = 1000 / (_config.frequency || 60);

    _stopped = false;
    (function frame(timestamp) {
        next = next || timestamp;
        if (!_stopped) {
            if (timestamp >= next) {
                next += delay;
                update();
            }
            window.requestAnimFrame(frame);
        }
    }(performance.now()));
}

function start() {
    if (_onUIThread && _config.inputStream.type === "LiveStream") {
        startContinousUpdate();
    } else {
        update();
    }
}

@JauernigIT
Copy link
Author

That's brilliant! I've made the first proposal, but already thought that the location was not the best. You're more into the whole library, so you know where to put it. I've pushed the updated branch, works fine for me.

@serratus serratus merged commit 3cf474d into serratus:master Mar 27, 2016
serratus added a commit that referenced this pull request Mar 27, 2016
@JauernigIT JauernigIT deleted the scanDelay branch March 30, 2016 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants