winlin

Merge branch 'srs.master'

@@ -28,24 +28,45 @@ gcc srs_h264_raw_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_h @@ -28,24 +28,45 @@ gcc srs_h264_raw_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_h
28 #include <stdlib.h> 28 #include <stdlib.h>
29 #include <unistd.h> 29 #include <unistd.h>
30 30
  31 +// for open h264 raw file.
  32 +#include <sys/types.h>
  33 +#include <sys/stat.h>
  34 +#include <fcntl.h>
  35 +
31 #include "../../objs/include/srs_librtmp.h" 36 #include "../../objs/include/srs_librtmp.h"
32 37
33 #define srs_trace(msg, ...) printf(msg, ##__VA_ARGS__);printf("\n") 38 #define srs_trace(msg, ...) printf(msg, ##__VA_ARGS__);printf("\n")
34 39
35 int main(int argc, char** argv) 40 int main(int argc, char** argv)
36 { 41 {
37 - srs_rtmp_t rtmp;  
38 -  
39 - // packet data  
40 - int type, size;  
41 - u_int32_t timestamp = 0;  
42 - char* data;  
43 -  
44 srs_trace("publish raw h.264 as rtmp stream to server like FMLE/FFMPEG/Encoder"); 42 srs_trace("publish raw h.264 as rtmp stream to server like FMLE/FFMPEG/Encoder");
45 srs_trace("srs(simple-rtmp-server) client librtmp library."); 43 srs_trace("srs(simple-rtmp-server) client librtmp library.");
46 - srs_trace("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); 44 + srs_trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
  45 +
  46 + if (argc <= 2) {
  47 + srs_trace("Usage: %s <h264_raw_file> <rtmp_publish_url>", argv[0]);
  48 + srs_trace(" h264_raw_file: the h264 raw steam file.");
  49 + srs_trace(" rtmp_publish_url: the rtmp publish url.");
  50 + srs_trace("For example:");
  51 + srs_trace(" %s ./720p.h264.raw rtmp://127.0.0.1:1935/live/livestream", argv[0]);
  52 + srs_trace("Where the file: http://winlinvip.github.io/srs.release/3rdparty/720p.h264.raw");
  53 + srs_trace("See: https://github.com/winlinvip/simple-rtmp-server/issues/66");
  54 + exit(-1);
  55 + }
  56 +
  57 + const char* raw_file = argv[1];
  58 + const char* rtmp_url = argv[2];
  59 + srs_trace("raw_file=%s, rtmp_url=%s", raw_file, rtmp_url);
  60 +
  61 + // open file
  62 + int raw_fd = open(raw_file, O_RDONLY);
  63 + if (raw_fd < 0) {
  64 + srs_trace("open h264 raw file %s failed.", raw_fd);
  65 + goto rtmp_destroy;
  66 + }
47 67
48 - rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream"); 68 + // connect rtmp context
  69 + srs_rtmp_t rtmp = srs_rtmp_create(rtmp_url);
49 70
50 if (srs_simple_handshake(rtmp) != 0) { 71 if (srs_simple_handshake(rtmp) != 0) {
51 srs_trace("simple handshake failed."); 72 srs_trace("simple handshake failed.");
@@ -65,22 +86,42 @@ int main(int argc, char** argv) @@ -65,22 +86,42 @@ int main(int argc, char** argv)
65 } 86 }
66 srs_trace("publish stream success"); 87 srs_trace("publish stream success");
67 88
  89 + u_int32_t dts = 0;
  90 + u_int32_t pts = 0;
68 for (;;) { 91 for (;;) {
69 - type = SRS_RTMP_TYPE_VIDEO;  
70 - timestamp += 40;  
71 - size = 4096;  
72 - data = (char*)malloc(4096); 92 + // read from file, or get h264 raw data from device, whatever.
  93 + int size = 4096;
  94 + char* data = (char*)malloc(4096);
  95 + if ((size = read(raw_fd, data, size)) < 0) {
  96 + srs_trace("read h264 raw data failed. nread=%d", size);
  97 + goto rtmp_destroy;
  98 + }
  99 + if (size == 0) {
  100 + srs_trace("publish h264 raw data completed.");
  101 + goto rtmp_destroy;
  102 + }
  103 +
  104 + char* rtmp_data = NULL;
  105 + int rtmp_size = 0;
  106 + u_int32_t timestamp = 0;
  107 + if (srs_h264_to_rtmp(data, size, dts, pts, &rtmp_data, &rtmp_size, &timestamp) < 0) {
  108 + srs_trace("h264 raw data to rtmp data failed.");
  109 + goto rtmp_destroy;
  110 + }
73 111
74 - if (srs_write_packet(rtmp, type, timestamp, data, size) != 0) { 112 + int type = SRS_RTMP_TYPE_VIDEO;
  113 + if (srs_write_packet(rtmp, type, timestamp, rtmp_data, rtmp_size) != 0) {
75 goto rtmp_destroy; 114 goto rtmp_destroy;
76 } 115 }
77 - srs_trace("sent packet: type=%s, time=%d, size=%d", srs_type2string(type), timestamp, size); 116 + srs_trace("sent packet: type=%s, time=%d, size=%d", srs_type2string(type), timestamp, rtmp_size);
78 117
79 usleep(40 * 1000); 118 usleep(40 * 1000);
80 } 119 }
81 120
82 rtmp_destroy: 121 rtmp_destroy:
83 srs_rtmp_destroy(rtmp); 122 srs_rtmp_destroy(rtmp);
  123 + close(raw_fd);
84 124
85 return 0; 125 return 0;
86 } 126 }
  127 +
@@ -996,6 +996,13 @@ char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize) @@ -996,6 +996,13 @@ char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize)
996 return any->human_print(pdata, psize); 996 return any->human_print(pdata, psize);
997 } 997 }
998 998
  999 +int srs_h264_to_rtmp(char* h264_raw_data, int h264_raw_size, u_int32_t dts, u_int32_t pts, char** prtmp_data, int* prtmp_size, u_int32_t* ptimestamp)
  1000 +{
  1001 + *prtmp_data = h264_raw_data;
  1002 + *prtmp_size = h264_raw_size;
  1003 + return 0;
  1004 +}
  1005 +
999 #ifdef __cplusplus 1006 #ifdef __cplusplus
1000 } 1007 }
1001 #endif 1008 #endif
@@ -42,6 +42,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -42,6 +42,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 extern "C"{ 42 extern "C"{
43 #endif 43 #endif
44 44
  45 +/*************************************************************
  46 +**************************************************************
  47 +* RTMP protocol context
  48 +**************************************************************
  49 +*************************************************************/
45 // the RTMP handler. 50 // the RTMP handler.
46 typedef void* srs_rtmp_t; 51 typedef void* srs_rtmp_t;
47 52
@@ -51,7 +56,7 @@ typedef void* srs_rtmp_t; @@ -51,7 +56,7 @@ typedef void* srs_rtmp_t;
51 * rtmp://localhost/live/livestream 56 * rtmp://localhost/live/livestream
52 * @return a rtmp handler, or NULL if error occured. 57 * @return a rtmp handler, or NULL if error occured.
53 */ 58 */
54 -srs_rtmp_t srs_rtmp_create(const char* url); 59 +extern srs_rtmp_t srs_rtmp_create(const char* url);
55 /** 60 /**
56 * create rtmp with url, used for connection specified application. 61 * create rtmp with url, used for connection specified application.
57 * @param url the tcUrl, for exmple: 62 * @param url the tcUrl, for exmple:
@@ -59,13 +64,18 @@ srs_rtmp_t srs_rtmp_create(const char* url); @@ -59,13 +64,18 @@ srs_rtmp_t srs_rtmp_create(const char* url);
59 * @remark this is used to create application connection-oriented, 64 * @remark this is used to create application connection-oriented,
60 * for example, the bandwidth client used this, no stream specified. 65 * for example, the bandwidth client used this, no stream specified.
61 */ 66 */
62 -srs_rtmp_t srs_rtmp_create2(const char* url); 67 +extern srs_rtmp_t srs_rtmp_create2(const char* url);
63 /** 68 /**
64 * close and destroy the rtmp stack. 69 * close and destroy the rtmp stack.
65 * @remark, user should use the rtmp again. 70 * @remark, user should use the rtmp again.
66 */ 71 */
67 -void srs_rtmp_destroy(srs_rtmp_t rtmp); 72 +extern void srs_rtmp_destroy(srs_rtmp_t rtmp);
68 73
  74 +/*************************************************************
  75 +**************************************************************
  76 +* RTMP protocol stack
  77 +**************************************************************
  78 +*************************************************************/
69 /** 79 /**
70 * connect and handshake with server 80 * connect and handshake with server
71 * category: publish/play 81 * category: publish/play
@@ -84,13 +94,13 @@ void srs_rtmp_destroy(srs_rtmp_t rtmp); @@ -84,13 +94,13 @@ void srs_rtmp_destroy(srs_rtmp_t rtmp);
84 * __srs_do_simple_handshake() 94 * __srs_do_simple_handshake()
85 * user can use these functions if needed. 95 * user can use these functions if needed.
86 */ 96 */
87 -int srs_simple_handshake(srs_rtmp_t rtmp); 97 +extern int srs_simple_handshake(srs_rtmp_t rtmp);
88 // parse uri, create socket, resolve host 98 // parse uri, create socket, resolve host
89 -int __srs_dns_resolve(srs_rtmp_t rtmp); 99 +extern int __srs_dns_resolve(srs_rtmp_t rtmp);
90 // connect socket to server 100 // connect socket to server
91 -int __srs_connect_server(srs_rtmp_t rtmp); 101 +extern int __srs_connect_server(srs_rtmp_t rtmp);
92 // do simple handshake over socket. 102 // do simple handshake over socket.
93 -int __srs_do_simple_handshake(srs_rtmp_t rtmp); 103 +extern int __srs_do_simple_handshake(srs_rtmp_t rtmp);
94 104
95 /** 105 /**
96 * connect to rtmp vhost/app 106 * connect to rtmp vhost/app
@@ -99,7 +109,7 @@ int __srs_do_simple_handshake(srs_rtmp_t rtmp); @@ -99,7 +109,7 @@ int __srs_do_simple_handshake(srs_rtmp_t rtmp);
99 * next: publish or play 109 * next: publish or play
100 * @return 0, success; otherwise, failed. 110 * @return 0, success; otherwise, failed.
101 */ 111 */
102 -int srs_connect_app(srs_rtmp_t rtmp); 112 +extern int srs_connect_app(srs_rtmp_t rtmp);
103 113
104 /** 114 /**
105 * connect to server, get the debug srs info. 115 * connect to server, get the debug srs info.
@@ -112,7 +122,7 @@ int srs_connect_app(srs_rtmp_t rtmp); @@ -112,7 +122,7 @@ int srs_connect_app(srs_rtmp_t rtmp);
112 * @param srs_id, int, debug info, client id in server log. 122 * @param srs_id, int, debug info, client id in server log.
113 * @param srs_pid, int, debug info, server pid in log. 123 * @param srs_pid, int, debug info, server pid in log.
114 */ 124 */
115 -int srs_connect_app2(srs_rtmp_t rtmp, 125 +extern int srs_connect_app2(srs_rtmp_t rtmp,
116 char srs_server_ip[128], char srs_server[128], char srs_primary_authors[128], 126 char srs_server_ip[128], char srs_server[128], char srs_primary_authors[128],
117 char srs_version[32], int* srs_id, int* srs_pid 127 char srs_version[32], int* srs_id, int* srs_pid
118 ); 128 );
@@ -124,7 +134,7 @@ int srs_connect_app2(srs_rtmp_t rtmp, @@ -124,7 +134,7 @@ int srs_connect_app2(srs_rtmp_t rtmp,
124 * next: destroy 134 * next: destroy
125 * @return 0, success; otherwise, failed. 135 * @return 0, success; otherwise, failed.
126 */ 136 */
127 -int srs_play_stream(srs_rtmp_t rtmp); 137 +extern int srs_play_stream(srs_rtmp_t rtmp);
128 138
129 /** 139 /**
130 * publish a live stream. 140 * publish a live stream.
@@ -133,7 +143,7 @@ int srs_play_stream(srs_rtmp_t rtmp); @@ -133,7 +143,7 @@ int srs_play_stream(srs_rtmp_t rtmp);
133 * next: destroy 143 * next: destroy
134 * @return 0, success; otherwise, failed. 144 * @return 0, success; otherwise, failed.
135 */ 145 */
136 -int srs_publish_stream(srs_rtmp_t rtmp); 146 +extern int srs_publish_stream(srs_rtmp_t rtmp);
137 147
138 /** 148 /**
139 * do bandwidth check with srs server. 149 * do bandwidth check with srs server.
@@ -148,7 +158,7 @@ int srs_publish_stream(srs_rtmp_t rtmp); @@ -148,7 +158,7 @@ int srs_publish_stream(srs_rtmp_t rtmp);
148 * @param play_duration, output the play/download test duration, in ms. 158 * @param play_duration, output the play/download test duration, in ms.
149 * @param publish_duration, output the publish/upload test duration, in ms. 159 * @param publish_duration, output the publish/upload test duration, in ms.
150 */ 160 */
151 -int srs_bandwidth_check(srs_rtmp_t rtmp, 161 +extern int srs_bandwidth_check(srs_rtmp_t rtmp,
152 int64_t* start_time, int64_t* end_time, 162 int64_t* start_time, int64_t* end_time,
153 int* play_kbps, int* publish_kbps, 163 int* play_kbps, int* publish_kbps,
154 int* play_bytes, int* publish_bytes, 164 int* play_bytes, int* publish_bytes,
@@ -173,7 +183,7 @@ int srs_bandwidth_check(srs_rtmp_t rtmp, @@ -173,7 +183,7 @@ int srs_bandwidth_check(srs_rtmp_t rtmp,
173 * @remark user never free the return char*, 183 * @remark user never free the return char*,
174 * it's static shared const string. 184 * it's static shared const string.
175 */ 185 */
176 -const char* srs_type2string(int type); 186 +extern const char* srs_type2string(int type);
177 /** 187 /**
178 * read a audio/video/script-data packet from rtmp stream. 188 * read a audio/video/script-data packet from rtmp stream.
179 * @param type, output the packet type, macros: 189 * @param type, output the packet type, macros:
@@ -191,113 +201,144 @@ const char* srs_type2string(int type); @@ -191,113 +201,144 @@ const char* srs_type2string(int type);
191 * @remark: for read, user must free the data. 201 * @remark: for read, user must free the data.
192 * @remark: for write, user should never free the data, even if error. 202 * @remark: for write, user should never free the data, even if error.
193 */ 203 */
194 -int srs_read_packet(srs_rtmp_t rtmp, int* type, u_int32_t* timestamp, char** data, int* size);  
195 -int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, int size); 204 +extern int srs_read_packet(srs_rtmp_t rtmp,
  205 + int* type, u_int32_t* timestamp, char** data, int* size
  206 +);
  207 +extern int srs_write_packet(srs_rtmp_t rtmp,
  208 + int type, u_int32_t timestamp, char* data, int size
  209 +);
196 210
197 -/**  
198 -* get protocol stack version  
199 -*/  
200 -int srs_version_major();  
201 -int srs_version_minor();  
202 -int srs_version_revision(); 211 +// get protocol stack version
  212 +extern int srs_version_major();
  213 +extern int srs_version_minor();
  214 +extern int srs_version_revision();
203 215
204 -/** 216 +/*************************************************************
  217 +**************************************************************
205 * utilities 218 * utilities
206 -*/  
207 -int64_t srs_get_time_ms();  
208 -int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp);  
209 -int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp); 219 +**************************************************************
  220 +*************************************************************/
  221 +extern int64_t srs_get_time_ms();
  222 +extern int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp);
  223 +extern int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp);
210 224
211 -/** 225 +
  226 +/*************************************************************
  227 +**************************************************************
212 * flv codec 228 * flv codec
213 -*/ 229 +**************************************************************
  230 +*************************************************************/
214 typedef void* srs_flv_t; 231 typedef void* srs_flv_t;
215 typedef int flv_bool; 232 typedef int flv_bool;
216 /* open flv file for both read/write. */ 233 /* open flv file for both read/write. */
217 -srs_flv_t srs_flv_open_read(const char* file);  
218 -srs_flv_t srs_flv_open_write(const char* file);  
219 -void srs_flv_close(srs_flv_t flv); 234 +extern srs_flv_t srs_flv_open_read(const char* file);
  235 +extern srs_flv_t srs_flv_open_write(const char* file);
  236 +extern void srs_flv_close(srs_flv_t flv);
220 /* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */ 237 /* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */
221 -int srs_flv_read_header(srs_flv_t flv, char header[9]); 238 +extern int srs_flv_read_header(srs_flv_t flv, char header[9]);
222 /* read the flv tag header, 1bytes tag, 3bytes data_size, 4bytes time, 3bytes stream id. */ 239 /* read the flv tag header, 1bytes tag, 3bytes data_size, 4bytes time, 3bytes stream id. */
223 -int srs_flv_read_tag_header(srs_flv_t flv, char* ptype, int32_t* pdata_size, u_int32_t* ptime); 240 +extern int srs_flv_read_tag_header(srs_flv_t flv,
  241 + char* ptype, int32_t* pdata_size, u_int32_t* ptime
  242 +);
224 /* read the tag data. drop the 4bytes previous tag size */ 243 /* read the tag data. drop the 4bytes previous tag size */
225 -int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size); 244 +extern int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size);
226 /* write flv header to file, auto write the 4bytes zero previous tag size. */ 245 /* write flv header to file, auto write the 4bytes zero previous tag size. */
227 -int srs_flv_write_header(srs_flv_t flv, char header[9]); 246 +extern int srs_flv_write_header(srs_flv_t flv, char header[9]);
228 /* write flv tag to file, auto write the 4bytes previous tag size */ 247 /* write flv tag to file, auto write the 4bytes previous tag size */
229 -int srs_flv_write_tag(srs_flv_t flv, char type, int32_t time, char* data, int size); 248 +extern int srs_flv_write_tag(srs_flv_t flv, char type, int32_t time, char* data, int size);
230 /* get the tag size, for flv injecter to adjust offset, size=tag_header+data+previous_tag */ 249 /* get the tag size, for flv injecter to adjust offset, size=tag_header+data+previous_tag */
231 -int srs_flv_size_tag(int data_size); 250 +extern int srs_flv_size_tag(int data_size);
232 /* file stream */ 251 /* file stream */
233 /* file stream tellg to get offset */ 252 /* file stream tellg to get offset */
234 -int64_t srs_flv_tellg(srs_flv_t flv); 253 +extern int64_t srs_flv_tellg(srs_flv_t flv);
235 /* seek file stream, offset is form the start of file */ 254 /* seek file stream, offset is form the start of file */
236 -void srs_flv_lseek(srs_flv_t flv, int64_t offset); 255 +extern void srs_flv_lseek(srs_flv_t flv, int64_t offset);
237 /* error code */ 256 /* error code */
238 /* whether the error code indicates EOF */ 257 /* whether the error code indicates EOF */
239 -flv_bool srs_flv_is_eof(int error_code); 258 +extern flv_bool srs_flv_is_eof(int error_code);
240 /* media codec */ 259 /* media codec */
241 /* whether the video body is sequence header */ 260 /* whether the video body is sequence header */
242 -flv_bool srs_flv_is_sequence_header(char* data, int32_t size); 261 +extern flv_bool srs_flv_is_sequence_header(char* data, int32_t size);
243 /* whether the video body is keyframe */ 262 /* whether the video body is keyframe */
244 -flv_bool srs_flv_is_keyframe(char* data, int32_t size); 263 +extern flv_bool srs_flv_is_keyframe(char* data, int32_t size);
245 264
246 -/** 265 +/*************************************************************
  266 +**************************************************************
247 * amf0 codec 267 * amf0 codec
248 -*/ 268 +**************************************************************
  269 +*************************************************************/
249 /* the output handler. */ 270 /* the output handler. */
250 typedef void* srs_amf0_t; 271 typedef void* srs_amf0_t;
251 typedef int amf0_bool; 272 typedef int amf0_bool;
252 typedef double amf0_number; 273 typedef double amf0_number;
253 -srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed);  
254 -srs_amf0_t srs_amf0_create_number(amf0_number value);  
255 -srs_amf0_t srs_amf0_create_ecma_array();  
256 -srs_amf0_t srs_amf0_create_strict_array();  
257 -srs_amf0_t srs_amf0_create_object();  
258 -void srs_amf0_free(srs_amf0_t amf0);  
259 -void srs_amf0_free_bytes(char* data); 274 +extern srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed);
  275 +extern srs_amf0_t srs_amf0_create_number(amf0_number value);
  276 +extern srs_amf0_t srs_amf0_create_ecma_array();
  277 +extern srs_amf0_t srs_amf0_create_strict_array();
  278 +extern srs_amf0_t srs_amf0_create_object();
  279 +extern void srs_amf0_free(srs_amf0_t amf0);
  280 +extern void srs_amf0_free_bytes(char* data);
260 /* size and to bytes */ 281 /* size and to bytes */
261 -int srs_amf0_size(srs_amf0_t amf0);  
262 -int srs_amf0_serialize(srs_amf0_t amf0, char* data, int size); 282 +extern int srs_amf0_size(srs_amf0_t amf0);
  283 +extern int srs_amf0_serialize(srs_amf0_t amf0, char* data, int size);
263 /* type detecter */ 284 /* type detecter */
264 -amf0_bool srs_amf0_is_string(srs_amf0_t amf0);  
265 -amf0_bool srs_amf0_is_boolean(srs_amf0_t amf0);  
266 -amf0_bool srs_amf0_is_number(srs_amf0_t amf0);  
267 -amf0_bool srs_amf0_is_null(srs_amf0_t amf0);  
268 -amf0_bool srs_amf0_is_object(srs_amf0_t amf0);  
269 -amf0_bool srs_amf0_is_ecma_array(srs_amf0_t amf0);  
270 -amf0_bool srs_amf0_is_strict_array(srs_amf0_t amf0); 285 +extern amf0_bool srs_amf0_is_string(srs_amf0_t amf0);
  286 +extern amf0_bool srs_amf0_is_boolean(srs_amf0_t amf0);
  287 +extern amf0_bool srs_amf0_is_number(srs_amf0_t amf0);
  288 +extern amf0_bool srs_amf0_is_null(srs_amf0_t amf0);
  289 +extern amf0_bool srs_amf0_is_object(srs_amf0_t amf0);
  290 +extern amf0_bool srs_amf0_is_ecma_array(srs_amf0_t amf0);
  291 +extern amf0_bool srs_amf0_is_strict_array(srs_amf0_t amf0);
271 /* value converter */ 292 /* value converter */
272 -const char* srs_amf0_to_string(srs_amf0_t amf0);  
273 -amf0_bool srs_amf0_to_boolean(srs_amf0_t amf0);  
274 -amf0_number srs_amf0_to_number(srs_amf0_t amf0); 293 +extern const char* srs_amf0_to_string(srs_amf0_t amf0);
  294 +extern amf0_bool srs_amf0_to_boolean(srs_amf0_t amf0);
  295 +extern amf0_number srs_amf0_to_number(srs_amf0_t amf0);
275 /* value setter */ 296 /* value setter */
276 -void srs_amf0_set_number(srs_amf0_t amf0, amf0_number value); 297 +extern void srs_amf0_set_number(srs_amf0_t amf0, amf0_number value);
277 /* object value converter */ 298 /* object value converter */
278 -int srs_amf0_object_property_count(srs_amf0_t amf0);  
279 -const char* srs_amf0_object_property_name_at(srs_amf0_t amf0, int index);  
280 -srs_amf0_t srs_amf0_object_property_value_at(srs_amf0_t amf0, int index);  
281 -srs_amf0_t srs_amf0_object_property(srs_amf0_t amf0, const char* name);  
282 -void srs_amf0_object_property_set(srs_amf0_t amf0, const char* name, srs_amf0_t value);  
283 -void srs_amf0_object_clear(srs_amf0_t amf0); 299 +extern int srs_amf0_object_property_count(srs_amf0_t amf0);
  300 +extern const char* srs_amf0_object_property_name_at(srs_amf0_t amf0, int index);
  301 +extern srs_amf0_t srs_amf0_object_property_value_at(srs_amf0_t amf0, int index);
  302 +extern srs_amf0_t srs_amf0_object_property(srs_amf0_t amf0, const char* name);
  303 +extern void srs_amf0_object_property_set(srs_amf0_t amf0, const char* name, srs_amf0_t value);
  304 +extern void srs_amf0_object_clear(srs_amf0_t amf0);
284 /* ecma array value converter */ 305 /* ecma array value converter */
285 -int srs_amf0_ecma_array_property_count(srs_amf0_t amf0);  
286 -const char* srs_amf0_ecma_array_property_name_at(srs_amf0_t amf0, int index);  
287 -srs_amf0_t srs_amf0_ecma_array_property_value_at(srs_amf0_t amf0, int index);  
288 -srs_amf0_t srs_amf0_ecma_array_property(srs_amf0_t amf0, const char* name);  
289 -void srs_amf0_ecma_array_property_set(srs_amf0_t amf0, const char* name, srs_amf0_t value); 306 +extern int srs_amf0_ecma_array_property_count(srs_amf0_t amf0);
  307 +extern const char* srs_amf0_ecma_array_property_name_at(srs_amf0_t amf0, int index);
  308 +extern srs_amf0_t srs_amf0_ecma_array_property_value_at(srs_amf0_t amf0, int index);
  309 +extern srs_amf0_t srs_amf0_ecma_array_property(srs_amf0_t amf0, const char* name);
  310 +extern void srs_amf0_ecma_array_property_set(srs_amf0_t amf0, const char* name, srs_amf0_t value);
290 /* strict array value converter */ 311 /* strict array value converter */
291 -int srs_amf0_strict_array_property_count(srs_amf0_t amf0);  
292 -srs_amf0_t srs_amf0_strict_array_property_at(srs_amf0_t amf0, int index);  
293 -void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value); 312 +extern int srs_amf0_strict_array_property_count(srs_amf0_t amf0);
  313 +extern srs_amf0_t srs_amf0_strict_array_property_at(srs_amf0_t amf0, int index);
  314 +extern void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value);
294 /** 315 /**
295 * human readable print 316 * human readable print
296 * @param pdata, output the heap data, NULL to ignore. 317 * @param pdata, output the heap data, NULL to ignore.
297 * user must use srs_amf0_free_bytes to free it. 318 * user must use srs_amf0_free_bytes to free it.
298 * @return return the *pdata for print. NULL to ignore. 319 * @return return the *pdata for print. NULL to ignore.
299 */ 320 */
300 -char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize); 321 +extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize);
  322 +
  323 +/*************************************************************
  324 +**************************************************************
  325 +* h264 raw codec
  326 +**************************************************************
  327 +*************************************************************/
  328 +/**
  329 +convert h264 stream data to rtmp packet.
  330 +@param h264_raw_data the input h264 raw data, a encoded h.264 I/P/B frame data.
  331 +@paam h264_raw_size the size of h264 raw data.
  332 +@param dts the dts of h.264 raw data.
  333 +@param pts the pts of h.264 raw data.
  334 +@param prtmp_data the output rtmp format packet, which can be send by srs_write_packet.
  335 +@param prtmp_size the size of rtmp packet, for srs_write_packet.
  336 +@param ptimestamp the timestamp of rtmp packet, for srs_write_packet.
  337 +*/
  338 +extern int srs_h264_to_rtmp(
  339 + char* h264_raw_data, int h264_raw_size, u_int32_t dts, u_int32_t pts,
  340 + char** prtmp_data, int* prtmp_size, u_int32_t* ptimestamp
  341 +);
301 342
302 #ifdef __cplusplus 343 #ifdef __cplusplus
303 } 344 }