Skip to content

Commit

Permalink
Fix render events on desktop platforms (#128)
Browse files Browse the repository at this point in the history
Co-authored-by: alexlapa <[email protected]>
  • Loading branch information
rogurotus and alexlapa authored Oct 12, 2023
1 parent 395c876 commit b1d6edc
Show file tree
Hide file tree
Showing 17 changed files with 850 additions and 339 deletions.
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions crates/native/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use crate::{

// Re-exporting since it is used in the generated code.
pub use crate::{
PeerConnection, RtpEncodingParameters, RtpTransceiver, RtpTransceiverInit,
renderer::TextureEvent, PeerConnection, RtpEncodingParameters,
RtpTransceiver, RtpTransceiverInit,
};

lazy_static::lazy_static! {
Expand Down Expand Up @@ -1939,9 +1940,9 @@ pub fn set_transceiver_init_direction(
#[allow(clippy::needless_pass_by_value)]
pub fn add_transceiver_init_send_encoding(
init: RustOpaque<Arc<RtpTransceiverInit>>,
encoding: RustOpaque<Arc<RtpEncodingParameters>>,
enc: RustOpaque<Arc<RtpEncodingParameters>>,
) {
init.add_encoding(&encoding);
init.add_encoding(&enc);
}

/// Creates new [`RtpEncodingParameters`] with the provided settings.
Expand Down Expand Up @@ -2238,11 +2239,13 @@ pub fn set_on_device_changed(cb: StreamSink<()>) -> anyhow::Result<()> {
/// `callback_ptr` argument should be a pointer to an [`UniquePtr`] pointing to
/// an [`OnFrameCallbackInterface`].
pub fn create_video_sink(
cb: StreamSink<TextureEvent>,
sink_id: i64,
track_id: String,
callback_ptr: u64,
texture_id: i64,
) -> anyhow::Result<()> {
let handler = FrameHandler::new(callback_ptr as _);
let handler = FrameHandler::new(callback_ptr as _, cb.into(), texture_id);

WEBRTC
.lock()
Expand Down
72 changes: 58 additions & 14 deletions crates/native/src/bridge_generated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(
non_camel_case_types,
unused,
Expand All @@ -14,13 +13,13 @@

use crate::api::*;
use core::panic::UnwindSafe;
use flutter_rust_bridge::rust2dart::IntoIntoDart;
use flutter_rust_bridge::*;
use std::ffi::c_void;
use std::sync::Arc;
use flutter_rust_bridge::{rust2dart::IntoIntoDart, *};
use std::{ffi::c_void, sync::Arc};

// Section: imports

use crate::renderer::TextureEvent;

// Section: wire functions

fn wire_enable_fake_media_impl(port_: MessagePort) {
Expand Down Expand Up @@ -178,7 +177,7 @@ fn wire_set_transceiver_init_direction_impl(
fn wire_add_transceiver_init_send_encoding_impl(
port_: MessagePort,
init: impl Wire2Api<RustOpaque<Arc<RtpTransceiverInit>>> + UnwindSafe,
encoding: impl Wire2Api<RustOpaque<Arc<RtpEncodingParameters>>> + UnwindSafe,
enc: impl Wire2Api<RustOpaque<Arc<RtpEncodingParameters>>> + UnwindSafe,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
WrapInfo {
Expand All @@ -188,9 +187,9 @@ fn wire_add_transceiver_init_send_encoding_impl(
},
move || {
let api_init = init.wire2api();
let api_encoding = encoding.wire2api();
let api_enc = enc.wire2api();
move |task_callback| {
Ok(add_transceiver_init_send_encoding(api_init, api_encoding))
Ok(add_transceiver_init_send_encoding(api_init, api_enc))
}
},
)
Expand Down Expand Up @@ -704,19 +703,27 @@ fn wire_create_video_sink_impl(
sink_id: impl Wire2Api<i64> + UnwindSafe,
track_id: impl Wire2Api<String> + UnwindSafe,
callback_ptr: impl Wire2Api<u64> + UnwindSafe,
texture_id: impl Wire2Api<i64> + UnwindSafe,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
WrapInfo {
debug_name: "create_video_sink",
port: Some(port_),
mode: FfiCallMode::Normal,
mode: FfiCallMode::Stream,
},
move || {
let api_sink_id = sink_id.wire2api();
let api_track_id = track_id.wire2api();
let api_callback_ptr = callback_ptr.wire2api();
let api_texture_id = texture_id.wire2api();
move |task_callback| {
create_video_sink(api_sink_id, api_track_id, api_callback_ptr)
create_video_sink(
task_callback.stream_sink::<_, TextureEvent>(),
api_sink_id,
api_track_id,
api_callback_ptr,
api_texture_id,
)
}
},
)
Expand Down Expand Up @@ -1590,6 +1597,35 @@ impl rust2dart::IntoIntoDart<SignalingState> for SignalingState {
}
}

impl support::IntoDart for TextureEvent {
fn into_dart(self) -> support::DartAbi {
match self {
Self::OnTextureChange {
texture_id,
width,
height,
rotation,
} => vec![
0.into_dart(),
texture_id.into_into_dart().into_dart(),
width.into_into_dart().into_dart(),
height.into_into_dart().into_dart(),
rotation.into_into_dart().into_dart(),
],
Self::OnFirstFrameRendered { texture_id } => {
vec![1.into_dart(), texture_id.into_into_dart().into_dart()]
}
}
.into_dart()
}
}
impl support::IntoDartExceptPrimitive for TextureEvent {}
impl rust2dart::IntoIntoDart<TextureEvent> for TextureEvent {
fn into_into_dart(self) -> Self {
self
}
}

impl support::IntoDart for TrackEvent {
fn into_dart(self) -> support::DartAbi {
match self {
Expand Down Expand Up @@ -1624,7 +1660,8 @@ impl rust2dart::IntoIntoDart<TrackState> for TrackState {
// Section: executor

support::lazy_static! {
pub static ref FLUTTER_RUST_BRIDGE_HANDLER: support::DefaultHandler = Default::default();
pub static ref FLUTTER_RUST_BRIDGE_HANDLER: support::DefaultHandler =
Default::default();
}

#[cfg(not(target_family = "wasm"))]
Expand Down Expand Up @@ -1712,9 +1749,9 @@ mod io {
pub extern "C" fn wire_add_transceiver_init_send_encoding(
port_: i64,
init: wire_ArcRtpTransceiverInit,
encoding: wire_ArcRtpEncodingParameters,
enc: wire_ArcRtpEncodingParameters,
) {
wire_add_transceiver_init_send_encoding_impl(port_, init, encoding)
wire_add_transceiver_init_send_encoding_impl(port_, init, enc)
}

#[no_mangle]
Expand Down Expand Up @@ -1966,8 +2003,15 @@ mod io {
sink_id: i64,
track_id: *mut wire_uint_8_list,
callback_ptr: u64,
texture_id: i64,
) {
wire_create_video_sink_impl(port_, sink_id, track_id, callback_ptr)
wire_create_video_sink_impl(
port_,
sink_id,
track_id,
callback_ptr,
texture_id,
)
}

#[no_mangle]
Expand Down
Loading

0 comments on commit b1d6edc

Please sign in to comment.