Skip to content

Commit 64d74cf

Browse files
author
Clement Champetier
committed
AudioFrame: add getBytesPerSample method
1 parent 9c02a02 commit 64d74cf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/AvTranscoder/data/decoded/AudioFrame.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ AudioFrame::~AudioFrame()
6969
freeData();
7070
}
7171

72+
size_t AudioFrame::getBytesPerSample() const
73+
{
74+
return av_get_bytes_per_sample(getSampleFormat());
75+
}
76+
7277
size_t AudioFrame::getSize() const
7378
{
7479
if(getSampleFormat() == AV_SAMPLE_FMT_NONE)
@@ -77,14 +82,14 @@ size_t AudioFrame::getSize() const
7782
return 0;
7883
}
7984

80-
const size_t size = getNbSamplesPerChannel() * getNbChannels() * av_get_bytes_per_sample(getSampleFormat());
85+
const size_t size = getNbSamplesPerChannel() * getNbChannels() * getBytesPerSample();
8186
if(size == 0)
8287
{
8388
std::stringstream msg;
8489
msg << "Unable to determine audio buffer size:" << std::endl;
8590
msg << "nb sample per channel = " << getNbSamplesPerChannel() << std::endl;
8691
msg << "channels = " << getNbChannels() << std::endl;
87-
msg << "bytes per sample = " << av_get_bytes_per_sample(getSampleFormat()) << std::endl;
92+
msg << "bytes per sample = " << getBytesPerSample() << std::endl;
8893
throw std::runtime_error(msg.str());
8994
}
9095
return size;

src/AvTranscoder/data/decoded/AudioFrame.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AvExport AudioFrame : public IFrame
5252
size_t getChannelLayout() const { return av_frame_get_channel_layout(_frame); }
5353
std::string getChannelLayoutDesc() const; ///< Get a description of a channel layout (example: '5.1').
5454
AVSampleFormat getSampleFormat() const { return static_cast<AVSampleFormat>(_frame->format); }
55+
size_t getBytesPerSample() const; ///< 0 if unknown sample format
5556
size_t getNbSamplesPerChannel() const { return _frame->nb_samples; }
5657

5758
size_t getSize() const;

0 commit comments

Comments
 (0)