Skip to content
Snippets Groups Projects
Commit 1b48a480 authored by Eloi Bail's avatar Eloi Bail Committed by Guillaume Roguez
Browse files

daemon: handle libav opus native decoder

Since libavcodec56 libav native opus decoder is used instead of libopus
decoder.
This decoder only ouput float planar audio data (AV_SAMPLE_FMT_FLTP)
This commit detect the output format and convert it to signed 16bits
in case of float planar.

Refs #64245

Change-Id: Idb8240a1158a0add446d7df3b4a1ed51089e2781
parent 48f16309
No related branches found
No related tags found
No related merge requests found
......@@ -214,6 +214,26 @@ void AudioBuffer::deinterleave(const std::vector<ring::AudioSample>& in, AudioFo
deinterleave(in.data(), in.size()/format.nb_channels, format.nb_channels);
}
void AudioBuffer::convertFloatPlanarToSigned16(uint8_t** extended_data, size_t frame_num, unsigned nb_channels)
{
if (extended_data == nullptr)
return;
// Resize buffer
setChannelNum(nb_channels);
resize(frame_num);
for (unsigned j = 0, c = channels(); j < c; j++){
float* inputChannel = (float*)extended_data[j];
for (unsigned i=0, f=frames(); i < f; i++){
float inputChannelVal = *inputChannel++;
// avoid saturation: limit val between -1 and 1
inputChannelVal = std::max(-1.0f, std::min(inputChannelVal, 1.0f));
samples_[j][i] = (int16_t) (inputChannelVal * 32768.0f);
}
}
}
size_t AudioBuffer::mix(const AudioBuffer& other, bool up /* = true */)
{
const bool upmix = up && (other.samples_.size() < samples_.size());
......
......@@ -288,6 +288,12 @@ class AudioBuffer {
*/
void deinterleave(const std::vector<ring::AudioSample>& in, AudioFormat format);
/**
* convert float planar data to signed 16
*/
void convertFloatPlanarToSigned16(uint8_t** extended_data, size_t frame_num, unsigned nb_channels = 1);
/**
* In-place gain transformation.
*
......
......@@ -432,8 +432,13 @@ void MediaDecoder::writeToRingBuffer(AVFrame* decoded_frame,
ring::AudioBuffer out(decoded_frame->nb_samples, decoderFormat);
out.deinterleave(reinterpret_cast<const ring::AudioSample*>(decoded_frame->data[0]),
decoded_frame->nb_samples, decoderCtx_->channels);
if ( decoderCtx_->sample_fmt == AV_SAMPLE_FMT_FLTP ) {
out.convertFloatPlanarToSigned16(decoded_frame->extended_data,
decoded_frame->nb_samples, decoderCtx_->channels);
} else if ( decoderCtx_->sample_fmt == AV_SAMPLE_FMT_S16 ) {
out.deinterleave(reinterpret_cast<const ring::AudioSample*>(decoded_frame->data[0]),
decoded_frame->nb_samples, decoderCtx_->channels);
}
if ((unsigned)decoded_frame->sample_rate != outFormat.sample_rate) {
if (!resampler_) {
RING_DBG("Creating audio resampler");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment