36
36
#include <string.h>
37
37
#include <rfb/rfb.h>
38
38
#include <rfb/rfbregion.h>
39
- #include "partialupdateregionbuf.h"
39
+ #include "ghpringbuf.h"
40
+ #include "partialupdateregion.h"
40
41
#include "private.h"
41
42
42
43
@@ -124,6 +125,7 @@ static const int tight2turbo_subsamp[10] = {
124
125
};
125
126
#endif
126
127
128
+
127
129
static void rfbProcessClientProtocolVersion (rfbClientPtr cl );
128
130
static void rfbProcessClientNormalMessage (rfbClientPtr cl );
129
131
static void rfbProcessClientInitMessage (rfbClientPtr cl );
@@ -134,6 +136,7 @@ static rfbMulticastFramebufferUpdateMsg* rfbPutMulticastHeader(rfbClientPtr cl,
134
136
rfbBool save );
135
137
static int rfbPutMulticastRectEncodingPreferred (rfbClientPtr cl , int x , int y , int w , int h , rfbBool save );
136
138
139
+ #define MULTICAST_FLAG_BUFFER_DIRTY 11
137
140
138
141
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
139
142
void rfbIncrClientRef (rfbClientPtr cl )
@@ -625,7 +628,7 @@ rfbClientConnectionGone(rfbClientPtr cl)
625
628
626
629
if (someclient == NULL ) { /* no other one has this */
627
630
free (cl -> multicastUpdPendingPtr );
628
- partUpdRgnBufDestroy (cl -> multicastPartUpdRgnBuf );
631
+ ghpringbuf_destroy (cl -> multicastPartUpdRgnBuf );
629
632
free (cl -> multicastWholeUpdId );
630
633
free (cl -> multicastPartialUpdId );
631
634
}
@@ -2619,7 +2622,7 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
2619
2622
2620
2623
case rfbMulticastFramebufferUpdateNACK :
2621
2624
{
2622
- partUpdRgnBuf * buf = (partUpdRgnBuf * )cl -> multicastPartUpdRgnBuf ;
2625
+ ghpringbuf * buf = (ghpringbuf * )cl -> multicastPartUpdRgnBuf ;
2623
2626
uint32_t firstInBuf ;
2624
2627
2625
2628
/* maybe this client sent a NACK without having registered for MulticastVNC? */
@@ -2650,22 +2653,24 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
2650
2653
sz_rfbMulticastFramebufferUpdateNACKMsg );
2651
2654
2652
2655
LOCK (cl -> screen -> multicastSharedMutex );
2653
- firstInBuf = partUpdRgnBufAt (buf , 0 )-> idPartial ;
2656
+
2657
+ firstInBuf = ((partialUpdRegion * )ghpringbuf_at (buf , 0 ))-> idPartial ;
2658
+
2654
2659
/* check if this partial update is in the buffer */
2655
- if (msg .mfun .idPartialUpd >= firstInBuf && msg .mfun .idPartialUpd < firstInBuf + partUpdRgnBufCount (buf )) {
2660
+ if (msg .mfun .idPartialUpd >= firstInBuf && msg .mfun .idPartialUpd < firstInBuf + ghpringbuf_count (buf )) {
2656
2661
uint32_t start = msg .mfun .idPartialUpd - firstInBuf ;
2657
2662
uint32_t i ;
2658
2663
uint32_t significantNACKsInPast = 0 ;
2659
2664
2660
- for (i = start ; i < start + msg .mfun .nPartialUpds && i < buf -> len ; ++ i ) {
2665
+ for (i = start ; i < start + msg .mfun .nPartialUpds && i < buf -> capacity ; ++ i ) {
2661
2666
#ifdef MULTICAST_DEBUG
2662
2667
rfbLog ("MulticastVNC DEBUG: marking buffer position %u, partial id %u as NACKed\n" ,
2663
2668
i , partUpdRgnBufAt (buf , i )-> idPartial );
2664
2669
rfbLog (" its sendrate was %d, was decreased %d\n" ,
2665
2670
partUpdRgnBufAt (buf , i )-> sendrate , partUpdRgnBufAt (buf , i )-> sendrate_decreased );
2666
2671
#endif
2667
2672
/* mark the lost partial updates as requested */
2668
- partUpdRgnBufAt ( buf , i )-> pending = TRUE;
2673
+ (( partialUpdRegion * ) ghpringbuf_at ( buf , i ) )-> pending = TRUE;
2669
2674
2670
2675
2671
2676
/* this NACK CANNOT be part of a 'tightly packed' burst of sufficient size,
@@ -2674,7 +2679,7 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
2674
2679
if (msg .mfun .nPartialUpds < MULTICAST_MAXSENDRATE_NACKS_REQUIRED ) {
2675
2680
uint32_t lookback = 2 * MULTICAST_MAXSENDRATE_NACKS_REQUIRED ;
2676
2681
while (lookback ) {
2677
- partialUpdRegion * p = partUpdRgnBufAt ( buf , i - lookback );
2682
+ partialUpdRegion * p = (( partialUpdRegion * ) ghpringbuf_at ( buf , i - lookback ) );
2678
2683
if (p
2679
2684
&& p -> pending
2680
2685
&& !p -> sendrate_decreased
@@ -2688,8 +2693,8 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
2688
2693
if (!cl -> screen -> multicastMaxSendRateFixed
2689
2694
&& ( msg .mfun .nPartialUpds >= MULTICAST_MAXSENDRATE_NACKS_REQUIRED /* this NACK belongs to a 'packed' burst of required size */
2690
2695
|| significantNACKsInPast + 1 >= MULTICAST_MAXSENDRATE_NACKS_REQUIRED ) /* this NACK belongs to a 'sparse' burst of required size */
2691
- && !partUpdRgnBufAt ( buf , i )-> sendrate_decreased
2692
- && cl -> screen -> multicastMaxSendRate >= partUpdRgnBufAt ( buf , i )-> sendrate ) {
2696
+ && ! (( partialUpdRegion * ) ghpringbuf_at ( buf , i ) )-> sendrate_decreased
2697
+ && cl -> screen -> multicastMaxSendRate >= (( partialUpdRegion * ) ghpringbuf_at ( buf , i ) )-> sendrate ) {
2693
2698
uint32_t j ;
2694
2699
#ifdef MULTICAST_DEBUG
2695
2700
uint32_t oldrate = cl -> screen -> multicastMaxSendRate ;
@@ -2710,14 +2715,14 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
2710
2715
cl -> screen -> multicastMaxSendRateIncrement );
2711
2716
#endif
2712
2717
/* mark this sendrate as decreased */
2713
- for (j = 0 ; j < partUpdRgnBufCount (buf ); ++ j )
2714
- if (partUpdRgnBufAt ( buf , j )-> sendrate == partUpdRgnBufAt ( buf , i )-> sendrate )
2715
- partUpdRgnBufAt ( buf , j )-> sendrate_decreased = TRUE;
2718
+ for (j = 0 ; j < ghpringbuf_count (buf ); ++ j )
2719
+ if ((( partialUpdRegion * ) ghpringbuf_at ( buf , j )) -> sendrate == (( partialUpdRegion * ) ghpringbuf_at ( buf , i ) )-> sendrate )
2720
+ (( partialUpdRegion * ) ghpringbuf_at ( buf , j ) )-> sendrate_decreased = TRUE;
2716
2721
}
2717
2722
}
2718
2723
2719
2724
/* mark this pixelformat and encoding as needing repair */
2720
- buf -> dirty = TRUE ;
2725
+ buf -> flags = MULTICAST_FLAG_BUFFER_DIRTY ;
2721
2726
}
2722
2727
else
2723
2728
rfbLog ("MulticastVNC: partial update %d NACKed by client %s not in sent buffer! Increasing sent buffer size helps.\n" ,
@@ -3184,7 +3189,7 @@ rfbSendFramebufferUpdate(rfbClientPtr cl,
3184
3189
3185
3190
if (someclient == NULL ) { /* no other one has this */
3186
3191
free (cl -> multicastUpdPendingPtr );
3187
- partUpdRgnBufDestroy (cl -> multicastPartUpdRgnBuf );
3192
+ ghpringbuf_destroy (cl -> multicastPartUpdRgnBuf );
3188
3193
free (cl -> multicastWholeUpdId );
3189
3194
free (cl -> multicastPartialUpdId );
3190
3195
}
@@ -3208,7 +3213,10 @@ rfbSendFramebufferUpdate(rfbClientPtr cl,
3208
3213
3209
3214
if (someclient == NULL ) { /* no other client has this, alloc new ones on the heap */
3210
3215
cl -> multicastUpdPendingPtr = calloc (sizeof (rfbBool ), 1 );
3211
- cl -> multicastPartUpdRgnBuf = partUpdRgnBufCreate (MULTICAST_PART_UPD_RGN_BUF_SIZE /cl -> screen -> multicastPacketSize );
3216
+ cl -> multicastPartUpdRgnBuf = ghpringbuf_create (MULTICAST_PART_UPD_RGN_BUF_SIZE /cl -> screen -> multicastPacketSize ,
3217
+ sizeof (partialUpdRegion ),
3218
+ 1 ,
3219
+ clean_partialUpdRegion );
3212
3220
cl -> multicastWholeUpdId = calloc (sizeof (uint16_t ), 1 );
3213
3221
cl -> multicastPartialUpdId = calloc (sizeof (uint32_t ), 1 );
3214
3222
rfbLog ("MulticastVNC encountered new pixelformat and/or encoding, allocating new data for client %s\n" , cl -> host );
@@ -3883,18 +3891,18 @@ rfbSendMulticastFramebufferUpdate(rfbClientPtr cl,
3883
3891
rfbBool
3884
3892
rfbSendMulticastRepairUpdate (rfbClientPtr cl )
3885
3893
{
3886
- partUpdRgnBuf * buf ;
3894
+ ghpringbuf * buf ;
3887
3895
rfbBool repairPending ;
3888
3896
3889
3897
LOCK (cl -> screen -> multicastUpdateMutex );
3890
3898
3891
- buf = (partUpdRgnBuf * )cl -> multicastPartUpdRgnBuf ;
3899
+ buf = (ghpringbuf * )cl -> multicastPartUpdRgnBuf ;
3892
3900
LOCK (cl -> screen -> multicastSharedMutex );
3893
- repairPending = buf -> dirty ;
3901
+ repairPending = buf -> flags == MULTICAST_FLAG_BUFFER_DIRTY ;
3894
3902
UNLOCK (cl -> screen -> multicastSharedMutex );
3895
3903
3896
3904
if (repairPending ) {
3897
- size_t i , count = partUpdRgnBufCount (buf ); /* multicastUpdateMutex above ensures the buffer size isn't modified by other threads */
3905
+ size_t i , count = ghpringbuf_count (buf ); /* multicastUpdateMutex above ensures the buffer size isn't modified by other threads */
3898
3906
3899
3907
/* flush buffer just for safety */
3900
3908
if (!rfbSendMulticastUpdateBuf (cl -> screen )) {
@@ -3903,7 +3911,7 @@ rfbSendMulticastRepairUpdate(rfbClientPtr cl)
3903
3911
}
3904
3912
3905
3913
for (i = 0 ; i < count ; ++ i ) {
3906
- partialUpdRegion * pur = partUpdRgnBufAt (buf , i );
3914
+ partialUpdRegion * pur = ( partialUpdRegion * ) ghpringbuf_at (buf , i );
3907
3915
if (pur -> pending ) {
3908
3916
sraRectangleIterator * i = NULL ;
3909
3917
sraRect rect ;
@@ -3938,7 +3946,7 @@ rfbSendMulticastRepairUpdate(rfbClientPtr cl)
3938
3946
3939
3947
/* mark this pixelformat and encoding combination as done */
3940
3948
LOCK (cl -> screen -> multicastSharedMutex );
3941
- buf -> dirty = FALSE;
3949
+ buf -> flags = 0 ; /* unset dirty flag */
3942
3950
UNLOCK (cl -> screen -> multicastSharedMutex );
3943
3951
}
3944
3952
@@ -3957,15 +3965,15 @@ rfbPutMulticastHeader(rfbClientPtr cl, uint16_t idWholeUpd, uint32_t idPartialUp
3957
3965
{
3958
3966
if (save ) {
3959
3967
LOCK (cl -> screen -> multicastSharedMutex );
3960
- partUpdRgnBuf * buf = (partUpdRgnBuf * )cl -> multicastPartUpdRgnBuf ;
3968
+ ghpringbuf * buf = (ghpringbuf * )cl -> multicastPartUpdRgnBuf ;
3961
3969
partialUpdRegion tmp ;
3962
3970
tmp .idWhole = idWholeUpd ;
3963
3971
tmp .idPartial = idPartialUpd ;
3964
3972
tmp .region = sraRgnCreate ();
3965
3973
tmp .pending = FALSE;
3966
3974
tmp .sendrate = cl -> screen -> multicastMaxSendRate ;
3967
3975
tmp .sendrate_decreased = FALSE;
3968
- partUpdRgnBufInsert (buf , tmp );
3976
+ ghpringbuf_put (buf , & tmp );
3969
3977
UNLOCK (cl -> screen -> multicastSharedMutex );
3970
3978
}
3971
3979
@@ -4000,9 +4008,9 @@ rfbPutMulticastRectEncodingPreferred(rfbClientPtr cl, int x, int y, int w, int h
4000
4008
{
4001
4009
if (save ) {
4002
4010
LOCK (cl -> screen -> multicastSharedMutex );
4003
- partUpdRgnBuf * buf = (partUpdRgnBuf * )cl -> multicastPartUpdRgnBuf ;
4011
+ ghpringbuf * buf = (ghpringbuf * )cl -> multicastPartUpdRgnBuf ;
4004
4012
sraRegionPtr tmp = sraRgnCreateRect (x , y , x + w , y + h );
4005
- partialUpdRegion * lastone = partUpdRgnBufAt ( buf , partUpdRgnBufCount (buf )- 1 );
4013
+ partialUpdRegion * lastone = ( partialUpdRegion * ) ghpringbuf_at ( buf , ghpringbuf_count (buf )- 1 );
4006
4014
sraRgnOr (lastone -> region , tmp );
4007
4015
sraRgnDestroy (tmp );
4008
4016
UNLOCK (cl -> screen -> multicastSharedMutex );
0 commit comments