Skip to content

Commit

Permalink
Change VideoReader::get() propertyVal type from double to size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
cudawarped committed Jul 7, 2023
1 parent 395492a commit 00ef267
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions modules/cudacodec/include/opencv2/cudacodec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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. :
Expand Down
17 changes: 9 additions & 8 deletions modules/cudacodec/src/video_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand All @@ -337,7 +337,7 @@ namespace
else
break;
case VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB:
propertyVal = static_cast<double>(rawPackets.size());
propertyVal = rawPackets.size();
return true;
case VideoReaderProps::PROP_RAW_MODE:
propertyVal = videoSource_->RawModeEnabled();
Expand All @@ -349,17 +349,18 @@ namespace
propertyVal = videoParser_->udpSource();
return true;
case VideoReaderProps::PROP_COLOR_FORMAT:
propertyVal = static_cast<double>(colorFormat);
propertyVal = static_cast<size_t>(colorFormat);
return true;
default:
break;
}
return false;
}

bool VideoReaderImpl::rawPackageHasKeyFrame(const int idx) const {
const int iPacket = idx - rawPacketsBaseIdx;
if (videoSource_->RawModeEnabled() && iPacket >= 0 && static_cast<size_t>(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;
Expand Down
33 changes: 16 additions & 17 deletions modules/cudacodec/test/test_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cv::cudacodec::VideoReader> 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));
Expand All @@ -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;
Expand All @@ -157,13 +157,13 @@ CUDA_TEST_P(CheckExtraData, Reader)
cv::cudacodec::VideoReaderInitParams params;
params.rawMode = true;
cv::Ptr<cv::cudacodec::VideoReader> 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<size_t>(1) );
GpuMat frame;
ASSERT_TRUE(reader->nextFrame(frame));
cv::Mat extraData;
const bool newData = reader->retrieve(extraData, static_cast<size_t>(extraDataIdx));
const bool newData = reader->retrieve(extraData, extraDataIdx);
ASSERT_TRUE((newData && sz) || (!newData && !sz));
ASSERT_EQ(extraData.total(), sz);
}
Expand All @@ -181,17 +181,17 @@ CUDA_TEST_P(CheckKeyFrame, Reader)
cv::cudacodec::VideoReaderInitParams params;
params.rawMode = true;
cv::Ptr<cv::cudacodec::VideoReader> 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<size_t>(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<int>(rawIdxBase); i < static_cast<int>(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;
Expand Down Expand Up @@ -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<cudacodec::ColorFormat>(colorFormat) == formatToChannels.first);
ASSERT_TRUE(reader->nextFrame(frame));
const int height = formatToChannels.first == cudacodec::ColorFormat::NV_NV12 ? static_cast<int>(1.5 * fmt.height) : fmt.height;
Expand Down Expand Up @@ -435,18 +435,17 @@ CUDA_TEST_P(VideoReadRaw, Reader)
cv::cudacodec::VideoReaderInitParams params;
params.rawMode = true;
cv::Ptr<cv::cudacodec::VideoReader> 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;
for (int i = 0; i < 100; i++)
{
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<int>(rawIdxBase); j <= static_cast<int>(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());
Expand Down Expand Up @@ -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<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile, {}, params);
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_UDP_SOURCE, udpSource) && static_cast<bool>(udpSource) == params.udpSource);
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_ALLOW_FRAME_DROP, allowFrameDrop) && static_cast<bool>(allowFrameDrop) == params.allowFrameDrop);
Expand Down

0 comments on commit 00ef267

Please sign in to comment.