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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
/* CVideoDevice: video capture base class
part of CamStream: a collection of GUI webcam tools
Copyright (C) 2002 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.
*/
#ifndef VIDEO_DEVICE_HPP
#define VIDEO_DEVICE_HPP
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <qglobal.h>
#if (QT_VERSION >= 0x030000)
#include <qmutex.h>
#endif
#include <qarray.h>
#include <qcolor.h>
#include <qdom.h>
#include <qimage.h>
#include <qlist.h>
#include <qobject.h>
#include <qsocketnotifier.h>
#include <qtimer.h>
#include <qthread.h>
#include <qvector.h>
#include "VideoFrame.h"
#include "TVChannel.h"
class CChannelEditorDlg;
class CVideoDevice: public QObject, protected QThread
{
friend class CVideoCollector;
Q_OBJECT
public:
enum Signals {
frame_ready = 1,
};
private:
enum Palettes {
RGB,
YUV,
};
QList<CVideoFrame> m_VideoFrames;
QList<CVideoFrame> m_EmptyFrames, m_FullFrames;
CVideoFrame *m_pFillFrame; ///< Pointer to frame that can be filled.
QMutex m_BufMutex; ///< Lock when you're about to manipulate m_CurBuffer or access an image
/// QWaitCondition m_WaitForEmpty;
QWaitCondition m_WaitFromFrame;
CChannelEditorDlg *m_pTunerDlg;
int m_CaptureCount;
void IncrementPalette(Palettes);
void DecrementPalette(Palettes);
void ParseTVChannels(const QDomNode &);
void GetTVChannels(QDomNode &) const;
private slots:
virtual void NewFrequency(float) = 0;
void NewCurrentChannel();
protected:
QList<TVChannel> m_TVChannels;
bool m_Validated;
QString m_NodeName, m_IntfName, m_SerialNumber;
bool m_HasDisplayDialog, m_HasFormatDialog, m_HasSourceDialog, m_HasTunerDialog;
bool m_Mutable;
int m_OpenCount;
int m_PalRGB; ///< RGB images are requested
int m_PalYUV; ///< YUV images are requested
uint m_RequestedBuffers, m_Buffers;
int m_FrameCount; ///< Reset at \ref Open()
int m_FrameDropped;
QSize m_ImageSize;
QVector<QImage> m_RGB;
QVector<QImage> m_Y, m_U, m_V;
QImage *m_pNullImage;
QRgb m_GrayScale[256];
int GetCaptureCount() const;
virtual bool Init() = 0;
virtual void Exit() = 0;
virtual void CreateImagesRGB() = 0;
virtual void DeleteImagesRGB() = 0;
virtual void CreateImagesYUV() = 0;
virtual void DeleteImagesYUV() = 0;
void CreateVideoFrames();
void DeleteVideoFrames();
CVideoFrame *GetFillFrame();
void ReturnFillFrame(bool filled = true);
virtual bool StartCapture() = 0;
virtual void StopCapture() = 0;
void SendSignal(Signals s);
public:
enum ErrorCodes {
NoError,
SizeChangeFailed,
};
CVideoDevice();
virtual ~CVideoDevice();
virtual bool event(QEvent *);
virtual void SetConfiguration(const QDomNode &);
virtual void GetConfiguration(QDomNode &) const;
bool IsValid() const;
bool Open(uint buffers = 0);
void Close();
bool IsOpen() const;
virtual int GetNumberOfInputs() const = 0;
/**
\brief Select an input
\param input The input to use. Between 0 and GetNumberOfInputs()
This will select an input on your TV card. Most cards have more
than one input, for example S-VHS, composite and tuner. Even if you
have only one input, you may want to select it so it gets initialized
properly.
\note \ref GetConfiguration() and \ref SetConfiguration() will remember
the selected input.
*/
virtual void SetInput(int input) = 0;
/**
\brief Get currently selected input
\return A positive integer, or -1 in case input is unknown
Returns the number of the currently selected input (if known). Otherwise
returns -1.
Usually this variable will be initialized during SetConfiguration().
*/
virtual int GetInput() const = 0;
/**
\brief Get number of tuners attached to this video device
\return A positive integer
When you use a TV card, it has a tuner on board which you can use to
select a frequency to watch. This function tells the number of tuners
attached. Rarely this will be larger than 1.
You may have to select a specific input to watch TV; some cards also
have S-VHS or composite input. Unfortunately it is not possible to
determine to which input a tuner is attached.
*/
virtual int GetNumberOfTuners() const = 0;
/**
\brief Select a tuner
\param tuner The tuner to use. between 0 and GetNumberOfTuners()
This will select a tuner. Even if you have only one tuner, you may want
to select it so it gets initialized properly.
\note \ref GetConfiguration() and \ref SetConfiguration() will remember
the selected tuner.
*/
virtual void SetTuner(int tuner) = 0;
virtual int GetTuner() const = 0;
unsigned int GetNumberOfTVChannels() const;
TVChannel QueryTVChannel(unsigned int preset);
TVChannel GetCurrentTVChannel() const;
TVChannel SelectTVChannel(unsigned int preset);
TVChannel SelectNextTVChannel(bool wrap = true);
TVChannel SelectPrevTVChannel(bool wrap = true);
/** \brief System dependant descriptor to device.
File descriptor under Unix, WHND under Windows; should be casted
to apropriate type.
Only valid when the device is open!
*/
virtual long GetDescriptor() const = 0;
QString GetNodeName() const;
QString GetIntfName() const;
QString GetSerialNumber() const;
int GetBuffers() const;
CVideoFrame *GetLatestVideoFrame(int backlog = 0);
bool HasDisplayDialog() const;
bool HasFormatDialog() const;
bool HasSourceDialog() const;
bool HasTunerDialog() const;
virtual QSize GetSize() const;
// Do we need these?
bool IsMutable() const;
virtual void Mute(bool on) const = 0;
public slots:
virtual void ShowDisplayDialog() = 0;
virtual void ShowFormatDialog() = 0;
virtual void ShowSourceDialog() = 0;
virtual void ShowTunerDialog();
void EnableRGB();
void DisableRGB();
void EnableYUV();
void DisableYUV();
signals:
/** The device is being opened by the first user; the device is now ready and streaming */
void Opened();
/** The device is being closed by the last user; the device is not accessible */
void Closed();
/** New size */
void SizeChanged(const QSize &);
/** New framerate */
void FramerateChanged(int rate);
/** An error occured. err_num is one of the errno values. */
void Error(int err_num);
/** One ore more new image(s) is(are) available. */
void FrameReady();
/** A new TV channel (frequency) was selected */
void TVChannelChanged();
};
#endif
|