#include "VideoStreamCatcher.h" bool VideoStreamCatcher::m_bStartOrNot = false; VideoStreamCatcher::VideoStreamCatcher() { //init the pointer m_pVideoSource = nullptr; m_pVideoDecoder = nullptr; m_pVideoDataManager = nullptr; m_pSyncProc = nullptr; //init the image m_pOutputImage = nullptr; m_nOutputImageHeight = 0; m_nOutputImageWidth = 0; m_nOutputImagePitch = 0; m_bStartOrNot = false; } VideoStreamCatcher::~VideoStreamCatcher() { delete m_pVideoSource; delete m_pVideoDecoder; delete m_pVideoDataManager; delete m_pSyncProc; delete m_pOutputImage; } bool VideoStreamCatcher::Init(QString strAddress) { CVideoDataManager* pDataMan = new CVideoDataManager(); CVideoSource* pSource = new CVideoSource(); bool bRes = pSource->Init(strAddress.toStdString().c_str(), pDataMan); if (!bRes) return false; CVideoDecoder* pDecode = new CVideoDecoder(pSource->GetVideoDecode(), CVideoSource::IsHardDecode(), pDataMan); CSyncProc::getInstance().AddDataManager(pDataMan); m_pVideoDataManager = pDataMan; m_pVideoDecoder = pDecode; m_pVideoSource = pSource; m_nOutputImageHeight = m_pVideoSource->GetHeight(); m_nOutputImageWidth = m_pVideoSource->GetWidth(); m_nOutputImagePitch = (m_nOutputImageWidth*3+3)/4*4; m_nVideoWidth = m_nOutputImageWidth; m_nVideoHeight = m_nOutputImageHeight; //allocate memory for the output image m_pOutputImage = new unsigned char[m_nOutputImagePitch * m_nOutputImageHeight]; return bRes; } void VideoStreamCatcher::Start() { //check the start flag if (m_bStartOrNot) { return; } CSyncProc::getInstance().Start(); m_bStartOrNot = true; } void VideoStreamCatcher::Stop() { //put off until some time later } void VideoStreamCatcher::GetVideoImage(unsigned char*& pImage, int& nWidth, int& nHeight, int& nPitch) { //check the frame decoder data count if (m_pVideoDataManager->GetDecoderDataCount() >= 0) { //get a frame from the video data manager int nFrameDataSize = m_nOutputImagePitch * m_nOutputImageHeight; double dbAngle = 0; m_pVideoDataManager->GetDecoderData(m_pOutputImage, nFrameDataSize, dbAngle); } //set the image pointer pImage = m_pOutputImage; nWidth = m_nOutputImageWidth; nHeight = m_nOutputImageHeight; nPitch = m_nOutputImagePitch; cv::Mat img(m_nOutputImageHeight,m_nOutputImageWidth , CV_8UC3, m_pOutputImage); }