Changeset 130
- Timestamp:
- 18/11/05 00:14:19 (3 years ago)
- Files:
-
- trunk/examples/decode_mpeg.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/examples/decode_mpeg.c
r129 r130 171 171 memset( p_dst, 0, i_size ); 172 172 i_rc = read( i_socket, p_dst, i_size ); 173 if( i_rc < 0 ) printf( "READ INTERRUPTED BY SIGNAL\n" ); 174 if( i_rc == 0 ) printf( "READ RETURNS 0\n" ); 173 175 return (i_rc <= i_size ) ? 1 : 0; 174 176 } … … 418 420 int i_mtu = 1316; /* (7 * 188) = 1316 < 1500 network MTU */ 419 421 #ifdef HAVE_SYS_SOCKET_H 420 int i_port = 0; 421 char *ipaddress = NULL; 422 time_t time_prev = 0; 423 int i_old_cc = -1; 424 mtime_t i_prev_pcr = 0; /* 33 bits */ 425 #endif 422 int i_port = 0; 423 char * ipaddress = NULL; 424 time_t time_prev = 0; 425 int i_old_cc = -1; 426 mtime_t i_prev_pcr = 0; /* 33 bits */ 427 #endif 428 uint32_t i_bytes = 0; /* bytes transmitted between PCR's */ 426 429 char *filename = NULL; 427 430 … … 447 450 i_mtu = atoi( optarg ); 448 451 if( i_mtu < 0 ) i_mtu = 1316; 452 else i_mtu = (i_mtu / 188) * 188; 449 453 break; 450 454 case 'p': … … 466 470 } while( next_option != -1 ); 467 471 472 #ifdef HAVE_SYS_SOCKET_H 473 if( b_verbose ) 474 { 475 printf( "set mtu to %d\n", i_mtu ); 476 } 477 #endif 468 478 /* initialize */ 469 479 if( filename ) … … 490 500 /* Read first packet */ 491 501 if( filename ) 502 { 492 503 b_ok = ReadPacket( i_fd, p_data); 493 #ifdef HAVE_SYS_SOCKET_H 494 else 504 i_bytes += 188; 505 } 506 #ifdef HAVE_SYS_SOCKET_H 507 else 508 { 495 509 b_ok = ReadPacketFromSocket( i_fd, p_data, i_mtu ); 496 510 i_bytes += i_mtu; 511 } 497 512 if( b_verbose ) 498 printf( "seqno, network (ms), PCR value (ms), PCR prev (ms), delta (ms) \n" );513 printf( "seqno, network (ms), PCR value (ms), PCR prev (ms), delta (ms), bytes, bitrate (bytes/delta)\n" ); 499 514 #endif 500 515 501 516 /* Enter infinite loop */ 502 517 p_stream->pat.handle = dvbpsi_AttachPAT( DumpPAT, p_stream ); 503 while( b_ok)518 while( b_ok ) 504 519 { 505 520 int i = 0; … … 538 553 p_stream->pid[i_pid].i_cc = i_cc; 539 554 } 540 555 541 556 /* Other adaptation field */ 542 557 if( b_adaptation ) … … 555 570 { 556 571 mtime_t i_pcr; /* 33 bits */ 557 mtime_t i_delta = 0; 558 struct timeval tv; 572 mtime_t i_delta = 0; 559 573 560 574 i_pcr = ( ( (mtime_t)p_tmp[6] << 25 ) | … … 572 586 time_t time_current; 573 587 time_t tv_delta; 588 struct timeval tv; 574 589 575 590 gettimeofday( &tv, NULL ); 576 591 time_current = (tv.tv_sec*1000) + (tv.tv_usec/1000); 577 tv_delta = time_current - time_prev; 578 printf( "arrival %.2ld, ", (long)tv_delta ); 592 if( time_prev == 0 ) /* probably the first one */ 593 printf( "arrival -, " ); 594 else 595 { 596 tv_delta = time_current - time_prev; 597 printf( "arrival %.2lld, ", (long long int)tv_delta ); 598 } 579 599 time_prev = time_current; 580 600 } 581 if( i_delta < 0 )582 printf( "value %lld, previous %lld, delta %lld \n",601 if( i_delta <= 0 ) 602 printf( "value %lld, previous %lld, delta %lld, bytes %u, ", 583 603 (long long int)p_stream->pid[i_pid].i_pcr, (long long int)i_prev_pcr, 584 (long long int)i_delta );604 (long long int)i_delta, i_bytes ); 585 605 else if( b_verbose ) 586 printf( "value %lld, previous %lld, delta %lld \n",606 printf( "value %lld, previous %lld, delta %lld, bytes %u, ", 587 607 (long long int)p_stream->pid[i_pid].i_pcr, (long long int)i_prev_pcr, 588 (long long int)i_delta ); 608 (long long int)i_delta, i_bytes ); 609 if( (i_delta > 0) ) 610 printf( "%lld Kbps", ((i_bytes*8)/i_delta) ); 611 else 612 printf( "-" ); 613 if( (i_delta <= 0) || b_verbose ) 614 printf( "\n" ); 615 616 i_bytes = 0; 589 617 } 590 618 } 591 619 592 620 /* Handle discontinuities if they occured, 593 621 * according to ISO/IEC 13818-1: DIS pages 20-22 */ … … 600 628 { 601 629 if( b_pcr ) 602 printf( "New PCR pid %d value %lld (previous %lld, delta %lld)\n", i_pid, 603 (long long int)p_stream->pid[i_pid].i_pcr, (long long int)i_prev_pcr, 604 (long long int)p_stream->pid[i_pid].i_pcr - (long long int)i_prev_pcr ); 630 { 631 mtime_t i_delta; 632 struct timeval tv; 633 634 i_delta = (long long int)p_stream->pid[i_pid].i_pcr - (long long int)i_prev_pcr; 635 printf( "New PCR pid %d, value %lld, previous %lld, delta %lld, bytes %u, ", 636 i_pid, 637 (long long int)p_stream->pid[i_pid].i_pcr, 638 (long long int)i_prev_pcr, 639 i_delta, 640 i_bytes ); 641 if( i_delta > 0 ) 642 printf( "%lld", (i_bytes*8)/(i_delta/1000) ); 643 printf( "\n" ); 644 645 /* Initialize the arrival time */ 646 gettimeofday( &tv, NULL ); 647 time_prev = (tv.tv_sec*1000) + (tv.tv_usec/1000); 648 i_bytes = 0; 649 } 605 650 if( b_discontinuity_seen ) 606 651 { … … 622 667 /* Read next packet */ 623 668 if( filename ) 669 { 624 670 b_ok = ReadPacket( i_fd, p_data); 671 i_bytes += 188; 672 } 625 673 #ifdef HAVE_SYS_SOCKET_H 626 674 else 675 { 627 676 b_ok = ReadPacketFromSocket( i_fd, p_data, i_mtu ); 677 i_bytes += i_mtu; 678 } 628 679 #endif 629 680 }
