libfreerdp-core: support continuous auto-detection.
authorVic Lee <llyzs.vic@gmail.com>
Fri, 7 Nov 2014 08:18:49 +0000 (16:18 +0800)
committerVic Lee <llyzs.vic@gmail.com>
Fri, 7 Nov 2014 08:18:49 +0000 (16:18 +0800)
include/freerdp/autodetect.h
libfreerdp/core/autodetect.c
libfreerdp/core/rdp.c

index 40bff71..3f69f92 100644 (file)
@@ -43,7 +43,8 @@ struct rdp_autodetect
        ALIGN64 UINT32 netCharBandwidth; /* 5 */
        ALIGN64 UINT32 netCharBaseRTT; /* 6 */
        ALIGN64 UINT32 netCharAverageRTT; /* 7 */
-       UINT64 paddingA[16 - 8]; /* 8 */
+       ALIGN64 BOOL bandwidthMeasureStarted; /* 8 */
+       UINT64 paddingA[16 - 9]; /* 9 */
 
        ALIGN64 pRTTMeasureRequest RTTMeasureRequest; /* 16 */
        ALIGN64 pRTTMeasureResponse RTTMeasureResponse; /* 17 */
index 7dca1e9..c636778 100644 (file)
@@ -322,6 +322,12 @@ static BOOL autodetect_recv_bandwidth_measure_start(rdpRdp* rdp, wStream* s, AUT
        rdp->autodetect->bandwidthMeasureStartTime = GetTickCount();
        rdp->autodetect->bandwidthMeasureByteCount = 0;
 
+       /* Continuous Auto-Detection: mark the start of the measurement */
+       if (autodetectReqPdu->requestType == 0x0014)
+       {
+               rdp->autodetect->bandwidthMeasureStarted = TRUE;
+       }
+
        return TRUE;
 }
 
@@ -373,6 +379,12 @@ static BOOL autodetect_recv_bandwidth_measure_stop(rdpRdp* rdp, wStream* s, AUTO
        /* Add the payload length to the bandwidth measurement parameters */
        rdp->autodetect->bandwidthMeasureByteCount += payloadLength;
 
+       /* Continuous Auto-Detection: mark the stop of the measurement */
+       if (autodetectReqPdu->requestType == 0x0429)
+       {
+               rdp->autodetect->bandwidthMeasureStarted = FALSE;
+       }
+
        /* Send a response the server */
        responseType = autodetectReqPdu->requestType == 0x002B ? 0x0003 : 0x000B;
 
index 914140b..3b2bb62 100644 (file)
@@ -1001,6 +1001,11 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
        if (rdp->disconnect)
                return 0;
  
+       if (rdp->autodetect->bandwidthMeasureStarted)
+       {
+               rdp->autodetect->bandwidthMeasureByteCount += length;
+       }
+
        if (rdp->settings->DisableEncryption)
        {
                if (!rdp_read_security_header(s, &securityFlags))
@@ -1096,6 +1101,11 @@ static int rdp_recv_fastpath_pdu(rdpRdp* rdp, wStream* s)
                return -1;
        }
 
+       if (rdp->autodetect->bandwidthMeasureStarted)
+       {
+               rdp->autodetect->bandwidthMeasureByteCount += length;
+       }
+
        if (fastpath->encryptionFlags & FASTPATH_OUTPUT_ENCRYPTED)
        {
                UINT16 flags = (fastpath->encryptionFlags & FASTPATH_OUTPUT_SECURE_CHECKSUM) ? SEC_SECURE_CHECKSUM : 0;