main.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <QCoreApplication>
  2. #include "modulecomm.h"
  3. #include "xmlparam.h"
  4. #include "imx291frame.h"
  5. imx291frame * gpframe;
  6. std::thread * gpthread;
  7. void * gpa;
  8. bool gbrun = true;
  9. #include <QDateTime>
  10. #ifdef TEST_SAVEH264
  11. #include <QFile>
  12. QFile gFile;
  13. #endif
  14. void ThreadGetData()
  15. {
  16. while(gbrun)
  17. {
  18. iv::h264framendata xframe;
  19. if(gpframe->GetFrame(xframe) == 1)
  20. {
  21. qint64 recvtime = std::chrono::system_clock::now().time_since_epoch().count();
  22. recvtime = recvtime/1000;
  23. double frecvtime = recvtime;
  24. frecvtime = frecvtime/1000000.0;
  25. #ifdef TEST_SAVEH264
  26. static int ncount = 0;
  27. if(ncount<50)
  28. {
  29. gFile.write(xframe.mpstr_ptr.get(),xframe.mdatalen);
  30. gFile.flush();
  31. }
  32. // ncount++;
  33. #endif
  34. // qDebug(" recvtime : %13.6f datatime:%13.6f",frecvtime,xframe.mfrecvtime);
  35. iv::modulecomm::ModuleSendMsg(gpa,xframe.mpstr_ptr.get(),xframe.mdatalen);
  36. // char * str = (char * )xframe.mpstr_ptr.get();
  37. // if(xframe.mdatalen > 5)
  38. // {
  39. // qDebug(" Head: %02x %02x %02x %02x %02x",str[0],str[1],str[2],str[3],str[4]);
  40. // if(str[4] != 0x67)
  41. // {
  42. // int a;
  43. // a= 1;
  44. // }
  45. // }
  46. }
  47. }
  48. }
  49. int main(int argc, char *argv[])
  50. {
  51. QCoreApplication a(argc, argv);
  52. std::string strxmlpath;
  53. if(argc == 1)
  54. {
  55. strxmlpath = "./driver_h264_usbimx291.xml";
  56. }
  57. else
  58. {
  59. strxmlpath = argv[1];
  60. }
  61. #ifdef TEST_SAVEH264
  62. gFile.setFileName("/home/yuchuli/imx291.h264");
  63. gFile.open(QIODevice::ReadWrite);
  64. #endif
  65. iv::xmlparam::Xmlparam xp(strxmlpath);
  66. std::string strdevname = xp.GetParam("devname","/dev/video5");
  67. int nwidth = xp.GetParam("width",1920);
  68. int nheigth = xp.GetParam("height",1080);
  69. int nbitrate = xp.GetParam("bitrate",4000000);
  70. int ngop = xp.GetParam("gop",10);
  71. std::string strframename = xp.GetParam("outmsgname","h264frame");
  72. gpa = iv::modulecomm::RegisterSend(strframename.data(),3000000,1);
  73. gpframe = new imx291frame(strdevname.data(),nwidth,nheigth,nbitrate,ngop);
  74. gpthread = new std::thread(&ThreadGetData);
  75. return a.exec();
  76. }