#include "PlayManage.h"
PlayManager::PlayManager(const std::string &strUrl, HWND hWnd)
{
if (!strUrl.empty())
{
hwnd_ = hWnd;
m_TrackerThread = std::thread(std::bind(&PlayManager::PullStreamThread, this));
m_DetectorThread = std::thread(std::bind(&PlayManager::DecodeThread, this));
m_TrackerThread.join();
m_DetectorThread.join();
}
}
PlayManager::~PlayManager()
{
}
void PlayManager::PullStreamThread()
{
//在这里处理rtsp点播的一系列流程
//然后通过PullStreamHandler来上报结果
//DoWork()是个阻塞函数
RtspWork rtspWork(this);
rtspWork.DoWork();
}
void PlayManager::DecodeThread()
{
do
{
std::unique_lock<std::mutex> lk(s_mutex);
while (IsDequeEmpty())
m_ConVar.wait(lk);
if (!s_deque.empty())
{
StreamInfo info;
PopData(info);
//对info.pByte进行解码,假设结果还是存在info里;
DoDecode(info);
//第一种多线程通信方式:SendMessage/PostMessage
//对stream进行操作,最简单的就是发消息到HWND上,然后在里面绘图
SendMessage(hwnd_, WM_USER + 1, (WPARAM)info.pByte, (LPARAM)info.nLength);
if (info.pByte)
{
delete[] info.pByte;
info.pByte = nullptr;
}
}
lk.unlock();
} while (1);
}
void PlayManager::DoDecode(StreamInfo & info)
{
//解码的具体操作
//.....
}
void PlayManager::NoticeStream(byte* pByte, int nLength)
{
if (pByte == NULL || nLength <= 0)
return;
std::unique_lock<std::mutex> lk(s_mutex);
StreamInfo info;
info.nLength = nLength;
info.pByte = new byte[nLength];
memcpy(info.pByte, pByte, nLength);
PushData(info);
//这一个看情况是外面释放,还是里面释放
delete[]pByte;
// 通过条件变量通知其它等待的线程
m_ConVar.notify_all();
lk.unlock();
}
void PlayManager::PushData(const StreamInfo& info)
{
std::lock_guard<std::mutex> lockTmp(s_mutex2);
s_deque.push_back(info);
}
bool PlayManager::PopData(StreamInfo& info)
{
std::lock_guard<std::mutex> lockTmp(s_mutex2);
if (s_deque.size())
{
info = s_deque.front();
s_deque.pop_front();
return true;
}
else
{
return false;
}
}
bool PlayManager::IsDequeEmpty()
{
std::lock_guard<std::mutex> lockTmp(s_mutex2);
return !s_deque.empty();
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MultiThread.7z (23个子文件)
MultiThread
MultiThread
PlayManage.h 3KB
MultiThread.vcxproj.filters 1KB
MultiThread.vcxproj 4KB
PlayManage.cpp 2KB
main.cpp 89B
Debug
vc120.pdb 572KB
PlayManage.obj 316KB
main.obj 153KB
MultiThread.log 2KB
vc120.idb 1MB
MultiThread.tlog
CL.write.1.tlog 2KB
CL.read.1.tlog 62KB
cl.command.1.tlog 2KB
link.write.1.tlog 994B
link.command.1.tlog 2KB
link.read.1.tlog 3KB
MultiThread.lastbuildstate 206B
MultiThread.sln 979B
MultiThread.v12.suo 26KB
Debug
MultiThread.pdb 1.38MB
MultiThread.exe 92KB
MultiThread.ilk 526KB
MultiThread.sdf 31.69MB
共 23 条
- 1
资源评论
SimpleSimple
- 粉丝: 138
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功