Skip to content

Commit 6573353

Browse files
committed
Replace internal raw pointer with vect.
1 parent 66809ea commit 6573353

File tree

3 files changed

+10
-37
lines changed

3 files changed

+10
-37
lines changed

modules/cudacodec/src/frame_queue.cpp

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

4646
#ifdef HAVE_NVCUVID
4747

48-
RawPacket::RawPacket(const unsigned char* _data, const size_t _size, const bool _containsKeyFrame) : size(_size), containsKeyFrame(_containsKeyFrame) {
49-
data = new unsigned char[size];
50-
memcpy(data, _data, size);
51-
};
52-
53-
RawPacket::~RawPacket() {
54-
if (data) delete[] data;
55-
}
56-
57-
RawPacket::RawPacket(const RawPacket& other) : RawPacket(other.data, other.size, other.containsKeyFrame) {
58-
}
59-
60-
RawPacket::RawPacket(RawPacket&& other) noexcept : data(std::exchange(other.data, nullptr)), size(std::exchange(other.size, 0)),
61-
containsKeyFrame(std::exchange(other.containsKeyFrame, false)) {
62-
}
63-
64-
RawPacket& RawPacket::operator=(const RawPacket& other) {
65-
return *this = RawPacket(other);
66-
}
67-
68-
RawPacket& RawPacket::operator=(RawPacket&& other) noexcept {
69-
std::swap(data, other.data);
70-
size = other.size;
71-
containsKeyFrame = other.containsKeyFrame;
72-
return *this;
73-
}
48+
RawPacket::RawPacket(const unsigned char* data_, const size_t size, const bool containsKeyFrame_) :
49+
data(data_,data_ + size), containsKeyFrame(containsKeyFrame_) {};
7450

7551
cv::cudacodec::detail::FrameQueue::~FrameQueue() {
7652
if (isFrameInUse_)

modules/cudacodec/src/frame_queue.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,12 @@
5050
class RawPacket {
5151
public:
5252
RawPacket(const unsigned char* _data, const size_t _size = 0, const bool _containsKeyFrame = false);
53-
~RawPacket();
54-
RawPacket(const RawPacket& other);
55-
RawPacket(RawPacket&& other) noexcept;
56-
RawPacket& operator=(const RawPacket& other);
57-
RawPacket& operator=(RawPacket&& other) noexcept;
58-
unsigned char* Data() const { return data; }
59-
size_t size = 0;
60-
bool containsKeyFrame = false;
53+
const unsigned char* Data() const noexcept { return data.data(); }
54+
size_t Size() const noexcept { return data.size(); }
55+
bool ContainsKeyFrame() const noexcept { return containsKeyFrame; }
6156
private:
62-
unsigned char* data = 0;
57+
std::vector<unsigned char> data;
58+
bool containsKeyFrame = false;
6359
};
6460

6561
namespace cv { namespace cudacodec { namespace detail {

modules/cudacodec/src/video_reader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ namespace
254254
if (idx >= rawPacketsBaseIdx && idx < rawPacketsBaseIdx + rawPackets.size()) {
255255
if (!frame.isMat())
256256
CV_Error(Error::StsUnsupportedFormat, "Raw data is stored on the host and must be retrieved using a cv::Mat");
257-
Mat tmp(1, rawPackets.at(idx - rawPacketsBaseIdx).size, CV_8UC1, rawPackets.at(idx - rawPacketsBaseIdx).Data(), rawPackets.at(idx - rawPacketsBaseIdx).size);
257+
const size_t i = idx - rawPacketsBaseIdx;
258+
Mat tmp(1, rawPackets.at(i).Size(), CV_8UC1, const_cast<unsigned char*>(rawPackets.at(i).Data()), rawPackets.at(i).Size());
258259
frame.getMatRef() = tmp;
259260
}
260261
}
@@ -299,7 +300,7 @@ namespace
299300
case VideoReaderProps::PROP_LRF_HAS_KEY_FRAME: {
300301
const int iPacket = propertyVal - rawPacketsBaseIdx;
301302
if (videoSource_->RawModeEnabled() && iPacket >= 0 && iPacket < rawPackets.size()) {
302-
propertyVal = rawPackets.at(iPacket).containsKeyFrame;
303+
propertyVal = rawPackets.at(iPacket).ContainsKeyFrame();
303304
return true;
304305
}
305306
else

0 commit comments

Comments
 (0)