NDEVR
API Documentation
LocalPhysicalCameraView.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: LocalPhysicalCameraView
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#define NDEVR_SUPPORTS_LOCAL_CAMERA 1
35#if NDEVR_SUPPORTS_LOCAL_CAMERA
36#include "DesignWidgets/Headers/PhysicalCameraView.h"
37#include "Design/Headers/Camera.h"
38#include "Base/Headers/Pointer.hpp"
39#include "Base/Headers/File.h"
40#include <qglobal.h>
41#include <QCameraDevice>
42class QAudioInput;
43class QImageCapture;
44class QMediaPlayer;
45class QCamera;
46class QCameraDevice;
47class QVideoWidget;
48class QMediaDevices;
49class QGraphicsView;
50class QMediaRecorder;
51class QMediaCaptureSession;
52class QGraphicsLineItem;
53class QCameraInfo;
54class QCameraImageCapture;
55class QVideoEncoderSettings;
56class QAudioEncoderSettings;
57class QImage;
58namespace NDEVR
59{
60#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
61 class QCustomComboBox;
62 class Button;
67 class LOCAL_CAMERA_STREAM_API LocalPhysicalCameraView : public PhysicalCameraView
68 {
69 Q_OBJECT
70 public:
77 LocalPhysicalCameraView(const DynamicPointer<Camera>& camera, QWidget* parent = nullptr);
82 virtual bool setCameraSource(const StringView& connection_id) override;
87 virtual bool setCameraSource(const QCameraDevice& connection_id);
89 virtual void refreshInstance() override;
97 virtual void setCameraZoom(fltp08 zoom) override;
105 virtual void setRemoteSource(const StringView& remote);
109 void findBestFormat(const QCameraDevice& camera_evice);
119 virtual void resizeEvent(QResizeEvent* event) override;
124 bool event(QEvent* event) override;
125 protected slots:
130 void processCapturedImage(int index, const QImage& img);
134 void handleCameraError(int camera_error);
140 void handleScreenshotError(int id, int error, const QString& errorString);
146 void updateCameraState(bool state);
150 void updateRecorderState(int state);
153 protected:
155 void init() override;
162 bool startRecord(const File& file) override;
167 bool finishRecord(File file) override;
173 virtual bool pauseRecord(bool paused, const File& file) override;
178 virtual bool takeImage(const File& file) override;
182 virtual void invertScreenColors(bool invert) override;
183 protected:
185
186 QMediaCaptureSession* m_capture_session = nullptr;
187 QMediaPlayer* m_media_player = nullptr;
188 QCamera* m_q_camera = nullptr;
189 QGraphicsView* m_graphics_view;
190 QAudioInput* m_audio_input = nullptr;
191 QImageCapture* m_image_capture = nullptr;
193 QMediaRecorder* m_media_recorder = nullptr;
195 QGraphicsLineItem* m_cross_hair_x = nullptr;
196 QGraphicsLineItem* m_cross_hair_y = nullptr;
198 };
199
203 {
206 QCameraDevice device;
207 };
208
211 class QMediaDeviceManager : public QObject
212 {
213 Q_OBJECT
214 private:
218 QMediaDeviceManager(QObject* parent = nullptr);
219 public:
223 static QMediaDeviceManager& Default();
228 protected slots:
231 protected:
232 QMediaDevices* m_devices = nullptr;
234 };
235
239 {
240 public:
247 virtual PhysicalCameraView* createView(const DynamicPointer<Camera>& camera, DesignObjectLookup* model_manager, QWidget* parent) override;
254 virtual bool canCreateView(const DynamicPointer<Camera>& camera, DesignObjectLookup* model_manager, bool ignore_active) override;
259 };
260#else
264 class NDEVR_WIDGETS_API LocalPhysicalCameraView : public PhysicalCameraView
265 {
266 Q_OBJECT
267 public:
274 LocalPhysicalCameraView(DynamicPointer<Camera>& camera, QWidget* parent = nullptr);
279 virtual bool setCameraSource(const String& connection_id) override;
284 virtual bool setCameraSource(const QCameraInfo& connection_id);
286 virtual void refreshInstance() override;
288 void setToDefaultCamera();
292 QAudioEncoderSettings audioSettings() const;
296 QVideoEncoderSettings videoSettings() const;
298 virtual ~LocalPhysicalCameraView();
299 protected slots:
304 void processCapturedImage(int index, const QImage& img);
308 void handleCameraError(int camera_error);
309 protected:
314 bool startRecord(const File& file) override;
319 bool finishRecord(const File& file) override;
324 virtual bool takeImage(const File& file) override;
328 virtual void invertScreenColors(bool invert) override;
332 void updateCameraState(int state);
333 protected:
334 File m_screenshot_location;
335 QCamera* m_camera;
336 QCameraImageCapture* imageCapture;
337 QMediaRecorder* mediaRecorder;
338 QVideoWidget* m_video_widget;
339 };
340#endif
341}
342#endif
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core widget that allows the user to click one of many button types.
Definition Button.h:68
A core class where all Design Objects including models, materials, and geometries are stored.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
Provides an interface to PhysicalCameraViewFactory for creating a LocalPhysicalCameraView.
virtual Buffer< DynamicPointer< Camera > > availableCameraStreams() const override
Gets the list of available local camera streams.
virtual PhysicalCameraView * createView(const DynamicPointer< Camera > &camera, DesignObjectLookup *model_manager, QWidget *parent) override
Creates a local camera view for the given camera.
virtual bool canCreateView(const DynamicPointer< Camera > &camera, DesignObjectLookup *model_manager, bool ignore_active) override
Checks whether this factory can create a view for the given camera.
Provides access to a local camera on the system, such as a webcam or camera for a phone.
bool event(QEvent *event) override
Handles general events for the camera view.
QCamera * m_q_camera
The Qt camera device.
Button * m_camera_flash_button
Button for toggling camera flash.
virtual ~LocalPhysicalCameraView()
Destructor.
void handleCameraError(int camera_error)
Handles a camera error.
void updateCameraSourceCombo()
Updates the camera source combo box with available devices.
QCustomComboBox * m_selection_combo
Combo box for selecting camera sources.
QMediaPlayer * m_media_player
The media player for remote sources.
virtual bool setCameraSource(const StringView &connection_id) override
Sets the camera source by connection identifier string.
QGraphicsLineItem * m_cross_hair_x
Horizontal cross-hair overlay line.
LocalPhysicalCameraView()
Default constructor.
QAudioInput * m_audio_input
The audio input for recording.
void processCapturedImage(int index, const QImage &img)
Processes a captured image frame.
void handleVideoError()
Handles a video recording error.
void setToDefaultCamera()
Sets the camera source to the system default camera.
QGraphicsView * m_graphics_view
The graphics view for video display.
bool finishRecord(File file) override
Finishes recording and saves the video file.
virtual void refreshInstance() override
Refreshes the camera instance and reconnects if needed.
virtual bool setCameraSource(const QCameraDevice &connection_id)
Sets the camera source from a QCameraDevice.
void updateCameraState(bool state)
Updates the UI based on the camera active state.
QMediaRecorder * m_media_recorder
The media recorder for video recording.
fltp08 defaultScale() const
Gets the default scale factor for the camera view.
bool startRecord(const File &file) override
Starts recording video to a file.
void updateRecorderState(int state)
Updates the UI based on the recorder state.
virtual void invertScreenColors(bool invert) override
Inverts the screen colors.
LocalVideoRenderer * m_video_widget
The video renderer widget.
virtual void setRemoteSource(const StringView &remote)
Sets a remote media source URL for the camera view.
virtual bool takeImage(const File &file) override
Captures a single image to a file.
virtual void setCameraZoom(fltp08 zoom) override
Sets the zoom level for the camera display.
void findBestFormat(const QCameraDevice &camera_evice)
Selects the best camera format for the given device.
LocalVideoRenderer * videoWidget()
Gets the video renderer widget.
File m_screenshot_location
The file path for screenshot output.
QImageCapture * m_image_capture
The image capture handler.
QGraphicsLineItem * m_cross_hair_y
Vertical cross-hair overlay line.
QMediaCaptureSession * m_capture_session
The media capture session.
void adjustCrossHairs()
Adjusts the cross-hair overlay to match the current view size.
LocalPhysicalCameraView(const DynamicPointer< Camera > &camera, QWidget *parent=nullptr)
Constructs a view for a specific camera.
virtual void resizeEvent(QResizeEvent *event) override
Handles resize events by adjusting the video and cross-hairs.
void init() override
Initializes the camera view UI and connections.
virtual bool pauseRecord(bool paused, const File &file) override
Pauses or resumes recording.
void updateRecorderTimespan()
Updates the displayed recording timespan.
void handleScreenshotError(int id, int error, const QString &errorString)
Handles a screenshot capture error.
A QGraphicsVideoItem subclass that provides custom rendering for local camera video streams.
Factory for creating PhysicalCameraView instances and querying supported output formats.
A Viewport that represents a physical camera stream, or real world camera view.
virtual ConstPointer< Camera > camera() const override
Returns a read-only pointer to the Camera.
PhysicalCameraView()
Default constructor for subclass use only.
A compact way to present a list of options to the user.
const Buffer< MediaDeviceInfo > & cameraDevices() const
Gets the list of available camera devices.
QMediaDevices * m_devices
The Qt media devices monitor.
static QMediaDeviceManager & Default()
Gets the singleton instance.
Buffer< MediaDeviceInfo > m_camera_devices
The cached list of camera devices.
void updateCameraSources()
Refreshes the list of available camera sources.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
double fltp08
Defines an alias representing an 8 byte floating-point number.
Stores information about a media capture device (camera).
TranslatedString name
The translated display name of the device.
String id
The unique identifier for the device.
QCameraDevice device
The Qt camera device descriptor.