Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
offcntools
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
李维杰
offcntools
Commits
e133208f
Commit
e133208f
authored
Apr 14, 2023
by
李维杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将mqtt地址放到配置文件里
parent
7ac30709
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
560 additions
and
545 deletions
+560
-545
cmd_transport_mqtt.cpp
thirdparty/mqtt/cmd_transport_mqtt.cpp
+183
-182
cmd_transport_mqtt.h
thirdparty/mqtt/cmd_transport_mqtt.h
+46
-44
global_data.h
wb_rebuild/global_data.h
+105
-100
rebuild_manager.cpp
wb_rebuild/rebuild_manager.cpp
+144
-143
wb_rebuild.cpp
wb_rebuild/wb_rebuild.cpp
+65
-65
wb_rebuild.vcxproj
wb_rebuild/wb_rebuild.vcxproj
+0
-0
wb_rebuild_config.ini
wb_rebuild/wb_rebuild_config.ini
+7
-5
读我.txt
wb_rebuild/读我.txt
+10
-6
No files found.
thirdparty/mqtt/cmd_transport_mqtt.cpp
View file @
e133208f
#include "cmd_transport_mqtt.h"
static
const
std
::
string
kMqttUrl
=
"mqq-large.offcncloud.com"
;
//"47.95.181.254";
static
const
std
::
string
kUseName
=
"admin"
;
static
const
std
::
string
kPassWord
=
"admin"
;
static
const
std
::
string
kTopicServer
=
"whiteboard/c50d86590070538228fdfa19978a87e3/liweijieisvip_309485708"
;
//"rtc_server";
static
struct
Options
{
char
*
connection
;
/**< connection to system under test. */
int
verbose
;
int
test_no
;
int
size
;
/**< size of big message */
int
MQTTVersion
;
int
iterations
;
}
options
;
CmdTransportMqtt
::
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
)
:
observer_
(
observer
),
uu_id_
(
uu_id
),
room_id_
(
room_id
)
{
mqtt_client_
=
NULL
;
}
bool
CmdTransportMqtt
::
ConnectServer
(
)
{
options
.
connection
=
(
char
*
)
malloc
(
128
);
memset
(
options
.
connection
,
0
,
128
);
memcpy
(
options
.
connection
,
kMqttUrl
.
c_str
(),
kMqttUrl
.
size
());
options
.
verbose
=
0
;
options
.
test_no
=
-
1
;
options
.
size
=
10000
;
options
.
MQTTVersion
=
MQTTVERSION_3_1
;
options
.
iterations
=
1
;
MQTTAsync_connectOptions
opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
wopts
=
MQTTAsync_willOptions_initializer
;
//uuid@roomid
std
::
string
clientid
=
uu_id_
;
int
nRet
=
MQTTAsync_create
(
&
mqtt_client_
,
options
.
connection
,
clientid
.
c_str
(),
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
nRet
=
MQTTAsync_setCallbacks
(
mqtt_client_
,
this
,
NULL
,
mqtt_messageArrive
,
NULL
);
std
::
string
new_token
=
kPassWord
;
opts
.
keepAliveInterval
=
20
;
opts
.
cleansession
=
1
;
opts
.
username
=
kUseName
.
c_str
();
opts
.
password
=
kPassWord
.
c_str
();
opts
.
MQTTVersion
=
options
.
MQTTVersion
;
opts
.
cleansession
=
true
;
opts
.
will
=
NULL
;
opts
.
onSuccess
=
mqtt_onConnectSuccess
;
opts
.
onFailure
=
mqtt_onConnectFailed
;
opts
.
context
=
this
;
opts
.
connectTimeout
=
10
;
nRet
=
MQTTAsync_connect
(
mqtt_client_
,
&
opts
);
if
(
nRet
!=
MQTTASYNC_SUCCESS
)
{
return
false
;
}
return
true
;
}
bool
CmdTransportMqtt
::
SendRequest
(
std
::
string
req
)
{
MQTTAsync_message
pubmsg
=
MQTTAsync_message_initializer
;
pubmsg
.
payload
=
(
void
*
)(
req
.
c_str
());
pubmsg
.
payloadlen
=
req
.
length
();
pubmsg
.
qos
=
2
;
pubmsg
.
retained
=
0
;
std
::
string
sTopic
=
"whiteboard/"
;
sTopic
=
sTopic
+
room_id_
+
"/"
;
sTopic
=
sTopic
+
uu_id_
;
int
nRet
=
MQTTAsync_send
(
mqtt_client_
,
sTopic
.
c_str
(),
pubmsg
.
payloadlen
,
pubmsg
.
payload
,
pubmsg
.
qos
,
pubmsg
.
retained
,
NULL
);
return
true
;
}
void
CmdTransportMqtt
::
DisConnectServer
()
{
if
(
mqtt_client_
)
{
MQTTAsync_disconnect
(
mqtt_client_
,
NULL
);
mqtt_client_
=
NULL
;
}
}
void
CmdTransportMqtt
::
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onConnectServerResult
(
true
);
}
void
CmdTransportMqtt
::
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onConnectServerResult
(
false
);
}
void
CmdTransportMqtt
::
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onSubscribeResult
(
true
);
}
void
CmdTransportMqtt
::
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onSubscribeResult
(
false
);
}
int
CmdTransportMqtt
::
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
)
{
if
(
message
->
payloadlen
<=
0
)
{
return
0
;
}
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onMessageArrive
(
message
);
MQTTAsync_freeMessage
(
&
message
);
MQTTAsync_free
(
topicName
);
return
0
;
}
void
CmdTransportMqtt
::
onConnectServerResult
(
bool
success
)
{
if
(
!
success
)
{
if
(
observer_
)
{
observer_
->
OnConnectServerSuccess
(
false
);
}
}
else
{
MQTTAsync_responseOptions
opts
=
MQTTAsync_responseOptions_initializer
;
opts
.
onSuccess
=
mqtt_subscribeSuccess
;
opts
.
onFailure
=
mqtt_subscribeFailed
;
opts
.
context
=
this
;
std
::
string
topic
=
uu_id_
+
"_"
+
room_id_
;
MQTTAsync_subscribe
(
mqtt_client_
,
topic
.
c_str
(),
2
,
&
opts
);
//uuid_roomid
if
(
observer_
)
{
observer_
->
OnConnectServerSuccess
(
true
);
}
}
}
void
CmdTransportMqtt
::
onSubscribeResult
(
bool
success
)
{
if
(
!
success
)
{
if
(
observer_
)
{
observer_
->
OnSubscribeTopicSuccess
(
false
);
}
}
else
{
if
(
observer_
)
{
observer_
->
OnSubscribeTopicSuccess
(
true
);
}
}
}
void
CmdTransportMqtt
::
onMessageArrive
(
MQTTAsync_message
*
message
)
{
std
::
string
msg
;
msg
.
append
((
char
*
)
message
->
payload
,
message
->
payloadlen
);
if
(
observer_
)
{
observer_
->
OnReceiveMessage
(
msg
);
}
#include "cmd_transport_mqtt.h"
//static const std::string kMqttUrl = "mqq-large-cdn.offcncloud.com";//"mqq-large.offcncloud.com";//"47.95.181.254";
static
const
std
::
string
kUseName
=
"admin"
;
static
const
std
::
string
kPassWord
=
"admin"
;
//static const std::string kTopicServer = "whiteboard/c50d86590070538228fdfa19978a87e3/liweijieisvip_309485708";//"rtc_server";
static
struct
Options
{
char
*
connection
;
/**< connection to system under test. */
int
verbose
;
int
test_no
;
int
size
;
/**< size of big message */
int
MQTTVersion
;
int
iterations
;
}
options
;
CmdTransportMqtt
::
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
)
:
observer_
(
observer
),
uu_id_
(
uu_id
),
room_id_
(
room_id
)
{
mqtt_client_
=
NULL
;
}
bool
CmdTransportMqtt
::
ConnectServer
(
std
::
string
mqtt
)
{
options
.
connection
=
(
char
*
)
malloc
(
128
);
memset
(
options
.
connection
,
0
,
128
);
memcpy
(
options
.
connection
,
mqtt
.
c_str
(),
mqtt
.
size
());
options
.
verbose
=
0
;
options
.
test_no
=
-
1
;
options
.
size
=
10000
;
options
.
MQTTVersion
=
MQTTVERSION_3_1
;
options
.
iterations
=
1
;
MQTTAsync_connectOptions
opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
wopts
=
MQTTAsync_willOptions_initializer
;
//uuid@roomid
std
::
string
clientid
=
uu_id_
;
int
nRet
=
MQTTAsync_create
(
&
mqtt_client_
,
options
.
connection
,
clientid
.
c_str
(),
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
nRet
=
MQTTAsync_setCallbacks
(
mqtt_client_
,
this
,
NULL
,
mqtt_messageArrive
,
NULL
);
std
::
string
new_token
=
kPassWord
;
opts
.
keepAliveInterval
=
20
;
opts
.
cleansession
=
1
;
opts
.
username
=
kUseName
.
c_str
();
opts
.
password
=
kPassWord
.
c_str
();
opts
.
MQTTVersion
=
options
.
MQTTVersion
;
opts
.
cleansession
=
true
;
opts
.
will
=
NULL
;
opts
.
onSuccess
=
mqtt_onConnectSuccess
;
opts
.
onFailure
=
mqtt_onConnectFailed
;
opts
.
context
=
this
;
opts
.
connectTimeout
=
10
;
nRet
=
MQTTAsync_connect
(
mqtt_client_
,
&
opts
);
if
(
nRet
!=
MQTTASYNC_SUCCESS
)
{
return
false
;
}
return
true
;
}
bool
CmdTransportMqtt
::
SendRequest
(
std
::
string
req
)
{
MQTTAsync_message
pubmsg
=
MQTTAsync_message_initializer
;
pubmsg
.
payload
=
(
void
*
)(
req
.
c_str
());
pubmsg
.
payloadlen
=
req
.
length
();
pubmsg
.
qos
=
2
;
pubmsg
.
retained
=
0
;
std
::
string
sTopic
=
"whiteboard/"
;
sTopic
=
sTopic
+
room_id_
+
"/"
;
sTopic
=
sTopic
+
uu_id_
;
int
nRet
=
MQTTAsync_send
(
mqtt_client_
,
sTopic
.
c_str
(),
pubmsg
.
payloadlen
,
pubmsg
.
payload
,
pubmsg
.
qos
,
pubmsg
.
retained
,
NULL
);
return
true
;
}
void
CmdTransportMqtt
::
DisConnectServer
()
{
if
(
mqtt_client_
)
{
MQTTAsync_disconnect
(
mqtt_client_
,
NULL
);
mqtt_client_
=
NULL
;
}
}
void
CmdTransportMqtt
::
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onConnectServerResult
(
true
);
}
void
CmdTransportMqtt
::
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onConnectServerResult
(
false
);
}
void
CmdTransportMqtt
::
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onSubscribeResult
(
true
);
}
void
CmdTransportMqtt
::
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onSubscribeResult
(
false
);
}
int
CmdTransportMqtt
::
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
)
{
if
(
message
->
payloadlen
<=
0
)
{
return
0
;
}
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onMessageArrive
(
message
);
MQTTAsync_freeMessage
(
&
message
);
MQTTAsync_free
(
topicName
);
return
0
;
}
void
CmdTransportMqtt
::
onConnectServerResult
(
bool
success
)
{
if
(
!
success
)
{
if
(
observer_
)
{
observer_
->
OnConnectServerSuccess
(
false
);
}
}
else
{
MQTTAsync_responseOptions
opts
=
MQTTAsync_responseOptions_initializer
;
opts
.
onSuccess
=
mqtt_subscribeSuccess
;
opts
.
onFailure
=
mqtt_subscribeFailed
;
opts
.
context
=
this
;
std
::
string
topic
=
uu_id_
+
"_"
+
room_id_
;
MQTTAsync_subscribe
(
mqtt_client_
,
topic
.
c_str
(),
2
,
&
opts
);
//uuid_roomid
if
(
observer_
)
{
observer_
->
OnConnectServerSuccess
(
true
);
}
}
}
void
CmdTransportMqtt
::
onSubscribeResult
(
bool
success
)
{
if
(
!
success
)
{
if
(
observer_
)
{
observer_
->
OnSubscribeTopicSuccess
(
false
);
}
}
else
{
if
(
observer_
)
{
observer_
->
OnSubscribeTopicSuccess
(
true
);
}
}
}
void
CmdTransportMqtt
::
onMessageArrive
(
MQTTAsync_message
*
message
)
{
std
::
string
msg
;
msg
.
append
((
char
*
)
message
->
payload
,
message
->
payloadlen
);
if
(
observer_
)
{
observer_
->
OnReceiveMessage
(
msg
);
}
}
\ No newline at end of file
thirdparty/mqtt/cmd_transport_mqtt.h
View file @
e133208f
#pragma once
#include "MQTTAsync.h"
#include <string>
class
TransportObserver
{
public
:
virtual
void
OnConnectServerSuccess
(
bool
success
)
=
0
;
virtual
void
OnSubscribeTopicSuccess
(
bool
success
)
=
0
;
virtual
void
OnReceiveMessage
(
std
::
string
message
)
=
0
;
};
class
CmdTransportMqtt
{
public
:
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
);
public
:
bool
ConnectServer
();
bool
SendRequest
(
std
::
string
req
);
void
DisConnectServer
();
private
:
static
void
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
void
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
int
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
);
private
:
void
onConnectServerResult
(
bool
success
);
void
onSubscribeResult
(
bool
success
);
void
onMessageArrive
(
MQTTAsync_message
*
message
);
private
:
MQTTAsync
mqtt_client_
;
TransportObserver
*
observer_
;
private
:
std
::
string
uu_id_
;
std
::
string
room_id_
;
#pragma once
#include "MQTTAsync.h"
#include <string>
class
TransportObserver
{
public
:
virtual
void
OnConnectServerSuccess
(
bool
success
)
=
0
;
virtual
void
OnSubscribeTopicSuccess
(
bool
success
)
=
0
;
virtual
void
OnReceiveMessage
(
std
::
string
message
)
=
0
;
};
class
CmdTransportMqtt
{
public
:
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
);
public
:
bool
ConnectServer
(
std
::
string
mqtt
);
bool
SendRequest
(
std
::
string
req
);
void
DisConnectServer
();
private
:
static
void
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
void
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
int
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
);
private
:
void
onConnectServerResult
(
bool
success
);
void
onSubscribeResult
(
bool
success
);
void
onMessageArrive
(
MQTTAsync_message
*
message
);
private
:
MQTTAsync
mqtt_client_
;
TransportObserver
*
observer_
;
private
:
std
::
string
mqtt_url_
;
std
::
string
uu_id_
;
std
::
string
room_id_
;
};
\ No newline at end of file
wb_rebuild/global_data.h
View file @
e133208f
#pragma once
#include <string>
#include "json/json.h"
const
std
::
string
kRoomId
=
"roomid"
;
const
std
::
string
kUuId
=
"uuid"
;
const
std
::
string
kFilePath
=
"filepath"
;
const
std
::
string
kMediaKey
=
"key"
;
class
GlobalData
{
public
:
GlobalData
()
:
m_sRoomId
(
""
),
m_sUuId
(
""
),
m_sFilePath
(
""
),
m_sMediaKey
(
""
)
{
}
~
GlobalData
(){}
bool
LoadConfigFile
()
{
FILE
*
file
=
fopen
(
"./wb_rebuild_config.ini"
,
"r"
);
if
(
file
==
NULL
)
{
printf
(
"error : open config file failed
\n
"
);
return
false
;
}
long
fileSize
=
0
;
fseek
(
file
,
0
,
SEEK_END
);
fileSize
=
ftell
(
file
);
if
(
fileSize
<=
0
)
{
printf
(
"error : config file size is zero
\n
"
);
return
false
;
}
char
*
p
=
new
char
[
fileSize
];
rewind
(
file
);
long
ret
=
fread
(
p
,
1
,
fileSize
,
file
);
if
(
ret
<=
0
)
{
printf
(
"error : read config file error
\n
"
);
delete
p
;
fclose
(
file
);
return
false
;
}
std
::
string
message
(
p
);
delete
p
;
Json
::
Value
root
;
Json
::
CharReaderBuilder
readerBuilder
;
std
::
unique_ptr
<
Json
::
CharReader
>
const
reader
(
readerBuilder
.
newCharReader
());
const
char
*
start_pos
=
message
.
c_str
();
std
::
string
err
;
if
(
!
reader
->
parse
(
start_pos
,
start_pos
+
message
.
length
(),
&
root
,
&
err
))
{
printf
(
"error : config file is not json format
\n
"
);
return
false
;
}
m_sMediaKey
=
""
;
if
(
!
root
[
kRoomId
]
||
!
root
[
kUuId
]
||
!
root
[
kFilePath
])
{
printf
(
"error : no roomid uuid filepath param
\n
"
);
return
false
;
}
m_sRoomId
=
root
[
kRoomId
].
asString
();
m_sUuId
=
root
[
kUuId
].
asString
();
m_sFilePath
=
root
[
kFilePath
].
asString
();
if
(
root
[
kMediaKey
])
{
m_sMediaKey
=
root
[
kMediaKey
].
asString
();
}
return
true
;
}
std
::
string
RoomId
()
{
return
m_sRoomId
;
}
std
::
string
UuId
()
{
return
m_sUuId
;
}
std
::
string
FilePath
()
{
return
m_sFilePath
;
}
std
::
string
MediaKey
()
{
return
m_sMediaKey
;
}
private
:
std
::
string
m_sRoomId
;
std
::
string
m_sUuId
;
std
::
string
m_sFilePath
;
std
::
string
m_sMediaKey
;
#pragma once
#include <string>
#include "json/json.h"
const
std
::
string
kMqttUrl
=
"mqtt_url"
;
const
std
::
string
kRoomId
=
"roomid"
;
const
std
::
string
kUuId
=
"uuid"
;
const
std
::
string
kFilePath
=
"filepath"
;
const
std
::
string
kMediaKey
=
"key"
;
class
GlobalData
{
public
:
GlobalData
()
:
m_sRoomId
(
""
),
m_sUuId
(
""
),
m_sFilePath
(
""
),
m_sMediaKey
(
""
)
{
}
~
GlobalData
(){}
bool
LoadConfigFile
()
{
FILE
*
file
=
fopen
(
"./wb_rebuild_config.ini"
,
"r"
);
if
(
file
==
NULL
)
{
printf
(
"error : open config file failed
\n
"
);
return
false
;
}
long
fileSize
=
0
;
fseek
(
file
,
0
,
SEEK_END
);
fileSize
=
ftell
(
file
);
if
(
fileSize
<=
0
)
{
printf
(
"error : config file size is zero
\n
"
);
return
false
;
}
char
*
p
=
new
char
[
fileSize
];
rewind
(
file
);
long
ret
=
fread
(
p
,
1
,
fileSize
,
file
);
if
(
ret
<=
0
)
{
printf
(
"error : read config file error
\n
"
);
delete
p
;
fclose
(
file
);
return
false
;
}
std
::
string
message
(
p
);
delete
p
;
Json
::
Value
root
;
Json
::
CharReaderBuilder
readerBuilder
;
std
::
unique_ptr
<
Json
::
CharReader
>
const
reader
(
readerBuilder
.
newCharReader
());
const
char
*
start_pos
=
message
.
c_str
();
std
::
string
err
;
if
(
!
reader
->
parse
(
start_pos
,
start_pos
+
message
.
length
(),
&
root
,
&
err
))
{
printf
(
"error : config file is not json format
\n
"
);
return
false
;
}
m_sMediaKey
=
""
;
if
(
!
root
[
kRoomId
]
||
!
root
[
kUuId
]
||
!
root
[
kFilePath
])
{
printf
(
"error : no roomid uuid filepath param
\n
"
);
return
false
;
}
m_sMqttUrl
=
root
[
kMqttUrl
].
asString
();
m_sRoomId
=
root
[
kRoomId
].
asString
();
m_sUuId
=
root
[
kUuId
].
asString
();
m_sFilePath
=
root
[
kFilePath
].
asString
();
if
(
root
[
kMediaKey
])
{
m_sMediaKey
=
root
[
kMediaKey
].
asString
();
}
return
true
;
}
std
::
string
MqttUrl
()
{
return
m_sMqttUrl
;
}
std
::
string
RoomId
()
{
return
m_sRoomId
;
}
std
::
string
UuId
()
{
return
m_sUuId
;
}
std
::
string
FilePath
()
{
return
m_sFilePath
;
}
std
::
string
MediaKey
()
{
return
m_sMediaKey
;
}
private
:
std
::
string
m_sMqttUrl
;
std
::
string
m_sRoomId
;
std
::
string
m_sUuId
;
std
::
string
m_sFilePath
;
std
::
string
m_sMediaKey
;
};
\ No newline at end of file
wb_rebuild/rebuild_manager.cpp
View file @
e133208f
#include "rebuild_manager.h"
RebuildManager
::
RebuildManager
()
:
ZCWorkThread
(
"MediaReadThread"
),
m_pMqtt
(
nullptr
),
m_nMqttSuccess
(
0
)
{}
RebuildManager
::~
RebuildManager
()
{
delete
m_pMqtt
;
m_pMqtt
=
nullptr
;
}
bool
RebuildManager
::
Init
()
{
if
(
!
m_configData
.
LoadConfigFile
())
{
return
false
;
}
m_pMqtt
=
new
CmdTransportMqtt
(
m_configData
.
UuId
(),
m_configData
.
RoomId
(),
this
);
if
(
!
m_pMqtt
)
{
return
false
;
}
return
true
;
}
bool
RebuildManager
::
ConnectMqttServer
()
{
if
(
!
m_pMqtt
)
return
false
;
if
(
!
m_pMqtt
->
ConnectServer
(
))
return
false
;
return
true
;
}
void
RebuildManager
::
DisConnectMqttServer
()
{
if
(
m_pMqtt
)
{
m_pMqtt
->
DisConnectServer
();
}
}
bool
RebuildManager
::
OpenMediaFile
()
{
int
nRet
=
m_fileReader
.
OpenFile
(
m_configData
.
FilePath
(),
m_configData
.
MediaKey
());
if
(
nRet
!=
0
)
return
false
;
return
true
;
}
void
RebuildManager
::
CloseMediaFile
()
{
m_fileReader
.
CloseFile
();
}
bool
RebuildManager
::
StartPull
()
{
StartThread
();
return
true
;
}
void
RebuildManager
::
StopPull
()
{
StopThread
();
}
bool
RebuildManager
::
EndOfFile
()
{
return
m_fileReader
.
GetEof
();
}
void
RebuildManager
::
DoRunning
()
{
if
(
!
m_fileReader
.
GetEof
())
{
AVPacket
pkt
=
{
0
};
av_init_packet
(
&
pkt
);
int
nRet
=
m_fileReader
.
ReadFile
(
pkt
);
if
(
nRet
==
-
1
)
{
printf
(
"
End of media file ...
\n
"
);
m_fileReader
.
SetEof
(
true
);
}
else
{
if
(
pkt
.
stream_index
==
m_fileReader
.
VideoStreamIndex
())
{
ParseNaluBySize
(
pkt
);
}
else
{
av_packet_unref
(
&
pkt
);
}
}
}
else
{
std
::
chrono
::
milliseconds
dura
(
5
);
std
::
this_thread
::
sleep_for
(
dura
);
}
}
void
RebuildManager
::
OnConnectServerSuccess
(
bool
success
)
{
m_nMqttSuccess
=
success
?
1
:
2
;
if
(
success
)
{
printf
(
"mqtt : connect mqtt server sucess ...
\n
"
);
}
else
{
printf
(
"mqtt : connect mqtt server failed ...
\n
"
);
}
}
void
RebuildManager
::
OnSubscribeTopicSuccess
(
bool
success
)
{
if
(
success
)
{
printf
(
"mqtt : subscrible topic sucess ...
\n
"
);
}
else
{
printf
(
"mqtt : subscrible topic failed ...
\n
"
);
}
}
void
RebuildManager
::
OnReceiveMessage
(
std
::
string
message
)
{
printf
(
"mqtt : receive mqtt message:
\n
"
);
printf
(
"%s
\n
"
,
message
.
c_str
());
}
void
RebuildManager
::
CallBackWhiteBoardData
(
AVPacket
&
pkt
)
{
CFrameInfo
info
;
if
(
GetWhiteBoardData
(
pkt
,
info
))
{
if
(
info
.
m_pData
[
0
]
==
0
&&
info
.
m_pData
[
1
]
==
0
)
{
#include "rebuild_manager.h"
RebuildManager
::
RebuildManager
()
:
ZCWorkThread
(
"MediaReadThread"
),
m_pMqtt
(
nullptr
),
m_nMqttSuccess
(
0
)
{}
RebuildManager
::~
RebuildManager
()
{
delete
m_pMqtt
;
m_pMqtt
=
nullptr
;
}
bool
RebuildManager
::
Init
()
{
if
(
!
m_configData
.
LoadConfigFile
())
{
return
false
;
}
m_pMqtt
=
new
CmdTransportMqtt
(
m_configData
.
UuId
(),
m_configData
.
RoomId
(),
this
);
if
(
!
m_pMqtt
)
{
return
false
;
}
return
true
;
}
bool
RebuildManager
::
ConnectMqttServer
()
{
if
(
!
m_pMqtt
)
return
false
;
if
(
!
m_pMqtt
->
ConnectServer
(
m_configData
.
MqttUrl
()))
return
false
;
return
true
;
}
void
RebuildManager
::
DisConnectMqttServer
()
{
if
(
m_pMqtt
)
{
m_pMqtt
->
DisConnectServer
();
}
}
bool
RebuildManager
::
OpenMediaFile
()
{
int
nRet
=
m_fileReader
.
OpenFile
(
m_configData
.
FilePath
(),
m_configData
.
MediaKey
());
if
(
nRet
!=
0
)
return
false
;
return
true
;
}
void
RebuildManager
::
CloseMediaFile
()
{
m_fileReader
.
CloseFile
();
}
bool
RebuildManager
::
StartPull
()
{
StartThread
();
return
true
;
}
void
RebuildManager
::
StopPull
()
{
StopThread
();
}
bool
RebuildManager
::
EndOfFile
()
{
return
m_fileReader
.
GetEof
();
}
void
RebuildManager
::
DoRunning
()
{
if
(
!
m_fileReader
.
GetEof
())
{
AVPacket
pkt
=
{
0
};
av_init_packet
(
&
pkt
);
int
nRet
=
m_fileReader
.
ReadFile
(
pkt
);
if
(
nRet
==
-
1
)
{
printf
(
"
end of media file ...
\n
"
);
m_fileReader
.
SetEof
(
true
);
}
else
{
if
(
pkt
.
stream_index
==
m_fileReader
.
VideoStreamIndex
())
{
ParseNaluBySize
(
pkt
);
}
else
{
av_packet_unref
(
&
pkt
);
}
}
}
else
{
std
::
chrono
::
milliseconds
dura
(
5
);
std
::
this_thread
::
sleep_for
(
dura
);
}
}
void
RebuildManager
::
OnConnectServerSuccess
(
bool
success
)
{
m_nMqttSuccess
=
success
?
1
:
2
;
if
(
success
)
{
printf
(
"mqtt : connect mqtt server sucess ...
\n
"
);
}
else
{
printf
(
"mqtt : connect mqtt server failed ...
\n
"
);
}
}
void
RebuildManager
::
OnSubscribeTopicSuccess
(
bool
success
)
{
if
(
success
)
{
printf
(
"mqtt : subscrible topic sucess ...
\n
"
);
}
else
{
printf
(
"mqtt : subscrible topic failed ...
\n
"
);
}
}
void
RebuildManager
::
OnReceiveMessage
(
std
::
string
message
)
{
printf
(
"mqtt : receive mqtt message:
\n
"
);
printf
(
"%s
\n
"
,
message
.
c_str
());
}
void
RebuildManager
::
CallBackWhiteBoardData
(
AVPacket
&
pkt
)
{
CFrameInfo
info
;
if
(
GetWhiteBoardData
(
pkt
,
info
))
{
if
(
info
.
m_pData
[
0
]
==
0
&&
info
.
m_pData
[
1
]
==
0
)
{
std
::
string
req
((
char
*
)
info
.
m_pData
+
6
,
info
.
m_nDataSize
-
6
);
int
index
=
*
(
int
*
)(
info
.
m_pData
+
6
+
8
);
...
...
@@ -144,10 +144,10 @@ void RebuildManager::CallBackWhiteBoardData(AVPacket &pkt)
{
m_pMqtt
->
SendRequest
(
req
);
}
info
.
UnInitFrame
();
}
}
av_packet_unref
(
&
pkt
);
info
.
UnInitFrame
();
}
}
av_packet_unref
(
&
pkt
);
}
\ No newline at end of file
wb_rebuild/wb_rebuild.cpp
View file @
e133208f
// wb_rebuild.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include "rebuild_manager.h"
int
main
()
{
RebuildManager
*
manager
=
new
RebuildManager
();
if
(
!
manager
->
Init
())
{
printf
(
"error : init failed ...
\n
"
);
goto
Error
;
}
printf
(
"init ok ...
\n
"
);
if
(
!
manager
->
ConnectMqttServer
())
{
printf
(
"error : connect mqtt failed ...
\n
"
);
goto
Error
;
}
while
(
manager
->
Connected
()
==
0
)
{
printf
(
"wait connect mqtt resualt ...
\n
"
);
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
this_thread
::
sleep_for
(
dura
);
}
if
(
manager
->
Connected
()
==
1
)
{
printf
(
"connect mqtt server success ...
\n
"
);
}
else
{
goto
Error
;
}
if
(
!
manager
->
OpenMediaFile
())
{
printf
(
"error : open media file failed ...
\n
"
);
goto
Error
;
}
manager
->
StartPull
();
while
(
!
manager
->
EndOfFile
())
{
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
this_thread
::
sleep_for
(
dura
);
}
manager
->
StopPull
();
manager
->
CloseMediaFile
();
manager
->
DisConnectMqttServer
();
printf
(
"
Mission completed ...!"
);
Error
:
delete
manager
;
printf
(
"
Press enter key to exit ...
\n
"
);
getchar
();
return
0
;
}
// wb_rebuild.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include "rebuild_manager.h"
int
main
()
{
RebuildManager
*
manager
=
new
RebuildManager
();
if
(
!
manager
->
Init
())
{
printf
(
"error : init failed ...
\n
"
);
goto
Error
;
}
printf
(
"init ok ...
\n
"
);
if
(
!
manager
->
ConnectMqttServer
())
{
printf
(
"error : connect mqtt failed ...
\n
"
);
goto
Error
;
}
while
(
manager
->
Connected
()
==
0
)
{
printf
(
"wait connect mqtt resualt ...
\n
"
);
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
this_thread
::
sleep_for
(
dura
);
}
if
(
manager
->
Connected
()
==
1
)
{
printf
(
"connect mqtt server success ...
\n
"
);
}
else
{
goto
Error
;
}
if
(
!
manager
->
OpenMediaFile
())
{
printf
(
"error : open media file failed ...
\n
"
);
goto
Error
;
}
manager
->
StartPull
();
while
(
!
manager
->
EndOfFile
())
{
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
this_thread
::
sleep_for
(
dura
);
}
manager
->
StopPull
();
manager
->
CloseMediaFile
();
manager
->
DisConnectMqttServer
();
printf
(
"
mission completed ...!"
);
Error
:
delete
manager
;
printf
(
"
press enter key to exit ...
\n
"
);
getchar
();
return
0
;
}
wb_rebuild/wb_rebuild.vcxproj
View file @
e133208f
This diff is collapsed.
Click to expand it.
wb_rebuild/wb_rebuild_config.ini
View file @
e133208f
{
"roomid":"3ae42ba21356a02a9535092b0c6b777b",
"uuid":"liweijieisvip_309",
"filepath":"https://vod-live.offcncloud.com/vod/20211109037879836/vod/47a480ebd9a2c46912ac21836aaeb22e/index.m3u8",
"key":"7b539939e9103688"
{
"mqtt_url":"mqq-large.offcncloud.com",
"roomid":"b9d36b0a22268130643765deca9a03b2",
"uuid":"liweijieisvip_309",
"filepath":"https://live-record-offcncloud.bj.bcebos.com/bd-play.offcncloud.com/pro/2023040373900774/record/index_t.m3u8"
"key":"ts加密key"
}
\ No newline at end of file
wb_rebuild/读我.txt
View file @
e133208f
1 将 wb_rebuild_config.ini 拷贝到当前目录
1 将 wb_rebuild_config.ini 拷贝到当前目录
1 将 wb_rebuild_config.ini 拷贝到当前目录
2 修改配置文件内容
3 将thirdparty下的相关dll放到当前目录
4 启动exe
\ No newline at end of file
1 将 wb_rebuild_config.ini 拷贝到当前目录
2 修改配置文件内容
3 将thirdparty下的相关dll放到当前目录
4 启动exe
注意:
配置文件中的key为加密的ts文件的key,没有则删掉;
uuid可以随机填写一个
\ No newline at end of file
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