From ab24325df3e87b3f3838756b305113a3d3a9a2e5 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 18 Jun 2019 17:25:43 +0300 Subject: [PATCH] videoio(test): avoid raw ptr in ffmpeg tests causes leaks if FFmpeg is disabled through OPENCV_VIDEOIO_PRIORITY_FFMPEG=0 --- modules/videoio/test/test_ffmpeg.cpp | 31 +++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/modules/videoio/test/test_ffmpeg.cpp b/modules/videoio/test/test_ffmpeg.cpp index e9e5e9aca1..7e508e7782 100644 --- a/modules/videoio/test/test_ffmpeg.cpp +++ b/modules/videoio/test/test_ffmpeg.cpp @@ -227,7 +227,7 @@ public: const static Size FrameSize; static std::string TmpDirectory; - CreateVideoWriterInvoker(std::vector& _writers, std::vector& _files) : + CreateVideoWriterInvoker(std::vector< cv::Ptr >& _writers, std::vector& _files) : writers(_writers), files(_files) { } @@ -241,14 +241,14 @@ public: std::string fileName = tempfile(stream.str().c_str()); files[i] = fileName; - writers[i] = new VideoWriter(fileName, CAP_FFMPEG, VideoWriter::fourcc('X','V','I','D'), 25.0f, FrameSize); + writers[i] = makePtr(fileName, CAP_FFMPEG, VideoWriter::fourcc('X','V','I','D'), 25.0f, FrameSize); CV_Assert(writers[i]->isOpened()); } } private: - std::vector& writers; + std::vector< cv::Ptr >& writers; std::vector& files; }; @@ -264,7 +264,7 @@ public: static const Scalar ObjectColor; static const Point Center; - WriteVideo_Invoker(const std::vector& _writers) : + WriteVideo_Invoker(const std::vector< cv::Ptr >& _writers) : ParallelLoopBody(), writers(&_writers) { } @@ -304,7 +304,7 @@ protected: } private: - const std::vector* writers; + const std::vector< cv::Ptr >* writers; }; const Scalar WriteVideo_Invoker::ObjectColor(Scalar::all(0)); @@ -315,7 +315,7 @@ class CreateVideoCaptureInvoker : public ParallelLoopBody { public: - CreateVideoCaptureInvoker(std::vector& _readers, const std::vector& _files) : + CreateVideoCaptureInvoker(std::vector< cv::Ptr >& _readers, const std::vector& _files) : ParallelLoopBody(), readers(&_readers), files(&_files) { } @@ -324,12 +324,12 @@ public: { for (int i = range.start; i != range.end; ++i) { - readers->operator[](i) = new VideoCapture(files->operator[](i), CAP_FFMPEG); + readers->operator[](i) = makePtr(files->operator[](i), CAP_FFMPEG); CV_Assert(readers->operator[](i)->isOpened()); } } private: - std::vector* readers; + std::vector< cv::Ptr >* readers; const std::vector* files; }; @@ -337,7 +337,7 @@ class ReadImageAndTest : public ParallelLoopBody { public: - ReadImageAndTest(const std::vector& _readers, cvtest::TS* _ts) : + ReadImageAndTest(const std::vector< cv::Ptr >& _readers, cvtest::TS* _ts) : ParallelLoopBody(), readers(&_readers), ts(_ts) { } @@ -346,7 +346,7 @@ public: { for (int j = range.start; j < range.end; ++j) { - VideoCapture* capture = readers->operator[](j); + VideoCapture* capture = readers->operator[](j).get(); CV_Assert(capture != NULL); CV_Assert(capture->isOpened()); @@ -394,7 +394,7 @@ public: static bool next; private: - const std::vector* readers; + const std::vector< cv::Ptr >* readers; cvtest::TS* ts; }; @@ -406,7 +406,7 @@ TEST(Videoio_Video_parallel_writers_and_readers, accuracy) cvtest::TS* ts = cvtest::TS::ptr(); // creating VideoWriters - std::vector writers(threadsCount); + std::vector< cv::Ptr > writers(threadsCount); Range range(0, threadsCount); std::vector files(threadsCount); CreateVideoWriterInvoker invoker1(writers, files); @@ -416,11 +416,9 @@ TEST(Videoio_Video_parallel_writers_and_readers, accuracy) parallel_for_(range, WriteVideo_Invoker(writers)); // deleting the writers - for (std::vector::iterator i = writers.begin(), end = writers.end(); i != end; ++i) - delete *i; writers.clear(); - std::vector readers(threadsCount); + std::vector > readers(threadsCount); CreateVideoCaptureInvoker invoker2(readers, files); parallel_for_(range, invoker2); @@ -437,8 +435,7 @@ TEST(Videoio_Video_parallel_writers_and_readers, accuracy) } // delete the readers - for (std::vector::iterator i = readers.begin(), end = readers.end(); i != end; ++i) - delete *i; + readers.clear(); } #endif