⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errinsert.c

📁 一个264程序在NS2下面的仿真程序。非常好用
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <memory.h>#include <malloc.h>#include <float.h>#include <math.h>typedef struct {  unsigned id, size, retry, rest, segm;  double t1, t2, j1, j2, d1, d2;  char type, lost, signal, noise;} dump_t;typedef struct {  dump_t *P, *F;  unsigned long nP, nF;} data_t;static data_t D;  char *skips(char *p, const char *s, int n){  int i;  size_t l = strlen(s);  for (i=0; i<n; i++)    if ((p = strstr(p, s)) != 0) p += l;    else break;  return p;}int ReadDump(char* argv[], data_t *D){  int i, intime;  FILE *f3, *f4;  static dump_t null;  double t = 0, tmax;  unsigned long ti, line, id = 0;  char buf[0x1000], *p, *e, j, c;  int l=0, h, m, lost;  size_t num = 0;  void *tmp;    f3 = fopen(argv[3],"r");  f4 = fopen(argv[4],"r");    line = 0;  while (c = 0, line++, !feof(f3) && !ferror(f3)) {    if (!fgets(buf, sizeof buf, f3) || feof(f3) || ferror(f3)) break;    if (*buf == '\n') continue;    if (!(t = strtod(buf, &e)) && e == buf) { c = 1; goto e1; }    if (!(p = skips(buf, " id ", 1))) {      if (!(p = skips(buf, "frag ", 1))) { c = 1; goto e1; }    }    if (!(id = strtoul(p, &e, 10)) && e == p) { c = 1; goto e1; }    if (!(p = skips(buf, " udp ", 1)))      if (!(p = skips(buf, "UDP, length:", 1)))        if (!(p = skips(buf, "UDP, length", 1))) { c = 1; goto e1; }    if (!(l = strtoul(p, &e, 10)) && e == p) c = 1;e1: if (c) {      fprintf(stderr, "malformed input (%s, %lu)\n", argv[3], line);      continue;    }        if (++D->nP > num) {      num += 16384;      if ((tmp = realloc(D->P, num * sizeof *D->P)) == 0) {        fprintf(stderr, "realloc error\n");        return 0;      }      D->P = tmp;    }        D->P[D->nP-1] = null;    D->P[D->nP-1].id = id;    D->P[D->nP-1].t1 = t; /* t1: send time */    D->P[D->nP-1].size = l; /* l: packet size */    D->P[D->nP-1].lost = 1;    D->P[D->nP-1].type = ' ';  }  fclose(f3);  printf("sender trace process finish\n");  line = m = 0;  while (lost=0, c=0, line++, !feof(f4) && !ferror(f4)) {    if (!fgets(buf, sizeof buf, f4) || feof(f4) || ferror(f4)) break;    if (*buf == '\n') continue;    if (!(t = strtod(buf, &e)) && e == buf) { c = 1; goto e2; }    if (!(p = skips(buf, " id ", 1))) { c = 1; goto e2; }    if (!(id = strtoul(p, &e, 10)) && e == p) { c = 1; goto e2; }e2: if (c) {      fprintf(stderr, "malformed input (%s, %lu)\n", argv[4], line);      continue;    }    if (p = skips(buf, " lost ", 1)) lost = strtoul(p, 0, 10);    for (i=m; i<D->nP; i++)      if (id == D->P[i].id) {        D->P[i].t2 = t; /* t2: received time */        D->P[i].lost = lost; /* not lost:0, lost: other value */        if (i > 100) m = i - 100;        break;      }  }  fclose(f4);  printf("receiver trace process finish\n");    for(i=0; i<D->nP;i++)  	if(D->P[i].lost!=0)  	 printf("packet id %d lost\n", i);  return 1;}int main(int argc, char* argv[]){  unsigned int bufsize;  unsigned char buf[65000];  FILE *f1,*f2;  int i, intime, pid=0;  if (argc != 5)  {    printf ("Usage: %s [original H.264 file] [distorted H.264 file name] [sender trace file] [receiver trace file\n", argv[0]);    return -1;  }  if (NULL == (f1 = fopen (argv[1], "rb")))  {    printf ("%s: cannot open H.26L packet file %s for reading\n", argv[0], argv[1]);    return -2;  }  f2 = fopen(argv[2],"wb");    if (!ReadDump(argv, &D)) return -3;    while (1)  {    if (4 != fread (&bufsize, 1, 4, f1))      return 0;     if (4 != fread (&intime, 1, 4, f1))    {      printf ("Panic, cannot read timestamp, old software version file?\n");      return -1;    }     if (bufsize != fread (buf, 1, bufsize, f1))    {      printf ("Problems while reading buffer, exit\n");      return -3;    }    /*printf("D.P[%d].lost:%d\n", pid, D.P[pid].lost);*/    if(D.P[pid++].lost==0) {      fwrite(&bufsize,1,4,f2);      fwrite(&intime,1,4,f2);      fwrite(buf,bufsize,1,f2);    }  }  fclose(f1);  fclose(f2);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -