#include <gst/gst.h>
#include <gst/app/gstappsink.h>
#include <sstream>
#include <format>
#include <gst/video/gstvideometa.h>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <mutex>
#include <fstream>

#define MY_GST_USE_OPENCV

#ifdef MY_GST_USE_OPENCV
#include "opencv2/opencv.hpp"

// TODO: use synchronized deque
std::mutex g_mutex;
std::deque<cv::Mat> frameQueue;
#endif // MY_GST_USE_OPENCV

GstFlowReturn new_preroll(GstAppSink* appsink, gpointer data);

GstFlowReturn new_sample(GstAppSink* appsink, gpointer data);

static gboolean my_bus_callback(GstBus* bus, GstMessage* message, gpointer data);

static gint repeats = 2;
static gchar* ndi_name = nullptr;
static gint use_gui = 0;
static gboolean beep = FALSE;

static GOptionEntry entries[] =
{
        { "repeats", 'r', 0, G_OPTION_ARG_INT, &repeats,      "Среднее число повторений N",               "N" },
        { "ndi-name", 'n', 0, G_OPTION_ARG_STRING, &ndi_name, "you can enter the string here (ndi-name)", "M" },
        { "gui", 'g', 0, G_OPTION_ARG_INT, &use_gui,         "use gui",                                  nullptr },
        { "beep", 'b', 0, G_OPTION_ARG_NONE, &beep,           "Сигнал при выполнениии", NULL },
        { NULL }
};