Skip to content

Commit 748f8f8

Browse files
author
zhenhe206793
committed
All files.
1 parent 83a7a11 commit 748f8f8

File tree

7 files changed

+38400
-0
lines changed

7 files changed

+38400
-0
lines changed

build/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
2+
3+
PROJECT(raw_h264_publisher)
4+
5+
include(CheckCXXCompilerFlag)
6+
7+
SET(CMAKE_BUILD_TYPE Release)
8+
SET(EXECUTABLE_OUTPUT_PATH ../bin)
9+
10+
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
11+
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
12+
13+
INCLUDE_DIRECTORIES(../include)
14+
INCLUDE_DIRECTORIES(../src/trunk/out)
15+
16+
LINK_DIRECTORIES(../lib/linux)
17+
18+
AUX_SOURCE_DIRECTORY(../src/trunk/out SRC_DIR)
19+
AUX_SOURCE_DIRECTORY(../src/trunk/research/librtmp SRC_DIR)
20+
21+
ADD_EXECUTABLE(raw_h264_publisher ${SRC_DIR})
22+
TARGET_LINK_LIBRARIES(raw_h264_publisher rawquic)
23+
24+

include/raw_quic_api.h

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @file raw_quic_api.h
3+
* @brief RawQuic api声明文件.
4+
* @author sonysuqin
5+
* @copyright sonysuqin
6+
* @version 1.0.1
7+
*/
8+
9+
#ifndef NET_QUIC_RAW_QUIC_RAW_QUIC_API_H_
10+
#define NET_QUIC_RAW_QUIC_RAW_QUIC_API_H_
11+
12+
#include "raw_quic_define.h"
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* @brief 创建一个RawQuic句柄.
20+
* @param callback 异步回调.
21+
* @param opaque 上层传递的参数,将在回调中作为参数回传.
22+
* @param verify 是否校验证书.
23+
* @return RawQuic句柄.
24+
*/
25+
RAW_QUIC_API RawQuicHandle RAW_QUIC_CALL RawQuicOpen(RawQuicCallbacks callback,
26+
void* opaque,
27+
bool verify);
28+
29+
/**
30+
* @brief 关闭一个RawQuic句柄.
31+
* @param handle RawQuic句柄.
32+
* @return 错误码.
33+
*/
34+
RAW_QUIC_API int32_t RAW_QUIC_CALL RawQuicClose(RawQuicHandle handle);
35+
36+
/**
37+
* @brief 使用RawQuic句柄连接一个服务.
38+
* @param handle RawQuic句柄.
39+
* @param host 服务端域名,注意QUIC必须加密,所以必须有域名及证书.
40+
* @param port 服务端端口.
41+
* @param port 服务端路径.
42+
* @param timeout 超时时间,ms.
43+
* @note timeout非0时,为同步方法,会阻塞直到连接成功、失败、或者超时,
44+
* 当timeout为0时,为异步方法,connect_callback将被回调.
45+
* @return 错误码.
46+
*/
47+
RAW_QUIC_API int32_t RAW_QUIC_CALL RawQuicConnect(RawQuicHandle handle,
48+
const char* host,
49+
uint16_t port,
50+
const char* path,
51+
int32_t timeout);
52+
53+
/**
54+
* @brief 使用RawQuic句柄发送一段数据.
55+
* @param handle RawQuic句柄.
56+
* @param data 数据缓存地址.
57+
* @param size 数据长度.
58+
* @note 只是放到发送缓冲区.
59+
* @return 发送的字节数或者错误码.
60+
*/
61+
RAW_QUIC_API int32_t RAW_QUIC_CALL RawQuicSend(RawQuicHandle handle,
62+
uint8_t* data,
63+
uint32_t size);
64+
65+
/**
66+
* @brief 使用RawQuic句柄接收一段数据.
67+
* @param handle RawQuic句柄.
68+
* @param data 数据缓存地址.
69+
* @param size 数据缓存长度.
70+
* @param timeout 超时时间,ms.
71+
* @note timeout非0时,将等待直到有数据、失败、或者超时,
72+
* timeout为0时,只是尝试检查接收缓冲区是否有数据,
73+
* 有则返回数据,否则返回EAGAIN. can_read_callback
74+
* 回调将会通知有数据可读(边缘触发).
75+
* @return 接收的字节数或者错误码.
76+
*/
77+
RAW_QUIC_API int32_t RAW_QUIC_CALL RawQuicRecv(RawQuicHandle handle,
78+
uint8_t* data,
79+
uint32_t size,
80+
int32_t timeout);
81+
82+
#ifdef __cplusplus
83+
}
84+
#endif
85+
86+
#endif // NET_QUIC_RAW_QUIC_RAW_QUIC_API_H_

include/raw_quic_define.h

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @file raw_quic_define.h
3+
* @brief RawQuic api数据结构声明文件.
4+
* @author sonysuqin
5+
* @copyright sonysuqin
6+
* @version 1.0.1
7+
*/
8+
9+
#ifndef NET_QUIC_RAW_QUIC_RAW_QUIC_DEFINE_H_
10+
#define NET_QUIC_RAW_QUIC_RAW_QUIC_DEFINE_H_
11+
12+
#ifdef WIN32
13+
#ifdef RAW_QUIC_SHARED_LIBRARY
14+
#ifdef RAW_QUIC_EXPORTS
15+
#define RAW_QUIC_API __declspec(dllexport)
16+
#else
17+
#define RAW_QUIC_API __declspec(dllimport)
18+
#endif
19+
#else
20+
#define RAW_QUIC_API
21+
#endif
22+
#define RAW_QUIC_CALL __cdecl
23+
#define RAW_QUIC_CALLBACK __cdecl
24+
#else
25+
#ifdef RAW_QUIC_EXPORTS
26+
#define RAW_QUIC_API __attribute__((visibility("default")))
27+
#else
28+
#define RAW_QUIC_API
29+
#endif
30+
#define RAW_QUIC_CALL
31+
#define RAW_QUIC_CALLBACK
32+
#endif
33+
34+
/// 需要支持C99.
35+
#include <stdint.h>
36+
#include <stdbool.h>
37+
38+
/// 错误码.
39+
typedef enum RawQuicErrorCode {
40+
RAW_QUIC_ERROR_CODE_SUCCESS = 0, //!< 成功.
41+
RAW_QUIC_ERROR_CODE_INVALID_PARAM = -1, //!< 非法参数.
42+
RAW_QUIC_ERROR_CODE_INVALID_STATE = -2, //!< 非法状态.
43+
RAW_QUIC_ERROR_CODE_NULL_POINTER = -3, //!< 空指针.
44+
RAW_QUIC_ERROR_CODE_SOCKET_ERROR = -4, //!< Socket错误.
45+
RAW_QUIC_ERROR_CODE_RESOLVE_FAILED = -5, //!< 解析失败.
46+
RAW_QUIC_ERROR_CODE_BUFFER_OVERFLOWED = -6, //!< 缓冲区溢出.
47+
RAW_QUIC_ERROR_CODE_STREAM_FIN = -7, //!< 流被结束.
48+
RAW_QUIC_ERROR_CODE_STREAM_RESET = -8, //!< 流被重置.
49+
RAW_QUIC_ERROR_CODE_NET_ERROR = -9, //!< 网络错误.
50+
RAW_QUIC_ERROR_CODE_QUIC_ERROR = -10, //!< QUIC错误.
51+
RAW_QUIC_ERROR_CODE_TIMEOUT = -11, //!< 超时.
52+
RAW_QUIC_ERROR_CODE_UNKNOWN = -12, //!< 未知错误.
53+
RAW_QUIC_ERROR_CODE_INVALID_HANDLE = -13, //!< 非法句柄.
54+
RAW_QUIC_ERROR_CODE_EAGAIN = -14, //!< EAGAIN.
55+
RAW_QUIC_ERROR_CODE_COUNT
56+
} RawQuicErrorCode;
57+
58+
/// 错误结构.
59+
typedef struct RawQuicError {
60+
RawQuicErrorCode error; //!< RawQuicErrorCode错误码.
61+
int32_t net_error; //!< 网络错误码.
62+
int32_t quic_error; //!< QUIC错误码.
63+
} RawQuicError;
64+
65+
/// RawQuic句柄类型.
66+
typedef void* RawQuicHandle;
67+
68+
/**
69+
* @brief 连接结果回调,只有在timeout为0才回调.
70+
* @param handle RawQuic句柄.
71+
* @param error 错误结构.
72+
* @param opaque 透传参数.
73+
*/
74+
typedef void(RAW_QUIC_CALLBACK* ConnectCallback)(RawQuicHandle handle,
75+
RawQuicError* error,
76+
void* opaque);
77+
78+
/**
79+
* @brief 错误回调,发生错误时回调.
80+
* @param handle RawQuic句柄.
81+
* @param error 错误结构.
82+
* @param opaque 透传参数.
83+
*/
84+
typedef void(RAW_QUIC_CALLBACK* ErrorCallback)(RawQuicHandle handle,
85+
RawQuicError* error,
86+
void* opaque);
87+
88+
/**
89+
* @brief 可读回调.
90+
* @param handle RawQuic句柄.
91+
* @param size 可读数据长度.
92+
* @param opaque 透传参数.
93+
*/
94+
typedef void(RAW_QUIC_CALLBACK* CanReadCallback)(RawQuicHandle handle,
95+
uint32_t size,
96+
void* opaque);
97+
98+
/// RawQuic回调结构.
99+
typedef struct RawQuicCallbacks {
100+
ConnectCallback connect_callback; //!< 连接结果回调.
101+
ErrorCallback error_callback; //!< 错误回调.
102+
CanReadCallback can_read_callback; //!< 可读回调.
103+
} RawQuicCallbacks;
104+
105+
#endif // NET_QUIC_RAW_QUIC_RAW_QUIC_DEFINE_H_

lib/linux/librawquic.so

5.02 MB
Binary file not shown.

0 commit comments

Comments
 (0)