您当前的位置: 首页 > 

qianbo_insist

暂无认证

  • 1浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

一种流水线方式处理远程视频的方案

qianbo_insist 发布时间:2022-10-15 21:50:15 ,浏览量:1

目的

目的是为了流水处理网络视频,所有处理都为线程,每个线程单元都从TThreadRunable 继承下来,以下为TThreadRunable 基础类。从读,解码,处理算法,压缩,到发送,几个部分合成一整个流程,其中算法处理比较耗时,最后要显示到web浏览器里面,所有最后处理算法以后又直接通过websocket送到浏览器显示。远程视频这里启用的是rtsp视频。 在这里插入图片描述

#ifndef _TTHREAD_RUN_ABLE_H_
#define _TTHREAD_RUN_ABLE_H_


#include 
#include 
#include 
#include 
#include 
using namespace std;

class TThreadRunable
{
private:

	//线程
	thread _thread;
	//等待信号
	std::mutex _signal_mutex;
	std::condition_variable _cond;
protected:
	//char  _running = false;
	char _stop = true;
	//锁定运行状态
	std::mutex _mutex;
public:
	TThreadRunable()
	{}
	virtual ~TThreadRunable()
	{}

public:
	char * status(){
		return &_stop;
	}
	
	void Join()
	{
		if (_thread.joinable())
			_thread.join();
	}
	bool  IsStop()
	{
		return _stop == 1 ? true : false;
	}

	void WaitForSignal()
	{
		std::unique_lock ul(_signal_mutex);
		_cond.wait(ul);
	}
	void Notify()
	{
		_cond.notify_one();
	}

	virtual int Start()
	{
		if (_stop == 0)
			return -1;
		_stop = 0;
		_thread = std::thread(std::bind(&TThreadRunable::Run, this));
		return 0;
	}	
	
	virtual void Stop()
	{
		_stop = 1; // true;
	}

	virtual void Run() = 0;
};
#endif
定义流程中第一个读

注意其中的SetNextProcess 函数。

#pragma once
#include 
#include 
#include "TThreadRunable.h"
#include "config.h"
#include 
#include "TQueue.h"
#include 
typedef enum open_type
{
	_type_usb,
	_type_rtsp,
	_type_rtsp_live555
}open_type;


class TProcessRead :public TThreadRunable
{
	cv::VideoCapture cap;
	open_type _type;
	int _show = 0;
	vconfig * _videoconfig = NULL;
	func_cb_send _cs = NULL;
	string _name;
public:
	void Set(open_type type, string name,vconfig * obj)
	{
		_name = name;
		_type = type;
		_videoconfig = obj;
	}
	void SetNextProcess(func_cb_send cs)
	{
		_cs = cs;
	}


	Group_Mat* ReadFrame()
	{
		Group_Mat * gm = new Group_Mat();
		if (gm == NULL)
		{
			cout _bgrMat.empty())
		{
			delete gm;
			cout width);
		cap.set(cv::CAP_PROP_FRAME_HEIGHT, _videoconfig->height);
		//cap.set(cv::CAP_PROP_FPS, _videoconfig->fps);	cap.open(0);
		cv::CAP_PROP_CHANNEL
		//VideoCapture cap(0);
		//cap.set(CAP_PROP_FRAME_WIDTH, 1920);
		//cap.set(CAP_PROP_FRAME_HEIGHT, 1080);
		//cv::CAP_CROSSBAR_INPIN_TYPE 
		//cap.set(cv::CAP_CROSSBAR_INPIN_TYPE , 6);

		//Mat img;
		//namedWindow("test", WINDOW_NORMAL);
		//resizeWindow("test", 960, 640);

		if (!cap.isOpened())
		{
			cout             
关注
打赏
1663161521
查看更多评论
0.0588s