Commit 9bf1620e by lenz su

音频发送优化

parent 4296f2b2
#include "GetAudioThread.h"
FILE *fp = NULL;
BOOL bDone = FALSE;
#define REFTIMES_PER_SEC 10000000
#define REFTIMES_PER_MILLISEC 10000
......@@ -15,12 +13,10 @@ const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
#define SAFE_RELEASE(punk) \
if ((punk) != NULL) { (punk)->Release(); (punk) = NULL; }
static char usb_buf[2049] = {0};
char buff[2048];
static char usb_buf[1025] = {0};
usb_fram_t *usb_fram = (usb_fram_t *)&usb_buf[1];
usb_fram_t *usb_fram2 = (usb_fram_t *)&usb_buf[1025];
int aid=0;
GetAudioThread::GetAudioThread(){
......@@ -158,14 +154,6 @@ void GetAudioThread::RecordAudioStream()
sendAudioFrame(numFramesAvailable * pwfx->nBlockAlign,(unsigned char*)pData);
cout<<"byte count:"<<numFramesAvailable * pwfx->nBlockAlign<<endl;
//pMySink->CopyData((char *)pOneChannelBuf,960, &bDone);
// unsigned char * pOneChannelBuf=get_oneChannel_left_from_doubleChannel((unsigned char*)pData,numFramesAvailable * pwfx->nBlockAlign,2);
// pcmToAAC->TransPCMToAAC(pOneChannelBuf, 960, data);
// pMySink->CopyData((char *)pOneChannelBuf,960, &bDone);
// hr = pMySink->CopyData((char *)pOneChannelBuf,960, &bDone);
hr = pCaptureClient->ReleaseBuffer(numFramesAvailable);
// EXIT_ON_ERROR(hr,pwfx,pEnumerator, pDevice,pAudioClient,pCaptureClient );
......@@ -176,8 +164,7 @@ void GetAudioThread::RecordAudioStream()
hr = pAudioClient->Stop(); // Stop recording.
EXIT_ON_ERROR(hr,pwfx,pEnumerator, pDevice,pAudioClient,pCaptureClient );
fflush(fp);
fclose(fp);
cout<<"record over";
return ;
......@@ -199,25 +186,26 @@ void GetAudioThread::run(){
void GetAudioThread::sendAudioFrame( int pkt_len,uint8_t *p){
cout<<"pkt le:"<<pkt_len<<endl;
if(pkt_len==384){
/*if(pkt_len==384){
usb_fram->head = 0x44332233;
memcpy(usb_fram->buff, p, pkt_len);
usb_fram->length = pkt_len;
usb_fram->id =++aid;
int res = hid_write(hid_fd, (const unsigned char *)usb_buf, 1025);
}
}*/
if(pkt_len==1920){
usb_fram->head = 0x44332233;
memcpy(usb_fram->buff, p, 1012);
usb_fram->length = 1012;
usb_fram->id =++aid;
int res = hid_write(hid_fd, (const unsigned char *)usb_buf, 1025);
usb_fram->head = 0x44332233;
memcpy(usb_fram->buff, p+1012, 908);
usb_fram->length = 908;
usb_fram->id =++aid;
res = hid_write(hid_fd, (const unsigned char *)usb_buf, 1025);
usb_fram2->head = 0x44332233;
memcpy(usb_fram2->buff, p+1012, 908);
usb_fram2->length = 908;
usb_fram2->id =++aid;
hid_write(hid_fd, (const unsigned char *)usb_buf, 2049);
}
}
......
......@@ -61,13 +61,16 @@ void MainWindow::onRole(int s){
sUI->label->setText(roleStr);
break;
case SCREEN_SHOT_START:{
recordAudio->start();
if(isFirstStartComplete==false){
if (isVedioRecordInitSuccessful== SUCCEED)
{
// cout<<"delay test send frame to usb"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
recordVideo->start();
}
// recordAudio->start();
isFirstStartComplete=true;
}else{
recordVideo->restoreRecord();
......@@ -76,8 +79,8 @@ void MainWindow::onRole(int s){
break;
}
case SCREEN_SHOT_STOP:{
recordVideo->pauseRecord();
cout<<"stop bbbbb"<<endl;
// recordVideo->pauseRecord();
break;
}
}
......
......@@ -3,7 +3,7 @@
#include <QDateTime>
#include<QApplication>
using namespace std;
FILE *fph = fopen("woha","wb");
USBOperator::USBOperator(QObject *parent) : QThread(parent){
hid_init();
......@@ -12,7 +12,7 @@ USBOperator::USBOperator(QObject *parent) : QThread(parent){
qDebug("usb hid open failed!");
}
if (hid_set_nonblocking(hid_fd, 1) < 0) {
if (hid_set_nonblocking(hid_fd, 0) < 0) {
qDebug("hid_set_nonblocking error");
}
......@@ -64,9 +64,9 @@ void USBOperator::run()
char *usb_buf[2048] = {0};
usb_fram_t *usb_fram1 = (usb_fram_t *)(usb_buf);
usb_fram_t *usb_fram2 = (usb_fram_t *)(&usb_buf[1024]);
// hid_set_nonblocking(hid_fd,1);
while (1) {
// msleep(200);
msleep(2000);
memset(usb_buf,0,2048);
if(hid_fd==nullptr){
cout<<"hid not open"<<endl;
......@@ -74,20 +74,23 @@ void USBOperator::run()
}
int res=hid_read(hid_fd,(unsigned char *)usb_buf,2048);
cout<<"read it hid!"<<res<<endl;
if(res!=2048 && res != 1024){
if(res!=2048){
continue;
}
cout<<"res "<< res<<endl;
cout<<"head1 "<< usb_fram1->head<<endl;
cout<<"id1 "<< usb_fram1->id<<endl;
cout<<"length1 "<< usb_fram1->length<<endl;
cout<<"head2 "<< usb_fram2->head<<endl;
cout<<"id2 "<< usb_fram2->id<<endl;
cout<<"length2 "<< usb_fram2->length<<endl;
//角色信息
if(1144201762==usb_fram1->head){
// fwrite(usb_buf,1,2048,fph);
cout<<"frame re res "<< res<<endl;
cout<<"frame re head1 "<< usb_fram1->head<<endl;
cout<<"frame re id1 "<< usb_fram1->id<<endl;
cout<<"frame re length1 "<< usb_fram1->length<<endl;
cout<<"frame re head2 "<< usb_fram2->head<<endl;
cout<<"frame re id2 "<< usb_fram2->id<<endl;
cout<<"frame re length2 "<< usb_fram2->length<<endl;
if(0x44332222==usb_fram1->head){
//查询角色返回
if((usb_fram1->id==ROLE_INFO)&&(usb_fram1->buff[0] == 0x01&&usb_fram1->buff[1] == 0x01)){
if(usb_fram1->buff[2]==ROLE_NOT_SET){
......@@ -113,20 +116,20 @@ void USBOperator::run()
}
}
if((usb_fram1->id==SCREEN_SHOT)){
//开始投屏
if(usb_fram1->buff[0] == 0x01&&usb_fram1->buff[1] == 0x01){
cout<<"start screen shot"<<endl;
char usb_buf_re[1025] = {0};
memcpy(&usb_buf_re[1],usb_buf, 1024);
// char usb_buf_re[1025] = {0};
// memcpy(&usb_buf_re[1],usb_buf, 1024);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb(SCREEN_SHOT_START);
}
if(usb_fram1->buff[0] == 0x02&&usb_fram1->buff[1] == 0x02){
cout<<"stop screen shot"<<endl;
char usb_buf_re[1025] = {0};
memcpy(&usb_buf_re[1],usb_buf, 1024);
// char usb_buf_re[1025] = {0};
// memcpy(&usb_buf_re[1],usb_buf, 1024);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb(SCREEN_SHOT_STOP);
}
......@@ -136,20 +139,21 @@ void USBOperator::run()
//开始投屏
if(usb_fram2->buff[0] == 0x01&&usb_fram2->buff[1] == 0x01){
cout<<"start screen shot"<<endl;
char usb_buf_re[1025] = {0};
memcpy(&usb_buf_re[1],usb_buf+1024, 1024);
// char usb_buf_re[1025] = {0};
// memcpy(&usb_buf_re[1],usb_buf+1024, 1024);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb(SCREEN_SHOT_START);
}
if(usb_fram2->buff[0] == 0x02&&usb_fram2->buff[1] == 0x02){
cout<<"stop screen shot"<<endl;
char usb_buf_re[1025] = {0};
memcpy(&usb_buf_re[1],usb_buf+1024, 1024);
// char usb_buf_re[1025] = {0};
// memcpy(&usb_buf_re[1],usb_buf+1024, 1024);
//hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb(SCREEN_SHOT_STOP);
}
}
}
}
}
......
......@@ -6,8 +6,8 @@
#include "hidapi.h"
#endif
#define MAX_PAYLOAD 1012
#define ROLE_INFO 21845
#define SCREEN_SHOT 26214
#define ROLE_INFO 0x5555
#define SCREEN_SHOT 0x6666
#define MAX_PAYLOAD 1012
#define ROLE_NOT_SET 0
#define ROLE_SEND 1
......
......@@ -125,7 +125,7 @@ void VideoEncoder::run()
}
memcpy(picture_buf, node.buffer, node.size);
// cout<<"delay test send codec"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
// cout<<"delay test send codec"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
int ret = avcodec_send_frame(pCodecCtx, picture);
......@@ -169,13 +169,13 @@ void VideoEncoder::run()
memcpy(usb_fram->buff, p, pkt_len);
usb_fram->length = pkt_len;
usb_fram->id = ++fram_id;
// cout<<"delay test send frame to usb"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
// cout<<"delay test send frame to usb"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
res = hid_write(hid_fd, (const unsigned char *)usb_buf, 2049);
}else{
memcpy(usb_fram2->buff, p, pkt_len);
usb_fram2->length = pkt_len;
usb_fram2->id = ++fram_id;
// cout<<"delay test send frame to usb"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
// cout<<"delay test send frame to usb"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
res = hid_write(hid_fd, (const unsigned char *)usb_buf, 2049);
}
//memset((char *)&usb_fram->length, 0x00, sizeof (usb_fram)-8);
......
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