Skip to content

Commit

Permalink
for #304, support config default acodec/vcodec. 2.0.118.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 15, 2015
1 parent 922150b commit 78f34ad
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 381 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ Supported operating systems and hardware:

### SRS 2.0 history

* v2.0, 2015-02-15, for [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304), support config default acodec/vcodec. 2.0.118.
* 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-11, dev code ZhouGuowen for 2.0.115.
Expand Down
46 changes: 28 additions & 18 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,19 @@ vhost with-hls.srs.com {
# 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
# the available audio codec:
# aac, mp3
# default: aac
# TODO: FIXME: update wiki for it.
hls_acodec aac;
# the default video 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 pure audio(without video) to vn.
# the available video codec:
# h264, vn
# default: h264
# TODO: FIXME: update wiki for it.
hls_vcodec h264;
}
}
# the vhost with hls disabled.
Expand Down Expand Up @@ -713,9 +722,9 @@ vhost example.transcode.srs.com {
filter_complex 'overlay=10:10';
}
# video encoder name. can be:
# libx264: use h.264(libx264) video encoder.
# copy: donot encoder the video stream, copy it.
# vn: disable video output.
# libx264: use h.264(libx264) video encoder.
# copy: donot encoder the video stream, copy it.
# vn: disable video output.
vcodec libx264;
# video bitrate, in kbps
vbitrate 1500;
Expand All @@ -731,8 +740,8 @@ vhost example.transcode.srs.com {
# high,main,baseline
vprofile main;
# x264 preset, @see x264 -help, can be:
# ultrafast,superfast,veryfast,faster,fast
# medium,slow,slower,veryslow,placebo
# ultrafast,superfast,veryfast,faster,fast
# medium,slow,slower,veryslow,placebo
vpreset medium;
# other x264 or ffmpeg video params
vparams {
Expand All @@ -745,14 +754,15 @@ vhost example.transcode.srs.com {
refs 10;
}
# audio encoder name. can be:
# libaacplus: use aac(libaacplus) audio encoder.
# copy: donot encoder the audio stream, copy it.
# an: disable audio output.
# libaacplus: use aac(libaacplus) audio encoder.
# libfdk_aac: use aac(libfdk_aac) audio encoder.
# copy: donot encoder the audio stream, copy it.
# an: disable audio output.
acodec libaacplus;
# audio bitrate, in kbps. [16, 72] for libaacplus.
abitrate 70;
# audio sample rate. for flv/rtmp, it must be:
# 44100,22050,11025,5512
# 44100,22050,11025,5512
asample_rate 44100;
# audio channel, 1 for mono, 2 for stereo.
achannels 2;
Expand All @@ -762,17 +772,17 @@ vhost example.transcode.srs.com {
profile:a aac_low;
}
# output format, can be:
# off, do not specifies the format, ffmpeg will guess it.
# flv, for flv or RTMP stream.
# other format, for example, mp4/aac whatever.
# off, do not specifies the format, ffmpeg will guess it.
# flv, for flv or RTMP stream.
# other format, for example, mp4/aac whatever.
# default: flv
oformat flv;
# output stream. variables:
# [vhost] the input stream vhost.
# [port] the intput stream port.
# [app] the input stream app.
# [stream] the input stream name.
# [engine] the tanscode engine name.
# [vhost] the input stream vhost.
# [port] the intput stream port.
# [app] the input stream app.
# [stream] the input stream name.
# [engine] the tanscode engine name.
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
Expand Down
19 changes: 18 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -927,6 +928,10 @@ class SrsConfig
* 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:
/**
Expand Down
41 changes: 29 additions & 12 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class SrsHlsSegment
// 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:
/**
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 117
#define VERSION_REVISION 118

// server info.
#define RTMP_SIG_SRS_KEY "SRS"
Expand Down
5 changes: 4 additions & 1 deletion trunk/src/kernel/srs_kernel_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ enum SrsCodecVideo
// set to the zero to reserved, for array map.
SrsCodecVideoReserved = 0,
SrsCodecVideoReserved1 = 1,
SrsCodecVideoReserved2 = 8,
SrsCodecVideoReserved2 = 9,

// for user to disable video, for example, use pure audio hls.
SrsCodecVideoDisabled = 8,

SrsCodecVideoSorensonH263 = 2,
SrsCodecVideoScreenVideo = 3,
Expand Down
Loading

0 comments on commit 78f34ad

Please sign in to comment.