Commit 0ba2cf40 by lenz su

添加音频读取

parent b04e98a8
......@@ -33,6 +33,7 @@ include(VideoDecoder/VideoDecoder.pri)
SOURCES += \
src/Video/ShowVideoWidget.cpp \
src/audio/PlayThread.cpp \
src/main.cpp \
src/Base/FunctionTransfer.cpp \
src/AppConfig.cpp \
......@@ -43,6 +44,7 @@ HEADERS += \
src/AppConfig.h \
src/Base/FunctionTransfer.h \
src/Video/ShowVideoWidget.h \
src/audio/PlayThread.h \
src/mainwindow.h \
src/usb/USBOperator.h \
src/usb/hidapi.h
......@@ -52,3 +54,6 @@ FORMS += \
src/mainwindow.ui
INCLUDEPATH += $$PWD/src
LIBS += -L$$PWD/lib/ -lOle32 \
-lksuser
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.10.2, 2020-01-02T10:53:03. -->
<!-- Written by QtCreator 4.10.2, 2020-01-04T16:33:07. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......@@ -71,7 +71,7 @@
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/sulin/Documents/QT_PAIR_RECEIVE2/rjb</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/sulin/Documents/QT_PAIR_RECEIVE/rjb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
......
......@@ -5,6 +5,9 @@
*/
#include "VideoDecoder.h"
#include "QDataStream"
#include "iostream"
using namespace std;
VideoDecoder::VideoDecoder()
{
......
......@@ -11,7 +11,9 @@
#include <string.h>
#include <QDebug>
#include <list>
#include "iostream"
#include "QDateTime"
using namespace std;
NALUParsing::NALUParsing()
{
......@@ -85,6 +87,7 @@ T_NALU *NALUParsing::getNextFrame()
/// 现在 pos和pos_2之间的数据就是一帧数据了
/// 把他取出来
cout<<"time get frame:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
///由于传递给ffmpeg解码的数据 需要带上起始码 因此这里的nalu带上了起始码
Buf = mH264Buffer + pos; //这帧数据的起始数据(包含起始码)
......
......@@ -2,6 +2,7 @@
#include <QDebug>
#include "usb/USBOperator.h"
#include<QApplication>
#include "QDateTime"
#define MAX_PAYLOAD 1012
typedef struct USB_FRAM_S{
......@@ -27,10 +28,9 @@ void hid_thread::run()
int res = hid_read(hid_fd,buffer, 2048);
qDebug("res = %d", res);
// FILE *h264Fp = fopen("out.log","wb");
char buff[2048];
while(true) {
//memset(buffer, 0, 2048);
memset(buffer, 0, 2048);
res = hid_read(hid_fd,buffer, 2048);
if (res ==-1) {
QApplication* app;
......@@ -40,15 +40,13 @@ void hid_thread::run()
msleep(100);
continue;
}
cout<<"youle"<<endl;
cout<<"pUsbFram1:"<<pUsbFram1->id<<endl;
cout<<"pUsbFram1->buff[0]"<<pUsbFram1->head<<endl;
cout<<"pUsbFram1->buff[1]"<<pUsbFram1->length<<endl;
cout<<"pUsbFram1->head"<<pUsbFram1->head<<endl;
cout<<"pUsbFram1->length"<<pUsbFram1->length<<endl;
cout<<"pUsbFram2:"<<pUsbFram2->id<<endl;
cout<<"pUsbFram2->buff[0]"<<pUsbFram2->head<<endl;
cout<<"pUsbFram2->buff[1]"<<pUsbFram2->length<<endl;
cout<<"pUsbFram2->head"<<pUsbFram2->head<<endl;
cout<<"pUsbFram2->length"<<pUsbFram2->length<<endl;
if(0x44332222==pUsbFram1->head){
//查询角色返回
......@@ -73,6 +71,7 @@ void hid_thread::run()
hid_write(hid_fd,(unsigned char *)usb_buf_re,2049);
mcb(SCREEN_SHOT_START);
}
//停止投屏
if(pUsbFram1->buff[0] == 0x02&&pUsbFram1->buff[1] == 0x02){
cout<<"stop screen shot"<<endl;
isPlay=false;
......@@ -120,7 +119,8 @@ void hid_thread::run()
continue;
}
if(isPlay==false){
if(isPlay==false){
cout<<"bu bo fang"<<endl;
mcb(SCREEN_SHOT_STOP);
continue;
}
......@@ -130,11 +130,10 @@ void hid_thread::run()
qDebug("delay 1 ");
msleep(10);
}
cout<<"time send decode:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
int nCount = pNaluParsing->inputH264Data(pUsbFram1->buff,pUsbFram1->length);
qDebug("fram id:%d %d ", pUsbFram1->id, pUsbFram1->length);
memset(buff, 0x00, sizeof (buff));
sprintf(buff, "fram id:%d %d\n", pUsbFram1->id, pUsbFram1->length);
// fwrite(buff, 1, strlen(buff), h264Fp);
if((frameId+1)!=pUsbFram1->id){
qDebug("fram id error current id %d real id %d",frameId, pUsbFram1->id);
}
......@@ -146,18 +145,26 @@ void hid_thread::run()
qDebug("delay 2 ");
msleep(10);
}
cout<<"time send decode:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
int nCount = pNaluParsing->inputH264Data(pUsbFram2->buff,pUsbFram2->length);
qDebug("fram id:%d %d ", pUsbFram2->id, pUsbFram2->length);
memset(buff, 0x00, sizeof (buff));
sprintf(buff, "fram id:%d %d\n", pUsbFram2->id, pUsbFram2->length);
// fwrite(buff, 1, strlen(buff), h264Fp);
if((frameId+1)!=pUsbFram2->id){
qDebug("fram id error current id %d real id %d",frameId, pUsbFram2->id);
}
frameId=pUsbFram2->id;
}
/* if(pUsbFram1->head == 0x44332233) {
cout<<"you yin pin data"<<endl;
playThread->play(pUsbFram1->buff,pUsbFram1->length);
}
if(pUsbFram2->head == 0x44332233) {
cout<<"you yin pin data"<<endl;
playThread->play(pUsbFram2->buff,pUsbFram2->length);
}*/
}
}
void hid_thread::setCallback(Func cb){
......
......@@ -5,7 +5,7 @@
#include "NALUParsing.h"
#include "usb/hidapi.h"
#include "iostream"
#include "audio/PlayThread.h"
using namespace std;
typedef std::function<void(int s)> Func;
......@@ -16,15 +16,18 @@ public:
bool isPlay=false;
hid_device *hid_fd;
NALUParsing *pNaluParsing;
PlayThread *playThread;
void setCallback(Func cb);
hid_thread(){
}
hid_thread(NALUParsing *p,hid_device *hid){
hid_thread(NALUParsing *p,hid_device *hid,PlayThread *play ){
playThread=play;
pNaluParsing=p;
hid_fd=hid;
hid_thread();
}
protected:
Func mcb;
......
No preview for this file type
......@@ -21,8 +21,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_MainWindow_t {
QByteArrayData data[8];
char stringdata0[82];
QByteArrayData data[6];
char stringdata0[47];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
......@@ -36,14 +36,11 @@ QT_MOC_LITERAL(1, 11, 12), // "slotBtnClick"
QT_MOC_LITERAL(2, 24, 0), // ""
QT_MOC_LITERAL(3, 25, 9), // "isChecked"
QT_MOC_LITERAL(4, 35, 6), // "onRole"
QT_MOC_LITERAL(5, 42, 4), // "role"
QT_MOC_LITERAL(6, 47, 26), // "on_pushButton_play_clicked"
QT_MOC_LITERAL(7, 74, 7) // "checked"
QT_MOC_LITERAL(5, 42, 4) // "role"
},
"MainWindow\0slotBtnClick\0\0isChecked\0"
"onRole\0role\0on_pushButton_play_clicked\0"
"checked"
"onRole\0role"
};
#undef QT_MOC_LITERAL
......@@ -53,7 +50,7 @@ static const uint qt_meta_data_MainWindow[] = {
8, // revision
0, // classname
0, 0, // classinfo
4, 14, // methods
2, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
......@@ -61,16 +58,12 @@ static const uint qt_meta_data_MainWindow[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 1, 34, 2, 0x08 /* Private */,
4, 1, 37, 2, 0x08 /* Private */,
6, 0, 40, 2, 0x08 /* Private */,
6, 1, 41, 2, 0x08 /* Private */,
1, 1, 24, 2, 0x08 /* Private */,
4, 1, 27, 2, 0x08 /* Private */,
// slots: parameters
QMetaType::Void, QMetaType::Bool, 3,
QMetaType::Void, QMetaType::Int, 5,
QMetaType::Void,
QMetaType::Void, QMetaType::Bool, 7,
0 // eod
};
......@@ -83,7 +76,6 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
switch (_id) {
case 0: _t->slotBtnClick((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 1: _t->onRole((*reinterpret_cast< int(*)>(_a[1]))); break;
default: ;
}
}
......@@ -120,13 +112,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 4)
if (_id < 2)
qt_static_metacall(this, _c, _id, _a);
_id -= 4;
_id -= 2;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 4)
if (_id < 2)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 4;
_id -= 2;
}
return _id;
}
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -7,6 +7,7 @@ obj/Obj/NALUParsing.o
obj/Obj/ReadVideoFileThread.o
obj/Obj/hid_thread.o
obj/Obj/ShowVideoWidget.o
obj/Obj/PlayThread.o
obj/Obj/main.o
obj/Obj/FunctionTransfer.o
obj/Obj/AppConfig.o
......
......@@ -7,6 +7,7 @@ obj/Obj/NALUParsing.o
obj/Obj/ReadVideoFileThread.o
obj/Obj/hid_thread.o
obj/Obj/ShowVideoWidget.o
obj/Obj/PlayThread.o
obj/Obj/main.o
obj/Obj/FunctionTransfer.o
obj/Obj/AppConfig.o
......
#include "PlayThread.h"
#include "iostream"
using namespace std;
#define REFTIMES_PER_SEC 10000000
#define REFTIMES_PER_MILLISEC 10000
#define EXIT_ON_ERROR(hres) \
if (FAILED(hres)) { goto Exit; }
#define SAFE_RELEASE(punk) \
if ((punk) != NULL) { (punk)->Release(); (punk) = NULL; }
BOOL bDone = FALSE;
BOOL goOn =TRUE;
BOOL pause=FALSE;
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
const IID IID_IAudioClient = __uuidof(IAudioClient);
const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
BYTE *audioBuffer= (uint8_t*)malloc(1920);
FILE *fp = NULL;
int blockAlign=4;
int bufferlength=0;
PlayThread::PlayThread(){
}
BOOL PlayThread::AdjustFormatTo16Bits(WAVEFORMATEX *pwfx)
{
BOOL bRet(FALSE);
if(pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
pwfx->wFormatTag = WAVE_FORMAT_PCM;
else if(pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
{
PWAVEFORMATEXTENSIBLE pEx = reinterpret_cast<PWAVEFORMATEXTENSIBLE>(pwfx);
if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, pEx->SubFormat))
{
pEx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
pEx->Samples.wValidBitsPerSample = 16;
}
}
else
return bRet;
pwfx->wBitsPerSample = 16;
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample / 8;
pwfx->nAvgBytesPerSec = pwfx->nBlockAlign * pwfx->nSamplesPerSec;
bRet = TRUE;
return bRet;
}
void PlayThread::initPlay()
{
HRESULT hr;
REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC;
REFERENCE_TIME hnsActualDuration;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
IAudioClient *pAudioClient = NULL;
IAudioRenderClient *pRenderClient = NULL;
WAVEFORMATEX *pwfx = NULL;
UINT32 bufferFrameCount;
UINT32 numFramesAvailable;
UINT32 numFramesPadding;
BYTE *pData;
DWORD flags = 0;
hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
hr = pDevice->Activate(IID_IAudioClient, CLSCTX_ALL, NULL, (void**)&pAudioClient);
hr = pAudioClient->GetMixFormat(&pwfx);
AdjustFormatTo16Bits(pwfx);
hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, hnsRequestedDuration, 0, pwfx, NULL);
// Tell the audio source which format to use.
// Get the actual size of the allocated buffer.
hr = pAudioClient->GetBufferSize(&bufferFrameCount);
hr = pAudioClient->GetService(IID_IAudioRenderClient, (void**)&pRenderClient);
// Grab the entire buffer for the initial fill operation.
hr = pRenderClient->GetBuffer(bufferFrameCount, &pData);
// Load the initial data into the shared buffer.
hr = pRenderClient->ReleaseBuffer(bufferFrameCount, flags);
// Calculate the actual duration of the allocated buffer.
hnsActualDuration = (double)REFTIMES_PER_SEC * bufferFrameCount / pwfx->nSamplesPerSec;
hr = pAudioClient->Start(); // Start playing.
}
void PlayThread::play(BYTE *pData,int length){
/* if(length==384){
pRenderClient->GetBuffer(length/4, &pData);
pRenderClient->ReleaseBuffer(length/4, flags);
cout<<"play384"<<endl;
}
if(length==1012){
if(bufferlength>0){
bufferlength=0;
memset(audioBuffer,0,1920);
}
memcpy(audioBuffer ,pData, length);
bufferlength+=length;
cout<<"play add 1012"<<endl;
}
if(length==(1920-1012)){
if(bufferlength==1012){
memcpy(audioBuffer+1012 ,pData, length);
bufferlength+=length;
cout<<"play 1920-1012"<<endl;
pRenderClient->GetBuffer(length/4, &audioBuffer);
pRenderClient->ReleaseBuffer(length/4, flags);
cout<<"play wanle"<<endl;
}
memset(audioBuffer,0,1920);
bufferlength=0;
}*/
}
void PlayThread::run(){
initPlay();
}
#ifndef PLAY_H
#define PLAY_H
#endif // PLAY_H
#include <mmdeviceapi.h>
#include <Audioclient.h>
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <QThread>
using namespace std;
class PlayThread:public QThread{
public:
PlayThread();
void initPlay();
BOOL AdjustFormatTo16Bits(WAVEFORMATEX *pwfx);
void play(BYTE *ppData,int length);
private:
IAudioRenderClient *pRenderClient = NULL;
DWORD flags = 0;
void run() override;
};
......@@ -6,7 +6,7 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDateTime"
#include <QDebug>
#include <QMessageBox>
......@@ -33,8 +33,9 @@ ui=new Ui::MainWindow;
// usb->setCallback(onRole);
// usb->start();
hidThread=new hid_thread(mNaluParsing,usb->getHidDevice());
PlayThread *playThread=new PlayThread;
// playThread->start();
hidThread=new hid_thread(mNaluParsing,usb->getHidDevice(),playThread);
hidThread->setCallback(onRole);
hidThread->start();
mReadVideoFileThread = new ReadVideoFileThread(mNaluParsing);
......@@ -102,9 +103,9 @@ void MainWindow::onDisplayVideo(std::shared_ptr<VideoFrame> videoFrame, int fram
if(hidThread->isPlay==false){
return;
}
cout<<"time send play:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
ui->label_frameNum->setText(QString("%1").arg(frameNum));
ui->widget_videoPlayer->inputOneFrame(videoFrame);
}
......
......@@ -32,9 +32,7 @@ private slots:
void slotBtnClick(bool isChecked);
static void onRole(int role);
///以下函数,是播放器的回调函数,用于输出信息给界面
void on_pushButton_play_clicked();
void on_pushButton_play_clicked(bool checked);
protected:
///显示视频数据,此函数不宜做耗时操作,否则会影响播放的流畅性。
......
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