winlin

refine hijack io for srslibrtmp

@@ -21,8 +21,8 @@ @@ -21,8 +21,8 @@
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */ 22 */
23 23
24 -#ifndef SRS_KERNEL_AAC_HPP  
25 -#define SRS_KERNEL_AAC_HPP 24 +#ifndef SRS_KERNEL_BALANCE_HPP
  25 +#define SRS_KERNEL_BALANCE_HPP
26 26
27 /* 27 /*
28 #include <srs_kernel_balance.hpp> 28 #include <srs_kernel_balance.hpp>
@@ -102,7 +102,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -102,7 +102,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
102 SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; 102 SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
103 srs_freep(skt); 103 srs_freep(skt);
104 } 104 }
105 - int srs_hijack_io_create_socket(srs_hijack_io_t ctx) 105 + int srs_hijack_io_create_socket(srs_hijack_io_t ctx, srs_rtmp_t owner)
106 { 106 {
107 SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; 107 SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
108 108
@@ -329,10 +329,10 @@ srs_hijack_io_t SimpleSocketStream::hijack_io() @@ -329,10 +329,10 @@ srs_hijack_io_t SimpleSocketStream::hijack_io()
329 return io; 329 return io;
330 } 330 }
331 331
332 -int SimpleSocketStream::create_socket() 332 +int SimpleSocketStream::create_socket(srs_rtmp_t owner)
333 { 333 {
334 srs_assert(io); 334 srs_assert(io);
335 - return srs_hijack_io_create_socket(io); 335 + return srs_hijack_io_create_socket(io, owner);
336 } 336 }
337 337
338 int SimpleSocketStream::connect(const char* server_ip, int port) 338 int SimpleSocketStream::connect(const char* server_ip, int port)
@@ -51,7 +51,7 @@ public: @@ -51,7 +51,7 @@ public:
51 virtual ~SimpleSocketStream(); 51 virtual ~SimpleSocketStream();
52 public: 52 public:
53 virtual srs_hijack_io_t hijack_io(); 53 virtual srs_hijack_io_t hijack_io();
54 - virtual int create_socket(); 54 + virtual int create_socket(srs_rtmp_t owner);
55 virtual int connect(const char* server, int port); 55 virtual int connect(const char* server, int port);
56 // ISrsBufferReader 56 // ISrsBufferReader
57 public: 57 public:
@@ -539,7 +539,7 @@ srs_rtmp_t srs_rtmp_create(const char* url) @@ -539,7 +539,7 @@ srs_rtmp_t srs_rtmp_create(const char* url)
539 srs_freep(context->skt); 539 srs_freep(context->skt);
540 context->skt = new SimpleSocketStream(); 540 context->skt = new SimpleSocketStream();
541 541
542 - if (context->skt->create_socket() != ERROR_SUCCESS) { 542 + if (context->skt->create_socket(context) != ERROR_SUCCESS) {
543 // free the context and return NULL 543 // free the context and return NULL
544 srs_freep(context); 544 srs_freep(context);
545 return NULL; 545 return NULL;
@@ -561,7 +561,7 @@ srs_rtmp_t srs_rtmp_create2(const char* url) @@ -561,7 +561,7 @@ srs_rtmp_t srs_rtmp_create2(const char* url)
561 srs_freep(context->skt); 561 srs_freep(context->skt);
562 context->skt = new SimpleSocketStream(); 562 context->skt = new SimpleSocketStream();
563 563
564 - if (context->skt->create_socket() != ERROR_SUCCESS) { 564 + if (context->skt->create_socket(context) != ERROR_SUCCESS) {
565 // free the context and return NULL 565 // free the context and return NULL
566 srs_freep(context); 566 srs_freep(context);
567 return NULL; 567 return NULL;
@@ -992,7 +992,7 @@ typedef void* srs_hijack_io_t; @@ -992,7 +992,7 @@ typedef void* srs_hijack_io_t;
992 extern srs_hijack_io_t srs_hijack_io_get(srs_rtmp_t rtmp); 992 extern srs_hijack_io_t srs_hijack_io_get(srs_rtmp_t rtmp);
993 #endif 993 #endif
994 // define the following macro and functions in your module to hijack the io. 994 // define the following macro and functions in your module to hijack the io.
995 -// the example @see https://github.com/winlinvip/st-load 995 +// the example @see https://github.com/ossrs/srs-bench
996 // which use librtmp but use its own io(use st also). 996 // which use librtmp but use its own io(use st also).
997 #ifdef SRS_HIJACK_IO 997 #ifdef SRS_HIJACK_IO
998 /** 998 /**
@@ -1006,9 +1006,10 @@ typedef void* srs_hijack_io_t; @@ -1006,9 +1006,10 @@ typedef void* srs_hijack_io_t;
1006 extern void srs_hijack_io_destroy(srs_hijack_io_t ctx); 1006 extern void srs_hijack_io_destroy(srs_hijack_io_t ctx);
1007 /** 1007 /**
1008 * create socket, not connect yet. 1008 * create socket, not connect yet.
  1009 + * @param owner, the rtmp context which create this socket.
1009 * @return 0, success; otherswise, failed. 1010 * @return 0, success; otherswise, failed.
1010 */ 1011 */
1011 - extern int srs_hijack_io_create_socket(srs_hijack_io_t ctx); 1012 + extern int srs_hijack_io_create_socket(srs_hijack_io_t ctx, srs_rtmp_t owner);
1012 /** 1013 /**
1013 * connect socket at server_ip:port. 1014 * connect socket at server_ip:port.
1014 * @return 0, success; otherswise, failed. 1015 * @return 0, success; otherswise, failed.
@@ -29,6 +29,9 @@ @@ -29,6 +29,9 @@
29 */ 29 */
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
  32 +// default http listen port.
  33 +#define SRS_DEFAULT_HTTP_PORT 80
  34 +
32 #if !defined(SRS_EXPORT_LIBRTMP) 35 #if !defined(SRS_EXPORT_LIBRTMP)
33 36
34 #include <map> 37 #include <map>
@@ -68,9 +71,6 @@ class ISrsHttpResponseWriter; @@ -68,9 +71,6 @@ class ISrsHttpResponseWriter;
68 // for ead all of http body, read each time. 71 // for ead all of http body, read each time.
69 #define SRS_HTTP_READ_CACHE_BYTES 4096 72 #define SRS_HTTP_READ_CACHE_BYTES 4096
70 73
71 -// default http listen port.  
72 -#define SRS_DEFAULT_HTTP_PORT 80  
73 -  
74 // for http parser macros 74 // for http parser macros
75 #define SRS_CONSTS_HTTP_OPTIONS HTTP_OPTIONS 75 #define SRS_CONSTS_HTTP_OPTIONS HTTP_OPTIONS
76 #define SRS_CONSTS_HTTP_GET HTTP_GET 76 #define SRS_CONSTS_HTTP_GET HTTP_GET