-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathrtmp.h
185 lines (149 loc) · 4.83 KB
/
rtmp.h
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
/*
librtmp
Copyright (C) 2009 ITOYANAGI Kazunori
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ITOYANAGI Kazunori
*/
#ifndef _rtmp_H_
#define _rtmp_H_
#ifdef MACOS_OPENTRANSPORT
#include <OpenTransport.h>
#include <OpenTptInternet.h>
#else
#if defined(__WIN32__) || defined(WIN32)
#define __USE_W32_SOCKETS
#include <windows.h>
#ifdef __CYGWIN__
#include <netinet/in.h>
#endif
#else /* UNIX */
#ifdef __OS2__
#include <types.h>
#include <sys/ioctl.h>
#endif
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#ifndef __BEOS__
#include <arpa/inet.h>
#endif
#ifdef linux /* FIXME: what other platforms have this? */
#include <netinet/tcp.h>
#endif
#include <netdb.h>
#include <sys/socket.h>
#endif /* WIN32 */
#endif /* Open Transport */
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#define RTMP_HANDSHAKE_SIZE 1536
#define RTMP_BUFFER_SIZE 4096
typedef struct rtmp_server_client_t rtmp_server_client_t;
struct rtmp_server_client_t
{
unsigned int conn_sock;
struct sockaddr_in conn_sockaddr;
unsigned char received_buffer[RTMP_BUFFER_SIZE];
size_t received_size;
unsigned char will_send_buffer[RTMP_BUFFER_SIZE];
size_t will_send_size;
size_t amf_chunk_size;
void *data;
void (*process_message)(rtmp_server_client_t *rsc);
unsigned char handshake[RTMP_HANDSHAKE_SIZE];
rtmp_server_client_t *prev;
rtmp_server_client_t *next;
};
typedef struct rtmp_server_t rtmp_server_t;
struct rtmp_server_t
{
int conn_sock;
struct sockaddr_in conn_sockaddr;
int stand_by_socket;
rtmp_server_client_t *client_working;
rtmp_server_client_t *client_pool;
};
extern rtmp_server_t *rtmp_server_create(unsigned short port_number);
extern void rtmp_server_process_message(rtmp_server_t *rs);
extern void rtmp_server_free(rtmp_server_t *rs);
#define DEFAULT_AMF_CHUNK_SIZE 128
typedef enum rtmp_result rtmp_result_t;
enum rtmp_result
{
RTMP_SUCCESS,
RTMP_ERROR_UNKNOWN,
RTMP_ERROR_BUFFER_OVERFLOW,
RTMP_ERROR_BROKEN_PACKET,
RTMP_ERROR_DIVIDED_PACKET,
RTMP_ERROR_MEMORY_ALLOCATION,
RTMP_ERROR_LACKED_MEMORY,
RTMP_ERROR_DISCONNECTED,
};
typedef struct rtmp_event_t rtmp_event_t;
struct rtmp_event_t
{
char *code;
char *level;
rtmp_event_t *next;
};
typedef struct rtmp_client_t rtmp_client_t;
struct rtmp_client_t
{
int conn_sock;
unsigned char received_buffer[RTMP_BUFFER_SIZE];
size_t received_size;
unsigned char will_send_buffer[RTMP_BUFFER_SIZE];
size_t will_send_size;
void (*process_message)(rtmp_client_t *client);
void *data;
char *url;
char *protocol;
char *host;
int port_number;
char *path;
size_t amf_chunk_size;
unsigned char handshake[RTMP_HANDSHAKE_SIZE];
long message_number;
rtmp_event_t *events;
};
rtmp_client_t *rtmp_client_create(const char *url);
extern void rtmp_client_free(rtmp_client_t *client);
extern rtmp_event_t *rtmp_client_get_event(rtmp_client_t *client);
extern void rtmp_client_delete_event(rtmp_client_t *client);
extern void rtmp_client_connect(
rtmp_client_t *client
/* FIXME: take URL */);
extern void rtmp_client_create_stream(rtmp_client_t *client);
extern void rtmp_client_play(rtmp_client_t *client, const char *file_name);
extern void rtmp_server_client_send_server_bandwidth(rtmp_server_client_t *rsc);
extern void rtmp_server_client_send_client_bandwidth(rtmp_server_client_t *rsc);
extern void rtmp_server_client_send_ping(rtmp_server_client_t *rsc);
extern void rtmp_server_client_send_chunk_size(rtmp_server_client_t *rsc);
extern void rtmp_server_client_send_connect_result(
rtmp_server_client_t *rsc, double number);
extern void rtmp_server_client_send_create_stream_result(
rtmp_server_client_t *rsc, double number);
extern void rtmp_server_client_send_play_result_error(
rtmp_server_client_t *rsc, double number);
extern void rtmp_server_client_send_play_result_success(
rtmp_server_client_t *rsc, double number);
extern void rtmp_client_process_message(rtmp_client_t *client);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif