正在显示
3 个修改的文件
包含
18 行增加
和
9 行删除
| @@ -39,22 +39,23 @@ int main(int argc, char** argv) | @@ -39,22 +39,23 @@ int main(int argc, char** argv) | ||
| 39 | 39 | ||
| 40 | if (srs_simple_handshake(rtmp) != 0) { | 40 | if (srs_simple_handshake(rtmp) != 0) { |
| 41 | printf("simple handshake failed.\n"); | 41 | printf("simple handshake failed.\n"); |
| 42 | - return -1; | 42 | + goto rtmp_destroy; |
| 43 | } | 43 | } |
| 44 | printf("simple handshake success\n"); | 44 | printf("simple handshake success\n"); |
| 45 | 45 | ||
| 46 | if (srs_connect_app(rtmp) != 0) { | 46 | if (srs_connect_app(rtmp) != 0) { |
| 47 | printf("connect vhost/app failed.\n"); | 47 | printf("connect vhost/app failed.\n"); |
| 48 | - return -1; | 48 | + goto rtmp_destroy; |
| 49 | } | 49 | } |
| 50 | printf("connect vhost/app success\n"); | 50 | printf("connect vhost/app success\n"); |
| 51 | 51 | ||
| 52 | if (srs_play_stream(rtmp) != 0) { | 52 | if (srs_play_stream(rtmp) != 0) { |
| 53 | printf("play stream failed.\n"); | 53 | printf("play stream failed.\n"); |
| 54 | - return -1; | 54 | + goto rtmp_destroy; |
| 55 | } | 55 | } |
| 56 | printf("play stream success\n"); | 56 | printf("play stream success\n"); |
| 57 | 57 | ||
| 58 | +rtmp_destroy: | ||
| 58 | srs_rtmp_destroy(rtmp); | 59 | srs_rtmp_destroy(rtmp); |
| 59 | 60 | ||
| 60 | return 0; | 61 | return 0; |
| @@ -39,22 +39,23 @@ int main(int argc, char** argv) | @@ -39,22 +39,23 @@ int main(int argc, char** argv) | ||
| 39 | 39 | ||
| 40 | if (srs_simple_handshake(rtmp) != 0) { | 40 | if (srs_simple_handshake(rtmp) != 0) { |
| 41 | printf("simple handshake failed.\n"); | 41 | printf("simple handshake failed.\n"); |
| 42 | - return -1; | 42 | + goto rtmp_destroy; |
| 43 | } | 43 | } |
| 44 | printf("simple handshake success\n"); | 44 | printf("simple handshake success\n"); |
| 45 | 45 | ||
| 46 | if (srs_connect_app(rtmp) != 0) { | 46 | if (srs_connect_app(rtmp) != 0) { |
| 47 | printf("connect vhost/app failed.\n"); | 47 | printf("connect vhost/app failed.\n"); |
| 48 | - return -1; | 48 | + goto rtmp_destroy; |
| 49 | } | 49 | } |
| 50 | printf("connect vhost/app success\n"); | 50 | printf("connect vhost/app success\n"); |
| 51 | 51 | ||
| 52 | if (srs_publish_stream(rtmp) != 0) { | 52 | if (srs_publish_stream(rtmp) != 0) { |
| 53 | printf("publish stream failed.\n"); | 53 | printf("publish stream failed.\n"); |
| 54 | - return -1; | 54 | + goto rtmp_destroy; |
| 55 | } | 55 | } |
| 56 | printf("publish stream success\n"); | 56 | printf("publish stream success\n"); |
| 57 | 57 | ||
| 58 | +rtmp_destroy: | ||
| 58 | srs_rtmp_destroy(rtmp); | 59 | srs_rtmp_destroy(rtmp); |
| 59 | 60 | ||
| 60 | return 0; | 61 | return 0; |
| @@ -39,17 +39,17 @@ struct Context | @@ -39,17 +39,17 @@ struct Context | ||
| 39 | { | 39 | { |
| 40 | std::string url; | 40 | std::string url; |
| 41 | SrsRtmpClient* rtmp; | 41 | SrsRtmpClient* rtmp; |
| 42 | - SimpleSocketStream* stream; | 42 | + SimpleSocketStream* skt; |
| 43 | int stream_id; | 43 | int stream_id; |
| 44 | 44 | ||
| 45 | Context() { | 45 | Context() { |
| 46 | rtmp = NULL; | 46 | rtmp = NULL; |
| 47 | - stream = NULL; | 47 | + skt = NULL; |
| 48 | stream_id = 0; | 48 | stream_id = 0; |
| 49 | } | 49 | } |
| 50 | virtual ~Context() { | 50 | virtual ~Context() { |
| 51 | srs_freep(rtmp); | 51 | srs_freep(rtmp); |
| 52 | - srs_freep(stream); | 52 | + srs_freep(skt); |
| 53 | } | 53 | } |
| 54 | }; | 54 | }; |
| 55 | 55 | ||
| @@ -66,11 +66,18 @@ srs_rtmp_t srs_rtmp_create(const char* url){ | @@ -66,11 +66,18 @@ srs_rtmp_t srs_rtmp_create(const char* url){ | ||
| 66 | void srs_rtmp_destroy(srs_rtmp_t rtmp){ | 66 | void srs_rtmp_destroy(srs_rtmp_t rtmp){ |
| 67 | srs_assert(rtmp != NULL); | 67 | srs_assert(rtmp != NULL); |
| 68 | Context* context = (Context*)rtmp; | 68 | Context* context = (Context*)rtmp; |
| 69 | + | ||
| 69 | srs_freep(context); | 70 | srs_freep(context); |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | int srs_simple_handshake(srs_rtmp_t rtmp) | 73 | int srs_simple_handshake(srs_rtmp_t rtmp) |
| 73 | { | 74 | { |
| 75 | + srs_assert(rtmp != NULL); | ||
| 76 | + Context* context = (Context*)rtmp; | ||
| 77 | + | ||
| 78 | + srs_freep(context->skt); | ||
| 79 | + context->skt = new SimpleSocketStream(); | ||
| 80 | + | ||
| 74 | return ERROR_SUCCESS; | 81 | return ERROR_SUCCESS; |
| 75 | } | 82 | } |
| 76 | 83 |
-
请 注册 或 登录 后发表评论