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"
#include "cmd_transport_mqtt.h"
static
const
std
::
string
kMqttUrl
=
"mqq-large.offcncloud.com"
;
//"47.95.181.254";
//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
kUseName
=
"admin"
;
static
const
std
::
string
kPassWord
=
"admin"
;
static
const
std
::
string
kPassWord
=
"admin"
;
static
const
std
::
string
kTopicServer
=
"whiteboard/c50d86590070538228fdfa19978a87e3/liweijieisvip_309485708"
;
//"rtc_server";
//static const std::string kTopicServer = "whiteboard/c50d86590070538228fdfa19978a87e3/liweijieisvip_309485708";//"rtc_server";
static
struct
Options
static
struct
Options
{
{
char
*
connection
;
/**< connection to system under test. */
char
*
connection
;
/**< connection to system under test. */
int
verbose
;
int
verbose
;
int
test_no
;
int
test_no
;
int
size
;
/**< size of big message */
int
size
;
/**< size of big message */
int
MQTTVersion
;
int
MQTTVersion
;
int
iterations
;
int
iterations
;
}
options
;
}
options
;
CmdTransportMqtt
::
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
)
CmdTransportMqtt
::
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
)
:
observer_
(
observer
),
:
observer_
(
observer
),
uu_id_
(
uu_id
),
uu_id_
(
uu_id
),
room_id_
(
room_id
)
room_id_
(
room_id
)
{
{
mqtt_client_
=
NULL
;
mqtt_client_
=
NULL
;
}
}
bool
CmdTransportMqtt
::
ConnectServer
(
)
bool
CmdTransportMqtt
::
ConnectServer
(
std
::
string
mqtt
)
{
{
options
.
connection
=
(
char
*
)
malloc
(
128
);
options
.
connection
=
(
char
*
)
malloc
(
128
);
memset
(
options
.
connection
,
0
,
128
);
memset
(
options
.
connection
,
0
,
128
);
memcpy
(
options
.
connection
,
kMqttUrl
.
c_str
(),
kMqttUrl
.
size
());
memcpy
(
options
.
connection
,
mqtt
.
c_str
(),
mqtt
.
size
());
options
.
verbose
=
0
;
options
.
verbose
=
0
;
options
.
test_no
=
-
1
;
options
.
test_no
=
-
1
;
options
.
size
=
10000
;
options
.
size
=
10000
;
options
.
MQTTVersion
=
MQTTVERSION_3_1
;
options
.
MQTTVersion
=
MQTTVERSION_3_1
;
options
.
iterations
=
1
;
options
.
iterations
=
1
;
MQTTAsync_connectOptions
opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_connectOptions
opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
wopts
=
MQTTAsync_willOptions_initializer
;
MQTTAsync_willOptions
wopts
=
MQTTAsync_willOptions_initializer
;
//uuid@roomid
//uuid@roomid
std
::
string
clientid
=
uu_id_
;
std
::
string
clientid
=
uu_id_
;
int
nRet
=
MQTTAsync_create
(
&
mqtt_client_
,
options
.
connection
,
clientid
.
c_str
(),
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
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
);
nRet
=
MQTTAsync_setCallbacks
(
mqtt_client_
,
this
,
NULL
,
mqtt_messageArrive
,
NULL
);
std
::
string
new_token
=
kPassWord
;
std
::
string
new_token
=
kPassWord
;
opts
.
keepAliveInterval
=
20
;
opts
.
keepAliveInterval
=
20
;
opts
.
cleansession
=
1
;
opts
.
cleansession
=
1
;
opts
.
username
=
kUseName
.
c_str
();
opts
.
username
=
kUseName
.
c_str
();
opts
.
password
=
kPassWord
.
c_str
();
opts
.
password
=
kPassWord
.
c_str
();
opts
.
MQTTVersion
=
options
.
MQTTVersion
;
opts
.
MQTTVersion
=
options
.
MQTTVersion
;
opts
.
cleansession
=
true
;
opts
.
cleansession
=
true
;
opts
.
will
=
NULL
;
opts
.
will
=
NULL
;
opts
.
onSuccess
=
mqtt_onConnectSuccess
;
opts
.
onSuccess
=
mqtt_onConnectSuccess
;
opts
.
onFailure
=
mqtt_onConnectFailed
;
opts
.
onFailure
=
mqtt_onConnectFailed
;
opts
.
context
=
this
;
opts
.
context
=
this
;
opts
.
connectTimeout
=
10
;
opts
.
connectTimeout
=
10
;
nRet
=
MQTTAsync_connect
(
mqtt_client_
,
&
opts
);
nRet
=
MQTTAsync_connect
(
mqtt_client_
,
&
opts
);
if
(
nRet
!=
MQTTASYNC_SUCCESS
)
if
(
nRet
!=
MQTTASYNC_SUCCESS
)
{
{
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
bool
CmdTransportMqtt
::
SendRequest
(
std
::
string
req
)
bool
CmdTransportMqtt
::
SendRequest
(
std
::
string
req
)
{
{
MQTTAsync_message
pubmsg
=
MQTTAsync_message_initializer
;
MQTTAsync_message
pubmsg
=
MQTTAsync_message_initializer
;
pubmsg
.
payload
=
(
void
*
)(
req
.
c_str
());
pubmsg
.
payload
=
(
void
*
)(
req
.
c_str
());
pubmsg
.
payloadlen
=
req
.
length
();
pubmsg
.
payloadlen
=
req
.
length
();
pubmsg
.
qos
=
2
;
pubmsg
.
qos
=
2
;
pubmsg
.
retained
=
0
;
pubmsg
.
retained
=
0
;
std
::
string
sTopic
=
"whiteboard/"
;
std
::
string
sTopic
=
"whiteboard/"
;
sTopic
=
sTopic
+
room_id_
+
"/"
;
sTopic
=
sTopic
+
room_id_
+
"/"
;
sTopic
=
sTopic
+
uu_id_
;
sTopic
=
sTopic
+
uu_id_
;
int
nRet
=
MQTTAsync_send
(
mqtt_client_
,
sTopic
.
c_str
(),
pubmsg
.
payloadlen
,
pubmsg
.
payload
,
pubmsg
.
qos
,
pubmsg
.
retained
,
NULL
);
int
nRet
=
MQTTAsync_send
(
mqtt_client_
,
sTopic
.
c_str
(),
pubmsg
.
payloadlen
,
pubmsg
.
payload
,
pubmsg
.
qos
,
pubmsg
.
retained
,
NULL
);
return
true
;
return
true
;
}
}
void
CmdTransportMqtt
::
DisConnectServer
()
void
CmdTransportMqtt
::
DisConnectServer
()
{
{
if
(
mqtt_client_
)
if
(
mqtt_client_
)
{
{
MQTTAsync_disconnect
(
mqtt_client_
,
NULL
);
MQTTAsync_disconnect
(
mqtt_client_
,
NULL
);
mqtt_client_
=
NULL
;
mqtt_client_
=
NULL
;
}
}
}
}
void
CmdTransportMqtt
::
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
void
CmdTransportMqtt
::
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onConnectServerResult
(
true
);
pThis
->
onConnectServerResult
(
true
);
}
}
void
CmdTransportMqtt
::
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
void
CmdTransportMqtt
::
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onConnectServerResult
(
false
);
pThis
->
onConnectServerResult
(
false
);
}
}
void
CmdTransportMqtt
::
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
void
CmdTransportMqtt
::
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onSubscribeResult
(
true
);
pThis
->
onSubscribeResult
(
true
);
}
}
void
CmdTransportMqtt
::
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
void
CmdTransportMqtt
::
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
{
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onSubscribeResult
(
false
);
pThis
->
onSubscribeResult
(
false
);
}
}
int
CmdTransportMqtt
::
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
)
int
CmdTransportMqtt
::
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
)
{
{
if
(
message
->
payloadlen
<=
0
)
if
(
message
->
payloadlen
<=
0
)
{
{
return
0
;
return
0
;
}
}
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
CmdTransportMqtt
*
pThis
=
(
CmdTransportMqtt
*
)
context
;
pThis
->
onMessageArrive
(
message
);
pThis
->
onMessageArrive
(
message
);
MQTTAsync_freeMessage
(
&
message
);
MQTTAsync_freeMessage
(
&
message
);
MQTTAsync_free
(
topicName
);
MQTTAsync_free
(
topicName
);
return
0
;
return
0
;
}
}
void
CmdTransportMqtt
::
onConnectServerResult
(
bool
success
)
void
CmdTransportMqtt
::
onConnectServerResult
(
bool
success
)
{
{
if
(
!
success
)
if
(
!
success
)
{
{
if
(
observer_
)
if
(
observer_
)
{
{
observer_
->
OnConnectServerSuccess
(
false
);
observer_
->
OnConnectServerSuccess
(
false
);
}
}
}
}
else
else
{
{
MQTTAsync_responseOptions
opts
=
MQTTAsync_responseOptions_initializer
;
MQTTAsync_responseOptions
opts
=
MQTTAsync_responseOptions_initializer
;
opts
.
onSuccess
=
mqtt_subscribeSuccess
;
opts
.
onSuccess
=
mqtt_subscribeSuccess
;
opts
.
onFailure
=
mqtt_subscribeFailed
;
opts
.
onFailure
=
mqtt_subscribeFailed
;
opts
.
context
=
this
;
opts
.
context
=
this
;
std
::
string
topic
=
uu_id_
+
"_"
+
room_id_
;
std
::
string
topic
=
uu_id_
+
"_"
+
room_id_
;
MQTTAsync_subscribe
(
mqtt_client_
,
topic
.
c_str
(),
2
,
&
opts
);
//uuid_roomid
MQTTAsync_subscribe
(
mqtt_client_
,
topic
.
c_str
(),
2
,
&
opts
);
//uuid_roomid
if
(
observer_
)
if
(
observer_
)
{
{
observer_
->
OnConnectServerSuccess
(
true
);
observer_
->
OnConnectServerSuccess
(
true
);
}
}
}
}
}
}
void
CmdTransportMqtt
::
onSubscribeResult
(
bool
success
)
void
CmdTransportMqtt
::
onSubscribeResult
(
bool
success
)
{
{
if
(
!
success
)
if
(
!
success
)
{
{
if
(
observer_
)
if
(
observer_
)
{
{
observer_
->
OnSubscribeTopicSuccess
(
false
);
observer_
->
OnSubscribeTopicSuccess
(
false
);
}
}
}
}
else
else
{
{
if
(
observer_
)
if
(
observer_
)
{
{
observer_
->
OnSubscribeTopicSuccess
(
true
);
observer_
->
OnSubscribeTopicSuccess
(
true
);
}
}
}
}
}
}
void
CmdTransportMqtt
::
onMessageArrive
(
MQTTAsync_message
*
message
)
void
CmdTransportMqtt
::
onMessageArrive
(
MQTTAsync_message
*
message
)
{
{
std
::
string
msg
;
std
::
string
msg
;
msg
.
append
((
char
*
)
message
->
payload
,
message
->
payloadlen
);
msg
.
append
((
char
*
)
message
->
payload
,
message
->
payloadlen
);
if
(
observer_
)
if
(
observer_
)
{
{
observer_
->
OnReceiveMessage
(
msg
);
observer_
->
OnReceiveMessage
(
msg
);
}
}
}
}
\ No newline at end of file
thirdparty/mqtt/cmd_transport_mqtt.h
View file @
e133208f
#pragma once
#pragma once
#include "MQTTAsync.h"
#include "MQTTAsync.h"
#include <string>
#include <string>
class
TransportObserver
class
TransportObserver
{
{
public
:
public
:
virtual
void
OnConnectServerSuccess
(
bool
success
)
=
0
;
virtual
void
OnConnectServerSuccess
(
bool
success
)
=
0
;
virtual
void
OnSubscribeTopicSuccess
(
bool
success
)
=
0
;
virtual
void
OnSubscribeTopicSuccess
(
bool
success
)
=
0
;
virtual
void
OnReceiveMessage
(
std
::
string
message
)
=
0
;
virtual
void
OnReceiveMessage
(
std
::
string
message
)
=
0
;
};
};
class
CmdTransportMqtt
class
CmdTransportMqtt
{
{
public
:
public
:
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
);
CmdTransportMqtt
(
std
::
string
uu_id
,
std
::
string
room_id
,
TransportObserver
*
observer
);
public
:
public
:
bool
ConnectServer
();
bool
ConnectServer
(
std
::
string
mqtt
);
bool
SendRequest
(
std
::
string
req
);
bool
SendRequest
(
std
::
string
req
);
void
DisConnectServer
();
void
DisConnectServer
();
private
:
private
:
static
void
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_onConnectSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
void
mqtt_onConnectFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
void
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_subscribeSuccess
(
void
*
context
,
MQTTAsync_successData
*
response
);
static
void
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
void
mqtt_subscribeFailed
(
void
*
context
,
MQTTAsync_failureData
*
response
);
static
int
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
);
static
int
mqtt_messageArrive
(
void
*
context
,
char
*
topicName
,
int
len
,
MQTTAsync_message
*
message
);
private
:
private
:
void
onConnectServerResult
(
bool
success
);
void
onConnectServerResult
(
bool
success
);
void
onSubscribeResult
(
bool
success
);
void
onSubscribeResult
(
bool
success
);
void
onMessageArrive
(
MQTTAsync_message
*
message
);
void
onMessageArrive
(
MQTTAsync_message
*
message
);
private
:
private
:
MQTTAsync
mqtt_client_
;
MQTTAsync
mqtt_client_
;
TransportObserver
*
observer_
;
TransportObserver
*
observer_
;
private
:
private
:
std
::
string
uu_id_
;
std
::
string
mqtt_url_
;
std
::
string
room_id_
;
std
::
string
uu_id_
;
std
::
string
room_id_
;
};
};
\ No newline at end of file
wb_rebuild/global_data.h
View file @
e133208f
#pragma once
#pragma once
#include <string>
#include <string>
#include "json/json.h"
#include "json/json.h"
const
std
::
string
kRoomId
=
"roomid"
;
const
std
::
string
kMqttUrl
=
"mqtt_url"
;
const
std
::
string
kUuId
=
"uuid"
;
const
std
::
string
kRoomId
=
"roomid"
;
const
std
::
string
kFilePath
=
"filepath"
;
const
std
::
string
kUuId
=
"uuid"
;
const
std
::
string
kMediaKey
=
"key"
;
const
std
::
string
kFilePath
=
"filepath"
;
const
std
::
string
kMediaKey
=
"key"
;
class
GlobalData
{
class
GlobalData
public
:
{
GlobalData
()
public
:
:
m_sRoomId
(
""
),
GlobalData
()
m_sUuId
(
""
),
:
m_sRoomId
(
""
),
m_sFilePath
(
""
),
m_sUuId
(
""
),
m_sMediaKey
(
""
)
m_sFilePath
(
""
),
{
m_sMediaKey
(
""
)
}
{
~
GlobalData
(){}
}
~
GlobalData
(){}
bool
LoadConfigFile
()
{
bool
LoadConfigFile
()
FILE
*
file
=
fopen
(
"./wb_rebuild_config.ini"
,
"r"
);
{
if
(
file
==
NULL
)
FILE
*
file
=
fopen
(
"./wb_rebuild_config.ini"
,
"r"
);
{
if
(
file
==
NULL
)
printf
(
"error : open config file failed
\n
"
);
{
return
false
;
printf
(
"error : open config file failed
\n
"
);
}
return
false
;
}
long
fileSize
=
0
;
fseek
(
file
,
0
,
SEEK_END
);
long
fileSize
=
0
;
fileSize
=
ftell
(
file
);
fseek
(
file
,
0
,
SEEK_END
);
if
(
fileSize
<=
0
)
fileSize
=
ftell
(
file
);
{
if
(
fileSize
<=
0
)
printf
(
"error : config file size is zero
\n
"
);
{
return
false
;
printf
(
"error : config file size is zero
\n
"
);
}
return
false
;
}
char
*
p
=
new
char
[
fileSize
];
rewind
(
file
);
char
*
p
=
new
char
[
fileSize
];
rewind
(
file
);
long
ret
=
fread
(
p
,
1
,
fileSize
,
file
);
if
(
ret
<=
0
)
long
ret
=
fread
(
p
,
1
,
fileSize
,
file
);
{
if
(
ret
<=
0
)
printf
(
"error : read config file error
\n
"
);
{
printf
(
"error : read config file error
\n
"
);
delete
p
;
fclose
(
file
);
delete
p
;
return
false
;
fclose
(
file
);
}
return
false
;
}
std
::
string
message
(
p
);
delete
p
;
std
::
string
message
(
p
);
delete
p
;
Json
::
Value
root
;
Json
::
CharReaderBuilder
readerBuilder
;
Json
::
Value
root
;
Json
::
CharReaderBuilder
readerBuilder
;
std
::
unique_ptr
<
Json
::
CharReader
>
const
reader
(
readerBuilder
.
newCharReader
());
std
::
unique_ptr
<
Json
::
CharReader
>
const
reader
(
readerBuilder
.
newCharReader
());
const
char
*
start_pos
=
message
.
c_str
();
const
char
*
start_pos
=
message
.
c_str
();
std
::
string
err
;
if
(
!
reader
->
parse
(
start_pos
,
start_pos
+
message
.
length
(),
&
root
,
&
err
))
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
;
printf
(
"error : config file is not json format
\n
"
);
}
return
false
;
}
m_sMediaKey
=
""
;
m_sMediaKey
=
""
;
if
(
!
root
[
kRoomId
]
||
!
root
[
kUuId
]
||
!
root
[
kFilePath
])
{
if
(
!
root
[
kRoomId
]
||
!
root
[
kUuId
]
||
!
root
[
kFilePath
])
printf
(
"error : no roomid uuid filepath param
\n
"
);
{
return
false
;
printf
(
"error : no roomid uuid filepath param
\n
"
);
}
return
false
;
}
m_sRoomId
=
root
[
kRoomId
].
asString
();
m_sUuId
=
root
[
kUuId
].
asString
();
m_sMqttUrl
=
root
[
kMqttUrl
].
asString
();
m_sFilePath
=
root
[
kFilePath
].
asString
();
m_sRoomId
=
root
[
kRoomId
].
asString
();
m_sUuId
=
root
[
kUuId
].
asString
();
if
(
root
[
kMediaKey
])
m_sFilePath
=
root
[
kFilePath
].
asString
();
{
m_sMediaKey
=
root
[
kMediaKey
].
asString
();
if
(
root
[
kMediaKey
])
}
{
m_sMediaKey
=
root
[
kMediaKey
].
asString
();
return
true
;
}
}
return
true
;
std
::
string
RoomId
()
{
return
m_sRoomId
;
}
}
std
::
string
UuId
()
{
return
m_sUuId
;
}
std
::
string
FilePath
()
{
return
m_sFilePath
;
}
std
::
string
MqttUrl
()
{
return
m_sMqttUrl
;
}
std
::
string
MediaKey
()
{
return
m_sMediaKey
;
}
std
::
string
RoomId
()
{
return
m_sRoomId
;
}
std
::
string
UuId
()
{
return
m_sUuId
;
}
private
:
std
::
string
FilePath
()
{
return
m_sFilePath
;
}
std
::
string
m_sRoomId
;
std
::
string
MediaKey
()
{
return
m_sMediaKey
;
}
std
::
string
m_sUuId
;
std
::
string
m_sFilePath
;
private
:
std
::
string
m_sMediaKey
;
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"
#include "rebuild_manager.h"
RebuildManager
::
RebuildManager
()
RebuildManager
::
RebuildManager
()
:
ZCWorkThread
(
"MediaReadThread"
),
:
ZCWorkThread
(
"MediaReadThread"
),
m_pMqtt
(
nullptr
),
m_pMqtt
(
nullptr
),
m_nMqttSuccess
(
0
)
m_nMqttSuccess
(
0
)
{}
{}
RebuildManager
::~
RebuildManager
()
RebuildManager
::~
RebuildManager
()
{
{
delete
m_pMqtt
;
delete
m_pMqtt
;
m_pMqtt
=
nullptr
;
m_pMqtt
=
nullptr
;
}
}
bool
RebuildManager
::
Init
()
bool
RebuildManager
::
Init
()
{
{
if
(
!
m_configData
.
LoadConfigFile
())
if
(
!
m_configData
.
LoadConfigFile
())
{
{
return
false
;
return
false
;
}
}
m_pMqtt
=
new
CmdTransportMqtt
(
m_configData
.
UuId
(),
m_configData
.
RoomId
(),
this
);
m_pMqtt
=
new
CmdTransportMqtt
(
m_configData
.
UuId
(),
m_configData
.
RoomId
(),
this
);
if
(
!
m_pMqtt
)
if
(
!
m_pMqtt
)
{
{
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
bool
RebuildManager
::
ConnectMqttServer
()
bool
RebuildManager
::
ConnectMqttServer
()
{
{
if
(
!
m_pMqtt
)
return
false
;
if
(
!
m_pMqtt
)
return
false
;
if
(
!
m_pMqtt
->
ConnectServer
(
))
return
false
;
if
(
!
m_pMqtt
->
ConnectServer
(
m_configData
.
MqttUrl
()))
return
false
;
return
true
;
return
true
;
}
}
void
RebuildManager
::
DisConnectMqttServer
()
void
RebuildManager
::
DisConnectMqttServer
()
{
{
if
(
m_pMqtt
)
if
(
m_pMqtt
)
{
{
m_pMqtt
->
DisConnectServer
();
m_pMqtt
->
DisConnectServer
();
}
}
}
}
bool
RebuildManager
::
OpenMediaFile
()
bool
RebuildManager
::
OpenMediaFile
()
{
{
int
nRet
=
m_fileReader
.
OpenFile
(
m_configData
.
FilePath
(),
m_configData
.
MediaKey
());
int
nRet
=
m_fileReader
.
OpenFile
(
m_configData
.
FilePath
(),
m_configData
.
MediaKey
());
if
(
nRet
!=
0
)
return
false
;
if
(
nRet
!=
0
)
return
false
;
return
true
;
return
true
;
}
}
void
RebuildManager
::
CloseMediaFile
()
void
RebuildManager
::
CloseMediaFile
()
{
{
m_fileReader
.
CloseFile
();
m_fileReader
.
CloseFile
();
}
}
bool
RebuildManager
::
StartPull
()
bool
RebuildManager
::
StartPull
()
{
{
StartThread
();
StartThread
();
return
true
;
return
true
;
}
}
void
RebuildManager
::
StopPull
()
void
RebuildManager
::
StopPull
()
{
{
StopThread
();
StopThread
();
}
}
bool
RebuildManager
::
EndOfFile
()
bool
RebuildManager
::
EndOfFile
()
{
{
return
m_fileReader
.
GetEof
();
return
m_fileReader
.
GetEof
();
}
}
void
RebuildManager
::
DoRunning
()
void
RebuildManager
::
DoRunning
()
{
{
if
(
!
m_fileReader
.
GetEof
())
if
(
!
m_fileReader
.
GetEof
())
{
{
AVPacket
pkt
=
{
0
};
AVPacket
pkt
=
{
0
};
av_init_packet
(
&
pkt
);
av_init_packet
(
&
pkt
);
int
nRet
=
m_fileReader
.
ReadFile
(
pkt
);
int
nRet
=
m_fileReader
.
ReadFile
(
pkt
);
if
(
nRet
==
-
1
)
if
(
nRet
==
-
1
)
{
{
printf
(
"
End of media file ...
\n
"
);
printf
(
"
end of media file ...
\n
"
);
m_fileReader
.
SetEof
(
true
);
m_fileReader
.
SetEof
(
true
);
}
}
else
else
{
{
if
(
pkt
.
stream_index
==
m_fileReader
.
VideoStreamIndex
())
if
(
pkt
.
stream_index
==
m_fileReader
.
VideoStreamIndex
())
{
{
ParseNaluBySize
(
pkt
);
ParseNaluBySize
(
pkt
);
}
}
else
else
{
{
av_packet_unref
(
&
pkt
);
av_packet_unref
(
&
pkt
);
}
}
}
}
}
}
else
else
{
{
std
::
chrono
::
milliseconds
dura
(
5
);
std
::
chrono
::
milliseconds
dura
(
5
);
std
::
this_thread
::
sleep_for
(
dura
);
std
::
this_thread
::
sleep_for
(
dura
);
}
}
}
}
void
RebuildManager
::
OnConnectServerSuccess
(
bool
success
)
void
RebuildManager
::
OnConnectServerSuccess
(
bool
success
)
{
{
m_nMqttSuccess
=
success
?
1
:
2
;
m_nMqttSuccess
=
success
?
1
:
2
;
if
(
success
)
if
(
success
)
{
{
printf
(
"mqtt : connect mqtt server sucess ...
\n
"
);
printf
(
"mqtt : connect mqtt server sucess ...
\n
"
);
}
}
else
else
{
{
printf
(
"mqtt : connect mqtt server failed ...
\n
"
);
printf
(
"mqtt : connect mqtt server failed ...
\n
"
);
}
}
}
}
void
RebuildManager
::
OnSubscribeTopicSuccess
(
bool
success
)
void
RebuildManager
::
OnSubscribeTopicSuccess
(
bool
success
)
{
{
if
(
success
)
if
(
success
)
{
{
printf
(
"mqtt : subscrible topic sucess ...
\n
"
);
printf
(
"mqtt : subscrible topic sucess ...
\n
"
);
}
}
else
else
{
{
printf
(
"mqtt : subscrible topic failed ...
\n
"
);
printf
(
"mqtt : subscrible topic failed ...
\n
"
);
}
}
}
}
void
RebuildManager
::
OnReceiveMessage
(
std
::
string
message
)
void
RebuildManager
::
OnReceiveMessage
(
std
::
string
message
)
{
{
printf
(
"mqtt : receive mqtt message:
\n
"
);
printf
(
"mqtt : receive mqtt message:
\n
"
);
printf
(
"%s
\n
"
,
message
.
c_str
());
printf
(
"%s
\n
"
,
message
.
c_str
());
}
}
void
RebuildManager
::
CallBackWhiteBoardData
(
AVPacket
&
pkt
)
void
RebuildManager
::
CallBackWhiteBoardData
(
AVPacket
&
pkt
)
{
{
CFrameInfo
info
;
CFrameInfo
info
;
if
(
GetWhiteBoardData
(
pkt
,
info
))
if
(
GetWhiteBoardData
(
pkt
,
info
))
{
{
if
(
info
.
m_pData
[
0
]
==
0
&&
info
.
m_pData
[
1
]
==
0
)
if
(
info
.
m_pData
[
0
]
==
0
&&
info
.
m_pData
[
1
]
==
0
)
{
{
std
::
string
req
((
char
*
)
info
.
m_pData
+
6
,
info
.
m_nDataSize
-
6
);
std
::
string
req
((
char
*
)
info
.
m_pData
+
6
,
info
.
m_nDataSize
-
6
);
int
index
=
*
(
int
*
)(
info
.
m_pData
+
6
+
8
);
int
index
=
*
(
int
*
)(
info
.
m_pData
+
6
+
8
);
...
@@ -144,10 +144,10 @@ void RebuildManager::CallBackWhiteBoardData(AVPacket &pkt)
...
@@ -144,10 +144,10 @@ void RebuildManager::CallBackWhiteBoardData(AVPacket &pkt)
{
{
m_pMqtt
->
SendRequest
(
req
);
m_pMqtt
->
SendRequest
(
req
);
}
}
info
.
UnInitFrame
();
info
.
UnInitFrame
();
}
}
}
}
av_packet_unref
(
&
pkt
);
av_packet_unref
(
&
pkt
);
}
}
\ No newline at end of file
wb_rebuild/wb_rebuild.cpp
View file @
e133208f
// wb_rebuild.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// wb_rebuild.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
//
#include <iostream>
#include <iostream>
#include "rebuild_manager.h"
#include "rebuild_manager.h"
int
main
()
int
main
()
{
{
RebuildManager
*
manager
=
new
RebuildManager
();
RebuildManager
*
manager
=
new
RebuildManager
();
if
(
!
manager
->
Init
())
if
(
!
manager
->
Init
())
{
{
printf
(
"error : init failed ...
\n
"
);
printf
(
"error : init failed ...
\n
"
);
goto
Error
;
goto
Error
;
}
}
printf
(
"init ok ...
\n
"
);
printf
(
"init ok ...
\n
"
);
if
(
!
manager
->
ConnectMqttServer
())
if
(
!
manager
->
ConnectMqttServer
())
{
{
printf
(
"error : connect mqtt failed ...
\n
"
);
printf
(
"error : connect mqtt failed ...
\n
"
);
goto
Error
;
goto
Error
;
}
}
while
(
manager
->
Connected
()
==
0
)
while
(
manager
->
Connected
()
==
0
)
{
{
printf
(
"wait connect mqtt resualt ...
\n
"
);
printf
(
"wait connect mqtt resualt ...
\n
"
);
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
this_thread
::
sleep_for
(
dura
);
std
::
this_thread
::
sleep_for
(
dura
);
}
}
if
(
manager
->
Connected
()
==
1
)
if
(
manager
->
Connected
()
==
1
)
{
{
printf
(
"connect mqtt server success ...
\n
"
);
printf
(
"connect mqtt server success ...
\n
"
);
}
}
else
else
{
{
goto
Error
;
goto
Error
;
}
}
if
(
!
manager
->
OpenMediaFile
())
if
(
!
manager
->
OpenMediaFile
())
{
{
printf
(
"error : open media file failed ...
\n
"
);
printf
(
"error : open media file failed ...
\n
"
);
goto
Error
;
goto
Error
;
}
}
manager
->
StartPull
();
manager
->
StartPull
();
while
(
!
manager
->
EndOfFile
())
while
(
!
manager
->
EndOfFile
())
{
{
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
chrono
::
milliseconds
dura
(
1000
);
std
::
this_thread
::
sleep_for
(
dura
);
std
::
this_thread
::
sleep_for
(
dura
);
}
}
manager
->
StopPull
();
manager
->
StopPull
();
manager
->
CloseMediaFile
();
manager
->
CloseMediaFile
();
manager
->
DisConnectMqttServer
();
manager
->
DisConnectMqttServer
();
printf
(
"
Mission completed ...!"
);
printf
(
"
mission completed ...!"
);
Error
:
Error
:
delete
manager
;
delete
manager
;
printf
(
"
Press enter key to exit ...
\n
"
);
printf
(
"
press enter key to exit ...
\n
"
);
getchar
();
getchar
();
return
0
;
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",
"mqtt_url":"mqq-large.offcncloud.com",
"uuid":"liweijieisvip_309",
"roomid":"b9d36b0a22268130643765deca9a03b2",
"filepath":"https://vod-live.offcncloud.com/vod/20211109037879836/vod/47a480ebd9a2c46912ac21836aaeb22e/index.m3u8",
"uuid":"liweijieisvip_309",
"key":"7b539939e9103688"
"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 拷贝到当前目录
1 将 wb_rebuild_config.ini 拷贝到当前目录
2 修改配置文件内容
2 修改配置文件内容
3 将thirdparty下的相关dll放到当前目录
3 将thirdparty下的相关dll放到当前目录
4 启动exe
4 启动exe
\ No newline at end of file
注意:
配置文件中的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