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

fix #145, refine ffmpeg log, check abitrate for libaacplus. 0.9.186.

This commit is contained in:
winlin 2014-08-03 13:06:37 +08:00
parent d5ba529d32
commit 5a95d594e7
3 changed files with 44 additions and 22 deletions

View file

@ -207,7 +207,8 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/> * 2013-10-17, Created.<br/>
## History ## History
* v1.0, 2014-08-02, fix [#143](https://github.com/winlinvip/simple-rtmp-server/issues/143), fix retrieve sys stat bug for all linux. 0.9.185. * v1.0, 2014-08-03, fix [#145](https://github.com/winlinvip/simple-rtmp-server/issues/145), refine ffmpeg log, check abitrate for libaacplus. 0.9.186.
* v1.0, 2014-08-03, fix [#143](https://github.com/winlinvip/simple-rtmp-server/issues/143), fix retrieve sys stat bug for all linux. 0.9.185.
* v1.0, 2014-08-02, fix [#138](https://github.com/winlinvip/simple-rtmp-server/issues/138), fix http hooks bug, regression bug. 0.9.184. * v1.0, 2014-08-02, fix [#138](https://github.com/winlinvip/simple-rtmp-server/issues/138), fix http hooks bug, regression bug. 0.9.184.
* v1.0, 2014-08-02, fix [#142](https://github.com/winlinvip/simple-rtmp-server/issues/142), fix tcp stat slow bug, use /proc/net/sockstat instead, refer to 'ss -s'. 0.9.183. * v1.0, 2014-08-02, fix [#142](https://github.com/winlinvip/simple-rtmp-server/issues/142), fix tcp stat slow bug, use /proc/net/sockstat instead, refer to 'ss -s'. 0.9.183.
* v1.0, 2014-07-31, fix [#141](https://github.com/winlinvip/simple-rtmp-server/issues/141), support tun0(vpn network device) ip retrieve. 0.9.179. * v1.0, 2014-07-31, fix [#141](https://github.com/winlinvip/simple-rtmp-server/issues/141), support tun0(vpn network device) ip retrieve. 0.9.179.

View file

@ -41,14 +41,15 @@ using namespace std;
#ifdef SRS_AUTO_FFMPEG #ifdef SRS_AUTO_FFMPEG
#define SRS_RTMP_ENCODER_COPY "copy" #define SRS_RTMP_ENCODER_COPY "copy"
#define SRS_RTMP_ENCODER_NO_VIDEO "vn" #define SRS_RTMP_ENCODER_NO_VIDEO "vn"
#define SRS_RTMP_ENCODER_NO_AUDIO "an" #define SRS_RTMP_ENCODER_NO_AUDIO "an"
// only support libx264 encoder. // only support libx264 encoder.
#define SRS_RTMP_ENCODER_VCODEC "libx264" #define SRS_RTMP_ENCODER_VCODEC "libx264"
// any aac encoder is ok which contains the aac, // any aac encoder is ok which contains the aac,
// for example, libaacplus, aac, fdkaac // for example, libaacplus, aac, fdkaac
#define SRS_RTMP_ENCODER_ACODEC "aac" #define SRS_RTMP_ENCODER_ACODEC "aac"
#define SRS_RTMP_ENCODER_LIBAACPLUS "libaacplus"
SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin) SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin)
{ {
@ -173,6 +174,15 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
} }
} }
// @see, https://github.com/winlinvip/simple-rtmp-server/issues/145
if (acodec == SRS_RTMP_ENCODER_LIBAACPLUS) {
if (abitrate < 16 || abitrate > 72) {
ret = ERROR_ENCODER_ABITRATE;
srs_error("invalid abitrate for aac: %d, must in [16, 72], ret=%d", abitrate, ret);
return ret;
}
}
if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) { if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) {
if (acodec.find(SRS_RTMP_ENCODER_ACODEC) == std::string::npos) { if (acodec.find(SRS_RTMP_ENCODER_ACODEC) == std::string::npos) {
ret = ERROR_ENCODER_ACODEC; ret = ERROR_ENCODER_ACODEC;
@ -182,20 +192,17 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
} }
if (abitrate <= 0) { if (abitrate <= 0) {
ret = ERROR_ENCODER_ABITRATE; ret = ERROR_ENCODER_ABITRATE;
srs_error("invalid abitrate: %d, ret=%d", srs_error("invalid abitrate: %d, ret=%d", abitrate, ret);
abitrate, ret);
return ret; return ret;
} }
if (asample_rate <= 0) { if (asample_rate <= 0) {
ret = ERROR_ENCODER_ASAMPLE_RATE; ret = ERROR_ENCODER_ASAMPLE_RATE;
srs_error("invalid sample rate: %d, ret=%d", srs_error("invalid sample rate: %d, ret=%d", asample_rate, ret);
asample_rate, ret);
return ret; return ret;
} }
if (achannels != 1 && achannels != 2) { if (achannels != 1 && achannels != 2) {
ret = ERROR_ENCODER_ACHANNELS; ret = ERROR_ENCODER_ACHANNELS;
srs_error("invalid achannels, must be 1 or 2, actual %d, ret=%d", srs_error("invalid achannels, must be 1 or 2, actual %d, ret=%d", achannels, ret);
achannels, ret);
return ret; return ret;
} }
} }
@ -359,21 +366,21 @@ int SrsFFMPEG::start()
params.push_back("-y"); params.push_back("-y");
params.push_back(_output); params.push_back(_output);
std::string cli;
if (true) { if (true) {
int pparam_size = 8 * 1024;
char* pparam = new char[pparam_size];
char* p = pparam;
char* last = pparam + pparam_size;
for (int i = 0; i < (int)params.size(); i++) { for (int i = 0; i < (int)params.size(); i++) {
std::string ffp = params[i]; std::string ffp = params[i];
snprintf(p, last - p, "%s ", ffp.c_str()); cli += ffp;
p += ffp.length() + 1; if (i < (int)params.size() - 1) {
cli += " ";
}
} }
srs_trace("start transcoder, log: %s, params: %s", srs_trace("start ffmpeg, log: %s, params: %s", log_file.c_str(), cli.c_str());
log_file.c_str(), pparam);
srs_freep(pparam);
} }
// for log
int cid = _srs_context->get_id();
// TODO: fork or vfork? // TODO: fork or vfork?
if ((pid = fork()) < 0) { if ((pid = fork()) < 0) {
ret = ERROR_ENCODER_FORK; ret = ERROR_ENCODER_FORK;
@ -392,6 +399,19 @@ int SrsFFMPEG::start()
srs_error("open encoder file %s failed. ret=%d", log_file.c_str(), ret); srs_error("open encoder file %s failed. ret=%d", log_file.c_str(), ret);
return ret; return ret;
} }
// log basic info
if (true) {
char buf[4096];
int pos = 0;
pos += snprintf(buf + pos, sizeof(buf) - pos, "\n");
pos += snprintf(buf + pos, sizeof(buf) - pos, "ffmpeg cid=%d\n", cid);
pos += snprintf(buf + pos, sizeof(buf) - pos, "log=%s\n", log_file.c_str());
pos += snprintf(buf + pos, sizeof(buf) - pos, "params: %s\n", cli.c_str());
::write(log_fd, buf, pos);
}
// dup to stdout and stderr.
if (dup2(log_fd, STDOUT_FILENO) < 0) { if (dup2(log_fd, STDOUT_FILENO) < 0) {
ret = ERROR_ENCODER_DUP2; ret = ERROR_ENCODER_DUP2;
srs_error("dup2 encoder file failed. ret=%d", ret); srs_error("dup2 encoder file failed. ret=%d", ret);
@ -402,6 +422,7 @@ int SrsFFMPEG::start()
srs_error("dup2 encoder file failed. ret=%d", ret); srs_error("dup2 encoder file failed. ret=%d", ret);
return ret; return ret;
} }
// close log fd // close log fd
::close(log_fd); ::close(log_fd);
// close other fds // close other fds

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR "0" #define VERSION_MAJOR "0"
#define VERSION_MINOR "9" #define VERSION_MINOR "9"
#define VERSION_REVISION "185" #define VERSION_REVISION "186"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info. // server info.
#define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_KEY "SRS"