Skip to content

Question re framesQueued and popOutputBuffer, and a suggestion ? #4

Open
@g40

Description

@g40

At first glance, it is not clear that the callback function framesQueued runs in a different thread. Might this be documented a little more clearly?

The next question is can you run capture loop in a single thread? The answer seems to be yes, but with the inefficiency of polling.

The example code below is just to illustrate the concept. what would be great here is to make popOutputBuffer() a blocking call when given an optional timeout - this would put the calling thread to sleep until either a frame is ready or the timeout expires. Similar to WaitObject() in the Windows API.

Just a thought. Thanks for listening.

	//
	class NullListener : public ic4::QueueSinkListener {
	public:
		// caution! this callback is in a different thread
		void framesQueued(ic4::QueueSink& qsink) override {
			// do nothing rather than popping a queued image
			// auto image = qsink.popOutputBuffer();
		}
	}

	// N.B. No error checking for brevity
	int main()
	{
		ic4::initLibrary();
		// 1 device. use it
		auto device_list = ic4::DeviceEnum::enumDevices();	
		ic4::DeviceInfo di = device_list[0]
		//
		ic4::Grabber grabber;
		grabber.deviceOpen(di.serial());
		// create a queue sink with the null listener. 
		NullListener nl;
		auto qsink = ic4::QueueSink::create(nl);
		// hook up grabber sink and run grabber.
		grabber.streamSetup(qsink, ic4::StreamSetupOption::AcquisitionStart);
		// loop - this polled model is operating in the *same* thread
		while (true) {
			// image d'tor will handle image recycling
                        // make popOutputBuffer a blocking call?
			auto image = qsink->popOutputBuffer(std::chrono::seconds(10));
			if (!image)
				continue;
			// do work with the image ...
		}
		grabber.streamStop();	
		grabber.deviceClose();
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions