# default: off
enabled on;
# the caster type of stream, the casters:
# rtsp, Real Time Streaming Protocol (RTSP).
caster rtsp;
# the output rtmp url.
# for rtsp caster, the typically output url:
# rtmp://127.0.0.1/[app]/[stream]
# for example, the rtsp url:
# rtsp://192.168.1.173:8544/live/livestream.sdp
# where the [app] is "live" and [stream] is "livestream", output is:
# rtmp://127.0.0.1/live/livestream
output rtmp://127.0.0.1:1936/[app]/[stream];
# the listen port for stream caster.
# for rtsp caster, listen at tcp port. for example, 554.
listen 1554;
# for the rtsp caster, the rtp server local port over udp,
# which reply the rtsp setup request message, the port will be used:
# [rtp_port_min, rtp_port_max)
rtp_port_min 57200;
rtp_port_max 57300;
}
rtc_server {
enabled on;
Listen at udp://8000
listen 8000;
#
# The $CANDIDATE means fetch from env, if not configed, use * as default.
#
# The * means retrieving server IP automatically, from all network interfaces,
# @see https://github.com/ossrs/srs/issues/307#issuecomment-599028124
candidate $CANDIDATE;
**Replay**
**How to replay bug?**
> Steps to reproduce the bug
1. ffmpeg -re -i D:\code\ffmpegabout\ffmpeg4.2\ffmpeg-20200223-90913ab-win32-static\bin\123.mp4 -vcodec libx264 -bf 0 -x264-params keyint=120 -acodec aac -ac 2 -ar 48000 -f flv rtmp://192.168.1.165:1935/live/669E0DB78AC84B86B031E587FB330C2B
2. 1. ffmpeg -re -i D:\code\ffmpegabout\ffmpeg4.2\ffmpeg-20200223-90913ab-win32-static\bin\123.mp4 -vcodec libx264 -bf 0 -x264-params keyint=120 -acodec aac -ac 1 -ar 48000 -f flv rtmp://192.168.1.165:1935/live/669E0DB78AC84B86B031E587FB330C2B
**Audio playback is normal when using 2 WebRTC streams for pushing, but there is noise when using 1 WebRTC stream for pushing.**
**The repair process is as follows: it is necessary to determine whether the decoded audio data is in plane format. Based on this situation, copy the left and right channel data to contiguous memory space. When resampling, the left and right channel data should also be organized according to this rule. The processing process of the completed PCM data is the same as above.**
git diff 4bb3ad5637b5541df515fa9a9d69143310397c60
diff --git a/trunk/src/app/srs_app_rtc_codec.cpp b/trunk/src/app/srs_app_rtc_codec.cpp
index b3db983..ceb3837 100644
--- a/trunk/src/app/srs_app_rtc_codec.cpp
+++ b/trunk/src/app/srs_app_rtc_codec.cpp
@@ -129,13 +129,24 @@ srs_error_t SrsAudioDecoder::decode(SrsSample pkt, char buf, int &size)
if (pcm_size < 0) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "Failed to calculate data size");
}
for (int i = 0; i < frame_->nb_samples; i++) {
if (size + pcm_size * codecctx->channels <= max) {
memcpy(buf + size,frame_->data[0] + pcm_sizecodecctx->channels i, pcm_size * codecctx->channels);
Description'
Please ensure that the markdown structure is maintained.
4.0.62
http_server { enabled on; listen 8088; dir html; }
http_api { enabled on; listen 1985; } stats { network 0; }
RTSP
stream_caster {
whether stream caster is enabled.
}
rtc_server { enabled on;
Listen at udp://8000
}
vhost defaultVhost { gop_cache off; queue_length 10; min_latency on; mr { enabled off; } mw_latency 100; tcp_nodelay on; rtc { enabled on; bframe discard; } http_remux { enabled on; mount [vhost]/[app]/[stream].flv; hstrs on; } }
git diff 4bb3ad5637b5541df515fa9a9d69143310397c60 diff --git a/trunk/src/app/srs_app_rtc_codec.cpp b/trunk/src/app/srs_app_rtc_codec.cpp index b3db983..ceb3837 100644 --- a/trunk/src/app/srs_app_rtc_codec.cpp +++ b/trunk/src/app/srs_app_rtc_codec.cpp @@ -129,13 +129,24 @@ srs_error_t SrsAudioDecoder::decode(SrsSample pkt, char buf, int &size) if (pcm_size < 0) { return srs_error_new(ERROR_RTC_RTP_MUXER, "Failed to calculate data size"); }
} }
return err;
@@ -368,7 +381,21 @@ srs_error_t SrsAudioResample::resample(SrsSample pcm, char buf, int &size) if (srclinesize * plane < pcm->size || pcm->size < 0) { return srs_error_new(ERROR_RTC_RTP_MUXER, "size not ok"); }
memcpy(srcdata[0], pcm->bytes, pcm->size);
bool bsrcplane = av_sample_fmt_is_planar(src_samplefmt);
if (bsrcplane){
int offset = 0;
int src_pcm_size = av_get_bytes_per_sample(src_samplefmt);
for (int i = 0; i < src_nbsamples; i++) {
for (int channel=0;channel< src_nbchannels; channel++){
memcpy(srcdata[channel] + i * src_pcm_size, pcm->bytes + offset, src_pcm_size);
offset += src_pcm_size;
}
}
}
else{
memcpy(srcdata[0], pcm->bytes, pcm->size);
}
dst_nbsamples = av_rescale_rnd(swr_get_delay(swrctx, srcrate) + src_nbsamples, dstrate, srcrate, AV_ROUND_UP); @@ -389,16 +416,35 @@ srs_error_t SrsAudioResample::resample(SrsSample pcm, char buf, int &size)
int dst_bufsize = av_samples_get_buffer_size(&dstlinesize, dst_nbchannels, ret, dst_samplefmt, 1);
if (dst_bufsize < 0) { return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not get sample buffer size"); }
int max = size;
size = 0;
if (max >= dst_bufsize) {
memcpy(buf, dstdata[0], dst_bufsize);
size = dst_bufsize;
bool bdstplane = av_sample_fmt_is_planar(dst_samplefmt);
if (bdstplane){
int pcm_size = av_get_bytes_per_sample(dst_samplefmt);
int max = size;
size = 0;
for (int i = 0; i < dst_nbsamples; i++) {
for (int channel=0;channel< dst_nbchannels; channel++){
if (size + pcm_size <= max) {
memcpy(buf + size,dstdata[channel] + pcm_size* i, pcm_size);
size += pcm_size;// * codecctx->channels;
}
}
} }
else{
int max = size;
size = 0;
if (max >= dst_bufsize) {
memcpy(buf, dstdata[0], dst_bufsize);
size = dst_bufsize;
}
}
return err; }