Skip to content
Merged
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
5 changes: 3 additions & 2 deletions include/livekit/audio_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
/// @param num_channels Number of channels.
/// @param samples_per_channel Number of samples per channel.
///
/// @throws std::invalid_argument if the data size is inconsistent with
/// num_channels * samples_per_channel.
/// @throws std::invalid_argument if @p num_channels or
/// @p samples_per_channel is not positive, or if the data size is
/// inconsistent with num_channels * samples_per_channel.
AudioFrame(std::vector<std::int16_t> data, int sample_rate, int num_channels, int samples_per_channel);
AudioFrame(); // Default constructor
virtual ~AudioFrame() = default;
Expand Down Expand Up @@ -85,7 +86,7 @@
friend class AudioSource;

private:
std::vector<std::int16_t> data_;

Check warning on line 89 in include/livekit/audio_frame.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::AudioFrame::data_': 'std::vector<int16_t,std::allocator<int16_t>>' needs to have dll-interface to be used by clients of 'livekit::AudioFrame' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 89 in include/livekit/audio_frame.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::AudioFrame::data_': 'std::vector<int16_t,std::allocator<int16_t>>' needs to have dll-interface to be used by clients of 'livekit::AudioFrame' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 89 in include/livekit/audio_frame.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::AudioFrame::data_': 'std::vector<int16_t,std::allocator<int16_t>>' needs to have dll-interface to be used by clients of 'livekit::AudioFrame' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 89 in include/livekit/audio_frame.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::AudioFrame::data_': 'std::vector<int16_t,std::allocator<int16_t>>' needs to have dll-interface to be used by clients of 'livekit::AudioFrame' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 89 in include/livekit/audio_frame.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::AudioFrame::data_': 'std::vector<int16_t,std::allocator<int16_t>>' needs to have dll-interface to be used by clients of 'livekit::AudioFrame' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 89 in include/livekit/audio_frame.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::AudioFrame::data_': 'std::vector<int16_t,std::allocator<int16_t>>' needs to have dll-interface to be used by clients of 'livekit::AudioFrame' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]
int sample_rate_;
int num_channels_;
int samples_per_channel_;
Expand Down
8 changes: 7 additions & 1 deletion src/audio_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ AudioFrame::AudioFrame(std::vector<std::int16_t> data, int sample_rate, int num_
sample_rate_(sample_rate),
num_channels_(num_channels),
samples_per_channel_(samples_per_channel) {
const std::size_t expected = static_cast<std::size_t>(num_channels_) * static_cast<std::size_t>(samples_per_channel_);
if (num_channels_ <= 0 || samples_per_channel_ <= 0) {
throw std::invalid_argument("AudioFrame: num_channels and samples_per_channel must be positive");
}

const auto channels = static_cast<std::size_t>(num_channels_);
const auto samples = static_cast<std::size_t>(samples_per_channel_);
const std::size_t expected = channels * samples;

if (data_.size() < expected) {
throw std::invalid_argument("AudioFrame: data size must be >= num_channels * samples_per_channel");
Expand Down
9 changes: 9 additions & 0 deletions src/tests/unit/test_audio_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,13 @@ TEST_F(AudioFrameTest, InvalidDataSizeThrows) {
EXPECT_THROW(AudioFrame(data, 48000, 2, 960), std::invalid_argument);
}

TEST_F(AudioFrameTest, NonPositiveDimensionsThrow) {
const std::vector<std::int16_t> data;

EXPECT_THROW(AudioFrame(data, 48000, 0, 960), std::invalid_argument);
EXPECT_THROW(AudioFrame(data, 48000, 2, 0), std::invalid_argument);
EXPECT_THROW(AudioFrame(data, 48000, -1, 960), std::invalid_argument);
EXPECT_THROW(AudioFrame(data, 48000, 2, -1), std::invalid_argument);
}

} // namespace livekit::test
Loading