File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ edition = "2021"
66# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77
88[dependencies ]
9- bzip2 = " 0.4.3 "
9+ zstd = " 0.9 "
Original file line number Diff line number Diff line change 1- use std:: io:: Read ;
2-
3- use bzip2:: { read:: { BzEncoder , BzDecoder } , Compression } ;
41
52// 默认帧率
63pub const FPS : u64 = 20 ;
74
85// 传输像素保留位数(右边0越多压缩程度越大)
96pub const BIT_SAVE : u8 = 0b1111_1000 ;
107
8+ // 传输压缩水平0-21 0消耗资源最小但是压缩率小(需要带宽大) 21消耗资源最大,但但是压缩率大(需要带宽小)
9+ pub const COMPRESS_LEVEL : i32 = 3 ;
10+
1111// key事件 start
1212pub const KEY_UP : u8 = 1 ;
1313pub const KEY_DOWN : u8 = 2 ;
@@ -23,19 +23,20 @@ pub const MOVE:u8 = 7;
2323
2424
2525pub fn compress ( src : & [ u8 ] , dst : & mut Vec < u8 > ) -> usize {
26+
2627 unsafe {
2728 dst. set_len ( 0 ) ;
2829 }
29- let mut compressor = BzEncoder :: new ( src, Compression :: best ( ) ) ;
30- return compressor . read_to_end ( dst) . unwrap ( ) ;
30+ zstd :: stream :: copy_encode ( src, & mut * dst , COMPRESS_LEVEL ) . unwrap ( ) ;
31+ return dst. len ( ) ;
3132}
3233
3334pub fn decompress ( src : & [ u8 ] , dst : & mut Vec < u8 > ) -> usize {
3435 unsafe {
3536 dst. set_len ( 0 ) ;
3637 }
37- let mut decompressor = BzDecoder :: new ( src) ;
38- return decompressor . read_to_end ( dst) . unwrap ( ) ;
38+ zstd :: stream :: copy_decode ( src, & mut * dst ) . unwrap ( ) ;
39+ return dst. len ( ) ;
3940}
4041
4142#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments