VideoStreamCatcher.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "VideoStreamCatcher.h"
  2. bool VideoStreamCatcher::m_bStartOrNot = false;
  3. VideoStreamCatcher::VideoStreamCatcher()
  4. {
  5. //init the pointer
  6. m_pVideoSource = nullptr;
  7. m_pVideoDecoder = nullptr;
  8. m_pVideoDataManager = nullptr;
  9. m_pSyncProc = nullptr;
  10. //init the image
  11. m_pOutputImage = nullptr;
  12. m_nOutputImageHeight = 0;
  13. m_nOutputImageWidth = 0;
  14. m_nOutputImagePitch = 0;
  15. m_bStartOrNot = false;
  16. }
  17. VideoStreamCatcher::~VideoStreamCatcher()
  18. {
  19. delete m_pVideoSource;
  20. delete m_pVideoDecoder;
  21. delete m_pVideoDataManager;
  22. delete m_pSyncProc;
  23. delete m_pOutputImage;
  24. }
  25. bool VideoStreamCatcher::Init(QString strAddress)
  26. {
  27. CVideoDataManager* pDataMan = new CVideoDataManager();
  28. CVideoSource* pSource = new CVideoSource();
  29. bool bRes = pSource->Init(strAddress.toStdString().c_str(), pDataMan);
  30. if (!bRes)
  31. return false;
  32. CVideoDecoder* pDecode = new CVideoDecoder(pSource->GetVideoDecode(), CVideoSource::IsHardDecode(), pDataMan);
  33. CSyncProc::getInstance().AddDataManager(pDataMan);
  34. m_pVideoDataManager = pDataMan;
  35. m_pVideoDecoder = pDecode;
  36. m_pVideoSource = pSource;
  37. m_nOutputImageHeight = m_pVideoSource->GetHeight();
  38. m_nOutputImageWidth = m_pVideoSource->GetWidth();
  39. m_nOutputImagePitch = (m_nOutputImageWidth*3+3)/4*4;
  40. m_nVideoWidth = m_nOutputImageWidth;
  41. m_nVideoHeight = m_nOutputImageHeight;
  42. //allocate memory for the output image
  43. m_pOutputImage = new unsigned char[m_nOutputImagePitch * m_nOutputImageHeight];
  44. return bRes;
  45. }
  46. void VideoStreamCatcher::Start()
  47. {
  48. //check the start flag
  49. if (m_bStartOrNot)
  50. {
  51. return;
  52. }
  53. CSyncProc::getInstance().Start();
  54. m_bStartOrNot = true;
  55. }
  56. void VideoStreamCatcher::Stop()
  57. {
  58. //put off until some time later
  59. }
  60. void VideoStreamCatcher::GetVideoImage(unsigned char*& pImage, int& nWidth, int& nHeight, int& nPitch)
  61. {
  62. //check the frame decoder data count
  63. if (m_pVideoDataManager->GetDecoderDataCount() >= 0)
  64. {
  65. //get a frame from the video data manager
  66. int nFrameDataSize = m_nOutputImagePitch * m_nOutputImageHeight;
  67. double dbAngle = 0;
  68. m_pVideoDataManager->GetDecoderData(m_pOutputImage, nFrameDataSize, dbAngle);
  69. }
  70. //set the image pointer
  71. pImage = m_pOutputImage;
  72. nWidth = m_nOutputImageWidth;
  73. nHeight = m_nOutputImageHeight;
  74. nPitch = m_nOutputImagePitch;
  75. cv::Mat img(m_nOutputImageHeight,m_nOutputImageWidth , CV_8UC3, m_pOutputImage);
  76. }