diff --git a/Makefile.w32 b/Makefile.w32 index 8bb4e4a..2014423 100644 --- a/Makefile.w32 +++ b/Makefile.w32 @@ -95,16 +95,19 @@ LIB_OBJS = \ $(OBJDIR)\audio.obj \ $(OBJDIR)\bitdata.obj \ $(OBJDIR)\es.obj \ + $(OBJDIR)\ethernet.obj \ $(OBJDIR)\filter.obj \ $(OBJDIR)\fmtx.obj \ $(OBJDIR)\h222.obj \ $(OBJDIR)\h262.obj \ + $(OBJDIR)\ipv4.obj \ $(OBJDIR)\l2audio.obj \ $(OBJDIR)\misc.obj \ $(OBJDIR)\nalunit.obj \ - $(OBJDIR)\ps.obj \ + $(OBJDIR)\pcap.obj \ $(OBJDIR)\pes.obj \ $(OBJDIR)\pidint.obj \ + $(OBJDIR)\ps.obj \ $(OBJDIR)\reverse.obj \ $(OBJDIR)\ts.obj \ $(OBJDIR)\tswrite.obj @@ -118,7 +121,7 @@ PROG_OBJS = \ $(OBJDIR)/esreport.obj \ $(OBJDIR)/esreverse.obj \ $(OBJDIR)/m2ts2ts.obj \ - $(OBJDIR)/pcapreport.obj \ + $(OBJDIR)/pcapreport.obj \ $(OBJDIR)/ps2ts.obj \ $(OBJDIR)/psdots.obj \ $(OBJDIR)/psreport.obj \ @@ -169,6 +172,9 @@ $(EXEDIR)\m2ts2ts.exe: $(OBJDIR)\m2ts2ts.obj $(LIBFILE) $(EXEDIR)\stream_type.exe: $(OBJDIR)\stream_type.obj $(LIBFILE) link /out:$@ $(LOPT) $** wsock32.lib +$(EXEDIR)\pcapreport.exe: $(OBJDIR)\pcapreport.obj $(LIBFILE) + link /out:$@ $(LOPT) $** wsock32.lib + $(EXEDIR)\psreport.exe: $(OBJDIR)\psreport.obj $(LIBFILE) link /out:$@ $(LOPT) $** wsock32.lib diff --git a/compat.h b/compat.h index c24d523..7f5d02a 100644 --- a/compat.h +++ b/compat.h @@ -39,17 +39,21 @@ // Kill deprecation warnings #pragma warning( 4: 4996 ) +#include + // Windows doesn't seem to supply , so we shall have to try // for values we hope work -typedef unsigned char byte; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long uint32_t; -typedef unsigned __int64 uint64_t; +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; -typedef short int16_t; -typedef long int32_t; -typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +typedef uint8_t byte; // On BSD, lseek takes a 64-bit off_t value // On Linux, if the system supports long files, it does the same @@ -94,6 +98,7 @@ typedef __int64 offset_t; // Other than on Windows, using the C99 integer definitions is what people // expect, so do so #include +#include // Keep "byte" for historical/affectionate reasons typedef uint8_t byte; diff --git a/esdots.c b/esdots.c index 9c02082..993c9fc 100644 --- a/esdots.c +++ b/esdots.c @@ -390,6 +390,20 @@ static int dots_by_access_unit(ES_p es, int show_gop_time) { + int err = 0; + int access_unit_count = 0; + access_unit_context_p context; + + int gop_start_found = FALSE; + int k_frame = 0; + int size_gop; + int size_gop_max = 0; + int size_gop_min = 100000; + int gops = 0; + int size_gop_tot = 0; + int is_first_k_frame = TRUE; + char char_nal_type = 'a'; + if (verbose) printf("\n" "Each character represents a single access unit\n" @@ -408,20 +422,6 @@ static int dots_by_access_unit(ES_p es, " # means an EOS (end-of-stream) NAL unit.\n" "\n"); - int err = 0; - int access_unit_count = 0; - access_unit_context_p context; - - int gop_start_found = FALSE; - int k_frame = 0; - int size_gop; - int size_gop_max = 0; - int size_gop_min = 100000; - int gops = 0; - int size_gop_tot = 0; - int is_first_k_frame = TRUE; - char char_nal_type = 'a'; - err = build_access_unit_context(es,&context); if (err) return err; diff --git a/ethernet.h b/ethernet.h index 70544a3..b9bcfe7 100644 --- a/ethernet.h +++ b/ethernet.h @@ -32,7 +32,7 @@ #include #include -#include +#include "compat.h" #include "pcap.h" diff --git a/ipv4.h b/ipv4.h index e89a1ad..1f158b6 100644 --- a/ipv4.h +++ b/ipv4.h @@ -30,7 +30,7 @@ #ifndef _ipv4_h #define _ipv4_h -#include +#include "compat.h" /*! This is all held in host byte order (including the * IP addresses! You have been warned .. ) diff --git a/m2ts2ts.c b/m2ts2ts.c index f4285dc..af6bd63 100644 --- a/m2ts2ts.c +++ b/m2ts2ts.c @@ -210,7 +210,7 @@ static int extract_packets(int input, FILE * output, (unsigned int)(packet_buffer->next)); reorder_buffer_entries++; - if (reorder_buffer_entries > reorder_buffer_size) + if (reorder_buffer_entries > (int)reorder_buffer_size) { // Write out the head of the reorder buffer printf("### queue head @ 0x%08x, next=0x%08x\n", diff --git a/misc_fns.h b/misc_fns.h index bce9f06..285ee56 100644 --- a/misc_fns.h +++ b/misc_fns.h @@ -30,9 +30,12 @@ #include "misc_defns.h" #include "es_defns.h" +#ifndef _WIN32 #include +#endif #ifdef _WIN32 +#include "compat.h" #include #endif // _WIN32 diff --git a/pcap.h b/pcap.h index 797554d..1fd49d1 100644 --- a/pcap.h +++ b/pcap.h @@ -34,8 +34,7 @@ #include #include -#include - +#include "compat.h" //! Out of memory. #define PCAP_ERR_OUT_OF_MEMORY (-8) diff --git a/ts_packet_insert.c b/ts_packet_insert.c index b5f9a72..7fa41dd 100644 --- a/ts_packet_insert.c +++ b/ts_packet_insert.c @@ -24,13 +24,12 @@ * ***** END LICENSE BLOCK ***** */ +#include "compat.h" #include #include #include #include #include -#include -#include #include #define TS_PACKET_SIZE 188 @@ -43,6 +42,8 @@ static uint8_t *create_out_packet(char *in_data,int in_len,uint16_t pid) { uint8_t *out_packet = malloc(TS_PACKET_SIZE); uint8_t *ptr = out_packet; + uint16_t flags; + uint16_t flags_pid; if (!ptr) return NULL; @@ -53,7 +54,7 @@ static uint8_t *create_out_packet(char *in_data,int in_len,uint16_t pid) ptr++; /* Transport Error Indicator */ - uint16_t flags = 0<<15; + flags = 0<<15; /* Payload Unit Start Indicator */ flags = flags | 0<<14; @@ -61,7 +62,7 @@ static uint8_t *create_out_packet(char *in_data,int in_len,uint16_t pid) /* Transport Priority */ flags = flags | 0<<13; - uint16_t flags_pid = flags | pid; + flags_pid = flags | pid; TO_BE16(flags_pid,ptr); ptr+=2; @@ -76,16 +77,18 @@ static uint8_t *create_out_packet(char *in_data,int in_len,uint16_t pid) assert((ptr-TS_PACKET_SIZE) == out_packet); - int i; - ptr = out_packet; - DBG_INFO(("Packet to be written is:\n")); - for (i=0;i 0 && count >= (uint32_t)max) { printf("Stopping after %d packets (PMT was at %d)\n",max,pmt_at); @@ -352,26 +355,41 @@ static int report_buffering_stats(TS_reader_p tsreader, index = pid_index(stats,num_streams,pid); -//lorenzo - start - if (continuity_cnt_pid == pid) + if (index != -1) { - continuity_counter = (int)(packet[3] & 0xF); - if (continuity_counter == 15) - fprintf(file_cnt, "%d \n", continuity_counter); - else - fprintf(file_cnt, "%d ", continuity_counter); - - if (prev_continuity_counter != 16 ) + // Do continuity counter checking + int cc = packet[3] & 15; + if (stats[index].last_cc > 0) { - if ( ((prev_continuity_counter+1)%16) != continuity_counter ) + // We are allowed 1 dup packet + // *** Could check that it actually is a dup... + if (stats[index].last_cc == cc) { - printf("- Discontinuity in continuity_counter at " OFFSET_T_FORMAT "\n",posn); - fprintf(file_cnt, " [Discontinuity] "); + if (stats[index].cc_dup_count++ != 0) + { + if (stats[index].err_cc_dup_error++ == 0) + { + printf("### PID(%d): Continuity Counter >1 duplicate %d at " OFFSET_T_FORMAT "\n", + stats[index].pid, cc, posn); + } + } + } + else + { + // Otherwise CC must go up by 1 mod 16 + stats[index].cc_dup_count = 0; + if (((stats[index].last_cc + 1) & 15) != cc) + { + if (stats[index].err_cc_error++ == 0) + { + printf("### PID(%d): Continuity Counter discontinuity %d->%d at " OFFSET_T_FORMAT "\n", + stats[index].pid, stats[index].last_cc, cc, posn); + } + } } } - prev_continuity_counter = continuity_counter; + stats[index].last_cc = cc; } -//lorenzo - end if (index != -1 && payload && payload_unit_start_indicator) { @@ -616,6 +634,10 @@ static int report_buffering_stats(TS_reader_p tsreader, fmtx_timestamp(stats[ii].first_dts, tfmt_abs), fmtx_timestamp(stats[ii].dts, tfmt_abs)); + if (stats[ii].err_cc_error != 0) + printf(" ### CC error * %d\n", stats[ii].err_cc_error); + if (stats[ii].err_cc_dup_error != 0) + printf(" ### CC duplicate error * %d\n", stats[ii].err_cc_dup_error); if (stats[ii].err_pts_lt_dts != 0) printf(" ### PTS < DTS * %d\n", stats[ii].err_pts_lt_dts); if (stats[ii].err_dts_lt_prev_dts != 0)