1 //*********************************************************
2 //
3 // Copyright (c) Microsoft. All rights reserved.
4 // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
8 //
9 //*********************************************************
10 
11 //
12 // AdvancedCapture.xaml.h
13 // Declaration of the AdvancedCapture class
14 //
15 
16 #pragma once
17 
18 #include "pch.h"
19 #include "AdvancedCapture.g.h"
20 #include "MainPage.xaml.h"
21 #include <ppl.h>
22 
23 #define VIDEO_FILE_NAME "video.mp4"
24 #define PHOTO_FILE_NAME "photo.jpg"
25 #define TEMP_PHOTO_FILE_NAME "photoTmp.jpg"
26 
27 using namespace concurrency;
28 using namespace Windows::Devices::Enumeration;
29 
30 namespace SDKSample
31 {
32     namespace MediaCapture
33     {
34         /// <summary>
35         /// An empty page that can be used on its own or navigated to within a Frame.
36         /// </summary>
37         [Windows::Foundation::Metadata::WebHostHidden]
38         public ref class AdvancedCapture sealed
39         {
40         public:
41             AdvancedCapture();
42 
43         protected:
44             virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
45             virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
46 
47         private:
48             MainPage^ rootPage;
49             void ScenarioInit();
50             void ScenarioReset();
51 
52             void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args);
53 
54             void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
55 
56             void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
57 
58             void lstEnumedDevices_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
59             void EnumerateWebcamsAsync();
60 
61             void AddEffectToImageStream();
62 
63             void ShowStatusMessage(Platform::String^ text);
64             void ShowExceptionMessage(Platform::Exception^ ex);
65 
66             void EnableButton(bool enabled, Platform::String ^name);
67 
68             task<Windows::Storage::StorageFile^> ReencodePhotoAsync(
69                 Windows::Storage::StorageFile ^tempStorageFile,
70                 Windows::Storage::FileProperties::PhotoOrientation photoRotation);
71             Windows::Storage::FileProperties::PhotoOrientation GetCurrentPhotoRotation();
72             void PrepareForVideoRecording();
73             void DisplayProperties_OrientationChanged(Platform::Object^ sender);
74             Windows::Storage::FileProperties::PhotoOrientation PhotoRotationLookup(
75                 Windows::Graphics::Display::DisplayOrientations displayOrientation, bool counterclockwise);
76             Windows::Media::Capture::VideoRotation VideoRotationLookup(
77                 Windows::Graphics::Display::DisplayOrientations displayOrientation, bool counterclockwise);
78 
79             Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediaCaptureMgr;
80             Windows::Storage::StorageFile^ m_recordStorageFile;
81             bool m_bRecording;
82             bool m_bEffectAdded;
83             bool m_bEffectAddedToRecord;
84             bool m_bEffectAddedToPhoto;
85             bool m_bSuspended;
86             bool m_bPreviewing;
87             DeviceInformationCollection^ m_devInfoCollection;
88             Windows::Foundation::EventRegistrationToken m_eventRegistrationToken;
89             bool m_bRotateVideoOnOrientationChange;
90             bool m_bReversePreviewRotation;
91             Windows::Foundation::EventRegistrationToken m_orientationChangedEventToken;
92             void Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
93         };
94     }
95 }
96