mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #304, support config default acodec/vcodec. 2.0.118.
This commit is contained in:
parent
922150b2cf
commit
78f34ad46f
10 changed files with 114 additions and 381 deletions
|
@ -1480,7 +1480,7 @@ int SrsConfig::check_config()
|
|||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
string m = conf->at(j)->name.c_str();
|
||||
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_acodec"
|
||||
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_acodec" && m != "hls_vcodec"
|
||||
) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
|
||||
|
@ -3349,6 +3349,23 @@ string SrsConfig::get_hls_acodec(string vhost)
|
|||
return conf->arg0();
|
||||
}
|
||||
|
||||
string SrsConfig::get_hls_vcodec(string vhost)
|
||||
{
|
||||
SrsConfDirective* hls = get_hls(vhost);
|
||||
|
||||
if (!hls) {
|
||||
return SRS_CONF_DEFAULT_HLS_VCODEC;
|
||||
}
|
||||
|
||||
SrsConfDirective* conf = hls->get("hls_vcodec");
|
||||
|
||||
if (!conf) {
|
||||
return SRS_CONF_DEFAULT_HLS_VCODEC;
|
||||
}
|
||||
|
||||
return conf->arg0();
|
||||
}
|
||||
|
||||
SrsConfDirective* SrsConfig::get_dvr(string vhost)
|
||||
{
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
|
|
|
@ -56,6 +56,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define SRS_CONF_DEFAULT_HLS_STORAGE "disk"
|
||||
#define SRS_CONF_DEFAULT_HLS_MOUNT "[vhost]/[app]/[stream].m3u8"
|
||||
#define SRS_CONF_DEFAULT_HLS_ACODEC "aac"
|
||||
#define SRS_CONF_DEFAULT_HLS_VCODEC "h264"
|
||||
#define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html"
|
||||
#define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session"
|
||||
#define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment"
|
||||
|
@ -927,6 +928,10 @@ public:
|
|||
* get the HLS default audio codec.
|
||||
*/
|
||||
virtual std::string get_hls_acodec(std::string vhost);
|
||||
/**
|
||||
* get the HLS default video codec.
|
||||
*/
|
||||
virtual std::string get_hls_vcodec(std::string vhost);
|
||||
// dvr section
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -131,14 +131,14 @@ string SrsHlsCacheWriter::cache()
|
|||
return data;
|
||||
}
|
||||
|
||||
SrsHlsSegment::SrsHlsSegment(bool write_cache, bool write_file, SrsCodecAudio ac)
|
||||
SrsHlsSegment::SrsHlsSegment(bool write_cache, bool write_file, SrsCodecAudio ac, SrsCodecVideo vc)
|
||||
{
|
||||
duration = 0;
|
||||
sequence_no = 0;
|
||||
segment_start_dts = 0;
|
||||
is_sequence_header = false;
|
||||
writer = new SrsHlsCacheWriter(write_cache, write_file);
|
||||
muxer = new SrsTSMuxer(writer, ac);
|
||||
muxer = new SrsTSMuxer(writer, ac, vc);
|
||||
}
|
||||
|
||||
SrsHlsSegment::~SrsHlsSegment()
|
||||
|
@ -246,19 +246,36 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
|
|||
|
||||
// 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());
|
||||
if (true) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
// load the default vcodec from config.
|
||||
SrsCodecVideo default_vcodec = SrsCodecVideoAVC;
|
||||
if (true) {
|
||||
std::string default_vcodec_str = _srs_config->get_hls_vcodec(req->vhost);
|
||||
if (default_vcodec_str == "h264") {
|
||||
default_vcodec = SrsCodecVideoAVC;
|
||||
srs_info("hls: use default h264 vcodec");
|
||||
} else if (default_vcodec_str == "vn") {
|
||||
default_vcodec = SrsCodecVideoDisabled;
|
||||
srs_info("hls: use default vn vcodec for pure audio");
|
||||
} else {
|
||||
srs_warn("hls: use h264 for other codec=%s", default_vcodec_str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// new segment.
|
||||
current = new SrsHlsSegment(should_write_cache, should_write_file, default_acodec);
|
||||
current = new SrsHlsSegment(should_write_cache, should_write_file, default_acodec, default_vcodec);
|
||||
current->sequence_no = _sequence_no++;
|
||||
current->segment_start_dts = segment_start_dts;
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ public:
|
|||
// whether current segement is sequence header.
|
||||
bool is_sequence_header;
|
||||
public:
|
||||
SrsHlsSegment(bool write_cache, bool write_file, SrsCodecAudio ac);
|
||||
SrsHlsSegment(bool write_cache, bool write_file, SrsCodecAudio ac, SrsCodecVideo vc);
|
||||
virtual ~SrsHlsSegment();
|
||||
public:
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue