Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
QT_PAIR_SEND
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lenz su
QT_PAIR_SEND
Commits
9bf1620e
Commit
9bf1620e
authored
Jan 10, 2020
by
lenz su
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
音频发送优化
parent
4296f2b2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
56 deletions
+51
-56
GetAudioThread.cpp
src/audio/GetAudioThread.cpp
+12
-24
mainwindow.cpp
src/mainwindow.cpp
+6
-3
USBOperator.cpp
src/video/USBOperator.cpp
+28
-24
USBOperator.h
src/video/USBOperator.h
+2
-2
VideoEncoder.cpp
src/video/VideoEncoder.cpp
+3
-3
No files found.
src/audio/GetAudioThread.cpp
View file @
9bf1620e
#include "GetAudioThread.h"
#include "GetAudioThread.h"
FILE
*
fp
=
NULL
;
BOOL
bDone
=
FALSE
;
BOOL
bDone
=
FALSE
;
#define REFTIMES_PER_SEC 10000000
#define REFTIMES_PER_SEC 10000000
#define REFTIMES_PER_MILLISEC 10000
#define REFTIMES_PER_MILLISEC 10000
...
@@ -15,12 +13,10 @@ const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
...
@@ -15,12 +13,10 @@ const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
#define SAFE_RELEASE(punk) \
#define SAFE_RELEASE(punk) \
if ((punk) != NULL) { (punk)->Release(); (punk) = NULL; }
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_fram
=
(
usb_fram_t
*
)
&
usb_buf
[
1
];
usb_fram_t
*
usb_fram2
=
(
usb_fram_t
*
)
&
usb_buf
[
1025
];
int
aid
=
0
;
int
aid
=
0
;
GetAudioThread
::
GetAudioThread
(){
GetAudioThread
::
GetAudioThread
(){
...
@@ -158,14 +154,6 @@ void GetAudioThread::RecordAudioStream()
...
@@ -158,14 +154,6 @@ void GetAudioThread::RecordAudioStream()
sendAudioFrame
(
numFramesAvailable
*
pwfx
->
nBlockAlign
,(
unsigned
char
*
)
pData
);
sendAudioFrame
(
numFramesAvailable
*
pwfx
->
nBlockAlign
,(
unsigned
char
*
)
pData
);
cout
<<
"byte count:"
<<
numFramesAvailable
*
pwfx
->
nBlockAlign
<<
endl
;
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
);
hr
=
pCaptureClient
->
ReleaseBuffer
(
numFramesAvailable
);
// EXIT_ON_ERROR(hr,pwfx,pEnumerator, pDevice,pAudioClient,pCaptureClient );
// EXIT_ON_ERROR(hr,pwfx,pEnumerator, pDevice,pAudioClient,pCaptureClient );
...
@@ -176,8 +164,7 @@ void GetAudioThread::RecordAudioStream()
...
@@ -176,8 +164,7 @@ void GetAudioThread::RecordAudioStream()
hr
=
pAudioClient
->
Stop
();
// Stop recording.
hr
=
pAudioClient
->
Stop
();
// Stop recording.
EXIT_ON_ERROR
(
hr
,
pwfx
,
pEnumerator
,
pDevice
,
pAudioClient
,
pCaptureClient
);
EXIT_ON_ERROR
(
hr
,
pwfx
,
pEnumerator
,
pDevice
,
pAudioClient
,
pCaptureClient
);
fflush
(
fp
);
fclose
(
fp
);
cout
<<
"record over"
;
cout
<<
"record over"
;
return
;
return
;
...
@@ -199,25 +186,26 @@ void GetAudioThread::run(){
...
@@ -199,25 +186,26 @@ void GetAudioThread::run(){
void
GetAudioThread
::
sendAudioFrame
(
int
pkt_len
,
uint8_t
*
p
){
void
GetAudioThread
::
sendAudioFrame
(
int
pkt_len
,
uint8_t
*
p
){
cout
<<
"pkt le:"
<<
pkt_len
<<
endl
;
cout
<<
"pkt le:"
<<
pkt_len
<<
endl
;
if
(
pkt_len
==
384
){
/*
if(pkt_len==384){
usb_fram->head = 0x44332233;
usb_fram->head = 0x44332233;
memcpy(usb_fram->buff, p, pkt_len);
memcpy(usb_fram->buff, p, pkt_len);
usb_fram->length = pkt_len;
usb_fram->length = pkt_len;
usb_fram->id =++aid;
usb_fram->id =++aid;
int res = hid_write(hid_fd, (const unsigned char *)usb_buf, 1025);
int res = hid_write(hid_fd, (const unsigned char *)usb_buf, 1025);
}
}
*/
if
(
pkt_len
==
1920
){
if
(
pkt_len
==
1920
){
usb_fram
->
head
=
0x44332233
;
usb_fram
->
head
=
0x44332233
;
memcpy
(
usb_fram
->
buff
,
p
,
1012
);
memcpy
(
usb_fram
->
buff
,
p
,
1012
);
usb_fram
->
length
=
1012
;
usb_fram
->
length
=
1012
;
usb_fram
->
id
=++
aid
;
usb_fram
->
id
=++
aid
;
int
res
=
hid_write
(
hid_fd
,
(
const
unsigned
char
*
)
usb_buf
,
1025
);
usb_fram
->
head
=
0x44332233
;
usb_fram
2
->
head
=
0x44332233
;
memcpy
(
usb_fram
->
buff
,
p
+
1012
,
908
);
memcpy
(
usb_fram
2
->
buff
,
p
+
1012
,
908
);
usb_fram
->
length
=
908
;
usb_fram
2
->
length
=
908
;
usb_fram
->
id
=++
aid
;
usb_fram
2
->
id
=++
aid
;
res
=
hid_write
(
hid_fd
,
(
const
unsigned
char
*
)
usb_buf
,
1025
);
hid_write
(
hid_fd
,
(
const
unsigned
char
*
)
usb_buf
,
2049
);
}
}
}
}
...
...
src/mainwindow.cpp
View file @
9bf1620e
...
@@ -61,13 +61,16 @@ void MainWindow::onRole(int s){
...
@@ -61,13 +61,16 @@ void MainWindow::onRole(int s){
sUI
->
label
->
setText
(
roleStr
);
sUI
->
label
->
setText
(
roleStr
);
break
;
break
;
case
SCREEN_SHOT_START
:{
case
SCREEN_SHOT_START
:{
recordAudio
->
start
();
if
(
isFirstStartComplete
==
false
){
if
(
isFirstStartComplete
==
false
){
if
(
isVedioRecordInitSuccessful
==
SUCCEED
)
if
(
isVedioRecordInitSuccessful
==
SUCCEED
)
{
{
// 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;
recordVideo
->
start
();
recordVideo
->
start
();
}
}
// recordAudio->start();
isFirstStartComplete
=
true
;
isFirstStartComplete
=
true
;
}
else
{
}
else
{
recordVideo
->
restoreRecord
();
recordVideo
->
restoreRecord
();
...
@@ -76,8 +79,8 @@ void MainWindow::onRole(int s){
...
@@ -76,8 +79,8 @@ void MainWindow::onRole(int s){
break
;
break
;
}
}
case
SCREEN_SHOT_STOP
:{
case
SCREEN_SHOT_STOP
:{
recordVideo
->
pauseRecord
();
//
recordVideo->pauseRecord();
cout
<<
"stop bbbbb"
<<
endl
;
break
;
break
;
}
}
}
}
...
...
src/video/USBOperator.cpp
View file @
9bf1620e
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include <QDateTime>
#include <QDateTime>
#include<QApplication>
#include<QApplication>
using
namespace
std
;
using
namespace
std
;
FILE
*
fph
=
fopen
(
"woha"
,
"wb"
);
USBOperator
::
USBOperator
(
QObject
*
parent
)
:
QThread
(
parent
){
USBOperator
::
USBOperator
(
QObject
*
parent
)
:
QThread
(
parent
){
hid_init
();
hid_init
();
...
@@ -12,7 +12,7 @@ USBOperator::USBOperator(QObject *parent) : QThread(parent){
...
@@ -12,7 +12,7 @@ USBOperator::USBOperator(QObject *parent) : QThread(parent){
qDebug
(
"usb hid open failed!"
);
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"
);
qDebug
(
"hid_set_nonblocking error"
);
}
}
...
@@ -64,9 +64,9 @@ void USBOperator::run()
...
@@ -64,9 +64,9 @@ void USBOperator::run()
char
*
usb_buf
[
2048
]
=
{
0
};
char
*
usb_buf
[
2048
]
=
{
0
};
usb_fram_t
*
usb_fram1
=
(
usb_fram_t
*
)(
usb_buf
);
usb_fram_t
*
usb_fram1
=
(
usb_fram_t
*
)(
usb_buf
);
usb_fram_t
*
usb_fram2
=
(
usb_fram_t
*
)(
&
usb_buf
[
1024
]);
usb_fram_t
*
usb_fram2
=
(
usb_fram_t
*
)(
&
usb_buf
[
1024
]);
// hid_set_nonblocking(hid_fd,1);
while
(
1
)
{
while
(
1
)
{
// msleep(2
00);
msleep
(
20
00
);
memset
(
usb_buf
,
0
,
2048
);
memset
(
usb_buf
,
0
,
2048
);
if
(
hid_fd
==
nullptr
){
if
(
hid_fd
==
nullptr
){
cout
<<
"hid not open"
<<
endl
;
cout
<<
"hid not open"
<<
endl
;
...
@@ -74,20 +74,23 @@ void USBOperator::run()
...
@@ -74,20 +74,23 @@ void USBOperator::run()
}
}
int
res
=
hid_read
(
hid_fd
,(
unsigned
char
*
)
usb_buf
,
2048
);
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
;
continue
;
}
}
cout
<<
"res "
<<
res
<<
endl
;
cout
<<
"head1 "
<<
usb_fram1
->
head
<<
endl
;
// fwrite(usb_buf,1,2048,fph);
cout
<<
"id1 "
<<
usb_fram1
->
id
<<
endl
;
cout
<<
"frame re res "
<<
res
<<
endl
;
cout
<<
"length1 "
<<
usb_fram1
->
length
<<
endl
;
cout
<<
"frame re head1 "
<<
usb_fram1
->
head
<<
endl
;
cout
<<
"frame re id1 "
<<
usb_fram1
->
id
<<
endl
;
cout
<<
"head2 "
<<
usb_fram2
->
head
<<
endl
;
cout
<<
"frame re length1 "
<<
usb_fram1
->
length
<<
endl
;
cout
<<
"id2 "
<<
usb_fram2
->
id
<<
endl
;
cout
<<
"length2 "
<<
usb_fram2
->
length
<<
endl
;
cout
<<
"frame re head2 "
<<
usb_fram2
->
head
<<
endl
;
//角色信息
cout
<<
"frame re id2 "
<<
usb_fram2
->
id
<<
endl
;
if
(
1144201762
==
usb_fram1
->
head
){
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
->
id
==
ROLE_INFO
)
&&
(
usb_fram1
->
buff
[
0
]
==
0x01
&&
usb_fram1
->
buff
[
1
]
==
0x01
)){
if
(
usb_fram1
->
buff
[
2
]
==
ROLE_NOT_SET
){
if
(
usb_fram1
->
buff
[
2
]
==
ROLE_NOT_SET
){
...
@@ -113,20 +116,20 @@ void USBOperator::run()
...
@@ -113,20 +116,20 @@ void USBOperator::run()
}
}
}
}
if
((
usb_fram1
->
id
==
SCREEN_SHOT
)){
if
((
usb_fram1
->
id
==
SCREEN_SHOT
)){
//开始投屏
//开始投屏
if
(
usb_fram1
->
buff
[
0
]
==
0x01
&&
usb_fram1
->
buff
[
1
]
==
0x01
){
if
(
usb_fram1
->
buff
[
0
]
==
0x01
&&
usb_fram1
->
buff
[
1
]
==
0x01
){
cout
<<
"start screen shot"
<<
endl
;
cout
<<
"start screen shot"
<<
endl
;
char
usb_buf_re
[
1025
]
=
{
0
};
// char usb_buf_re[1025] = {0};
memcpy
(
&
usb_buf_re
[
1
],
usb_buf
,
1024
);
// memcpy(&usb_buf_re[1],usb_buf, 1024);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb
(
SCREEN_SHOT_START
);
mcb
(
SCREEN_SHOT_START
);
}
}
if
(
usb_fram1
->
buff
[
0
]
==
0x02
&&
usb_fram1
->
buff
[
1
]
==
0x02
){
if
(
usb_fram1
->
buff
[
0
]
==
0x02
&&
usb_fram1
->
buff
[
1
]
==
0x02
){
cout
<<
"stop screen shot"
<<
endl
;
cout
<<
"stop screen shot"
<<
endl
;
char
usb_buf_re
[
1025
]
=
{
0
};
//
char usb_buf_re[1025] = {0};
memcpy
(
&
usb_buf_re
[
1
],
usb_buf
,
1024
);
//
memcpy(&usb_buf_re[1],usb_buf, 1024);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb
(
SCREEN_SHOT_STOP
);
mcb
(
SCREEN_SHOT_STOP
);
}
}
...
@@ -136,20 +139,21 @@ void USBOperator::run()
...
@@ -136,20 +139,21 @@ void USBOperator::run()
//开始投屏
//开始投屏
if
(
usb_fram2
->
buff
[
0
]
==
0x01
&&
usb_fram2
->
buff
[
1
]
==
0x01
){
if
(
usb_fram2
->
buff
[
0
]
==
0x01
&&
usb_fram2
->
buff
[
1
]
==
0x01
){
cout
<<
"start screen shot"
<<
endl
;
cout
<<
"start screen shot"
<<
endl
;
char
usb_buf_re
[
1025
]
=
{
0
};
//
char usb_buf_re[1025] = {0};
memcpy
(
&
usb_buf_re
[
1
],
usb_buf
+
1024
,
1024
);
//
memcpy(&usb_buf_re[1],usb_buf+1024, 1024);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
// hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb
(
SCREEN_SHOT_START
);
mcb
(
SCREEN_SHOT_START
);
}
}
if
(
usb_fram2
->
buff
[
0
]
==
0x02
&&
usb_fram2
->
buff
[
1
]
==
0x02
){
if
(
usb_fram2
->
buff
[
0
]
==
0x02
&&
usb_fram2
->
buff
[
1
]
==
0x02
){
cout
<<
"stop screen shot"
<<
endl
;
cout
<<
"stop screen shot"
<<
endl
;
char
usb_buf_re
[
1025
]
=
{
0
};
//
char usb_buf_re[1025] = {0};
memcpy
(
&
usb_buf_re
[
1
],
usb_buf
+
1024
,
1024
);
//
memcpy(&usb_buf_re[1],usb_buf+1024, 1024);
//hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
//hid_write(hid_fd,(unsigned char *)usb_buf_re,1025);
mcb
(
SCREEN_SHOT_STOP
);
mcb
(
SCREEN_SHOT_STOP
);
}
}
}
}
}
}
}
}
}
}
...
...
src/video/USBOperator.h
View file @
9bf1620e
...
@@ -6,8 +6,8 @@
...
@@ -6,8 +6,8 @@
#include "hidapi.h"
#include "hidapi.h"
#endif
#endif
#define MAX_PAYLOAD 1012
#define MAX_PAYLOAD 1012
#define ROLE_INFO
2184
5
#define ROLE_INFO
0x555
5
#define SCREEN_SHOT
26214
#define SCREEN_SHOT
0x6666
#define MAX_PAYLOAD 1012
#define MAX_PAYLOAD 1012
#define ROLE_NOT_SET 0
#define ROLE_NOT_SET 0
#define ROLE_SEND 1
#define ROLE_SEND 1
...
...
src/video/VideoEncoder.cpp
View file @
9bf1620e
...
@@ -125,7 +125,7 @@ void VideoEncoder::run()
...
@@ -125,7 +125,7 @@ void VideoEncoder::run()
}
}
memcpy
(
picture_buf
,
node
.
buffer
,
node
.
size
);
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
);
int
ret
=
avcodec_send_frame
(
pCodecCtx
,
picture
);
...
@@ -169,13 +169,13 @@ void VideoEncoder::run()
...
@@ -169,13 +169,13 @@ void VideoEncoder::run()
memcpy
(
usb_fram
->
buff
,
p
,
pkt_len
);
memcpy
(
usb_fram
->
buff
,
p
,
pkt_len
);
usb_fram
->
length
=
pkt_len
;
usb_fram
->
length
=
pkt_len
;
usb_fram
->
id
=
++
fram_id
;
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
);
res
=
hid_write
(
hid_fd
,
(
const
unsigned
char
*
)
usb_buf
,
2049
);
}
else
{
}
else
{
memcpy
(
usb_fram2
->
buff
,
p
,
pkt_len
);
memcpy
(
usb_fram2
->
buff
,
p
,
pkt_len
);
usb_fram2
->
length
=
pkt_len
;
usb_fram2
->
length
=
pkt_len
;
usb_fram2
->
id
=
++
fram_id
;
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
);
res
=
hid_write
(
hid_fd
,
(
const
unsigned
char
*
)
usb_buf
,
2049
);
}
}
//memset((char *)&usb_fram->length, 0x00, sizeof (usb_fram)-8);
//memset((char *)&usb_fram->length, 0x00, sizeof (usb_fram)-8);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment