zhanghua
2024-09-28 7873c6f56380d28e1ae6958f77a84081797c817f
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.dahua.netsdk.lib.streamParserAndPackage;
 
import com.dahua.netsdk.lib.LibraryLoad;
import com.dahua.netsdk.lib.SDKCallback;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
 
 
public interface StreamPackage  extends Library{
    StreamPackage INSTANCE = Native.load(LibraryLoad.getLoadLibrary("StreamPackage"), StreamPackage.class);
    
    // 接口返回值
    public static interface  SG_ERR_TYPE
    {
        public static final int SG_ERR_NOERR = 0;                                    /*成功*/
        public static final int SG_ERR_HANDLE_EMPTY = 1;                            /*无效句柄*/
        public static final int SG_ERR_INIT_FAIL = 2;                                /*初始化失败*/
        public static final int SG_ERR_PARAM_ERR = 3;                                /*参数错误*/
    }
    
    // 码流封装类型
    public static interface SG_STREAM_TYPE
    {
        public static final int SG_STREAM_TYPE_DAV_STREAM = 19;                        /*封装格式 DAV*/
    }
    
    // 帧类型
    public static interface SG_FRAME_TYPE
    {
        public static final int SG_FRAME_TYPE_VIDEO = 1;                            /*视频帧*/
        public static final int SG_FRAME_TYPE_AUDIO = 2;                            /*音频帧*/
        public static final int SG_FRAME_TYPE_EXT = 3;                                /*DH扩展帧*/
    }
    
    // 视频帧子类型
    public static interface SG_FRAME_SUB_TYPE
    {
        public static final int SG_FRAME_SUB_TYPE_I = 0;                            /* I帧 */
        public static final int SG_FRAME_SUB_TYPE_P = 1;                            /* P帧 */
        public static final int SG_FRAME_SUB_TYPE_B = 2;                            /* B帧 */
        public static final int SG_FRAME_SUB_TYPE_JPEG_FRAME = 8;                   /*JPEG 帧*/                
    }
    
    // 编码类型
    public static interface SG_ENCODE_TYPE
    {
        public static final int SG_ENCODE_VIDEO_UNKNOWN = 0;                        /*视频编码格式不可知*/
        public static final int SG_ENCODE_VIDEO_MPEG4 = 1;                            /*视频编码格式是MPEG4*/
        public static final int SG_ENCODE_VIDEO_JPEG = 3;                            /*视频编码格式是标准JPEG*/
        public static final int SG_ENCODE_VIDEO_H264 = 4;                            /*视频编码格式是DH码流H264*/
 
        public static final int    SG_ENCODE_AUDIO_PCM    = 7;                            /*音频编码格式是PCM8*/
        public static final int    SG_ENCODE_AUDIO_G711A = 14;                            /*音频编码格式是G711A*/
        public static final int    SG_ENCODE_AUDIO_PCM16 = 16;                            /*音频编码格式是PCM16*/
        public static final int SG_ENCODE_AUDIO_G711U = 22;                             /*音频编码格式是G711U*/
        public static final int SG_ENCODE_AUDIO_AAC = 26;                            /*音频编码格式是AAC*/
        public static final int SG_ENCODE_AUDIO_MP2    = 31;                            /*音频编码格式是MP2*/
    }
    
    // 解交错标志
    public static interface SG_DEINTERLACE_TYPE
    {
        public static final int SG_DEINTERLACE_NONE = 2;                            /*无解交错*/ 
    }
    
    // 加密类型
    public static interface SG_ENCRYPT_TYPE
    {
        public static final int SG_ENCRYPT = 0;
    }
    
    // 文件头信息
    class SGHeaderInfo extends Structure
    {
        public int struct_size;
    }
    
    // 文件尾信息
    class SGTailerInfo extends Structure
    {
        public int struct_size;
    }
    
    // 帧数据信息
    @Structure.FieldOrder(value={"struct_size","frame_pointer","frame_size","frame_type","frame_sub_type",
                                "frame_encode","frame_time","frame_data","width","heigth",
                                "frame_rate","deinter_lace","sample_rate","bit_per_sample","channels",
                                "bit_rate","rtp_channel","reserved","frame_seq","reserved2"})
    class SGFrameInfo extends Structure
    {
        public int struct_size;                                                        /*结构体大小*/
        public Pointer frame_pointer;                                                /*帧数据指针*/
        public int    frame_size;                                                        /*帧数据长度*/
        public int frame_type;                                                        /*帧类型  SG_FRAME_TYPE*/
        public int frame_sub_type;                                                    /*帧子类型 SG_FRAME_SUB_TYPE*/
        public int frame_encode;                                                    /*编码类型 SG_ENCODE_TYPE*/
        public int frame_time;                                                        /*帧时间戳*/
        public int frame_data;                                                        /*日期时间,UTC时间*/
        
        public int width;                                                            /*宽*/
        public int heigth;                                                            /*高*/
        public int frame_rate;                                                        /*帧率*/
        public int deinter_lace;                                                    /*解交错信息 SG_DEINTERLACE_TYPE*/
        
        public int sample_rate;                                                        /*音频采样率*/                    
        public int bit_per_sample;                                                    /*音频采样位数*/
        public int channels;                                                        /*通道*/
        public int bit_rate;                                                        /*音频比特率*/
        
        public byte rtp_channel;                                                    /*通道号*/
        public byte[] reserved = new byte[7];                                        /*保留字段1*/
        public int frame_seq;                                                        /*帧序号*/
        public byte[] reserved2 = new byte[188];                                    /*保留字段2*/
        
        public SGFrameInfo()
        {
            super(ALIGN_NONE);
        }
    }
    
    // 数据输出信息
    @Structure.FieldOrder(value={"struct_size","data_pointer","data_size","offset_type",
                        "offset_pos"})
    class SGOutputData extends Structure
    {
        public int       struct_size;                                                        /*结构体大小*/
        public Pointer data_pointer;                                                    /*数据指针*/
        public int      data_size;                                                        /*数据长度*/
        public int       offset_type;                                                        /*数据偏移类型*/
        public int       offset_pos;                                                        /*数据偏移位置*/
        public SGOutputData()
        {
            super(ALIGN_NONE);
        }
    }
    
    // 内存分配函数
    public interface SGMalloc_t extends SDKCallback
    {
        public void invoke(int memory_size);
    }
    
    // 内存释放函数
    public interface SGFree_t extends SDKCallback
    {
        public void invoke(Pointer memory_pointer, 
                        int memory_size);
    }
    
    // 数据输出回调函数
    public interface SGDataCB_t extends SDKCallback
    {
        public void invoke(Pointer data, Pointer user);
    }
    
    // 创建流封装器信息
    @Structure.FieldOrder(value={"struct_size","user","sg_malloc","sg_free","sg_datacb"})
    class SGCreateParam extends Structure
    {
        public int struct_size;                                                            /*结构体大小*/
        public Pointer user;                                                                /*用户数据*/
        public SGMalloc_t sg_malloc;                                                        /*用户自定义内存分配函数指针*/
        public SGFree_t   sg_free;                                                            /*用户自定义内存释放函数指针*/
        public SGDataCB_t sg_datacb;                                                        /*用户自定义数据输出回调函数*/
        
        public SGCreateParam()
        {
            super(ALIGN_NONE);
        }
    }
    /********************************************************************
    *    Funcname:            SG_CreateHandle
    *    Purpose:            创建流封装器
    *   InputParam:         nType : 码流封装类型  SG_STREAM_TYPE
    *                                pCreateParam : 创建流封装器信息
    *   Return:                void* : 返回打包句柄, 失败返回NULL
    *   Created:            2020.12.08 
    *********************************************************************/
    Pointer SG_CreateHandle(int nType, Pointer pCreateParam);
        
    /********************************************************************
    *    Funcname:             SG_DestroyHandle
    *    Purpose:            销毁流封装器
    *   InputParam:         handle : 流封装器句柄
    *   Return:                成功返回 SG_ERR_NOERR,失败返回错误码
    *   Created:            2020.12.08  
    *********************************************************************/
    int    SG_DestroyHandle(Pointer handle);
        
    /********************************************************************
    *    Funcname:             SG_CreateHeader
    *    Purpose:            创建文件头
    *   InputParam:         handle : 流封装器句柄
    *                                pHeader : 文件头信息
    *   Return:                成功返回 SG_ERR_NOERR,失败返回错误码
    *   Created:            2020.12.08
    *********************************************************************/
    int SG_CreateHeader(Pointer handle, Pointer pHeader);
        
    /********************************************************************
    *    Funcname:             StreamPacket_InputData
    *    Purpose:            传入媒体数据
    *   InputParam:         handle : 打包句柄
    *                                frame_info : 需要打包的媒体信息
    *   Return:                成功返回 SG_ERR_NOERR,失败返回错误码
    *   Created:            2013.12.08 
    *********************************************************************/
    int SG_InputFrame(Pointer handle, Pointer pFrame);
        
    /********************************************************************
    *    Funcname:             StreamPacket_CreateTailer
    *    Purpose:            删除打包句柄
    *   InputParam:         handle : 打包句柄
    *   Return:                成功返回 SG_ERR_NOERR,失败返回错误码
    *   Created:            2020.12.08 
    *********************************************************************/
    int SG_CreateTailer(Pointer handle, Pointer pTailer);
        
    /********************************************************************
    *    Funcname:             SG_SetEncryptType
    *    Purpose:            设置加密类型
    *   InputParam:         handle : 打包句柄
                            type: 加密类型,见SG_ENCRYPT_TYPE
                            key: 秘钥指针
                            keylen: 秘钥长度
    *   Return:             成功返回 SG_ERR_NOERR,失败返回错误码
    *   Created:            2020.12.08
    *********************************************************************/
    int SG_SetEncryptType(Pointer handle, int type, byte[] key, int keyLen);
}