Skip to content

Commit 50d46ad

Browse files
author
Clement Champetier
committed
Video/Audio frames: fix message logged when failing to allocate data
* "os" is the name of the variable in LOG_* defines, so rename it to "stream". * Print "none" when the format is no found.
1 parent ccdbbea commit 50d46ad

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/AvTranscoder/data/decoded/AudioFrame.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ void AudioFrame::allocateData()
110110
av_samples_alloc(_frame->data, _frame->linesize, _frame->channels, _frame->nb_samples, _desc._sampleFormat, align);
111111
if(ret < 0)
112112
{
113-
std::stringstream os;
114-
os << "Unable to allocate an audio frame of ";
115-
os << "sample rate = " << _frame->sample_rate << ", ";
116-
os << "nb channels = " << _frame->channels << ", ";
117-
os << "channel layout = " << av_get_channel_name(_frame->channels) << ", ";
118-
os << "nb samples = " << _frame->nb_samples << ", ";
119-
os << "sample format = " << getSampleFormatName(_desc._sampleFormat);
120-
LOG_ERROR(os.str())
113+
const std::string formatName = getSampleFormatName(_desc._sampleFormat);
114+
std::stringstream stream;
115+
stream << "Unable to allocate an audio frame of ";
116+
stream << "sample rate = " << _frame->sample_rate << ", ";
117+
stream << "nb channels = " << _frame->channels << ", ";
118+
stream << "channel layout = " << av_get_channel_name(_frame->channels) << ", ";
119+
stream << "nb samples = " << _frame->nb_samples << ", ";
120+
stream << "sample format = " << (formatName.empty() ? "none" : formatName);
121+
LOG_ERROR(stream.str())
121122
throw std::bad_alloc();
122123
}
123124
_dataAllocated = true;

src/AvTranscoder/data/decoded/VideoFrame.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ void VideoFrame::allocateData()
9090
const int ret = avpicture_alloc(reinterpret_cast<AVPicture*>(_frame), _desc._pixelFormat, _desc._width, _desc._height);
9191
if(ret < 0)
9292
{
93-
std::stringstream os;
94-
os << "Unable to allocate an image frame of ";
95-
os << "width = " << _frame->width << ", ";
96-
os << "height = " << _frame->height << ", ";
97-
os << "pixel format = " << getPixelFormatName(_desc._pixelFormat);
98-
LOG_ERROR(os.str())
93+
const std::string formatName = getPixelFormatName(_desc._pixelFormat);
94+
std::stringstream stream;
95+
stream << "Unable to allocate an image frame of ";
96+
stream << "width = " << _frame->width << ", ";
97+
stream << "height = " << _frame->height << ", ";
98+
stream << "pixel format = " << (formatName.empty() ? "none" : formatName);
99+
LOG_ERROR(stream.str())
99100
throw std::bad_alloc();
100101
}
101102
_dataAllocated = true;

0 commit comments

Comments
 (0)