1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef DSCAMERASESSION_H |
|
43 #define DSCAMERASESSION_H |
|
44 |
|
45 #include <QtCore/qobject.h> |
|
46 #include <QTime> |
|
47 #include <QUrl> |
|
48 #include <QMutex> |
|
49 |
|
50 #include <experimental/qcamera.h> |
|
51 #include <QtMultimedia/qvideoframe.h> |
|
52 #include <QtMultimedia/qabstractvideosurface.h> |
|
53 #include <QtMultimedia/qvideosurfaceformat.h> |
|
54 |
|
55 #include <tchar.h> |
|
56 #include <dshow.h> |
|
57 #include <objbase.h> |
|
58 #include <initguid.h> |
|
59 #pragma comment(lib, "strmiids.lib") |
|
60 #pragma comment(lib, "ole32.lib") |
|
61 #include <windows.h> |
|
62 |
|
63 #pragma include_alias("dxtrans.h","qedit.h") |
|
64 #define __IDxtCompositor_INTERFACE_DEFINED__ |
|
65 #define __IDxtAlphaSetter_INTERFACE_DEFINED__ |
|
66 #define __IDxtJpeg_INTERFACE_DEFINED__ |
|
67 #define __IDxtKey_INTERFACE_DEFINED__ |
|
68 #include <qedit.h> |
|
69 |
|
70 #define SAFE_RELEASE(x) { if(x) x->Release(); x = NULL; } |
|
71 |
|
72 class DSVideoRenderer; |
|
73 class SampleGrabberCallbackPrivate; |
|
74 |
|
75 QTM_USE_NAMESPACE |
|
76 |
|
77 struct video_buffer { |
|
78 unsigned char* buffer; |
|
79 int length; |
|
80 qint64 time; |
|
81 }; |
|
82 |
|
83 typedef QMap<unsigned int, QList<QSize>> FormatResolutionMap; |
|
84 |
|
85 class DSCameraSession : public QObject |
|
86 { |
|
87 Q_OBJECT |
|
88 public: |
|
89 DSCameraSession(QObject *parent = 0); |
|
90 ~DSCameraSession(); |
|
91 |
|
92 bool deviceReady(); |
|
93 |
|
94 // camera controls |
|
95 |
|
96 int framerate() const; |
|
97 void setFrameRate(int rate); |
|
98 int brightness() const; |
|
99 void setBrightness(int b); |
|
100 int contrast() const; |
|
101 void setContrast(int c); |
|
102 int saturation() const; |
|
103 void setSaturation(int s); |
|
104 int hue() const; |
|
105 void setHue(int h); |
|
106 int sharpness() const; |
|
107 void setSharpness(int s); |
|
108 int zoom() const; |
|
109 void setZoom(int z); |
|
110 bool backlightCompensation() const; |
|
111 void setBacklightCompensation(bool); |
|
112 int whitelevel() const; |
|
113 void setWhitelevel(int w); |
|
114 int rotation() const; |
|
115 void setRotation(int r); |
|
116 bool flash() const; |
|
117 void setFlash(bool f); |
|
118 bool autofocus() const; |
|
119 void setAutofocus(bool f); |
|
120 |
|
121 QSize frameSize() const; |
|
122 void setFrameSize(const QSize& s); |
|
123 void setDevice(const QString &device); |
|
124 QList<QVideoFrame::PixelFormat> supportedPixelFormats(); |
|
125 QVideoFrame::PixelFormat pixelFormat() const; |
|
126 void setPixelFormat(QVideoFrame::PixelFormat fmt); |
|
127 QList<QSize> supportedResolutions(QVideoFrame::PixelFormat format); |
|
128 |
|
129 // media control |
|
130 |
|
131 bool setOutputLocation(const QUrl &sink); |
|
132 QUrl outputLocation() const; |
|
133 qint64 position() const; |
|
134 int state() const; |
|
135 void record(); |
|
136 void pause(); |
|
137 void stop(); |
|
138 |
|
139 void setSurface(QAbstractVideoSurface* surface); |
|
140 |
|
141 void captureImage(const QString &fileName); |
|
142 |
|
143 AM_MEDIA_TYPE StillMediaType; |
|
144 QList<video_buffer*> frames; |
|
145 SampleGrabberCallbackPrivate* StillCapCB; |
|
146 |
|
147 QMutex mutex; |
|
148 |
|
149 Q_SIGNALS: |
|
150 void stateChanged(QCamera::State); |
|
151 void imageCaptured(const QString &fileName, const QImage &img); |
|
152 |
|
153 private Q_SLOTS: |
|
154 void captureFrame(); |
|
155 |
|
156 private: |
|
157 QVideoSurfaceFormat actualFormat; |
|
158 QList<QVideoFrame::PixelFormat> types; |
|
159 |
|
160 QTime timeStamp; |
|
161 bool graph; |
|
162 bool active; |
|
163 bool opened; |
|
164 bool available; |
|
165 QCamera::State m_state; |
|
166 QByteArray m_device; |
|
167 QUrl m_sink; |
|
168 DSVideoRenderer* m_output; |
|
169 QAbstractVideoSurface* m_surface; |
|
170 QVideoFrame::PixelFormat pixelF; |
|
171 QSize m_windowSize; |
|
172 FormatResolutionMap resolutions; |
|
173 |
|
174 ICaptureGraphBuilder2* pBuild; |
|
175 IGraphBuilder* pGraph; |
|
176 IMediaControl* pControl; |
|
177 IBaseFilter* pCap; |
|
178 IBaseFilter* pSG_Filter; |
|
179 IBaseFilter* pNullRenderer; |
|
180 ISampleGrabber* pSG; |
|
181 IAMStreamConfig* pConfig; |
|
182 IAMVideoControl* pVideoControl; |
|
183 IAMVideoProcAmp* pProcAmp; |
|
184 IAMCameraControl* pCameraControl; |
|
185 |
|
186 QString m_snapshot; |
|
187 |
|
188 protected: |
|
189 HRESULT GetPin(IBaseFilter *pFilter,PIN_DIRECTION PinDir,IPin **ppPin); |
|
190 bool createFilterGraph(); |
|
191 void updateProperties(); |
|
192 bool setProperties(); |
|
193 bool openStream(); |
|
194 void closeStream(); |
|
195 bool startStream(); |
|
196 void stopStream(); |
|
197 void suspendStream(); |
|
198 void resumeStream(); |
|
199 }; |
|
200 |
|
201 #endif |
|