winlin

for #474, always release publish for source.

@@ -343,6 +343,7 @@ Remark: @@ -343,6 +343,7 @@ Remark:
343 343
344 ## History 344 ## History
345 345
  346 +* v2.0, 2015-09-14, for [#474][bug #474] always release publish for source.
346 * v2.0, 2015-09-14, for [#458][bug #458] http hooks use source thread cid. 2.0.188 347 * v2.0, 2015-09-14, for [#458][bug #458] http hooks use source thread cid. 2.0.188
347 * v2.0, 2015-09-14, for [#475][bug #475] fix http hooks crash for st context switch. 2.0.187 348 * v2.0, 2015-09-14, for [#475][bug #475] fix http hooks crash for st context switch. 2.0.187
348 * v2.0, 2015-09-09, support reload utc_time. 2.0.186 349 * v2.0, 2015-09-09, support reload utc_time. 2.0.186
@@ -1026,6 +1027,7 @@ Winlin @@ -1026,6 +1027,7 @@ Winlin
1026 [bug #133]: https://github.com/simple-rtmp-server/srs/issues/133 1027 [bug #133]: https://github.com/simple-rtmp-server/srs/issues/133
1027 [bug #92]: https://github.com/simple-rtmp-server/srs/issues/92 1028 [bug #92]: https://github.com/simple-rtmp-server/srs/issues/92
1028 [bug #380]: https://github.com/simple-rtmp-server/srs/issues/380 1029 [bug #380]: https://github.com/simple-rtmp-server/srs/issues/380
  1030 +[bug #474]: https://github.com/simple-rtmp-server/srs/issues/474
1029 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475 1031 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475
1030 [bug #458]: https://github.com/simple-rtmp-server/srs/issues/458 1032 [bug #458]: https://github.com/simple-rtmp-server/srs/issues/458
1031 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454 1033 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454
@@ -834,9 +834,13 @@ int SrsRtmpConn::publishing(SrsSource* source) @@ -834,9 +834,13 @@ int SrsRtmpConn::publishing(SrsSource* source)
834 834
835 // stop isolate recv thread 835 // stop isolate recv thread
836 trd.stop(); 836 trd.stop();
837 -  
838 - release_publish(source, vhost_is_edge);  
839 } 837 }
  838 +
  839 + // whatever the acquire publish, always release publish.
  840 + // when the acquire error in the midlle-way, the publish state changed,
  841 + // but failed, so we must cleanup it.
  842 + // @see https://github.com/simple-rtmp-server/srs/issues/474
  843 + release_publish(source, vhost_is_edge);
840 844
841 http_hooks_on_unpublish(); 845 http_hooks_on_unpublish();
842 846
@@ -944,10 +948,12 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge) @@ -944,10 +948,12 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge)
944 if (is_edge) { 948 if (is_edge) {
945 if ((ret = source->on_edge_start_publish()) != ERROR_SUCCESS) { 949 if ((ret = source->on_edge_start_publish()) != ERROR_SUCCESS) {
946 srs_error("notice edge start publish stream failed. ret=%d", ret); 950 srs_error("notice edge start publish stream failed. ret=%d", ret);
  951 + return ret;
947 } 952 }
948 } else { 953 } else {
949 if ((ret = source->on_publish()) != ERROR_SUCCESS) { 954 if ((ret = source->on_publish()) != ERROR_SUCCESS) {
950 srs_error("notify publish failed. ret=%d", ret); 955 srs_error("notify publish failed. ret=%d", ret);
  956 + return ret;
951 } 957 }
952 } 958 }
953 959
@@ -2066,6 +2066,7 @@ int SrsSource::on_publish() @@ -2066,6 +2066,7 @@ int SrsSource::on_publish()
2066 } 2066 }
2067 SrsStatistic* stat = SrsStatistic::instance(); 2067 SrsStatistic* stat = SrsStatistic::instance();
2068 stat->on_stream_publish(_req, _source_id); 2068 stat->on_stream_publish(_req, _source_id);
  2069 +
2069 return ret; 2070 return ret;
2070 } 2071 }
2071 2072
@@ -217,6 +217,8 @@ namespace internal { @@ -217,6 +217,8 @@ namespace internal {
217 217
218 handler->on_thread_stop(); 218 handler->on_thread_stop();
219 srs_info("thread %s cycle finished", _name); 219 srs_info("thread %s cycle finished", _name);
  220 +
  221 + // TODO: FIXME: when thread terminated normally, set the tid to NULL.
220 } 222 }
221 223
222 void* SrsThread::thread_fun(void* arg) 224 void* SrsThread::thread_fun(void* arg)