opt: no copy during transmitting the decoded frame

This commit is contained in:
Kingtous 2023-02-11 12:25:13 +08:00
parent f8c78a6bf2
commit f521b1665a
4 changed files with 9 additions and 9 deletions

View File

@ -1545,7 +1545,7 @@ pub type MediaSender = mpsc::Sender<MediaData>;
/// * `video_callback` - The callback for video frame. Being called when a video frame is ready.
pub fn start_video_audio_threads<F>(video_callback: F) -> (MediaSender, MediaSender)
where
F: 'static + FnMut(&[u8]) + Send,
F: 'static + FnMut(Vec<u8>) + Send,
{
let (video_sender, video_receiver) = mpsc::channel::<MediaData>();
let mut video_callback = video_callback;
@ -1560,7 +1560,7 @@ where
match data {
MediaData::VideoFrame(vf) => {
if let Ok(true) = video_handler.handle_frame(vf) {
video_callback(&video_handler.rgb);
video_callback(std::mem::replace(&mut video_handler.rgb, vec![]));
}
}
MediaData::Reset => {

View File

@ -3,7 +3,7 @@ use crate::{
flutter_ffi::EventToUI,
ui_session_interface::{io_loop, InvokeUiSession, Session},
};
use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer};
use flutter_rust_bridge::{StreamSink};
use hbb_common::{
bail, config::LocalConfig, get_version_number, message_proto::*, rendezvous_proto::ConnType,
ResultType,
@ -289,9 +289,9 @@ impl InvokeUiSession for FlutterHandler {
// unused in flutter
fn adapt_size(&self) {}
fn on_rgba(&self, data: &[u8]) {
fn on_rgba(&self, data: Vec<u8>) {
if let Some(stream) = &*self.event_stream.read().unwrap() {
let former_rgba = self.rgba.write().unwrap().replace(data.to_owned());
let former_rgba = self.rgba.write().unwrap().replace(data);
if former_rgba.is_none() {
// The [former_rgba] is none, which means the latest rgba had taken from flutter.
// We need to send a signal to flutter for notifying there's a new rgba buffer here.

View File

@ -201,12 +201,12 @@ impl InvokeUiSession for SciterHandler {
self.call("adaptSize", &make_args!());
}
fn on_rgba(&self, data: &[u8]) {
fn on_rgba(&self, data: Vec<u8>) {
VIDEO
.lock()
.unwrap()
.as_mut()
.map(|v| v.render_frame(data).ok());
.map(|v| v.render_frame(&data).ok());
}
fn set_peer_info(&self, pi: &PeerInfo) {

View File

@ -712,7 +712,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default {
fn update_block_input_state(&self, on: bool);
fn job_progress(&self, id: i32, file_num: i32, speed: f64, finished_size: f64);
fn adapt_size(&self);
fn on_rgba(&self, data: &[u8]);
fn on_rgba(&self, data: Vec<u8>);
fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str, retry: bool);
#[cfg(any(target_os = "android", target_os = "ios"))]
fn clipboard(&self, content: String);
@ -957,7 +957,7 @@ pub async fn io_loop<T: InvokeUiSession>(handler: Session<T>) {
let frame_count = Arc::new(AtomicUsize::new(0));
let frame_count_cl = frame_count.clone();
let ui_handler = handler.ui_handler.clone();
let (video_sender, audio_sender) = start_video_audio_threads(move |data: &[u8]| {
let (video_sender, audio_sender) = start_video_audio_threads(move |data: Vec<u8>| {
frame_count_cl.fetch_add(1, Ordering::Relaxed);
ui_handler.on_rgba(data);
});