Skip to content

Commit

Permalink
use VideoFormat in VideoFrame. All parameters are computed by FFmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Nov 9, 2013
1 parent 5f87499 commit 5673c16
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 466 deletions.
23 changes: 22 additions & 1 deletion src/AudioFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,35 @@ class AudioFramePrivate : public FramePrivate
AudioFramePrivate()
: FramePrivate()
{}
virtual ~AudioFramePrivate() {}
~AudioFramePrivate() {}
};

AudioFrame::AudioFrame():
Frame(*new AudioFramePrivate())
{
}

/*!
Constructs a shallow copy of \a other. Since AudioFrame is
explicitly shared, these two instances will reflect the same frame.
*/
AudioFrame::AudioFrame(const AudioFrame &other)
: Frame(other)
{
}

/*!
Assigns the contents of \a other to this video frame. Since AudioFrame is
explicitly shared, these two instances will reflect the same frame.
*/
AudioFrame &AudioFrame::operator =(const AudioFrame &other)
{
d_ptr = other.d_ptr;
return *this;
}

AudioFrame::~AudioFrame()
{
}
Expand Down
58 changes: 38 additions & 20 deletions src/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@

namespace QtAV {

Frame::Frame(const Frame &other)
:d_ptr(other.d_ptr)
{
}

Frame::Frame(FramePrivate &d):
DPTR_INIT(&d)
d_ptr(&d)
{
}

Frame::~Frame()
{
}

Frame &Frame::operator =(const Frame &other)
{
d_ptr = other.d_ptr;
return *this;
}

int Frame::bytesPerLine(int plane) const
Expand All @@ -40,63 +50,69 @@ int Frame::bytesPerLine(int plane) const
qWarning("Invalid plane! Valid range is [0, %d)", planeCount());
return 0;
}
return d_func().line_size[plane];
return d_func()->line_sizes[plane];
}

QByteArray Frame::frameData() const
{
return d_func()->data;
}

QByteArray Frame::data(int plane) const
{
DPTR_D(const Frame);
if (plane < 0 || plane >= planeCount()) {
qWarning("Invalid plane! Valid range is [0, %d)", planeCount());
return QByteArray();
}
return QByteArray((char*)d.planes[plane], bytesPerLine(plane));
return QByteArray((char*)d_func()->planes[plane], bytesPerLine(plane));
}

uchar* Frame::bits(int plane)
{
DPTR_D(Frame);
if (plane < 0 || plane >= planeCount()) {
qWarning("Invalid plane! Valid range is [0, %d)", planeCount());
return 0;
}
return d.planes[plane];
return d_func()->planes[plane];
}

const uchar* Frame::bits(int plane) const
{
DPTR_D(const Frame);
if (plane < 0 || plane >= planeCount()) {
qWarning("Invalid plane! Valid range is [0, %d)", planeCount());
return 0;
}
return d.planes[plane];
return d_func()->planes[plane];
}

void Frame::setBits(uchar *b, int plane)
{
d_func().planes[plane] = b;
Q_D(Frame);
d->planes[plane] = b;
}

void Frame::setBits(const QVector<uchar *> &b)
{
d_func().planes = b;
Q_D(Frame);
d->planes = b;
}

void Frame::setBytesPerLine(int lineSize, int plane)
{
d_func().line_size[plane] = lineSize;
Q_D(Frame);
d->line_sizes[plane] = lineSize;
}

void Frame::setBytesPerLine(const QVector<int> &lineSize)
{
d_func().line_size = lineSize;
Q_D(Frame);
d->line_sizes = lineSize;
}

int Frame::planeCount() const
{
DPTR_D(const Frame);
return d.planes.size();
Q_D(const Frame);
return d->planes.size();
}


Expand All @@ -105,7 +121,8 @@ int Frame::planeCount() const
*/
QVariantMap Frame::availableMetaData() const
{
return d_func().metadata;
Q_D(const Frame);
return d->metadata;
}

/*!
Expand All @@ -119,25 +136,26 @@ QVariantMap Frame::availableMetaData() const
*/
QVariant Frame::metaData(const QString &key) const
{
return d_func().metadata.value(key);
Q_D(const Frame);
return d->metadata.value(key);
}

/*!
Sets the metadata for the given \a key to \a value.
If \a value is a null variant, any metadata for this key will be removed.
If \a value is a null variant, any metadata for this key will be removed->
The producer of the video frame might use this to associate
certain data with this frame, or for an intermediate processor
to add information for a consumer of this frame.
*/
void Frame::setMetaData(const QString &key, const QVariant &value)
{
DPTR_D(Frame);
Q_D(Frame);
if (!value.isNull())
d.metadata.insert(key, value);
d->metadata.insert(key, value);
else
d.metadata.remove(key);
d->metadata.remove(key);
}

} //namespace QtAV
6 changes: 5 additions & 1 deletion src/QtAV/AudioFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ namespace QtAV {
class AudioFramePrivate;
class Q_AV_EXPORT AudioFrame : public Frame
{
DPTR_DECLARE_PRIVATE(AudioFrame)
Q_DECLARE_PRIVATE(AudioFrame)
public:
AudioFrame();
AudioFrame(const AudioFrame &other);
virtual ~AudioFrame();

AudioFrame &operator =(const AudioFrame &other);

};

} //namespace QtAV
Expand Down
12 changes: 8 additions & 4 deletions src/QtAV/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@

#include <QtAV/QtAV_Global.h>
#include <QtCore/QVariant>
#include <QtCore/QSharedData>

// TODO: plane=>channel
namespace QtAV {

class FramePrivate;
class Q_AV_EXPORT Frame
{
DPTR_DECLARE_PRIVATE(Frame)
Q_DECLARE_PRIVATE(Frame)
public:
Frame(const Frame& other);
virtual ~Frame() = 0;
Frame& operator =(const Frame &other);

/*!
* \brief bytesPerLine
Expand All @@ -45,7 +48,9 @@ class Q_AV_EXPORT Frame
*/
int planeCount() const;
virtual int bytesPerLine(int plane = 0) const;
// deep copy the data
// the whole frame data
QByteArray frameData() const;
// deep copy 1 plane data
QByteArray data(int plane = 0) const;
uchar* bits(int plane = 0);
const uchar *bits(int plane = 0) const;
Expand All @@ -69,8 +74,7 @@ class Q_AV_EXPORT Frame

protected:
Frame(FramePrivate &d);
DPTR_DECLARE(Frame)
// QExplicitlySharedDataPointer<QVideoFramePrivate> d;
QExplicitlySharedDataPointer<FramePrivate> d_ptr;
};

} //namespace QtAV
Expand Down
12 changes: 12 additions & 0 deletions src/QtAV/VideoFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QtCore/QSharedDataPointer>
#include <QtCore/QString>
#include <QtGui/QImage>
#include <QtAV/QtAV_Global.h>

namespace QtAV {
Expand Down Expand Up @@ -74,7 +75,14 @@ class Q_AV_EXPORT VideoFormat
Format_User
};

static PixelFormat pixelFormatFromImageFormat(QImage::Format format);
static QImage::Format imageFormatFromPixelFormat(PixelFormat format);
static PixelFormat pixelFormatFromFFmpeg(int ff); //AVPixelFormat
static int pixelFormatToFFmpeg(PixelFormat fmt);

VideoFormat(PixelFormat format = Format_Invalid);
VideoFormat(int formatFF);
VideoFormat(QImage::Format fmt);
VideoFormat(const QString& name);
VideoFormat(const VideoFormat &other);
~VideoFormat();
Expand All @@ -100,6 +108,10 @@ class Q_AV_EXPORT VideoFormat
* \return -1 if not a valid format
*/
int planeCount() const;
/*!
* https://wiki.videolan.org/YUV
* YUV420P: 1pix = 4Y+U+V
*/
int bitsPerPixel() const;
int bitsPerPixelPadded() const;
int bitsPerPixel(int plane) const;
Expand Down
Loading

0 comments on commit 5673c16

Please sign in to comment.