Merge pull request #156 from nfedera/pcaptimestampfix

pcap: fix timstamps to use gettimeofday
This commit is contained in:
Marc-André Moreau 2011-10-18 09:59:04 -07:00
commit 4b52871d33
3 changed files with 52 additions and 23 deletions

View File

@ -22,7 +22,6 @@
#include <freerdp/api.h>
#include <freerdp/types.h>
#include <freerdp/utils/stopwatch.h>
struct _pcap_header
{
@ -59,7 +58,6 @@ struct rdp_pcap
{
FILE* fp;
char* name;
STOPWATCH* sw;
boolean write;
int file_size;
int record_count;

View File

@ -17,7 +17,7 @@
* limitations under the License.
*/
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
@ -65,6 +65,7 @@ void pcap_write_record(rdpPcap* pcap, pcap_record* record)
void pcap_add_record(rdpPcap* pcap, void* data, uint32 length)
{
pcap_record* record;
struct timeval tp;
if (pcap->tail == NULL)
{
@ -88,9 +89,9 @@ void pcap_add_record(rdpPcap* pcap, void* data, uint32 length)
record->header.incl_len = length;
record->header.orig_len = length;
stopwatch_stop(pcap->sw);
stopwatch_get_elapsed_time_in_useconds(pcap->sw, &record->header.ts_sec, &record->header.ts_usec);
stopwatch_start(pcap->sw);
gettimeofday(&tp, 0);
record->header.ts_sec = tp.tv_sec;
record->header.ts_usec = tp.tv_usec;
}
boolean pcap_has_next_record(rdpPcap* pcap)
@ -161,9 +162,6 @@ rdpPcap* pcap_open(char* name, boolean write)
fseek(pcap->fp, 0, SEEK_SET);
pcap_read_header(pcap, &pcap->header);
}
pcap->sw = stopwatch_create();
stopwatch_start(pcap->sw);
}
return pcap;
@ -187,7 +185,4 @@ void pcap_close(rdpPcap* pcap)
if (pcap->fp != NULL)
fclose(pcap->fp);
stopwatch_stop(pcap->sw);
stopwatch_free(pcap->sw);
}

View File

@ -33,6 +33,7 @@
#include <freerdp/listener.h>
static char* test_pcap_file = NULL;
static boolean test_dump_rfx_realtime = True;
/* HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, LL3 */
static const unsigned int test_quantization_values[] =
@ -246,11 +247,49 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
context->icon_y = y;
}
static boolean test_sleep_tsdiff(uint32 *old_sec, uint32 *old_usec, uint32 new_sec, uint32 new_usec)
{
sint32 sec, usec;
if (*old_sec==0 && *old_usec==0)
{
*old_sec = new_sec;
*old_usec = new_usec;
return True;
}
sec = new_sec - *old_sec;
usec = new_usec - *old_usec;
if (sec<0 || (sec==0 && usec<0))
{
printf("Invalid time stamp detected.\n");
return False;
}
*old_sec = new_sec;
*old_usec = new_usec;
while (usec < 0)
{
usec += 1000000;
sec--;
}
if (sec > 0)
freerdp_sleep(sec);
if (usec > 0)
freerdp_usleep(usec);
return True;
}
void tf_peer_dump_rfx(freerdp_peer* client)
{
STREAM* s;
uint32 seconds;
uint32 useconds;
uint32 prev_seconds;
uint32 prev_useconds;
rdpUpdate* update;
rdpPcap* pcap_rfx;
pcap_record record;
@ -260,7 +299,7 @@ void tf_peer_dump_rfx(freerdp_peer* client)
client->update->pcap_rfx = pcap_open(test_pcap_file, False);
pcap_rfx = client->update->pcap_rfx;
seconds = useconds = 0;
prev_seconds = prev_useconds = 0;
while (pcap_has_next_record(pcap_rfx))
{
@ -273,14 +312,8 @@ void tf_peer_dump_rfx(freerdp_peer* client)
pcap_get_next_record_content(pcap_rfx, &record);
s->p = s->data + s->size;
seconds = record.header.ts_sec - seconds;
useconds = record.header.ts_usec - useconds;
if (seconds > 0)
freerdp_sleep(seconds);
if (useconds > 0)
freerdp_usleep(useconds);
if (test_dump_rfx_realtime && test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, record.header.ts_usec) == False)
break;
update->SurfaceCommand(update, s);
}
@ -548,6 +581,9 @@ int main(int argc, char* argv[])
if (argc > 1)
test_pcap_file = argv[1];
if (argc > 2 && !strcmp(argv[2], "--fast"))
test_dump_rfx_realtime = False;
/* Open the server socket and start listening. */
if (instance->Open(instance, NULL, 3389))