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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
52 deletions
+47
-52
GetAudioThread.cpp
src/audio/GetAudioThread.cpp
+12
-24
mainwindow.cpp
src/mainwindow.cpp
+6
-3
USBOperator.cpp
src/video/USBOperator.cpp
+27
-23
USBOperator.h
src/video/USBOperator.h
+2
-2
VideoEncoder.cpp
src/video/VideoEncoder.cpp
+0
-0
No files found.
src/audio/GetAudioThread.cpp
View file @
9bf1620e
#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_fram
2
->
head
=
0x44332233
;
memcpy
(
usb_fram
2
->
buff
,
p
+
1012
,
908
);
usb_fram
2
->
length
=
908
;
usb_fram
2
->
id
=++
aid
;
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){
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
;
}
}
...
...
src/video/USBOperator.cpp
View file @
9bf1620e
...
...
@@ -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(2
00);
msleep
(
20
00
);
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
);
}
}
}
}
}
...
...
src/video/USBOperator.h
View file @
9bf1620e
...
...
@@ -6,8 +6,8 @@
#include "hidapi.h"
#endif
#define MAX_PAYLOAD 1012
#define ROLE_INFO
2184
5
#define SCREEN_SHOT
26214
#define ROLE_INFO
0x555
5
#define SCREEN_SHOT
0x6666
#define MAX_PAYLOAD 1012
#define ROLE_NOT_SET 0
#define ROLE_SEND 1
...
...
src/video/VideoEncoder.cpp
View file @
9bf1620e
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