Text   |  XML   |  ReML   |   Visible Warnings:

Redundant Condition  at tap-rtp-common.c:527

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

rtp_packet_analyse

(/home/sate/Testcases/c/cve/wireshark-1.2.0/tap-rtp-common.c)expand/collapse
Show more  
 434  int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
 435                                packet_info *pinfo,
 436                                const struct _rtp_info *rtpinfo)
 437  {
 438          double current_time;
 439          double current_jitter;
 440          double current_diff = 0;
 441          double nominaltime;
 442          double arrivaltime;             /* Time relative to start_time */
 443          double expected_time;
 444          double absskew;
 445          guint32 clock_rate;
 446          guint32 old_flags;
 447   
 448          /* Store the current time */
 449          current_time = nstime_to_msec(&pinfo->fd->rel_ts);
 450   
 451          /*  Is this the first packet we got in this direction? */
 452          if (statinfo->first_packet) {
 453                  statinfo->start_seq_nr = rtpinfo->info_seq_num;
 454                  statinfo->stop_seq_nr = rtpinfo->info_seq_num;
 455                  statinfo->seq_num = rtpinfo->info_seq_num;
 456                  statinfo->start_time = current_time;
 457                  statinfo->timestamp = rtpinfo->info_timestamp;
 458                  statinfo->first_timestamp = rtpinfo->info_timestamp;
 459                  statinfo->time = current_time;
 460                  statinfo->pt = rtpinfo->info_payload_type;
 461                  statinfo->reg_pt = rtpinfo->info_payload_type;
 462                  statinfo->bw_history[statinfo->bw_index].bytes = rtpinfo->info_data_len + 28;
 463                  statinfo->bw_history[statinfo->bw_index].time = current_time;
 464                  statinfo->bw_index++;
 465                  statinfo->total_bytes += rtpinfo->info_data_len + 28;
 466                  statinfo->bandwidth = (double)(statinfo->total_bytes*8)/1000;
 467                  /* Not needed ? initialised to zero? */
 468                  statinfo->delta = 0;
 469                  statinfo->jitter = 0;
 470                  statinfo->diff = 0;
 471   
 472                  statinfo->total_nr++;
 473                  statinfo->flags |= STAT_FLAG_FIRST;
 474                  if (rtpinfo->info_marker_set) {
 475                          statinfo->flags |= STAT_FLAG_MARKER;
 476                  }
 477                  statinfo->first_packet = FALSE;
 478                  return 0;
 479          }
 480   
 481          /* Save old flags and reset flags */
 482          old_flags = statinfo->flags;
 483          statinfo->flags = 0;
 484   
 485          /* When calculating expected rtp packets the seq number can wrap around 
 486           * so we have to count the number of cycles 
 487           * Variable cycles counts the wraps around in forwarding connection and
 488           * under is flag that indicates where we are
 489           *
 490           * XXX How to determine number of cycles with all possible lost, late 
 491           * and duplicated packets without any doubt? It seems to me, that 
 492           * because of all possible combination of late, duplicated or lost 
 493           * packets, this can only be more or less good approximation 
 494           *
 495           * There are some combinations (rare but theoretically possible),
 496           * where below code won't work correctly - statistic may be wrong then.
 497           */
 498   
 499          /* So if the current sequence number is less than the start one
 500           * we assume, that there is another cycle running
 501           */
 502          if ((rtpinfo->info_seq_num < statinfo->start_seq_nr) && (statinfo->under == FALSE)){
 503                  statinfo->cycles++;
 504                  statinfo->under = TRUE;
 505          }
 506          /* what if the start seq nr was 0? Then the above condition will never
 507           * be true, so we add another condition. XXX The problem would arise 
 508           * if one of the packets with seq nr 0 or 65535 would be lost or late
 509           */
 510          else if ((rtpinfo->info_seq_num == 0) && (statinfo->stop_seq_nr == 65535) &&
 511                  (statinfo->under == FALSE)){
 512                  statinfo->cycles++;
 513                  statinfo->under = TRUE;
 514          }
 515          /* the whole round is over, so reset the flag */
 516          else if ((rtpinfo->info_seq_num > statinfo->start_seq_nr) && (statinfo->under != FALSE)) {
 517                  statinfo->under = FALSE;
 518          }
 519   
 520          /* Since it is difficult to count lost, duplicate or late packets separately,
 521           * we would like to know at least how many times the sequence number was not ok
 522           */
 523   
 524          /* If the current seq number equals the last one or if we are here for 
 525           * the first time, then it is ok, we just store the current one as the last one
 526           */
 527          if ( (statinfo->seq_num+1 == rtpinfo->info_seq_num) || (statinfo->flags & STAT_FLAG_FIRST) )
 528                  statinfo->seq_num = rtpinfo->info_seq_num;
 529          /* If the first one is 65535. XXX same problem as above: if seq 65535 or 0 is lost... */
 530          else if ( (statinfo->seq_num == 65535) && (rtpinfo->info_seq_num == 0) )
 531                  statinfo->seq_num = rtpinfo->info_seq_num;
 532          /* Lost packets */
 533          else if (statinfo->seq_num+1 < rtpinfo->info_seq_num) {
 534                  statinfo->seq_num = rtpinfo->info_seq_num;
 535                  statinfo->sequence++;
 536                  statinfo->flags |= STAT_FLAG_WRONG_SEQ;
 537          }
 538          /* Late or duplicated */
 539          else if (statinfo->seq_num+1 > rtpinfo->info_seq_num) {
 540                  statinfo->sequence++;
 541                  statinfo->flags |= STAT_FLAG_WRONG_SEQ;
 542          }
 543   
 544          /* Check payload type */
 545          if (rtpinfo->info_payload_type == PT_CN 
 546                  || rtpinfo->info_payload_type == PT_CN_OLD)
 547                  statinfo->flags |= STAT_FLAG_PT_CN;
 548          if (statinfo->pt == PT_CN 
 549                  || statinfo->pt == PT_CN_OLD)
 550                  statinfo->flags |= STAT_FLAG_FOLLOW_PT_CN;
 551          if (rtpinfo->info_payload_type != statinfo->pt)
 552                  statinfo->flags |= STAT_FLAG_PT_CHANGE;
 553          statinfo->pt = rtpinfo->info_payload_type;
 554   
 555          /*
 556           * Return 0 for unknown payload types
 557           * Ignore jitter calculation for clockrate = 0 
 558           */
 559          if (statinfo->pt < 96 ){
 560                  clock_rate = get_clock_rate(statinfo->pt);
 561          }else{ /* Dynamic PT */
 562                  if ( rtpinfo->info_payload_type_str != NULL ){
 563                          /* Is it a "telephone-event" ?
 564                           * Timestamp is not increased for telepone-event packets inpacting
 565                           * caluculation of Jitter Skew and clock drift.
 566                           * see 2.2.1 of RFC 4733 
 567                           */
 568                          if (g_ascii_strncasecmp("telephone-event",rtpinfo->info_payload_type_str,(strlen("telephone-event")))==0){
 569                                  clock_rate = 0;
 570                                  statinfo->flags |= STAT_FLAG_PT_T_EVENT;
 571                          }else{
 572                                  clock_rate = get_dyn_pt_clock_rate(rtpinfo-> info_payload_type_str);
 573                          }
 574                  }else{
 575                          clock_rate = 0;
 576                  }
 577          }
 578   
 579                  /* Handle wraparound ? */
 580          arrivaltime = current_time - statinfo->start_time;
 581   
 582          if (statinfo->first_timestamp > rtpinfo->info_timestamp){
 583                  /* Handle wraparound */
 584                  nominaltime = (double)(rtpinfo->info_timestamp + 0xffffffff - statinfo->first_timestamp + 1);
 585          }else{
 586                  nominaltime = (double)(rtpinfo->info_timestamp - statinfo->first_timestamp);
 587          }
 588   
 589          /* Can only analyze defined sampling rates */
 590      if (clock_rate != 0) {  
 591                  statinfo->clock_rate = clock_rate;
 592                  /* Convert from sampling clock to ms */
 593                  nominaltime = nominaltime /(clock_rate/1000);
 594   
 595                  /* Calculate the current jitter(in ms) */
 596                  if (!statinfo->first_packet) {
 597                          expected_time = statinfo->time + (nominaltime - statinfo->lastnominaltime);
 598                          current_diff = fabs(current_time - expected_time);
 599                          current_jitter = (15 * statinfo->jitter + current_diff) / 16;
 600   
 601                          statinfo->delta = current_time-(statinfo->time);
 602                          statinfo->jitter = current_jitter;
 603                          statinfo->diff = current_diff;
 604                  }
 605                  statinfo->lastnominaltime = nominaltime;
 606                  /* Calculate skew, i.e. absolute jitter that also catches clock drift 
 607                   * Skew is positive if TS (nominal) is too fast 
 608                   */
 609                  statinfo->skew    = nominaltime - arrivaltime;
 610                  absskew = fabs(statinfo->skew);
 611                  if(absskew > fabs(statinfo->max_skew)){
 612                          statinfo->max_skew = statinfo->skew;
 613                  }
 614                  /* Gather data for calculation of average, minimum and maximum framerate based on timestamp */
 615  #if 0 
 616                  if (numPackets > 0 && (!hardPayloadType || !alternatePayloadType)) {  
 617                          /* Skip first packet and possibly alternate payload type packets */
 618                          double dt;
 619                          dt     = nominaltime - statinfo->lastnominaltime;
 620                          sumdt += 1.0 * dt;
 621                          numdt += (dt != 0 ? 1 : 0);
 622                          mindt  = (dt < mindt ? dt : mindt);
 623                          maxdt  = (dt > maxdt ? dt : maxdt);
 624                  }
 625  #endif
 626                  /* Gather data for calculation of skew least square */
 627                  statinfo->sumt   += 1.0 * current_time;
 628                  statinfo->sumTS  += 1.0 * nominaltime;
 629                  statinfo->sumt2  += 1.0 * current_time * current_time;
 630                  statinfo->sumtTS += 1.0 * current_time * nominaltime;
 631          }
 632   
 633          /* Calculate the BW in Kbps adding the IP+UDP header to the RTP -> 20bytes(IP)+8bytes(UDP) = 28bytes */
 634          statinfo->bw_history[statinfo->bw_index].bytes = rtpinfo->info_data_len + 28;
 635          statinfo->bw_history[statinfo->bw_index].time = current_time;
 636   
 637          /* Check if there are more than 1sec in the history buffer to calculate BW in bps. If so, remove those for the calculation */
 638          while ((statinfo->bw_history[statinfo->bw_start_index].time+1000/* ms */)<current_time){
 639                  statinfo->total_bytes -= statinfo->bw_history[statinfo->bw_start_index].bytes;
 640                  statinfo->bw_start_index++;
 641                  if (statinfo->bw_start_index == BUFF_BW) statinfo->bw_start_index=0;
 642          };
 643          statinfo->total_bytes += rtpinfo->info_data_len + 28;
 644          statinfo->bandwidth = (double)(statinfo->total_bytes*8)/1000;
 645          statinfo->bw_index++;
 646          if (statinfo->bw_index == BUFF_BW) statinfo->bw_index = 0;
 647   
 648   
 649          /* Is it a packet with the mark bit set? */
 650          if (rtpinfo->info_marker_set) {
 651                  statinfo->delta_timestamp = rtpinfo->info_timestamp - statinfo->timestamp;
 652                  if (rtpinfo->info_timestamp > statinfo->timestamp){
 653                          statinfo->flags |= STAT_FLAG_MARKER;
 654                  }
 655                  else{
 656                          statinfo->flags |= STAT_FLAG_WRONG_TIMESTAMP;
 657                  }
 658          }
 659          /* Is it a regular packet? */
 660          if (!(statinfo->flags & STAT_FLAG_FIRST)
 661                  && !(statinfo->flags & STAT_FLAG_MARKER)
 662                  && !(statinfo->flags & STAT_FLAG_PT_CN)
 663                  && !(statinfo->flags & STAT_FLAG_WRONG_TIMESTAMP)
 664                  && !(statinfo->flags & STAT_FLAG_FOLLOW_PT_CN)) {
 665                  /* Include it in maximum delta calculation */
 666                  if (statinfo->delta > statinfo->max_delta) {
 667                          statinfo->max_delta = statinfo->delta;
 668                          statinfo->max_nr = pinfo->fd->num;
 669                  }
 670                  if (clock_rate != 0) {  
 671                          /* Maximum and mean jitter calculation */
 672                          if (statinfo->jitter > statinfo->max_jitter) {
 673                                  statinfo->max_jitter = statinfo->jitter;
 674                          }
 675                          statinfo->mean_jitter = (statinfo->mean_jitter*statinfo->total_nr + current_diff) / (statinfo->total_nr+1);
 676                  }
 677          }
 678          /* Regular payload change? (CN ignored) */
 679          if (!(statinfo->flags & STAT_FLAG_FIRST)
 680                  && !(statinfo->flags & STAT_FLAG_PT_CN)) {
 681                  if ((statinfo->pt != statinfo->reg_pt)
 682                          && (statinfo->reg_pt != PT_UNDEFINED)) {
 683                          statinfo->flags |= STAT_FLAG_REG_PT_CHANGE;
 684                  }
 685          }
 686   
 687          /* Set regular payload*/
 688          if (!(statinfo->flags & STAT_FLAG_PT_CN)) {
 689                  statinfo->reg_pt = statinfo->pt;
 690          }
 691   
 692          statinfo->time = current_time;
 693          statinfo->timestamp = rtpinfo->info_timestamp;
 694          statinfo->stop_seq_nr = rtpinfo->info_seq_num;
 695          statinfo->total_nr++;
 696   
 697          return 0;
 698  }
Show more  




Change Warning 4410.29825 : Redundant Condition

Priority:
State:
Finding:
Owner:
Note: