Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rustdesk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李朝发
rustdesk
Commits
d19a8fdc
Commit
d19a8fdc
authored
Jul 21, 2022
by
fufesou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix_capturer_trait_name_shadowing: build win
Signed-off-by:
fufesou
<
shuanglongchen@yeah.net
>
parent
416832a1
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
119 additions
and
114 deletions
+119
-114
capture_mag.rs
libs/scrap/examples/capture_mag.rs
+1
-1
ffplay.rs
libs/scrap/examples/ffplay.rs
+1
-1
record-screen.rs
libs/scrap/examples/record-screen.rs
+1
-1
screenshot.rs
libs/scrap/examples/screenshot.rs
+1
-1
android.rs
libs/scrap/src/common/android.rs
+5
-1
dxgi.rs
libs/scrap/src/common/dxgi.rs
+40
-22
linux.rs
libs/scrap/src/common/linux.rs
+11
-8
mod.rs
libs/scrap/src/common/mod.rs
+10
-0
quartz.rs
libs/scrap/src/common/quartz.rs
+7
-1
wayland.rs
libs/scrap/src/common/wayland.rs
+8
-6
x11.rs
libs/scrap/src/common/x11.rs
+8
-6
video_service.rs
src/server/video_service.rs
+2
-52
wayland.rs
src/server/wayland.rs
+24
-14
No files found.
libs/scrap/examples/capture_mag.rs
View file @
d19a8fdc
...
...
@@ -4,7 +4,7 @@ extern crate scrap;
use
std
::
fs
::
File
;
#[cfg(windows)]
use
scrap
::
CapturerMag
;
use
scrap
::
{
CapturerMag
,
TraitCapturer
}
;
use
scrap
::{
i420_to_rgb
,
Display
};
fn
main
()
{
...
...
libs/scrap/examples/ffplay.rs
View file @
d19a8fdc
...
...
@@ -3,7 +3,7 @@ use std::time::Duration;
extern
crate
scrap
;
fn
main
()
{
use
scrap
::{
Capturer
,
Display
};
use
scrap
::{
Capturer
,
Display
,
TraitCapturer
};
use
std
::
io
::
ErrorKind
::
WouldBlock
;
use
std
::
io
::
Write
;
use
std
::
process
::{
Command
,
Stdio
};
...
...
libs/scrap/examples/record-screen.rs
View file @
d19a8fdc
...
...
@@ -18,7 +18,7 @@ use webm::mux;
use
webm
::
mux
::
Track
;
use
scrap
::
vpxcodec
as
vpx_encode
;
use
scrap
::{
Capturer
,
Display
,
STRIDE_ALIGN
};
use
scrap
::{
TraitCapturer
,
Capturer
,
Display
,
STRIDE_ALIGN
};
const
USAGE
:
&
'static
str
=
"
Simple WebM screen capture.
...
...
libs/scrap/examples/screenshot.rs
View file @
d19a8fdc
...
...
@@ -6,7 +6,7 @@ use std::io::ErrorKind::WouldBlock;
use
std
::
thread
;
use
std
::
time
::
Duration
;
use
scrap
::{
i420_to_rgb
,
Capturer
,
Display
};
use
scrap
::{
i420_to_rgb
,
Capturer
,
Display
,
TraitCapturer
};
fn
main
()
{
let
n
=
Display
::
all
()
.unwrap
()
.len
();
...
...
libs/scrap/src/common/android.rs
View file @
d19a8fdc
...
...
@@ -32,8 +32,12 @@ impl Capturer {
pub
fn
height
(
&
self
)
->
usize
{
self
.display
.height
()
as
usize
}
}
impl
TraitCapturer
for
Capturer
{
fn
set_use_yuv
(
&
mut
self
,
_use_yuv
:
bool
)
{}
pub
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
if
let
Some
(
buf
)
=
get_video_raw
()
{
crate
::
would_block_if_equal
(
&
mut
self
.saved_raw_data
,
buf
)
?
;
rgba_to_i420
(
self
.width
(),
self
.height
(),
buf
,
&
mut
self
.bgra
);
...
...
libs/scrap/src/common/dxgi.rs
View file @
d19a8fdc
use
crate
::
dxgi
;
use
std
::
io
::
ErrorKind
::{
NotFound
,
TimedOut
,
WouldBlock
};
use
std
::
time
::
Duration
;
use
std
::{
io
,
ops
};
use
crate
::{
common
::
TraitCapturer
,
dxgi
};
use
std
::{
io
::{
self
,
ErrorKind
::{
NotFound
,
TimedOut
,
WouldBlock
},
},
ops
,
time
::
Duration
,
};
pub
struct
Capturer
{
inner
:
dxgi
::
Capturer
,
...
...
@@ -21,18 +26,6 @@ impl Capturer {
})
}
pub
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.inner
.set_use_yuv
(
use_yuv
);
}
pub
fn
is_gdi
(
&
self
)
->
bool
{
self
.inner
.is_gdi
()
}
pub
fn
set_gdi
(
&
mut
self
)
->
bool
{
self
.inner
.set_gdi
()
}
pub
fn
cancel_gdi
(
&
mut
self
)
{
self
.inner
.cancel_gdi
()
}
...
...
@@ -44,14 +37,28 @@ impl Capturer {
pub
fn
height
(
&
self
)
->
usize
{
self
.height
}
}
impl
TraitCapturer
for
Capturer
{
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.inner
.set_use_yuv
(
use_yuv
);
}
pub
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
match
self
.inner
.frame
(
timeout
.as_millis
()
as
_
)
{
Ok
(
frame
)
=>
Ok
(
Frame
(
frame
)),
Err
(
ref
error
)
if
error
.kind
()
==
TimedOut
=>
Err
(
WouldBlock
.into
()),
Err
(
error
)
=>
Err
(
error
),
}
}
fn
is_gdi
(
&
self
)
->
bool
{
self
.inner
.is_gdi
()
}
fn
set_gdi
(
&
mut
self
)
->
bool
{
self
.inner
.set_gdi
()
}
}
pub
struct
Frame
<
'a
>
(
&
'a
[
u8
]);
...
...
@@ -134,10 +141,6 @@ impl CapturerMag {
})
}
pub
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.inner
.set_use_yuv
(
use_yuv
)
}
pub
fn
exclude
(
&
mut
self
,
cls
:
&
str
,
name
:
&
str
)
->
io
::
Result
<
bool
>
{
self
.inner
.exclude
(
cls
,
name
)
}
...
...
@@ -145,8 +148,23 @@ impl CapturerMag {
pub
fn
get_rect
(
&
self
)
->
((
i32
,
i32
),
usize
,
usize
)
{
self
.inner
.get_rect
()
}
pub
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout_ms
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
}
impl
TraitCapturer
for
CapturerMag
{
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.inner
.set_use_yuv
(
use_yuv
)
}
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout_ms
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
self
.inner
.frame
(
&
mut
self
.data
)
?
;
Ok
(
Frame
(
&
self
.data
))
}
fn
is_gdi
(
&
self
)
->
bool
{
false
}
fn
set_gdi
(
&
mut
self
)
->
bool
{
false
}
}
libs/scrap/src/common/linux.rs
View file @
d19a8fdc
use
crate
::
common
::{
wayland
,
x11
::{
self
,
Frame
},
TraitCapturer
,
};
use
std
::{
io
,
time
::
Duration
};
...
...
@@ -17,13 +18,6 @@ impl Capturer {
})
}
pub
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
match
self
{
Capturer
::
X11
(
d
)
=>
d
.set_use_yuv
(
use_yuv
),
Capturer
::
WAYLAND
(
d
)
=>
d
.set_use_yuv
(
use_yuv
),
}
}
pub
fn
width
(
&
self
)
->
usize
{
match
self
{
Capturer
::
X11
(
d
)
=>
d
.width
(),
...
...
@@ -37,8 +31,17 @@ impl Capturer {
Capturer
::
WAYLAND
(
d
)
=>
d
.height
(),
}
}
}
impl
TraitCapturer
for
Capturer
{
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
match
self
{
Capturer
::
X11
(
d
)
=>
d
.set_use_yuv
(
use_yuv
),
Capturer
::
WAYLAND
(
d
)
=>
d
.set_use_yuv
(
use_yuv
),
}
}
pub
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
match
self
{
Capturer
::
X11
(
d
)
=>
d
.frame
(
timeout
),
Capturer
::
WAYLAND
(
d
)
=>
d
.frame
(
timeout
),
...
...
libs/scrap/src/common/mod.rs
View file @
d19a8fdc
...
...
@@ -49,3 +49,13 @@ pub fn would_block_if_equal(old: &mut Vec<u128>, b: &[u8]) -> std::io::Result<()
old
.copy_from_slice
(
b
);
Ok
(())
}
pub
trait
TraitCapturer
{
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
);
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
std
::
time
::
Duration
)
->
std
::
io
::
Result
<
Frame
<
'a
>>
;
#[cfg(windows)]
fn
is_gdi
(
&
self
)
->
bool
;
#[cfg(windows)]
fn
set_gdi
(
&
mut
self
)
->
bool
;
}
libs/scrap/src/common/quartz.rs
View file @
d19a8fdc
...
...
@@ -50,8 +50,14 @@ impl Capturer {
pub
fn
height
(
&
self
)
->
usize
{
self
.inner
.height
()
}
}
impl
TraitCapturer
for
Capturer
{
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.use_yuv
=
use_yuv
;
}
pub
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout_ms
:
std
::
time
::
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout_ms
:
std
::
time
::
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
match
self
.frame
.try_lock
()
{
Ok
(
mut
handle
)
=>
{
let
mut
frame
=
None
;
...
...
libs/scrap/src/common/wayland.rs
View file @
d19a8fdc
use
crate
::
common
::
x11
::
Frame
;
use
crate
::
common
::
{
x11
::
Frame
,
TraitCapturer
}
;
use
crate
::
wayland
::{
capturable
::
*
,
*
};
use
std
::{
io
,
time
::
Duration
};
...
...
@@ -14,10 +14,6 @@ impl Capturer {
Ok
(
Capturer
(
display
,
r
,
yuv
,
Default
::
default
()))
}
pub
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.
2
=
use_yuv
;
}
pub
fn
width
(
&
self
)
->
usize
{
self
.
0
.width
()
}
...
...
@@ -25,8 +21,14 @@ impl Capturer {
pub
fn
height
(
&
self
)
->
usize
{
self
.
0
.height
()
}
}
impl
TraitCapturer
for
Capturer
{
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.
2
=
use_yuv
;
}
pub
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
match
self
.
1
.capture
(
timeout
.as_millis
()
as
_
)
.map_err
(
map_err
)
?
{
PixelProvider
::
BGR0
(
w
,
h
,
x
)
=>
Ok
(
Frame
(
if
self
.
2
{
crate
::
common
::
bgra_to_i420
(
w
as
_
,
h
as
_
,
&
x
,
&
mut
self
.
3
);
...
...
libs/scrap/src/common/x11.rs
View file @
d19a8fdc
use
crate
::
x11
;
use
crate
::
{
x11
,
common
::
TraitCapturer
}
;
use
std
::{
io
,
ops
,
time
::
Duration
};
pub
struct
Capturer
(
x11
::
Capturer
);
...
...
@@ -8,10 +8,6 @@ impl Capturer {
x11
::
Capturer
::
new
(
display
.
0
,
yuv
)
.map
(
Capturer
)
}
pub
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.
0
.set_use_yuv
(
use_yuv
);
}
pub
fn
width
(
&
self
)
->
usize
{
self
.
0
.display
()
.rect
()
.w
as
usize
}
...
...
@@ -19,8 +15,14 @@ impl Capturer {
pub
fn
height
(
&
self
)
->
usize
{
self
.
0
.display
()
.rect
()
.h
as
usize
}
}
impl
TraitCapturer
for
Capturer
{
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.
0
.set_use_yuv
(
use_yuv
);
}
pub
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout
:
Duration
)
->
io
::
Result
<
Frame
<
'a
>>
{
Ok
(
Frame
(
self
.
0
.frame
()
?
))
}
}
...
...
src/server/video_service.rs
View file @
d19a8fdc
...
...
@@ -26,11 +26,11 @@ use hbb_common::tokio::sync::{
use
scrap
::{
codec
::{
Encoder
,
EncoderCfg
,
HwEncoderConfig
},
vpxcodec
::{
VpxEncoderConfig
,
VpxVideoCodecId
},
Capturer
,
Display
,
Frame
,
Capturer
,
Display
,
TraitCapturer
,
};
use
std
::{
collections
::
HashSet
,
io
::
{
ErrorKind
::
WouldBlock
,
Result
}
,
io
::
ErrorKind
::
WouldBlock
,
ops
::{
Deref
,
DerefMut
},
time
::{
self
,
Duration
,
Instant
},
};
...
...
@@ -128,56 +128,6 @@ impl VideoFrameController {
}
}
pub
(
super
)
trait
TraitCapturer
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
Result
<
Frame
<
'a
>>
;
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
);
#[cfg(windows)]
fn
is_gdi
(
&
self
)
->
bool
;
#[cfg(windows)]
fn
set_gdi
(
&
mut
self
)
->
bool
;
}
impl
TraitCapturer
for
Capturer
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
Result
<
Frame
<
'a
>>
{
self
.frame
(
timeout
)
}
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.set_use_yuv
(
use_yuv
);
}
#[cfg(windows)]
fn
is_gdi
(
&
self
)
->
bool
{
self
.is_gdi
()
}
#[cfg(windows)]
fn
set_gdi
(
&
mut
self
)
->
bool
{
self
.set_gdi
()
}
}
#[cfg(windows)]
impl
TraitCapturer
for
scrap
::
CapturerMag
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
_timeout_ms
:
Duration
)
->
Result
<
Frame
<
'a
>>
{
self
.frame
(
_timeout_ms
)
}
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
self
.set_use_yuv
(
use_yuv
);
}
fn
is_gdi
(
&
self
)
->
bool
{
false
}
fn
set_gdi
(
&
mut
self
)
->
bool
{
false
}
}
pub
fn
new
()
->
GenericService
{
let
sp
=
GenericService
::
new
(
NAME
,
true
);
sp
.run
(
run
);
...
...
src/server/wayland.rs
View file @
d19a8fdc
use
super
::
*
;
use
hbb_common
::
allow_err
;
use
scrap
::{
Capturer
,
Display
,
Frame
};
use
std
::
{
io
::
Result
,
time
::
Duration
}
;
use
scrap
::{
Capturer
,
Display
,
Frame
,
TraitCapturer
};
use
std
::
io
::
Result
;
lazy_static
::
lazy_static!
{
static
ref
CAP_DISPLAY_INFO
:
RwLock
<
u64
>
=
RwLock
::
new
(
0
);
}
struct
CapDisplayInfo
{
rects
:
Vec
<
((
i32
,
i32
),
usize
,
usize
)
>
,
displays
:
Vec
<
DisplayInfo
>
,
num
:
usize
,
primary
:
usize
,
current
:
usize
,
capturer
:
*
mut
Capturer
,
struct
CapturerPtr
(
*
mut
Capturer
);
impl
Clone
for
CapturerPtr
{
fn
clone
(
&
self
)
->
Self
{
Self
(
self
.
0
)
}
}
impl
super
::
video_service
::
TraitCapturer
for
*
mut
Capture
r
{
impl
TraitCapturer
for
CapturerPt
r
{
fn
frame
<
'a
>
(
&
'a
mut
self
,
timeout
:
Duration
)
->
Result
<
Frame
<
'a
>>
{
unsafe
{
(
*
*
self
)
.frame
(
timeout
)
}
unsafe
{
(
*
self
.
0
)
.frame
(
timeout
)
}
}
fn
set_use_yuv
(
&
mut
self
,
use_yuv
:
bool
)
{
unsafe
{
(
*
*
self
)
.set_use_yuv
(
use_yuv
);
(
*
self
.
0
)
.set_use_yuv
(
use_yuv
);
}
}
}
struct
CapDisplayInfo
{
rects
:
Vec
<
((
i32
,
i32
),
usize
,
usize
)
>
,
displays
:
Vec
<
DisplayInfo
>
,
num
:
usize
,
primary
:
usize
,
current
:
usize
,
capturer
:
CapturerPtr
,
}
async
fn
check_init
()
->
ResultType
<
()
>
{
if
!
scrap
::
is_x11
()
{
let
mut
minx
=
0
;
...
...
@@ -68,6 +77,7 @@ async fn check_init() -> ResultType<()> {
let
capturer
=
Box
::
into_raw
(
Box
::
new
(
Capturer
::
new
(
display
,
true
)
.with_context
(||
"Failed to create capturer"
)
?
,
));
let
capturer
=
CapturerPtr
(
capturer
);
let
cap_display_info
=
Box
::
into_raw
(
Box
::
new
(
CapDisplayInfo
{
rects
,
displays
,
...
...
@@ -104,7 +114,7 @@ pub fn clear() {
if
*
lock
!=
0
{
unsafe
{
let
cap_display_info
=
Box
::
from_raw
(
*
lock
as
*
mut
CapDisplayInfo
);
let
_
=
Box
::
from_raw
(
cap_display_info
.capturer
);
let
_
=
Box
::
from_raw
(
cap_display_info
.capturer
.
0
);
}
*
lock
=
0
;
}
...
...
@@ -170,7 +180,7 @@ pub(super) fn get_capturer() -> ResultType<super::video_service::CapturerInfo> {
current
:
cap_display_info
.current
,
privacy_mode_id
:
0
,
_captuerer_privacy_mode_id
:
0
,
capturer
:
Box
::
new
(
cap_display_info
.capturer
),
capturer
:
Box
::
new
(
cap_display_info
.capturer
.clone
()
),
})
}
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment