Skip to main content

webrtc_sys/
video_frame.rs

1// Copyright 2025 LiveKit, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::impl_thread_safety;
16
17#[cxx::bridge(namespace = "livekit_ffi")]
18pub mod ffi {
19    #[derive(Debug)]
20    #[repr(i32)]
21    pub enum VideoRotation {
22        VideoRotation0 = 0,
23        VideoRotation90 = 90,
24        VideoRotation180 = 180,
25        VideoRotation270 = 270,
26    }
27
28    extern "C++" {
29        include!("livekit/video_frame_buffer.h");
30
31        type VideoFrameBuffer = crate::video_frame_buffer::ffi::VideoFrameBuffer;
32    }
33
34    unsafe extern "C++" {
35        include!("livekit/video_frame.h");
36
37        type VideoFrame;
38
39        fn width(self: &VideoFrame) -> u32;
40        fn height(self: &VideoFrame) -> u32;
41        fn size(self: &VideoFrame) -> u32;
42        fn id(self: &VideoFrame) -> u16;
43        fn timestamp_us(self: &VideoFrame) -> i64;
44        fn ntp_time_ms(self: &VideoFrame) -> i64;
45        fn timestamp(self: &VideoFrame) -> u32;
46        fn rotation(self: &VideoFrame) -> VideoRotation;
47        unsafe fn video_frame_buffer(self: &VideoFrame) -> UniquePtr<VideoFrameBuffer>;
48
49        // VideoFrameBuilder
50        type VideoFrameBuilder;
51        fn new_video_frame_builder() -> UniquePtr<VideoFrameBuilder>;
52        fn set_timestamp_us(self: Pin<&mut VideoFrameBuilder>, timestamp_us: i64);
53        fn set_rotation(self: Pin<&mut VideoFrameBuilder>, rotation: VideoRotation);
54        fn set_id(self: Pin<&mut VideoFrameBuilder>, id: u16);
55        fn set_video_frame_buffer(self: Pin<&mut VideoFrameBuilder>, buffer: &VideoFrameBuffer);
56
57        fn build(self: Pin<&mut VideoFrameBuilder>) -> UniquePtr<VideoFrame>;
58
59    }
60}
61
62impl_thread_safety!(ffi::VideoFrame, Send + Sync);