blob: 96f071e806969bb6e27b2cc9956cb30fe3ccf520 [file] [log] [blame]
atraczyk14ba30c2016-09-22 18:31:59 -04001/**************************************************************************
2* Copyright (C) 2016 by Savoir-faire Linux *
3* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
4* Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> *
5* *
6* This program is free software; you can redistribute it and/or modify *
7* it under the terms of the GNU General Public License as published by *
8* the Free Software Foundation; either version 3 of the License, or *
9* (at your option) any later version. *
10* *
11* This program is distributed in the hope that it will be useful, *
12* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14* GNU General Public License for more details. *
15* *
16* You should have received a copy of the GNU General Public License *
17* along with this program. If not, see <http://www.gnu.org/licenses/>. *
18**************************************************************************/
19#pragma once
20
21using namespace Windows::UI::Xaml;
22using namespace Windows::ApplicationModel::Core;
23using namespace Windows::Devices::Enumeration;
24using namespace Windows::Media::Capture;
25using namespace Windows::Foundation;
atraczykacc4c412016-11-10 22:56:52 -050026using namespace Windows::UI::Xaml::Controls;
atraczyk14ba30c2016-09-22 18:31:59 -040027using namespace Concurrency;
28
29namespace RingClientUWP
30{
31
32delegate void StartPreviewing();
33delegate void StopPreviewing();
atraczykacc4c412016-11-10 22:56:52 -050034delegate CaptureElement^ GetSink();
35delegate CaptureElement^ GetSettingsPreviewSink();
36delegate void CaptureEnumerationComplete();
atraczyk14ba30c2016-09-22 18:31:59 -040037
38namespace Video
39{
40
41public ref class VideoCaptureManager sealed
42{
atraczyk1e120ad2017-02-15 18:36:49 -050043public:
44 double aspectRatio();
45
atraczyk14ba30c2016-09-22 18:31:59 -040046internal:
47 property bool isPreviewing
48 {
49 bool get() { return isPreviewing_; }
50 void set(bool value) { isPreviewing_ = value; }
51 }
atraczyk1e120ad2017-02-15 18:36:49 -050052
atraczykacc4c412016-11-10 22:56:52 -050053 property bool isSettingsPreviewing
54 {
55 bool get() { return isSettingsPreviewing_; }
56 void set(bool value) { isSettingsPreviewing_ = value; }
57 }
atraczyk14ba30c2016-09-22 18:31:59 -040058
59 Map<String^,String^>^ getSettings(String^ device);
60
61 VideoCaptureManager();
62
atraczyk14ba30c2016-09-22 18:31:59 -040063 Windows::Graphics::Display::DisplayOrientations displayOrientation;
64
65 Windows::System::Display::DisplayRequest^ displayRequest;
66
67 const GUID RotationKey;
68
69 bool externalCamera;
70 bool mirroringPreview;
71 bool isInitialized;
72 bool isChangingCamera;
73 bool isRendering;
74
75 Vector<Device^>^ deviceList;
76 Device^ activeDevice;
77
78 DeviceInformationCollection^ devInfoCollection;
79
80 Platform::Agile<Windows::Media::Capture::MediaCapture^> mediaCapture;
81
atraczykacc4c412016-11-10 22:56:52 -050082 task<void> InitializeCameraAsync(bool isSettingsPreview);
83 task<void> StartPreviewAsync(bool isSettingsPreview);
atraczyk14ba30c2016-09-22 18:31:59 -040084 task<void> StopPreviewAsync();
85 task<void> EnumerateWebcamsAsync();
86 task<void> CleanupCameraAsync();
87
88 // event tokens
89 EventRegistrationToken mediaCaptureFailedEventToken;
atraczyk14ba30c2016-09-22 18:31:59 -040090 EventRegistrationToken visibilityChangedEventToken;
91
92 cancellation_token_source* captureTaskTokenSource;
93
94 void MediaCapture_Failed(MediaCapture ^currentCaptureObject, MediaCaptureFailedEventArgs^ errorEventArgs);
atraczykacc4c412016-11-10 22:56:52 -050095 task<void> AddVideoDeviceAsync(uint8_t index);
atraczyk14ba30c2016-09-22 18:31:59 -040096 void SetCaptureSettings();
97
98 DispatcherTimer^ videoFrameCopyInvoker;
99 task<void> CopyFrameAsync();
100 void CopyFrame(Object^ sender, Object^ e);
atraczyk40afd722016-12-29 19:33:09 -0500101 void InitializeCopyFrameDispatcher(unsigned frameRate);
atraczyk14ba30c2016-09-22 18:31:59 -0400102
103 event StartPreviewing^ startPreviewing;
104 event StopPreviewing^ stopPreviewing;
105 event GetSink^ getSink;
atraczykacc4c412016-11-10 22:56:52 -0500106 event GetSettingsPreviewSink^ getSettingsPreviewSink;
107 event CaptureEnumerationComplete^ captureEnumerationComplete;
atraczyk14ba30c2016-09-22 18:31:59 -0400108
109private:
110 bool isPreviewing_;
atraczykacc4c412016-11-10 22:56:52 -0500111 bool isSettingsPreviewing_;
atraczyk14ba30c2016-09-22 18:31:59 -0400112
113};
114
115} /* namespace Video */
116} /* namespace RingClientUWP */