Skip to content

Commit 00ef267

Browse files
committed
Change VideoReader::get() propertyVal type from double to size_t
1 parent 395492a commit 00ef267

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

modules/cudacodec/include/opencv2/cudacodec.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class CV_EXPORTS_W VideoReader
419419
- Out: Value of the property.
420420
@return `true` unless the property is not supported.
421421
*/
422-
CV_WRAP_AS(getVideoReaderProps) virtual bool get(const VideoReaderProps propertyId, CV_OUT double& propertyVal) const = 0;
422+
CV_WRAP_AS(getVideoReaderProps) virtual bool get(const VideoReaderProps propertyId, CV_OUT size_t& propertyVal) const = 0;
423423

424424
/** @brief Retrieves the specified property used by the VideoSource.
425425
@@ -466,7 +466,7 @@ class CV_EXPORTS_W VideoReader
466466
```
467467
\sa retrieve
468468
*/
469-
CV_WRAP virtual bool rawPackageHasKeyFrame(const int idx) const = 0;
469+
CV_WRAP virtual bool rawPackageHasKeyFrame(const size_t idx) const = 0;
470470
};
471471

472472
/** @brief Interface for video demultiplexing. :

modules/cudacodec/src/video_reader.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ namespace
127127

128128
bool set(const ColorFormat colorFormat_) CV_OVERRIDE;
129129

130-
bool get(const VideoReaderProps propertyId, double& propertyVal) const CV_OVERRIDE;
130+
bool get(const VideoReaderProps propertyId, size_t& propertyVal) const CV_OVERRIDE;
131131

132132
bool get(const int propertyId, double& propertyVal) const CV_OVERRIDE;
133133

134-
bool rawPackageHasKeyFrame(const int idx) const CV_OVERRIDE;
134+
bool rawPackageHasKeyFrame(const size_t idx) const CV_OVERRIDE;
135135

136136
private:
137137
void waitForDecoderInit();
@@ -323,7 +323,7 @@ namespace
323323
return true;
324324
}
325325

326-
bool VideoReaderImpl::get(const VideoReaderProps propertyId, double& propertyVal) const {
326+
bool VideoReaderImpl::get(const VideoReaderProps propertyId, size_t& propertyVal) const {
327327
switch (propertyId)
328328
{
329329
case VideoReaderProps::PROP_EXTRA_DATA_INDEX:
@@ -337,7 +337,7 @@ namespace
337337
else
338338
break;
339339
case VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB:
340-
propertyVal = static_cast<double>(rawPackets.size());
340+
propertyVal = rawPackets.size();
341341
return true;
342342
case VideoReaderProps::PROP_RAW_MODE:
343343
propertyVal = videoSource_->RawModeEnabled();
@@ -349,17 +349,18 @@ namespace
349349
propertyVal = videoParser_->udpSource();
350350
return true;
351351
case VideoReaderProps::PROP_COLOR_FORMAT:
352-
propertyVal = static_cast<double>(colorFormat);
352+
propertyVal = static_cast<size_t>(colorFormat);
353353
return true;
354354
default:
355355
break;
356356
}
357357
return false;
358358
}
359359

360-
bool VideoReaderImpl::rawPackageHasKeyFrame(const int idx) const {
361-
const int iPacket = idx - rawPacketsBaseIdx;
362-
if (videoSource_->RawModeEnabled() && iPacket >= 0 && static_cast<size_t>(iPacket) < rawPackets.size())
360+
bool VideoReaderImpl::rawPackageHasKeyFrame(const size_t idx) const {
361+
if (idx < rawPacketsBaseIdx) return false;
362+
const size_t iPacket = idx - rawPacketsBaseIdx;
363+
if (videoSource_->RawModeEnabled() && iPacket < rawPackets.size())
363364
return rawPackets.at(iPacket).ContainsKeyFrame();
364365
else
365366
return false;

modules/cudacodec/test/test_video.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ CUDA_TEST_P(CheckSet, Reader)
123123

124124
std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + +"../" + GET_PARAM(1);
125125
cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile);
126-
double unsupportedVal = -1;
126+
size_t unsupportedVal = 0;
127127
ASSERT_FALSE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NOT_SUPPORTED, unsupportedVal));
128-
double rawModeVal = -1;
128+
size_t rawModeVal = 0;
129129
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_RAW_MODE, rawModeVal));
130130
ASSERT_FALSE(rawModeVal);
131131
ASSERT_TRUE(reader->set(cv::cudacodec::VideoReaderProps::PROP_RAW_MODE,true));
@@ -134,7 +134,7 @@ CUDA_TEST_P(CheckSet, Reader)
134134
bool rawPacketsAvailable = false;
135135
GpuMat frame;
136136
while (reader->nextFrame(frame)) {
137-
double nRawPackages = -1;
137+
size_t nRawPackages = 0;
138138
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB, nRawPackages));
139139
if (nRawPackages > 0) {
140140
rawPacketsAvailable = true;
@@ -157,13 +157,13 @@ CUDA_TEST_P(CheckExtraData, Reader)
157157
cv::cudacodec::VideoReaderInitParams params;
158158
params.rawMode = true;
159159
cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile, {}, params);
160-
double extraDataIdx = -1;
160+
size_t extraDataIdx = 0;
161161
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_EXTRA_DATA_INDEX, extraDataIdx));
162-
ASSERT_EQ(extraDataIdx, 1 );
162+
ASSERT_EQ(extraDataIdx, static_cast<size_t>(1) );
163163
GpuMat frame;
164164
ASSERT_TRUE(reader->nextFrame(frame));
165165
cv::Mat extraData;
166-
const bool newData = reader->retrieve(extraData, static_cast<size_t>(extraDataIdx));
166+
const bool newData = reader->retrieve(extraData, extraDataIdx);
167167
ASSERT_TRUE((newData && sz) || (!newData && !sz));
168168
ASSERT_EQ(extraData.total(), sz);
169169
}
@@ -181,17 +181,17 @@ CUDA_TEST_P(CheckKeyFrame, Reader)
181181
cv::cudacodec::VideoReaderInitParams params;
182182
params.rawMode = true;
183183
cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile, {}, params);
184-
double rawIdxBase = -1;
184+
size_t rawIdxBase = 0;
185185
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_RAW_PACKAGES_BASE_INDEX, rawIdxBase));
186-
ASSERT_EQ(rawIdxBase, 2);
186+
ASSERT_EQ(rawIdxBase, static_cast<size_t>(2));
187187
constexpr int maxNPackagesToCheck = 2;
188188
int nPackages = 0;
189189
GpuMat frame;
190190
while (nPackages < maxNPackagesToCheck) {
191191
ASSERT_TRUE(reader->nextFrame(frame));
192-
double N = -1;
192+
size_t N = 0;
193193
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB,N));
194-
for (int i = static_cast<int>(rawIdxBase); i < static_cast<int>(N + rawIdxBase); i++) {
194+
for (size_t i = rawIdxBase; i < N + rawIdxBase; i++) {
195195
nPackages++;
196196
const bool containsKeyFrame = reader->rawPackageHasKeyFrame(i);
197197
ASSERT_TRUE((nPackages == 1 && containsKeyFrame) || (nPackages == 2 && !containsKeyFrame)) << "nPackage: " << i;
@@ -304,7 +304,7 @@ CUDA_TEST_P(Video, Reader)
304304
// request a different colour format for each frame
305305
const std::pair< cudacodec::ColorFormat, int>& formatToChannels = formatsToChannels[i % formatsToChannels.size()];
306306
ASSERT_TRUE(reader->set(formatToChannels.first));
307-
double colorFormat;
307+
size_t colorFormat;
308308
ASSERT_TRUE(reader->get(cudacodec::VideoReaderProps::PROP_COLOR_FORMAT, colorFormat) && static_cast<cudacodec::ColorFormat>(colorFormat) == formatToChannels.first);
309309
ASSERT_TRUE(reader->nextFrame(frame));
310310
const int height = formatToChannels.first == cudacodec::ColorFormat::NV_NV12 ? static_cast<int>(1.5 * fmt.height) : fmt.height;
@@ -435,18 +435,17 @@ CUDA_TEST_P(VideoReadRaw, Reader)
435435
cv::cudacodec::VideoReaderInitParams params;
436436
params.rawMode = true;
437437
cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile, {}, params);
438-
double rawIdxBase = -1;
438+
size_t rawIdxBase = 0;
439439
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_RAW_PACKAGES_BASE_INDEX, rawIdxBase));
440440
ASSERT_EQ(rawIdxBase, 2);
441441
cv::cuda::GpuMat frame;
442442
for (int i = 0; i < 100; i++)
443443
{
444444
ASSERT_TRUE(reader->nextFrame(frame));
445445
ASSERT_FALSE(frame.empty());
446-
double N = -1;
447-
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB,N));
448-
ASSERT_TRUE(N >= 0) << N << " < 0";
449-
for (int j = static_cast<int>(rawIdxBase); j <= static_cast<int>(N + rawIdxBase); j++) {
446+
size_t N = 0;
447+
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_NUMBER_OF_RAW_PACKAGES_SINCE_LAST_GRAB, N));
448+
for (size_t j = rawIdxBase; j <= N + rawIdxBase; j++) {
450449
Mat rawPackets;
451450
reader->retrieve(rawPackets, j);
452451
file.write((char*)rawPackets.data, rawPackets.total());
@@ -565,7 +564,7 @@ CUDA_TEST_P(CheckInitParams, Reader)
565564
params.udpSource = GET_PARAM(2);
566565
params.allowFrameDrop = GET_PARAM(3);
567566
params.rawMode = GET_PARAM(4);
568-
double udpSource = 0, allowFrameDrop = 0, rawMode = 0;
567+
size_t udpSource = 0, allowFrameDrop = 0, rawMode = 0;
569568
cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile, {}, params);
570569
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_UDP_SOURCE, udpSource) && static_cast<bool>(udpSource) == params.udpSource);
571570
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_ALLOW_FRAME_DROP, allowFrameDrop) && static_cast<bool>(allowFrameDrop) == params.allowFrameDrop);

0 commit comments

Comments
 (0)