Skip to content

Commit

Permalink
优化EasyPlayer延迟、音视频同步及录像
Browse files Browse the repository at this point in the history
  • Loading branch information
jinlong0813 committed May 7, 2017
1 parent 7590343 commit 4d6c0da
Show file tree
Hide file tree
Showing 20 changed files with 635 additions and 71 deletions.
Binary file added win32/EasyPlayer/test0.h264
Binary file not shown.
6 changes: 4 additions & 2 deletions win32/EasyPlayerWebActiveX/EasyPlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ EasyPlayerManager::~EasyPlayerManager(void)
//
// char szURL[128] = {0,};
// __WCharToMByte(wszURL, szURL, sizeof(szURL)/sizeof(szURL[0]));
//
int EasyPlayerManager::Start(char* szURL, HWND hShowWnd,
RENDER_FORMAT eRenderFormat, int rtpovertcp, const char *username, const char *password, MediaSourceCallBack callback, void *userPtr)
RENDER_FORMAT eRenderFormat, int rtpovertcp, const char *username, const char *password, int bHardDecode, MediaSourceCallBack callback, void *userPtr)
{
//Stop
if (m_sSourceInfo.rtspSourceId > 0)
Expand All @@ -35,7 +36,8 @@ int EasyPlayerManager::Start(char* szURL, HWND hShowWnd,
return -1;
}

m_sSourceInfo.rtspSourceId = EasyPlayer_OpenStream(szURL, hShowWnd, eRenderFormat, rtpovertcp, username, password, callback, userPtr, true);
m_sSourceInfo.rtspSourceId = EasyPlayer_OpenStream(szURL, hShowWnd, eRenderFormat,
rtpovertcp, username, password, callback, userPtr, (bHardDecode==TRUE)?true:false );
return m_sSourceInfo.rtspSourceId ;
}

Expand Down
2 changes: 1 addition & 1 deletion win32/EasyPlayerWebActiveX/EasyPlayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class EasyPlayerManager
}

//打开流
int Start(char* szURL, HWND hShowWnd, RENDER_FORMAT eRenderFormat, int rtpovertcp, const char *username, const char *password, MediaSourceCallBack callback=NULL, void *userPtr=NULL) ;
int Start(char* szURL, HWND hShowWnd, RENDER_FORMAT eRenderFormat, int rtpovertcp, const char *username, const char *password, int bHardDecode, MediaSourceCallBack callback=NULL, void *userPtr=NULL) ;
//设置参数
void Config(int nFrameCache, BOOL bPlaySound, BOOL bShowToScale = TRUE, BOOL bShowStatisticInfo = FALSE);
//关闭流
Expand Down
2 changes: 1 addition & 1 deletion win32/EasyPlayerWebActiveX/EasyPlayerWebActiveX.idl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ library EasyPlayerWebActiveXLib
methods:

[id(DISPID_ABOUTBOX)] void AboutBox();
[id(1)] LONG Start(BSTR sURL, BSTR sRenderFormat, BSTR sUserName, BSTR sPassword);
[id(1)] LONG Start(BSTR sURL, BSTR sRenderFormat, BSTR sUserName, BSTR sPassword, BSTR sHardDecord);
[id(2)] void Config(BSTR sFrameCache, BSTR sPlaySound, BSTR sShowToScale, BSTR sShowStatisticInfo);
[id(3)] void Close(void);
};
Expand Down
13 changes: 10 additions & 3 deletions win32/EasyPlayerWebActiveX/EasyPlayerWebActiveXCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CEasyPlayerWebActiveXCtrl, COleControl)
DISP_FUNCTION_ID(CEasyPlayerWebActiveXCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
DISP_FUNCTION_ID(CEasyPlayerWebActiveXCtrl, "Start", dispidStart, Start, VT_I4, VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR)
DISP_FUNCTION_ID(CEasyPlayerWebActiveXCtrl, "Start", dispidStart, Start, VT_I4, VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR)
DISP_FUNCTION_ID(CEasyPlayerWebActiveXCtrl, "Config", dispidConfig, Config, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR)
DISP_FUNCTION_ID(CEasyPlayerWebActiveXCtrl, "Close", dispidClose, Close, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
Expand Down Expand Up @@ -255,14 +255,15 @@ void CEasyPlayerWebActiveXCtrl::OnDestroy()
}


LONG CEasyPlayerWebActiveXCtrl::Start(LPCTSTR sURL, LPCTSTR sRenderFormat, LPCTSTR sUserName, LPCTSTR sPassword)
LONG CEasyPlayerWebActiveXCtrl::Start(LPCTSTR sURL, LPCTSTR sRenderFormat, LPCTSTR sUserName, LPCTSTR sPassword, LPCTSTR sHardDecord)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加调度处理程序代码
char szURL[512] = {0,};
char szRenderFormat[128] = {0,};
char szUserName[128] = {0,};
char szPassword[128] = {0,};
char szHardDecord[128] = {0,};

if (wcslen(sURL) < 1)
return -1;
Expand All @@ -279,6 +280,12 @@ LONG CEasyPlayerWebActiveXCtrl::Start(LPCTSTR sURL, LPCTSTR sRenderFormat, LPCTS
{
__WCharToMByte(sPassword, szPassword, sizeof(szPassword)/sizeof(szPassword[0]));
}
if (wcslen(sHardDecord) > 0)
{
__WCharToMByte(sHardDecord, szHardDecord, sizeof(szHardDecord)/sizeof(szHardDecord[0]));
}

int nHardDecode = atoi(szHardDecord);

int nRenderType = atoi(szRenderFormat);
RENDER_FORMAT eRenderFormat = DISPLAY_FORMAT_YV12;
Expand Down Expand Up @@ -310,7 +317,7 @@ LONG CEasyPlayerWebActiveXCtrl::Start(LPCTSTR sURL, LPCTSTR sRenderFormat, LPCTS
break;
}

int nRet = m_player.Start(szURL, m_pActiveDlg.GetSafeHwnd(), eRenderFormat , 1, szUserName , szPassword);
int nRet = m_player.Start(szURL, m_pActiveDlg.GetSafeHwnd(), eRenderFormat , 1, szUserName , szPassword, nHardDecode);
return nRet;
}

Expand Down
2 changes: 1 addition & 1 deletion win32/EasyPlayerWebActiveX/EasyPlayerWebActiveXCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CEasyPlayerWebActiveXCtrl : public COleControl
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
protected:
LONG Start(LPCTSTR sURL, LPCTSTR sRenderFormat, LPCTSTR sUserName, LPCTSTR sPassword);
LONG Start(LPCTSTR sURL, LPCTSTR sRenderFormat, LPCTSTR sUserName, LPCTSTR sPassword, LPCTSTR sHardDecord);
void Config(LPCTSTR sFrameCache, LPCTSTR sPlaySound, LPCTSTR sShowToScale, LPCTSTR sShowStatisticInfo);
void Close(void);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@

#include "EasyTypes.h"

#define RTSP_PROG_NAME "EasyRTSPClient v1.16.0721"

/*
_channelId: 通道号,暂时不用
_channelPtr: 通道对应对象,暂时不用
_frameType: EASY_SDK_VIDEO_FRAME_FLAG/EASY_SDK_AUDIO_FRAME_FLAG/EASY_SDK_EVENT_FRAME_FLAG/...
_pBuf: 回调的数据部分,具体用法看Demo
_frameInfo: 帧结构数据
*/
typedef int (Easy_APICALL *RTSPSourceCallBack)( int _channelId, int *_channelPtr, int _frameType, char *pBuf, RTSP_FRAME_INFO* _frameInfo);
typedef int (Easy_APICALL *RTSPSourceCallBack)( int _channelId, void *_channelPtr, int _frameType, char *pBuf, RTSP_FRAME_INFO* _frameInfo);

#ifdef __cplusplus
extern "C"
{
#endif
/* 获取最后一次错误的错误码 */
Easy_API int Easy_APICALL EasyRTSP_GetErrCode();
Easy_API int Easy_APICALL EasyRTSP_GetErrCode(Easy_RTSP_Handle handle);

/* 激活 */
Easy_API int Easy_APICALL EasyRTSP_Activate(char *license);

/* 创建RTSPClient句柄 返回0表示成功,返回非0表示失败 */
Easy_API int Easy_APICALL EasyRTSP_Init(Easy_RTSP_Handle *handle);
Expand All @@ -35,7 +40,7 @@ extern "C"
Easy_API int Easy_APICALL EasyRTSP_SetCallback(Easy_RTSP_Handle handle, RTSPSourceCallBack _callback);

/* 打开网络流 */
Easy_API int Easy_APICALL EasyRTSP_OpenStream(Easy_RTSP_Handle handle, int _channelid, char *_url, RTP_CONNECT_TYPE _connType, unsigned int _mediaType, char *_username, char *_password, void *userPtr, int _reconn/*1000表示长连接,即如果网络断开自动重连, 其它值为连接次数*/, int outRtpPacket/*默认为0,即回调输出完整的帧, 如果为1,则输出RTP包*/);
Easy_API int Easy_APICALL EasyRTSP_OpenStream(Easy_RTSP_Handle handle, int _channelid, char *_url, EASY_RTP_CONNECT_TYPE _connType, unsigned int _mediaType, char *_username, char *_password, void *userPtr, int _reconn/*1000表示长连接,即如果网络断开自动重连, 其它值为连接次数*/, int outRtpPacket/*默认为0,即回调输出完整的帧, 如果为1,则输出RTP包*/, int heartbeatType/*0x00:不发送心跳 0x01:OPTIONS 0x02:GET_PARAMETER*/, int _verbosity/*日志打印输出等级,0表示不输出*/);

/* 关闭网络流 */
Easy_API int Easy_APICALL EasyRTSP_CloseStream(Easy_RTSP_Handle handle);
Expand Down
87 changes: 60 additions & 27 deletions win32/EasyPlayerWebActiveX/libEasyPlayer/EasyRTSPClient/EasyTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
#define Easy_APICALL
#endif

// Handle类型
// Handle Type
#define Easy_RTSP_Handle void*
#define Easy_Pusher_Handle void*
#define Easy_HLS_Handle void*

typedef int Easy_I32;

typedef unsigned char Easy_U8;
typedef unsigned char Easy_UChar;
Expand Down Expand Up @@ -56,71 +59,101 @@ enum
};
typedef int Easy_Error;


typedef enum __EASY_ACTIVATE_ERR_CODE_ENUM
{
EASY_ACTIVATE_INVALID_KEY = -1, /* 无效Key */
EASY_ACTIVATE_TIME_ERR = -2, /* 时间错误 */
EASY_ACTIVATE_PROCESS_NAME_LEN_ERR = -3, /* 进程名称长度不匹配 */
EASY_ACTIVATE_PROCESS_NAME_ERR = -4, /* 进程名称不匹配 */
EASY_ACTIVATE_VALIDITY_PERIOD_ERR= -5, /* 有效期校验不一致 */
EASY_ACTIVATE_PLATFORM_ERR = -6, /* 平台不匹配 */
EASY_ACTIVATE_COMPANY_ID_LEN_ERR= -7, /* 授权使用商不匹配 */
EASY_ACTIVATE_SUCCESS = 0, /* 激活成功 */

}EASY_ACTIVATE_ERR_CODE_ENUM;


/* 视频编码 */
#define EASY_SDK_VIDEO_CODEC_H264 0x1C /* H264 */
#define EASY_SDK_VIDEO_CODEC_H265 0x48323635 /* 1211250229 */
#define EASY_SDK_VIDEO_CODEC_MJPEG 0x08 /* MJPEG */
#define EASY_SDK_VIDEO_CODEC_MPEG4 0x0D /* MPEG4 */

/* 音频编码 */
#define EASY_SDK_AUDIO_CODEC_AAC 0x15002 /* AAC */
#define EASY_SDK_AUDIO_CODEC_G711U 0x10006 /* G711 ulaw*/
#define EASY_SDK_AUDIO_CODEC_G711A 0x10007 /* G711 alaw*/
#define EASY_SDK_AUDIO_CODEC_G726 0x1100B /* G726 */

#define EASY_SDK_EVENT_CODEC_ERROR 0x63657272 /* ERROR */
#define EASY_SDK_EVENT_CODEC_EXIT 0x65786974 /* EXIT */
#define EASY_SDK_EVENT_CODEC_SHOT_START 0x12001 /* Screen shot start*/
#define EASY_SDK_EVENT_CODEC_SLOT_STOP 0x12002 /* Screen shot stop */
#define EASY_SDK_EVENT_CODEC_RECORD_START 0x12003 /* Record Start */
#define EASY_SDK_EVENT_CODEC_RECORD_STOP 0x12004 /* Record Stop */

/* 音视频帧标识 */
#define EASY_SDK_VIDEO_FRAME_FLAG 0x00000001 /* 视频帧标志 */
#define EASY_SDK_AUDIO_FRAME_FLAG 0x00000002 /* 音频帧标志 */
#define EASY_SDK_EVENT_FRAME_FLAG 0x00000004 /* 事件帧标志 */
#define EASY_SDK_RTP_FRAME_FLAG 0x00000008 /* RTP帧标志 */
#define EASY_SDK_SDP_FRAME_FLAG 0x00000010 /* SDP帧标志 */
#define EASY_SDK_MEDIA_INFO_FLAG 0x00000020 /* 媒体类型标志*/
#define EASY_SDK_VIDEO_RAW_RGB 0x00000040
#define EASY_SDK_MEDIA_INFO_FLAG 0x00000020 /* 媒体类型标志*/

/* 视频关键字标识 */
#define EASY_SDK_VIDEO_FRAME_I 0x01 /* I帧 */
#define EASY_SDK_VIDEO_FRAME_P 0x02 /* P帧 */
#define EASY_SDK_VIDEO_FRAME_B 0x03 /* B帧 */
#define EASY_SDK_VIDEO_FRAME_J 0x04 /* JPEG */

/* 连接类型 */
typedef enum __RTP_CONNECT_TYPE
typedef enum __EASY_RTP_CONNECT_TYPE
{
RTP_OVER_TCP = 0x01, /* RTP Over TCP */
RTP_OVER_UDP /* RTP Over UDP */
}RTP_CONNECT_TYPE;
EASY_RTP_OVER_TCP = 0x01, /* RTP Over TCP */
EASY_RTP_OVER_UDP /* RTP Over UDP */
}EASY_RTP_CONNECT_TYPE;

/* 媒体信息 */
typedef struct __EASY_MEDIA_INFO_T
{
Easy_U32 u32VideoCodec; /* 视频编码类型 */
Easy_U32 u32VideoFps; /* 视频帧率 */

Easy_U32 u32AudioCodec; /* 音频编码类型 */
Easy_U32 u32AudioSamplerate; /* 音频采样率 */
Easy_U32 u32AudioChannel; /* 音频通道数 */
Easy_U32 u32VideoCodec; /* 视频编码类型 */
Easy_U32 u32VideoFps; /* 视频帧率 */

Easy_U32 u32AudioCodec; /* 音频编码类型 */
Easy_U32 u32AudioSamplerate; /* 音频采样率 */
Easy_U32 u32AudioChannel; /* 音频通道数 */
Easy_U32 u32AudioBitsPerSample; /* 音频采样精度 */

Easy_U32 u32H264SpsLength; /* 视频sps帧长度 */
Easy_U32 u32H264PpsLength; /* 视频pps帧长度 */
Easy_U8 u8H264Sps[128]; /* 视频sps帧内容 */
Easy_U8 u8H264Pps[36]; /* 视频sps帧内容 */
}EASY_MEDIA_INFO_T;

/* 帧信息 */
typedef struct
{
unsigned int codec; /* 音视频格式 */
unsigned int codec; /* 音视频格式 */

unsigned int type; /* 视频帧类型 */
unsigned char fps; /* 视频帧率 */
unsigned short width; /* 视频宽 */
unsigned short height; /* 视频高 */
unsigned int type; /* 视频帧类型 */
unsigned char fps; /* 视频帧率 */
unsigned short width; /* 视频宽 */
unsigned short height; /* 视频高 */

unsigned int reserved1; /* 保留参数1 */
unsigned int reserved2; /* 保留参数2 */
unsigned int reserved1; /* 保留参数1 */
unsigned int reserved2; /* 保留参数2 */

unsigned int sample_rate; /* 音频采样率 */
unsigned int channels; /* 音频声道数 */
unsigned int sample_rate; /* 音频采样率 */
unsigned int channels; /* 音频声道数 */
unsigned int bits_per_sample; /* 音频采样精度 */

unsigned int length; /* 音视频帧大小 */
unsigned int timestamp_usec; /* 时间戳,微妙 */
unsigned int timestamp_sec; /* 时间戳 秒 */
unsigned int length; /* 音视频帧大小 */
unsigned int timestamp_usec; /* 时间戳,微妙 */
unsigned int timestamp_sec; /* 时间戳 秒 */

float bitrate; /* 比特率 */
float losspacket; /* 丢包率 */
float bitrate; /* 比特率 */
float losspacket; /* 丢包率 */
}RTSP_FRAME_INFO;

#endif
Binary file not shown.
Binary file not shown.
Binary file modified win32/EasyPlayerWebActiveX/libEasyPlayer/libEasyPlayer.dll
Binary file not shown.
Binary file modified win32/EasyPlayerWebActiveX/libEasyPlayer/libEasyPlayer.lib
Binary file not shown.
14 changes: 6 additions & 8 deletions win32/EasyPlayerWebActiveX/libEasyPlayer/libEasyPlayerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
Author: [email protected]
*/



#ifndef __LIB_EASY_PLAYER_API_H__
#define __LIB_EASY_PLAYER_API_H__

Expand All @@ -32,16 +30,13 @@ typedef enum __RENDER_FORMAT
DISPLAY_FORMAT_RGB24_GDI= 26
}RENDER_FORMAT;



typedef int (CALLBACK *MediaSourceCallBack)( int _channelId, int *_channelPtr, int _frameType, char *pBuf, RTSP_FRAME_INFO* _frameInfo);


LIB_EASYPLAYER_API int EasyPlayer_Init();
LIB_EASYPLAYER_API void EasyPlayer_Release();


LIB_EASYPLAYER_API int EasyPlayer_OpenStream(const char *url, HWND hWnd, RENDER_FORMAT renderFormat, int rtpovertcp, const char *username, const char *password, MediaSourceCallBack callback=NULL, void *userPtr=NULL, bool bHardDecode=true);
LIB_EASYPLAYER_API int EasyPlayer_OpenStream(const char *url, HWND hWnd, RENDER_FORMAT renderFormat,
int rtpovertcp, const char *username, const char *password, MediaSourceCallBack callback=NULL, void *userPtr=NULL, bool bHardDecode=true);
LIB_EASYPLAYER_API void EasyPlayer_CloseStream(int channelId);
LIB_EASYPLAYER_API int EasyPlayer_SetFrameCache(int channelId, int cache);
LIB_EASYPLAYER_API int EasyPlayer_SetShownToScale(int channelId, int shownToScale);
Expand All @@ -59,7 +54,10 @@ LIB_EASYPLAYER_API int EasyPlayer_StopManuRecording(int channelId);
LIB_EASYPLAYER_API int EasyPlayer_PlaySound(int channelId);
LIB_EASYPLAYER_API int EasyPlayer_StopSound();

LIB_EASYPLAYER_API int EasyPlayer_SetManuRecordPath(int channelId, const char* recordPath);
LIB_EASYPLAYER_API int EasyPlayer_SetManuPicShotPath(int channelId, const char* shotPath);


LIB_EASYPLAYER_API int EasyPlayer_StartManuPicShot(int channelId);//pThread->manuScreenshot
LIB_EASYPLAYER_API int EasyPlayer_StopManuPicShot(int channelId);

#endif
Binary file added win32/bin/EasyPlayerWebActiveX.ocx
Binary file not shown.
8 changes: 5 additions & 3 deletions win32/bin/ocx test.htm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<HTML>
<HEAD>
<TITLE>MyActiveX</TITLE>
<TITLE>EasyPlayer</TITLE>
<script type="text/javascript">


Expand All @@ -25,8 +25,9 @@
var rendertype = document.getElementById("rendertype").value;
var name= document.getElementById("name").value;
var password = document.getElementById("password").value;
var harddecode = document.getElementById("harddecode").value;

obj.Start(url, rendertype, name, password);
obj.Start(url, rendertype, name, password, harddecode);
config();

//alert(url+";"+rendertype+";"+name+";"+password);
Expand All @@ -45,7 +46,7 @@

<BODY>
<center>
MyActiveX Example
EasyPlayer Plugin Example
<p></p>


Expand All @@ -59,6 +60,7 @@
RenderFormat:<input type="text" name="rendertype" id="rendertype" VALUE="0"/>
用户名:<input type="text" name="name" id="name" size=25 value="admin"/>
密码:<input type="text" name="password" id="password" size=25 value="admin"/>
采用硬解码:<input type="text" name="harddecode" id="harddecode" size=25 value="1"/>

<br>
缓存:<input type="text" name="cache" id="cache" size=25 value ="3"/>
Expand Down
2 changes: 1 addition & 1 deletion win32/bin/reg.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

cd ./
regsvr32 EasyPlayerWebActiveX.ocx
Loading

0 comments on commit 4d6c0da

Please sign in to comment.