VideoCaptureManager.h 4.06 KB
Newer Older
atraczyk's avatar
atraczyk committed
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
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux                                *
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com>              *
* Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com>          *
*                                                                         *
* 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 3 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, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/
#pragma once

using namespace Windows::UI::Xaml;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Devices::Enumeration;
using namespace Windows::Media::Capture;
using namespace Windows::Foundation;
26
using namespace Windows::UI::Xaml::Controls;
atraczyk's avatar
atraczyk committed
27 28 29 30 31 32 33
using namespace Concurrency;

namespace RingClientUWP
{

delegate void StartPreviewing();
delegate void StopPreviewing();
34 35 36
delegate CaptureElement^ GetSink();
delegate CaptureElement^ GetSettingsPreviewSink();
delegate void CaptureEnumerationComplete();
atraczyk's avatar
atraczyk committed
37 38 39 40 41 42

namespace Video
{

public ref class VideoCaptureManager sealed
{
43 44 45
public:
    double aspectRatio();

atraczyk's avatar
atraczyk committed
46 47 48 49 50 51
internal:
    property bool isPreviewing
    {
        bool get() { return isPreviewing_; }
        void set(bool value) { isPreviewing_ = value; }
    }
52

53 54 55 56 57
    property bool isSettingsPreviewing
    {
        bool get() { return isSettingsPreviewing_; }
        void set(bool value) { isSettingsPreviewing_ = value; }
    }
atraczyk's avatar
atraczyk committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

    Map<String^,String^>^ getSettings(String^ device);

    VideoCaptureManager();

    Windows::Graphics::Display::DisplayOrientations displayOrientation;

    Windows::System::Display::DisplayRequest^ displayRequest;

    const GUID RotationKey;

    bool externalCamera;
    bool mirroringPreview;
    bool isInitialized;
    bool isChangingCamera;
    bool isRendering;

    Vector<Device^>^ deviceList;
    Device^ activeDevice;

    DeviceInformationCollection^ devInfoCollection;

    Platform::Agile<Windows::Media::Capture::MediaCapture^> mediaCapture;

82 83
    task<void> InitializeCameraAsync(bool isSettingsPreview);
    task<void> StartPreviewAsync(bool isSettingsPreview);
atraczyk's avatar
atraczyk committed
84 85 86 87 88 89 90 91 92 93 94
    task<void> StopPreviewAsync();
    task<void> EnumerateWebcamsAsync();
    task<void> CleanupCameraAsync();

    // event tokens
    EventRegistrationToken mediaCaptureFailedEventToken;
    EventRegistrationToken visibilityChangedEventToken;

    cancellation_token_source* captureTaskTokenSource;

    void MediaCapture_Failed(MediaCapture ^currentCaptureObject, MediaCaptureFailedEventArgs^ errorEventArgs);
95
    task<void> AddVideoDeviceAsync(uint8_t index);
atraczyk's avatar
atraczyk committed
96 97 98 99 100
    void SetCaptureSettings();

    DispatcherTimer^ videoFrameCopyInvoker;
    task<void> CopyFrameAsync();
    void CopyFrame(Object^ sender, Object^ e);
101
    void InitializeCopyFrameDispatcher(unsigned frameRate);
atraczyk's avatar
atraczyk committed
102 103 104 105

    event StartPreviewing^ startPreviewing;
    event StopPreviewing^ stopPreviewing;
    event GetSink^ getSink;
106 107
    event GetSettingsPreviewSink^ getSettingsPreviewSink;
    event CaptureEnumerationComplete^ captureEnumerationComplete;
atraczyk's avatar
atraczyk committed
108 109 110

private:
    bool isPreviewing_;
111
    bool isSettingsPreviewing_;
atraczyk's avatar
atraczyk committed
112 113 114 115 116

};

} /* namespace Video */
} /* namespace RingClientUWP */