// 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.Runtime.InteropServices;
// TODO: rs2_create_playback_device
// TODO: rs2_playback_device_set_status_changed_callback
public class PlaybackDevice : Device
{
internal PlaybackDevice(IntPtr dev)
: base(dev)
{
}
///
/// Create a from existing
///
/// a device that supports
/// a new
/// Thrown when does not support
public static PlaybackDevice FromDevice(Device dev)
{
object error;
if (NativeMethods.rs2_is_device_extendable_to(dev.Handle, Extension.Playback, out error) == 0)
{
throw new ArgumentException($"Device does not support {nameof(Extension.Playback)}");
}
var playback = Device.Create(dev.Handle);
playback.FileName = Marshal.PtrToStringAnsi(NativeMethods.rs2_playback_device_get_file_path(dev.Handle, out error));
return playback;
}
///
/// Gets the path of the file used by the playback device
///
/// Path to the file used by the playback device
public string FileName { get; private set; }
///
/// Pauses the playback
///
///
/// Calling Pause() in "Paused" status does nothing
/// If Pause() is called while playback status is "Playing" or "Stopped", the playback will not play until Resume() is called
///
public void Pause()
{
object error;
NativeMethods.rs2_playback_device_pause(Handle, out error);
}
///
/// Un-pauses the playback
///
///
/// Calling Resume() while playback status is "Playing" or "Stopped" does nothing
///
public void Resume()
{
object error;
NativeMethods.rs2_playback_device_resume(Handle, out error);
}
///
/// Stops the playback
///
///
/// Calling Stop() will stop all streaming playback sensors and will reset the playback(returning to beginning of file)
///
public void Stop()
{
object error;
NativeMethods.rs2_playback_device_stop(Handle, out error);
}
///
/// Gets the current state of the playback device
///
/// Current state of the playback
public PlaybackStatus Status
{
get
{
object error;
return NativeMethods.rs2_playback_device_get_current_status(Handle, out error);
}
}
///
/// Gets the total duration of the file in units of nanoseconds
///
/// Total duration of the file in units of nanoseconds
///
public ulong Duration
{
get
{
object error;
return NativeMethods.rs2_playback_get_duration(Handle, out error);
}
}
///
/// Gets or sets the current position of the playback in the file in terms of time. Units are expressed in nanoseconds
///
///
/// Current position of the playback in the file in terms of time. Units are expressed in nanoseconds
///
public ulong Position
{
get
{
object error;
return NativeMethods.rs2_playback_get_position(Handle, out error);
}
set
{
object error;
NativeMethods.rs2_playback_seek(Handle, (long)value, out error);
}
}
///
/// Set the playback to a specified time point of the played data
///
/// The time point to which playback should seek, expressed in units of nanoseconds (zero value = start)
public void Seek(long time)
{
object error;
NativeMethods.rs2_playback_seek(Handle, time, out error);
}
///
/// Gets or sets a value indicating whether the playback works in real time or non real time
///
/// Indicates if playback is in real time mode or non real time
///
/// In real time mode, playback will play the same way the file was recorded.
/// In real time mode if the application takes too long to handle the callback, frames may be dropped.
/// In non real time mode, playback will wait for each callback to finish handling the data before
/// reading the next frame. In this mode no frames will be dropped, and the application controls the
/// frame rate of the playback (according to the callback handler duration).
///
public bool Realtime
{
get
{
object error;
return NativeMethods.rs2_playback_device_is_real_time(Handle, out error) != 0;
}
set
{
object error;
NativeMethods.rs2_playback_device_set_real_time(Handle, value ? 1 : 0, out error);
}
}
///
/// Set the playing speed
///
/// Indicates a multiplication of the speed to play (e.g: 1 = normal, 0.5 twice as slow)
public void SetSpeed(float speed)
{
object error;
NativeMethods.rs2_playback_device_set_playback_speed(Handle, speed, out error);
}
}
}