stream optimizations

This commit is contained in:
Maik Jurischka
2025-12-12 14:37:57 +01:00
parent 43a1abdd31
commit 9c9f822f35
10 changed files with 168 additions and 24 deletions

View File

@@ -1,10 +1,11 @@
#include "GStreamerPipeline.h"
#include <iostream>
#include <cstring>
#include <utility>
GStreamerPipeline::GStreamerPipeline(const std::string& pipelineDescription)
GStreamerPipeline::GStreamerPipeline(std::string pipelineDescription)
: pipeline_(nullptr), appsrc_(nullptr), bus_(nullptr), running_(false),
pipelineDescription_(pipelineDescription), width_(0), height_(0) {
pipelineDescription_(std::move(pipelineDescription)), width_(0), height_(0) {
gst_init(nullptr, nullptr);
}
@@ -30,7 +31,7 @@ bool GStreamerPipeline::start() {
}
GError* error = nullptr;
std::string fullPipeline = "appsrc name=source ! " + pipelineDescription_;
const std::string fullPipeline = "appsrc name=source ! " + pipelineDescription_;
pipeline_ = gst_parse_launch(fullPipeline.c_str(), &error);
if (error) {
@@ -106,7 +107,7 @@ void GStreamerPipeline::stop() {
std::cout << "GStreamer pipeline stopped" << std::endl;
}
bool GStreamerPipeline::pushBuffer(uint8_t* data, size_t size, int width, int height, const std::string& format) {
bool GStreamerPipeline::pushBuffer(const uint8_t* data, const size_t size, const int width, const int height, const std::string& format) {
if (!running_ || !appsrc_) {
return false;
}
@@ -119,16 +120,13 @@ bool GStreamerPipeline::pushBuffer(uint8_t* data, size_t size, int width, int he
// Set caps based on format
std::string capsStr;
if (format == "YUY2" || format == "UYVY") {
if (format == "YUY2" || format == "UYVY" || format == "BGR" || format == "RGB") {
capsStr = "video/x-raw,format=" + format + ",width=" + std::to_string(width) +
",height=" + std::to_string(height) + ",framerate=30/1";
} else if (format == "MJPG") {
capsStr = "image/jpeg,width=" + std::to_string(width) +
",height=" + std::to_string(height) + ",framerate=30/1";
} else if (format == "BGR" || format == "RGB") {
capsStr = "video/x-raw,format=" + format + ",width=" + std::to_string(width) +
",height=" + std::to_string(height) + ",framerate=30/1";
} else {
} else {
capsStr = "video/x-raw,width=" + std::to_string(width) +
",height=" + std::to_string(height) + ",framerate=30/1";
}