add GStreamer
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
#include <iostream>
|
||||
|
||||
CameraController::CameraController(std::shared_ptr<VxCamera> camera)
|
||||
: camera_(camera), streaming_(false) {}
|
||||
: camera_(camera), gstPipeline_("videoconvert ! autovideosink") {
|
||||
streamingEngine_ = std::make_shared<StreamingEngine>(camera);
|
||||
}
|
||||
|
||||
std::string CameraController::processCommand(const std::string& jsonCommand) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -71,6 +73,8 @@ std::string CameraController::processCommand(const std::string& jsonCommand) {
|
||||
return handleStartStream();
|
||||
} else if (command == "stop_stream") {
|
||||
return handleStopStream();
|
||||
} else if (command == "set_pipeline") {
|
||||
return handleSetPipeline(getParam("pipeline"));
|
||||
} else {
|
||||
return createErrorResponse("Unknown command: " + command);
|
||||
}
|
||||
@@ -78,7 +82,7 @@ std::string CameraController::processCommand(const std::string& jsonCommand) {
|
||||
|
||||
std::string CameraController::handleSetFormat(const std::string& width, const std::string& height,
|
||||
const std::string& framerate, const std::string& format) {
|
||||
if (streaming_) {
|
||||
if (streamingEngine_->isRunning()) {
|
||||
return createErrorResponse("Cannot change format while streaming");
|
||||
}
|
||||
|
||||
@@ -94,6 +98,7 @@ std::string CameraController::handleSetFormat(const std::string& width, const st
|
||||
return createErrorResponse("Failed to set format");
|
||||
}
|
||||
|
||||
streamingEngine_->setFormat(fmt);
|
||||
return createSuccessResponse("Format set successfully");
|
||||
} catch (const std::exception& e) {
|
||||
return createErrorResponse(std::string("Invalid parameters: ") + e.what());
|
||||
@@ -231,34 +236,44 @@ std::string CameraController::handleSetGain(const std::string& value) {
|
||||
|
||||
std::string CameraController::handleGetStatus() {
|
||||
std::ostringstream oss;
|
||||
oss << "{\"status\":\"success\",\"streaming\":" << (streaming_ ? "true" : "false") << "}";
|
||||
oss << "{\"status\":\"success\",\"streaming\":" << (streamingEngine_->isRunning() ? "true" : "false")
|
||||
<< ",\"pipeline\":\"" << gstPipeline_ << "\"}";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string CameraController::handleStartStream() {
|
||||
if (streaming_) {
|
||||
if (streamingEngine_->isRunning()) {
|
||||
return createErrorResponse("Already streaming");
|
||||
}
|
||||
|
||||
if (VxStartStreaming(camera_) != 0) {
|
||||
if (!streamingEngine_->start(gstPipeline_)) {
|
||||
return createErrorResponse("Failed to start streaming");
|
||||
}
|
||||
|
||||
streaming_ = true;
|
||||
return createSuccessResponse("Streaming started");
|
||||
}
|
||||
|
||||
std::string CameraController::handleStopStream() {
|
||||
if (!streaming_) {
|
||||
if (!streamingEngine_->isRunning()) {
|
||||
return createErrorResponse("Not streaming");
|
||||
}
|
||||
|
||||
if (VxStopStreaming(camera_) != 0) {
|
||||
return createErrorResponse("Failed to stop streaming");
|
||||
streamingEngine_->stop();
|
||||
return createSuccessResponse("Streaming stopped");
|
||||
}
|
||||
|
||||
std::string CameraController::handleSetPipeline(const std::string& pipeline) {
|
||||
if (streamingEngine_->isRunning()) {
|
||||
return createErrorResponse("Cannot change pipeline while streaming");
|
||||
}
|
||||
|
||||
streaming_ = false;
|
||||
return createSuccessResponse("Streaming stopped");
|
||||
if (pipeline.empty()) {
|
||||
return createErrorResponse("Pipeline cannot be empty");
|
||||
}
|
||||
|
||||
gstPipeline_ = pipeline;
|
||||
streamingEngine_->setPipelineDescription(pipeline);
|
||||
return createSuccessResponse("Pipeline set successfully");
|
||||
}
|
||||
|
||||
VX_IMAGE_FORMAT CameraController::stringToFormat(const std::string& format) {
|
||||
|
||||
Reference in New Issue
Block a user