winlin

update demo, support acodec

... ... @@ -180,9 +180,32 @@ vhost players_pub {
}
}
vhost players_pub_rtmp {
vhost players_chat {
gop_cache off;
hls {
enabled off;
}
transcode {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine chat_hls {
enabled on;
vcodec copy;
acodec libaacplus;
abitrate 30;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=players_pub/[stream];
}
}
}
vhost chat_hls {
hls {
enabled on;
hls_path ./objs/nginx/html;
hls_fragment 2;
hls_window 8;
}
}
... ...
... ... @@ -2,6 +2,9 @@
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// to query the swf anti cache.
function srs_get_version_code() { return "1.20"; }
/**
* player specified size.
*/
... ... @@ -9,8 +12,6 @@ function srs_get_player_modal() { return 740; }
function srs_get_player_width() { return srs_get_player_modal() - 30; }
function srs_get_player_height() { return srs_get_player_width() * 9 / 19; }
// to query the swf anti cache.
function srs_get_version_code() { return "1.19"; }
// get the default vhost for players.
function srs_get_player_vhost() { return "players"; }
// the api server port, for chat room.
... ... @@ -23,7 +24,7 @@ function srs_get_srs_http_server_port() { return 8080; }
// if not equals to the player vhost, return the orignal vhost.
function srs_get_player_publish_vhost(src_vhost) { return (src_vhost != srs_get_player_vhost())? src_vhost:(src_vhost + "_pub"); }
// for chat, use rtmp only vhost, low latecy, without gop cache.
function srs_get_player_chat_vhost(src_vhost) { return (src_vhost != srs_get_player_vhost())? src_vhost:(src_vhost + "_pub_rtmp"); }
function srs_get_player_chat_vhost(src_vhost) { return (src_vhost != srs_get_player_vhost())? src_vhost:(src_vhost + "_chat"); }
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
... ... @@ -181,7 +182,8 @@ function srs_can_republish() {
// without default values set.
function srs_initialize_codec_page(
cameras, microphones,
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate,
sl_acodec
) {
$(sl_cameras).empty();
for (var i = 0; i < cameras.length; i++) {
... ... @@ -292,17 +294,25 @@ function srs_initialize_codec_page(
for (i = 0; i < bitrates.length; i++) {
$(sl_bitrate).append("<option value='" + bitrates[i] + "'>" + bitrates[i] + " kbps</option");
}
$(sl_acodec).empty();
var bitrates = ["speex", "nellymoser", "pcma", "pcmu"];
for (i = 0; i < bitrates.length; i++) {
$(sl_acodec).append("<option value='" + bitrates[i] + "'>" + bitrates[i] + "</option");
}
}
/**
* when publisher ready, init the page elements.
*/
function srs_publisher_initialize_page(
cameras, microphones,
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate,
sl_acodec
) {
srs_initialize_codec_page(
cameras, microphones,
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate,
sl_acodec
);
//var profiles = ["baseline", "main"];
... ... @@ -327,17 +337,22 @@ function srs_publisher_initialize_page(
//var bitrates = ["50", "200", "350", "500", "650", "800",
// "950", "1000", "1200", "1500", "1800", "2000", "3000", "5000"];
$(sl_bitrate + " option[value='500']").attr("selected", true);
// speex
$(sl_acodec + " option[value='speex']").attr("selected", true);
}
/**
* for chat, use low latecy settings.
*/
function srs_chat_initialize_page(
cameras, microphones,
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate,
sl_acodec
) {
srs_initialize_codec_page(
cameras, microphones,
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate,
sl_acodec
);
//var profiles = ["baseline", "main"];
... ... @@ -362,14 +377,19 @@ function srs_chat_initialize_page(
//var bitrates = ["50", "200", "350", "500", "650", "800",
// "950", "1000", "1200", "1500", "1800", "2000", "3000", "5000"];
$(sl_bitrate + " option[value='350']").attr("selected", true);
// speex
$(sl_acodec + " option[value='speex']").attr("selected", true);
}
/**
* get the vcodec and acodec.
*/
function srs_publiser_get_codec(
vcodec, acodec,
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate
sl_cameras, sl_microphones, sl_vcodec, sl_profile, sl_level, sl_gop, sl_size, sl_fps, sl_bitrate,
sl_acodec
) {
acodec.codec = $(sl_acodec).val();
acodec.device_code = $(sl_microphones).val();
acodec.device_name = $(sl_microphones).text();
... ...
... ... @@ -82,7 +82,8 @@
cameras, microphones,
"#sl_cameras", "#sl_microphones",
"#sl_vcodec", "#sl_profile", "#sl_level", "#sl_gop", "#sl_size",
"#sl_fps", "#sl_bitrate"
"#sl_fps", "#sl_bitrate",
"#sl_acodec"
);
};
srs_publisher.on_publisher_error = function(code, desc) {
... ... @@ -490,7 +491,8 @@
vcodec, acodec,
"#sl_cameras", "#sl_microphones",
"#sl_vcodec", "#sl_profile", "#sl_level", "#sl_gop", "#sl_size",
"#sl_fps", "#sl_bitrate"
"#sl_fps", "#sl_bitrate",
"#sl_acodec"
);
var chat = {};
... ... @@ -760,6 +762,17 @@
<select class="span4" id="sl_microphones"></select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="sl_acodec">
编码
<a id="sl_acodec_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
<img src="img/tooltip.png"/>
</a>
</label>
<div class="controls">
<select class="span2" id="sl_acodec"></select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
... ...
... ... @@ -67,7 +67,8 @@
cameras, microphones,
"#sl_cameras", "#sl_microphones",
"#sl_vcodec", "#sl_profile", "#sl_level", "#sl_gop", "#sl_size",
"#sl_fps", "#sl_bitrate"
"#sl_fps", "#sl_bitrate",
"#sl_acodec"
);
};
srs_publisher.on_publisher_error = function(code, desc) {
... ... @@ -184,7 +185,8 @@
vcodec, acodec,
"#sl_cameras", "#sl_microphones",
"#sl_vcodec", "#sl_profile", "#sl_level", "#sl_gop", "#sl_size",
"#sl_fps", "#sl_bitrate"
"#sl_fps", "#sl_bitrate",
"#sl_acodec"
);
info("开始推流到服务器");
... ... @@ -376,6 +378,17 @@
<select class="span4" id="sl_microphones"></select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="sl_acodec">
编码
<a id="sl_acodec_tips" href="#" data-toggle="tooltip" data-placement="right" title="">
<img src="img/tooltip.png"/>
</a>
</label>
<div class="controls">
<select class="span2" id="sl_acodec"></select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
... ...
... ... @@ -273,7 +273,7 @@ package
var microRate:int = 22; // 22 === 22050 Hz
trace("[Publish] audio encoding parameters: "
+ "audio(microphone) encodeQuality=" + microEncodeQuality
+ "audio(microphone) codec=" + acodec.codec + "encodeQuality=" + microEncodeQuality
+ ", rate=" + microRate + "(22050Hz)"
);
... ... @@ -288,7 +288,15 @@ package
m.rate = microRate;
// see: http://www.adobe.com/cn/devnet/flashplayer/articles/acoustic-echo-cancellation.html
m.codec = SoundCodec.SPEEX;
if (acodec.codec == "nellymoser") {
m.codec = SoundCodec.NELLYMOSER;
} else if (acodec.codec == "pcma") {
m.codec = SoundCodec.PCMA;
} else if (acodec.codec == "pcmu") {
m.codec = SoundCodec.PCMU;
} else {
m.codec = SoundCodec.SPEEX;
}
m.framesPerPacket = 1;
}
private function __build_video_codec(stream:NetStream, c:Camera, vcodec:Object):void {
... ...
... ... @@ -189,7 +189,7 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample)
// only support aac
if (audio_codec_id != SrsCodecAudioAAC) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("hls only support audio aac codec. ret=%d", ret);
srs_error("hls only support audio aac codec. actual=%d, ret=%d", audio_codec_id, ret);
return ret;
}
... ... @@ -299,7 +299,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample)
// only support h.264/avc
if (codec_id != SrsCodecVideoAVC) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("hls only support video h.264/avc codec. ret=%d", ret);
srs_error("hls only support video h.264/avc codec. actual=%d, ret=%d", codec_id, ret);
return ret;
}
video_codec_id = codec_id;
... ...
... ... @@ -289,7 +289,7 @@ int SrsRtmpConn::stream_service_cycle()
}
bool enabled_cache = _srs_config->get_gop_cache(req->vhost);
srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
srs_trace("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
source->set_cache(enabled_cache);
switch (type) {
... ...
... ... @@ -418,7 +418,7 @@ SrsSource* SrsSource::find(SrsRequest* req)
if (pool.find(stream_url) == pool.end()) {
pool[stream_url] = new SrsSource(req);
srs_verbose("create new source for url=%s, vhost=%s", stream_url.c_str(), vhost.c_str());
srs_info("create new source for url=%s, vhost=%s", stream_url.c_str(), vhost.c_str());
}
return pool[stream_url];
... ...