use qvector instead of raw array

This commit is contained in:
itsmattkc
2019-08-09 07:49:17 +10:00
parent 7a858aeca3
commit dfd33310a2
2 changed files with 7 additions and 62 deletions
+5 -46
View File
@@ -27,46 +27,10 @@
Frame::Frame() :
width_(0),
height_(0),
data_(nullptr)
height_(0)
{
}
Frame::Frame(const Frame &f) :
data_(nullptr)
{
Q_UNUSED(f)
}
Frame::Frame(Frame &&f) :
data_(f.data_)
{
f.data_ = nullptr;
}
Frame &Frame::operator=(const Frame &f)
{
Q_UNUSED(f)
data_ = nullptr;
return *this;
}
Frame &Frame::operator=(Frame &&f)
{
if (&f != this) {
data_ = f.data_;
f.data_ = nullptr;
}
return *this;
}
Frame::~Frame()
{
destroy();
}
const int &Frame::width()
{
return width_;
@@ -109,23 +73,19 @@ void Frame::set_format(const int &format)
uint8_t *Frame::data()
{
return data_;
return data_.data();
}
const uint8_t *Frame::const_data()
{
return data_;
return data_.constData();
}
void Frame::allocate()
{
if (data_ != nullptr) {
destroy();
}
// Assume this frame is intended to be a video frame
if (width_ > 0 && height_ > 0) {
data_ = new uint8_t[PixelService::GetBufferSize(static_cast<olive::PixelFormat>(format_), width_, height_)];
data_.resize(PixelService::GetBufferSize(static_cast<olive::PixelFormat>(format_), width_, height_));
}
// FIXME: Audio sample allocation
@@ -133,6 +93,5 @@ void Frame::allocate()
void Frame::destroy()
{
delete [] data_;
data_ = nullptr;
data_.clear();
}
+2 -16
View File
@@ -22,6 +22,7 @@
#define FRAME_H
#include <memory>
#include <QVector>
#include "common/rational.h"
#include "render/pixelformat.h"
@@ -39,21 +40,6 @@ public:
/// Normal constructor
Frame();
/// Copy constructor
Frame(const Frame& f);
/// Move constructor
Frame(Frame&& f);
/// Copy assignment operator
Frame& operator=(const Frame& f);
/// Move assignment operator
Frame& operator=(Frame&& f);
/// Destructor
~Frame();
/**
* @brief Get frame's width in pixels
*/
@@ -115,7 +101,7 @@ private:
int format_;
uint8_t* data_;
QVector<uint8_t> data_;
rational timestamp_;