diff --git a/modules/cudacodec/include/opencv2/cudacodec.hpp b/modules/cudacodec/include/opencv2/cudacodec.hpp index b718b967159..6194081aaca 100644 --- a/modules/cudacodec/include/opencv2/cudacodec.hpp +++ b/modules/cudacodec/include/opencv2/cudacodec.hpp @@ -419,7 +419,7 @@ class CV_EXPORTS_W VideoReader - Out: Value of the property. @return `true` unless the property is not supported. */ - CV_WRAP_AS(getVideoReaderProps) virtual bool get(const VideoReaderProps propertyId, CV_OUT double& propertyVal) const = 0; + CV_WRAP_AS(getVideoReaderProps) virtual bool get(const VideoReaderProps propertyId, CV_OUT size_t& propertyVal) const = 0; /** @brief Retrieves the specified property used by the VideoSource. @@ -466,7 +466,7 @@ class CV_EXPORTS_W VideoReader ``` \sa retrieve */ - CV_WRAP virtual bool rawPackageHasKeyFrame(const int idx) const = 0; + CV_WRAP virtual bool rawPackageHasKeyFrame(const size_t idx) const = 0; }; /** @brief Interface for video demultiplexing. : diff --git a/modules/cudacodec/src/video_reader.cpp b/modules/cudacodec/src/video_reader.cpp index c3b31f35d99..5e740ae8693 100644 --- a/modules/cudacodec/src/video_reader.cpp +++ b/modules/cudacodec/src/video_reader.cpp @@ -127,11 +127,11 @@ namespace bool set(const ColorFormat colorFormat_) CV_OVERRIDE; - bool get(const VideoReaderProps propertyId, double& propertyVal) const CV_OVERRIDE; + bool get(const VideoReaderProps propertyId, size_t& propertyVal) const CV_OVERRIDE; bool get(const int propertyId, double& propertyVal) const CV_OVERRIDE; - bool rawPackageHasKeyFrame(const int idx) const CV_OVERRIDE; + bool rawPackageHasKeyFrame(const size_t idx) const CV_OVERRIDE; private: void waitForDecoderInit(); @@ -323,7 +323,7 @@ namespace return true; } - bool VideoReaderImpl::get(const VideoReaderProps propertyId, double& propertyVal) const { + bool VideoReaderImpl::get(const VideoReaderProps propertyId, size_t& propertyVal) const { switch (propertyId) { case VideoReaderProps::PROP_EXTRA_DATA_INDEX: @@ -337,7 +337,7 @@ namespace else break; case VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB: - propertyVal = static_cast(rawPackets.size()); + propertyVal = rawPackets.size(); return true; case VideoReaderProps::PROP_RAW_MODE: propertyVal = videoSource_->RawModeEnabled(); @@ -349,7 +349,7 @@ namespace propertyVal = videoParser_->udpSource(); return true; case VideoReaderProps::PROP_COLOR_FORMAT: - propertyVal = static_cast(colorFormat); + propertyVal = static_cast(colorFormat); return true; default: break; @@ -357,9 +357,10 @@ namespace return false; } - bool VideoReaderImpl::rawPackageHasKeyFrame(const int idx) const { - const int iPacket = idx - rawPacketsBaseIdx; - if (videoSource_->RawModeEnabled() && iPacket >= 0 && static_cast(iPacket) < rawPackets.size()) + bool VideoReaderImpl::rawPackageHasKeyFrame(const size_t idx) const { + if (idx < rawPacketsBaseIdx) return false; + const size_t iPacket = idx - rawPacketsBaseIdx; + if (videoSource_->RawModeEnabled() && iPacket < rawPackets.size()) return rawPackets.at(iPacket).ContainsKeyFrame(); else return false; diff --git a/modules/cudacodec/test/test_video.cpp b/modules/cudacodec/test/test_video.cpp index 4123390c1cb..43e17c06fa6 100644 --- a/modules/cudacodec/test/test_video.cpp +++ b/modules/cudacodec/test/test_video.cpp @@ -123,9 +123,9 @@ CUDA_TEST_P(CheckSet, Reader) std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + +"../" + GET_PARAM(1); cv::Ptr reader = cv::cudacodec::createVideoReader(inputFile); - double unsupportedVal = -1; + size_t unsupportedVal = 0; ASSERT_FALSE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NOT_SUPPORTED, unsupportedVal)); - double rawModeVal = -1; + size_t rawModeVal = 0; ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_RAW_MODE, rawModeVal)); ASSERT_FALSE(rawModeVal); ASSERT_TRUE(reader->set(cv::cudacodec::VideoReaderProps::PROP_RAW_MODE,true)); @@ -134,7 +134,7 @@ CUDA_TEST_P(CheckSet, Reader) bool rawPacketsAvailable = false; GpuMat frame; while (reader->nextFrame(frame)) { - double nRawPackages = -1; + size_t nRawPackages = 0; ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB, nRawPackages)); if (nRawPackages > 0) { rawPacketsAvailable = true; @@ -157,13 +157,13 @@ CUDA_TEST_P(CheckExtraData, Reader) cv::cudacodec::VideoReaderInitParams params; params.rawMode = true; cv::Ptr reader = cv::cudacodec::createVideoReader(inputFile, {}, params); - double extraDataIdx = -1; + size_t extraDataIdx = 0; ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_EXTRA_DATA_INDEX, extraDataIdx)); - ASSERT_EQ(extraDataIdx, 1 ); + ASSERT_EQ(extraDataIdx, static_cast(1) ); GpuMat frame; ASSERT_TRUE(reader->nextFrame(frame)); cv::Mat extraData; - const bool newData = reader->retrieve(extraData, static_cast(extraDataIdx)); + const bool newData = reader->retrieve(extraData, extraDataIdx); ASSERT_TRUE((newData && sz) || (!newData && !sz)); ASSERT_EQ(extraData.total(), sz); } @@ -181,17 +181,17 @@ CUDA_TEST_P(CheckKeyFrame, Reader) cv::cudacodec::VideoReaderInitParams params; params.rawMode = true; cv::Ptr reader = cv::cudacodec::createVideoReader(inputFile, {}, params); - double rawIdxBase = -1; + size_t rawIdxBase = 0; ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_RAW_PACKAGES_BASE_INDEX, rawIdxBase)); - ASSERT_EQ(rawIdxBase, 2); + ASSERT_EQ(rawIdxBase, static_cast(2)); constexpr int maxNPackagesToCheck = 2; int nPackages = 0; GpuMat frame; while (nPackages < maxNPackagesToCheck) { ASSERT_TRUE(reader->nextFrame(frame)); - double N = -1; + size_t N = 0; ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB,N)); - for (int i = static_cast(rawIdxBase); i < static_cast(N + rawIdxBase); i++) { + for (size_t i = rawIdxBase; i < N + rawIdxBase; i++) { nPackages++; const bool containsKeyFrame = reader->rawPackageHasKeyFrame(i); ASSERT_TRUE((nPackages == 1 && containsKeyFrame) || (nPackages == 2 && !containsKeyFrame)) << "nPackage: " << i; @@ -304,7 +304,7 @@ CUDA_TEST_P(Video, Reader) // request a different colour format for each frame const std::pair< cudacodec::ColorFormat, int>& formatToChannels = formatsToChannels[i % formatsToChannels.size()]; ASSERT_TRUE(reader->set(formatToChannels.first)); - double colorFormat; + size_t colorFormat; ASSERT_TRUE(reader->get(cudacodec::VideoReaderProps::PROP_COLOR_FORMAT, colorFormat) && static_cast(colorFormat) == formatToChannels.first); ASSERT_TRUE(reader->nextFrame(frame)); const int height = formatToChannels.first == cudacodec::ColorFormat::NV_NV12 ? static_cast(1.5 * fmt.height) : fmt.height; @@ -435,7 +435,7 @@ CUDA_TEST_P(VideoReadRaw, Reader) cv::cudacodec::VideoReaderInitParams params; params.rawMode = true; cv::Ptr reader = cv::cudacodec::createVideoReader(inputFile, {}, params); - double rawIdxBase = -1; + size_t rawIdxBase = 0; ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_RAW_PACKAGES_BASE_INDEX, rawIdxBase)); ASSERT_EQ(rawIdxBase, 2); cv::cuda::GpuMat frame; @@ -443,10 +443,9 @@ CUDA_TEST_P(VideoReadRaw, Reader) { ASSERT_TRUE(reader->nextFrame(frame)); ASSERT_FALSE(frame.empty()); - double N = -1; - ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB,N)); - ASSERT_TRUE(N >= 0) << N << " < 0"; - for (int j = static_cast(rawIdxBase); j <= static_cast(N + rawIdxBase); j++) { + size_t N = 0; + ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB, N)); + for (size_t j = rawIdxBase; j <= N + rawIdxBase; j++) { Mat rawPackets; reader->retrieve(rawPackets, j); file.write((char*)rawPackets.data, rawPackets.total()); @@ -565,7 +564,7 @@ CUDA_TEST_P(CheckInitParams, Reader) params.udpSource = GET_PARAM(2); params.allowFrameDrop = GET_PARAM(3); params.rawMode = GET_PARAM(4); - double udpSource = 0, allowFrameDrop = 0, rawMode = 0; + size_t udpSource = 0, allowFrameDrop = 0, rawMode = 0; cv::Ptr reader = cv::cudacodec::createVideoReader(inputFile, {}, params); ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_UDP_SOURCE, udpSource) && static_cast(udpSource) == params.udpSource); ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_ALLOW_FRAME_DROP, allowFrameDrop) && static_cast(allowFrameDrop) == params.allowFrameDrop);