fix the rewind bug, support republish by restart the ffmpeg encoder.
正在显示
2 个修改的文件
包含
21 行增加
和
3 行删除
| @@ -27,6 +27,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -27,6 +27,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 27 | #include <unistd.h> | 27 | #include <unistd.h> |
| 28 | #include <sys/wait.h> | 28 | #include <sys/wait.h> |
| 29 | #include <fcntl.h> | 29 | #include <fcntl.h> |
| 30 | +#include <signal.h> | ||
| 31 | +#include <sys/types.h> | ||
| 30 | 32 | ||
| 31 | #include <algorithm> | 33 | #include <algorithm> |
| 32 | 34 | ||
| @@ -415,8 +417,6 @@ int SrsFFMPEG::cycle() | @@ -415,8 +417,6 @@ int SrsFFMPEG::cycle() | ||
| 415 | return ret; | 417 | return ret; |
| 416 | } | 418 | } |
| 417 | 419 | ||
| 418 | - // TODO: to support rewind. | ||
| 419 | - | ||
| 420 | if (p == 0) { | 420 | if (p == 0) { |
| 421 | srs_info("transcode process pid=%d is running.", pid); | 421 | srs_info("transcode process pid=%d is running.", pid); |
| 422 | return ret; | 422 | return ret; |
| @@ -439,7 +439,23 @@ void SrsFFMPEG::stop() | @@ -439,7 +439,23 @@ void SrsFFMPEG::stop() | ||
| 439 | return; | 439 | return; |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | - // TODO: kill the ffmpeg process when stop. | 442 | + // kill the ffmpeg, |
| 443 | + // when rewind, upstream will stop publish(unpublish), | ||
| 444 | + // unpublish event will stop all ffmpeg encoders, | ||
| 445 | + // then publish will start all ffmpeg encoders. | ||
| 446 | + if (pid > 0) { | ||
| 447 | + if (kill(pid, SIGKILL) < 0) { | ||
| 448 | + srs_warn("kill the encoder failed, ignored. pid=%d", pid); | ||
| 449 | + } | ||
| 450 | + | ||
| 451 | + int status = 0; | ||
| 452 | + if (waitpid(pid, &status, WNOHANG) < 0) { | ||
| 453 | + srs_warn("wait the encoder quit failed, ignored. pid=%d", pid); | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + srs_trace("stop the encoder success. pid=%d", pid); | ||
| 457 | + pid = -1; | ||
| 458 | + } | ||
| 443 | 459 | ||
| 444 | std::vector<std::string>::iterator it; | 460 | std::vector<std::string>::iterator it; |
| 445 | it = std::find(_transcoded_url.begin(), _transcoded_url.end(), output); | 461 | it = std::find(_transcoded_url.begin(), _transcoded_url.end(), output); |
| @@ -287,6 +287,8 @@ void SrsServer::on_signal(int signo) | @@ -287,6 +287,8 @@ void SrsServer::on_signal(int signo) | ||
| 287 | if (signo == SIGNAL_RELOAD) { | 287 | if (signo == SIGNAL_RELOAD) { |
| 288 | signal_reload = true; | 288 | signal_reload = true; |
| 289 | } | 289 | } |
| 290 | + | ||
| 291 | + // TODO: handle the SIGINT, SIGTERM. | ||
| 290 | } | 292 | } |
| 291 | 293 | ||
| 292 | void SrsServer::close_listeners() | 294 | void SrsServer::close_listeners() |
-
请 注册 或 登录 后发表评论