Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When playing WEBRTC, sometimes there is noise in the audio. #1975

Closed
nowgoing opened this issue Sep 28, 2020 · 10 comments
Closed

When playing WEBRTC, sometimes there is noise in the audio. #1975

nowgoing opened this issue Sep 28, 2020 · 10 comments
Assignees
Labels
TransByAI Translated by AI/GPT. WebRTC WebRTC, RTC2RTMP or RTMP2RTC.
Milestone

Comments

@nowgoing
Copy link

nowgoing commented Sep 28, 2020

Description'

Please ensure that the markdown structure is maintained.

When playing the same video streaming source using WEBRTC, there is sometimes noise in the audio, but there is no noise when pulling the stream using RTMP.

  1. SRS version: 4.0.37
  2. The log of SRS is as follows:
  1. The configuration of SRS is as follows:
Use the configuration file conf/rtc.conf.

Replay

How to replay bug?

Steps to replay the bug:

  1. ffmpeg rtmp streaming
  2. webrtc playback, check for noise in the audio
  3. If there is no noise, stop streaming and repeat steps 1-2-3

Expected Behavior:

Expecting webrtc playback to have no audio noise.

TRANS_BY_GPT3

@nowgoing nowgoing reopened this Sep 28, 2020
@PieerePi
Copy link
Contributor

PieerePi commented Sep 29, 2020

See PR #1969.

TRANS_BY_GPT3

@nowgoing
Copy link
Author

nowgoing commented Sep 29, 2020

See PR #1969.

> Test noise solution, thank you

TRANS_BY_GPT3

@PieerePi
Copy link
Contributor

PieerePi commented Sep 29, 2020

I saw that you said you made some changes and solved something before. Is it like what you said, there was no initialization or something like that?

TRANS_BY_GPT3

@nowgoing
Copy link
Author

nowgoing commented Sep 30, 2020

I saw that you mentioned before that you made some changes and resolved something. Was it like you said, without any initialization issues?

No, now we are using your PR.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Sep 30, 2020

I have also encountered noise, which means not being able to hear normal sounds, but only chaotic noise.
Restart the server and then refresh the page, and the noise will be gone. I don't know where this noise is coming from.

TRANS_BY_GPT3

@PieerePi
Copy link
Contributor

PieerePi commented Sep 30, 2020

@winlinvip, please take a look at PR #1969.

TRANS_BY_GPT3

@nowgoing
Copy link
Author

nowgoing commented Sep 30, 2020

@winlinvip please take a look at PR #1969.
Make sure to maintain the markdown structure.

Using OBS (setting the media source as an mp4 file) for RTMP streaming, setting the audio for streaming as stereo, and playing the stream with WebRTC; the chance of noise reproduction is very high.

@PieerePi
In the old code, within the function SrsAudioDecoder::decode...

for (int i = 0; i < frame_->nb_samples; i++) {
     if (size + pcm_size * codec_ctx_->channels <= max) {
           memcpy(buf + size,frame_->data[0] + pcm_size*codec_ctx_->channels * i, pcm_size * codec_ctx_->channels);      
           size += pcm_size * codec_ctx_->channels;
      }
}

Copying each sample one by one is meaningful to avoid losing too much sample data when it exceeds the maximum value.
So I made some changes to the old code, as follows...

for (int ch = 0; ch < codec_ctx_->channels; ch++) {
       for (int i = 0; i < frame_->nb_samples; i++) {
               if (size + pcm_size  <= max) {
                    memcpy(buf + size, frame_->data[ch] + pcm_size * i, pcm_size);
                    size += pcm_size;
                }
         }
 }

There was also no noise in the test.

TRANS_BY_GPT3

@PieerePi
Copy link
Contributor

PieerePi commented Oct 9, 2020

Copying each sample one by one is meaningful to avoid discarding too much sample data when it exceeds the maximum limit.

@nowgoing
If it were me, I would choose to discard the entire channel of data. :-)

TRANS_BY_GPT3

@winlinvip
Copy link
Member

👍

@winlinvip winlinvip added the WebRTC WebRTC, RTC2RTMP or RTMP2RTC. label Jan 18, 2021
@winlinvip
Copy link
Member

Fixed in 4.0.81 #2106 (comment)

@winlinvip winlinvip self-assigned this Aug 29, 2021
@winlinvip winlinvip added this to the 4.0 milestone Sep 4, 2021
@winlinvip winlinvip changed the title WEBRTC播放时,音频有时有噪音 When playing WEBRTC, sometimes there is noise in the audio. Jul 28, 2023
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT. WebRTC WebRTC, RTC2RTMP or RTMP2RTC.
Projects
None yet
Development

No branches or pull requests

3 participants