@@ -107,13 +107,15 @@ private static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
107
107
GetCursorState ( ) ;
108
108
bmpData = ScreenCap . LockBits ( new System . Drawing . Rectangle ( 0 , 0 , ScreenCap . Width , ScreenCap . Height ) ,
109
109
ImageLockMode . ReadWrite , ScreenCap . PixelFormat ) ;
110
- using ( MemoryStream MotionStream = new MemoryStream ( 10000000 ) ) // 10000000
110
+ // 10000000 allocate already enough memory to make it fast
111
+ using ( MemoryStream MotionStream = new MemoryStream ( 100000000 ) )
111
112
{
112
113
if ( UnsafeMotionCodec == null ) throw new Exception ( "StreamCodec can not be null." ) ;
113
114
UnsafeMotionCodec . CodeImage ( bmpData . Scan0 ,
114
115
new Rectangle ( 0 , 0 , ScreenCap . Width , ScreenCap . Height ) ,
115
116
new Size ( ScreenCap . Width , ScreenCap . Height ) ,
116
117
ScreenCap . PixelFormat , MotionStream ) ;
118
+ // 4 bytes = inactivity no motion detection
117
119
if ( MotionStream . Length > 4 )
118
120
{
119
121
// GlobalVariables.Root.Writetxtchatrom("Green", "Before no compressed: " + MotionStream.ToArray().Length);
@@ -122,20 +124,20 @@ private static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
122
124
SenderReceiver . SendMessage ( "b|" + Tipo + "|" + tempBytes . Length ) ;
123
125
SenderReceiver . client . Send ( tempBytes , 0 , tempBytes . Length ) ;
124
126
Array . Clear ( tempBytes , 0 , tempBytes . Length ) ;
125
- }
127
+ }
126
128
}
127
129
ScreenCap . UnlockBits ( bmpData ) ;
128
130
ScreenCap . Dispose ( ) ;
129
131
GC . Collect ( ) ;
130
132
// GlobalVariables.Root.Writetxtchatrom("Green", "time: " + time.ElapsedMilliseconds + " ms");
131
133
// time.Stop();
132
- }
134
+ }
133
135
catch ( Exception ex )
134
136
{
135
137
GlobalVariables . Root . Writetxtchatrom ( "Red" , "Stop Sharing Desktop: " + ex . Message ) ;
136
138
StopDesktop ( ) ;
137
139
GC . Collect ( ) ;
138
- }
140
+ }
139
141
}
140
142
141
143
private static Bitmap ScreenCap
0 commit comments