Commit 49903367 authored by Alexander Smorkalov's avatar Alexander Smorkalov

Base camera access sample for Windows RT added.

Microsoft Media Foundation Camera Sample for Windows RT added.
parent ee591efb
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<common:LayoutAwarePage
x:Class="SDKSample.MediaCapture.AdvancedCapture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:$rootsnamespace$"
xmlns:common="using:SDKSample.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="Input" Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Text="This scenario shows how to enumerate cameras in the system. Choose a camera from the list to preview, record or take a photo from the chosen camera. You can add the gray scale effect using the checkbox provided." Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left"/>
<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="0,10,0,0">
<ListBox x:Name="EnumedDeviceList2" SelectionChanged="lstEnumedDevices_SelectionChanged" ></ListBox>
<Button x:Name="btnStartDevice2" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0">StartDevice</Button>
<Button x:Name="btnStartPreview2" Click="btnStartPreview_Click" IsEnabled="true" Margin="0,0,10,0">StartPreview</Button>
<Button x:Name="btnStartStopRecord2" Click="btnStartStopRecord_Click" IsEnabled="false" Margin="0,0,10,0">StartRecord</Button>
<Button x:Name="btnTakePhoto2" Click="btnTakePhoto_Click" IsEnabled="false" Margin="0,0,10,0">TakePhoto</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="0,10,0,0">
<CheckBox x:Name="chkAddRemoveEffect" Margin="0,0,10,0" Content="Grayscale Effect" IsEnabled="False" Checked="chkAddRemoveEffect_Checked" Unchecked="chkAddRemoveEffect_Unchecked"/>
</StackPanel>
</Grid>
<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Preview' />
<Canvas x:Name="previewCanvas2" Width="320" Height="240" Background="Gray">
<CaptureElement x:Name="previewElement2" Width="320" Height="240" />
</Canvas>
</StackPanel>
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Video' />
<Canvas x:Name='playbackCanvas2' Width='320' Height ='240' >
<MediaElement x:Name='playbackElement2' Width="320" Height="240" />
</Canvas>
</StackPanel>
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Images' />
<Canvas x:Name="imageCanvas2" Width='320' Height ='240' >
<Image x:Name="imageElement2" Width="320" Height="240"/>
</Canvas>
</StackPanel>
</StackPanel>
</Grid>
<!-- Add Storyboards to the visual states below as necessary for supporting the various layouts -->
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="FullScreenLandscape"/>
<VisualState x:Name="Filled"/>
<VisualState x:Name="FullScreenPortrait"/>
<VisualState x:Name="Snapped"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</common:LayoutAwarePage>
This diff is collapsed.
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
// AdvancedCapture.xaml.h
// Declaration of the AdvancedCapture class
//
#pragma once
#include "pch.h"
#include "AdvancedCapture.g.h"
#include "MainPage.xaml.h"
#include <ppl.h>
#define VIDEO_FILE_NAME "video.mp4"
#define PHOTO_FILE_NAME "photo.jpg"
#define TEMP_PHOTO_FILE_NAME "photoTmp.jpg"
using namespace concurrency;
using namespace Windows::Devices::Enumeration;
namespace SDKSample
{
namespace MediaCapture
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[Windows::Foundation::Metadata::WebHostHidden]
public ref class AdvancedCapture sealed
{
public:
AdvancedCapture();
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
private:
MainPage^ rootPage;
void ScenarioInit();
void ScenarioReset();
void SoundLevelChanged(Object^ sender, Object^ e);
void RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^ mediaCapture);
void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args);
void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void lstEnumedDevices_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void EnumerateWebcamsAsync();
void chkAddRemoveEffect_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void chkAddRemoveEffect_Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void AddEffectToImageStream();
void ShowStatusMessage(Platform::String^ text);
void ShowExceptionMessage(Platform::Exception^ ex);
void EnableButton(bool enabled, Platform::String ^name);
void SwitchRecordButtonContent();
task<Windows::Storage::StorageFile^> ReencodePhotoAsync(
Windows::Storage::StorageFile ^tempStorageFile,
Windows::Storage::FileProperties::PhotoOrientation photoRotation);
Windows::Storage::FileProperties::PhotoOrientation GetCurrentPhotoRotation();
void PrepareForVideoRecording();
void DisplayProperties_OrientationChanged(Platform::Object^ sender);
Windows::Storage::FileProperties::PhotoOrientation PhotoRotationLookup(
Windows::Graphics::Display::DisplayOrientations displayOrientation, bool counterclockwise);
Windows::Media::Capture::VideoRotation VideoRotationLookup(
Windows::Graphics::Display::DisplayOrientations displayOrientation, bool counterclockwise);
Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediaCaptureMgr;
Windows::Storage::StorageFile^ m_recordStorageFile;
bool m_bRecording;
bool m_bEffectAdded;
bool m_bEffectAddedToRecord;
bool m_bEffectAddedToPhoto;
bool m_bSuspended;
bool m_bPreviewing;
DeviceInformationCollection^ m_devInfoCollection;
Windows::Foundation::EventRegistrationToken m_eventRegistrationToken;
bool m_bRotateVideoOnOrientationChange;
bool m_bReversePreviewRotation;
Windows::Foundation::EventRegistrationToken m_orientationChangedEventToken;
};
}
}
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SDKSample.App"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
<ResourceDictionary Source="Sample-Utils/SampleTemplateStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
// App.xaml.cpp
// Implementation of the App.xaml class.
//
#include "pch.h"
#include "MainPage.xaml.h"
#include "Common\SuspensionManager.h"
using namespace SDKSample;
using namespace SDKSample::Common;
using namespace Concurrency;
using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
{
InitializeComponent();
this->Suspending += ref new SuspendingEventHandler(this, &SDKSample::App::OnSuspending);
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points will
/// be used when the application is launched to open a specific file, to display search results,
/// and so forth.
/// </summary>
/// <param name="pArgs">Details about the launch request and process.</param>
void App::OnLaunched(LaunchActivatedEventArgs^ pArgs)
{
this->LaunchArgs = pArgs;
// Do not repeat app initialization when already running, just ensure that
// the window is active
if (pArgs->PreviousExecutionState == ApplicationExecutionState::Running)
{
Window::Current->Activate();
return;
}
// Create a Frame to act as the navigation context and associate it with
// a SuspensionManager key
auto rootFrame = ref new Frame();
SuspensionManager::RegisterFrame(rootFrame, "AppFrame");
auto prerequisite = task<void>([](){});
if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
{
// Restore the saved session state only when appropriate, scheduling the
// final launch steps after the restore is complete
prerequisite = SuspensionManager::RestoreAsync();
}
prerequisite.then([=]()
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (rootFrame->Content == nullptr)
{
if (!rootFrame->Navigate(TypeName(MainPage::typeid)))
{
throw ref new FailureException("Failed to create initial page");
}
}
// Place the frame in the current Window and ensure that it is active
Window::Current->Content = rootFrame;
Window::Current->Activate();
}, task_continuation_context::use_current());
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
{
(void) sender; // Unused parameter
auto deferral = e->SuspendingOperation->GetDeferral();
SuspensionManager::SaveAsync().then([=]()
{
deferral->Complete();
});
}
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
// App.xaml.h
// Declaration of the App.xaml class.
//
#pragma once
#include "pch.h"
#include "App.g.h"
#include "MainPage.g.h"
namespace SDKSample
{
ref class App
{
internal:
App();
virtual void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ pArgs);
Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ LaunchArgs;
protected:
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs) override;
private:
Windows::UI::Xaml::Controls::Frame^ rootFrame;
};
}
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<common:LayoutAwarePage
x:Class="SDKSample.MediaCapture.AudioCapture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:$rootsnamespace$"
xmlns:common="using:SDKSample.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="Input" Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="InputTextBlock1" TextWrapping="Wrap" Grid.Row="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" >
This scenario shows how to do an audio only capture using the default microphone. Click on StartRecord to start recording.
</TextBlock>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Grid.Row="1">
<Button x:Name="btnStartDevice3" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0">StartDevice</Button>
<Button x:Name="btnStartStopRecord3" Click="btnStartStopRecord_Click" IsEnabled="false" Margin="0,0,10,0">StartRecord</Button>
</StackPanel>
</Grid>
<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Audio' />
<Canvas x:Name='playbackCanvas3' Width='320' Height ='240' >
<MediaElement x:Name='playbackElement3' Width="320" Height="240" Margin="10,5,10,5"/>
</Canvas>
</StackPanel>
</Grid>
<!-- Add Storyboards to the visual states below as necessary for supporting the various layouts -->
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="FullScreenLandscape"/>
<VisualState x:Name="Filled"/>
<VisualState x:Name="FullScreenPortrait"/>
<VisualState x:Name="Snapped"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</common:LayoutAwarePage>
This diff is collapsed.
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
// AudioCapture.xaml.h
// Declaration of the AudioCapture class
//
#pragma once
#include "pch.h"
#include "AudioCapture.g.h"
#include "MainPage.xaml.h"
#define AUDIO_FILE_NAME "audio.mp4"
namespace SDKSample
{
namespace MediaCapture
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[Windows::Foundation::Metadata::WebHostHidden]
public ref class AudioCapture sealed
{
public:
AudioCapture();
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
private:
MainPage^ rootPage;
void ScenarioInit();
void ScenarioReset();
void SoundLevelChanged(Object^ sender, Object^ e);
void RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^ mediaCapture);
void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args);
void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ShowStatusMessage(Platform::String^ text);
void ShowExceptionMessage(Platform::Exception^ ex);
void EnableButton(bool enabled, Platform::String ^name);
void SwitchRecordButtonContent();
Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediaCaptureMgr;
Windows::Storage::StorageFile^ m_photoStorageFile;
Windows::Storage::StorageFile^ m_recordStorageFile;
bool m_bRecording;
bool m_bSuspended;
Windows::Foundation::EventRegistrationToken m_eventRegistrationToken;
};
}
}
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<common:LayoutAwarePage
x:Class="SDKSample.MediaCapture.BasicCapture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:$rootsnamespace$"
xmlns:common="using:SDKSample.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="Input" Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="InputTextBlock1" TextWrapping="Wrap" Grid.Row="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" >
This scenario demonstrates how to use the MediaCapture API to preview the camera stream, record a video, and take a picture using default initialization settings.
You can also adjust the brightness and contrast.
</TextBlock>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Grid.Row="1">
<Button x:Name="btnStartDevice1" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0">StartDevice</Button>
<Button x:Name="btnStartPreview1" Click="btnStartPreview_Click" IsEnabled="true" Margin="0,0,10,0">StartPreview</Button>
<Button x:Name="btnStartStopRecord1" Click="btnStartStopRecord_Click" IsEnabled="false" Margin="0,0,10,0">StartRecord</Button>
<Button x:Name="btnTakePhoto1" Click="btnTakePhoto_Click" IsEnabled="false" Margin="0,0,10,0">TakePhoto</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Grid.Row="2">
<TextBlock TextWrapping="Wrap" Text="Brightness" Style="{StaticResource BasicTextStyle}" Margin="0,0,10,0" VerticalAlignment="Center"/>
<Slider x:Name="sldBrightness" IsEnabled="False" ValueChanged="sldBrightness_ValueChanged" Width="207" Margin="0,0,10,0"/>
<TextBlock TextWrapping="Wrap" Text="Contrast" Style="{StaticResource BasicTextStyle}" Margin="0,0,10,0" VerticalAlignment="Center" />
<Slider x:Name="sldContrast" IsEnabled="False" ValueChanged="sldContrast_ValueChanged" Width="207" Margin="0,0,10,0"/>
</StackPanel>
</Grid>
<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Preview' />
<Canvas x:Name="previewCanvas1" Width="320" Height="240" Background="Gray">
<CaptureElement x:Name="previewElement1" Width="320" Height="240" />
</Canvas>
</StackPanel>
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Video' />
<Canvas x:Name='playbackCanvas1' Width='320' Height ='240' >
<MediaElement x:Name='playbackElement1' Width="320" Height="240" />
</Canvas>
</StackPanel>
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Images' />
<Canvas x:Name="imageCanvas1" Width='320' Height ='240' >
<Image x:Name="imageElement1" Width="320" Height="240"/>
</Canvas>
</StackPanel>
</StackPanel>
</Grid>
<!-- Add Storyboards to the visual states below as necessary for supporting the various layouts -->
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="FullScreenLandscape"/>
<VisualState x:Name="Filled"/>
<VisualState x:Name="FullScreenPortrait"/>
<VisualState x:Name="Snapped"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</common:LayoutAwarePage>
This diff is collapsed.
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
// BasicCapture.xaml.h
// Declaration of the BasicCapture class
//
#pragma once
#include "pch.h"
#include "BasicCapture.g.h"
#include "MainPage.xaml.h"
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::Graphics::Display;
using namespace Windows::UI::ViewManagement;
using namespace Windows::Devices::Enumeration;
#define VIDEO_FILE_NAME "video.mp4"
#define PHOTO_FILE_NAME "photo.jpg"
namespace SDKSample
{
namespace MediaCapture
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[Windows::Foundation::Metadata::WebHostHidden]
public ref class BasicCapture sealed
{
public:
BasicCapture();
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
private:
MainPage^ rootPage;
void ScenarioInit();
void ScenarioReset();
void Suspending(Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
void Resuming(Object^ sender, Object^ e);
void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void SoundLevelChanged(Object^ sender, Object^ e);
void RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^ mediaCapture);
void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args);
void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void SetupVideoDeviceControl(Windows::Media::Devices::MediaDeviceControl^ videoDeviceControl, Slider^ slider);
void sldBrightness_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e);
void sldContrast_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e);
void ShowStatusMessage(Platform::String^ text);
void ShowExceptionMessage(Platform::Exception^ ex);
void EnableButton(bool enabled, Platform::String ^name);
void SwitchRecordButtonContent();
Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediaCaptureMgr;
Windows::Storage::StorageFile^ m_photoStorageFile;
Windows::Storage::StorageFile^ m_recordStorageFile;
bool m_bRecording;
bool m_bEffectAdded;
bool m_bSuspended;
bool m_bPreviewing;
Windows::UI::Xaml::WindowVisibilityChangedEventHandler ^m_visbilityHandler;
Windows::Foundation::EventRegistrationToken m_eventRegistrationToken;
bool m_currentScenarioLoaded;
};
}
}
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#include "pch.h"
#include "MainPage.xaml.h"
#include "Constants.h"
using namespace SDKSample;
Platform::Array<Scenario>^ MainPage::scenariosInner = ref new Platform::Array<Scenario>
{
// The format here is the following:
// { "Description for the sample", "Fully quaified name for the class that implements the scenario" }
{ "Video preview, record and take pictures", "SDKSample.MediaCapture.BasicCapture" },
{ "Enumerate cameras and add a video effect", "SDKSample.MediaCapture.AdvancedCapture" },
{ "Audio Capture", "SDKSample.MediaCapture.AudioCapture" }
};
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#pragma once
#include <collection.h>
namespace SDKSample
{
public value struct Scenario
{
Platform::String^ Title;
Platform::String^ ClassName;
};
partial ref class MainPage
{
public:
static property Platform::String^ FEATURE_NAME
{
Platform::String^ get()
{
return ref new Platform::String(L"MediaCapture CPP sample");
}
}
static property Platform::Array<Scenario>^ scenarios
{
Platform::Array<Scenario>^ get()
{
return scenariosInner;
}
}
private:
static Platform::Array<Scenario>^ scenariosInner;
};
}
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<common:LayoutAwarePage
x:Class="SDKSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:common="using:SDKSample.Common"
mc:Ignorable="d"
x:Name="RootPage">
<common:LayoutAwarePage.Resources>
<Style x:Key="BaseStatusStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="Segoe UI Semilight"/>
<Setter Property="FontSize" Value="14.667"/>
<Setter Property="Margin" Value="0,0,0,5"/>
</Style>
<Style x:Key="StatusStyle" BasedOn="{StaticResource BaseStatusStyle}" TargetType="TextBlock">
<Setter Property="Foreground" Value="Green"/>
</Style>
<Style x:Key="ErrorStyle" BasedOn="{StaticResource BaseStatusStyle}" TargetType="TextBlock">
<Setter Property="Foreground" Value="Blue"/>
</Style>
</common:LayoutAwarePage.Resources>
<Grid x:Name="LayoutRoot" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="ContentRoot" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Margin="100,20,100,20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Header -->
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Image x:Name="WindowsLogo" Stretch="None" Source="Assets/windows-sdk.png" AutomationProperties.Name="Windows Logo" HorizontalAlignment="Left" Grid.Column="0"/>
<TextBlock Text="Windows 8 SDK Samples" VerticalAlignment="Bottom" Style="{StaticResource TitleTextStyle}" TextWrapping="Wrap" Grid.Column="1"/>
</StackPanel>
<ScrollViewer x:Name="MainScrollViewer" Grid.Row="1" ZoomMode="Disabled" IsTabStop="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Padding="0,0,0,20" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="FeatureName" Grid.Row="0" Text="Add Sample Title Here" Style="{StaticResource HeaderTextStyle}" TextWrapping="Wrap"/>
<!-- Content -->
<Grid Grid.Row="1">
<!-- All XAML in this section is purely for design time so you can see sample content in the designer. -->
<!-- This will be repaced at runtime by live content. -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Input" Style="{StaticResource H2Style}"/>
<TextBlock x:Name="ScenarioListLabel" Text="Select Scenario:" Grid.Row="1" Style="{StaticResource SubheaderTextStyle}" Margin="0,5,0,0" />
<ListBox x:Name="Scenarios" Margin="0,0,20,0" Grid.Row="2" AutomationProperties.Name="Scenarios" HorizontalAlignment="Left"
VerticalAlignment="Top" ScrollViewer.HorizontalScrollBarVisibility="Auto"
AutomationProperties.LabeledBy="{Binding ElementName=ScenarioListLabel}" MaxHeight="125">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:Name="DescriptionText" Margin="0,5,0,0" Text="Description:" Style="{StaticResource SubheaderTextStyle}" Grid.Row="1" Grid.Column="1"/>
<!-- Input Scenarios -->
<UserControl x:Name="InputSection" Margin="0,5,0,0" IsTabStop="False" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<!-- Output section -->
<TextBlock Text="Output" Grid.Row="5" Margin="0,25,0,20" Style="{StaticResource H2Style}" Grid.ColumnSpan="2"/>
<TextBlock x:Name="StatusBlock" Grid.Row="6" Margin="0,0,0,5" Grid.ColumnSpan="2"/>
<!-- Output Scenarios -->
<UserControl x:Name="OutputSection" Grid.Row="7" Grid.ColumnSpan="2" BorderThickness="0"/>
</Grid>
</Grid>
</Grid>
</ScrollViewer>
<!-- Footer -->
<Grid x:Name="Footer" Grid.Row="3" Margin="0,10,0,10" VerticalAlignment="Bottom" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Source="Assets/microsoft-sdk.png" AutomationProperties.Name="Microsoft Logo" Stretch="None" HorizontalAlignment="Left"/>
<TextBlock Style="{StaticResource FooterStyle}" Text="© Microsoft Corporation. All rights reserved." TextWrapping="Wrap" Grid.Row="1" HorizontalAlignment="Left"/>
<StackPanel x:Name="FooterPanel" Orientation="Horizontal" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right">
<HyperlinkButton Content="Terms of use" Tag="http://www.microsoft.com/About/Legal/EN/US/IntellectualProperty/Copyright/default.aspx"
Click="Footer_Click" FontSize="12" Style="{StaticResource HyperlinkStyle}"/>
<TextBlock Text="|" Style="{StaticResource SeparatorStyle}" VerticalAlignment="Center"/>
<HyperlinkButton Content="Trademarks" Tag="http://www.microsoft.com/About/Legal/EN/US/IntellectualProperty/Trademarks/EN-US.aspx"
Click="Footer_Click" FontSize="12" Style="{StaticResource HyperlinkStyle}"/>
<TextBlock Text="|" Style="{StaticResource SeparatorStyle}" VerticalAlignment="Center"/>
<HyperlinkButton Content="Privacy Statement" Tag="http://privacy.microsoft.com" Click="Footer_Click" FontSize="12" Style="{StaticResource HyperlinkStyle}"/>
</StackPanel>
</Grid>
</Grid>
<VisualStateManager.VisualStateGroups>
<!-- Visual states reflect the application's view state -->
<VisualStateGroup>
<VisualState x:Name="FullScreenLandscape">
<Storyboard>
</Storyboard>
</VisualState>
<VisualState x:Name="Filled">
<Storyboard>
</Storyboard>
</VisualState>
<VisualState x:Name="FullScreenPortrait">
<Storyboard>
</Storyboard>
</VisualState>
<VisualState x:Name="Snapped">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="ContentRoot">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Thickness>20,20,20,20</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</common:LayoutAwarePage>
This diff is collapsed.
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
// MainPage.xaml.h
// Declaration of the MainPage.xaml class.
//
#pragma once
#include "pch.h"
#include "MainPage.g.h"
#include "Common\LayoutAwarePage.h" // Required by generated header
#include "Constants.h"
namespace SDKSample
{
public enum class NotifyType
{
StatusMessage,
ErrorMessage
};
public ref class MainPageSizeChangedEventArgs sealed
{
public:
property Windows::UI::ViewManagement::ApplicationViewState ViewState
{
Windows::UI::ViewManagement::ApplicationViewState get()
{
return viewState;
}
void set(Windows::UI::ViewManagement::ApplicationViewState value)
{
viewState = value;
}
}
private:
Windows::UI::ViewManagement::ApplicationViewState viewState;
};
public ref class MainPage sealed
{
public:
MainPage();
protected:
virtual void LoadState(Platform::Object^ navigationParameter,
Windows::Foundation::Collections::IMap<Platform::String^, Platform::Object^>^ pageState) override;
virtual void SaveState(Windows::Foundation::Collections::IMap<Platform::String^, Platform::Object^>^ pageState) override;
internal:
property bool AutoSizeInputSectionWhenSnapped
{
bool get()
{
return autoSizeInputSectionWhenSnapped;
}
void set(bool value)
{
autoSizeInputSectionWhenSnapped = value;
}
}
property Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ LaunchArgs
{
Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ get()
{
return safe_cast<App^>(App::Current)->LaunchArgs;
}
}
void NotifyUser(Platform::String^ strMessage, NotifyType type);
void LoadScenario(Platform::String^ scenarioName);
event Windows::Foundation::EventHandler<Platform::Object^>^ ScenarioLoaded;
event Windows::Foundation::EventHandler<MainPageSizeChangedEventArgs^>^ MainPageResized;
private:
void PopulateScenarios();
void InvalidateSize();
void InvalidateViewState();
Platform::Collections::Vector<Object^>^ ScenarioList;
Windows::UI::Xaml::Controls::Frame^ HiddenFrame;
void Footer_Click(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
bool autoSizeInputSectionWhenSnapped;
void MainPage_SizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
void Scenarios_SelectionChanged(Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
internal:
static MainPage^ Current;
};
}

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11 Express for Windows 8
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MediaCapture", "MediaCapture.vcxproj", "{C5B886A7-8300-46FF-B533-9613DE2AF637}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GrayscaleTransform", "MediaExtensions\Grayscale\Grayscale.vcxproj", "{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|ARM = Release|ARM
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|ARM.ActiveCfg = Debug|ARM
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|ARM.Build.0 = Debug|ARM
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|Win32.ActiveCfg = Debug|Win32
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|Win32.Build.0 = Debug|Win32
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|x64.ActiveCfg = Debug|x64
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|x64.Build.0 = Debug|x64
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|ARM.ActiveCfg = Release|ARM
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|ARM.Build.0 = Release|ARM
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|Win32.ActiveCfg = Release|Win32
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|Win32.Build.0 = Release|Win32
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|x64.ActiveCfg = Release|x64
{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|x64.Build.0 = Release|x64
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|ARM.ActiveCfg = Debug|ARM
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|ARM.Build.0 = Debug|ARM
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|ARM.Deploy.0 = Debug|ARM
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|Win32.ActiveCfg = Debug|Win32
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|Win32.Build.0 = Debug|Win32
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|Win32.Deploy.0 = Debug|Win32
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|x64.ActiveCfg = Debug|x64
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|x64.Build.0 = Debug|x64
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|x64.Deploy.0 = Debug|x64
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|ARM.ActiveCfg = Release|ARM
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|ARM.Build.0 = Release|ARM
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|ARM.Deploy.0 = Release|ARM
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|Win32.ActiveCfg = Release|Win32
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|Win32.Build.0 = Release|Win32
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|Win32.Deploy.0 = Release|Win32
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|x64.ActiveCfg = Release|x64
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|x64.Build.0 = Release|x64
{C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|x64.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C5B886A7-8300-46FF-B533-9613DE2AF637}</ProjectGuid>
<RootNamespace>SDKSample</RootNamespace>
<DefaultLanguage>en-US</DefaultLanguage>
<VCTargetsPath Condition="'$(VCTargetsPath11)' != '' and '$(VSVersion)' == '' and '$(VisualStudioVersion)' == ''">$(VCTargetsPath11)</VCTargetsPath>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
<ProjectName>MediaCapture</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="AdvancedCapture.xaml.h">
<DependentUpon>AdvancedCapture.xaml</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="AudioCapture.xaml.h">
<DependentUpon>AudioCapture.xaml</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="BasicCapture.xaml.h">
<DependentUpon>BasicCapture.xaml</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="Constants.h" />
<ClInclude Include="MainPage.xaml.h">
<DependentUpon>MainPage.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="pch.h" />
<ClInclude Include="Common\LayoutAwarePage.h" />
<ClInclude Include="Common\SuspensionManager.h" />
<ClInclude Include="App.xaml.h">
<DependentUpon>App.xaml</DependentUpon>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="AdvancedCapture.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="AudioCapture.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="BasicCapture.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Common\StandardStyles.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="MainPage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Sample-Utils\SampleTemplateStyles.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AdvancedCapture.xaml.cpp">
<DependentUpon>AdvancedCapture.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="App.xaml.cpp">
<DependentUpon>App.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="AudioCapture.xaml.cpp">
<DependentUpon>AudioCapture.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="BasicCapture.xaml.cpp">
<DependentUpon>BasicCapture.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="Common\LayoutAwarePage.cpp" />
<ClCompile Include="Constants.cpp" />
<ClCompile Include="Common\SuspensionManager.cpp" />
<ClCompile Include="MainPage.xaml.cpp">
<DependentUpon>MainPage.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="Assets\microsoft-sdk.png" />
<Image Include="Assets\placeholder-sdk.png" />
<Image Include="Assets\smallTile-sdk.png" />
<Image Include="Assets\splash-sdk.png" />
<Image Include="Assets\squareTile-sdk.png" />
<Image Include="Assets\storeLogo-sdk.png" />
<Image Include="Assets\tile-sdk.png" />
<Image Include="Assets\windows-sdk.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="MediaExtensions\Grayscale\Grayscale.vcxproj">
<Project>{ba69218f-da5c-4d14-a78d-21a9e4dec669}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Image Include="Assets\microsoft-sdk.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\placeholder-sdk.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\smallTile-sdk.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\splash-sdk.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\squareTile-sdk.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\storeLogo-sdk.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\tile-sdk.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\windows-sdk.png">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest" />
</ItemGroup>
<ItemGroup>
<Page Include="MainPage.xaml" />
<Page Include="Common\StandardStyles.xaml">
<Filter>Common</Filter>
</Page>
<Page Include="Sample-Utils\SampleTemplateStyles.xaml">
<Filter>Sample-Utils</Filter>
</Page>
<Page Include="BasicCapture.xaml" />
<Page Include="AdvancedCapture.xaml" />
<Page Include="AudioCapture.xaml" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="MainPage.xaml.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="App.xaml.h" />
<ClInclude Include="Common\SuspensionManager.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Common\LayoutAwarePage.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Constants.h" />
<ClInclude Include="AdvancedCapture.xaml.h" />
<ClInclude Include="AudioCapture.xaml.h" />
<ClInclude Include="BasicCapture.xaml.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="App.xaml.cpp" />
<ClCompile Include="MainPage.xaml.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="Common\LayoutAwarePage.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Common\SuspensionManager.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Constants.cpp" />
<ClCompile Include="AdvancedCapture.xaml.cpp" />
<ClCompile Include="AudioCapture.xaml.cpp" />
<ClCompile Include="BasicCapture.xaml.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="Assets">
<UniqueIdentifier>{132eec18-b164-4b15-a746-643880e9c5d9}</UniqueIdentifier>
</Filter>
<Filter Include="Common">
<UniqueIdentifier>{476b4177-f316-4458-8e13-cab3dc2381c5}</UniqueIdentifier>
</Filter>
<Filter Include="Sample-Utils">
<UniqueIdentifier>{54f287f8-e4cb-4f47-97d0-4c469de6992e}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
\ No newline at end of file
#pragma once
//////////////////////////////////////////////////////////////////////////
// AsyncCallback [template]
//
// Description:
// Helper class that routes IMFAsyncCallback::Invoke calls to a class
// method on the parent class.
//
// Usage:
// Add this class as a member variable. In the parent class constructor,
// initialize the AsyncCallback class like this:
// m_cb(this, &CYourClass::OnInvoke)
// where
// m_cb = AsyncCallback object
// CYourClass = parent class
// OnInvoke = Method in the parent class to receive Invoke calls.
//
// The parent's OnInvoke method (you can name it anything you like) must
// have a signature that matches the InvokeFn typedef below.
//////////////////////////////////////////////////////////////////////////
// T: Type of the parent object
template<class T>
class AsyncCallback : public IMFAsyncCallback
{
public:
typedef HRESULT (T::*InvokeFn)(IMFAsyncResult *pAsyncResult);
AsyncCallback(T *pParent, InvokeFn fn) : m_pParent(pParent), m_pInvokeFn(fn)
{
}
// IUnknown
STDMETHODIMP_(ULONG) AddRef() {
// Delegate to parent class.
return m_pParent->AddRef();
}
STDMETHODIMP_(ULONG) Release() {
// Delegate to parent class.
return m_pParent->Release();
}
STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
{
if (!ppv)
{
return E_POINTER;
}
if (iid == __uuidof(IUnknown))
{
*ppv = static_cast<IUnknown*>(static_cast<IMFAsyncCallback*>(this));
}
else if (iid == __uuidof(IMFAsyncCallback))
{
*ppv = static_cast<IMFAsyncCallback*>(this);
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
// IMFAsyncCallback methods
STDMETHODIMP GetParameters(DWORD*, DWORD*)
{
// Implementation of this method is optional.
return E_NOTIMPL;
}
STDMETHODIMP Invoke(IMFAsyncResult* pAsyncResult)
{
return (m_pParent->*m_pInvokeFn)(pAsyncResult);
}
T *m_pParent;
InvokeFn m_pInvokeFn;
};
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
//////////////////////////////////////////////////////////////////////////
// VideoBufferLock
//
// Description:
// Locks a video buffer that might or might not support IMF2DBuffer.
//
//////////////////////////////////////////////////////////////////////////
class VideoBufferLock
{
public:
VideoBufferLock(IMFMediaBuffer *pBuffer) : m_p2DBuffer(NULL)
{
m_pBuffer = pBuffer;
m_pBuffer->AddRef();
// Query for the 2-D buffer interface. OK if this fails.
m_pBuffer->QueryInterface(IID_PPV_ARGS(&m_p2DBuffer));
}
~VideoBufferLock()
{
UnlockBuffer();
SafeRelease(&m_pBuffer);
SafeRelease(&m_p2DBuffer);
}
// LockBuffer:
// Locks the buffer. Returns a pointer to scan line 0 and returns the stride.
// The caller must provide the default stride as an input parameter, in case
// the buffer does not expose IMF2DBuffer. You can calculate the default stride
// from the media type.
HRESULT LockBuffer(
LONG lDefaultStride, // Minimum stride (with no padding).
DWORD dwHeightInPixels, // Height of the image, in pixels.
BYTE **ppbScanLine0, // Receives a pointer to the start of scan line 0.
LONG *plStride // Receives the actual stride.
)
{
HRESULT hr = S_OK;
// Use the 2-D version if available.
if (m_p2DBuffer)
{
hr = m_p2DBuffer->Lock2D(ppbScanLine0, plStride);
}
else
{
// Use non-2D version.
BYTE *pData = NULL;
hr = m_pBuffer->Lock(&pData, NULL, NULL);
if (SUCCEEDED(hr))
{
*plStride = lDefaultStride;
if (lDefaultStride < 0)
{
// Bottom-up orientation. Return a pointer to the start of the
// last row *in memory* which is the top row of the image.
*ppbScanLine0 = pData + abs(lDefaultStride) * (dwHeightInPixels - 1);
}
else
{
// Top-down orientation. Return a pointer to the start of the
// buffer.
*ppbScanLine0 = pData;
}
}
}
return hr;
}
HRESULT UnlockBuffer()
{
if (m_p2DBuffer)
{
return m_p2DBuffer->Unlock2D();
}
else
{
return m_pBuffer->Unlock();
}
}
private:
IMFMediaBuffer *m_pBuffer;
IMF2DBuffer *m_p2DBuffer;
};
#pragma once
//////////////////////////////////////////////////////////////////////////
// CritSec
// Description: Wraps a critical section.
//////////////////////////////////////////////////////////////////////////
class CritSec
{
public:
CRITICAL_SECTION m_criticalSection;
public:
CritSec()
{
InitializeCriticalSectionEx(&m_criticalSection, 100, 0);
}
~CritSec()
{
DeleteCriticalSection(&m_criticalSection);
}
_Acquires_lock_(m_criticalSection)
void Lock()
{
EnterCriticalSection(&m_criticalSection);
}
_Releases_lock_(m_criticalSection)
void Unlock()
{
LeaveCriticalSection(&m_criticalSection);
}
};
//////////////////////////////////////////////////////////////////////////
// AutoLock
// Description: Provides automatic locking and unlocking of a
// of a critical section.
//
// Note: The AutoLock object must go out of scope before the CritSec.
//////////////////////////////////////////////////////////////////////////
class AutoLock
{
private:
CritSec *m_pCriticalSection;
public:
_Acquires_lock_(m_pCriticalSection)
AutoLock(CritSec& crit)
{
m_pCriticalSection = &crit;
m_pCriticalSection->Lock();
}
_Releases_lock_(m_pCriticalSection)
~AutoLock()
{
m_pCriticalSection->Unlock();
}
};
//////////////////////////////////////////////////////////////////////////
//
// OpQueue.h
// Async operation queue.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////
#pragma once
#pragma warning( push )
#pragma warning( disable : 4355 ) // 'this' used in base member initializer list
/*
This header file defines an object to help queue and serialize
asynchronous operations.
Background:
To perform an operation asynchronously in Media Foundation, an object
does one of the following:
1. Calls MFPutWorkItem(Ex), using either a standard work queue
identifier or a caller-allocated work queue. The work-queue
thread invokes the object's callback.
2. Creates an async result object (IMFAsyncResult) and calls
MFInvokeCallback to invoke the object's callback.
Ultimately, either of these cause the object's callback to be invoked
from a work-queue thread. The object can then complete the operation
inside the callback.
However, the Media Foundation platform may dispatch async callbacks in
parallel on several threads. Putting an item on a work queue does NOT
guarantee that one operation will complete before the next one starts,
or even that work items will be dispatched in the same order they were
called.
To serialize async operations that should not overlap, an object should
use a queue. While one operation is pending, subsequent operations are
put on the queue, and only dispatched after the previous operation is
complete.
The granularity of a single "operation" depends on the requirements of
that particular object. A single operation might involve several
asynchronous calls before the object dispatches the next operation on
the queue.
*/
//-------------------------------------------------------------------
// OpQueue class template
//
// Base class for an async operation queue.
//
// TOperation: The class used to describe operations. This class must
// implement IUnknown.
//
// The OpQueue class is an abstract class. The derived class must
// implement the following pure-virtual methods:
//
// - IUnknown methods (AddRef, Release, QI)
//
// - DispatchOperation:
//
// Performs the asynchronous operation specified by pOp.
//
// At the end of each operation, the derived class must call
// ProcessQueue to process the next operation in the queue.
//
// NOTE: An operation is not required to complete inside the
// DispatchOperation method. A single operation might consist
// of several asynchronous method calls.
//
// - ValidateOperation:
//
// Checks whether the object can perform the operation specified
// by pOp at this time.
//
// If the object cannot perform the operation now (e.g., because
// another operation is still in progress) the method should
// return MF_E_NOTACCEPTING.
//
//-------------------------------------------------------------------
#include "linklist.h"
#include "AsyncCB.h"
template <class T, class TOperation>
class OpQueue //: public IUnknown
{
public:
typedef ComPtrList<TOperation> OpList;
HRESULT QueueOperation(TOperation *pOp);
protected:
HRESULT ProcessQueue();
HRESULT ProcessQueueAsync(IMFAsyncResult *pResult);
virtual HRESULT DispatchOperation(TOperation *pOp) = 0;
virtual HRESULT ValidateOperation(TOperation *pOp) = 0;
OpQueue(CRITICAL_SECTION& critsec)
: m_OnProcessQueue(static_cast<T *>(this), &OpQueue::ProcessQueueAsync),
m_critsec(critsec)
{
}
virtual ~OpQueue()
{
}
protected:
OpList m_OpQueue; // Queue of operations.
CRITICAL_SECTION& m_critsec; // Protects the queue state.
AsyncCallback<T> m_OnProcessQueue; // ProcessQueueAsync callback.
};
//-------------------------------------------------------------------
// Place an operation on the queue.
// Public method.
//-------------------------------------------------------------------
template <class T, class TOperation>
HRESULT OpQueue<T, TOperation>::QueueOperation(TOperation *pOp)
{
HRESULT hr = S_OK;
EnterCriticalSection(&m_critsec);
hr = m_OpQueue.InsertBack(pOp);
if (SUCCEEDED(hr))
{
hr = ProcessQueue();
}
LeaveCriticalSection(&m_critsec);
return hr;
}
//-------------------------------------------------------------------
// Process the next operation on the queue.
// Protected method.
//
// Note: This method dispatches the operation to a work queue.
//-------------------------------------------------------------------
template <class T, class TOperation>
HRESULT OpQueue<T, TOperation>::ProcessQueue()
{
HRESULT hr = S_OK;
if (m_OpQueue.GetCount() > 0)
{
hr = MFPutWorkItem2(
MFASYNC_CALLBACK_QUEUE_STANDARD, // Use the standard work queue.
0, // Default priority
&m_OnProcessQueue, // Callback method.
nullptr // State object.
);
}
return hr;
}
//-------------------------------------------------------------------
// Process the next operation on the queue.
// Protected method.
//
// Note: This method is called from a work-queue thread.
//-------------------------------------------------------------------
template <class T, class TOperation>
HRESULT OpQueue<T, TOperation>::ProcessQueueAsync(IMFAsyncResult *pResult)
{
HRESULT hr = S_OK;
TOperation *pOp = nullptr;
EnterCriticalSection(&m_critsec);
if (m_OpQueue.GetCount() > 0)
{
hr = m_OpQueue.GetFront(&pOp);
if (SUCCEEDED(hr))
{
hr = ValidateOperation(pOp);
}
if (SUCCEEDED(hr))
{
hr = m_OpQueue.RemoveFront(nullptr);
}
if (SUCCEEDED(hr))
{
(void)DispatchOperation(pOp);
}
}
if (pOp != nullptr)
{
pOp->Release();
}
LeaveCriticalSection(&m_critsec);
return hr;
}
#pragma warning( pop )
\ No newline at end of file
EXPORTS
DllCanUnloadNow PRIVATE
DllGetActivationFactory PRIVATE
DllGetClassObject PRIVATE
\ No newline at end of file
// Defines the transform class.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
#ifndef GRAYSCALE_H
#define GRAYSCALE_H
#include <new>
#include <mfapi.h>
#include <mftransform.h>
#include <mfidl.h>
#include <mferror.h>
#include <strsafe.h>
#include <assert.h>
// Note: The Direct2D helper library is included for its 2D matrix operations.
#include <D2d1helper.h>
#include <wrl\implements.h>
#include <wrl\module.h>
#include <windows.media.h>
#include "GrayscaleTransform.h"
// CLSID of the MFT.
DEFINE_GUID(CLSID_GrayscaleMFT,
0x2f3dbc05, 0xc011, 0x4a8f, 0xb2, 0x64, 0xe4, 0x2e, 0x35, 0xc6, 0x7b, 0xf4);
//
// * IMPORTANT: If you implement your own MFT, create a new GUID for the CLSID. *
//
// Configuration attributes
// {7BBBB051-133B-41F5-B6AA-5AFF9B33A2CB}
DEFINE_GUID(MFT_GRAYSCALE_DESTINATION_RECT,
0x7bbbb051, 0x133b, 0x41f5, 0xb6, 0xaa, 0x5a, 0xff, 0x9b, 0x33, 0xa2, 0xcb);
// {14782342-93E8-4565-872C-D9A2973D5CBF}
DEFINE_GUID(MFT_GRAYSCALE_SATURATION,
0x14782342, 0x93e8, 0x4565, 0x87, 0x2c, 0xd9, 0xa2, 0x97, 0x3d, 0x5c, 0xbf);
// {E0BADE5D-E4B9-4689-9DBA-E2F00D9CED0E}
DEFINE_GUID(MFT_GRAYSCALE_CHROMA_ROTATION,
0xe0bade5d, 0xe4b9, 0x4689, 0x9d, 0xba, 0xe2, 0xf0, 0xd, 0x9c, 0xed, 0xe);
template <class T> void SafeRelease(T **ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}
// Function pointer for the function that transforms the image.
typedef void (*IMAGE_TRANSFORM_FN)(
const D2D1::Matrix3x2F& mat, // Chroma transform matrix.
const D2D_RECT_U& rcDest, // Destination rectangle for the transformation.
BYTE* pDest, // Destination buffer.
LONG lDestStride, // Destination stride.
const BYTE* pSrc, // Source buffer.
LONG lSrcStride, // Source stride.
DWORD dwWidthInPixels, // Image width in pixels.
DWORD dwHeightInPixels // Image height in pixels.
);
// CGrayscale class:
// Implements a grayscale video effect.
class CGrayscale
: public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
ABI::Windows::Media::IMediaExtension,
IMFTransform >
{
InspectableClass(RuntimeClass_GrayscaleTransform_GrayscaleEffect, BaseTrust)
public:
CGrayscale();
~CGrayscale();
STDMETHOD(RuntimeClassInitialize)();
// IMediaExtension
STDMETHODIMP SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration);
// IMFTransform
STDMETHODIMP GetStreamLimits(
DWORD *pdwInputMinimum,
DWORD *pdwInputMaximum,
DWORD *pdwOutputMinimum,
DWORD *pdwOutputMaximum
);
STDMETHODIMP GetStreamCount(
DWORD *pcInputStreams,
DWORD *pcOutputStreams
);
STDMETHODIMP GetStreamIDs(
DWORD dwInputIDArraySize,
DWORD *pdwInputIDs,
DWORD dwOutputIDArraySize,
DWORD *pdwOutputIDs
);
STDMETHODIMP GetInputStreamInfo(
DWORD dwInputStreamID,
MFT_INPUT_STREAM_INFO * pStreamInfo
);
STDMETHODIMP GetOutputStreamInfo(
DWORD dwOutputStreamID,
MFT_OUTPUT_STREAM_INFO * pStreamInfo
);
STDMETHODIMP GetAttributes(IMFAttributes** pAttributes);
STDMETHODIMP GetInputStreamAttributes(
DWORD dwInputStreamID,
IMFAttributes **ppAttributes
);
STDMETHODIMP GetOutputStreamAttributes(
DWORD dwOutputStreamID,
IMFAttributes **ppAttributes
);
STDMETHODIMP DeleteInputStream(DWORD dwStreamID);
STDMETHODIMP AddInputStreams(
DWORD cStreams,
DWORD *adwStreamIDs
);
STDMETHODIMP GetInputAvailableType(
DWORD dwInputStreamID,
DWORD dwTypeIndex, // 0-based
IMFMediaType **ppType
);
STDMETHODIMP GetOutputAvailableType(
DWORD dwOutputStreamID,
DWORD dwTypeIndex, // 0-based
IMFMediaType **ppType
);
STDMETHODIMP SetInputType(
DWORD dwInputStreamID,
IMFMediaType *pType,
DWORD dwFlags
);
STDMETHODIMP SetOutputType(
DWORD dwOutputStreamID,
IMFMediaType *pType,
DWORD dwFlags
);
STDMETHODIMP GetInputCurrentType(
DWORD dwInputStreamID,
IMFMediaType **ppType
);
STDMETHODIMP GetOutputCurrentType(
DWORD dwOutputStreamID,
IMFMediaType **ppType
);
STDMETHODIMP GetInputStatus(
DWORD dwInputStreamID,
DWORD *pdwFlags
);
STDMETHODIMP GetOutputStatus(DWORD *pdwFlags);
STDMETHODIMP SetOutputBounds(
LONGLONG hnsLowerBound,
LONGLONG hnsUpperBound
);
STDMETHODIMP ProcessEvent(
DWORD dwInputStreamID,
IMFMediaEvent *pEvent
);
STDMETHODIMP ProcessMessage(
MFT_MESSAGE_TYPE eMessage,
ULONG_PTR ulParam
);
STDMETHODIMP ProcessInput(
DWORD dwInputStreamID,
IMFSample *pSample,
DWORD dwFlags
);
STDMETHODIMP ProcessOutput(
DWORD dwFlags,
DWORD cOutputBufferCount,
MFT_OUTPUT_DATA_BUFFER *pOutputSamples, // one per stream
DWORD *pdwStatus
);
private:
// HasPendingOutput: Returns TRUE if the MFT is holding an input sample.
BOOL HasPendingOutput() const { return m_pSample != NULL; }
// IsValidInputStream: Returns TRUE if dwInputStreamID is a valid input stream identifier.
BOOL IsValidInputStream(DWORD dwInputStreamID) const
{
return dwInputStreamID == 0;
}
// IsValidOutputStream: Returns TRUE if dwOutputStreamID is a valid output stream identifier.
BOOL IsValidOutputStream(DWORD dwOutputStreamID) const
{
return dwOutputStreamID == 0;
}
HRESULT OnGetPartialType(DWORD dwTypeIndex, IMFMediaType **ppmt);
HRESULT OnCheckInputType(IMFMediaType *pmt);
HRESULT OnCheckOutputType(IMFMediaType *pmt);
HRESULT OnCheckMediaType(IMFMediaType *pmt);
void OnSetInputType(IMFMediaType *pmt);
void OnSetOutputType(IMFMediaType *pmt);
HRESULT BeginStreaming();
HRESULT EndStreaming();
HRESULT OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut);
HRESULT OnFlush();
HRESULT UpdateFormatInfo();
CRITICAL_SECTION m_critSec;
// Transformation parameters
D2D1::Matrix3x2F m_transform; // Chroma transform matrix.
D2D_RECT_U m_rcDest; // Destination rectangle for the effect.
// Streaming
bool m_bStreamingInitialized;
IMFSample *m_pSample; // Input sample.
IMFMediaType *m_pInputType; // Input media type.
IMFMediaType *m_pOutputType; // Output media type.
// Fomat information
UINT32 m_imageWidthInPixels;
UINT32 m_imageHeightInPixels;
DWORD m_cbImageSize; // Image size, in bytes.
IMFAttributes *m_pAttributes;
// Image transform function. (Changes based on the media type.)
IMAGE_TRANSFORM_FN m_pTransformFn;
};
#endif
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resources">
<UniqueIdentifier>bdc52ff6-58cb-464b-bf4f-0c1804b135ff</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="Grayscale.def" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="Grayscale.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Grayscale.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="GrayscaleTransform.idl" />
</ItemGroup>
</Project>
\ No newline at end of file
import "Windows.Media.idl";
#include <sdkddkver.h>
namespace GrayscaleTransform
{
[version(NTDDI_WIN8)]
runtimeclass GrayscaleEffect
{
}
}
\ No newline at end of file
//////////////////////////////////////////////////////////////////////////
//
// dllmain.cpp
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////
#include <initguid.h>
#include "Grayscale.h"
using namespace Microsoft::WRL;
namespace Microsoft { namespace Samples {
ActivatableClass(CGrayscale);
}}
BOOL WINAPI DllMain( _In_ HINSTANCE hInstance, _In_ DWORD dwReason, _In_opt_ LPVOID lpReserved )
{
if( DLL_PROCESS_ATTACH == dwReason )
{
//
// Don't need per-thread callbacks
//
DisableThreadLibraryCalls( hInstance );
Module<InProc>::GetModule().Create();
}
else if( DLL_PROCESS_DETACH == dwReason )
{
Module<InProc>::GetModule().Terminate();
}
return TRUE;
}
HRESULT WINAPI DllGetActivationFactory( _In_ HSTRING activatibleClassId, _Outptr_ IActivationFactory** factory )
{
auto &module = Microsoft::WRL::Module< Microsoft::WRL::InProc >::GetModule();
return module.GetActivationFactory( activatibleClassId, factory );
}
HRESULT WINAPI DllCanUnloadNow()
{
auto &module = Microsoft::WRL::Module<Microsoft::WRL::InProc>::GetModule();
return (module.Terminate()) ? S_OK : S_FALSE;
}
STDAPI DllGetClassObject( _In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID FAR* ppv )
{
auto &module = Microsoft::WRL::Module<Microsoft::WRL::InProc>::GetModule();
return module.GetClassObject( rclsid, riid, ppv );
}
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Identity Name="Microsoft.SDKSamples.MediaCapture.CPP" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="1.0.0.0" />
<Properties>
<DisplayName>MediaCapture CPP sample</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>Assets\storeLogo-sdk.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.2.1</OSMinVersion>
<OSMaxVersionTested>6.2.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="MediaCapture.App" Executable="$targetnametoken$.exe" EntryPoint="MediaCapture.App">
<VisualElements DisplayName="MediaCapture CPP sample" Logo="Assets\squareTile-sdk.png" SmallLogo="Assets\smallTile-sdk.png" Description="MediaCapture CPP sample" ForegroundText="light" BackgroundColor="#00b2f0">
<DefaultTile ShortName="MC CPP" ShowName="allLogos" />
<SplashScreen Image="Assets\splash-sdk.png" BackgroundColor="#00b2f0" />
</VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="picturesLibrary" />
<Capability Name="musicLibrary" />
<Capability Name="videosLibrary" />
<DeviceCapability Name="webcam" />
<DeviceCapability Name="microphone" />
</Capabilities>
<Extensions>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
<Path>GrayscaleTransform.dll</Path>
<ActivatableClass ActivatableClassId="GrayscaleTransform.GrayscaleEffect" ThreadingModel="both" />
</InProcessServer>
</Extension>
</Extensions>
</Package>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment