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

for #304, rewrite hls/ts code, support h.264+mp3 for hls. 2.0.117.

This commit is contained in:
winlin 2015-02-15 17:43:35 +08:00
parent 3c813847bd
commit 922150b2cf
8 changed files with 54 additions and 10 deletions

View file

@ -487,6 +487,8 @@ Supported operating systems and hardware:
[#301](https://github.com/winlinvip/simple-rtmp-server/issues/301). [#301](https://github.com/winlinvip/simple-rtmp-server/issues/301).
1. Support push MPEG-TS over UDP to SRS, read 1. Support push MPEG-TS over UDP to SRS, read
[#250](https://github.com/winlinvip/simple-rtmp-server/issues/250). [#250](https://github.com/winlinvip/simple-rtmp-server/issues/250).
1. Rewrite HLS(h.264+aac/mp3) streaming, read
[#304](https://github.com/winlinvip/simple-rtmp-server/issues/304).
1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech). 1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech).
1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92). 1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92).
1. [no-plan] Support multiple processes, for both origin and edge 1. [no-plan] Support multiple processes, for both origin and edge
@ -525,6 +527,7 @@ Supported operating systems and hardware:
### SRS 2.0 history ### SRS 2.0 history
* v2.0, 2015-02-15, for [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304), rewrite hls/ts code, support h.264+mp3 for hls. 2.0.117.
* v2.0, 2015-02-12, for [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304), use stringstream to generate m3u8, add hls_td_ratio. 2.0.116. * v2.0, 2015-02-12, for [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304), use stringstream to generate m3u8, add hls_td_ratio. 2.0.116.
* v2.0, 2015-02-11, dev code ZhouGuowen for 2.0.115. * v2.0, 2015-02-11, dev code ZhouGuowen for 2.0.115.
* v2.0, 2015-02-10, for [#311](https://github.com/winlinvip/simple-rtmp-server/issues/311), set pcr_base to dts. 2.0.114. * v2.0, 2015-02-10, for [#311](https://github.com/winlinvip/simple-rtmp-server/issues/311), set pcr_base to dts. 2.0.114.

View file

@ -492,6 +492,13 @@ vhost with-hls.srs.com {
# @remark the hls_mount must endswith .m3u8. # @remark the hls_mount must endswith .m3u8.
# default: [vhost]/[app]/[stream].m3u8 # default: [vhost]/[app]/[stream].m3u8
hls_mount [vhost]/[app]/[stream].m3u8; hls_mount [vhost]/[app]/[stream].m3u8;
# the default audio codec of hls.
# when codec changed, write the PAT/PMT table, but maybe ok util next ts.
# so user can set the default codec for mp3.
# the available audio codec: aac, mp3
# default: aac
# TODO: FIXME: update wiki for it.
hls_acodec aac;
} }
} }
# the vhost with hls disabled. # the vhost with hls disabled.

View file

@ -1480,7 +1480,7 @@ int SrsConfig::check_config()
for (int j = 0; j < (int)conf->directives.size(); j++) { for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str(); string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error"
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_acodec"
) { ) {
ret = ERROR_SYSTEM_CONFIG_INVALID; ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
@ -3332,6 +3332,23 @@ string SrsConfig::get_hls_mount(string vhost)
return conf->arg0(); return conf->arg0();
} }
string SrsConfig::get_hls_acodec(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return SRS_CONF_DEFAULT_HLS_ACODEC;
}
SrsConfDirective* conf = hls->get("hls_acodec");
if (!conf) {
return SRS_CONF_DEFAULT_HLS_ACODEC;
}
return conf->arg0();
}
SrsConfDirective* SrsConfig::get_dvr(string vhost) SrsConfDirective* SrsConfig::get_dvr(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);

View file

@ -55,6 +55,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CONF_DEFAULT_HLS_ON_ERROR SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE #define SRS_CONF_DEFAULT_HLS_ON_ERROR SRS_CONF_DEFAULT_HLS_ON_ERROR_IGNORE
#define SRS_CONF_DEFAULT_HLS_STORAGE "disk" #define SRS_CONF_DEFAULT_HLS_STORAGE "disk"
#define SRS_CONF_DEFAULT_HLS_MOUNT "[vhost]/[app]/[stream].m3u8" #define SRS_CONF_DEFAULT_HLS_MOUNT "[vhost]/[app]/[stream].m3u8"
#define SRS_CONF_DEFAULT_HLS_ACODEC "aac"
#define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html" #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html"
#define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session"
#define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment"
@ -922,6 +923,10 @@ public:
* get the HLS mount url for HTTP server. * get the HLS mount url for HTTP server.
*/ */
virtual std::string get_hls_mount(std::string vhost); virtual std::string get_hls_mount(std::string vhost);
/**
* get the HLS default audio codec.
*/
virtual std::string get_hls_acodec(std::string vhost);
// dvr section // dvr section
private: private:
/** /**

View file

@ -131,14 +131,14 @@ string SrsHlsCacheWriter::cache()
return data; return data;
} }
SrsHlsSegment::SrsHlsSegment(bool write_cache, bool write_file) SrsHlsSegment::SrsHlsSegment(bool write_cache, bool write_file, SrsCodecAudio ac)
{ {
duration = 0; duration = 0;
sequence_no = 0; sequence_no = 0;
segment_start_dts = 0; segment_start_dts = 0;
is_sequence_header = false; is_sequence_header = false;
writer = new SrsHlsCacheWriter(write_cache, write_file); writer = new SrsHlsCacheWriter(write_cache, write_file);
muxer = new SrsTSMuxer(writer); muxer = new SrsTSMuxer(writer, ac);
} }
SrsHlsSegment::~SrsHlsSegment() SrsHlsSegment::~SrsHlsSegment()
@ -243,9 +243,22 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
// when segment open, the current segment must be NULL. // when segment open, the current segment must be NULL.
srs_assert(!current); srs_assert(!current);
// load the default acodec from config.
SrsCodecAudio default_acodec = SrsCodecAudioAAC;
std::string default_acodec_str = _srs_config->get_hls_acodec(req->vhost);
if (default_acodec_str == "mp3") {
default_acodec = SrsCodecAudioMP3;
srs_info("hls: use default mp3 acodec");
} else if (default_acodec_str == "aac") {
default_acodec = SrsCodecAudioAAC;
srs_info("hls: use default aac acodec");
} else {
srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str());
}
// new segment. // new segment.
current = new SrsHlsSegment(should_write_cache, should_write_file); current = new SrsHlsSegment(should_write_cache, should_write_file, default_acodec);
current->sequence_no = _sequence_no++; current->sequence_no = _sequence_no++;
current->segment_start_dts = segment_start_dts; current->segment_start_dts = segment_start_dts;

View file

@ -144,7 +144,7 @@ public:
// whether current segement is sequence header. // whether current segement is sequence header.
bool is_sequence_header; bool is_sequence_header;
public: public:
SrsHlsSegment(bool write_cache, bool write_file); SrsHlsSegment(bool write_cache, bool write_file, SrsCodecAudio ac);
virtual ~SrsHlsSegment(); virtual ~SrsHlsSegment();
public: public:
/** /**

View file

@ -2916,13 +2916,12 @@ int SrsTsPayloadPMT::psi_encode(SrsStream* stream)
return ret; return ret;
} }
SrsTSMuxer::SrsTSMuxer(SrsFileWriter* w) SrsTSMuxer::SrsTSMuxer(SrsFileWriter* w, SrsCodecAudio ac)
{ {
writer = w; writer = w;
context = NULL; context = NULL;
// default to aac. acodec = ac;
acodec = SrsCodecAudioAAC;
// default to avc(h.264) // default to avc(h.264)
vcodec = SrsCodecVideoAVC; vcodec = SrsCodecVideoAVC;
} }
@ -3296,7 +3295,7 @@ int SrsTsEncoder::initialize(SrsFileWriter* fs)
_fs = fs; _fs = fs;
srs_freep(muxer); srs_freep(muxer);
muxer = new SrsTSMuxer(fs); muxer = new SrsTSMuxer(fs, SrsCodecAudioAAC);
if ((ret = muxer->open("")) != ERROR_SUCCESS) { if ((ret = muxer->open("")) != ERROR_SUCCESS) {
return ret; return ret;

View file

@ -1547,7 +1547,7 @@ private:
SrsFileWriter* writer; SrsFileWriter* writer;
std::string path; std::string path;
public: public:
SrsTSMuxer(SrsFileWriter* w); SrsTSMuxer(SrsFileWriter* w, SrsCodecAudio ac);
virtual ~SrsTSMuxer(); virtual ~SrsTSMuxer();
public: public:
/** /**