Skip to content

Commit

Permalink
Fix Windows unit tests and examples warnings( treated as errors)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoLusardi committed Aug 4, 2024
1 parent 5b99d31 commit 70d90ee
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 32 deletions.
8 changes: 4 additions & 4 deletions video_io/examples/src/utils/frame_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class frame_queue
{
unique_guard g(_lock);
if (_queue.size() >= _max_size)
notFullCond_.wait(g, [=] { return _queue.size() < _max_size; });
notFullCond_.wait(g, [=, this] { return _queue.size() < _max_size; });
bool wasEmpty = _queue.empty();
_queue.emplace_back(std::move(val));
if (wasEmpty)
Expand Down Expand Up @@ -143,7 +143,7 @@ bool try_put_until(value_type* val, const std::chrono::time_point<Clock,Duration
{
unique_guard g(_lock);
if (_queue.empty())
notEmptyCond_.wait(g, [=] { return !_queue.empty(); });
notEmptyCond_.wait(g, [=, this] { return !_queue.empty(); });
*val = std::move(_queue.front());
_queue.pop_front();
if (_queue.size() == _max_size - 1)
Expand All @@ -157,7 +157,7 @@ bool try_put_until(value_type* val, const std::chrono::time_point<Clock,Duration
{
unique_guard g(_lock);
if (_queue.empty())
notEmptyCond_.wait(g, [=] { return !_queue.empty(); });
notEmptyCond_.wait(g, [=, this] { return !_queue.empty(); });
auto val = std::move(_queue.front());
_queue.pop();
if (_queue.size() == _max_size - 1)
Expand Down Expand Up @@ -214,4 +214,4 @@ bool try_get_until(value_type* val, const std::chrono::time_point<Clock,Duration
}
*/
};
}
}
5 changes: 2 additions & 3 deletions video_io/examples/src/video_reader_imgui_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ int main(int argc, char** argv)
tc::vio::video_reader v;

std::filesystem::path default_video_path = std::filesystem::path(tc::vio::examples::utils::video_data_path) / "video_10sec_2fps_HD.mp4";
const char* video_path = default_video_path.c_str();
auto video_path = default_video_path.string();
if (argc > 1)
video_path = argv[1];

if (!v.open(video_path)) // , vio::decode_support::SW
if (!v.open(video_path.c_str())) // , vio::decode_support::SW
{
std::cout << "Unable to open video: " << video_path << std::endl;
return 1;
}

const auto fps = v.get_fps();
const auto size = v.get_frame_size();
const auto [frame_width, frame_height] = size.value();

Expand Down
4 changes: 2 additions & 2 deletions video_io/examples/src/video_reader_opengl_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ int main(int argc, char** argv)
tc::vio::video_reader v;

std::filesystem::path default_video_path = std::filesystem::path(tc::vio::examples::utils::video_data_path) / "video_10sec_2fps_HD.mp4";
const char* video_path = default_video_path.c_str();
auto video_path = default_video_path.string();
if (argc > 1)
video_path = argv[1];

if (!v.open(video_path))
if (!v.open(video_path.c_str()))
{
std::cout << "Unable to open video: " << video_path << std::endl;
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,16 @@ int main(int argc, char** argv)
tc::vio::video_reader v;

std::filesystem::path default_video_path = std::filesystem::path(tc::vio::examples::utils::video_data_path) / "video_10sec_2fps_HD.mp4";
const char* video_path = default_video_path.c_str();
auto video_path = default_video_path.string();
if (argc > 1)
video_path = argv[1];

if (!v.open(video_path))
if (!v.open(video_path.c_str()))
{
std::cout << "Unable to open video: " << video_path << std::endl;
return 1;
}

const auto fps = v.get_fps();
const auto frame_size = v.get_frame_size();
const auto [frame_width, frame_height] = frame_size.value();

Expand Down
4 changes: 2 additions & 2 deletions video_io/examples/src/video_reader_simple_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ int main(int argc, char** argv)

// Locate video file to be opened
std::filesystem::path default_video_path = std::filesystem::path(tc::vio::examples::utils::video_data_path) / "video_10sec_2fps_HD.mp4";
const char* video_path = default_video_path.c_str();
auto video_path = default_video_path.string();
if (argc > 1)
video_path = argv[1];

// Open video (local file or RTSP stream)
if (!v.open(video_path)) //, vio::decode_support::HW);
if (!v.open(video_path.c_str())) //, vio::decode_support::HW);
{
std::cout << "Unable to open input video: " << video_path << std::endl;
return EXIT_FAILURE;
Expand Down
8 changes: 4 additions & 4 deletions video_io/examples/src/video_writer_simple_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ void record_n_frames(const char* format)

const auto video_name = std::string("out_" + std::to_string(num_frames_to_write) + "_frames" + format);
std::filesystem::path default_video_path = std::filesystem::path(tc::vio::examples::utils::video_data_path) / video_name;
const char* video_path = default_video_path.c_str();
const auto video_path = default_video_path.string();
const auto fps = 30;
const auto width = 640;
const auto height = 480;

v.open(video_path, width, height, fps);
v.open(video_path.c_str(), width, height, fps);

const auto frame_size = width * height * 3;
std::array<uint8_t, frame_size> frame_data = {};
Expand Down Expand Up @@ -105,12 +105,12 @@ void record_n_seconds(const char* format)

const auto video_name = std::string("out_" + std::to_string(num_seconds_to_write) + "_seconds" + format);
std::filesystem::path default_video_path = std::filesystem::path(tc::vio::examples::utils::video_data_path) / video_name;
const char* video_path = default_video_path.c_str();
const auto video_path = default_video_path.string();
const auto fps = 30;
const auto width = 640;
const auto height = 480;

v.open(video_path, width, height, fps, num_seconds_to_write);
v.open(video_path.c_str(), width, height, fps, num_seconds_to_write);

const auto frame_size = width * height * 3;
std::array<uint8_t, frame_size> frame_data = {};
Expand Down
20 changes: 10 additions & 10 deletions video_io/tests/src/test_video_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ namespace tc::vio::tests

TEST_F(video_reader_test, open_valid_video_path)
{
ASSERT_TRUE(v->open(default_video_path.c_str()));
ASSERT_TRUE(v->open(default_video_path.string().c_str()));
ASSERT_TRUE(v->is_opened());
}

TEST_F(video_reader_test, open_non_existing_video_path)
{
const auto invalid_video_path = default_input_directory / "invalid-path.mp4";
ASSERT_FALSE(v->open(invalid_video_path.c_str()));
ASSERT_FALSE(v->open(invalid_video_path.string().c_str()));
ASSERT_FALSE(v->is_opened());
}

TEST_F(video_reader_test, open_release_without_read)
{
ASSERT_TRUE(v->open(default_video_path.c_str()));
ASSERT_TRUE(v->open(default_video_path.string().c_str()));
ASSERT_TRUE(v->is_opened());

v->release();
Expand All @@ -43,7 +43,7 @@ TEST_F(video_reader_test, open_release_without_read)

TEST_F(video_reader_test, open_read_one_frame_release)
{
ASSERT_TRUE(v->open(default_video_path.c_str()));
ASSERT_TRUE(v->open(default_video_path.string().c_str()));
ASSERT_TRUE(v->is_opened());

uint8_t* data_buffer = frame_data.data();
Expand Down Expand Up @@ -74,25 +74,25 @@ TEST_F(video_reader_test, release_without_open)

TEST_F(video_reader_test, open_same_path_without_read)
{
ASSERT_TRUE(v->open(default_video_path.c_str()));
ASSERT_TRUE(v->open(default_video_path.c_str()));
ASSERT_TRUE(v->open(default_video_path.c_str()));
ASSERT_TRUE(v->open(default_video_path.string().c_str()));
ASSERT_TRUE(v->open(default_video_path.string().c_str()));
ASSERT_TRUE(v->open(default_video_path.string().c_str()));

ASSERT_TRUE(v->is_opened());
}

TEST_F(video_reader_test, open_different_paths_without_read)
{
const auto video_path1 = (default_input_directory / "video_10sec_4fps_HD.mp4");
ASSERT_TRUE(v->open(video_path1.c_str()));
ASSERT_TRUE(v->open(video_path1.string().c_str()));
ASSERT_TRUE(v->is_opened());

const auto video_path2 = (default_input_directory / "video_10sec_4fps_HD.mkv");
ASSERT_TRUE(v->open(video_path2.c_str()));
ASSERT_TRUE(v->open(video_path2.string().c_str()));
ASSERT_TRUE(v->is_opened());

const auto video_path3 = (default_input_directory / "video_2sec_2fps_HD.mp4");
ASSERT_TRUE(v->open(video_path3.c_str()));
ASSERT_TRUE(v->open(video_path3.string().c_str()));
ASSERT_TRUE(v->is_opened());
}

Expand Down
8 changes: 4 additions & 4 deletions video_io/tests/src/test_video_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class video_reader_test : public testing::Test

void read_half_video(const std::unique_ptr<vio::video_reader>& v, const std::filesystem::path& video_path, int video_duration_in_seconds, double fps, int width, int height)
{
ASSERT_TRUE(v->open(video_path.c_str()));
ASSERT_TRUE(v->open(video_path.string().c_str()));
ASSERT_TRUE(v->is_opened());

// Initialize the dummy frame
Expand All @@ -83,9 +83,9 @@ void read_half_video(const std::unique_ptr<vio::video_reader>& v, const std::fil
}
}

void read_full_video(const std::unique_ptr<vio::video_reader>& v, const std::filesystem::path& video_path, int video_duration_in_seconds, double fps, int width, int height)
void read_full_video(const std::unique_ptr<vio::video_reader>& v, const std::filesystem::path& video_path, size_t video_duration_in_seconds, double fps, size_t width, size_t height)
{
ASSERT_TRUE(v->open(video_path.c_str()));
ASSERT_TRUE(v->open(video_path.string().c_str()));
ASSERT_TRUE(v->is_opened());

// Initialize the dummy frame
Expand All @@ -98,7 +98,7 @@ void read_full_video(const std::unique_ptr<vio::video_reader>& v, const std::fil
double current_pts = 0.0;

// The expcted number of video frames is equal to video_duration * FPS
const int total_frames = static_cast<int>(fps) * video_duration_in_seconds;
const int total_frames = static_cast<int>(fps * video_duration_in_seconds);

// The expected pts increment (for each consecutive frame) is equal to 1 / FPS
const double pts_increment = 1.0 / fps;
Expand Down

0 comments on commit 70d90ee

Please sign in to comment.