Commit 5600fc90 authored by Jason Williams's avatar Jason Williams
Browse files

Merge remote-tracking branch 'origin/master'

parents 398b871d 935bd752
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -376,7 +376,7 @@ namespace SampleWdpClient

                    try
                    {
                        await portal.Reboot();
                        await this.portal.Reboot();
                    }
                    catch(Exception ex)
                    {
@@ -421,7 +421,7 @@ namespace SampleWdpClient

                    try
                    {
                        await portal.Shutdown();
                        await this.portal.Shutdown();
                    }
                    catch(Exception ex)
                    {
+21 −13
Original line number Diff line number Diff line
@@ -18,20 +18,25 @@ namespace Microsoft.Tools.WindowsDevicePortal
    public partial class DevicePortal
    {
        /// <summary>
        ///  API for getting or deleting a Mixed Reality Capture file
        ///  API for getting or deleting a Mixed Reality Capture file.
        /// </summary>
        public static readonly string MrcFileApi = "api/holographic/mrc/file";

        /// <summary>
        /// API for getting the list of Holographic Mixed Reality Capture files
        /// API for getting the list of Holographic Mixed Reality Capture files.
        /// </summary>
        public static readonly string MrcFileListApi = "api/holographic/mrc/files";

        /// <summary>
        /// API for taking a Mixed Reality Capture photo 
        /// API for taking a Mixed Reality Capture photo.
        /// </summary>
        public static readonly string MrcPhotoApi = "api/holographic/mrc/photo";

        /// <summary>
        /// API for getting or setting the default Mixed Reality Capture settings.
        /// </summary>
        public static readonly string MrcSettingsApi = "api/holographic/mrc/settings";

        /// <summary>
        /// API for starting a Holographic Mixed Reality Capture recording.
        /// </summary>
@@ -76,7 +81,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// Removes a Mixed Reality Capture file from the device's local storage.
        /// </summary>
        /// <param name="fileName">The name of the file to be deleted.</param>
        /// <returns>Task tracking the deletion request</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task DeleteMrcFile(string fileName)
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
@@ -94,7 +99,8 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// </summary>
        /// <param name="fileName">Name of the file to retrieve</param>
        /// <param name="isThumbnailRequest">Whether or not we just want a thumbnail</param>
        /// <returns>The raw capture data</returns>
        /// <returns>Byte array containing the file data.</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task<byte[]> GetMrcFileData(
            string fileName,
            bool isThumbnailRequest = false)
@@ -123,6 +129,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// Gets the list of capture files
        /// </summary>
        /// <returns>List of the capture files</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task<MrcFileList> GetMrcFileList()
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
@@ -150,6 +157,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// Gets the status of the reality capture
        /// </summary>
        /// <returns>Status of the capture</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task<MrcStatus> GetMrcStatus()
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
@@ -164,7 +172,8 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// Gets thumbnail data for the capture
        /// </summary>
        /// <param name="fileName">Name of the capture file</param>
        /// <returns>Thumbnail data</returns>
        /// <returns>Byte array containing the thumbnail image data</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task<byte[]> GetMrcThumbnailData(string fileName)
        {
            // GetMrcFileData checks for the appropriate platform. We do not need to duplicate the check here.
@@ -172,13 +181,13 @@ namespace Microsoft.Tools.WindowsDevicePortal
        }

        /// <summary>
        /// Starts a reality capture recording
        /// Starts a Mixed Reality Capture recording.
        /// </summary>
        /// <param name="includeHolograms">Whether to include holograms</param>
        /// <param name="includeColorCamera">Whether to include the color camera</param>
        /// <param name="includeMicrophone">Whether to include microphone data</param>
        /// <param name="includeAudio">Whether to include audio data</param>
        /// <returns>Task tracking the start recording request</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task StartMrcRecording(
            bool includeHolograms = true,
            bool includeColorCamera = true,
@@ -203,9 +212,9 @@ namespace Microsoft.Tools.WindowsDevicePortal
        }
        
        /// <summary>
        /// Stops the capture recording
        /// Stops the Mixed Reality Capture recording
        /// </summary>
        /// <returns>Task tracking the stop request</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task StopMrcRecording()
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
@@ -217,11 +226,11 @@ namespace Microsoft.Tools.WindowsDevicePortal
        }

        /// <summary>
        /// Take a capture photo
        /// Take a Mixed Reality Capture photo
        /// </summary>
        /// <param name="includeHolograms">Whether to include holograms</param>
        /// <param name="includeColorCamera">Whether to include the color camera</param>
        /// <returns>Task tracking the photo request</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task TakeMrcPhoto(
            bool includeHolograms = true,
            bool includeColorCamera = true)
@@ -237,7 +246,6 @@ namespace Microsoft.Tools.WindowsDevicePortal
        }

        #region Data contract

        /// <summary>
        /// Object representation of the capture file list
        /// </summary>
+121 −0
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@
// </copyright>
//----------------------------------------------------------------------------------------------

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;

namespace Microsoft.Tools.WindowsDevicePortal
@@ -28,8 +32,125 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// </summary>
        public static readonly string StopHolographicSimulationRecordingApi = "api/holographic/simulation/recording/stop";

        /// <summary>
        /// Gets the holographic simulation recording status.
        /// </summary>
        /// <returns>True if recording, false otherwise.</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task<bool> GetHolographicSimulationRecordingStatus()
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
            {
                throw new NotSupportedException("This method is only supported on HoloLens.");
            }

            HolographicSimulationRecordingStatus status = await this.Get<HolographicSimulationRecordingStatus>(HolographicSimulationRecordingStatusApi);
            return status.IsRecording;
        }

        /// <summary>
        /// Starts a Holographic Simulation recording session.
        /// </summary>
        /// <param name="name">The name of the recording.</param>
        /// <param name="recordHead">Should head data be recorded? The default value is true.</param>
        /// <param name="recordHands">Should hand data be recorded? The default value is true.</param>
        /// <param name="recordSpatialMapping">Should Spatial Mapping data be recorded? The default value is true.</param>
        /// <param name="recordEnvironment">Should environment data be recorded? The default value is true.</param>
        /// <param name="singleSpatialMappingFrame">Should the spatial mapping data be limited to a single frame? The default value is false.</param>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task StartHolographicSimulationRecording(
            string name,
            bool recordHead = true,
            bool recordHands = true,
            bool recordSpatialMapping = true,
            bool recordEnvironment = true)
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
            {
                throw new NotSupportedException("This method is only supported on HoloLens.");
            }

            string payload = string.Format(
                "head={0}&hands={1}&spatialMapping={2}&environment={3}&name={4}",
                recordHead ? 1 : 0,
                recordHands ? 1 : 0,
                recordSpatialMapping ? 1 : 0,
                recordEnvironment ? 1: 0,
                name);
            await this.Post(StartHolographicSimulationRecordingApi, payload);
        }

        /// <summary>
        /// Stops a Holographic Simulation recording session.
        /// </summary>
        /// <returns>Byte array containing the recorded data.</returns>
        /// <exception cref="InvalidOperationException">No recording was in progress.</exception>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task<byte[]> StopHolographicSimulationRecording()
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
            {
                throw new NotSupportedException("This method is only supported on HoloLens.");
            }

            Uri uri = Utilities.BuildEndpoint(
                this.deviceConnection.Connection,
                StopHolographicSimulationRecordingApi);

            byte[] dataBytes = null;

            using (Stream dataStream = await this.Get(uri))
            {
                if ((dataStream != null) &&
                    (dataStream.Length != 0))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(HolographicSimulationStopRecordingError));
                    HolographicSimulationStopRecordingError error = null;
 
                    try
                    {
                        // Try to get / interpret an error response.
                        error = (HolographicSimulationStopRecordingError)serializer.ReadObject(dataStream);
                    }
                    catch
                    {
                    }

                    if (error != null)
                    {
                        // We received an error response.
                        throw new InvalidOperationException(error.Reason);
                    }

                    // Getting here indicates that we have file data to return.
                    dataBytes = new byte[dataStream.Length];
                    dataStream.Read(dataBytes, 0, dataBytes.Length);
                }
            }

            return dataBytes;
        }

        #region Data contract
        public class HolographicSimulationStopRecordingError
        {
            [DataMember(Name = "Reason")]
            public string Reason { get; set; }
        }


        /// <summary>
        /// Object representation of Holographic Simulation recording status.
        /// </summary>
        [DataContract]
        public class HolographicSimulationRecordingStatus
        {
            /// <summary>
            /// Gets or sets the recording status.
            /// </summary>
            [DataMember(Name = "recording")]
            public bool IsRecording { get; set; }
        }
        #endregion // Data contract
    }
}