-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.cpp
157 lines (143 loc) · 3.6 KB
/
demo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "demo.h"
CKdmRtspHandler *g_pKdmRtspHandler = NULL;
int Init()
{
int nRet = OspInit(true, 60000);
if(nRet != true)
{
printf("osp init error\n");
return -1;
}
KdmPosaStartup();
g_pKdmRtspHandler = new CKdmRtspHandler;
if(NULL == g_pKdmRtspHandler)
{
printf("init error, g_pKdmRtspHandler = NULL\n");
return -1;
}
return 0;
}
u32 RtspMsgCallBack (void* dwContext, u32 dwRetCode, u32 dwOperateType, string& strResponse)
{
printf("rtsp msg cb here ...\n");
return 0;
}
u32 RtpDataCallBack (void* dwContext, u32 dwChnID, u8* pRtpData, u32 dwLenRtp)
{
printf("rtsp data cb here ... \n");
return 0;
}
void Uninit()
{
KdmPosaCleanup();
delete g_pKdmRtspHandler;
}
int main()
{
int nRet = Init();
if(nRet != 0)
{
printf("Init error\n");
return -1;
}
TKdmRtspUrl tKdmRtspUrl;
memset(&tKdmRtspUrl, 0, sizeof(tKdmRtspUrl));
tKdmRtspUrl.strRtspUrl = "rtsp://admin:[email protected]:554";
tKdmRtspUrl.bStreamUsingTCP = false;
tKdmRtspUrl.dwRtpPort = 9758;
tKdmRtspUrl.strUserName = "admin";
tKdmRtspUrl.strPassword = "admin123";
tKdmRtspUrl.dwContext = (void*)malloc(sizeof(char) * 1024);
if(tKdmRtspUrl.dwContext == NULL)
{
printf("malloc error\n");
Uninit();
return -1;
}
tKdmRtspUrl.bForceMulticast = false;
tKdmRtspUrl.funRtspMessage = RtspMsgCallBack;
tKdmRtspUrl.funRtpData = RtpDataCallBack;
tKdmRtspUrl.m_tKdmRtspConnectModeType = KDMRTSP_CONNECT_MODE_TYPE_SECOND;
//设置rtsp会话需要的参数
nRet = g_pKdmRtspHandler->SetRtspUrl(&tKdmRtspUrl);
if(nRet != TRUE)
{
printf("set url fail, line:%d, nRet = %d\n", __LINE__, nRet);
free(tKdmRtspUrl.dwContext);
tKdmRtspUrl.dwContext = NULL;
Uninit();
return -1;
}
//设置其他rtsp基本会话参数
TKdmRtspOtherParam tRtspOtherParam;
memset(&tRtspOtherParam, 0,sizeof(tRtspOtherParam));
tRtspOtherParam.m_bUseStopPlay = false;
nRet = g_pKdmRtspHandler->SetRtspOtherParam(&tRtspOtherParam);
if(nRet != true)
{
printf("rtst set other param error, line=%d, nRet = %d\n", __LINE__, nRet);
free(tKdmRtspUrl.dwContext);
tKdmRtspUrl.dwContext = NULL;
Uninit();
return -1;
}
nRet = g_pKdmRtspHandler->OpenConnect();
if(nRet != true)
{
printf("open connect error, line=%d, nRet = %d\n", __LINE__, nRet);
Uninit();
return -1;
}
//获取能力集
nRet = g_pKdmRtspHandler->SendOptionsRequest();
if(nRet != true)
{
printf("send option request error, line=%d, nRet = %d\n", __LINE__, nRet);
Uninit();
return -1;
}
//发送描述信息
nRet = g_pKdmRtspHandler->SendDescribeRequest();
if(nRet != true)
{
printf("send describe request error, line=%d, nRet = %d\n", __LINE__, nRet);
Uninit();
return -1;
}
nRet = g_pKdmRtspHandler->SendDescribeRequest();
if(nRet != true)
{
printf("send describe request error, line=%d, nRet = %d\n", __LINE__, nRet);
Uninit();
return -1;
}
//TKdmMediaSubSession tMediaSubSessInfo;
//memset(&tMediaSubSessInfo, 0, sizeof(tMediaSubSessInfo));
//nRet = g_pKdmRtspHandler->GetMediaSubSessionInfo(0, tMediaSubSessInfo);
//if(nRet != true)
//{
// printf("get submediasess info error, line=%d, nRet = %d\n", __LINE__, nRet);
// Uninit();
// return -1;
//}
bool streamUsingTcp = true;
bool streamOutgoing = false;
bool forceMulticastOnUnspecified = false;
int nIdx = 0xFF;
nRet = g_pKdmRtspHandler->SendSetupRequest(streamUsingTcp, streamOutgoing, forceMulticastOnUnspecified, nIdx);
if(nRet != true)
{
printf("send setup request error, line=%d, nRet = %d\n", __LINE__, nRet);
Uninit();
return -1;
}
nRet = g_pKdmRtspHandler->SendPlayRequest();
if(nRet != 0)
{
printf("start play fail, line:%d\n", __LINE__);
Uninit();
return -1;
}
delete g_pKdmRtspHandler;
return 0;
}