kopia lustrzana https://github.com/F5OEO/tstools
Added program number checking to PMT selection in case there are multiple PMTs on the same PID (or indeed other garbage)
--HG-- extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%4099issue20
rodzic
07dc395b13
commit
307d5475ae
|
@ -181,9 +181,6 @@ $(EXEDIR)\psreport.exe: $(OBJDIR)\psreport.obj $(LIBFILE)
|
|||
$(EXEDIR)\ps2ts.exe: $(OBJDIR)\ps2ts.obj $(LIBFILE)
|
||||
link /out:$@ $(LOPT) $** wsock32.lib
|
||||
|
||||
$(EXEDIR)\pcapreport.exe: $(OBJDIR)\pcapreport.obj $(LIBFILE)
|
||||
link /out:$@ $(LOPT) $** wsock32.lib
|
||||
|
||||
$(EXEDIR)\psdots.exe: $(OBJDIR)\psdots.obj $(LIBFILE)
|
||||
link /out:$@ $(LOPT) $** wsock32.lib
|
||||
|
||||
|
|
2
pes.c
2
pes.c
|
@ -968,7 +968,7 @@ static int find_first_PMT(PES_reader_p reader)
|
|||
|
||||
for (;;)
|
||||
{
|
||||
err = find_next_pmt(reader->tsreader,reader->pmt_pid,0,
|
||||
err = find_next_pmt(reader->tsreader,reader->pmt_pid,-1,0,
|
||||
FALSE,!reader->give_info,&nread,&pmt);
|
||||
if (err)
|
||||
{
|
||||
|
|
57
ts.c
57
ts.c
|
@ -3203,12 +3203,13 @@ extern int find_pat(TS_reader_p tsreader,
|
|||
* 1 if something else went wrong.
|
||||
*/
|
||||
extern int find_next_pmt(TS_reader_p tsreader,
|
||||
uint32_t pmt_pid,
|
||||
int max,
|
||||
int verbose,
|
||||
int quiet,
|
||||
int *num_read,
|
||||
pmt_p *pmt)
|
||||
uint32_t pmt_pid,
|
||||
int program_number,
|
||||
int max,
|
||||
int verbose,
|
||||
int quiet,
|
||||
int *num_read,
|
||||
pmt_p *pmt)
|
||||
{
|
||||
int err;
|
||||
byte *pmt_data = NULL;
|
||||
|
@ -3283,8 +3284,29 @@ extern int find_next_pmt(TS_reader_p tsreader,
|
|||
|
||||
if (pmt_data_len == pmt_data_used)
|
||||
{
|
||||
int pmt_program_number;
|
||||
|
||||
err = extract_pmt(verbose,pmt_data,pmt_data_len,pid,pmt);
|
||||
if (pmt_data) free(pmt_data);
|
||||
pmt_program_number = *pmt == NULL ? -1 : (int)((*pmt)->program_number);
|
||||
|
||||
if (pmt_data)
|
||||
{
|
||||
free(pmt_data);
|
||||
pmt_data = NULL;
|
||||
}
|
||||
|
||||
// Check we've got the right program number - it would appear to be
|
||||
// legitimate to have multiple PMTs carried in the same PID and some
|
||||
// abuse of this appears to happen in real life
|
||||
if (err == 0 && program_number >= 0)
|
||||
{
|
||||
if (pmt_program_number != program_number)
|
||||
{
|
||||
fprintf(stderr,"!!! Discarding PMT with program number %d\n", pmt_program_number);
|
||||
free_pmt(pmt);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
@ -3326,8 +3348,8 @@ extern int find_pmt(TS_reader_p tsreader,
|
|||
{
|
||||
int err;
|
||||
pidint_list_p prog_list = NULL;
|
||||
uint32_t pmt_pid;
|
||||
int sofar;
|
||||
int prog_index = 0;
|
||||
|
||||
*pmt = NULL;
|
||||
|
||||
|
@ -3358,16 +3380,23 @@ extern int find_pmt(TS_reader_p tsreader,
|
|||
else if (prog_list->length > 1 && !quiet)
|
||||
printf("Multiple programs in PAT - using the first non-zero\n\n");
|
||||
|
||||
pmt_pid = prog_list->pid[0];
|
||||
if (prog_list->number[0] == 0 && prog_list->length > 1)
|
||||
pmt_pid = prog_list->pid[1];
|
||||
|
||||
free_pidint_list(&prog_list);
|
||||
while (prog_list->number[prog_index] == 0)
|
||||
{
|
||||
if (++prog_index >= prog_list->length)
|
||||
{
|
||||
if (!quiet)
|
||||
printf("No non-zero program_numbers in PAT (packet %d)\n",sofar);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
// Amend max to take account of the packets we've already read
|
||||
max -= sofar;
|
||||
|
||||
err = find_next_pmt(tsreader,pmt_pid,max,verbose,quiet,num_read,pmt);
|
||||
err = find_next_pmt(tsreader,prog_list->pid[prog_index],prog_list->number[prog_index],
|
||||
max,verbose,quiet,num_read,pmt);
|
||||
|
||||
free_pidint_list(&prog_list);
|
||||
|
||||
*num_read += sofar;
|
||||
|
||||
|
|
1
ts_fns.h
1
ts_fns.h
|
@ -741,6 +741,7 @@ extern int find_pat(TS_reader_p tsreader,
|
|||
*/
|
||||
extern int find_next_pmt(TS_reader_p tsreader,
|
||||
uint32_t pmt_pid,
|
||||
int program_number,
|
||||
int max,
|
||||
int verbose,int quiet,
|
||||
int *num_read,
|
||||
|
|
4
tsinfo.c
4
tsinfo.c
|
@ -297,7 +297,7 @@ static void print_usage()
|
|||
"Switches:\n"
|
||||
" -stdin Input from standard input, instead of a file\n"
|
||||
" -verbose, -v Output extra information about packets\n"
|
||||
" -max <n>, -m <n> Number of TS packets to scan. Defaults to 1000.\n"
|
||||
" -max <n>, -m <n> Number of TS packets to scan. Defaults to 10000.\n"
|
||||
" -repeat <n> Look for <n> PMT packets, and report on each\n"
|
||||
);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ int main(int argc, char **argv)
|
|||
int use_stdin = FALSE;
|
||||
char *input_name = NULL;
|
||||
int had_input_name = FALSE;
|
||||
int max = 1000;
|
||||
int max = 10000;
|
||||
int verbose = FALSE; // True => output diagnostic/progress messages
|
||||
int lookfor = 1;
|
||||
int err = 0;
|
||||
|
|
12
tsplay.c
12
tsplay.c
|
@ -196,6 +196,7 @@ static int find_PCR_PID(TS_reader_p tsreader,
|
|||
byte *pmt_data = NULL;
|
||||
int pmt_data_len = 0;
|
||||
int pmt_data_used = 0;
|
||||
int pmt_program_number = -1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
@ -282,6 +283,8 @@ static int find_PCR_PID(TS_reader_p tsreader,
|
|||
printf("Multiple programs in PAT - using the first\n\n");
|
||||
|
||||
pmt_pid = prog_list->pid[0];
|
||||
pmt_program_number = prog_list->number[0];
|
||||
|
||||
got_PAT = TRUE;
|
||||
free_pidint_list(&prog_list);
|
||||
free(pat_data);
|
||||
|
@ -326,8 +329,17 @@ static int find_PCR_PID(TS_reader_p tsreader,
|
|||
|
||||
err = extract_pmt(FALSE,pmt_data,pmt_data_len,pmt_pid,&pmt);
|
||||
free(pmt_data);
|
||||
pmt_data = NULL;
|
||||
if (err) return err;
|
||||
|
||||
if (pmt->program_number != pmt_program_number)
|
||||
{
|
||||
if (!quiet)
|
||||
printf("Discarding PMT program %d - looking for %d\n", pmt->program_number, pmt_program_number);
|
||||
free_pmt(&pmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!quiet)
|
||||
report_pmt(stdout," ",pmt);
|
||||
*pcr_pid = pmt->PCR_pid;
|
||||
|
|
Ładowanie…
Reference in New Issue