1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Defines the profile type of pipeline.

use crate::{
    device::Device,
    error::{ErrorChecker, Result as RsResult},
    stream_profile_list::StreamProfileList,
};
use std::ptr::NonNull;

#[derive(Debug)]
pub struct PipelineProfile {
    ptr: NonNull<realsense_sys::rs2_pipeline_profile>,
}

impl PipelineProfile {
    /// Gets corresponding device of pipeline.
    pub fn device(&self) -> RsResult<Device> {
        let ptr = unsafe {
            let mut checker = ErrorChecker::new();
            let ptr = realsense_sys::rs2_pipeline_profile_get_device(
                self.ptr.as_ptr(),
                checker.inner_mut_ptr(),
            );
            checker.check()?;
            ptr
        };

        let device = unsafe { Device::from_ptr(NonNull::new(ptr).unwrap()) };
        Ok(device)
    }

    /// Gets iterable list of streams of pipeline.
    pub fn streams(&self) -> RsResult<StreamProfileList> {
        let ptr = unsafe {
            let mut checker = ErrorChecker::new();
            let ptr = realsense_sys::rs2_pipeline_profile_get_streams(
                self.ptr.as_ptr(),
                checker.inner_mut_ptr(),
            );
            checker.check()?;
            ptr
        };

        let list = unsafe { StreamProfileList::from_ptr(NonNull::new(ptr).unwrap()) };
        Ok(list)
    }

    pub(crate) unsafe fn from_ptr(ptr: NonNull<realsense_sys::rs2_pipeline_profile>) -> Self {
        Self { ptr }
    }
}

impl Drop for PipelineProfile {
    fn drop(&mut self) {
        unsafe {
            realsense_sys::rs2_delete_pipeline_profile(self.ptr.as_ptr());
        }
    }
}

unsafe impl Send for PipelineProfile {}