版权声明:www.gudianxiaoshuo.com (古典小说网) 今日头条号: 古典古韵古典小说、讨厌编程 https://blog.csdn.net/shuilan0066/article/details/83619884
1 获取可用的音视频设备列表
Nlss_GetFreeDevicesNum
获取当前摄像头/麦克风的个数。
NLSS_RET Nlss_GetFreeDevicesNum(NLSS_OUT int *iVideoDeviceNum, NLSS_OUT int *iAudioDeviceNum);
NLSS_RET Nlss_GetFreeDeviceInf(NLSS_OUT ST_NLSS_INDEVICE_INF *pstVideoDevices, int iMaxVideoDevicesNum, NLSS_OUT ST_NLSS_INDEVICE_INF* pstAudioDevices, int iMaxAudioDevicesNum);
bool LssManange::GetFreeDevicesNum(int* video_num, int* audio_num)
{
if (NLSS_OK == NLS_SDK_GET_FUNC(Nlss_GetFreeDevicesNum)(video_num, audio_num))
return true;
else
return false;
}
void CheckDeviceInfo(ST_NLSS_INDEVICE_INF** info, int num)
{
if (num > 0)
{
*info = new ST_NLSS_INDEVICE_INF[num];
for (int i = 0; i < num; i++)
{
(*info)[i].paPath = new char[1024];
(*info)[i].paFriendlyName = new char[1024];
}
}
}
bool LssManange::GetFreeDeviceInf(NLSS_OUT ST_NLSS_INDEVICE_INF **pstVideoDevices, int *iMaxVideoDevicesNum, NLSS_OUT ST_NLSS_INDEVICE_INF**pstAudioDevices, int *iMaxAudioDevicesNum)
{
GetFreeDevicesNum(iMaxVideoDevicesNum, iMaxAudioDevicesNum);
if (iMaxVideoDevicesNum)
{
CheckDeviceInfo(pstVideoDevices, *iMaxVideoDevicesNum);
}
if (iMaxAudioDevicesNum)
{
CheckDeviceInfo(pstAudioDevices, *iMaxAudioDevicesNum);
}
if (NLSS_OK == NLS_SDK_GET_FUNC(Nlss_GetFreeDeviceInf)(*pstVideoDevices, *iMaxVideoDevicesNum, *pstAudioDevices, *iMaxAudioDevicesNum))
return true;
else
return false;
}
示例:
int32_t m_iAudioDeviceNum; //麦克风数目
ST_NLSS_INDEVICE_INF * m_pAudioDevices; //麦克风设备列表
int32_t m_iVideoDeviceNum; //视频设备数目
ST_NLSS_INDEVICE_INF * m_pVideoDevices; //视频设备列表
nim_nls::LssManange::GetFreeDeviceInf(&m_pVideoDevices, &m_iVideoDeviceNum, &m_pAudioDevices, &m_iAudioDeviceNum);
2 遍历摄像头
扫描二维码关注公众号,回复:
5281350 查看本文章
std::string NLSLiveForm::GetCurCameraName(){
std::string curCameraPath = GetCurCameraPath();
for (int i = 0; i < m_iVideoDeviceNum;i++)
{
if (curCameraPath==m_pVideoDevices[i].paPath)
{
return m_pVideoDevices[i].paFriendlyName;
}
}
return "";
}
int NLSLiveForm::GetCameraIndeviceIndex(std::string accid){
for (int i = 0; i < m_iVideoDeviceNum;i++)
{
if (accid.find(m_pVideoDevices[i].paPath) != std::string::npos)
{
return i;
}
}
return -1;
}
std::string NLSLiveForm::GetCameraNameFromPath(std::string path){
for (int i = 0; i < m_iVideoDeviceNum; i++)
{
if (path == m_pVideoDevices[i].paPath)
{
return m_pVideoDevices[i].paFriendlyName;
}
}
return "";
}
std::string NLSLiveForm::GetCameraPathFromName(std::string name){
for (int i = 0; i < m_iVideoDeviceNum; i++)
{
if (name == m_pVideoDevices[i].paFriendlyName)
{
return m_pVideoDevices[i].paPath;
}
}
return "";
}
std::string vedioPath;
std::string firstCameraPath;
//加入第一个摄像头
//默认预览第一个
m_VideoSourceType = EN_NLSS_VIDEOIN_CAMERA;
vedioPath = m_pVideoDevices[0].paPath;
firstCameraPath = m_pVideoDevices[0].paPath;
m_CameraPathList.push_back(vedioPath);
pCameraWnd->SetCurCamera(GetCurCameraPath(), m_CameraCaptureQ);
//处于预览中,才能添加其它视频源
PreView();
//加入其它摄像头
for (int i = 1; i < m_iVideoDeviceNum;i++)
{
vedioPath = m_pVideoDevices[i].paPath;
m_CameraPathList.push_back(vedioPath);
//设置当前摄像头所能采集的清晰度
pCameraWnd->SetCurCamera(GetCurCameraPath(), m_CameraCaptureQ);
AddNewVideoSource(); //每次加的设备路径 为m_CameraPathList.back() 最后末尾
}
3 ACCID
std::string NLSLiveForm::GetAccidFromPath(std::string path, int nVideoType)
{
std::string accid;
bool bVideoExisten = false;
switch (nVideoType)
{
case EN_NLSS_VIDEOIN_FULLSCREEN:
accid = "video name is fullscreen";
break;
case EN_NLSS_VIDEOIN_CAMERA:
//获取视频参数
if (m_pVideoDevices != NULL)
{
// m_VideoTypeName = L"摄像头";
accid = nbase::StringPrintf("child video name is camera,path :%s", path.c_str());
}
else
{
return accid;
}
break;
case EN_NLSS_VIDEOIN_RECTSCREEN:
break;
case EN_NLSS_VIDEOIN_APP:
if (m_pAppWinds != NULL)
{
accid = nbase::StringPrintf("child video name is app path :%s", path.c_str());
}
else
{
return accid;
}
break;
case EN_NLSS_VIDEOIN_PNG:
{
}
break;
case EN_NLSS_VIDEOIN_NONE:
return accid;
break;
default:
return accid;
break;
}
return accid;
}
std::string NLSLiveForm::GetAccidFromName(std::string name){
std::string path = GetCameraPathFromName(name);
if (path != "")
{
std::string accid = GetAccidFromPath(path);
return accid;
}
else
return "";
}
std::string NLSLiveForm::GetCurCameraAccid(){
//m_CameraPathList.back();
std::string curVideoPath = m_CameraPathList.back();
return GetAccidFromPath(curVideoPath);
}
_HNLSSCHILDSERVICE
std::map<std::string, _HNLSSCHILDSERVICE > nlss_child_services_; //子窗口句柄映射
std::string accid; //子窗口标识符
_HNLSSCHILDSERVICE LsSession::GetChildServiceByAccid(std::string accid)
{
nbase::NAutoLock auto_lock(&lock_);
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
{
return iter->second;
}
return NULL;
}
打开摄像头时,创建该摄像头句柄
bool LsSession::OnChildVideoOpen(const std::string& accid, ST_NLSS_VIDEOIN_PARAM *pVideoInParam)
{
nbase::NAutoLock auto_lock(&lock_);
bool ret = false;
if (ls_client_)
{
_HNLSSCHILDSERVICE NewLsChildClient = NLS_SDK_GET_FUNC(Nlss_ChildVideoOpen)(LsClient, pVideoInParam);
if (NewLsChildClient != NULL)
{
if (nlss_child_services_.find(accid) == nlss_child_services_.end())
{
std::pair< std::map< std::string, _HNLSSCHILDSERVICE>::iterator, bool > inert_ret;
inert_ret = nlss_child_services_.insert(std::pair<std::string, _HNLSSCHILDSERVICE >(accid, NewLsChildClient));
if (inert_ret.second)
ret = true;
}
}
}
if (ret == false)
m_errorLog.WriteErrorFuc("OnChildVideoOpen");
return ret;
}
其它的摄像头管理操作,都是通过摄像头句柄实现的
设置为背景
void LsSession::OnChildVideoSetBackLayer(const std::string& accid)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoSetBackLayer)(iter->second);
}
上移图层
void LsSession::OnChildVideoSetAdjustLayer(const std::string& accid, bool bAdustUp)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoAdjustLayer)(iter->second, bAdustUp);
}
设置显示区域
void LsSession::OnChildVideoSetDisplayRect(const std::string& accid, ST_NLSS_RECTSCREEN_PARAM *pstRect)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoSetDisplayRect)(iter->second, pstRect);
}
关闭子窗口
void LsSession::OnChildVideoClose(const std::string& accid)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
{
NLS_SDK_GET_FUNC(Nlss_ChildVideoClose)(iter->second);
nlss_child_services_.erase(iter);
}
}
隐藏
void LsSession::OnChildVideoSwitchDisplay(const std::string& accid, bool bHide)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoSwitchDisplay)(iter->second, bHide);
}
开始采集
bool LsSession::OnChildVideoStartCapture(const std::string& accid)
{
bool ret = false;
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
{
NLSS_RET nReturn = NLS_SDK_GET_FUNC(Nlss_ChildVideoStartCapture)(iter->second);
if (NLSS_OK != nReturn)
m_errorLog.WriteErrorFuc("Nlss_ChildVideoStartCapture", (int)nReturn);
ret = (NLSS_OK == nReturn);
}
return ret;
}
停止采集
void LsSession::OnChildVideoStopCapture(const std::string& accid)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoStopCapture)(iter->second);
}
设置单视频回调
void LsSession::OnChildVideoSetSoloPreviewCB(const std::string& accid, PFN_NLSS_CHILD_VIDEO_SAMPLER_CB pFunVideoSamplerCB)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoSetSoloPreviewCB)(iter->second, pFunVideoSamplerCB);
}
单视频回调开关
void LsSession::OnChildVideoSwitchSoloPreview(const std::string& accid, bool bOn)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoSwitchSoloPreview)(iter->second, bOn);
}
暂停推流
void LsSession::OnChildVideoPauseLiveStream(const std::string& accid)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoPauseLiveStream)(iter->second);
}
恢复推流
void LsSession::OnChildVideoResumeLiveStream(const std::string&accid)
{
std::map<std::string, _HNLSSCHILDSERVICE>::const_iterator iter = nlss_child_services_.find(accid);
if (iter != nlss_child_services_.end())
NLS_SDK_GET_FUNC(Nlss_ChildVideoResumeLiveStream)(iter->second);
}
开始推流
void LsSession::DoStartLiveStream(nim_nls::OptCallback cb)
{
bool ret = false;
if (NLSS_OK == NLS_SDK_GET_FUNC(Nlss_StartLiveStream)(LsClient))
{
live_streaming_ = true;
ret = true;
}
else {
ret = false;
}
if (cb)
{
Post2UI(nbase::Bind(cb, ret));
}
}
结束推流
void LsSession::DoStopLiveStream(nim_nls::OptCallback cb)
{
nbase::NAutoLock auto_lock(&lock_);
bool ret = true;
if (live_streaming_ && ls_client_)
{
NLS_SDK_GET_FUNC(Nlss_StopLiveStream)(LsClient);
{
live_streaming_ = false;
ret = true;
}
}
else {
ret = false;
}
if (cb)
{
Post2UI(nbase::Bind(cb, ret));
}
}