Skip to content

Fix audio generator channel layout #241

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AvTranscoder/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define AVTRANSCODER_VERSION_MAJOR 0
#define AVTRANSCODER_VERSION_MINOR 9
#define AVTRANSCODER_VERSION_MICRO 1
#define AVTRANSCODER_VERSION_MICRO 2

#include <AvTranscoder/system.hpp>

Expand Down
6 changes: 3 additions & 3 deletions src/AvTranscoder/data/decoded/AudioFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ size_t AudioFrame::getSize() const
void AudioFrame::allocateAVSample(const AudioFrameDesc& desc)
{
// Set Frame properties
_frame->sample_rate = desc._sampleRate;
_frame->channels = desc._nbChannels;
_frame->channel_layout = av_get_default_channel_layout(desc._nbChannels);
av_frame_set_sample_rate(_frame, desc._sampleRate);
av_frame_set_channels(_frame, desc._nbChannels);
av_frame_set_channel_layout(_frame, av_get_default_channel_layout(desc._nbChannels));
_frame->format = desc._sampleFormat;
_frame->nb_samples = desc._sampleRate / 25.; // cannot be known before calling avcodec_decode_audio4

Expand Down
9 changes: 9 additions & 0 deletions src/AvTranscoder/decoder/AudioGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ void AudioGenerator::setNextFrame(Frame& inputFrame)

bool AudioGenerator::decodeNextFrame(Frame& frameBuffer)
{
// Check channel layout of the given frame to be able to copy audio data to it.
// @see Frame.copyData method
if(frameBuffer.getAVFrame().channel_layout == 0)
{
const size_t channelLayout = av_get_default_channel_layout(frameBuffer.getAVFrame().channels);
LOG_WARN("Channel layout en the audio frame is not set. Set it to '" << channelLayout << "' to be able to copy silence data.")
av_frame_set_channel_layout(&frameBuffer.getAVFrame(), channelLayout);
}

// Generate silent
if(!_inputFrame)
{
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/properties/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template <>
void add(PropertyVector& propertyVector, const std::string& key, const float& value)
{
std::stringstream ss;
if(value <= AV_NOPTS_VALUE || value >= AV_NOPTS_VALUE)
if(value <= AV_NOPTS_VALUE || value >= -(float)AV_NOPTS_VALUE)
ss << "N/A";
else
ss << value;
Expand Down