Skip to content

Commit

Permalink
Windows 10 Version 1709 - February 2018 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnewthing committed Feb 8, 2018
1 parent e924715 commit c2ca5ee
Show file tree
Hide file tree
Showing 281 changed files with 412 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Samples/360VideoPlayback/cpp/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Properties>
<DisplayName>360 Video Playback C++ Sample</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
<Logo>Assets\StoreLogo-sdk.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.15063.0" MaxVersionTested="10.0.16299.0"/>
Expand Down
4 changes: 2 additions & 2 deletions Samples/360VideoPlayback/cs/Common/DeviceResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ private void CreateDeviceIndependentResources()

// Initialize Direct2D resources.
var debugLevel = SharpDX.Direct2D1.DebugLevel.None;
//#if DEBUG
#if DEBUG
if (DirectXHelper.SdkLayersAvailable())
{
debugLevel = SharpDX.Direct2D1.DebugLevel.Information;
}
//#endif
#endif

// Initialize the Direct2D Factory.
d2dFactory = this.ToDispose(
Expand Down
2 changes: 1 addition & 1 deletion Samples/360VideoPlayback/cs/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Properties>
<DisplayName>360 Video Playback C# Sample</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
<Logo>Assets\StoreLogo-sdk.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.15063.0" MaxVersionTested="10.0.16299.0"/>
Expand Down
3 changes: 0 additions & 3 deletions Samples/BarcodeScanner/cs/BarcodeScanner.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
Expand Down Expand Up @@ -39,5 +38,3 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal


Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

50 changes: 36 additions & 14 deletions Samples/CameraGetPreviewFrame/cs/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.Devices.Enumeration;
Expand Down Expand Up @@ -63,6 +64,7 @@ public sealed partial class MainPage : Page
private MediaCapture _mediaCapture;
private bool _isInitialized = false;
private bool _isPreviewing = false;
private static readonly SemaphoreSlim _mediaCaptureLifeLock = new SemaphoreSlim(1);

// Information about the camera device
private bool _mirroringPreview = false;
Expand Down Expand Up @@ -93,7 +95,7 @@ private async void Application_Suspending(object sender, SuspendingEventArgs e)
await CleanupCameraAsync();

_displayInformation.OrientationChanged -= DisplayInformation_OrientationChanged;

deferral.Complete();
}
}
Expand Down Expand Up @@ -213,6 +215,8 @@ private async Task InitializeCameraAsync()
{
Debug.WriteLine("InitializeCameraAsync");

await _mediaCaptureLifeLock.WaitAsync();

if (_mediaCapture == null)
{
// Attempt to get the back camera if one is available, but use any camera device if not
Expand All @@ -221,6 +225,7 @@ private async Task InitializeCameraAsync()
if (cameraDevice == null)
{
Debug.WriteLine("No camera device found!");
_mediaCaptureLifeLock.Release();
return;
}

Expand All @@ -242,6 +247,10 @@ private async Task InitializeCameraAsync()
{
Debug.WriteLine("The app was denied access to the camera");
}
finally
{
_mediaCaptureLifeLock.Release();
}

// If initialization succeeded, start the preview
if (_isInitialized)
Expand All @@ -260,14 +269,18 @@ private async Task InitializeCameraAsync()
// Only mirror the preview if the camera is on the front panel
_mirroringPreview = (cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
}

await StartPreviewAsync();

var picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
// Fall back to the local app storage if the Pictures Library is not available
_captureFolder = picturesLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder;
}
}
else
{
_mediaCaptureLifeLock.Release();
}
}

/// <summary>
Expand Down Expand Up @@ -436,24 +449,33 @@ private async Task GetPreviewFrameAsD3DSurfaceAsync()
/// <returns></returns>
private async Task CleanupCameraAsync()
{
if (_isInitialized)
await _mediaCaptureLifeLock.WaitAsync();

try
{
if (_isPreviewing)
if (_isInitialized)
{
// The call to stop the preview is included here for completeness, but can be
// safely removed if a call to MediaCapture.Dispose() is being made later,
// as the preview will be automatically stopped at that point
await StopPreviewAsync();
if (_isPreviewing)
{
// The call to stop the preview is included here for completeness, but can be
// safely removed if a call to MediaCapture.Dispose() is being made later,
// as the preview will be automatically stopped at that point
await StopPreviewAsync();
}

_isInitialized = false;
}

_isInitialized = false;
if (_mediaCapture != null)
{
_mediaCapture.Failed -= MediaCapture_Failed;
_mediaCapture.Dispose();
_mediaCapture = null;
}
}

if (_mediaCapture != null)
finally
{
_mediaCapture.Failed -= MediaCapture_Failed;
_mediaCapture.Dispose();
_mediaCapture = null;
_mediaCaptureLifeLock.Release();
}
}

Expand Down
26 changes: 26 additions & 0 deletions Samples/CameraResolution/cpp/SampleConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,37 @@
#include "MainPage.xaml.h"
#include "SampleConfiguration.h"

using namespace Concurrency;
using namespace SDKTemplate;
using namespace Windows::Devices;
using namespace Windows::Devices::Enumeration;
using namespace Windows::Media::Capture;
using namespace Windows::Media::MediaProperties;
using namespace Windows::UI::Xaml::Controls;

Platform::Array<Scenario>^ MainPage::scenariosInner = ref new Platform::Array<Scenario>
{
{ "Change camera preview settings", "SDKTemplate.Scenario1_PreviewSettings" },
{ "Change preview and photo settings", "SDKTemplate.Scenario2_PhotoSettings" },
{ "Match aspect ratios", "SDKTemplate.Scenario3_AspectRatio" }
};

/// <summary>
/// Sets encoding properties on a camera stream. Ensures CaptureElement and preview stream are stopped before setting properties.
/// </summary>
task<void> MainPage::SetMediaStreamPropertiesAsync(MediaCapture^ mediaCapture, CaptureElement^ previewControl, MediaStreamType streamType, IMediaEncodingProperties^ encodingProperties)
{
// Stop preview and unlink the CaptureElement from the MediaCapture object
return create_task(mediaCapture->StopPreviewAsync())
.then([this, mediaCapture, previewControl, streamType, encodingProperties]()
{
previewControl->Source = nullptr;
// Apply desired stream properties
return create_task(mediaCapture->VideoDeviceController->SetMediaStreamPropertiesAsync(streamType, encodingProperties));
}).then([this, mediaCapture, previewControl]() {
// Recreate the CaptureElement pipeline and restart the preview
previewControl->Source = mediaCapture;
return create_task(mediaCapture->StartPreviewAsync());
});
}

2 changes: 2 additions & 0 deletions Samples/CameraResolution/cpp/SampleConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace SDKTemplate
}
}

Concurrency::task<void> SetMediaStreamPropertiesAsync(Windows::Media::Capture::MediaCapture^ mediaCapture, Windows::UI::Xaml::Controls::CaptureElement^ previewControl, Windows::Media::Capture::MediaStreamType streamType, Windows::Media::MediaProperties::IMediaEncodingProperties ^ encodingProperties);

private:
static Platform::Array<Scenario>^ scenariosInner;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void Scenario1_PreviewSettings::ComboBoxSettings_Changed(Platform::Object^ sende
{
auto selectedItem = static_cast<ComboBoxItem^>(static_cast<ComboBox^>(sender)->SelectedItem);
auto encodingProperties = static_cast<IMediaEncodingProperties^>(selectedItem->Tag);
create_task(_mediaCapture->VideoDeviceController->SetMediaStreamPropertiesAsync(MediaStreamType::VideoPreview, encodingProperties));
create_task(_rootPage->SetMediaStreamPropertiesAsync(_mediaCapture.Get(), PreviewControl, MediaStreamType::VideoPreview, encodingProperties));
}
}

Expand Down
4 changes: 2 additions & 2 deletions Samples/CameraResolution/cpp/Scenario2_PhotoSettings.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void Scenario2_PhotoSettings::PreviewSettings_Changed(Platform::Object^ sender,
{
auto selectedItem = static_cast<ComboBoxItem^>(static_cast<ComboBox^>(sender)->SelectedItem);
auto encodingProperties = static_cast<IMediaEncodingProperties^>(selectedItem->Tag);
create_task(_mediaCapture->VideoDeviceController->SetMediaStreamPropertiesAsync(MediaStreamType::VideoPreview, encodingProperties));
create_task(_rootPage->SetMediaStreamPropertiesAsync(_mediaCapture.Get(), PreviewControl, MediaStreamType::VideoPreview, encodingProperties));
}
}

Expand All @@ -206,7 +206,7 @@ void Scenario2_PhotoSettings::PhotoSettings_Changed(Platform::Object^ sender, Wi
{
auto selectedItem = static_cast<ComboBoxItem^>(static_cast<ComboBox^>(sender)->SelectedItem);
auto encodingProperties = static_cast<IMediaEncodingProperties^>(selectedItem->Tag);
create_task(_mediaCapture->VideoDeviceController->SetMediaStreamPropertiesAsync(MediaStreamType::Photo, encodingProperties));
create_task(_rootPage->SetMediaStreamPropertiesAsync(_mediaCapture.Get(), PreviewControl, MediaStreamType::Photo, encodingProperties));
}
}

Expand Down
4 changes: 2 additions & 2 deletions Samples/CameraResolution/cpp/Scenario3_AspectRatio.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void Scenario3_AspectRatio::PreviewSettings_Changed(Platform::Object^ sender, Wi
{
auto selectedItem = static_cast<ComboBoxItem^>(static_cast<ComboBox^>(sender)->SelectedItem);
auto encodingProperties = static_cast<IMediaEncodingProperties^>(selectedItem->Tag);
create_task(_mediaCapture->VideoDeviceController->SetMediaStreamPropertiesAsync(MediaStreamType::VideoPreview, encodingProperties));
create_task(_rootPage->SetMediaStreamPropertiesAsync(_mediaCapture.Get(), PreviewControl, MediaStreamType::VideoPreview, encodingProperties));

// The preview just changed, update the video combo box
MatchPreviewAspectRatio();
Expand All @@ -227,7 +227,7 @@ void Scenario3_AspectRatio::VideoSettings_Changed(Platform::Object^ sender, Wind
{
auto selectedItem = static_cast<ComboBoxItem^>(static_cast<ComboBox^>(sender)->SelectedItem);
auto encodingProperties = static_cast<IMediaEncodingProperties^>(selectedItem->Tag);
create_task(_mediaCapture->VideoDeviceController->SetMediaStreamPropertiesAsync(MediaStreamType::VideoRecord, encodingProperties));
create_task(_rootPage->SetMediaStreamPropertiesAsync(_mediaCapture.Get(), PreviewControl, MediaStreamType::VideoRecord, encodingProperties));
}
}

Expand Down
17 changes: 17 additions & 0 deletions Samples/CameraResolution/cs/SampleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Windows.UI.Xaml.Controls;
using Windows.Media.Capture;
using Windows.UI.Core;
using Windows.Media.MediaProperties;

namespace SDKTemplate
{
Expand Down Expand Up @@ -50,6 +51,22 @@ public MediaCapturePreviewer(CaptureElement previewControl, CoreDispatcher dispa
public bool IsRecording { get; set; }
public MediaCapture MediaCapture { get; private set; }

/// <summary>
/// Sets encoding properties on a camera stream. Ensures CaptureElement and preview stream are stopped before setting properties.
/// </summary>
public async Task SetMediaStreamPropertiesAsync(MediaStreamType streamType, IMediaEncodingProperties encodingProperties)
{
// Stop preview and unlink the CaptureElement from the MediaCapture object
await MediaCapture.StopPreviewAsync();
_previewControl.Source = null;

// Apply desired stream properties
await MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, encodingProperties);

// Recreate the CaptureElement pipeline and restart the preview
_previewControl.Source = MediaCapture;
await MediaCapture.StartPreviewAsync();
}

/// <summary>
/// Initializes the MediaCapture, starts preview.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private async void ComboBoxSettings_Changed(object sender, RoutedEventArgs e)
{
var selectedItem = (sender as ComboBox).SelectedItem as ComboBoxItem;
var encodingProperties = (selectedItem.Tag as StreamResolution).EncodingProperties;
await _previewer.MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, encodingProperties);
await _previewer.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, encodingProperties);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private async void PreviewSettings_Changed(object sender, RoutedEventArgs e)
{
var selectedItem = (sender as ComboBox).SelectedItem as ComboBoxItem;
var encodingProperties = (selectedItem.Tag as StreamResolution).EncodingProperties;
await _previewer.MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, encodingProperties);
await _previewer.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, encodingProperties);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Samples/CameraResolution/cs/Scenario3_AspectRatio.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private async void PreviewSettings_Changed(object sender, RoutedEventArgs e)
{
var selectedItem = (sender as ComboBox).SelectedItem as ComboBoxItem;
var encodingProperties = (selectedItem.Tag as StreamResolution).EncodingProperties;
await _previewer.MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, encodingProperties);
await _previewer.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, encodingProperties);

// The preview just changed, update the video combo box
MatchPreviewAspectRatio();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
if (cameraSettings.value == "")
return;

mediaCapture.videoDeviceController.setMediaStreamPropertiesAsync(Capture.MediaStreamType.videoPreview, allProperties[cameraSettings.value]);
setMediaStreamPropertiesAsync(mediaCapture, Capture.MediaStreamType.videoPreview, allProperties[cameraSettings.value]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Samples/CameraResolution/js/js/Scenario2_PhotoSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
if (previewSettings.value == "")
return;

mediaCapture.videoDeviceController.setMediaStreamPropertiesAsync(Capture.MediaStreamType.videoPreview, previewProperties[previewSettings.value]);
setMediaStreamPropertiesAsync(mediaCapture, Capture.MediaStreamType.videoPreview, previewProperties[previewSettings.value]);
}
}

Expand All @@ -114,7 +114,7 @@
if (photoSettings.value == "")
return;

mediaCapture.videoDeviceController.setMediaStreamPropertiesAsync(Capture.MediaStreamType.videoPreview, photoProperties[photoSettings.value]);
setMediaStreamPropertiesAsync(mediaCapture, Capture.MediaStreamType.videoPreview, photoProperties[photoSettings.value]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Samples/CameraResolution/js/js/Scenario3_AspectRatio.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
if (previewSettings.value == "")
return;
console.log(previewSettings.value)
mediaCapture.videoDeviceController.setMediaStreamPropertiesAsync(Capture.MediaStreamType.videoPreview, previewProperties[previewSettings.value]);
setMediaStreamPropertiesAsync(mediaCapture, Capture.MediaStreamType.videoPreview, previewProperties[previewSettings.value]);

// The preview just changed, update the video combo box
MatchPreviewAspectRatio();
Expand All @@ -128,7 +128,7 @@
// The first element is just text
if (videoSettings.value == "")
return;
mediaCapture.videoDeviceController.setMediaStreamPropertiesAsync(Capture.MediaStreamType.videoRecord, videoProperties[videoSettings.value]);
setMediaStreamPropertiesAsync(mediaCapture, Capture.MediaStreamType.videoRecord, videoProperties[videoSettings.value]);
}
}

Expand Down
20 changes: 20 additions & 0 deletions Samples/CameraResolution/js/js/StreamResolutionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,23 @@ streamResolutionHelper.prototype.frameRate = function () {
streamResolutionHelper.prototype.aspectRatio = function () {
return (this.width() / this.height()).toFixed(2);
}

/// <summary>
/// Sets encoding properties on a camera stream. Ensures VideoElement and preview stream are stopped before setting properties.
/// </summary>
function setMediaStreamPropertiesAsync(mediaCapture, streamType, encodingProperties) {
// Stop preview and unlink the VideoElement from the MediaCapture object
var previewVidTag = document.getElementById("cameraPreview");
previewVidTag.pause;
previewVidTag.src = null;

// Apply desired stream properties
return mediaCapture.videoDeviceController.setMediaStreamPropertiesAsync(streamType, encodingProperties)
.then(function () {
// Recreate pipeline and restart the preview
var previewVidTag = document.getElementById("cameraPreview");
var previewUrl = URL.createObjectURL(mediaCapture);
previewVidTag.src = previewUrl;
previewVidTag.play();
});
}
Loading

0 comments on commit c2ca5ee

Please sign in to comment.