#include "../tools/tools.h"

#include <EGrabber.h>

using namespace Euresys;

static void sample() {
    EGenTL genTL; // load GenTL producer
    EGrabber<CallbackOnDemand> grabber(genTL); // create grabber

    grabber.reallocBuffers(20); // prepare 20 buffers

    grabber.start(20); // grab 20 buffers
    for (size_t frame = 0; frame < 20; ++frame) {
        Buffer buffer(grabber.pop()); // wait and get a buffer
        // Note: Class Buffer do not push the current buffer back to the input queue automatically
        // convert the buffer to BGR8
        ConvertedBuffer bgr = buffer.convert(grabber, "BGR8");
        // output the converted buffer
        bgr.saveToDisk(Tools::getEnv("sample-output-path") + "/frame.NNN.jpeg", frame);
        // push the buffer back to the input queue
        buffer.push(grabber);
    }
}

static Tools::Sample addSample(__FILE__, sample, "Simple Grab N frames using Buffer class");
