// License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. namespace Intel.RealSense { using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using Base; /// /// Class to store the profile of stream /// public class StreamProfile : Base.PooledObject { [DebuggerBrowsable(DebuggerBrowsableState.Never)] internal static readonly Base.Deleter StreamProfileReleaser = NativeMethods.rs2_delete_stream_profile; internal override void Initialize() { object error; NativeMethods.rs2_get_stream_profile_data(Handle, out stream, out format, out index, out uniqueId, out framerate, out error); IsDefault = NativeMethods.rs2_is_stream_profile_default(Handle, out error) > 0; } internal StreamProfile(IntPtr ptr) : base(ptr, null) { this.Initialize(); } protected override void Dispose(bool disposing) { if (disposing) { if (clone != null) { clone.Dispose(); clone = null; } } base.Dispose(disposing); } [DebuggerBrowsable(DebuggerBrowsableState.Never)] private Stream stream; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private Format format; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private int framerate; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private int index; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private int uniqueId; [DebuggerBrowsable(DebuggerBrowsableState.Never)] internal DeleterHandle clone; /// /// Gets the stream type of the profile /// public Stream Stream { get { return stream; } } /// /// Gets the binary data format of the profile /// public Format Format { get { return format; } } /// /// Gets the expected rate for data frames to arrive, meaning expected number of frames per second /// public int Framerate { get { return framerate; } } /// /// Gets the stream index the input profile in case there are multiple streams of the same type /// public int Index { get { return index; } } /// /// Gets the identifier for the stream profile, unique within the application /// public int UniqueID { get { return uniqueId; } } /// /// Gets a value indicating whether the profile is recommended for the sensor /// /// This is an optional hint we offer to suggest profiles with best performance-quality tradeof /// /// public bool IsDefault { get; private set; } public bool IsCloned => clone?.IsInvalid == false; /// /// Gets the extrinsics from this profile to the other /// /// target stream profile /// extrinsics from this to target public Extrinsics GetExtrinsicsTo(StreamProfile other) { object error; Extrinsics extrinsics; NativeMethods.rs2_get_extrinsics(Handle, other.Handle, out extrinsics, out error); return extrinsics; } public void RegisterExtrinsicsTo(StreamProfile other, Extrinsics extrinsics) { object error; NativeMethods.rs2_register_extrinsics(Handle, other.Handle, extrinsics, out error); } /// /// Clone the current profile and change the type, index and format to input parameters /// /// will change the stream type from the cloned profile. /// will change the stream index from the cloned profile. /// will change the stream format from the cloned profile. /// the cloned stream profile. public StreamProfile Clone(Stream type, int index, Format format) { object error; var ptr = NativeMethods.rs2_clone_stream_profile(Handle, type, index, format, out error); var p = StreamProfile.Create(ptr); p.clone = new DeleterHandle(ptr, StreamProfileReleaser); return p; } /// /// Try to extend stream profile to an extension type /// /// extension type /// true if profile is extendable to specified extension public bool Is(Extension e) { object error; return NativeMethods.rs2_stream_profile_is(Handle, e, out error) > 0; } public T As() where T : StreamProfile { return Create(Handle); } public T Cast() where T : StreamProfile { using (this) { return Create(Handle); } } internal static T Create(IntPtr ptr) where T : StreamProfile { return ObjectPool.Get(ptr); } internal static StreamProfile Create(IntPtr ptr) { return Create(ptr); } } }