Skip to content

Commit b3d4b8d

Browse files
committed
Alter live source flag everywhere to indicate what it does not what it is for, which should be left up to the documentation.
1 parent 6c59714 commit b3d4b8d

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

modules/cudacodec/include/opencv2/cudacodec.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ enum class VideoReaderProps {
322322
PROP_LRF_HAS_KEY_FRAME = 5, //!< FFmpeg source only - Indicates whether the Last Raw Frame (LRF), output from VideoReader::retrieve() when VideoReader is initialized in raw mode, contains encoded data for a key frame.
323323
PROP_COLOR_FORMAT = 6, //!< Set the ColorFormat of the decoded frame. This can be changed before every call to nextFrame() and retrieve().
324324
PROP_UDP_SOURCE = 7, //!< Status of VideoReaderInitParams::udpSource initialization.
325-
PROP_LIVE_SOURCE = 8, //!< Status of VideoReaderInitParams::liveSource initialization.
325+
PROP_ALLOW_FRAME_DROP = 8, //!< Status of VideoReaderInitParams::allowFrameDrop initialization.
326326
#ifndef CV_DOXYGEN
327327
PROP_NOT_SUPPORTED
328328
#endif
@@ -472,18 +472,19 @@ class CV_EXPORTS_W RawVideoSource
472472

473473
/** @brief VideoReader initialization parameters
474474
@param udpSource Remove validation which can cause VideoReader() to throw exceptions when reading from a UDP source.
475-
@param liveCapture Prevent delay and eventual disconnection from a live capture source when the rate frames are consumed is less than the rate they are captured.
476-
Use with caution, frames will be dropped when nextFrame()/grab() are called at a slower rate than the source fps.
475+
@param allowFrameDrop Allow frames to be dropped when ingesting from a live capture source to prevent delay and eventual disconnection
476+
when calls to nextFrame()/grab() cannot keep up with the source's fps. Only use if delay and disconnection are a problem, i.e. not when decoding from
477+
video files where setting this flag will cause frames to be unnecessarily discarded.
477478
@param minNumDecodeSurfaces Minimum number of internal decode surfaces used by the hardware decoder. NVDEC will automatically determine the minimum number of
478479
surfaces it requires for correct functionality and optimal video memory usage but not necessarily for best performance, which depends on the design of the
479480
overall application. The optimal number of decode surfaces (in terms of performance and memory utilization) should be decided by experimentation for each application,
480481
but it cannot go below the number determined by NVDEC.
481482
@param rawMode Allow the raw encoded data which has been read up until the last call to grab() to be retrieved by calling retrieve(rawData,RAW_DATA_IDX).
482483
*/
483484
struct CV_EXPORTS_W_SIMPLE VideoReaderInitParams {
484-
CV_WRAP VideoReaderInitParams() : udpSource(false), liveSource(false), minNumDecodeSurfaces(0), rawMode(0) {};
485+
CV_WRAP VideoReaderInitParams() : udpSource(false), allowFrameDrop(false), minNumDecodeSurfaces(0), rawMode(0) {};
485486
CV_PROP_RW bool udpSource;
486-
CV_PROP_RW bool liveSource;
487+
CV_PROP_RW bool allowFrameDrop;
487488
CV_PROP_RW int minNumDecodeSurfaces;
488489
CV_PROP_RW bool rawMode;
489490
};

modules/cudacodec/src/video_parser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545

4646
#ifdef HAVE_NVCUVID
4747

48-
cv::cudacodec::detail::VideoParser::VideoParser(VideoDecoder* videoDecoder, FrameQueue* frameQueue, const bool liveSource, const bool udpSource) :
49-
videoDecoder_(videoDecoder), frameQueue_(frameQueue), liveSource_(liveSource)
48+
cv::cudacodec::detail::VideoParser::VideoParser(VideoDecoder* videoDecoder, FrameQueue* frameQueue, const bool allowFrameDrop, const bool udpSource) :
49+
videoDecoder_(videoDecoder), frameQueue_(frameQueue), allowFrameDrop_(allowFrameDrop)
5050
{
5151
if (udpSource) maxUnparsedPackets_ = 0;
5252
CUVIDPARSERPARAMS params;
@@ -124,7 +124,7 @@ int CUDAAPI cv::cudacodec::detail::VideoParser::HandleVideoSequence(void* userDa
124124
newFormat.height = format->coded_height;
125125
newFormat.displayArea = Rect(Point(format->display_area.left, format->display_area.top), Point(format->display_area.right, format->display_area.bottom));
126126
newFormat.fps = format->frame_rate.numerator / static_cast<float>(format->frame_rate.denominator);
127-
newFormat.ulNumDecodeSurfaces = min(!thiz->liveSource_ ? max(thiz->videoDecoder_->nDecodeSurfaces(), static_cast<int>(format->min_num_decode_surfaces)) :
127+
newFormat.ulNumDecodeSurfaces = min(!thiz->allowFrameDrop_ ? max(thiz->videoDecoder_->nDecodeSurfaces(), static_cast<int>(format->min_num_decode_surfaces)) :
128128
format->min_num_decode_surfaces * 2, 32);
129129
if (format->progressive_sequence)
130130
newFormat.deinterlaceMode = Weave;
@@ -167,7 +167,7 @@ int CUDAAPI cv::cudacodec::detail::VideoParser::HandlePictureDecode(void* userDa
167167

168168
thiz->unparsedPackets_ = 0;
169169

170-
bool isFrameAvailable = thiz->frameQueue_->waitUntilFrameAvailable(picParams->CurrPicIdx, thiz->liveSource_);
170+
bool isFrameAvailable = thiz->frameQueue_->waitUntilFrameAvailable(picParams->CurrPicIdx, thiz->allowFrameDrop_);
171171
if (!isFrameAvailable)
172172
return false;
173173

modules/cudacodec/src/video_parser.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace cv { namespace cudacodec { namespace detail {
5252
class VideoParser
5353
{
5454
public:
55-
VideoParser(VideoDecoder* videoDecoder, FrameQueue* frameQueue, const bool liveSource = false, const bool udpSource = false);
55+
VideoParser(VideoDecoder* videoDecoder, FrameQueue* frameQueue, const bool allowFrameDrop = false, const bool udpSource = false);
5656

5757
~VideoParser()
5858
{
@@ -65,7 +65,7 @@ class VideoParser
6565

6666
bool udpSource() const { return maxUnparsedPackets_ == 0; }
6767

68-
bool liveStream() const { return liveSource_; }
68+
bool allowFrameDrops() const { return allowFrameDrop_; }
6969

7070
private:
7171
VideoDecoder* videoDecoder_ = 0;
@@ -75,7 +75,7 @@ class VideoParser
7575
int maxUnparsedPackets_ = 20;
7676
std::vector<RawPacket> currentFramePackets;
7777
volatile bool hasError_ = false;
78-
bool liveSource_ = false;
78+
bool allowFrameDrop_ = false;
7979

8080
// Called when the decoder encounters a video format change (or initial sequence header)
8181
// This particular implementation of the callback returns 0 in case the video format changes

modules/cudacodec/src/video_reader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace
8686
class VideoReaderImpl : public VideoReader
8787
{
8888
public:
89-
explicit VideoReaderImpl(const Ptr<VideoSource>& source, const int minNumDecodeSurfaces, const bool liveSource = false , const bool udpSource = false);
89+
explicit VideoReaderImpl(const Ptr<VideoSource>& source, const int minNumDecodeSurfaces, const bool allowFrameDrop = false , const bool udpSource = false);
9090
~VideoReaderImpl();
9191

9292
bool nextFrame(GpuMat& frame, Stream& stream) CV_OVERRIDE;
@@ -130,7 +130,7 @@ namespace
130130
return videoSource_->format();
131131
}
132132

133-
VideoReaderImpl::VideoReaderImpl(const Ptr<VideoSource>& source, const int minNumDecodeSurfaces, const bool liveSource, const bool udpSource) :
133+
VideoReaderImpl::VideoReaderImpl(const Ptr<VideoSource>& source, const int minNumDecodeSurfaces, const bool allowFrameDrop, const bool udpSource) :
134134
videoSource_(source),
135135
lock_(0)
136136
{
@@ -143,7 +143,7 @@ namespace
143143
cuSafeCall( cuvidCtxLockCreate(&lock_, ctx) );
144144
frameQueue_.reset(new FrameQueue());
145145
videoDecoder_.reset(new VideoDecoder(videoSource_->format().codec, minNumDecodeSurfaces, ctx, lock_));
146-
videoParser_.reset(new VideoParser(videoDecoder_, frameQueue_, liveSource, udpSource));
146+
videoParser_.reset(new VideoParser(videoDecoder_, frameQueue_, allowFrameDrop, udpSource));
147147
videoSource_->setVideoParser(videoParser_);
148148
videoSource_->start();
149149
}
@@ -303,8 +303,8 @@ namespace
303303
else
304304
break;
305305
}
306-
case VideoReaderProps::PROP_LIVE_SOURCE: {
307-
propertyVal = videoParser_->liveStream();
306+
case VideoReaderProps::PROP_ALLOW_FRAME_DROP: {
307+
propertyVal = videoParser_->allowFrameDrops();
308308
return true;
309309
}
310310
case VideoReaderProps::PROP_UDP_SOURCE: {
@@ -347,7 +347,7 @@ Ptr<VideoReader> cv::cudacodec::createVideoReader(const String& filename, const
347347
videoSource.reset(new CuvidVideoSource(filename));
348348
}
349349

350-
return makePtr<VideoReaderImpl>(videoSource, params.minNumDecodeSurfaces, params.liveSource, params.udpSource);
350+
return makePtr<VideoReaderImpl>(videoSource, params.minNumDecodeSurfaces, params.allowFrameDrop, params.udpSource);
351351
}
352352

353353
Ptr<VideoReader> cv::cudacodec::createVideoReader(const Ptr<RawVideoSource>& source, const VideoReaderInitParams params)

modules/cudacodec/test/test_video.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ CUDA_TEST_P(CheckInitParams, Reader)
360360
const std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "../" + GET_PARAM(1);
361361
cv::cudacodec::VideoReaderInitParams params;
362362
params.udpSource = GET_PARAM(2);
363-
params.liveSource = GET_PARAM(3);
363+
params.allowFrameDrop = GET_PARAM(3);
364364
params.rawMode = GET_PARAM(4);
365-
double udpSource = 0, liveSource = 0, rawMode = 0;
365+
double udpSource = 0, allowFrameDrop = 0, rawMode = 0;
366366
cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile, {}, params);
367367
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_UDP_SOURCE, udpSource) && static_cast<bool>(udpSource) == params.udpSource);
368-
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_LIVE_SOURCE, liveSource) && static_cast<bool>(liveSource) == params.liveSource);
368+
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_ALLOW_FRAME_DROP, allowFrameDrop) && static_cast<bool>(allowFrameDrop) == params.allowFrameDrop);
369369
ASSERT_TRUE(reader->get(cv::cudacodec::VideoReaderProps::PROP_RAW_MODE, rawMode) && static_cast<bool>(rawMode) == params.rawMode);
370370
}
371371

0 commit comments

Comments
 (0)