diff --git a/trunk/src/core/srs_core_encoder.cpp b/trunk/src/core/srs_core_encoder.cpp index be0e5cb77..4315fcd54 100644 --- a/trunk/src/core/srs_core_encoder.cpp +++ b/trunk/src/core/srs_core_encoder.cpp @@ -27,6 +27,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include +#include #include @@ -415,8 +417,6 @@ int SrsFFMPEG::cycle() return ret; } - // TODO: to support rewind. - if (p == 0) { srs_info("transcode process pid=%d is running.", pid); return ret; @@ -439,7 +439,23 @@ void SrsFFMPEG::stop() return; } - // TODO: kill the ffmpeg process when stop. + // kill the ffmpeg, + // when rewind, upstream will stop publish(unpublish), + // unpublish event will stop all ffmpeg encoders, + // then publish will start all ffmpeg encoders. + if (pid > 0) { + if (kill(pid, SIGKILL) < 0) { + srs_warn("kill the encoder failed, ignored. pid=%d", pid); + } + + int status = 0; + if (waitpid(pid, &status, WNOHANG) < 0) { + srs_warn("wait the encoder quit failed, ignored. pid=%d", pid); + } + + srs_trace("stop the encoder success. pid=%d", pid); + pid = -1; + } std::vector::iterator it; it = std::find(_transcoded_url.begin(), _transcoded_url.end(), output); diff --git a/trunk/src/core/srs_core_server.cpp b/trunk/src/core/srs_core_server.cpp index 0c6da8e34..6dc089710 100644 --- a/trunk/src/core/srs_core_server.cpp +++ b/trunk/src/core/srs_core_server.cpp @@ -287,6 +287,8 @@ void SrsServer::on_signal(int signo) if (signo == SIGNAL_RELOAD) { signal_reload = true; } + + // TODO: handle the SIGINT, SIGTERM. } void SrsServer::close_listeners()