Skip to content

Commit

Permalink
EasyRTSPServer 库文件&demo
Browse files Browse the repository at this point in the history
  • Loading branch information
LAPTOP-OE3TQ4TC\gavin committed Sep 2, 2019
0 parents commit afd8817
Show file tree
Hide file tree
Showing 49 changed files with 2,409 additions and 0 deletions.
Binary file added Bin/Linux_32bits/easystreamingserver
Binary file not shown.
Binary file added Bin/Linux_32bits/libEasyRTSPClient.so
Binary file not shown.
Binary file added Bin/Linux_32bits/libEasyRTSPServer.so
Binary file not shown.
Binary file added Bin/Linux_64bits/easystreamingserver
Binary file not shown.
Binary file added Bin/Linux_64bits/libEasyRTSPClient.so
Binary file not shown.
Binary file added Bin/Linux_64bits/libEasyRTSPServer.so
Binary file not shown.
Binary file added Bin/Win32/EasyStreamingServer.exe
Binary file not shown.
Binary file added Bin/Win32/libEasyRTSPClient.dll
Binary file not shown.
Binary file added Bin/Win32/libEasyRTSPServer.dll
Binary file not shown.
Binary file added Bin/Win64/EasyStreamingServer.exe
Binary file not shown.
Binary file added Bin/Win64/libEasyRTSPClient.dll
Binary file not shown.
Binary file added Bin/Win64/libEasyRTSPServer.dll
Binary file not shown.
Binary file added Bin/himix200-Linux/libEasyRTSPClient.so
Binary file not shown.
Binary file added Bin/himix200-Linux/libEasyRTSPServer.so
Binary file not shown.
21 changes: 21 additions & 0 deletions Doc/说明.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#运行说明

##Win
运行EasyStreamingServer.exe


##Linux
运行easystreamingserver


#RTSP拉流
##rtsp源地址为摄像机或NVR的rtsp地址. 比如rtsp://192.168.1.100/ch1
rtsp://192.168.1.160:554/rtsp://192.168.1.100/ch1
##rtsp源需带用户名密码的地址如下(用户名: admin 密码:12345):
rtsp://192.168.1.160:554/rtsp://admin:[email protected]/ch1


##说明
示例代码中支持H264/H265;
用户验证设置为不验证;
167 changes: 167 additions & 0 deletions Src/EasyCommon/EasyTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
Copyright (c) 2012-2019 TSINGSEE.COM. All rights reserved.
Github: https://github.com/tsingsee
WEChat: tsingsee
Website: http://www.tsingsee.com
*/
#ifndef _Easy_Types_H
#define _Easy_Types_H

#ifdef _WIN32
#include <winsock2.h>
#define Easy_API __declspec(dllexport)
#define Easy_APICALL __stdcall
#define WIN32_LEAN_AND_MEAN
#else
#define Easy_API
#define Easy_APICALL
#define CALLBACK
#endif

#define Easy_Handle void*

typedef int Easy_I32;
typedef unsigned char Easy_U8;
typedef unsigned char Easy_UChar;
typedef unsigned short Easy_U16;
typedef unsigned int Easy_U32;
typedef unsigned char Easy_Bool;

enum
{
Easy_NoErr = 0,
Easy_RequestFailed = -1,
Easy_Unimplemented = -2,
Easy_RequestArrived = -3,
Easy_OutOfState = -4,
Easy_NotAModule = -5,
Easy_WrongVersion = -6,
Easy_IllegalService = -7,
Easy_BadIndex = -8,
Easy_ValueNotFound = -9,
Easy_BadArgument = -10,
Easy_ReadOnly = -11,
Easy_NotPreemptiveSafe = -12,
Easy_NotEnoughSpace = -13,
Easy_WouldBlock = -14,
Easy_NotConnected = -15,
Easy_FileNotFound = -16,
Easy_NoMoreData = -17,
Easy_AttrDoesntExist = -18,
Easy_AttrNameExists = -19,
Easy_InstanceAttrsNotAllowed = -20,
Easy_InvalidSocket = -21,
Easy_MallocError = -22,
Easy_ConnectError = -23,
Easy_SendError = -24
};
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 = 9999, /* 激活成功 */

}EASY_ACTIVATE_ERR_CODE_ENUM;

/* 视频编码 */
#define EASY_SDK_VIDEO_CODEC_H264 0x1C /* H264 */
#define EASY_SDK_VIDEO_CODEC_H265 0xAE /* H265 */
#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_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_SNAP_FRAME_FLAG 0x00000040 /* 图片标志*/

/* 视频关键字标识 */
#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 __EASY_RTP_CONNECT_TYPE
{
EASY_RTP_OVER_TCP = 0x01, /* RTP Over TCP */
EASY_RTP_OVER_UDP, /* RTP Over UDP */
EASY_RTP_OVER_MULTICAST /* RTP Over MULTICAST */
}EASY_RTP_CONNECT_TYPE;

typedef struct __EASY_AV_Frame
{
Easy_U32 u32AVFrameFlag; /* 帧标志 视频 or 音频 */
Easy_U32 u32AVFrameLen; /* 帧的长度 */
Easy_U32 u32VFrameType; /* 视频的类型,I帧或P帧 */
Easy_U8 *pBuffer; /* 数据 */
Easy_U32 u32TimestampSec; /* 时间戳(秒)*/
Easy_U32 u32TimestampUsec; /* 时间戳(微秒) */
} EASY_AV_Frame;

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

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

Easy_U32 u32VpsLength;
Easy_U32 u32SpsLength;
Easy_U32 u32PpsLength;
Easy_U32 u32SeiLength;
Easy_U8 u8Vps[256];
Easy_U8 u8Sps[256];
Easy_U8 u8Pps[128];
Easy_U8 u8Sei[128];
}EASY_MEDIA_INFO_T;

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

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

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

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

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

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

#endif
56 changes: 56 additions & 0 deletions Src/EasyRTSPClient/EasyRTSPClientAPI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright (c) 2013-2015 EasyDarwin.ORG. All rights reserved.
Github: https://github.com/EasyDarwin
WEChat: EasyDarwin
Website: http://www.easydarwin.org
*/
#ifndef _Easy_RTSPClient_API_H
#define _Easy_RTSPClient_API_H

#include "../EasyCommon/EasyTypes.h"

#define RTSP_PROG_NAME "libEasyRTSPClient v3.0.19.0415"

/*
_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, void *_channelPtr, int _frameType, char *pBuf, EASY_FRAME_INFO* _frameInfo);

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

/* 激活 */
#ifdef ANDROID
Easy_API int Easy_APICALL EasyRTSP_Activate(char *license, char* userPtr);
#else
Easy_API int Easy_APICALL EasyRTSP_Activate(char *license);
#endif

/* 创建RTSPClient句柄 返回0表示成功,返回非0表示失败 */
Easy_API int Easy_APICALL EasyRTSP_Init(Easy_Handle *handle);

/* 释放RTSPClient 参数为RTSPClient句柄 */
Easy_API int Easy_APICALL EasyRTSP_Deinit(Easy_Handle *handle);

/* 设置数据回调 */
Easy_API int Easy_APICALL EasyRTSP_SetCallback(Easy_Handle handle, RTSPSourceCallBack _callback);

/* 打开网络流 */
Easy_API int Easy_APICALL EasyRTSP_OpenStream(Easy_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_Handle handle);

#ifdef __cplusplus
}
#endif

#endif
Binary file added Src/EasyRTSPClient/Win32/libEasyRTSPClient.dll
Binary file not shown.
Binary file added Src/EasyRTSPClient/Win32/libEasyRTSPClient.lib
Binary file not shown.
Binary file added Src/EasyRTSPClient/Win64/libEasyRTSPClient.dll
Binary file not shown.
Binary file added Src/EasyRTSPClient/Win64/libEasyRTSPClient.lib
Binary file not shown.
142 changes: 142 additions & 0 deletions Src/EasyRTSPServer/EasyRtspServerAPI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@

#ifndef __EASY_RTSP_SERVER_H__
#define __EASY_RTSP_SERVER_H__

#include "../EasyCommon/EasyTypes.h"

typedef enum _EASY_AUTHENTICATION_TYPE_ENUM
{
EASY_AUTHENTICATION_TYPE_NONE = 0x00, //不验证
EASY_AUTHENTICATION_TYPE_BASIC = 0x01,
EASY_AUTHENTICATION_TYPE_DIGEST = 0x02,
}EASY_AUTHENTICATION_TYPE_ENUM;




/* 媒体信息 */
typedef struct __EASY_RTSPSERVER_MEDIA_INFO_T
{
Easy_U32 videoCodec; //视频编码类型
Easy_U32 videoFps; //视频帧率
Easy_U32 videoQueueSize; //视频队列大小 如: 1024 * 1024

Easy_U32 audioCodec; //音频编码类型
Easy_U32 audioSampleRate; //音频采样率
Easy_U32 audioChannel; //音频通道数
Easy_U32 audioBitsPerSample; //音频采样精度
Easy_U32 audioQueueSize; //音频队列大小 如: 1024 * 128

Easy_U32 metadataCodec; //Metadata类型
Easy_U32 metadataQueueSize; //Metadata队列大小 如: 1024 * 512

Easy_U32 vpsLength; //视频vps帧长度
Easy_U32 spsLength; //视频sps帧长度
Easy_U32 ppsLength; //视频pps帧长度
Easy_U32 seiLength; //视频sei帧长度
Easy_U8 vps[256]; //视频vps帧内容
Easy_U8 sps[256]; //视频sps帧内容
Easy_U8 pps[128]; //视频sps帧内容
Easy_U8 sei[128]; //视频sei帧内容
}EASY_RTSPSERVER_MEDIA_INFO_T;

typedef enum __EASY_PLAY_CTRL_CMD_ENUM
{
EASY_PLAY_CTRL_CMD_GET_DURATION = 0x00000001, //获取录像时长
EASY_PLAY_CTRL_CMD_PAUSE = 0x00000002, //暂停
EASY_PLAY_CTRL_CMD_RESUME, //恢复
EASY_PLAY_CTRL_CMD_SCALE, //调整倍率
EASY_PLAY_CTRL_CMD_SEEK_STREAM, //跳转时间
}EASY_PLAY_CTRL_CMD_ENUM;

typedef struct __EASY_PLAY_CONTROL_INFO_T
{
EASY_PLAY_CTRL_CMD_ENUM ctrlCommand;
unsigned int mediaType;
float scale;
char startTime[36];
char endTime[36];
char suffix[256];
}EASY_PLAY_CONTROL_INFO_T;

typedef enum __EASY_RTSPSERVER_STATE_T
{
EASY_RTSPSERVER_STATE_ERROR = 0, //内部错误
EASY_CHANNEL_OPEN_STREAM = 0x00000001, //请求打开通道
EASY_CHANNEL_START_STREAM, //开始推流
EASY_CHANNEL_FIND_STREAM, //查找流 在START_STREAM后, 即正常推送流, 如果库内部长时间没有收到流,则会回调该状态
EASY_CHANNEL_STOP_STREAM, //停止推流 当访问对应通道的所有客户端都断开连接后, 回调该状态
EASY_CHANNEL_CLOSE_STREAM, //关闭通道 当访问对应通道的所有客户端都断开连接后, 回调该状态
EASY_CHANNEL_PLAY_CONTROL, //播放控制
}EASY_RTSPSERVER_STATE_T;


typedef void *EASY_CHANNEL_HANDLE;

/* 回调函数定义 userptr表示用户自定义数据 */
//mediaInfo中,需填写videoCodec、sps、pps
typedef Easy_I32 (CALLBACK *EasyRtspServer_Callback)(EASY_RTSPSERVER_STATE_T serverStatus, const char *resourceName,
EASY_CHANNEL_HANDLE *channelHandle,
EASY_RTSPSERVER_MEDIA_INFO_T *mediaInfo,
EASY_PLAY_CONTROL_INFO_T *playCtrlInfo,
void *userPtr, void *channelPtr);

#ifdef __cplusplus
extern "C"
{
#endif

/* 激活 */
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_Activate(const char *license);

/* 启动 RTSP Server */
/*设置监听端口, 回调函数及自定义数据 */
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_Startup(Easy_U16 listenPort, const char *realm,
EASY_AUTHENTICATION_TYPE_ENUM authType, const char *username, const char *password,
EasyRtspServer_Callback callback, void *userPtr);

/* 终止 RTSP Server */
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_Shutdown();


//创建通道
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_CreateChannel(const char *resourceName,
EASY_CHANNEL_HANDLE *channelHandle, void *channelPtr);

//发送帧数据
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_PushFrame(EASY_CHANNEL_HANDLE channelHandle,
EASY_AV_Frame *frame);

//删除通道
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_DeleteChannel(EASY_CHANNEL_HANDLE *channelHandle);


//分辨率变化 只要视频或音频参数变化时, 调用 EasyRtspServer_ResetChannel
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_ResetChannel(EASY_CHANNEL_HANDLE channelHandle);


//添加用户 或 根据用户名修改用户密码
//如果添加的用户名不存在,则为新增, 如已存在,则为修改密码
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_AddUser(const Easy_U8 *username, const Easy_U8 *password);
//删除用户
Easy_API Easy_I32 Easy_APICALL EasyRtspServer_DelUser(const Easy_U8 *username);


#ifdef __cplusplus
}
#endif


/*
流程:
1. 调用 EasyRtspServer_Startup 设置监听端口、回调函数和自定义数据指针
2. 启动后,程序进入监听状态
2.1 接收到客户端请求, 回调 状态:EASY_IPCAMERA_STATE_REQUEST_MEDIA_INFO 上层程序在填充完mediainfo后,返回0, 则EasyRtspServer响应客户端ok
2.2 EasyRtspServer回调状态 EASY_IPCAMERA_STATE_REQUEST_PLAY_STREAM , 则表示rtsp交互完成, 开始发送流, 上层程序调用EasyRtspServer_PushFrame 发送帧数据
2.3 EasyRtspServer回调状态 EASY_IPCAMERA_STATE_REQUEST_STOP_STREAM , 则表示客户端已发送teaardown, 要求停止发送帧数据
3. 调用 EasyRtspServer_Shutdown(), 关闭EasyRtspServer,释放相关资源
*/


#endif
Binary file added Src/EasyRTSPServer/Win32/libEasyRTSPServer.dll
Binary file not shown.
Binary file added Src/EasyRTSPServer/Win32/libEasyRTSPServer.lib
Binary file not shown.
Binary file added Src/EasyRTSPServer/Win64/libEasyRTSPServer.dll
Binary file not shown.
Binary file added Src/EasyRTSPServer/Win64/libEasyRTSPServer.lib
Binary file not shown.
Loading

0 comments on commit afd8817

Please sign in to comment.