Initial downstream tracks
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
# IMPORTANT NOTE
|
||||
# This file is just used because some IDEs need to understand how to do autocompletion.
|
||||
# This file is completely ignored by the library ( See build.rs for the build system )
|
||||
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(livekit-webrtc)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_definitions(-DWEBRTC_WIN)
|
||||
|
||||
include_directories(libwebrtc/include)
|
||||
include_directories(libwebrtc/include/third_party/abseil-cpp/)
|
||||
include_directories(libwebrtc/include/third_party/libc++/)
|
||||
include_directories(include/)
|
||||
include_directories(../../../target/cxxbridge) # Can be different
|
||||
|
||||
file(GLOB_RECURSE SRC src/*.cpp)
|
||||
add_library(livekit-webrtc ${SRC})
|
||||
|
||||
#include_directories(/Users/theomonnom/Library/Android/sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include)
|
||||
#find_library(ANDROID_LIB_ANDROID android)
|
||||
#target_link_libraries(client_sdk_native PRIVATE android)
|
||||
@@ -52,7 +52,7 @@ fn macos_link_search_path() -> Option<String> {
|
||||
|
||||
fn main() {
|
||||
// TODO Download precompiled binaries of WebRTC for the target_os
|
||||
let target_os = "macos";
|
||||
let target_os = "windows";
|
||||
//let target_arch = "arm64";
|
||||
|
||||
let libwebrtc_dir = path::PathBuf::from("libwebrtc");
|
||||
@@ -79,6 +79,8 @@ fn main() {
|
||||
"src/rtp_transceiver.rs",
|
||||
"src/rtc_error.rs",
|
||||
"src/webrtc.rs",
|
||||
"src/video_frame.rs",
|
||||
"src/video_frame_buffer.rs",
|
||||
]);
|
||||
|
||||
builder.file("src/peer_connection.cpp");
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
-xc++
|
||||
-std=c++17
|
||||
-Iinclude
|
||||
-Ilibwebrtc/include
|
||||
-Ilibwebrtc/include/third_party/abseil-cpp
|
||||
-Ilibwebrtc/include/third_party/libc++
|
||||
-I../../../target/cxxbridge
|
||||
-DWEBRTC_WIN
|
||||
@@ -13,26 +13,7 @@
|
||||
|
||||
namespace livekit {
|
||||
|
||||
class MediaStreamTrack {
|
||||
public:
|
||||
explicit MediaStreamTrack(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track);
|
||||
|
||||
rust::String kind() const;
|
||||
rust::String id() const;
|
||||
|
||||
bool enabled() const;
|
||||
bool set_enabled(bool enable);
|
||||
|
||||
TrackState state() const;
|
||||
|
||||
private:
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
|
||||
};
|
||||
|
||||
static std::unique_ptr<MediaStreamTrack> _unique_media_stream_track() {
|
||||
return nullptr; // Ignore
|
||||
}
|
||||
class NativeVideoFrameSink;
|
||||
|
||||
class MediaStream {
|
||||
public:
|
||||
@@ -47,6 +28,96 @@ class MediaStream {
|
||||
static std::unique_ptr<MediaStream> _unique_media_stream() {
|
||||
return nullptr; // Ignore
|
||||
}
|
||||
|
||||
class MediaStreamTrack {
|
||||
protected:
|
||||
explicit MediaStreamTrack(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track);
|
||||
|
||||
public:
|
||||
static std::unique_ptr<MediaStreamTrack> from(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track);
|
||||
|
||||
rust::String kind() const;
|
||||
rust::String id() const;
|
||||
|
||||
bool enabled() const;
|
||||
bool set_enabled(bool enable);
|
||||
|
||||
TrackState state() const;
|
||||
|
||||
protected:
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
|
||||
};
|
||||
|
||||
static std::unique_ptr<MediaStreamTrack> _unique_media_stream_track() {
|
||||
return nullptr; // Ignore
|
||||
}
|
||||
|
||||
class AudioTrack : public MediaStreamTrack {
|
||||
public:
|
||||
explicit AudioTrack(rtc::scoped_refptr<webrtc::AudioTrackInterface> track);
|
||||
};
|
||||
|
||||
static std::unique_ptr<AudioTrack> _unique_audio_track() {
|
||||
return nullptr; // Ignore
|
||||
}
|
||||
|
||||
class VideoTrack : public MediaStreamTrack {
|
||||
public:
|
||||
explicit VideoTrack(rtc::scoped_refptr<webrtc::VideoTrackInterface> track);
|
||||
|
||||
void add_sink(NativeVideoFrameSink& sink);
|
||||
void remove_sink(NativeVideoFrameSink& sink);
|
||||
|
||||
void set_should_receive(bool should_receive);
|
||||
bool should_receive() const;
|
||||
ContentHint content_hint() const;
|
||||
void set_content_hint(ContentHint hint);
|
||||
|
||||
private:
|
||||
webrtc::VideoTrackInterface* track() const {
|
||||
return static_cast<webrtc::VideoTrackInterface*>(track_.get());
|
||||
}
|
||||
};
|
||||
|
||||
static std::unique_ptr<VideoTrack> _unique_video_track() {
|
||||
return nullptr; // Ignore
|
||||
}
|
||||
|
||||
class NativeVideoFrameSink
|
||||
: public rtc::VideoSinkInterface<webrtc::VideoFrame> {
|
||||
public:
|
||||
explicit NativeVideoFrameSink(rust::Box<VideoFrameSinkWrapper> observer);
|
||||
|
||||
void OnFrame(const webrtc::VideoFrame& frame) override;
|
||||
void OnDiscardedFrame() override;
|
||||
void OnConstraintsChanged(
|
||||
const webrtc::VideoTrackSourceConstraints& constraints) override;
|
||||
|
||||
private:
|
||||
rust::Box<VideoFrameSinkWrapper> observer_;
|
||||
};
|
||||
|
||||
std::unique_ptr<NativeVideoFrameSink> create_native_video_frame_sink(
|
||||
rust::Box<VideoFrameSinkWrapper> observer);
|
||||
|
||||
const MediaStreamTrack* video_to_media(const VideoTrack* track) {
|
||||
return track;
|
||||
}
|
||||
|
||||
const MediaStreamTrack* audio_to_media(const AudioTrack* track) {
|
||||
return track;
|
||||
}
|
||||
|
||||
const VideoTrack* media_to_video(const MediaStreamTrack* track) {
|
||||
return static_cast<const VideoTrack*>(track);
|
||||
}
|
||||
|
||||
const AudioTrack* media_to_audio(const MediaStreamTrack* track) {
|
||||
return static_cast<const AudioTrack*>(track);
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
|
||||
#endif // CLIENT_SDK_NATIVE_MEDIA_STREAM_INTERFACE_H
|
||||
|
||||
@@ -15,6 +15,7 @@ struct SetLocalSdpObserverWrapper;
|
||||
struct SetRemoteSdpObserverWrapper;
|
||||
struct DataChannelObserverWrapper;
|
||||
struct AddIceCandidateObserverWrapper;
|
||||
struct VideoFrameSinkWrapper;
|
||||
|
||||
// Shared types
|
||||
enum class PeerConnectionState;
|
||||
@@ -24,6 +25,9 @@ enum class IceGatheringState;
|
||||
enum class SdpType;
|
||||
enum class DataState;
|
||||
enum class TrackState;
|
||||
enum class ContentHint;
|
||||
enum class VideoRotation;
|
||||
enum class VideoFrameBufferType;
|
||||
struct SdpParseError;
|
||||
struct RTCOfferAnswerOptions;
|
||||
struct RTCError;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Created by theom on 14/11/2022.
|
||||
//
|
||||
|
||||
#ifndef LIVEKIT_WEBRTC_VIDEO_FRAME_H
|
||||
#define LIVEKIT_WEBRTC_VIDEO_FRAME_H
|
||||
|
||||
#include "api/video/video_frame.h"
|
||||
#include "livekit/rust_types.h"
|
||||
#include "livekit/video_frame_buffer.h"
|
||||
|
||||
namespace livekit {
|
||||
|
||||
class VideoFrame {
|
||||
public:
|
||||
explicit VideoFrame(const webrtc::VideoFrame& frame)
|
||||
: frame_(std::move(frame)) {}
|
||||
|
||||
int width() const { return frame_.width(); }
|
||||
int height() const { return frame_.height(); }
|
||||
uint32_t size() const { return frame_.size(); }
|
||||
uint16_t id() const { return frame_.id(); }
|
||||
int64_t timestamp_us() const { return frame_.timestamp_us(); }
|
||||
int64_t ntp_time_ms() const { return frame_.ntp_time_ms(); }
|
||||
uint32_t transport_frame_id() const { return frame_.transport_frame_id(); }
|
||||
uint32_t timestamp() const { return frame_.timestamp(); }
|
||||
|
||||
VideoRotation rotation() const {
|
||||
return static_cast<VideoRotation>(frame_.rotation());
|
||||
}
|
||||
|
||||
// TODO(theomonnom) This shouldn't create a new shared_ptr at each call
|
||||
std::shared_ptr<VideoFrameBuffer> video_frame_buffer() const {
|
||||
return std::make_shared<VideoFrameBuffer>(frame_.video_frame_buffer());
|
||||
}
|
||||
|
||||
private:
|
||||
webrtc::VideoFrame frame_;
|
||||
};
|
||||
|
||||
static std::unique_ptr<VideoFrame> _unique_video_frame() {
|
||||
return nullptr; // Ignore
|
||||
}
|
||||
|
||||
|
||||
} // namespace livekit
|
||||
|
||||
#endif // LIVEKIT_WEBRTC_VIDEO_FRAME_H
|
||||
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Created by theom on 14/11/2022.
|
||||
//
|
||||
|
||||
#ifndef LIVEKIT_WEBRTC_VIDEO_FRAME_BUFFER_H
|
||||
#define LIVEKIT_WEBRTC_VIDEO_FRAME_BUFFER_H
|
||||
|
||||
#include "api/video/video_frame_buffer.h"
|
||||
#include "rust_types.h"
|
||||
|
||||
namespace livekit {
|
||||
|
||||
class PlanarYuvBuffer;
|
||||
class PlanarYuv8Buffer;
|
||||
class I420Buffer;
|
||||
|
||||
class VideoFrameBuffer {
|
||||
public:
|
||||
explicit VideoFrameBuffer(rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer)
|
||||
: buffer_(std::move(buffer)) {}
|
||||
|
||||
VideoFrameBufferType buffer_type() const {
|
||||
return static_cast<VideoFrameBufferType>(buffer_->type());
|
||||
}
|
||||
|
||||
int width() const { return buffer_->width(); }
|
||||
int height() const { return buffer_->height(); }
|
||||
|
||||
std::shared_ptr<I420Buffer> to_i420() {
|
||||
return std::make_shared<I420Buffer>(buffer_->ToI420());
|
||||
}
|
||||
|
||||
protected:
|
||||
rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer_;
|
||||
};
|
||||
|
||||
class PlanarYuvBuffer : public VideoFrameBuffer {
|
||||
public:
|
||||
explicit PlanarYuvBuffer(rtc::scoped_refptr<webrtc::PlanarYuvBuffer> buffer)
|
||||
: VideoFrameBuffer(buffer) {}
|
||||
|
||||
int chroma_width() const { return buffer()->ChromaWidth(); }
|
||||
int chroma_height() const { return buffer()->ChromaHeight(); }
|
||||
|
||||
int stride_y() const { return buffer()->StrideY(); }
|
||||
int stride_u() const { return buffer()->StrideU(); }
|
||||
int stride_v() const { return buffer()->StrideV(); }
|
||||
|
||||
private:
|
||||
webrtc::PlanarYuvBuffer* buffer() const {
|
||||
return static_cast<webrtc::PlanarYuvBuffer*>(buffer_.get());
|
||||
}
|
||||
};
|
||||
|
||||
class PlanarYuv8Buffer : public PlanarYuvBuffer {
|
||||
public:
|
||||
explicit PlanarYuv8Buffer(rtc::scoped_refptr<webrtc::PlanarYuv8Buffer> buffer)
|
||||
: PlanarYuvBuffer(buffer) {}
|
||||
|
||||
const uint8_t* data_y() const { return buffer()->DataY(); }
|
||||
const uint8_t* data_u() const { return buffer()->DataU(); }
|
||||
const uint8_t* data_v() const { return buffer()->DataV(); }
|
||||
|
||||
private:
|
||||
webrtc::PlanarYuv8Buffer* buffer() const {
|
||||
return static_cast<webrtc::PlanarYuv8Buffer*>(buffer_.get());
|
||||
}
|
||||
};
|
||||
|
||||
class I420Buffer : public PlanarYuv8Buffer {
|
||||
public:
|
||||
explicit I420Buffer(rtc::scoped_refptr<webrtc::I420BufferInterface> buffer)
|
||||
: PlanarYuv8Buffer(buffer) {}
|
||||
};
|
||||
|
||||
std::shared_ptr<VideoFrameBuffer> to_video_frame_buffer(
|
||||
std::shared_ptr<PlanarYuvBuffer> buffer) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::shared_ptr<PlanarYuvBuffer> to_yuv_buffer(
|
||||
std::shared_ptr<PlanarYuv8Buffer> buffer) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::shared_ptr<PlanarYuv8Buffer> to_yuv8_buffer(
|
||||
std::shared_ptr<I420Buffer> buffer) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
|
||||
#endif // LIVEKIT_WEBRTC_VIDEO_FRAME_BUFFER_H
|
||||
@@ -7,4 +7,4 @@
|
||||
namespace livekit {
|
||||
Candidate::Candidate(const cricket::Candidate& candidate)
|
||||
: candidate_(candidate) {}
|
||||
} // namespace livekit
|
||||
} // namespace livekit
|
||||
|
||||
@@ -87,4 +87,4 @@ std::unique_ptr<NativeDataChannelObserver> create_native_data_channel_observer(
|
||||
rust::Box<DataChannelObserverWrapper> observer) {
|
||||
return std::make_unique<NativeDataChannelObserver>(std::move(observer));
|
||||
}
|
||||
} // namespace livekit
|
||||
} // namespace livekit
|
||||
|
||||
@@ -158,4 +158,4 @@ create_native_set_remote_sdp_observer(
|
||||
std::move(observer))});
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
} // namespace livekit
|
||||
|
||||
@@ -7,4 +7,10 @@ pub mod peer_connection_factory;
|
||||
pub mod rtc_error;
|
||||
pub mod rtp_receiver;
|
||||
pub mod rtp_transceiver;
|
||||
pub mod video_frame;
|
||||
pub mod video_frame_buffer;
|
||||
pub mod webrtc;
|
||||
|
||||
pub const MEDIA_TYPE_VIDEO: &str = "video";
|
||||
pub const MEDIA_TYPE_AUDIO: &str = "audio";
|
||||
pub const MEDIA_TYPE_DATA: &str = "data";
|
||||
|
||||
@@ -4,12 +4,27 @@
|
||||
|
||||
#include "livekit/media_stream.h"
|
||||
|
||||
#include "libwebrtc-sys/src/media_stream.rs.h"
|
||||
|
||||
namespace livekit {
|
||||
|
||||
MediaStreamTrack::MediaStreamTrack(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track)
|
||||
: track_(std::move(track)) {}
|
||||
|
||||
std::unique_ptr<MediaStreamTrack> MediaStreamTrack::from(
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track) {
|
||||
if (track->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) {
|
||||
return std::make_unique<VideoTrack>(
|
||||
rtc::scoped_refptr<webrtc::VideoTrackInterface>(
|
||||
static_cast<webrtc::VideoTrackInterface*>(track.get())));
|
||||
} else {
|
||||
return std::make_unique<AudioTrack>(
|
||||
rtc::scoped_refptr<webrtc::AudioTrackInterface>(
|
||||
static_cast<webrtc::AudioTrackInterface*>(track.get())));
|
||||
}
|
||||
}
|
||||
|
||||
rust::String MediaStreamTrack::kind() const {
|
||||
return track_->kind();
|
||||
}
|
||||
@@ -35,7 +50,60 @@ MediaStream::MediaStream(
|
||||
: media_stream_(std::move(stream)) {}
|
||||
|
||||
rust::String MediaStream::id() const {
|
||||
return media_stream_->id();
|
||||
return media_stream_->id();
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
VideoTrack::VideoTrack(rtc::scoped_refptr<webrtc::VideoTrackInterface> track)
|
||||
: MediaStreamTrack(std::move(track)) {}
|
||||
|
||||
void VideoTrack::add_sink(NativeVideoFrameSink& sink) {
|
||||
track()->AddOrUpdateSink(&sink, rtc::VideoSinkWants());
|
||||
}
|
||||
|
||||
void VideoTrack::remove_sink(NativeVideoFrameSink& sink) {
|
||||
track()->RemoveSink(&sink);
|
||||
}
|
||||
|
||||
void VideoTrack::set_should_receive(bool should_receive) {
|
||||
track()->set_should_receive(should_receive);
|
||||
}
|
||||
|
||||
bool VideoTrack::should_receive() const {
|
||||
return track()->should_receive();
|
||||
}
|
||||
|
||||
ContentHint VideoTrack::content_hint() const {
|
||||
return static_cast<ContentHint>(track()->content_hint());
|
||||
}
|
||||
|
||||
void VideoTrack::set_content_hint(ContentHint hint) {
|
||||
track()->set_content_hint(
|
||||
static_cast<webrtc::VideoTrackInterface::ContentHint>(hint));
|
||||
}
|
||||
|
||||
NativeVideoFrameSink::NativeVideoFrameSink(
|
||||
rust::Box<VideoFrameSinkWrapper> observer)
|
||||
: observer_(std::move(observer)) {}
|
||||
|
||||
void NativeVideoFrameSink::OnFrame(const webrtc::VideoFrame& frame) {
|
||||
observer_->on_frame(std::make_unique<VideoFrame>(frame));
|
||||
}
|
||||
|
||||
void NativeVideoFrameSink::OnDiscardedFrame() {
|
||||
observer_->on_discarded_frame();
|
||||
}
|
||||
|
||||
void NativeVideoFrameSink::OnConstraintsChanged(
|
||||
const webrtc::VideoTrackSourceConstraints& constraints) {
|
||||
VideoTrackSourceConstraints cst;
|
||||
cst.min_fps = constraints.min_fps.value_or(-1);
|
||||
cst.max_fps = constraints.max_fps.value_or(-1);
|
||||
observer_->on_constraints_changed(cst);
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeVideoFrameSink> create_native_video_frame_sink(
|
||||
rust::Box<VideoFrameSinkWrapper> observer) {
|
||||
return std::make_unique<NativeVideoFrameSink>(std::move(observer));
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
use cxx::UniquePtr;
|
||||
|
||||
use crate::video_frame::ffi::VideoFrame;
|
||||
|
||||
#[cxx::bridge(namespace = "livekit")]
|
||||
pub mod ffi {
|
||||
|
||||
@@ -8,11 +12,33 @@ pub mod ffi {
|
||||
Ended,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(i32)]
|
||||
pub enum ContentHint {
|
||||
None,
|
||||
Fluid,
|
||||
Detailed,
|
||||
Text,
|
||||
}
|
||||
|
||||
// -1 = optional
|
||||
pub struct VideoTrackSourceConstraints {
|
||||
pub min_fps: f64,
|
||||
pub max_fps: f64,
|
||||
}
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("livekit/media_stream.h");
|
||||
include!("livekit/video_frame.h");
|
||||
|
||||
type NativeVideoFrameSink;
|
||||
type MediaStreamTrack;
|
||||
type MediaStream;
|
||||
type AudioTrack;
|
||||
type VideoTrack;
|
||||
type VideoFrame = crate::video_frame::ffi::VideoFrame;
|
||||
|
||||
fn id(self: &MediaStream) -> String;
|
||||
|
||||
fn kind(self: &MediaStreamTrack) -> String;
|
||||
fn id(self: &MediaStreamTrack) -> String;
|
||||
@@ -20,17 +46,84 @@ pub mod ffi {
|
||||
fn set_enabled(self: Pin<&mut MediaStreamTrack>, enable: bool) -> bool;
|
||||
fn state(self: &MediaStreamTrack) -> TrackState;
|
||||
|
||||
fn id(self: &MediaStream) -> String;
|
||||
unsafe fn add_sink(self: Pin<&mut VideoTrack>, sink: Pin<&mut NativeVideoFrameSink>);
|
||||
unsafe fn remove_sink(self: Pin<&mut VideoTrack>, sink: Pin<&mut NativeVideoFrameSink>);
|
||||
|
||||
fn set_should_receive(self: Pin<&mut VideoTrack>, should_receive: bool);
|
||||
fn should_receive(self: &VideoTrack) -> bool;
|
||||
fn content_hint(self: &VideoTrack) -> ContentHint;
|
||||
fn set_content_hint(self: Pin<&mut VideoTrack>, hint: ContentHint);
|
||||
|
||||
fn create_native_video_frame_sink(
|
||||
observer: Box<VideoFrameSinkWrapper>,
|
||||
) -> UniquePtr<NativeVideoFrameSink>;
|
||||
|
||||
unsafe fn video_to_media(track: *const VideoTrack) -> *const MediaStreamTrack;
|
||||
unsafe fn audio_to_media(track: *const AudioTrack) -> *const MediaStreamTrack;
|
||||
unsafe fn media_to_video(track: *const MediaStreamTrack) -> *const VideoTrack;
|
||||
unsafe fn media_to_audio(track: *const MediaStreamTrack) -> *const AudioTrack;
|
||||
|
||||
fn _unique_media_stream_track() -> UniquePtr<MediaStreamTrack>; // Ignore
|
||||
fn _unique_media_stream() -> UniquePtr<MediaStream>; // Ignore
|
||||
fn _unique_audio_track() -> UniquePtr<AudioTrack>; // Ignore
|
||||
fn _unique_video_track() -> UniquePtr<VideoTrack>; // Ignore
|
||||
}
|
||||
|
||||
extern "Rust" {
|
||||
type VideoFrameSinkWrapper;
|
||||
|
||||
fn on_frame(self: &VideoFrameSinkWrapper, frame: UniquePtr<VideoFrame>);
|
||||
fn on_discarded_frame(self: &VideoFrameSinkWrapper);
|
||||
fn on_constraints_changed(
|
||||
self: &VideoFrameSinkWrapper,
|
||||
constraints: VideoTrackSourceConstraints,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for ffi::MediaStreamTrack {}
|
||||
|
||||
unsafe impl Send for ffi::MediaStreamTrack {}
|
||||
|
||||
unsafe impl Sync for ffi::MediaStream {}
|
||||
unsafe impl Send for ffi::MediaStream {}
|
||||
unsafe impl Send for ffi::AudioTrack {}
|
||||
unsafe impl Sync for ffi::AudioTrack {}
|
||||
unsafe impl Send for ffi::VideoTrack {}
|
||||
unsafe impl Sync for ffi::VideoTrack {}
|
||||
unsafe impl Send for ffi::NativeVideoFrameSink {}
|
||||
unsafe impl Sync for ffi::NativeVideoFrameSink {}
|
||||
|
||||
unsafe impl Send for ffi::MediaStream {}
|
||||
pub trait VideoFrameSink: Send + Sync {
|
||||
fn on_frame(&self, frame: UniquePtr<VideoFrame>);
|
||||
fn on_discarded_frame(&self);
|
||||
fn on_constraints_changed(&self, constraints: ffi::VideoTrackSourceConstraints);
|
||||
}
|
||||
|
||||
pub struct VideoFrameSinkWrapper {
|
||||
observer: *mut dyn VideoFrameSink,
|
||||
}
|
||||
|
||||
impl VideoFrameSinkWrapper {
|
||||
/// # Safety
|
||||
/// VideoFrameSink must lives as long as VideoSinkInterfaceWrapper does
|
||||
pub unsafe fn new(observer: *mut dyn VideoFrameSink) -> Self {
|
||||
Self { observer }
|
||||
}
|
||||
|
||||
fn on_frame(&self, frame: UniquePtr<VideoFrame>) {
|
||||
unsafe {
|
||||
(*self.observer).on_frame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_discarded_frame(&self) {
|
||||
unsafe {
|
||||
(*self.observer).on_discarded_frame();
|
||||
}
|
||||
}
|
||||
|
||||
fn on_constraints_changed(&self, constraints: ffi::VideoTrackSourceConstraints) {
|
||||
unsafe {
|
||||
(*self.observer).on_constraints_changed(constraints);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ pub struct PeerConnectionObserverWrapper {
|
||||
}
|
||||
|
||||
impl PeerConnectionObserverWrapper {
|
||||
/// SAFETY
|
||||
/// # Safety
|
||||
/// PeerConnectionObserver must lives as long as PeerConnectionObserverWrapper does
|
||||
pub unsafe fn new(observer: *mut dyn PeerConnectionObserver) -> Self {
|
||||
Self { observer }
|
||||
|
||||
@@ -45,7 +45,7 @@ pub mod ffi {
|
||||
) -> UniquePtr<PeerConnectionFactory>;
|
||||
fn create_rtc_configuration(conf: RTCConfiguration) -> UniquePtr<NativeRTCConfiguration>;
|
||||
|
||||
/// SAFETY
|
||||
/// # Safety
|
||||
/// The observer must live as long as the PeerConnection
|
||||
unsafe fn create_peer_connection(
|
||||
self: &PeerConnectionFactory,
|
||||
|
||||
@@ -10,7 +10,7 @@ RtpReceiver::RtpReceiver(
|
||||
: receiver_(std::move(receiver)) {}
|
||||
|
||||
std::unique_ptr<MediaStreamTrack> RtpReceiver::track() const {
|
||||
return std::make_unique<MediaStreamTrack>(receiver_->track());
|
||||
return MediaStreamTrack::from(receiver_->track());
|
||||
}
|
||||
|
||||
} // namespace livekit
|
||||
@@ -15,4 +15,4 @@ pub mod ffi {
|
||||
|
||||
unsafe impl Sync for ffi::RtpReceiver {}
|
||||
|
||||
unsafe impl Send for ffi::RtpReceiver {}
|
||||
unsafe impl Send for ffi::RtpReceiver {}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#[cxx::bridge(namespace = "livekit")]
|
||||
pub mod ffi {
|
||||
#[derive(Debug)]
|
||||
#[repr(i32)]
|
||||
pub enum VideoRotation {
|
||||
VideoRotation0 = 0,
|
||||
VideoRotation90 = 90,
|
||||
VideoRotation180 = 180,
|
||||
VideoRotation270 = 270,
|
||||
}
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("livekit/video_frame.h");
|
||||
include!("livekit/video_frame_buffer.h");
|
||||
|
||||
type VideoFrame;
|
||||
type VideoFrameBuffer = crate::video_frame_buffer::ffi::VideoFrameBuffer;
|
||||
|
||||
fn width(self: &VideoFrame) -> i32;
|
||||
fn height(self: &VideoFrame) -> i32;
|
||||
fn size(self: &VideoFrame) -> u32;
|
||||
fn id(self: &VideoFrame) -> u16;
|
||||
fn timestamp_us(self: &VideoFrame) -> i64;
|
||||
fn ntp_time_ms(self: &VideoFrame) -> i64;
|
||||
fn transport_frame_id(self: &VideoFrame) -> u32;
|
||||
fn timestamp(self: &VideoFrame) -> u32;
|
||||
fn rotation(self: &VideoFrame) -> VideoRotation;
|
||||
fn video_frame_buffer(self: &VideoFrame) -> SharedPtr<VideoFrameBuffer>;
|
||||
|
||||
fn _unique_video_frame() -> UniquePtr<VideoFrame>; // Ignore
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#[cxx::bridge(namespace = "livekit")]
|
||||
pub mod ffi {
|
||||
#[derive(Debug)]
|
||||
#[repr(i32)]
|
||||
pub enum VideoFrameBufferType {
|
||||
Native,
|
||||
I420,
|
||||
I420A,
|
||||
I422,
|
||||
I444,
|
||||
I010,
|
||||
NV12,
|
||||
}
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("livekit/video_frame_buffer.h");
|
||||
|
||||
type VideoFrameBuffer;
|
||||
type PlanarYuvBuffer;
|
||||
type PlanarYuv8Buffer;
|
||||
type I420Buffer;
|
||||
|
||||
fn buffer_type(self: &VideoFrameBuffer) -> VideoFrameBufferType;
|
||||
fn width(self: &VideoFrameBuffer) -> i32;
|
||||
fn height(self: &VideoFrameBuffer) -> i32;
|
||||
fn to_i420(self: Pin<&mut VideoFrameBuffer>) -> SharedPtr<I420Buffer>;
|
||||
|
||||
fn chroma_width(self: &PlanarYuvBuffer) -> i32;
|
||||
fn chroma_height(self: &PlanarYuvBuffer) -> i32;
|
||||
fn stride_y(self: &PlanarYuvBuffer) -> i32;
|
||||
fn stride_u(self: &PlanarYuvBuffer) -> i32;
|
||||
fn stride_v(self: &PlanarYuvBuffer) -> i32;
|
||||
|
||||
fn data_y(self: &PlanarYuv8Buffer) -> *const u8;
|
||||
fn data_u(self: &PlanarYuv8Buffer) -> *const u8;
|
||||
fn data_v(self: &PlanarYuv8Buffer) -> *const u8;
|
||||
|
||||
fn to_video_frame_buffer(buffer: SharedPtr<PlanarYuvBuffer>)
|
||||
-> SharedPtr<VideoFrameBuffer>;
|
||||
fn to_yuv_buffer(buffer: SharedPtr<PlanarYuv8Buffer>) -> SharedPtr<PlanarYuvBuffer>;
|
||||
fn to_yuv8_buffer(buffer: SharedPtr<I420Buffer>) -> SharedPtr<PlanarYuv8Buffer>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user