Commit 3f6baeb0 by 李维杰

修改逻辑

parent b6bf8a50
......@@ -16,6 +16,12 @@ extern "C"
CFileReader::CFileReader()
{
av_register_all();
avformat_network_init();
// 设置编解码库日志回调函数
av_log_set_callback(NULL);
resetReader();
}
CFileReader::~CFileReader()
......
......@@ -2,7 +2,8 @@
RebuildManager::RebuildManager()
:ZCWorkThread("MediaReadThread"),
m_pMqtt(nullptr)
m_pMqtt(nullptr),
m_nMqttSuccess(0)
{}
RebuildManager::~RebuildManager()
{
......@@ -40,9 +41,12 @@ void RebuildManager::DisConnectMqttServer()
}
}
bool RebuildManager::OpenMediaFile(std::string filePath, std::string key)
bool RebuildManager::OpenMediaFile()
{
return m_fileReader.OpenFile(filePath, key);
int nRet = m_fileReader.OpenFile(m_configData.FilePath(), m_configData.MediaKey());
if (nRet != 0) return false;
return true;
}
void RebuildManager::CloseMediaFile()
{
......@@ -58,6 +62,10 @@ void RebuildManager::StopPull()
{
StopThread();
}
bool RebuildManager::EndOfFile()
{
return m_fileReader.GetEof();
}
void RebuildManager::DoRunning()
{
if (!m_fileReader.GetEof())
......@@ -92,6 +100,8 @@ void RebuildManager::DoRunning()
void RebuildManager::OnConnectServerSuccess(bool success)
{
m_nMqttSuccess = success ? 1 : 2;
if (success)
{
printf("mqtt : connect mqtt server sucess ...\n");
......@@ -128,7 +138,7 @@ void RebuildManager::CallBackWhiteBoardData(AVPacket &pkt)
std::string req((char *)info.m_pData + 6, info.m_nDataSize - 6);
int index = *(int *)(info.m_pData + 6 + 8);
printf("---------------%d\n", index);
printf("whitebaord's data index = %d\n", index);
if (m_pMqtt)
{
......
......@@ -18,13 +18,16 @@ public:
bool ConnectMqttServer();
void DisConnectMqttServer();
int Connected() { return m_nMqttSuccess; }
bool OpenMediaFile(std::string filePath, std::string key);
bool OpenMediaFile();
void CloseMediaFile();
bool StartPull();
void StopPull();
bool EndOfFile();
private:
virtual void DoRunning();
......@@ -49,7 +52,10 @@ private:
private:
GlobalData m_configData;
private:
CmdTransportMqtt *m_pMqtt;
int m_nMqttSuccess;
private:
CFileReader m_fileReader;
......
......@@ -2,21 +2,63 @@
//
#include <iostream>
#include "global_data.h"
#include "rebuild_manager.h"
int main()
{
GlobalData config;
if (!config.LoadConfigFile())
RebuildManager *manager = new RebuildManager();
if (!manager->Init())
{
goto WaitFlag;
printf("init failed ...\n");
delete manager;
goto Error;
}
printf("init ok ...\n");
if (!manager->ConnectMqttServer())
{
delete manager;
printf("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
{
delete manager;
goto Error;
}
if (!manager->OpenMediaFile())
{
printf("open media file failed ...\n");
goto Error;
}
WaitFlag:
manager->StartPull();
while (!manager->EndOfFile())
{
std::chrono::milliseconds dura(1000);
std::this_thread::sleep_for(dura);
}
manager->StopPull();
manager->CloseMediaFile();
manager->DisConnectMqttServer();
Error:
printf("Press enter key to exit ...\n");
getchar();
return 0;
}
{
"roomid":"3ae42ba21356a02a9535092b0c6b777b",
"uuid":"liweijieisvip_309",
"filepath":"https://vod-live.offcncloud.com/vod/20211109037879836/vod/47a480ebd9a2c46912ac21836aaeb22e/index.m3u8",
"key":"7b539939e9103688"
}
\ No newline at end of file
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