Next step in message tidying - es.c and friends.

--HG--
extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%40137
issue20
tibs 2009-05-03 16:18:16 +00:00
rodzic 574a59f25c
commit ad059b4d61
7 zmienionych plików z 205 dodań i 218 usunięć

208
es.c
Wyświetl plik

@ -82,8 +82,7 @@ extern int open_elementary_stream(char *filename,
err = build_elementary_stream_file(input,es); err = build_elementary_stream_file(input,es);
if (err) if (err)
{ {
fprintf(stderr,"### Error building elementary stream for file %s\n", fprint_err("### Error building elementary stream for file %s\n", filename);
filename);
return 1; return 1;
} }
return 0; return 0;
@ -111,8 +110,8 @@ static int setup_readahead(ES_p es)
{ {
if (es->read_ahead_len < 3) if (es->read_ahead_len < 3)
{ {
fprintf(stderr,"### File only contains %d byte%s\n", fprint_err("### File only contains %d byte%s\n",
es->read_ahead_len,(es->read_ahead_len==1?"":"s")); es->read_ahead_len,(es->read_ahead_len==1?"":"s"));
return 1; return 1;
} }
} }
@ -120,15 +119,15 @@ static int setup_readahead(ES_p es)
{ {
if (es->reader->packet->es_data_len < 3) if (es->reader->packet->es_data_len < 3)
{ {
fprintf(stderr,"### File PES packet only contains %d byte%s\n", fprint_err("### File PES packet only contains %d byte%s\n",
es->reader->packet->es_data_len, es->reader->packet->es_data_len,
(es->reader->packet->es_data_len==1?"":"s")); (es->reader->packet->es_data_len==1?"":"s"));
return 1; return 1;
} }
} }
if (DEBUG) if (DEBUG)
printf("File starts %02x %02x %02x\n",es->data[0],es->data[1],es->data[2]); fprint_msg("File starts %02x %02x %02x\n",es->data[0],es->data[1],es->data[2]);
// Despite (maybe) reporting the above, we haven't actually read anything // Despite (maybe) reporting the above, we haven't actually read anything
// yet // yet
@ -156,7 +155,7 @@ extern int build_elementary_stream_file(int input,
ES_p new = malloc(SIZEOF_ES); ES_p new = malloc(SIZEOF_ES);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate elementary stream datastructure\n"); print_err("### Unable to allocate elementary stream datastructure\n");
return 1; return 1;
} }
@ -189,7 +188,7 @@ extern int build_elementary_stream_PES(PES_reader_p reader,
ES_p new = malloc(SIZEOF_ES); ES_p new = malloc(SIZEOF_ES);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate elementary stream datastructure\n"); print_err("### Unable to allocate elementary stream datastructure\n");
return 1; return 1;
} }
@ -282,7 +281,7 @@ extern int setup_ES_unit(ES_unit_p unit)
unit->data = malloc(ES_UNIT_DATA_START_SIZE); unit->data = malloc(ES_UNIT_DATA_START_SIZE);
if (unit->data == NULL) if (unit->data == NULL)
{ {
fprintf(stderr,"### Unable to allocate ES unit data buffer\n"); print_err("### Unable to allocate ES unit data buffer\n");
return 1; return 1;
} }
unit->data_len = 0; unit->data_len = 0;
@ -321,7 +320,7 @@ extern int build_ES_unit(ES_unit_p *unit)
ES_unit_p new = malloc(SIZEOF_ES_UNIT); ES_unit_p new = malloc(SIZEOF_ES_UNIT);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate ES unit datastructure\n"); print_err("### Unable to allocate ES unit datastructure\n");
return 1; return 1;
} }
err = setup_ES_unit(new); err = setup_ES_unit(new);
@ -349,13 +348,13 @@ extern int build_ES_unit_from_data(ES_unit_p *unit,
ES_unit_p new = malloc(SIZEOF_ES_UNIT); ES_unit_p new = malloc(SIZEOF_ES_UNIT);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate ES unit datastructure\n"); print_err("### Unable to allocate ES unit datastructure\n");
return 1; return 1;
} }
new->data = malloc(data_len); new->data = malloc(data_len);
if (new->data == NULL) if (new->data == NULL)
{ {
fprintf(stderr,"### Unable to allocate ES unit data buffer\n"); print_err("### Unable to allocate ES unit data buffer\n");
return 1; return 1;
} }
(void) memcpy(new->data, data, data_len); (void) memcpy(new->data, data, data_len);
@ -386,16 +385,17 @@ extern void free_ES_unit(ES_unit_p *unit)
} }
/* /*
* Print out some information this ES unit, on the given stream * Print out some information this ES unit, on normal or error output
*/ */
extern void report_ES_unit(FILE *stream, extern void report_ES_unit(int is_msg,
ES_unit_p unit) ES_unit_p unit)
{ {
byte s = unit->start_code; byte s = unit->start_code;
fprintf(stream,OFFSET_T_FORMAT_08 "/%4d: ES unit (%02x '%d%d%d%d %d%d%d%d')", fprint_msg_or_err(is_msg,
unit->start_posn.infile,unit->start_posn.inpacket,s, OFFSET_T_FORMAT_08 "/%4d: ES unit (%02x '%d%d%d%d %d%d%d%d')",
(s&0x80)>>7,(s&0x40)>>6,(s&0x20)>>5,(s&0x10)>>4, unit->start_posn.infile,unit->start_posn.inpacket,s,
(s&0x08)>>3,(s&0x04)>>2,(s&0x02)>>1,(s&0x01)); (s&0x80)>>7,(s&0x40)>>6,(s&0x20)>>5,(s&0x10)>>4,
(s&0x08)>>3,(s&0x04)>>2,(s&0x02)>>1,(s&0x01));
// Show the data bytes - but we don't need to show the first 4, // Show the data bytes - but we don't need to show the first 4,
// since we know they're 00 00 01 <start-code> // since we know they're 00 00 01 <start-code>
@ -404,13 +404,13 @@ extern void report_ES_unit(FILE *stream,
int ii; int ii;
int data_len = unit->data_len - 4; int data_len = unit->data_len - 4;
int show_len = (data_len>10?10:data_len); int show_len = (data_len>10?10:data_len);
fprintf(stream," %6d:",data_len); fprint_msg_or_err(is_msg," %6d:",data_len);
for (ii = 0; ii < show_len; ii++) for (ii = 0; ii < show_len; ii++)
fprintf(stream," %02x",unit->data[4+ii]); fprint_msg_or_err(is_msg," %02x",unit->data[4+ii]);
if (show_len < data_len) if (show_len < data_len)
fprintf(stream,"..."); fprint_msg_or_err(is_msg,"...");
} }
fprintf(stream,"\n"); fprint_msg_or_err(is_msg,"\n");
} }
// ------------------------------------------------------------ // ------------------------------------------------------------
@ -477,7 +477,7 @@ static inline int get_more_data(ES_p es)
return EOF; return EOF;
else if (len == -1) else if (len == -1)
{ {
fprintf(stderr,"### Error reading next bytes: %s\n",strerror(errno)); fprint_err("### Error reading next bytes: %s\n",strerror(errno));
return 1; return 1;
} }
es->read_ahead_posn += es->read_ahead_len; // length of the *last* buffer es->read_ahead_posn += es->read_ahead_len; // length of the *last* buffer
@ -627,7 +627,7 @@ static int find_ES_unit_end(ES_p es,
unit->data = realloc(unit->data,newsize); unit->data = realloc(unit->data,newsize);
if (unit->data == NULL) if (unit->data == NULL)
{ {
fprintf(stderr,"### Unable to extend ES unit data array\n"); print_err("### Unable to extend ES unit data array\n");
return 1; return 1;
} }
unit->data_size = newsize; unit->data_size = newsize;
@ -754,9 +754,9 @@ extern int write_ES_unit(FILE *output,
size_t written = fwrite(unit->data,1,unit->data_len,output); size_t written = fwrite(unit->data,1,unit->data_len,output);
if (written != unit->data_len) if (written != unit->data_len)
{ {
fprintf(stderr,"### Error writing out ES unit data: %s\n" fprint_err("### Error writing out ES unit data: %s\n"
" Wrote %ld bytes instead of %d\n", " Wrote %ld bytes instead of %d\n",
strerror(errno),(long int)written,unit->data_len); strerror(errno),(long int)written,unit->data_len);
return 1; return 1;
} }
else else
@ -782,8 +782,8 @@ static int seek_in_PES(ES_p es,
if (es->reader == NULL) if (es->reader == NULL)
{ {
fprintf(stderr,"### Attempt to seek in PES for an ES reader that" print_err("### Attempt to seek in PES for an ES reader that"
" is not attached to a PES reader\n"); " is not attached to a PES reader\n");
return 1; return 1;
} }
@ -795,25 +795,25 @@ static int seek_in_PES(ES_p es,
err = set_PES_reader_position(es->reader,where.infile); err = set_PES_reader_position(es->reader,where.infile);
if (err) if (err)
{ {
fprintf(stderr,"### Error seeking for PES packet at " OFFSET_T_FORMAT fprint_err("### Error seeking for PES packet at " OFFSET_T_FORMAT
"\n",where.infile); "\n",where.infile);
return 1; return 1;
} }
// Read the PES packet containing ES (ignoring packets we don't care about) // Read the PES packet containing ES (ignoring packets we don't care about)
err = get_next_pes_packet(es); err = get_next_pes_packet(es);
if (err) if (err)
{ {
fprintf(stderr,"### Error reading PES packet at " OFFSET_T_FORMAT "/%d\n", fprint_err("### Error reading PES packet at " OFFSET_T_FORMAT "/%d\n",
where.infile,where.inpacket); where.infile,where.inpacket);
return 1; return 1;
} }
// Now sort out the byte offset // Now sort out the byte offset
if (where.inpacket > es->reader->packet->es_data_len) if (where.inpacket > es->reader->packet->es_data_len)
{ {
fprintf(stderr,"### Error seeking PES packet at " OFFSET_T_FORMAT "/%d: " fprint_err("### Error seeking PES packet at " OFFSET_T_FORMAT "/%d: "
" packet ES data is only %d bytes long\n",where.infile, " packet ES data is only %d bytes long\n",where.infile,
where.inpacket,es->reader->packet->es_data_len); where.inpacket,es->reader->packet->es_data_len);
return 1; return 1;
} }
es->posn_of_next_byte = where; es->posn_of_next_byte = where;
@ -878,9 +878,8 @@ extern int seek_ES(ES_p es,
err = seek_in_PES(es,where); err = seek_in_PES(es,where);
if (err) if (err)
{ {
fprintf(stderr, fprint_err("### Error seeking within ES over PES (offset " OFFSET_T_FORMAT
"### Error seeking within ES over PES (offset " OFFSET_T_FORMAT "/%d)\n",where.infile,where.inpacket);
"/%d)\n",where.infile,where.inpacket);
return 1; return 1;
} }
} }
@ -977,7 +976,7 @@ extern int read_ES_data(ES_p es,
*data = realloc(*data,num_bytes); *data = realloc(*data,num_bytes);
if (*data == NULL) if (*data == NULL)
{ {
fprintf(stderr,"### Unable to reallocate data space\n"); print_err("### Unable to reallocate data space\n");
return 1; return 1;
} }
if (data_len != NULL) if (data_len != NULL)
@ -992,7 +991,7 @@ extern int read_ES_data(ES_p es,
{ {
if (err == EOF) if (err == EOF)
{ {
fprintf(stderr,"### Error (EOF) reading %d bytes\n",num_bytes); fprint_err("### Error (EOF) reading %d bytes\n",num_bytes);
return 1; return 1;
} }
else else
@ -1005,7 +1004,7 @@ extern int read_ES_data(ES_p es,
err = read_bytes_from_PES(es,*data,num_bytes); err = read_bytes_from_PES(es,*data,num_bytes);
if (err) if (err)
{ {
fprintf(stderr,"### Error reading %d bytes from PES\n",num_bytes); fprint_err("### Error reading %d bytes from PES\n",num_bytes);
return 1; return 1;
} }
} }
@ -1044,8 +1043,8 @@ extern int get_end_of_underlying_PES_packet(ES_p es,
if (es->reading_ES) if (es->reading_ES)
{ {
fprintf(stderr,"### Cannot retrieve end of PES packet - the ES data" fprint_err("### Cannot retrieve end of PES packet - the ES data"
" is direct ES, not ES read from PES\n"); " is direct ES, not ES read from PES\n");
return 1; return 1;
} }
if (es->reader->packet == NULL) if (es->reader->packet == NULL)
@ -1092,7 +1091,7 @@ extern int get_end_of_underlying_PES_packet(ES_p es,
*data = malloc(*data_len); *data = malloc(*data_len);
if (*data == NULL) if (*data == NULL)
{ {
fprintf(stderr,"### Cannot allocate space for rest of PES packet\n"); print_err("### Cannot allocate space for rest of PES packet\n");
return 1; return 1;
} }
(*data)[0] = es->prev2_byte; // Hmm - should be 0x00 (*data)[0] = es->prev2_byte; // Hmm - should be 0x00
@ -1118,7 +1117,7 @@ extern int build_ES_unit_list(ES_unit_list_p *list)
ES_unit_list_p new = malloc(SIZEOF_ES_UNIT_LIST); ES_unit_list_p new = malloc(SIZEOF_ES_UNIT_LIST);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate ES unit list datastructure\n"); print_err("### Unable to allocate ES unit list datastructure\n");
return 1; return 1;
} }
@ -1128,8 +1127,7 @@ extern int build_ES_unit_list(ES_unit_list_p *list)
if (new->array == NULL) if (new->array == NULL)
{ {
free(new); free(new);
fprintf(stderr, print_err("### Unable to allocate array in ES unit list datastructure\n");
"### Unable to allocate array in ES unit list datastructure\n");
return 1; return 1;
} }
*list = new; *list = new;
@ -1154,7 +1152,7 @@ extern int append_to_ES_unit_list(ES_unit_list_p list,
list->array = realloc(list->array,newsize*SIZEOF_ES_UNIT); list->array = realloc(list->array,newsize*SIZEOF_ES_UNIT);
if (list->array == NULL) if (list->array == NULL)
{ {
fprintf(stderr,"### Unable to extend ES unit list array\n"); print_err("### Unable to extend ES unit list array\n");
return 1; return 1;
} }
list->size = newsize; list->size = newsize;
@ -1166,7 +1164,7 @@ extern int append_to_ES_unit_list(ES_unit_list_p list,
ptr->data = malloc(unit->data_len); ptr->data = malloc(unit->data_len);
if (ptr->data == NULL) if (ptr->data == NULL)
{ {
fprintf(stderr,"### Unable to copy ES unit data array\n"); print_err("### Unable to copy ES unit data array\n");
return 1; return 1;
} }
memcpy(ptr->data,unit->data,unit->data_len); memcpy(ptr->data,unit->data,unit->data_len);
@ -1247,7 +1245,7 @@ extern void report_ES_unit_list(char *name,
for (ii=0; ii<list->length; ii++) for (ii=0; ii<list->length; ii++)
{ {
print_msg(" "); print_msg(" ");
report_ES_unit(stdout,&(list->array[ii])); report_ES_unit(TRUE,&(list->array[ii]));
} }
} }
} }
@ -1269,8 +1267,7 @@ extern int get_ES_unit_list_bounds(ES_unit_list_p list,
int ii; int ii;
if (list->array == NULL || list->length == 0) if (list->array == NULL || list->length == 0)
{ {
fprintf(stderr, print_err("### Cannot determine bounds of an ES unit list with no content\n");
"### Cannot determine bounds of an ES unit list with no content\n");
return 1; return 1;
} }
@ -1362,7 +1359,7 @@ static int try_to_guess_video_type(ES_unit_p unit,
byte nal_unit_type = 0; byte nal_unit_type = 0;
if (show_reasoning) if (show_reasoning)
printf("Looking at ES unit with start code %02X\n",unit->start_code); fprint_msg("Looking at ES unit with start code %02X\n",unit->start_code);
// The following are *not allowed* // The following are *not allowed*
// //
@ -1372,19 +1369,17 @@ static int try_to_guess_video_type(ES_unit_p unit,
if (unit->start_code == 0xBA) // PS pack header if (unit->start_code == 0xBA) // PS pack header
{ {
fprintf(stderr, print_err("### ES unit start code is 0xBA, which looks like a PS pack"
"### ES unit start code is 0xBA, which looks like a PS pack" " header\n i.e., data may be PS\n");
" header\n i.e., data may be PS\n");
return 1; return 1;
} }
if (unit->start_code >= 0xB9) // system start code - probably PES if (unit->start_code >= 0xB9) // system start code - probably PES
{ {
fprintf(stderr, fprint_err("### ES unit start code %02X is more than 0xB9, which is probably"
"### ES unit start code %02X is more than 0xB9, which is probably" " a PES system start code\n i.e., data may be PES, "
" a PES system start code\n i.e., data may be PES, " "and is thus probably PS or TS\n",
"and is thus probably PS or TS\n", unit->start_code);
unit->start_code);
return 1; return 1;
} }
@ -1392,7 +1387,7 @@ static int try_to_guess_video_type(ES_unit_p unit,
{ {
if (*maybe_h264) if (*maybe_h264)
{ {
if (show_reasoning) printf(" %02X has top bit set, so not H.264,\n",unit->start_code); if (show_reasoning) fprint_msg(" %02X has top bit set, so not H.264,\n",unit->start_code);
*maybe_h264 = FALSE; *maybe_h264 = FALSE;
} }
@ -1402,43 +1397,43 @@ static int try_to_guess_video_type(ES_unit_p unit,
{ {
*maybe_h262 = FALSE; *maybe_h262 = FALSE;
if (show_reasoning) if (show_reasoning)
printf(" Start code %02X is reserved in H.262, so not H.262\n", fprint_msg(" Start code %02X is reserved in H.262, so not H.262\n",
unit->start_code); unit->start_code);
} }
else if (unit->start_code == 0xB4 || else if (unit->start_code == 0xB4 ||
unit->start_code == 0xB8) unit->start_code == 0xB8)
{ {
*maybe_avs = FALSE; *maybe_avs = FALSE;
if (show_reasoning) if (show_reasoning)
printf(" Start code %02X is reserved in AVS, so not AVS\n", fprint_msg(" Start code %02X is reserved in AVS, so not AVS\n",
unit->start_code); unit->start_code);
} }
} }
else if (*maybe_h264) else if (*maybe_h264)
{ {
if (show_reasoning) if (show_reasoning)
printf(" Top bit not set, so might be H.264\n"); print_msg(" Top bit not set, so might be H.264\n");
// If we don't have that top bit set, then we need to work a bit harder // If we don't have that top bit set, then we need to work a bit harder
nal_ref_idc = (unit->start_code & 0x60) >> 5; nal_ref_idc = (unit->start_code & 0x60) >> 5;
nal_unit_type = (unit->start_code & 0x1F); nal_unit_type = (unit->start_code & 0x1F);
if (show_reasoning) if (show_reasoning)
printf(" Interpreting it as nal_ref_idc %d, nal_unit_type %d\n", fprint_msg(" Interpreting it as nal_ref_idc %d, nal_unit_type %d\n",
nal_ref_idc,nal_unit_type); nal_ref_idc,nal_unit_type);
if (nal_unit_type > 12 && nal_unit_type < 24) if (nal_unit_type > 12 && nal_unit_type < 24)
{ {
if (show_reasoning) if (show_reasoning)
printf(" H.264 reserves nal_unit_type %02X," fprint_msg(" H.264 reserves nal_unit_type %02X,"
" so not H.264\n",nal_unit_type); " so not H.264\n",nal_unit_type);
*maybe_h264 = FALSE; *maybe_h264 = FALSE;
} }
else if (nal_unit_type > 23) else if (nal_unit_type > 23)
{ {
if (show_reasoning) if (show_reasoning)
printf(" H.264 does not specify nal_unit_type %02X," fprint_msg(" H.264 does not specify nal_unit_type %02X,"
" so not H.264\n",nal_unit_type); " so not H.264\n",nal_unit_type);
*maybe_h264 = FALSE; *maybe_h264 = FALSE;
} }
else if (nal_ref_idc == 0) else if (nal_ref_idc == 0)
@ -1448,8 +1443,8 @@ static int try_to_guess_video_type(ES_unit_p unit,
nal_unit_type == 8) // picture parameter set nal_unit_type == 8) // picture parameter set
{ {
if (show_reasoning) if (show_reasoning)
printf(" H.264 does not allow nal_ref_idc 0 and nal_unit_type %d," fprint_msg(" H.264 does not allow nal_ref_idc 0 and nal_unit_type %d,"
" so not H.264\n",nal_unit_type); " so not H.264\n",nal_unit_type);
*maybe_h264 = FALSE; *maybe_h264 = FALSE;
} }
} }
@ -1463,8 +1458,8 @@ static int try_to_guess_video_type(ES_unit_p unit,
nal_unit_type == 12) // fille nal_unit_type == 12) // fille
{ {
if (show_reasoning) if (show_reasoning)
printf(" H.264 insists nal_ref_idc shall be 0 for nal_unit_type %d," fprint_msg(" H.264 insists nal_ref_idc shall be 0 for nal_unit_type %d,"
" so not H.264\n",nal_unit_type); " so not H.264\n",nal_unit_type);
*maybe_h264 = FALSE; *maybe_h264 = FALSE;
} }
} }
@ -1507,8 +1502,8 @@ extern int decide_ES_video_type(ES_p es,
err = setup_ES_unit(&unit); err = setup_ES_unit(&unit);
if (err) if (err)
{ {
fprintf(stderr,"### Error trying to setup ES unit before" print_err("### Error trying to setup ES unit before"
" working out video type\n"); " working out video type\n");
return 1; return 1;
} }
@ -1523,30 +1518,29 @@ extern int decide_ES_video_type(ES_p es,
// *very* sure it is not H.262 or AVS. And if the only other choice is H.264, // *very* sure it is not H.262 or AVS. And if the only other choice is H.264,
// then... // then...
if (show_reasoning) if (show_reasoning)
printf("Looking through first 500 ES units to try to decide video type\n"); print_msg("Looking through first 500 ES units to try to decide video type\n");
for (ii=0; ii<500; ii++) for (ii=0; ii<500; ii++)
{ {
if (print_dots) if (print_dots)
{ {
printf("."); print_msg(".");
fflush(stdout); fflush(stdout);
} }
else if (show_reasoning) else if (show_reasoning)
printf("%d: ",ii+1); fprint_msg("%d: ",ii+1);
err = find_next_ES_unit(es,&unit); err = find_next_ES_unit(es,&unit);
if (err == EOF) if (err == EOF)
{ {
if (print_dots) printf("\n"); if (print_dots) print_msg("\n");
if (show_reasoning) printf("End of file, trying to read ES unit %d\n",ii+2); if (show_reasoning) fprint_msg("End of file, trying to read ES unit %d\n",ii+2);
break; break;
} }
else if (err) else if (err)
{ {
if (print_dots) printf("\n"); if (print_dots) print_msg("\n");
fprintf(stderr, fprint_err("### Error trying to find 'unit' %d in ES whilst"
"### Error trying to find 'unit' %d in ES whilst" " working out video type\n",ii+2);
" working out video type\n",ii+2);
clear_ES_unit(&unit); clear_ES_unit(&unit);
return 1; return 1;
} }
@ -1554,40 +1548,39 @@ extern int decide_ES_video_type(ES_p es,
&maybe_h264,&maybe_h262,&maybe_avs); &maybe_h264,&maybe_h262,&maybe_avs);
if (err) if (err)
{ {
if (print_dots) printf("\n"); if (print_dots) print_msg("\n");
fprintf(stderr, print_err("### Whilst trying to work out video_type\n");
"### Whilst trying to work out video_type\n");
clear_ES_unit(&unit); clear_ES_unit(&unit);
return 1; return 1;
} }
if (maybe_h264 && !maybe_h262 && !maybe_avs) if (maybe_h264 && !maybe_h262 && !maybe_avs)
{ {
if (show_reasoning) printf(" Which leaves only H.264\n"); if (show_reasoning) print_msg(" Which leaves only H.264\n");
*video_type = VIDEO_H264; *video_type = VIDEO_H264;
decided = TRUE; decided = TRUE;
} }
else if (!maybe_h264 && maybe_h262 && !maybe_avs) else if (!maybe_h264 && maybe_h262 && !maybe_avs)
{ {
if (show_reasoning) printf(" Which leaves only H.262\n"); if (show_reasoning) print_msg(" Which leaves only H.262\n");
*video_type = VIDEO_H262; *video_type = VIDEO_H262;
decided = TRUE; decided = TRUE;
} }
else if (!maybe_h264 && !maybe_h262 && maybe_avs) else if (!maybe_h264 && !maybe_h262 && maybe_avs)
{ {
if (show_reasoning) printf(" Which leaves only AVS\n"); if (show_reasoning) print_msg(" Which leaves only AVS\n");
*video_type = VIDEO_AVS; *video_type = VIDEO_AVS;
decided = TRUE; decided = TRUE;
} }
else else
{ {
if (show_reasoning) if (show_reasoning)
printf(" It is not possible to decide from that start code\n"); print_msg(" It is not possible to decide from that start code\n");
} }
if (decided) if (decided)
break; break;
} }
if (print_dots) printf("\n"); if (print_dots) print_msg("\n");
clear_ES_unit(&unit); clear_ES_unit(&unit);
return 0; return 0;
} }
@ -1623,31 +1616,30 @@ extern int decide_ES_file_video_type(int input,
start_posn = tell_file(input); start_posn = tell_file(input);
if (start_posn == -1) if (start_posn == -1)
{ {
fprintf(stderr,"### Error remembering start position in file before" print_err("### Error remembering start position in file before"
" working out video type\n"); " working out video type\n");
return 1; return 1;
} }
err = seek_file(input,0); err = seek_file(input,0);
if (err) if (err)
{ {
fprintf(stderr,"### Error rewinding file before" print_err("### Error rewinding file before working out video type\n");
" working out video type\n");
return 1; return 1;
} }
err = build_elementary_stream_file(input,&es); err = build_elementary_stream_file(input,&es);
if (err) if (err)
{ {
fprintf(stderr,"### Error starting elementary stream before" print_err("### Error starting elementary stream before"
" working out video type\n"); " working out video type\n");
return 1; return 1;
} }
err = decide_ES_video_type(es,print_dots,show_reasoning,video_type); err = decide_ES_video_type(es,print_dots,show_reasoning,video_type);
if (err) if (err)
{ {
fprintf(stderr,"### Error deciding video type of file\n"); print_err("### Error deciding video type of file\n");
free_elementary_stream(&es); free_elementary_stream(&es);
return 1; return 1;
} }
@ -1657,8 +1649,8 @@ extern int decide_ES_file_video_type(int input,
err = seek_file(input,start_posn); err = seek_file(input,start_posn);
if (err) if (err)
{ {
fprintf(stderr,"### Error returning to start position in file after" print_err("### Error returning to start position in file after"
" working out video type\n"); " working out video type\n");
return 1; return 1;
} }
return 0; return 0;

Wyświetl plik

@ -105,7 +105,7 @@ static int transfer_data(ES_p es,
count++; count++;
if (verbose) if (verbose)
report_ES_unit(stderr,unit); report_ES_unit(FALSE,unit);
err = write_ES_unit_as_TS(output,unit,video_pid); err = write_ES_unit_as_TS(output,unit,video_pid);
if (err) if (err)

Wyświetl plik

@ -176,9 +176,9 @@ extern int build_ES_unit_from_data(ES_unit_p *unit,
extern void free_ES_unit(ES_unit_p *unit); extern void free_ES_unit(ES_unit_p *unit);
/* /*
* Print out some information this ES unit, on the given stream * Print out some information this ES unit, on normal or error output
*/ */
extern void report_ES_unit(FILE *stream, extern void report_ES_unit(int is_msg,
ES_unit_p unit); ES_unit_p unit);
/* /*

Wyświetl plik

@ -247,7 +247,7 @@ static void report_ES_units(ES_p es,
count++; count++;
if (!quiet) if (!quiet)
report_ES_unit(stdout,&unit); report_ES_unit(TRUE,&unit);
if (verbose) if (verbose)
print_data(TRUE," Data", print_data(TRUE," Data",

200
h262.c
Wyświetl plik

@ -44,7 +44,7 @@
/* /*
* Print out information derived from the start code, to the given stream. * Print out information derived from the start code
* *
* Note that if a "SYSTEM START" code is reported, then the data is * Note that if a "SYSTEM START" code is reported, then the data is
* likely to be PES or Transport Stream data, not Elementary Stream. * likely to be PES or Transport Stream data, not Elementary Stream.
@ -56,8 +56,7 @@
* that some of the apparent start code prefixes are actually false * that some of the apparent start code prefixes are actually false
* detections. * detections.
*/ */
extern void print_h262_start_code_str(FILE *stream, extern void print_h262_start_code_str(byte start_code)
byte start_code)
{ {
byte number; byte number;
char *str = NULL; char *str = NULL;
@ -98,25 +97,25 @@ extern void print_h262_start_code_str(FILE *stream,
} }
if (str != NULL) if (str != NULL)
fprintf(stream,str); print_msg(str);
else if (start_code == 0x47) else if (start_code == 0x47)
fprintf(stream,"TRANSPORT STREAM sync byte"); print_msg("TRANSPORT STREAM sync byte");
else if (start_code >= 0x01 && start_code <= 0xAF) else if (start_code >= 0x01 && start_code <= 0xAF)
fprintf(stream,"Slice, vertical posn %d",start_code); fprint_msg("Slice, vertical posn %d",start_code);
else if (start_code >= 0xC0 && start_code <=0xDF) else if (start_code >= 0xC0 && start_code <=0xDF)
{ {
number = start_code & 0x1F; number = start_code & 0x1F;
fprintf(stream,"SYSTEM START: Audio stream %02x",number); fprint_msg("SYSTEM START: Audio stream %02x",number);
} }
else if (start_code >= 0xE0 && start_code <= 0xEF) else if (start_code >= 0xE0 && start_code <= 0xEF)
{ {
number = start_code & 0x0F; number = start_code & 0x0F;
fprintf(stream,"SYSTEM START: Video stream %x",number); fprint_msg("SYSTEM START: Video stream %x",number);
} }
else if (start_code >= 0xFC && start_code <= 0xFE) else if (start_code >= 0xFC && start_code <= 0xFE)
fprintf(stream,"SYSTEM START: Reserved data stream"); print_msg("SYSTEM START: Reserved data stream");
else else
fprintf(stream,"SYSTEM START: Unrecognised stream id"); print_msg("SYSTEM START: Unrecognised stream id");
} }
/* /*
@ -130,13 +129,13 @@ extern int build_h262_item(h262_item_p *item)
h262_item_p new = malloc(SIZEOF_H262_ITEM); h262_item_p new = malloc(SIZEOF_H262_ITEM);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate MPEG2 item datastructure\n"); print_err("### Unable to allocate MPEG2 item datastructure\n");
return 1; return 1;
} }
err = setup_ES_unit(&(new->unit)); err = setup_ES_unit(&(new->unit));
if (err) if (err)
{ {
fprintf(stderr,"### Unable to allocate MPEG2 item data buffer\n"); print_err("### Unable to allocate MPEG2 item data buffer\n");
free(new); free(new);
return 1; return 1;
} }
@ -168,7 +167,7 @@ extern void report_h262_item(h262_item_p item)
fprint_msg(OFFSET_T_FORMAT_08 "/%04d: MPEG2 item %02x (", fprint_msg(OFFSET_T_FORMAT_08 "/%04d: MPEG2 item %02x (",
item->unit.start_posn.infile, item->unit.start_posn.infile,
item->unit.start_posn.inpacket,item->unit.start_code); item->unit.start_posn.inpacket,item->unit.start_code);
print_h262_start_code_str(stdout,item->unit.start_code); // XXX Fix print_h262_start_code_str(item->unit.start_code);
print_msg(")"); print_msg(")");
if (item->unit.start_code == 0) if (item->unit.start_code == 0)
fprint_msg(" %d (%s)",item->picture_coding_type, fprint_msg(" %d (%s)",item->picture_coding_type,
@ -232,7 +231,7 @@ extern int build_h262_context(ES_p es,
h262_context_p new = malloc(SIZEOF_H262_CONTEXT); h262_context_p new = malloc(SIZEOF_H262_CONTEXT);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate H.262 context datastructure\n"); print_err("### Unable to allocate H.262 context datastructure\n");
return 1; return 1;
} }
@ -355,14 +354,14 @@ static int build_h262_picture(h262_context_p context,
h262_picture_p new = malloc(SIZEOF_H262_PICTURE); h262_picture_p new = malloc(SIZEOF_H262_PICTURE);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate H.262 picture datastructure\n"); print_err("### Unable to allocate H.262 picture datastructure\n");
return 1; return 1;
} }
err = build_ES_unit_list(&(new->list)); err = build_ES_unit_list(&(new->list));
if (err) if (err)
{ {
fprintf(stderr,"### Unable to allocate internal list for H.262 picture\n"); print_err("### Unable to allocate internal list for H.262 picture\n");
free(new); free(new);
return 1; return 1;
} }
@ -401,9 +400,8 @@ static int build_h262_picture(h262_context_p context,
} }
else else
{ {
fprintf(stderr, fprint_err("!!! Building H.262 picture that starts with a %s (%02x)\n",
"!!! Building H.262 picture that starts with a %s (%02x)\n", H262_START_CODE_STR(item->unit.start_code),item->unit.start_code);
H262_START_CODE_STR(item->unit.start_code),item->unit.start_code);
new->is_picture = FALSE; new->is_picture = FALSE;
new->is_sequence_header = FALSE; new->is_sequence_header = FALSE;
new->picture_coding_type = 0; // Forbidden value, just in case new->picture_coding_type = 0; // Forbidden value, just in case
@ -412,8 +410,8 @@ static int build_h262_picture(h262_context_p context,
err = append_to_h262_picture(new,item); err = append_to_h262_picture(new,item);
if (err) if (err)
{ {
fprintf(stderr,"### Error appending first item to H.262 %s\n", fprint_err("### Error appending first item to H.262 %s\n",
H262_START_CODE_STR(item->unit.start_code)); H262_START_CODE_STR(item->unit.start_code));
free_h262_picture(&new); free_h262_picture(&new);
return 1; return 1;
} }
@ -439,7 +437,7 @@ static int append_fake_afd(h262_picture_p picture,
err = build_h262_item(&item); err = build_h262_item(&item);
if (err) if (err)
{ {
fprintf(stderr,"### Error building 'fake' AFD for H.262 picture\n"); print_err("### Error building 'fake' AFD for H.262 picture\n");
return 1; return 1;
} }
item->unit.data[0] = 0x00; item->unit.data[0] = 0x00;
@ -462,7 +460,7 @@ static int append_fake_afd(h262_picture_p picture,
err = append_to_h262_picture(picture,item); err = append_to_h262_picture(picture,item);
if (err) if (err)
{ {
fprintf(stderr,"### Error appending 'fake' AFD to H.262 picture\n"); print_err("### Error appending 'fake' AFD to H.262 picture\n");
return 1; return 1;
} }
@ -490,7 +488,7 @@ static int merge_fields(h262_picture_p picture1,
&picture2->list->array[ii]); &picture2->list->array[ii]);
if (err) if (err)
{ {
fprintf(stderr,"### Error merging two H.262 field pictures\n"); print_err("### Error merging two H.262 field pictures\n");
return 1; return 1;
} }
} }
@ -562,8 +560,7 @@ static int maybe_remember_this_picture(h262_context_p h262,
err = get_ES_unit_list_bounds(this_picture->list,&start_posn,&num_bytes); err = get_ES_unit_list_bounds(this_picture->list,&start_posn,&num_bytes);
if (err) if (err)
{ {
fprintf(stderr, print_err("### Error working out position/size of H.262 picture\n");
"### Error working out position/size of H.262 picture\n");
return 1; return 1;
} }
@ -573,14 +570,13 @@ static int maybe_remember_this_picture(h262_context_p h262,
this_picture->afd); this_picture->afd);
if (err) if (err)
{ {
fprintf(stderr, print_err("### Error remembering reversing data for H.262 item\n");
"### Error remembering reversing data for H.262 item\n");
return 1; return 1;
} }
if (verbose) if (verbose)
printf("REMEMBER I picture %5d at " OFFSET_T_FORMAT_08 fprint_msg("REMEMBER I picture %5d at " OFFSET_T_FORMAT_08
"/%04d for %5d\n",h262->picture_index, "/%04d for %5d\n",h262->picture_index,
start_posn.infile,start_posn.inpacket,num_bytes); start_posn.infile,start_posn.inpacket,num_bytes);
} }
} }
else if (this_picture->is_sequence_header) else if (this_picture->is_sequence_header)
@ -590,21 +586,21 @@ static int maybe_remember_this_picture(h262_context_p h262,
err = get_ES_unit_list_bounds(this_picture->list,&start_posn,&num_bytes); err = get_ES_unit_list_bounds(this_picture->list,&start_posn,&num_bytes);
if (err) if (err)
{ {
fprintf(stderr,"### Error working out position/size of H.262" print_err("### Error working out position/size of H.262"
" sequence header for reversing data\n"); " sequence header for reversing data\n");
return 1; return 1;
} }
err = remember_reverse_h262_data(h262->reverse_data,0, err = remember_reverse_h262_data(h262->reverse_data,0,
start_posn,num_bytes,0,0); start_posn,num_bytes,0,0);
if (err) if (err)
{ {
fprintf(stderr,"### Error remembering reversing data for H.262 item\n"); print_err("### Error remembering reversing data for H.262 item\n");
return 1; return 1;
} }
if (verbose) if (verbose)
printf("REMEMBER Sequence header at " OFFSET_T_FORMAT_08 fprint_msg("REMEMBER Sequence header at " OFFSET_T_FORMAT_08
"/%04d for %5d\n", "/%04d for %5d\n",
start_posn.infile,start_posn.inpacket,num_bytes); start_posn.infile,start_posn.inpacket,num_bytes);
} }
return 0; return 0;
} }
@ -628,16 +624,16 @@ static int extract_AFD(h262_item_p item,
// AFD flag set // AFD flag set
if (item->unit.data_len < 10) if (item->unit.data_len < 10)
{ {
fprintf(stderr,"!!! AFD too short (only %d bytes - AFD missing)\n", fprint_err("!!! AFD too short (only %d bytes - AFD missing)\n",
item->unit.data_len); item->unit.data_len);
*afd = UNSET_AFD_BYTE; *afd = UNSET_AFD_BYTE;
return 1; return 1;
} }
*afd = item->unit.data[9]; *afd = item->unit.data[9];
if ((item->unit.data[9] & 0xF0) != 0xF0) if ((item->unit.data[9] & 0xF0) != 0xF0)
{ {
fprintf(stderr,"### Bad AFD %02x (reserved bits not 1111)\n", fprint_err("### Bad AFD %02x (reserved bits not 1111)\n",
item->unit.data[9]); item->unit.data[9]);
return 1; return 1;
} }
} }
@ -647,8 +643,8 @@ static int extract_AFD(h262_item_p item,
} }
else else
{ {
fprintf(stderr,"### AFD datastructure malformed: flag byte is %02x" fprint_err("### AFD datastructure malformed: flag byte is %02x"
" instead of 0x41 or 0x01\n",item->unit.data[8]); " instead of 0x41 or 0x01\n",item->unit.data[8]);
if (item->unit.data_len == 9) if (item->unit.data_len == 9)
*afd = UNSET_AFD_BYTE; *afd = UNSET_AFD_BYTE;
else else
@ -664,21 +660,21 @@ static int extract_AFD(h262_item_p item,
*/ */
static void _show_item(h262_item_p item) static void _show_item(h262_item_p item)
{ {
printf("__ "); print_msg("__ ");
if (item == NULL) if (item == NULL)
{ {
printf("<no item>\n"); print_msg("<no item>\n");
return; return;
} }
if (is_h262_picture_item(item)) if (is_h262_picture_item(item))
printf("%s picture",H262_PICTURE_CODING_STR(item->picture_coding_type)); fprint_msg("%s picture",H262_PICTURE_CODING_STR(item->picture_coding_type));
else if (is_h262_slice_item(item)) else if (is_h262_slice_item(item))
printf("slice %2x",item->unit.start_code); fprint_msg("slice %2x",item->unit.start_code);
else else
printf("%s",H262_START_CODE_STR(item->unit.start_code)); fprint_msg("%s",H262_START_CODE_STR(item->unit.start_code));
printf(" at " OFFSET_T_FORMAT "/%d for %d\n", fprint_msg(" at " OFFSET_T_FORMAT "/%d for %d\n",
item->unit.start_posn.infile,item->unit.start_posn.inpacket, item->unit.start_posn.infile,item->unit.start_posn.inpacket,
item->unit.data_len); item->unit.data_len);
} }
#endif #endif
@ -718,7 +714,7 @@ extern int get_next_h262_single_picture(h262_context_p context,
int num_slices = 0; int num_slices = 0;
int had_slice = FALSE; int had_slice = FALSE;
int last_slice_start_code = 0; int last_slice_start_code = 0;
if (verbose && context->last_item) printf("__ reuse last item\n"); if (verbose && context->last_item) print_msg("__ reuse last item\n");
#endif #endif
context->last_item = NULL; context->last_item = NULL;
@ -756,7 +752,7 @@ extern int get_next_h262_single_picture(h262_context_p context,
#if DEBUG_GET_NEXT_PICTURE #if DEBUG_GET_NEXT_PICTURE
if (verbose) if (verbose)
{ {
printf("__ --------------------------------- <start picture>\n"); print_msg("__ --------------------------------- <start picture>\n");
_show_item(item); _show_item(item);
} }
#endif #endif
@ -771,7 +767,7 @@ extern int get_next_h262_single_picture(h262_context_p context,
// A sequence end is a single item, so we're done // A sequence end is a single item, so we're done
#if DEBUG_GET_NEXT_PICTURE #if DEBUG_GET_NEXT_PICTURE
if (verbose) if (verbose)
printf("__ --------------------------------- <end picture>\n"); print_msg("__ --------------------------------- <end picture>\n");
#endif #endif
return 0; return 0;
} }
@ -814,14 +810,14 @@ extern int get_next_h262_single_picture(h262_context_p context,
// We found a *real* AFD - remember it // We found a *real* AFD - remember it
err = extract_AFD(item,&(*picture)->afd); err = extract_AFD(item,&(*picture)->afd);
if (err) if (err)
fprintf(stderr,"!!! Assuming AFD %x at " OFFSET_T_FORMAT "/%d\n", fprint_err("!!! Assuming AFD %x at " OFFSET_T_FORMAT "/%d\n",
(*picture)->afd, (*picture)->afd,
item->unit.start_posn.infile,item->unit.start_posn.inpacket); item->unit.start_posn.infile,item->unit.start_posn.inpacket);
(*picture)->is_real_afd = TRUE; (*picture)->is_real_afd = TRUE;
#if DEBUG_AFD #if DEBUG_AFD
if ((*picture)->afd != context->last_afd) if ((*picture)->afd != context->last_afd)
{ {
printf("* "); print_msg("* ");
report_h262_picture(stdout,*picture,FALSE); report_h262_picture(stdout,*picture,FALSE);
} }
#endif #endif
@ -843,10 +839,10 @@ extern int get_next_h262_single_picture(h262_context_p context,
#if DEBUG_GET_NEXT_PICTURE #if DEBUG_GET_NEXT_PICTURE
if (verbose) if (verbose)
{ {
printf("__ fake AFD "); print_msg("__ fake AFD ");
print_bits(4,(*picture)->afd); print_bits(4,(*picture)->afd);
printf(", i.e., %s",SHORT_AFD_STR((*picture)->afd)); fprint_msg(", i.e., %s",SHORT_AFD_STR((*picture)->afd));
printf("\n"); print_msg("\n");
} }
#endif #endif
} }
@ -871,7 +867,7 @@ extern int get_next_h262_single_picture(h262_context_p context,
err = append_to_h262_picture(*picture,item); err = append_to_h262_picture(*picture,item);
if (err) if (err)
{ {
fprintf(stderr,"### Error adding item to H.262 sequence header\n"); print_err("### Error adding item to H.262 sequence header\n");
free_h262_picture(picture); free_h262_picture(picture);
return 1; return 1;
} }
@ -892,15 +888,15 @@ extern int get_next_h262_single_picture(h262_context_p context,
if (num_slices > 1) if (num_slices > 1)
{ {
ES_unit_p unit = &(*picture)->list->array[(*picture)->list->length-1]; ES_unit_p unit = &(*picture)->list->array[(*picture)->list->length-1];
printf("__ ...\n"); print_msg("__ ...\n");
printf("__ slice %2x",last_slice_start_code); fprint_msg("__ slice %2x",last_slice_start_code);
printf(" at " OFFSET_T_FORMAT "/%d for %d\n", fprint_msg(" at " OFFSET_T_FORMAT "/%d for %d\n",
unit->start_posn.infile,unit->start_posn.inpacket, unit->start_posn.infile,unit->start_posn.inpacket,
unit->data_len); unit->data_len);
} }
printf("__ (%2d slices)\n",num_slices); fprint_msg("__ (%2d slices)\n",num_slices);
} }
printf("__ --------------------------------- <end picture>\n"); print_msg("__ --------------------------------- <end picture>\n");
if (in_picture || in_sequence_header) if (in_picture || in_sequence_header)
_show_item(item); _show_item(item);
} }
@ -936,15 +932,15 @@ static int get_next_field_of_pair(h262_context_p context,
h262_picture_p second; h262_picture_p second;
if (verbose) if (verbose)
printf("@@ Looking for second field (%s time)\n", fprint_msg("@@ Looking for second field (%s time)\n",
(first_time?"first":"second")); (first_time?"first":"second"));
// We assume (hope) the next picture will be our second half // We assume (hope) the next picture will be our second half
err = get_next_h262_single_picture(context,verbose,&second); err = get_next_h262_single_picture(context,verbose,&second);
if (err) if (err)
{ {
if (err != EOF) if (err != EOF)
fprintf(stderr,"### Trying to read second field\n"); print_err("### Trying to read second field\n");
return err; return err;
} }
@ -952,8 +948,8 @@ static int get_next_field_of_pair(h262_context_p context,
{ {
// But it was either a frame or a sequence header - oh dear // But it was either a frame or a sequence header - oh dear
if (!quiet) if (!quiet)
fprintf(stderr,"!!! Field followed by a %s - ignoring the field\n", fprint_err("!!! Field followed by a %s - ignoring the field\n",
(second->is_picture?"frame":"sequence header")); (second->is_picture?"frame":"sequence header"));
free_h262_picture(picture); free_h262_picture(picture);
*picture = second; *picture = second;
// and pretend to success // and pretend to success
@ -961,7 +957,7 @@ static int get_next_field_of_pair(h262_context_p context,
else if ((*picture)->temporal_reference == second->temporal_reference) else if ((*picture)->temporal_reference == second->temporal_reference)
{ {
// They appear to be matching fields - make a frame from them // They appear to be matching fields - make a frame from them
if (verbose) printf("@@ Merging two fields\n"); if (verbose) print_msg("@@ Merging two fields\n");
err = merge_fields(*picture,second); err = merge_fields(*picture,second);
if (err) if (err)
{ {
@ -973,10 +969,10 @@ static int get_next_field_of_pair(h262_context_p context,
else if (first_time) else if (first_time)
{ {
if (!quiet) if (!quiet)
fprintf(stderr,"!!! Field with temporal ref %d (%x) followed by" fprint_err("!!! Field with temporal ref %d (%x) followed by"
" field with temporal ref %d (%x) - ignoring first field\n", " field with temporal ref %d (%x) - ignoring first field\n",
(*picture)->temporal_reference,(*picture)->temporal_reference, (*picture)->temporal_reference,(*picture)->temporal_reference,
second->temporal_reference,second->temporal_reference); second->temporal_reference,second->temporal_reference);
// Try again // Try again
free_h262_picture(picture); free_h262_picture(picture);
@ -986,8 +982,8 @@ static int get_next_field_of_pair(h262_context_p context,
} }
else else
{ {
fprintf(stderr,"### Adjacent fields do not share temporal references" print_err("### Adjacent fields do not share temporal references"
" - unable to match fields up\n"); " - unable to match fields up\n");
return 1; return 1;
} }
return 0; return 0;
@ -1100,7 +1096,7 @@ extern int write_h262_picture_as_TS(TS_writer_p tswriter,
DEFAULT_VIDEO_STREAM_ID); DEFAULT_VIDEO_STREAM_ID);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing out picture list to TS\n"); print_err("### Error writing out picture list to TS\n");
return err; return err;
} }
} }
@ -1133,7 +1129,7 @@ extern int write_h262_picture_as_ES(FILE *output,
err = write_ES_unit(output,unit); err = write_ES_unit(output,unit);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing out picture list to ES\n"); print_err("### Error writing out picture list to ES\n");
return err; return err;
} }
} }
@ -1152,44 +1148,44 @@ extern void report_h262_picture(h262_picture_p picture,
{ {
if (picture->is_picture) if (picture->is_picture)
{ {
printf("%s %s #%02d", fprint_msg("%s %s #%02d",
H262_PICTURE_CODING_STR(picture->picture_coding_type), H262_PICTURE_CODING_STR(picture->picture_coding_type),
H262_PICTURE_STRUCTURE_STR(picture->picture_structure), H262_PICTURE_STRUCTURE_STR(picture->picture_structure),
picture->temporal_reference); picture->temporal_reference);
if (picture->was_two_fields) if (picture->was_two_fields)
printf(" (merged)"); print_msg(" (merged)");
printf(" %s",H262_ASPECT_RATIO_INFO_STR(picture->aspect_ratio_info)); fprint_msg(" %s",H262_ASPECT_RATIO_INFO_STR(picture->aspect_ratio_info));
if (picture->is_real_afd) if (picture->is_real_afd)
printf(" AFD "); print_msg(" AFD ");
else else
printf(" afd "); print_msg(" afd ");
print_bits(4,picture->afd); print_bits(4,picture->afd);
printf(", i.e., %s",SHORT_AFD_STR(picture->afd)); fprint_msg(", i.e., %s",SHORT_AFD_STR(picture->afd));
printf("\n"); print_msg("\n");
} }
else if (picture->is_sequence_header) else if (picture->is_sequence_header)
{ {
printf("Sequence header: "); print_msg("Sequence header: ");
switch (picture->progressive_sequence) switch (picture->progressive_sequence)
{ {
case 0: printf("frames and fields"); break; case 0: print_msg("frames and fields"); break;
case 1: printf("progressive frames only"); break; case 1: print_msg("progressive frames only"); break;
default: default:
printf("progressive_sequence=%d", fprint_msg("progressive_sequence=%d",
picture->progressive_sequence); picture->progressive_sequence);
break; break;
} }
printf(", aspect ratio %s", fprint_msg(", aspect ratio %s",
H262_ASPECT_RATIO_INFO_STR(picture->aspect_ratio_info)); H262_ASPECT_RATIO_INFO_STR(picture->aspect_ratio_info));
printf("\n"); print_msg("\n");
} }
else else
{ {
printf("Sequence end\n"); print_msg("Sequence end\n");
} }
if (report_data) if (report_data)
report_ES_unit_list("ES units",picture->list); report_ES_unit_list("ES units",picture->list);

Wyświetl plik

@ -32,7 +32,7 @@
#include "h262_defns.h" #include "h262_defns.h"
/* /*
* Print out information derived from the start code, to the given stream. * Print out information derived from the start code
* *
* Note that if a "SYSTEM START" code is reported, then the data is * Note that if a "SYSTEM START" code is reported, then the data is
* likely to be PES or Transport Stream data, not Elementary Stream. * likely to be PES or Transport Stream data, not Elementary Stream.
@ -44,8 +44,7 @@
* that some of the apparent start code prefixes are actually false * that some of the apparent start code prefixes are actually false
* detections. * detections.
*/ */
extern void print_h262_start_code_str(FILE *stream, extern void print_h262_start_code_str(byte start_code);
byte start_code);
/* /*
* Build a new MPEG2 item datastructure. * Build a new MPEG2 item datastructure.
* *

2
pes.c
Wyświetl plik

@ -3056,7 +3056,7 @@ extern void report_PES_data_array2(int stream_type,
printf(" Start code: %02x %02x %02x\n", printf(" Start code: %02x %02x %02x\n",
payload[0],payload[1],payload[2]); payload[0],payload[1],payload[2]);
printf(" Stream ID: %02x (%d) ",stream_id,stream_id); printf(" Stream ID: %02x (%d) ",stream_id,stream_id);
print_h262_start_code_str(stdout,stream_id); print_h262_start_code_str(stream_id);
printf("\n"); printf("\n");
printf(" PES packet length: %04x (%d)\n", printf(" PES packet length: %04x (%d)\n",
PES_packet_length,PES_packet_length); PES_packet_length,PES_packet_length);