Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
Add support for MRC recording indicator toggling
Browse files Browse the repository at this point in the history
Allow enabling and disabling the on-screen recording indicator while
Mixed Reality Capture (MRC) is active.
  • Loading branch information
djee-ms committed Oct 16, 2019
1 parent 8dabe48 commit 08e83d3
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 14 deletions.
9 changes: 8 additions & 1 deletion libs/Microsoft.MixedReality.WebRTC.Native/include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ rtc::Thread* UnsafeGetWorkerThread();

extern "C" {

/// 32-bit boolean for interop API.
enum class mrsBool : int32_t { kTrue = -1, kFalse = 0 };

//
// Errors
//
Expand Down Expand Up @@ -478,7 +481,11 @@ struct VideoDeviceConfiguration {
/// shared apps with the restricted capability "rescap:screenDuplication". In
/// any other case the capability will not be granted and MRC will silently
/// fail, falling back to a simple webcam video feed without holograms.
bool enable_mrc = true;
mrsBool enable_mrc = mrsBool::kTrue;

/// When Mixed Reality Capture is enabled, enable or disable the recording
/// indicator shown on screen.
mrsBool enable_mrc_recording_indicator = mrsBool::kTrue;
};

/// Add a local video track from a local video capture device (webcam) to
Expand Down
4 changes: 3 additions & 1 deletion libs/Microsoft.MixedReality.WebRTC.Native/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ mrsResult OpenVideoCaptureDevice(
}
createParams->videoProfileKind =
(wrapper::org::webRtc::VideoProfileKind)config.video_profile_kind;
createParams->enableMrc = config.enable_mrc;
createParams->enableMrc = (config.enable_mrc != mrsBool::kFalse);
createParams->enableMrcRecordingIndicator =
(config.enable_mrc_recording_indicator != mrsBool::kFalse);
createParams->width = config.width;
createParams->height = config.height;
createParams->framerate = config.framerate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class LocalVideoSourceEditor : UnityEditor.Editor
SerializedProperty _autoStartCapture;
SerializedProperty _preferredVideoCodec;
SerializedProperty _enableMixedRealityCapture;
SerializedProperty _enableMrcRecordingIndicator;
SerializedProperty _autoAddTrack;
SerializedProperty _mode;
SerializedProperty _videoProfileId;
Expand Down Expand Up @@ -79,6 +80,7 @@ void OnEnable()
_autoStartCapture = serializedObject.FindProperty("AutoStartCapture");
_preferredVideoCodec = serializedObject.FindProperty("PreferredVideoCodec");
_enableMixedRealityCapture = serializedObject.FindProperty("EnableMixedRealityCapture");
_enableMrcRecordingIndicator = serializedObject.FindProperty("EnableMRCRecordingIndicator");
_autoAddTrack = serializedObject.FindProperty("AutoAddTrack");
_mode = serializedObject.FindProperty("Mode");
_videoProfileId = serializedObject.FindProperty("VideoProfileId");
Expand All @@ -103,12 +105,16 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_autoStartCapture);

EditorGUILayout.PropertyField(_enableMixedRealityCapture);
if (_enableMixedRealityCapture.boolValue && !PlayerSettings.virtualRealitySupported)
{
EditorGUILayout.HelpBox("Mixed Reality Capture can only work in exclusive-mode apps. XR support must be enabled in Project Settings > Player > XR Settings > Virtual Reality Supported, and the project then saved to disk.", MessageType.Error);
if (GUILayout.Button("Enable XR support"))
if (_enableMixedRealityCapture.boolValue)
{
EditorGUILayout.PropertyField(_enableMrcRecordingIndicator);
if (!PlayerSettings.virtualRealitySupported)
{
PlayerSettings.virtualRealitySupported = true;
EditorGUILayout.HelpBox("Mixed Reality Capture can only work in exclusive-mode apps. XR support must be enabled in Project Settings > Player > XR Settings > Virtual Reality Supported, and the project then saved to disk.", MessageType.Error);
if (GUILayout.Button("Enable XR support"))
{
PlayerSettings.virtualRealitySupported = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LocalAudioSource : AudioSource
/// <summary>
/// Peer connection this local audio source will add an audio track to.
/// </summary>
[Header("Video track")]
[Header("Audio track")]
public PeerConnection PeerConnection;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ public class LocalVideoSource : VideoSource

/// <summary>
/// Enable Mixed Reality Capture (MRC) if available on the local device.
/// This option has no effect on devices not supporting MRC.
/// This option has no effect on devices not supporting MRC, and is silently ignored.
/// </summary>
[Tooltip("Enable Mixed Reality Capture (MRC) if available on the local device")]
public bool EnableMixedRealityCapture = true;
public bool EnableMixedRealityCapture = true;

/// <summary>
/// Enable the on-screen recording indicator when Mixed Reality Capture (MRC) is
/// available and enabled.
/// This option has no effect on devices not supporting MRC, or if MRC is not enabled.
/// </summary>
[Tooltip("Enable the on-screen recording indicator when MRC is enabled")]
public bool EnableMRCRecordingIndicator = true;

/// <summary>
/// Peer connection this local video source will add a video track to.
Expand Down Expand Up @@ -253,7 +261,8 @@ private void AddLocalVideoTrackImpl(WebRTC.PeerConnection nativePeer)
width = (width > 0 ? (uint?)width : null),
height = (height > 0 ? (uint?)height : null),
framerate = (framerate > 0 ? (double?)framerate : null),
enableMrc = EnableMixedRealityCapture
enableMrc = EnableMixedRealityCapture,
enableMrcRecordingIndicator = EnableMRCRecordingIndicator
};
nativePeer.AddLocalVideoTrackAsync(trackSettings);
VideoStreamStarted.Invoke();
Expand Down
14 changes: 14 additions & 0 deletions libs/Microsoft.MixedReality.WebRTC/Interop/InteropUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

namespace Microsoft.MixedReality.WebRTC.Interop
{
/// <summary>
/// Interop boolean.
/// </summary>
[StructLayout(LayoutKind.Sequential, Size = 4)]
internal struct mrsBool
{
public static readonly mrsBool True = new mrsBool(true);
public static readonly mrsBool False = new mrsBool(false);
private int _value;
public mrsBool(bool value) { _value = (value ? -1 : 0); }
public static explicit operator mrsBool(bool b) { return (b ? True : False); }
public static explicit operator bool(mrsBool b) { return (b._value != 0); }
}

/// <summary>
/// Attribute to decorate managed delegates used as native callbacks (reverse P/Invoke).
/// Required by Mono in Ahead-Of-Time (AOT) compiling, and Unity with the IL2CPP backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,57 @@ internal struct VideoDeviceConfiguration
/// </summary>
public string VideoDeviceId;

/// <summary>
/// Optional video profile unique identifier to use.
/// Ignored if the video capture device specified by <see cref="VideoDeviceId"/> does not
/// support video profiles.
/// </summary>
/// <remarks>
/// This is generally preferred over <see cref="VideoProfileKind"/> to get full
/// control over the video profile selection. Specifying both this and <see cref="VideoProfileKind"/>
/// is discouraged, as it over-constraints the selection algorithm.
/// </remarks>
/// <seealso xref="MediaCapture.IsVideoProfileSupported(string)"/>
public string VideoProfileId;

/// <summary>
/// Optional video profile kind to select a video profile from.
/// Ignored if the video capture device specified by <see cref="VideoDeviceId"/> does not
/// support video profiles.
/// </summary>
/// <remarks>
/// This is generally preferred over <see cref="VideoProfileId"/> to find a matching
/// capture format (resolution and/or framerate) when one does not care about which video
/// profile provides this capture format. Specifying both this and <see cref="VideoProfileId"/>
/// is discouraged, as it over-constraints the selection algorithm.
/// </remarks>
/// <seealso xref="MediaCapture.IsVideoProfileSupported(string)"/>
public PeerConnection.VideoProfileKind VideoProfileKind;

/// <summary>
/// Optional capture resolution width, in pixels, or zero for no constraint.
/// </summary>
public uint Width;

/// <summary>
/// Optional capture resolution height, in pixels, or zero for no constraint.
/// </summary>
public uint Height;

/// <summary>
/// Optional capture framerate, in frames per second (FPS), or zero for no constraint.
/// </summary>
public double Framerate;

/// <summary>
/// Enable Mixed Reality Capture (MRC). This flag is ignored if the platform doesn't support MRC.
/// </summary>
public bool EnableMixedRealityCapture;
public mrsBool EnableMixedRealityCapture;

/// <summary>
/// When MRC is enabled, enable the on-screen recording indicator.
/// </summary>
public mrsBool EnableMRCRecordingIndicator;
}


Expand Down
22 changes: 20 additions & 2 deletions libs/Microsoft.MixedReality.WebRTC/PeerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,22 +406,39 @@ public class LocalVideoTrackSettings
public VideoProfileKind videoProfileKind = VideoProfileKind.Unspecified;

/// <summary>
/// Enable Mixed Reality Capture on devices supporting the feature.
/// Enable Mixed Reality Capture (MRC) on devices supporting the feature.
/// This setting is silently ignored on device not supporting MRC.
/// </summary>
/// <remarks>
/// This is only supported on UWP.
/// </remarks>
public bool enableMrc = true;

/// <summary>
/// Display the on-screen recording indicator while MRC is enabled.
/// This setting is silently ignored on device not supporting MRC, or if
/// <see cref="enableMrc"/> is set to <c>false</c>.
/// </summary>
/// <remarks>
/// This is only supported on UWP.
/// </remarks>
public bool enableMrcRecordingIndicator = true;

/// <summary>
/// Optional capture resolution width, in pixels.
/// This must be a resolution width the device supports.
/// </summary>
public uint? width;

/// <summary>
/// Optional capture resolution height, in pixels.
/// This must be a resolution width the device supports.
/// </summary>
public uint? height;

/// <summary>
/// Optional capture frame rate, in frames per second (FPS).
/// This must be a capture framerate the device supports.
/// </summary>
/// <remarks>
/// This is compared by strict equality, so is best left unspecified or to an exact value
Expand Down Expand Up @@ -881,7 +898,8 @@ public Task AddLocalVideoTrackAsync(LocalVideoTrackSettings settings = default)
Width = settings.width.GetValueOrDefault(0),
Height = settings.height.GetValueOrDefault(0),
Framerate = settings.framerate.GetValueOrDefault(0.0),
EnableMixedRealityCapture = settings.enableMrc
EnableMixedRealityCapture = (mrsBool)settings.enableMrc,
EnableMRCRecordingIndicator = (mrsBool)settings.enableMrcRecordingIndicator
} : new PeerConnectionInterop.VideoDeviceConfiguration());
uint res = PeerConnectionInterop.PeerConnection_AddLocalVideoTrack(_nativePeerhandle, config);
Utils.ThrowOnErrorCode(res);
Expand Down

0 comments on commit 08e83d3

Please sign in to comment.