Skip to content

Commit

Permalink
A simple video panel UI that can display images. Images are not upsid…
Browse files Browse the repository at this point in the history
…e-down. You can set resolution and frame rate.
  • Loading branch information
motionsmith committed Apr 11, 2017
1 parent 7bfe64f commit 99bc9e3
Show file tree
Hide file tree
Showing 20 changed files with 681 additions and 89 deletions.
3 changes: 3 additions & 0 deletions HoloLensCameraStream/Dummy Project/Dummy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<Compile Include="VideoCaptureSample.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetDir)$(TargetFileName)" "$(SolutionDir)..\HoloLensVideoCaptureExample\Assets\CamStream\Plugins\WSA\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
3 changes: 3 additions & 0 deletions HoloLensCameraStream/Plugin Project/Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetDir)$(TargetFileName)" "$(SolutionDir)..\HoloLensVideoCaptureExample\Assets\CamStream\Plugins\WSA\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
21 changes: 11 additions & 10 deletions HoloLensCameraStream/Plugin Project/VideoCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public bool IsStreaming
}
}

static MediaStreamType streamType = MediaStreamType.VideoPreview;
static readonly MediaStreamType STREAM_TYPE = MediaStreamType.VideoPreview;
static readonly Guid ROTATION_KEY = new Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1");

MediaFrameSourceGroup _frameSourceGroup;
MediaFrameSourceInfo _frameSourceInfo;
Expand All @@ -123,7 +124,7 @@ public bool IsStreaming
public static async void CreateAync(OnVideoCaptureResourceCreatedCallback onCreatedCallback)
{
var allFrameSourceGroups = await MediaFrameSourceGroup.FindAllAsync(); //Returns IReadOnlyList<MediaFrameSourceGroup>
var candidateFrameSourceGroups = allFrameSourceGroups.Where(group => group.SourceInfos.Any(IsColorVideoPreview)); //Returns IEnumerable<MediaFrameSourceGroup>
var candidateFrameSourceGroups = allFrameSourceGroups.Where(group => group.SourceInfos.Any(IsColorVideo)); //Returns IEnumerable<MediaFrameSourceGroup>
var selectedFrameSourceGroup = candidateFrameSourceGroups.FirstOrDefault(); //Returns a single MediaFrameSourceGroup

if (selectedFrameSourceGroup == null)
Expand Down Expand Up @@ -158,7 +159,7 @@ public IEnumerable<Resolution> GetSupportedResolutions()
{
List<Resolution> resolutions = new List<Resolution>();

var allPropertySets = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(streamType).Select(x => x as VideoEncodingProperties); //Returns IEnumerable<VideoEncodingProperties>
var allPropertySets = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(STREAM_TYPE).Select(x => x as VideoEncodingProperties); //Returns IEnumerable<VideoEncodingProperties>
foreach (var propertySet in allPropertySets)
{
resolutions.Add(new Resolution((int)propertySet.Width, (int)propertySet.Height));
Expand All @@ -170,7 +171,7 @@ public IEnumerable<Resolution> GetSupportedResolutions()
public IEnumerable<float> GetSupportedFrameRatesForResolution(Resolution resolution)
{
//Get all property sets that match the supported resolution
var allPropertySets = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(streamType).Select((x) => x as VideoEncodingProperties)
var allPropertySets = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(STREAM_TYPE).Select((x) => x as VideoEncodingProperties)
.Where((x) =>
{
return x != null &&
Expand Down Expand Up @@ -225,9 +226,9 @@ public async void StartVideoModeAsync(CameraParameters setupParams, OnVideoModeS
_frameReader.FrameArrived += HandleFrameArrived;
await _frameReader.StartAsync();
VideoEncodingProperties properties = GetVideoEncodingPropertiesForCameraParams(setupParams);

//TODO: Cannot set the encoding properties yet. This is producing an error which I haven't solved.
//await _mediaCapture.SetEncodingPropertiesAsync(streamType, properties, null);
properties.Properties.Add(ROTATION_KEY, 180);
await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(STREAM_TYPE, properties);

onVideoModeStartedCallback?.Invoke(new VideoCaptureResult(0, ResultType.Success, true));
}
Expand Down Expand Up @@ -347,7 +348,7 @@ void HandleFrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args

VideoEncodingProperties GetVideoEncodingPropertiesForCameraParams(CameraParameters cameraParams)
{
var allPropertySets = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(streamType).Select((x) => x as VideoEncodingProperties)
var allPropertySets = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(STREAM_TYPE).Select((x) => x as VideoEncodingProperties)
.Where((x) =>
{
if (x == null) return false;
Expand All @@ -370,10 +371,10 @@ VideoEncodingProperties GetVideoEncodingPropertiesForCameraParams(CameraParamete
return chosenPropertySet;
}

static bool IsColorVideoPreview(MediaFrameSourceInfo sourceInfo)
static bool IsColorVideo(MediaFrameSourceInfo sourceInfo)
{
//TODO: Determine whether 'VideoPreview' or 'VideoRecord' is the appropriate type. What's the difference?
return (sourceInfo.MediaStreamType == streamType &&
return (sourceInfo.MediaStreamType == STREAM_TYPE &&
sourceInfo.SourceKind == MediaFrameSourceKind.Color);
}

Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 99bc9e3

Please sign in to comment.