ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.34k stars 5.33k forks source link

PR: RTMP push streaming, WebRTC playback, dual-channel audio has issues, single-channel audio is normal. #2172

Closed 18981707877 closed 3 years ago

18981707877 commented 3 years ago

Description'

Please ensure that the markdown structure is maintained.

Please describe the issue you encountered here. ' Make sure to maintain the markdown structure.

  1. SRS version: 4.0.62
  2. The log of SRS is as follows:
    The log is normal.
  3. The configuration of SRS is as follows (Config):
    
    daemon              off;
    listen              1935;
    max_connections     1000;
    srs_log_file        srs.log;

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.

# 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;

}

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; } }


**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"); }

@@ -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"); }



`TRANS_BY_GPT3`
winlinvip commented 3 years ago

See also #2011 has not been merged yet.

TRANS_BY_GPT3

winlinvip commented 3 years ago

Fixed.