海康二次开发资料
- 格式:docx
- 大小:187.80 KB
- 文档页数:8
流媒体二次开发 -- C++
(2012-03-16 18:00:45)
转载▼
标签:
/s/blog_6310d7110100xu49.html
流媒体开发
it
好了,现在让我们先从VC6.0开始研究海康流媒体二次开发吧。
首先,联系杭州海康威视官方获取流媒体二次开发SDK文档和Demo示例
(client.dll,PlayM4.dll)这两个Dll文件是进行流媒体二次开发必需DLL。
接着,用官方Demo 里的.exe程序测试你所获取的流媒体实时流是否可用。
好了,到这里如果可以看到视频播放了,那么你的流媒体实时流URL就是正确的了。
运行VC6.0,打开clientTest工程文件,如果没有看见clientTest.dsw,可以任意打开一个.cpp 文件,编译时系统自动生成.dsw工程文件。
这里需注意的是,本文运用的是VC6.0,因此海康Demo里的例子编译会提示出错信息:无法识别关键字super。
在研究过程中,我将这些编译错误一一解决,编译通过,但是运行时,却无启动任何操作界面。
于是结合SDK开发文档,研究Demo里流媒体播放的代码,发现不是很复杂,于是就自己在VC6.0重新写一个测试流媒体播放的程序。
1. C++新建MFC AppWizard[exe]工程(单个或多个Dialog)
2. 在Dialog上拖拉picture,button,editbox控件,并右击属性更改控件名称
这里的picture里的Image可以通过菜单Insert-Resource,导入图片(系统自动命名IDB_BITMAP1),然后在上述picture属性框中Image选择导入图片名称即可。
3. 接着选择button,右击选中ClassWizard,添加点击事件
(1)可以看到Button默认有BN_CLICKED,BN_DOUBLECLICKED事件,因此可以不必再添加。
(2)可以看见Dialog中所有控件都在此显示,因此在这里我们为EditBox添加变量
4. 右击Button,选择Events,可以更改单击事件名称OnBtnPlay
5. 双击Button,进入点击事件,可以在此编写播放事件(暂时不编写,等待准备工作就绪再编写)
6. 工程FileView视图-HeadFiles导入client.h,clntsink.h
7. 更改clientTestDlg.h文件,继承clntsink回调函数集,并声明2个全局变量,intm_hSession;intm_hdown;
#include "client.h"
#include "afxcmn.h"
#include "afxwin.h"
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CClientTestDlg dialog
#define NORMALBACK
#ifdef NORMALBACK
classCClientTestDlg : public CDialog,publicIHikClientAdviseSink
#else
classCClientTestDlg : public CDialog
#endif
{
// Construction
public:
CClientTestDlg(CWnd* pParent = NULL); // standard constructor
#ifdef NORMALBACK
virtualintOnPosLength(unsigned long nLength);
virtualintOnPresentationOpened(int success);
virtualintOnPresentationClosed();
virtualintOnPreSeek(unsigned long uOldTime, unsigned long uNewTime);
virtualintOnPostSeek(unsigned long uOldTime, unsigned long uNewTime);
virtualintOnStop();
virtualintOnPause(unsigned long uTime);
virtualintOnBegin(unsigned long uTime);
virtualintOnRandomBegin(unsigned long uTime);
virtualintOnContacting(const char* pszHost);
virtualintOnBuffering(unsigned intuFlag, unsigned short uPercentComplete);
virtualintOnPutErrorMsg(const char* pError);
virtualintOnChangeRate(int flag);
virtualintOnDisconnect();
#endif
.....................
public:
intm_hSession;
intm_hdown;
8. 更改clientTest.cpp文件(引用client.h),在初始化InitInstance中加入InitStreamClientLib();, FiniStreamClientLib();
9. 到这里,我们可以开始在clientTestDlg.cpp(引用client.h, clintsink.h)中编写Button点击事件:
// TODO: Add your control notification handler code here
intnRet;
if (m_hSession>=0)
{
nRet=HIKS_Stop(m_hSession);
m_opened=-1;
}
HWND hWnd = GetDlgItem(IDC_STATIC_PictureShow)->GetSafeHwnd();
m_hSession=HIKS_CreatePlayer(this,hWnd,DoRecord);
if (m_hSession!=-1)
{
UpdateData(true);
nRet=HIKS_OpenURL(m_hSession,m_URLvalue.GetBuffer(0),0);
if (nRet != 1)
{
HIKS_Destroy(m_hSession);
m_hSession=-1;
m_opened=-1;
return;
}
}
while (m_opened< 0)
{
Sleep(500);
}
if (m_opened<= 0)
{
HIKS_Destroy(m_hSession);
m_hSession = -1;
m_opened = -1;
}
nRet=HIKS_Play(m_hSession);
if(nRet != 1)
{
HIKS_Stop(m_hSession);
m_hSession = -1;
m_opened = -1;
}
注意:
(1)菜单栏Project-settings,选择Link,添加client.lib 。
在VC安装目录下,找到Include,添加client.h,clntsink.h;在Lib添加client.lib
(2)在debug编译的clientTest.exe,添加client.cll,playm4.cll等文件。