Commit b04e98a8 by lenz su

修复停止之后屏幕不变黑的问题,原因是停止的时候,已经有之前的视频帧数据在队列中进行解码,解码完成后会继续被送去显示

parent 323b29fd
#include "hid_thread.h" #include "hid_thread.h"
#include <QDebug> #include <QDebug>
#include "usb/USBOperator.h" #include "usb/USBOperator.h"
#include<QApplication> #include<QApplication>
#define MAX_PAYLOAD 1012 #define MAX_PAYLOAD 1012
typedef struct USB_FRAM_S{ typedef struct USB_FRAM_S{
int head; int head;
int id; int id;
...@@ -67,6 +67,7 @@ void hid_thread::run() ...@@ -67,6 +67,7 @@ void hid_thread::run()
//开始投屏 //开始投屏
if(pUsbFram1->buff[0] == 0x01&&pUsbFram1->buff[1] == 0x01){ if(pUsbFram1->buff[0] == 0x01&&pUsbFram1->buff[1] == 0x01){
cout<<"start screen shot"<<endl; cout<<"start screen shot"<<endl;
isPlay=true;
char usb_buf_re[2049] = {0}; char usb_buf_re[2049] = {0};
memcpy(&usb_buf_re[1],buffer, 2048); memcpy(&usb_buf_re[1],buffer, 2048);
hid_write(hid_fd,(unsigned char *)usb_buf_re,2049); hid_write(hid_fd,(unsigned char *)usb_buf_re,2049);
...@@ -74,6 +75,7 @@ void hid_thread::run() ...@@ -74,6 +75,7 @@ void hid_thread::run()
} }
if(pUsbFram1->buff[0] == 0x02&&pUsbFram1->buff[1] == 0x02){ if(pUsbFram1->buff[0] == 0x02&&pUsbFram1->buff[1] == 0x02){
cout<<"stop screen shot"<<endl; cout<<"stop screen shot"<<endl;
isPlay=false;
char usb_buf_re[2049] = {0}; char usb_buf_re[2049] = {0};
memcpy(&usb_buf_re[1],buffer, 2048); memcpy(&usb_buf_re[1],buffer, 2048);
hid_write(hid_fd,(unsigned char *)usb_buf_re,2049); hid_write(hid_fd,(unsigned char *)usb_buf_re,2049);
...@@ -99,13 +101,16 @@ void hid_thread::run() ...@@ -99,13 +101,16 @@ void hid_thread::run()
//开始投屏 //开始投屏
if(pUsbFram2->buff[0] == 0x01&&pUsbFram2->buff[1] == 0x01){ if(pUsbFram2->buff[0] == 0x01&&pUsbFram2->buff[1] == 0x01){
cout<<"start screen shot"<<endl; cout<<"start screen shot"<<endl;
isPlay=true;
char usb_buf_re[2049] = {0}; char usb_buf_re[2049] = {0};
memcpy(&usb_buf_re[1024],buffer, 2048); memcpy(&usb_buf_re[1024],buffer, 2048);
hid_write(hid_fd,(unsigned char *)usb_buf_re,2049); hid_write(hid_fd,(unsigned char *)usb_buf_re,2049);
mcb(SCREEN_SHOT_START); mcb(SCREEN_SHOT_START);
} }
if(pUsbFram2->buff[0] == 0x02&&pUsbFram2->buff[1] == 0x02){ if(pUsbFram2->buff[0] == 0x02&&pUsbFram2->buff[1] == 0x02){
cout<<"stop screen shot"<<endl; cout<<"stop screen shot"<<endl;
isPlay=false;
char usb_buf_re[2049] = {0}; char usb_buf_re[2049] = {0};
memcpy(&usb_buf_re[1024],buffer, 2048); memcpy(&usb_buf_re[1024],buffer, 2048);
hid_write(hid_fd,(unsigned char *)usb_buf_re,2049); hid_write(hid_fd,(unsigned char *)usb_buf_re,2049);
...@@ -115,7 +120,10 @@ void hid_thread::run() ...@@ -115,7 +120,10 @@ void hid_thread::run()
continue; continue;
} }
if(isPlay==false){
mcb(SCREEN_SHOT_STOP);
continue;
}
if(pUsbFram1->head == 0x44332211) { if(pUsbFram1->head == 0x44332211) {
while (pNaluParsing->lock) { while (pNaluParsing->lock) {
...@@ -148,6 +156,8 @@ void hid_thread::run() ...@@ -148,6 +156,8 @@ void hid_thread::run()
} }
frameId=pUsbFram2->id; frameId=pUsbFram2->id;
} }
} }
} }
void hid_thread::setCallback(Func cb){ void hid_thread::setCallback(Func cb){
......
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
#include "NALUParsing.h" #include "NALUParsing.h"
#include "usb/hidapi.h" #include "usb/hidapi.h"
#include "iostream" #include "iostream"
using namespace std; using namespace std;
typedef std::function<void(int s)> Func; typedef std::function<void(int s)> Func;
class hid_thread:public QThread class hid_thread:public QThread
{ {
public: public:
bool isPlay=false;
hid_device *hid_fd; hid_device *hid_fd;
NALUParsing *pNaluParsing; NALUParsing *pNaluParsing;
void setCallback(Func cb); void setCallback(Func cb);
......
No preview for this file type
...@@ -99,6 +99,9 @@ void MainWindow::slotBtnClick(bool isChecked) ...@@ -99,6 +99,9 @@ void MainWindow::slotBtnClick(bool isChecked)
///显示视频数据,此函数不宜做耗时操作,否则会影响播放的流畅性。 ///显示视频数据,此函数不宜做耗时操作,否则会影响播放的流畅性。
void MainWindow::onDisplayVideo(std::shared_ptr<VideoFrame> videoFrame, int frameNum) void MainWindow::onDisplayVideo(std::shared_ptr<VideoFrame> videoFrame, int frameNum)
{ {
if(hidThread->isPlay==false){
return;
}
ui->label_frameNum->setText(QString("%1").arg(frameNum)); ui->label_frameNum->setText(QString("%1").arg(frameNum));
ui->widget_videoPlayer->inputOneFrame(videoFrame); ui->widget_videoPlayer->inputOneFrame(videoFrame);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment