提交 | 用户 | 时间
|
ce910c
|
1 |
package com.netsdk.demo.module; |
H |
2 |
|
|
3 |
import com.netsdk.lib.NetSDKLib; |
|
4 |
import com.netsdk.lib.ToolKits; |
|
5 |
|
|
6 |
import java.util.*; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author : 47040 |
|
10 |
* @since : Created in 2020/7/25 17:59 |
|
11 |
*/ |
|
12 |
public class VideoStateSummaryModule { |
|
13 |
|
|
14 |
public static Map<Integer, NetSDKLib.LLong> getM_hAttachMap() { |
|
15 |
return m_hAttachMap; |
|
16 |
} |
|
17 |
|
|
18 |
// handle map |
|
19 |
private static Map<Integer, NetSDKLib.LLong> m_hAttachMap = new HashMap<Integer, NetSDKLib.LLong>(); |
|
20 |
|
|
21 |
// Attach 订阅 人数统计事件 |
|
22 |
public static boolean attachVideoStatSummary(int channel, NetSDKLib.fVideoStatSumCallBack fVideoStatSumCallBack) { |
|
23 |
|
|
24 |
if (!m_hAttachMap.containsKey(channel)) { |
|
25 |
|
|
26 |
NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM inParam = new NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM(); |
|
27 |
inParam.nChannel = channel; |
|
28 |
inParam.cbVideoStatSum = fVideoStatSumCallBack; |
|
29 |
|
|
30 |
NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM outParam = new NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM(); |
|
31 |
NetSDKLib.LLong m_hAttachHandle = LoginModule.netsdk.CLIENT_AttachVideoStatSummary(LoginModule.m_hLoginHandle, inParam, outParam, 5000); |
|
32 |
if (m_hAttachHandle.longValue() == 0) { |
|
33 |
System.err.printf("Attach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); |
|
34 |
return false; |
|
35 |
} |
|
36 |
m_hAttachMap.put(channel, m_hAttachHandle); |
|
37 |
System.out.printf("Attach Succeed at Channel %d ! AttachHandle: %d. Wait Device Notify Information\n", channel, m_hAttachHandle.longValue()); |
|
38 |
return true; |
|
39 |
} else { // 非 0 说明正在订阅,先退订,再返回订阅失败 |
|
40 |
System.err.print("Attach Handle is not Zero, Please Detach First.\n"); |
|
41 |
return false; |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
// Check if Channel is Attached 是否订阅通道 |
|
46 |
public static boolean channelAttached(int channel) { |
|
47 |
|
|
48 |
return m_hAttachMap.containsKey(channel); |
|
49 |
} |
|
50 |
|
|
51 |
// Detach 退订 人数统计事件 |
|
52 |
public static boolean detachVideoStatSummary(int channel) { |
|
53 |
if (m_hAttachMap.containsKey(channel)) { |
|
54 |
|
|
55 |
NetSDKLib.LLong m_hAttachHandle = m_hAttachMap.get(channel); |
|
56 |
|
|
57 |
if (m_hAttachHandle.longValue() != 0) { |
|
58 |
if (!LoginModule.netsdk.CLIENT_DetachVideoStatSummary(m_hAttachHandle)) { |
|
59 |
System.err.printf("Detach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); |
|
60 |
return false; |
|
61 |
} |
|
62 |
System.out.println("Channel " + channel + ". Handle: " + m_hAttachHandle.longValue() + ". Detach Succeed!"); |
|
63 |
m_hAttachHandle.setValue(0); |
|
64 |
m_hAttachMap.remove(channel); |
|
65 |
return true; |
|
66 |
} else { |
|
67 |
System.err.print("Attach Handle is Zero, no Need for Detach.\n"); |
|
68 |
return false; |
|
69 |
} |
|
70 |
} else { |
|
71 |
System.err.print("Attach Handle not found.\n"); |
|
72 |
return false; |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
// Detach All 退订 人数统计事件 |
|
77 |
public static void detachAllVideoStatSummary() { |
|
78 |
Set<Integer> keySet = m_hAttachMap.keySet(); |
|
79 |
|
|
80 |
for (Iterator<Integer> iter = keySet.iterator(); iter.hasNext(); ) { |
|
81 |
int channel = iter.next(); |
|
82 |
|
|
83 |
NetSDKLib.LLong m_hAttachHandle = m_hAttachMap.get(channel); |
|
84 |
if (!LoginModule.netsdk.CLIENT_DetachVideoStatSummary(m_hAttachHandle)) { |
|
85 |
System.err.printf("Detach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); |
|
86 |
} |
|
87 |
System.out.println("Channel " + channel + ". Handle: " + m_hAttachHandle.longValue() + ". Detach Succeed!"); |
|
88 |
iter.remove(); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
// reAttach 重订 人数统计事件 |
|
93 |
public static void reAttachAllVideoStatSummary(NetSDKLib.fVideoStatSumCallBack fVideoStatSumCallBack) { |
|
94 |
Set<Integer> keySet = m_hAttachMap.keySet(); |
|
95 |
for (int channel : keySet) { |
|
96 |
NetSDKLib.LLong m_hAttachHandle = m_hAttachMap.get(channel); |
|
97 |
if (!LoginModule.netsdk.CLIENT_DetachVideoStatSummary(m_hAttachHandle)) { |
|
98 |
System.err.printf("Detach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); |
|
99 |
} |
|
100 |
System.out.println("Channel " + channel + ". Handle: " + m_hAttachHandle.longValue() + ". Detach Succeed!"); |
|
101 |
|
|
102 |
NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM inParam = new NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM(); |
|
103 |
inParam.nChannel = channel; |
|
104 |
inParam.cbVideoStatSum = fVideoStatSumCallBack; |
|
105 |
|
|
106 |
NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM outParam = new NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM(); |
|
107 |
m_hAttachHandle = LoginModule.netsdk.CLIENT_AttachVideoStatSummary(LoginModule.m_hLoginHandle, inParam, outParam, 5000); |
|
108 |
if (m_hAttachHandle.longValue() == 0) { |
|
109 |
System.err.printf("Attach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); |
|
110 |
} |
|
111 |
m_hAttachMap.put(channel, m_hAttachHandle); |
|
112 |
System.out.printf("Attach Succeed at Channel %d ! AttachHandle: %d. Wait Device Notify Information\n", channel, m_hAttachHandle.longValue()); |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
// clear OSD info |
|
117 |
public static boolean clearVideoStateSummary(int channel) { |
|
118 |
NetSDKLib.NET_CTRL_CLEAR_SECTION_STAT_INFO info = new NetSDKLib.NET_CTRL_CLEAR_SECTION_STAT_INFO(); |
|
119 |
info.nChannel = channel; |
|
120 |
info.write(); |
|
121 |
if (!LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_CLEAR_SECTION_STAT, info.getPointer(), 5000)) { |
|
122 |
System.err.printf("Clear Video State Summary Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); |
|
123 |
return false; |
|
124 |
} |
|
125 |
System.out.println("Clear Video State Summary Succeed!"); |
|
126 |
return true; |
|
127 |
} |
|
128 |
} |