// mainwindow.h
std::map<std::string, std::unique_ptr<PGCapture>>captures;
// mycaptures.h
class MyCaptures : public sigc::trackable {
// all other members
sigc::signal<void, Buffer> new_frame; // i create instance of buffer in new_sample method in pipeline.cpp so that i can send frame of pipeline.cpp new_sample to prepare frame on mainwindow.cpp
Pipeline streamer; // this object does all the streaming to new_sample in pipeline.cpp. MyCapture just wrap it with additional logic
}
//main.cpp
int main(int argc, char *argv[])
{
Gst::init(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
// mainwindow.cpp
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
connect(ui->managePlay, SIGNAL(pressed()), this, SLOT(open_file()));
// alot of other connections
}
void MainWindow::open_player() {
ui->stackedWidget->setCurrentWidget(ui->playerMenu);
}
void MainWindow::open_file() {
std::map<std::string, std::string> inst_settings = {
{"rtspsrc.location", "rtsp://192.xxx.x.yy:554/H.264/media.smp"}
};
this->set_capture(file, "cam00", "h264ip_appsink", inst_settings);
inst_settings["rtspsrc.location"] = "rtsp://192.xxx.x.xx:554/H.264/media.smp";
this->set_capture(file, "cam01", "h264ip_appsink", inst_settings);
}
void MainWindow::set_capture(... // settings) {
this->captures[cap_name] = std::unique_ptr<MyCapture>(new MyCapture());
this->captures[cap_name]->setup_stream(this->get_default_settings(file, cap_name, stream_config, settings));
this->captures[cap_name]->new_frame.connect(sigc::mem_fun(*this, &MainWindow::prepare_frame)); //sigc signal included to connect new frame and prepare_frame
}
// here comes buffers from all concurent streams
void MainWindow::prepare_frame(gstpg::PGBuffer buffer) {
image = image.scaledToWidth(320, Qt::SmoothTransformation);
if (!image.isNull()) {
if (buffer.id == "cam00") {
this->show_frame(buffer.id, image,0,0);
}
if (buffer.id == "cam01") {
this->show_frame(buffer.id,image,0,1);
}
}
void MainWindow
::show_frame(const std
::string &cap_name,
const QImage & image,
const int x,
const int y
) {
QLabel *pixmap
= (QLabel *)ui
->streamPlayerTable
->cellWidget
(x,y
)->findChild<QLabel
*>
();
pixmap->setPixmap(map);
}
// pipeline.cpp
void Pipeline::set_appsink(const Glib::ustring &name)
{
g_signal_connect(appsink->gobj(), "new-sample", G_CALLBACK(&Pipeline::on_new_sample), (gpointer)this);
}
GstFlowReturn Pipeline::on_new_sample(GstAppSink* sink, gpointer gSelf)
{
auto sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
if (sample != NULL) {
auto self = reinterpret_cast<Pipeline*>(gSelf);
if (self->sample != NULL) {
gst_sample_unref(self->sample);
}
self->sample = sample;
GstBuffer* gst_buffer = gst_sample_get_buffer(self->sample);
if (gst_buffer != NULL) {
GstCaps *caps = gst_sample_get_caps(sample);
if (GST_IS_CAPS (caps) && gst_caps_is_fixed (caps)) {
GstMapInfo info;
GstStructure *structure = gst_caps_get_structure (caps, 0);
int w = 0;
int h = 0;
// // add all possible stuff here. Check if they exists
gst_structure_get_int (structure, "width", &w);
gst_structure_get_int (structure, "height", &h);
gst_buffer_map (gst_buffer, &info, GST_MAP_READ);
self->buffer.width = w;
self->buffer.height = h;
self->buffer.data = info.data;
self->buffer.id = self->settings.stream_id;
gst_buffer_unmap(gst_buffer, &info);
self->frame_formated.emit(self->buffer);
}
}
}
return GST_FLOW_OK;
}
// mainwindow.h
std::map<std::string, std::unique_ptr<PGCapture>>captures;
// mycaptures.h
class MyCaptures : public sigc::trackable {
// all other members
sigc::signal<void, Buffer> new_frame; // i create instance of buffer in new_sample method in pipeline.cpp so that i can send frame of pipeline.cpp new_sample to prepare frame on mainwindow.cpp
Pipeline streamer; // this object does all the streaming to new_sample in pipeline.cpp. MyCapture just wrap it with additional logic
}
//main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Gst::init(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
// mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
connect(ui->managePlay, SIGNAL(pressed()), this, SLOT(open_file()));
// alot of other connections
}
void MainWindow::open_player() {
ui->stackedWidget->setCurrentWidget(ui->playerMenu);
}
void MainWindow::open_file() {
std::map<std::string, std::string> inst_settings = {
{"rtspsrc.location", "rtsp://192.xxx.x.yy:554/H.264/media.smp"}
};
this->set_capture(file, "cam00", "h264ip_appsink", inst_settings);
inst_settings["rtspsrc.location"] = "rtsp://192.xxx.x.xx:554/H.264/media.smp";
this->set_capture(file, "cam01", "h264ip_appsink", inst_settings);
}
void MainWindow::set_capture(... // settings) {
this->captures[cap_name] = std::unique_ptr<MyCapture>(new MyCapture());
this->captures[cap_name]->setup_stream(this->get_default_settings(file, cap_name, stream_config, settings));
this->captures[cap_name]->new_frame.connect(sigc::mem_fun(*this, &MainWindow::prepare_frame)); //sigc signal included to connect new frame and prepare_frame
}
// here comes buffers from all concurent streams
void MainWindow::prepare_frame(gstpg::PGBuffer buffer) {
QImage image = QImage(buffer.data, buffer.width, buffer.height, QImage::Format_RGB888);
image = image.scaledToWidth(320, Qt::SmoothTransformation);
if (!image.isNull()) {
if (buffer.id == "cam00") {
this->show_frame(buffer.id, image,0,0);
}
if (buffer.id == "cam01") {
this->show_frame(buffer.id,image,0,1);
}
}
void MainWindow::show_frame(const std::string &cap_name, const QImage & image, const int x, const int y)
{
QPixmap map = QPixmap::fromImage(image);
QLabel *pixmap = (QLabel *)ui->streamPlayerTable->cellWidget(x,y)->findChild<QLabel*>();
pixmap->setPixmap(map);
}
// pipeline.cpp
void Pipeline::set_appsink(const Glib::ustring &name)
{
g_signal_connect(appsink->gobj(), "new-sample", G_CALLBACK(&Pipeline::on_new_sample), (gpointer)this);
}
GstFlowReturn Pipeline::on_new_sample(GstAppSink* sink, gpointer gSelf)
{
auto sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
if (sample != NULL) {
auto self = reinterpret_cast<Pipeline*>(gSelf);
if (self->sample != NULL) {
gst_sample_unref(self->sample);
}
self->sample = sample;
GstBuffer* gst_buffer = gst_sample_get_buffer(self->sample);
if (gst_buffer != NULL) {
GstCaps *caps = gst_sample_get_caps(sample);
if (GST_IS_CAPS (caps) && gst_caps_is_fixed (caps)) {
GstMapInfo info;
GstStructure *structure = gst_caps_get_structure (caps, 0);
int w = 0;
int h = 0;
// // add all possible stuff here. Check if they exists
gst_structure_get_int (structure, "width", &w);
gst_structure_get_int (structure, "height", &h);
gst_buffer_map (gst_buffer, &info, GST_MAP_READ);
self->buffer.width = w;
self->buffer.height = h;
self->buffer.data = info.data;
self->buffer.id = self->settings.stream_id;
gst_buffer_unmap(gst_buffer, &info);
self->frame_formated.emit(self->buffer);
}
}
}
return GST_FLOW_OK;
}
To copy to clipboard, switch view to plain text mode
Bookmarks