1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

reap the transcode process

This commit is contained in:
winlin 2013-12-02 23:51:51 +08:00
parent b5bba29768
commit 113731dd6b
6 changed files with 63 additions and 12 deletions

View file

@ -72,18 +72,19 @@ vhost __defaultVhost__ {
vhost dev { vhost dev {
enabled on; enabled on;
gop_cache on; gop_cache on;
hls on; hls off;
hls_path ./objs/nginx/html; hls_path ./objs/nginx/html;
hls_fragment 5; hls_fragment 5;
hls_window 30; hls_window 30;
#forward 127.0.0.1:19350; #forward 127.0.0.1:19350;
forward 127.0.0.1:1936; #forward 127.0.0.1:1936;
transcode { transcode {
enabled off; enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg; ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine dev { engine dev {
enabled on; enabled on;
vfilter { vfilter {
t 10;
} }
vcodec libx264; vcodec libx264;
vbitrate 300; vbitrate 300;

View file

@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h>
#include <algorithm> #include <algorithm>
@ -356,6 +357,34 @@ int SrsFFMPEG::start()
return ret; return ret;
} }
int SrsFFMPEG::cycle()
{
int ret = ERROR_SUCCESS;
if (!started) {
return ret;
}
int status = 0;
pid_t p = waitpid(pid, &status, WNOHANG);
if (p < 0) {
ret = ERROR_SYSTEM_WAITPID;
srs_error("transcode waitpid failed, pid=%d, ret=%d", pid, ret);
return ret;
}
if (p == 0) {
srs_info("transcode process pid=%d is running.", pid);
return ret;
}
srs_trace("transcode process pid=%d terminate, restart it.", pid);
started = false;
return ret;
}
void SrsFFMPEG::stop() void SrsFFMPEG::stop()
{ {
if (!started) { if (!started) {
@ -538,17 +567,22 @@ int SrsEncoder::cycle()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
// start all ffmpegs.
std::vector<SrsFFMPEG*>::iterator it; std::vector<SrsFFMPEG*>::iterator it;
for (it = ffmpegs.begin(); it != ffmpegs.end(); ++it) { for (it = ffmpegs.begin(); it != ffmpegs.end(); ++it) {
SrsFFMPEG* ffmpeg = *it; SrsFFMPEG* ffmpeg = *it;
// start all ffmpegs.
if ((ret = ffmpeg->start()) != ERROR_SUCCESS) { if ((ret = ffmpeg->start()) != ERROR_SUCCESS) {
srs_error("ffmpeg start failed. ret=%d", ret); srs_error("ffmpeg start failed. ret=%d", ret);
return ret; return ret;
} }
}
// TODO: cycle all processes. // check ffmpeg status.
if ((ret = ffmpeg->cycle()) != ERROR_SUCCESS) {
srs_error("ffmpeg cycle failed. ret=%d", ret);
return ret;
}
}
return ret; return ret;
} }

View file

@ -73,6 +73,7 @@ public:
public: public:
virtual int initialize(SrsRequest* req, SrsConfDirective* engine); virtual int initialize(SrsRequest* req, SrsConfDirective* engine);
virtual int start(); virtual int start();
virtual int cycle();
virtual void stop(); virtual void stop();
}; };

View file

@ -86,6 +86,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_SYSTEM_IP_INVALID 411 #define ERROR_SYSTEM_IP_INVALID 411
#define ERROR_SYSTEM_CONFIG_TOO_LARGE 412 #define ERROR_SYSTEM_CONFIG_TOO_LARGE 412
#define ERROR_SYSTEM_FORWARD_LOOP 413 #define ERROR_SYSTEM_FORWARD_LOOP 413
#define ERROR_SYSTEM_WAITPID 414
// see librtmp. // see librtmp.
// failed when open ssl create the dh // failed when open ssl create the dh

View file

@ -502,6 +502,7 @@ SrsM3u8Muxer::SrsM3u8Muxer()
video_stream_dts = 0; video_stream_dts = 0;
file_index = 0; file_index = 0;
current = NULL; current = NULL;
_is_open = false;
} }
SrsM3u8Muxer::~SrsM3u8Muxer() SrsM3u8Muxer::~SrsM3u8Muxer()
@ -516,6 +517,11 @@ SrsM3u8Muxer::~SrsM3u8Muxer()
srs_freep(current); srs_freep(current);
} }
bool SrsM3u8Muxer::is_open()
{
return _is_open;
}
int SrsM3u8Muxer::update_config( int SrsM3u8Muxer::update_config(
std::string _app, std::string _stream, std::string _app, std::string _stream,
std::string path, int fragment, int window std::string path, int fragment, int window
@ -571,6 +577,8 @@ int SrsM3u8Muxer::segment_open()
srs_info("open HLS muxer success. vhost=%s, path=%s", srs_info("open HLS muxer success. vhost=%s, path=%s",
vhost.c_str(), current->full_path.c_str()); vhost.c_str(), current->full_path.c_str());
_is_open = true;
return ret; return ret;
} }
@ -709,6 +717,8 @@ int SrsM3u8Muxer::segment_close()
return ret; return ret;
} }
_is_open = false;
return ret; return ret;
} }
@ -1171,12 +1181,14 @@ void SrsHls::on_unpublish()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
// close muxer when unpublish. if (muxer->is_open()) {
ret = ts_cache->flush_audio(muxer); // close muxer when unpublish.
ret += muxer->segment_close(); ret = ts_cache->flush_audio(muxer);
if (ret != ERROR_SUCCESS) { ret += muxer->segment_close();
srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret);
return; if (ret != ERROR_SUCCESS) {
srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret);
}
} }
hls_enabled = false; hls_enabled = false;

View file

@ -131,6 +131,7 @@ private:
int hls_fragment; int hls_fragment;
int hls_window; int hls_window;
private: private:
bool _is_open;
int file_index; int file_index;
std::string m3u8; std::string m3u8;
private: private:
@ -148,6 +149,7 @@ public:
SrsM3u8Muxer(); SrsM3u8Muxer();
virtual ~SrsM3u8Muxer(); virtual ~SrsM3u8Muxer();
public: public:
virtual bool is_open();
virtual int update_config(std::string _app, std::string _stream, std::string path, int fragment, int window); virtual int update_config(std::string _app, std::string _stream, std::string path, int fragment, int window);
virtual int segment_open(); virtual int segment_open();
virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab); virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab);