mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +00:00
RTC: Refine FFmpeg opus audio noisy issue. v5.0.197 (#3852)
When converting between AAC and Opus formats (aac2opus or opus2aac), the `av_frame_get_buffer` API is frequently called. The goal is to optimize the code logic and reduce the frequent allocation and deallocation of memory. In the case of aac2opus, av_frame_get_buffer is still frequently called. In the case of opus2aac, the goal is to avoid calling av_frame_get_buffer and reduce memory allocations. Before calling the `av_audio_fifo_read` API, use `av_frame_make_writable` to check if the frame is writable. If it is not writable, create a new frame. --------- Co-authored-by: john <hondaxiao@tencent.com>
This commit is contained in:
parent
35f479c6bc
commit
f1db76011b
9 changed files with 25 additions and 23 deletions
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
|
@ -195,7 +195,8 @@ jobs:
|
||||||
- name: Run SRS regression-test
|
- name: Run SRS regression-test
|
||||||
run: |
|
run: |
|
||||||
docker run --rm srs:test bash -c './objs/srs -c conf/regression-test.conf && \
|
docker run --rm srs:test bash -c './objs/srs -c conf/regression-test.conf && \
|
||||||
cd 3rdparty/srs-bench && ./objs/srs_test -test.v && ./objs/srs_gb28181_test -test.v'
|
cd 3rdparty/srs-bench && (./objs/srs_test -test.v || (cat ../../objs/srs.log && exit 1)) && \
|
||||||
|
./objs/srs_gb28181_test -test.v'
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
|
|
|
@ -448,8 +448,7 @@ function parse_user_option() {
|
||||||
--ffmpeg-tool) SRS_FFMPEG_TOOL=$(switch2value $value) ;;
|
--ffmpeg-tool) SRS_FFMPEG_TOOL=$(switch2value $value) ;;
|
||||||
|
|
||||||
# use cache for build.
|
# use cache for build.
|
||||||
--build-cache) SRS_BUILD_CACHE=YES ;;
|
--build-cache) SRS_BUILD_CACHE=$(switch2value $value) ;;
|
||||||
--without-build-cache) SRS_BUILD_CACHE=NO ;;
|
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "$0: error: invalid option \"$option\""
|
echo "$0: error: invalid option \"$option\""
|
||||||
|
|
|
@ -7,6 +7,7 @@ The changelog for SRS.
|
||||||
<a name="v5-changes"></a>
|
<a name="v5-changes"></a>
|
||||||
|
|
||||||
## SRS 5.0 Changelog
|
## SRS 5.0 Changelog
|
||||||
|
* v5.0, 2023-11-04, Merge [#3852](https://github.com/ossrs/srs/pull/3852): RTC: Refine FFmpeg opus audio noisy issue. v5.0.197 (#3852)
|
||||||
* v5.0, 2023-11-01, Merge [#3858](https://github.com/ossrs/srs/pull/3858): Support build without cache to test if actions fail. v5.0.196 (#3858)
|
* v5.0, 2023-11-01, Merge [#3858](https://github.com/ossrs/srs/pull/3858): Support build without cache to test if actions fail. v5.0.196 (#3858)
|
||||||
* v5.0, 2023-10-25, Merge [#3845](https://github.com/ossrs/srs/pull/3845): RTC: Fix FFmpeg opus audio noisy issue. v5.0.195 (#3845)
|
* v5.0, 2023-10-25, Merge [#3845](https://github.com/ossrs/srs/pull/3845): RTC: Fix FFmpeg opus audio noisy issue. v5.0.195 (#3845)
|
||||||
* v5.0, 2023-10-21, Merge [#3847](https://github.com/ossrs/srs/pull/3847): WebRTC: TCP transport should use read_fully instead of read. v5.0.194 (#3847)
|
* v5.0, 2023-10-21, Merge [#3847](https://github.com/ossrs/srs/pull/3847): WebRTC: TCP transport should use read_fully instead of read. v5.0.194 (#3847)
|
||||||
|
|
|
@ -13,7 +13,6 @@ function srs_get_player_height() { return srs_get_player_width() * 9 / 19; }
|
||||||
* update the navigator, add same query string.
|
* update the navigator, add same query string.
|
||||||
*/
|
*/
|
||||||
function update_nav() {
|
function update_nav() {
|
||||||
$("#srs_index").attr("href", "index.html" + window.location.search);
|
|
||||||
$("#nav_srs_player").attr("href", "srs_player.html" + window.location.search);
|
$("#nav_srs_player").attr("href", "srs_player.html" + window.location.search);
|
||||||
$("#nav_rtc_player").attr("href", "rtc_player.html" + window.location.search);
|
$("#nav_rtc_player").attr("href", "rtc_player.html" + window.location.search);
|
||||||
$("#nav_rtc_publisher").attr("href", "rtc_publisher.html" + window.location.search);
|
$("#nav_rtc_publisher").attr("href", "rtc_publisher.html" + window.location.search);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<div class="navbar navbar-fixed-top">
|
<div class="navbar navbar-fixed-top">
|
||||||
<div class="navbar-inner">
|
<div class="navbar-inner">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a id="srs_index" class="brand" href="#">SRS</a>
|
<a class="brand" href="https://github.com/ossrs/srs" target="_blank">SRS</a>
|
||||||
<div class="nav-collapse collapse">
|
<div class="nav-collapse collapse">
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li class="active"><a id="nav_srs_player" href="srs_player.html">LivePlayer</a></li>
|
<li class="active"><a id="nav_srs_player" href="srs_player.html">LivePlayer</a></li>
|
||||||
|
@ -29,11 +29,11 @@
|
||||||
<!--<li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>-->
|
<!--<li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>-->
|
||||||
<!--li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>-->
|
<!--li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>-->
|
||||||
<!--<li><a id="nav_gb28181" href="srs_gb28181.html">GB28181</a></li>-->
|
<!--<li><a id="nav_gb28181" href="srs_gb28181.html">GB28181</a></li>-->
|
||||||
<li>
|
<!--<li>
|
||||||
<a href="https://github.com/ossrs/srs">
|
<a href="https://github.com/ossrs/srs">
|
||||||
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/ossrs/srs?style=social">
|
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/ossrs/srs?style=social">
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>-->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<div class="navbar navbar-fixed-top">
|
<div class="navbar navbar-fixed-top">
|
||||||
<div class="navbar-inner">
|
<div class="navbar-inner">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a id="srs_index" class="brand" href="https://github.com/ossrs/srs">SRS</a>
|
<a class="brand" href="https://github.com/ossrs/srs" target="_blank">SRS</a>
|
||||||
<div class="nav-collapse collapse">
|
<div class="nav-collapse collapse">
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li><a id="nav_srs_player" href="srs_player.html">LivePlayer</a></li>
|
<li><a id="nav_srs_player" href="srs_player.html">LivePlayer</a></li>
|
||||||
|
@ -34,11 +34,11 @@
|
||||||
<!--<li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>-->
|
<!--<li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>-->
|
||||||
<!--<li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>-->
|
<!--<li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>-->
|
||||||
<!--<li><a id="nav_gb28181" href="srs_gb28181.html">GB28181</a></li>-->
|
<!--<li><a id="nav_gb28181" href="srs_gb28181.html">GB28181</a></li>-->
|
||||||
<li>
|
<!--<li>
|
||||||
<a href="https://github.com/ossrs/srs">
|
<a href="https://github.com/ossrs/srs">
|
||||||
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/ossrs/srs?style=social">
|
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/ossrs/srs?style=social">
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>-->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<div class="navbar navbar-fixed-top">
|
<div class="navbar navbar-fixed-top">
|
||||||
<div class="navbar-inner">
|
<div class="navbar-inner">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a id="srs_index" class="brand" href="https://github.com/ossrs/srs">SRS</a>
|
<a class="brand" href="https://github.com/ossrs/srs" target="_blank">SRS</a>
|
||||||
<div class="nav-collapse collapse">
|
<div class="nav-collapse collapse">
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li><a id="nav_srs_player" href="srs_player.html">LivePlayer</a></li>
|
<li><a id="nav_srs_player" href="srs_player.html">LivePlayer</a></li>
|
||||||
|
@ -34,11 +34,11 @@
|
||||||
<!--<li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>-->
|
<!--<li><a id="nav_srs_bwt" href="srs_bwt.html">SRS测网速</a></li>-->
|
||||||
<!--<li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>-->
|
<!--<li><a id="nav_vlc" href="vlc.html">VLC播放器</a></li>-->
|
||||||
<!--<li><a id="nav_gb28181" href="srs_gb28181.html">GB28181</a></li>-->
|
<!--<li><a id="nav_gb28181" href="srs_gb28181.html">GB28181</a></li>-->
|
||||||
<li>
|
<!--<li>
|
||||||
<a href="https://github.com/ossrs/srs">
|
<a href="https://github.com/ossrs/srs">
|
||||||
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/ossrs/srs?style=social">
|
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/ossrs/srs?style=social">
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>-->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -260,6 +260,13 @@ srs_error_t SrsAudioTranscoder::init_enc(SrsAudioCodecId dst_codec, int dst_chan
|
||||||
if (!enc_frame_) {
|
if (!enc_frame_) {
|
||||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not allocate audio encode in frame");
|
return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not allocate audio encode in frame");
|
||||||
}
|
}
|
||||||
|
enc_frame_->format = enc_->sample_fmt;
|
||||||
|
enc_frame_->nb_samples = enc_->frame_size;
|
||||||
|
enc_frame_->channel_layout = enc_->channel_layout;
|
||||||
|
|
||||||
|
if (av_frame_get_buffer(enc_frame_, 0) < 0) {
|
||||||
|
return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not get audio frame buffer");
|
||||||
|
}
|
||||||
|
|
||||||
enc_packet_ = av_packet_alloc();
|
enc_packet_ = av_packet_alloc();
|
||||||
if (!enc_packet_) {
|
if (!enc_packet_) {
|
||||||
|
@ -381,26 +388,21 @@ srs_error_t SrsAudioTranscoder::encode(std::vector<SrsAudioFrame*> &pkts)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (av_audio_fifo_size(fifo_) >= enc_->frame_size) {
|
while (av_audio_fifo_size(fifo_) >= enc_->frame_size) {
|
||||||
enc_frame_->format = enc_->sample_fmt;
|
// make sure the frame is writable
|
||||||
enc_frame_->nb_samples = enc_->frame_size;
|
if (av_frame_make_writable(enc_frame_) < 0) {
|
||||||
enc_frame_->channel_layout = enc_->channel_layout;
|
return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not make writable frame");
|
||||||
|
|
||||||
if (av_frame_get_buffer(enc_frame_, 0) < 0) {
|
|
||||||
av_frame_free(&enc_frame_);
|
|
||||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not get audio frame buffer");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read as many samples from the FIFO buffer as required to fill the frame.
|
/* Read as many samples from the FIFO buffer as required to fill the frame.
|
||||||
* The samples are stored in the frame temporarily. */
|
* The samples are stored in the frame temporarily. */
|
||||||
if (av_audio_fifo_read(fifo_, (void **)enc_frame_->data, enc_->frame_size) < enc_->frame_size) {
|
if (av_audio_fifo_read(fifo_, (void **)enc_frame_->data, enc_->frame_size) < enc_->frame_size) {
|
||||||
av_frame_free(&enc_frame_);
|
|
||||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not read data from FIFO");
|
return srs_error_new(ERROR_RTC_RTP_MUXER, "Could not read data from FIFO");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send the frame for encoding */
|
/* send the frame for encoding */
|
||||||
enc_frame_->pts = next_out_pts_;
|
enc_frame_->pts = next_out_pts_;
|
||||||
next_out_pts_ += enc_->frame_size;
|
next_out_pts_ += enc_->frame_size;
|
||||||
int error = avcodec_send_frame(enc_, enc_frame_);
|
int error = avcodec_send_frame(enc_, enc_frame_);
|
||||||
av_frame_unref(enc_frame_);
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "Error sending the frame to the encoder(%d,%s)", error,
|
return srs_error_new(ERROR_RTC_RTP_MUXER, "Error sending the frame to the encoder(%d,%s)", error,
|
||||||
av_make_error_string(err_buf, AV_ERROR_MAX_STRING_SIZE, error));
|
av_make_error_string(err_buf, AV_ERROR_MAX_STRING_SIZE, error));
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 5
|
#define VERSION_MAJOR 5
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 196
|
#define VERSION_REVISION 197
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue