SpireCV/video_io/driver/sv_camera_GX40.cpp

86 lines
2.0 KiB
C++

/*
* @Description:
* @Author: L LC @amov
* @Date: 2023-12-19 18:30:17
* @LastEditors: L LC @amov
* @LastEditTime: 2023-12-21 17:57:02
* @FilePath: /SpireCV/video_io/driver/sv_camera_GX40.cpp
*/
#include "sv_camera_privately.h"
#include <fstream>
class sv_camera_GX40 : public sv_p::CameraBase
{
private:
std::string _ip;
uint16_t _port = 554;
public:
bool setStream(const std::string &ip, uint16_t port);
sv::CameraType getType(void) { return sv::CameraType::GX40; }
std::string getName(void) { return _ip; }
bool open(void);
sv_camera_GX40(int timeOut);
~sv_camera_GX40();
static CameraBase *creat(int timeOut)
{
return new sv_camera_GX40(timeOut);
}
};
sv_camera_GX40::sv_camera_GX40(int timeOut) : sv_p::CameraBase(timeOut)
{
}
bool sv_camera_GX40::setStream(const std::string &ip, uint16_t port)
{
bool ret = false;
if (!this->cap.isOpened())
{
this->_ip = ip;
this->_port = port;
ret = true;
}
return ret;
}
// 无论如何都用gst打开 因此安装的时候必须安装gst
bool sv_camera_GX40::open(void)
{
bool ret = false;
std::ostringstream pipeline;
pipeline << "rtspsrc location = rtsp://user:0000@" << this->_ip << ":" << this->_port
<< "/cam/realmonitor?channel=1&subtype=0 latency=100 ! application/x-rtp,media=video ! "
<< "rtph265depay ! parsebin ! ";
#ifdef PLATFORM_JETSON
pipeline << "nvv4l2decoder ! nvvidconv flip-method=4 ! ";
#else
pipeline << "avdec_h265 ! videoscale ! ";
#endif
pipeline << "video/x-raw,format=(string)BGRx"
<< ",width=(int)" << this->getW()
<< ",height=(int)" << this->getH()
<< " ";
#ifndef PLATFORM_JETSON
pipeline << "! videoflip video-direction=4 ";
#endif
pipeline << " ! videoconvert ! video/x-raw,format=(string)BGR ! appsink sync=false";
if (this->cap.open(pipeline.str(), cv::CAP_GSTREAMER))
{
// 开启读取线程
std::thread readLoop(&CameraBase::readThread, this);
this->readThreadHandle = readLoop.native_handle();
readLoop.detach();
ret = true;
}
return ret;
}