Skip to content
Snippets Groups Projects
Commit cbf74f49 authored by Philippe Gorley's avatar Philippe Gorley Committed by Adrien Béraud
Browse files

audio: add function to fill frames with silence

When mixing audio frames, the mix buffer needs to be initialized with
silence.

Change-Id: I15d0573d8036a2755cbc33bdf91619cfedcf8f2d
parent 1fe0f48e
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "client/ring_signal.h" #include "client/ring_signal.h"
#include "audio/ringbufferpool.h" #include "audio/ringbufferpool.h"
#include "dring/media_const.h" #include "dring/media_const.h"
#include "libav_utils.h"
#include <functional> #include <functional>
#include <memory> #include <memory>
...@@ -108,6 +109,7 @@ AudioFrame::mix(const AudioFrame& frame) ...@@ -108,6 +109,7 @@ AudioFrame::mix(const AudioFrame& frame)
} }
if (f.nb_samples == 0) { if (f.nb_samples == 0) {
reserve(fIn.nb_samples); reserve(fIn.nb_samples);
ring::libav_utils::fillWithSilence(&f);
} else if (f.nb_samples != fIn.nb_samples) { } else if (f.nb_samples != fIn.nb_samples) {
throw std::invalid_argument("Can't mix frames with different length"); throw std::invalid_argument("Can't mix frames with different length");
} }
......
...@@ -38,6 +38,7 @@ extern "C" { ...@@ -38,6 +38,7 @@ extern "C" {
#include <libavutil/imgutils.h> #include <libavutil/imgutils.h>
#include <libavutil/intreadwrite.h> #include <libavutil/intreadwrite.h>
#include <libavutil/log.h> #include <libavutil/log.h>
#include <libavutil/samplefmt.h>
} }
#include "libav_utils.h" #include "libav_utils.h"
......
...@@ -222,4 +222,12 @@ fillWithBlack(AVFrame* frame) ...@@ -222,4 +222,12 @@ fillWithBlack(AVFrame* frame)
} }
} }
void
fillWithSilence(AVFrame* frame)
{
int ret = av_samples_set_silence(frame->extended_data, 0, frame->nb_samples, frame->channels, (AVSampleFormat)frame->format);
if (ret < 0)
RING_ERR() << "Failed to fill frame with silence";
}
}} // namespace ring::libav_utils }} // namespace ring::libav_utils
...@@ -47,4 +47,6 @@ namespace ring { namespace libav_utils { ...@@ -47,4 +47,6 @@ namespace ring { namespace libav_utils {
void fillWithBlack(AVFrame* frame); void fillWithBlack(AVFrame* frame);
void fillWithSilence(AVFrame* frame);
}} // namespace ring::libav_utils }} // namespace ring::libav_utils
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment