1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/* CamStream: a collection of GUI webcam tools
Copyright (C) 2002-2005 Nemosoft Unv.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For questions, remarks, patches, etc. for this program, the author can be
reached at camstream@smcc.demon.nl.
*/
/**
\class CVideoFrame
CVideoFrame holds a single image from a video stream. It can hold
the RGB or YUV image (or both). It contains sequence number and timestamp
fields.
The classes uses shared data, so passing copies of the class around does
not incur a penalty. However, changes to the image data will be reflected
by all shared objects!
*/
#include "VideoFrame.h"
CVideoFrame::CVideoFrame(uint number, const QImage *rgb, const QImage *y, const QImage *u, const QImage *v)
{
data = new VideoDataShared;
if (data == 0)
return;
data->RGB = rgb;
data->Y = y;
data->U = u;
data->V = v;
data->sequence = 0;
data->time_stamp = 0;
m_Number = number;
}
CVideoFrame::CVideoFrame(const CVideoFrame &f)
{
data = f.data;
if (data != 0)
{
data->ref();
}
}
CVideoFrame::~CVideoFrame()
{
if (data && data->deref()) {
delete data;
data = 0;
}
}
// private
uint CVideoFrame::GetRefCount() const
{
if (data != 0)
return 0;
return data->count;
}
// public
CVideoFrame &CVideoFrame::operator =(const CVideoFrame &f)
{
if (f.data == 0)
return *this;
f.data->ref();
if (data && data->deref()) {
delete data;
data = 0;
}
data = f.data;
return *this;
}
const QImage *CVideoFrame::GetRGB() const
{
return data->RGB;
}
const QImage *CVideoFrame::GetY() const
{
return data->Y;
}
const QImage *CVideoFrame::GetU() const
{
return data->U;
}
const QImage *CVideoFrame::GetV() const
{
return data->V;
}
uint CVideoFrame::GetNumber() const
{
return m_Number;
}
void CVideoFrame::SetSequence(unsigned long seq)
{
data->sequence = seq;
}
/**
\brief Get sequence number
VideoFrames are sequentially numbered as they are fetches from videodevice
or file. The sequence number is a monotonous increasing number.
Note: when fetching frames from a video device, sequence numbers are not
contiguous in case frames are dropped by the capture process.
*/
unsigned long CVideoFrame::GetSequence() const
{
return data->sequence;
}
void CVideoFrame::SetTimeStamp(unsigned long stamp)
{
data->time_stamp = stamp;
}
/**
\brief Get time stamp
\return Time in milliseconds
VideoFrames are time stamped, to make it easier to order/reference them. The
timestamp is measured in milliseconds.
Note: The first video frame of a video sequence is not guaranteed to have a
timestamp of 0! The only guarantee you have is that the timestamp is a monotonous
increasing number.
*/
unsigned long CVideoFrame::GetTimeStamp() const
{
return data->time_stamp;
}
|