More print changes

--HG--
extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%40139
issue20
tibs 2009-05-03 19:33:45 +00:00
rodzic 87addc998a
commit ef54a360b1
7 zmienionych plików z 582 dodań i 583 usunięć

149
esmerge.c
Wyświetl plik

@ -39,6 +39,7 @@
#include "ts_fns.h"
#include "tswrite_fns.h"
#include "misc_fns.h"
#include "printing_fns.h"
#include "version.h"
// Default audio rates, in Hertz
@ -75,10 +76,10 @@ static int check(uint64_t value)
if (err) return 1;
if (value == result)
printf("Value " LLU_FORMAT " OK\n",value);
fprint_msg("Value " LLU_FORMAT " OK\n",value);
else
{
printf("Input " LLU_FORMAT ", output " LLU_FORMAT "\n",value,result);
fprint_msg("Input " LLU_FORMAT ", output " LLU_FORMAT "\n",value,result);
return 1;
}
@ -160,8 +161,8 @@ static int merge_with_avs(avs_context_p video_context,
int got_audio = TRUE;
if (verbose)
printf("Video PTS increment %u\n"
"Audio PTS increment %u\n",video_pts_increment,audio_pts_increment);
fprint_msg("Video PTS increment %u\n"
"Audio PTS increment %u\n",video_pts_increment,audio_pts_increment);
// Start off our output with some null packets - this is in case the
// reader needs some time to work out its byte alignment before it starts
@ -203,7 +204,7 @@ static int merge_with_avs(avs_context_p video_context,
2,prog_pids,prog_type);
if (err)
{
fprintf(stderr,"### Error writing out TS program data\n");
print_err("### Error writing out TS program data\n");
return 1;
}
@ -219,7 +220,7 @@ static int merge_with_avs(avs_context_p video_context,
if (err == EOF)
{
if (verbose)
printf("EOF: no more video data\n");
print_msg("EOF: no more video data\n");
got_video = FALSE;
}
else if (err)
@ -236,7 +237,7 @@ static int merge_with_avs(avs_context_p video_context,
if (err)
{
free_avs_frame(&avs_frame);
fprintf(stderr,"### Error writing AVS frame (sequence header/end)\n");
print_err("### Error writing AVS frame (sequence header/end)\n");
return 1;
}
continue; // look for a "proper" frame
@ -249,16 +250,16 @@ static int merge_with_avs(avs_context_p video_context,
video_pts += video_pts_increment;
video_frame_count ++;
if (verbose)
printf("\n%s video frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
(is_avs_I_frame(avs_frame)?"**":"++"),
video_frame_count,video_time,video_pts);
fprint_msg("\n%s video frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
(is_avs_I_frame(avs_frame)?"**":"++"),
video_frame_count,video_time,video_pts);
if (pat_pmt_freq && !(video_frame_count % pat_pmt_freq))
{
if (verbose)
{
printf("\nwriting PAT and PMT (frame = %d, freq = %d).. ",
video_frame_count, pat_pmt_freq);
fprint_msg("\nwriting PAT and PMT (frame = %d, freq = %d).. ",
video_frame_count, pat_pmt_freq);
}
err = write_TS_program_data2(output,
@ -293,7 +294,7 @@ static int merge_with_avs(avs_context_p video_context,
if (err)
{
free_avs_frame(&avs_frame);
fprintf(stderr,"### Error writing AVS frame\n");
print_err("### Error writing AVS frame\n");
return 1;
}
free_avs_frame(&avs_frame);
@ -309,7 +310,7 @@ static int merge_with_avs(avs_context_p video_context,
if (err == EOF)
{
if (verbose)
printf("EOF: no more audio data\n");
print_msg("EOF: no more audio data\n");
got_audio = FALSE;
break;
}
@ -321,8 +322,8 @@ static int merge_with_avs(avs_context_p video_context,
audio_pts += audio_pts_increment;
audio_frame_count ++;
if (verbose)
printf("** audio frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
audio_frame_count,audio_time,audio_pts);
fprint_msg("** audio frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
audio_frame_count,audio_time,audio_pts);
err = write_ES_as_TS_PES_packet_with_pts_dts(output,aframe->data,
aframe->data_len,
@ -333,7 +334,7 @@ static int merge_with_avs(avs_context_p video_context,
if (err)
{
free_audio_frame(&aframe);
fprintf(stderr,"### Error writing audio frame\n");
print_err("### Error writing audio frame\n");
return 1;
}
free_audio_frame(&aframe);
@ -345,12 +346,12 @@ static int merge_with_avs(avs_context_p video_context,
uint32_t video_elapsed = (uint32_t)((double)(100*video_frame_count)/video_frame_rate);
uint32_t audio_elapsed = 100*audio_frame_count*
audio_samples_per_frame/audio_sample_rate;
printf("Read %d video frame%s, %.2fs elapsed (%dm %.2fs)\n",
video_frame_count,(video_frame_count==1?"":"s"),
video_elapsed/100.0,video_elapsed/6000,(video_elapsed%6000)/100.0);
printf("Read %d audio frame%s, %.2fs elapsed (%dm %.2fs)\n",
audio_frame_count,(audio_frame_count==1?"":"s"),
audio_elapsed/100.0,audio_elapsed/6000,(audio_elapsed%6000)/100.0);
fprint_msg("Read %d video frame%s, %.2fs elapsed (%dm %.2fs)\n",
video_frame_count,(video_frame_count==1?"":"s"),
video_elapsed/100.0,video_elapsed/6000,(video_elapsed%6000)/100.0);
fprint_msg("Read %d audio frame%s, %.2fs elapsed (%dm %.2fs)\n",
audio_frame_count,(audio_frame_count==1?"":"s"),
audio_elapsed/100.0,audio_elapsed/6000,(audio_elapsed%6000)/100.0);
}
return 0;
@ -396,8 +397,8 @@ static int merge_with_h264(access_unit_context_p video_context,
int got_audio = TRUE;
if (verbose)
printf("Video PTS increment %u\n"
"Audio PTS increment %u\n",video_pts_increment,audio_pts_increment);
fprint_msg("Video PTS increment %u\n"
"Audio PTS increment %u\n",video_pts_increment,audio_pts_increment);
// Start off our output with some null packets - this is in case the
// reader needs some time to work out its byte alignment before it starts
@ -439,7 +440,7 @@ static int merge_with_h264(access_unit_context_p video_context,
2,prog_pids,prog_type);
if (err)
{
fprintf(stderr,"### Error writing out TS program data\n");
print_err("### Error writing out TS program data\n");
return 1;
}
@ -455,7 +456,7 @@ static int merge_with_h264(access_unit_context_p video_context,
if (err == EOF)
{
if (verbose)
printf("EOF: no more video data\n");
print_msg("EOF: no more video data\n");
got_video = FALSE;
}
else if (err)
@ -468,16 +469,16 @@ static int merge_with_h264(access_unit_context_p video_context,
video_pts += video_pts_increment;
video_frame_count ++;
if (verbose)
printf("\n%s video frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
(is_I_or_IDR_frame(access_unit)?"**":"++"),
video_frame_count,video_time,video_pts);
fprint_msg("\n%s video frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
(is_I_or_IDR_frame(access_unit)?"**":"++"),
video_frame_count,video_time,video_pts);
if (pat_pmt_freq && !(video_frame_count % pat_pmt_freq))
{
if (verbose)
{
printf("\nwriting PAT and PMT (frame = %d, freq = %d).. ",
video_frame_count, pat_pmt_freq);
fprint_msg("\nwriting PAT and PMT (frame = %d, freq = %d).. ",
video_frame_count, pat_pmt_freq);
}
err = write_TS_program_data2(output,
1, // tsid
@ -509,7 +510,7 @@ static int merge_with_h264(access_unit_context_p video_context,
if (err)
{
free_access_unit(&access_unit);
fprintf(stderr,"### Error writing access unit (frame)\n");
print_err("### Error writing access unit (frame)\n");
return 1;
}
free_access_unit(&access_unit);
@ -518,7 +519,7 @@ static int merge_with_h264(access_unit_context_p video_context,
if (video_context->end_of_stream)
{
if (verbose)
printf("Found End-of-stream NAL unit\n");
print_msg("Found End-of-stream NAL unit\n");
got_video = FALSE;
}
}
@ -533,7 +534,7 @@ static int merge_with_h264(access_unit_context_p video_context,
if (err == EOF)
{
if (verbose)
printf("EOF: no more audio data\n");
print_msg("EOF: no more audio data\n");
got_audio = FALSE;
break;
}
@ -545,8 +546,8 @@ static int merge_with_h264(access_unit_context_p video_context,
audio_pts += audio_pts_increment;
audio_frame_count ++;
if (verbose)
printf("** audio frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
audio_frame_count,audio_time,audio_pts);
fprint_msg("** audio frame %5d (@ %.2fs, " LLU_FORMAT ")\n",
audio_frame_count,audio_time,audio_pts);
err = write_ES_as_TS_PES_packet_with_pts_dts(output,aframe->data,
aframe->data_len,
@ -557,7 +558,7 @@ static int merge_with_h264(access_unit_context_p video_context,
if (err)
{
free_audio_frame(&aframe);
fprintf(stderr,"### Error writing audio frame\n");
print_err("### Error writing audio frame\n");
return 1;
}
free_audio_frame(&aframe);
@ -569,12 +570,12 @@ static int merge_with_h264(access_unit_context_p video_context,
uint32_t video_elapsed = 100*video_frame_count/video_frame_rate;
uint32_t audio_elapsed = 100*audio_frame_count*
audio_samples_per_frame/audio_sample_rate;
printf("Read %d video frame%s, %.2fs elapsed (%dm %.2fs)\n",
video_frame_count,(video_frame_count==1?"":"s"),
video_elapsed/100.0,video_elapsed/6000,(video_elapsed%6000)/100.0);
printf("Read %d audio frame%s, %.2fs elapsed (%dm %.2fs)\n",
audio_frame_count,(audio_frame_count==1?"":"s"),
audio_elapsed/100.0,audio_elapsed/6000,(audio_elapsed%6000)/100.0);
fprint_msg("Read %d video frame%s, %.2fs elapsed (%dm %.2fs)\n",
video_frame_count,(video_frame_count==1?"":"s"),
video_elapsed/100.0,video_elapsed/6000,(video_elapsed%6000)/100.0);
fprint_msg("Read %d audio frame%s, %.2fs elapsed (%dm %.2fs)\n",
audio_frame_count,(audio_frame_count==1?"":"s"),
audio_elapsed/100.0,audio_elapsed/6000,(audio_elapsed%6000)/100.0);
}
return 0;
@ -583,13 +584,13 @@ static int merge_with_h264(access_unit_context_p video_context,
static void print_usage()
{
printf(
print_msg(
"Usage:\n"
" esmerge <video-file> <audio-file> <output-file>\n"
"\n"
);
REPORT_VERSION("esmerge");
printf(
print_msg(
"\n"
" Merge the contents of two Elementary Stream (ES) files, one containing\n"
" video data, and the other audio, to produce an output file containing\n"
@ -750,8 +751,8 @@ int main(int argc, char **argv)
}
else
{
fprintf(stderr,"### esmerge: "
"Unrecognised command line switch '%s'\n",argv[ii]);
fprint_err("### esmerge: "
"Unrecognised command line switch '%s'\n",argv[ii]);
return 1;
}
}
@ -774,7 +775,7 @@ int main(int argc, char **argv)
}
else
{
fprintf(stderr,"### esmerge: Unexpected '%s'\n",argv[ii]);
fprint_err("### esmerge: Unexpected '%s'\n",argv[ii]);
return 1;
}
}
@ -783,25 +784,25 @@ int main(int argc, char **argv)
if (!had_video_name)
{
fprintf(stderr,"### esmerge: No video input file specified\n");
print_err("### esmerge: No video input file specified\n");
return 1;
}
if (!had_audio_name)
{
fprintf(stderr,"### esmerge: No audio input file specified\n");
print_err("### esmerge: No audio input file specified\n");
return 1;
}
if (!had_output_name)
{
fprintf(stderr,"### esmerge: No output file specified\n");
print_err("### esmerge: No output file specified\n");
return 1;
}
err = open_elementary_stream(video_name,&video_es);
if (err)
{
fprintf(stderr,"### esmerge: "
"Problem starting to read video as ES - abandoning reading\n");
print_err("### esmerge: "
"Problem starting to read video as ES - abandoning reading\n");
return 1;
}
@ -810,8 +811,8 @@ int main(int argc, char **argv)
err = build_access_unit_context(video_es,&h264_video_context);
if (err)
{
fprintf(stderr,"### esmerge: "
"Problem starting to read video as H.264 - abandoning reading\n");
print_err("### esmerge: "
"Problem starting to read video as H.264 - abandoning reading\n");
close_elementary_stream(&video_es);
return 1;
}
@ -821,23 +822,23 @@ int main(int argc, char **argv)
err = build_avs_context(video_es,&avs_video_context);
if (err)
{
fprintf(stderr,"### esmerge: "
"Problem starting to read video as H.264 - abandoning reading\n");
print_err("### esmerge: "
"Problem starting to read video as H.264 - abandoning reading\n");
close_elementary_stream(&video_es);
return 1;
}
}
else
{
fprintf(stderr,"### esmerge: Unknown video type\n");
print_err("### esmerge: Unknown video type\n");
return 1;
}
audio_file = open_binary_file(audio_name,FALSE);
if (audio_file == -1)
{
fprintf(stderr,"### esmerge: "
"Problem opening audio file - abandoning reading\n");
print_err("### esmerge: "
"Problem opening audio file - abandoning reading\n");
close_elementary_stream(&video_es);
free_access_unit_context(&h264_video_context);
free_avs_context(&avs_video_context);
@ -847,9 +848,9 @@ int main(int argc, char **argv)
err = tswrite_open(TS_W_FILE,output_name,NULL,0,quiet,&output);
if (err)
{
fprintf(stderr,"### esmerge: "
"Problem opening output file %s - abandoning reading\n",
output_name);
fprint_err("### esmerge: "
"Problem opening output file %s - abandoning reading\n",
output_name);
close_elementary_stream(&video_es);
close_file(audio_file);
free_access_unit_context(&h264_video_context);
@ -875,13 +876,13 @@ int main(int argc, char **argv)
if (!quiet)
{
printf("Reading video from %s\n",video_name);
printf("Reading audio from %s (as %s)\n",audio_name,AUDIO_STR(audio_type));
printf("Writing output to %s\n",output_name);
printf("Audio sample rate: %dHz (%.2fKHz)\n",audio_sample_rate,
audio_sample_rate/1000.0);
printf("Audio samples per frame: %d\n",audio_samples_per_frame);
printf("Video frame rate: %dHz\n",video_frame_rate);
fprint_msg("Reading video from %s\n",video_name);
fprint_msg("Reading audio from %s (as %s)\n",audio_name,AUDIO_STR(audio_type));
fprint_msg("Writing output to %s\n",output_name);
fprint_msg("Audio sample rate: %dHz (%.2fKHz)\n",audio_sample_rate,
audio_sample_rate/1000.0);
fprint_msg("Audio samples per frame: %d\n",audio_samples_per_frame);
fprint_msg("Video frame rate: %dHz\n",video_frame_rate);
}
@ -901,12 +902,12 @@ int main(int argc, char **argv)
quiet,verbose,debugging);
else
{
fprintf(stderr,"### esmerge: Unknown video type\n");
print_err("### esmerge: Unknown video type\n");
return 1;
}
if (err)
{
fprintf(stderr,"### esmerge: Error merging video and audio streams\n");
print_err("### esmerge: Error merging video and audio streams\n");
close_elementary_stream(&video_es);
close_file(audio_file);
free_access_unit_context(&h264_video_context);
@ -922,7 +923,7 @@ int main(int argc, char **argv)
err = tswrite_close(output,quiet);
if (err)
{
fprintf(stderr,"### esmerge: Error closing output %s\n",output_name);
fprint_err("### esmerge: Error closing output %s\n",output_name);
return 1;
}
return 0;

Wyświetl plik

@ -47,6 +47,7 @@
#include "h262_fns.h"
#include "avs_fns.h"
#include "misc_fns.h"
#include "printing_fns.h"
#include "version.h"
#define FRAMES_PER_SECOND 25
@ -96,8 +97,7 @@ static void report_avs_frames(ES_p es,
err = build_avs_context(es,&avs);
if (err)
{
fprintf(stderr,
"### Error trying to build AVS reader from ES reader\n");
print_err("### Error trying to build AVS reader from ES reader\n");
return;
}
@ -110,7 +110,7 @@ static void report_avs_frames(ES_p es,
break;
else if (err)
{
fprintf(stderr,"### Error getting next AVS frame\n");
print_err("### Error getting next AVS frame\n");
break;
}
count++;
@ -166,51 +166,51 @@ static void report_avs_frames(ES_p es,
}
free_avs_context(&avs);
printf("Found %d AVS 'frame'%s:\n"
" %5d frame%s (%d I, %d P, %d B)\n"
" %5d sequence header%s\n"
" %5d sequence end%s\n",
count,(count==1?"":"s"),
num_frames,(num_frames==1?"":"s"),
num_x_frames[AVS_I_PICTURE_CODING],
num_x_frames[AVS_P_PICTURE_CODING],
num_x_frames[AVS_B_PICTURE_CODING],
num_sequence_headers,(num_sequence_headers==1?"":"s"),
num_sequence_ends,(num_sequence_ends==1?"":"s"));
fprint_msg("Found %d AVS 'frame'%s:\n"
" %5d frame%s (%d I, %d P, %d B)\n"
" %5d sequence header%s\n"
" %5d sequence end%s\n",
count,(count==1?"":"s"),
num_frames,(num_frames==1?"":"s"),
num_x_frames[AVS_I_PICTURE_CODING],
num_x_frames[AVS_P_PICTURE_CODING],
num_x_frames[AVS_B_PICTURE_CODING],
num_sequence_headers,(num_sequence_headers==1?"":"s"),
num_sequence_ends,(num_sequence_ends==1?"":"s"));
{
double total_seconds = num_frames / (double)FRAMES_PER_SECOND;
int minutes = (int)(total_seconds / 60);
double seconds = total_seconds - 60*minutes;
printf("At 25 frames/second, that is %dm %.1fs (%.2fs)\n",minutes,seconds,
total_seconds);
fprint_msg("At 25 frames/second, that is %dm %.1fs (%.2fs)\n",minutes,seconds,
total_seconds);
}
if (count_sizes)
{
int ii;
if (num_frames > 0)
printf("Frame sizes ranged from %5u to %7u bytes, mean %9.2f\n",
min_frame_size,max_frame_size,
sum_frame_size/(double)num_frames);
fprint_msg("Frame sizes ranged from %5u to %7u bytes, mean %9.2f\n",
min_frame_size,max_frame_size,
sum_frame_size/(double)num_frames);
for (ii = 0; ii < 3; ii++)
{
if (num_x_frames[ii] > 0)
printf(" %s frames from %5u to %7u bytes, mean %9.2f\n",
(ii==0?"I":
ii==1?"P":
ii==2?"B":"?"),
min_x_frame_size[ii],max_x_frame_size[ii],
sum_x_frame_size[ii]/(double)num_x_frames[ii]);
fprint_msg(" %s frames from %5u to %7u bytes, mean %9.2f\n",
(ii==0?"I":
ii==1?"P":
ii==2?"B":"?"),
min_x_frame_size[ii],max_x_frame_size[ii],
sum_x_frame_size[ii]/(double)num_x_frames[ii]);
}
if (num_sequence_headers > 0)
{
if (min_seq_hdr_size == max_seq_hdr_size)
printf("Sequence headers were all %u bytes\n",min_seq_hdr_size);
fprint_msg("Sequence headers were all %u bytes\n",min_seq_hdr_size);
else
printf("Sequence headers from %5u to %7u bytes, mean %9.2f\n",
min_seq_hdr_size,max_seq_hdr_size,
sum_seq_hdr_size/(double)num_sequence_headers);
fprint_msg("Sequence headers from %5u to %7u bytes, mean %9.2f\n",
min_seq_hdr_size,max_seq_hdr_size,
sum_seq_hdr_size/(double)num_sequence_headers);
}
}
}
@ -241,7 +241,7 @@ static void report_ES_units(ES_p es,
break;
else if (err)
{
fprintf(stderr,"### Error finding next ES unit\n");
print_err("### Error finding next ES unit\n");
break;
}
count++;
@ -257,7 +257,7 @@ static void report_ES_units(ES_p es,
break;
}
clear_ES_unit(&unit);
printf("Found %d ES unit%s\n",count,(count==1?"":"s"));
fprint_msg("Found %d ES unit%s\n",count,(count==1?"":"s"));
}
/*
@ -283,8 +283,7 @@ static void find_h262_fields(ES_p es,
err = build_h262_context(es,&h262);
if (err)
{
fprintf(stderr,
"### Error trying to build H.262 reader from ES reader\n");
print_err("### Error trying to build H.262 reader from ES reader\n");
return;
}
@ -297,7 +296,7 @@ static void find_h262_fields(ES_p es,
break;
else if (err)
{
fprintf(stderr,"### Error getting next H.262 picture\n");
print_err("### Error getting next H.262 picture\n");
break;
}
count++;
@ -324,16 +323,16 @@ static void find_h262_fields(ES_p es,
}
free_h262_context(&h262);
printf("Found %d MPEG-2 'picture'%s:\n"
" %5d field%s\n"
" %5d frame%s\n"
" %5d sequence header%s\n"
" %5d sequence end%s\n",
count,(count==1?"":"s"),
num_fields,(num_fields==1?"":"s"),
num_frames,(num_frames==1?"":"s"),
num_sequence_headers,(num_sequence_headers==1?"":"s"),
num_sequence_ends,(num_sequence_ends==1?"":"s"));
fprint_msg("Found %d MPEG-2 'picture'%s:\n"
" %5d field%s\n"
" %5d frame%s\n"
" %5d sequence header%s\n"
" %5d sequence end%s\n",
count,(count==1?"":"s"),
num_fields,(num_fields==1?"":"s"),
num_frames,(num_frames==1?"":"s"),
num_sequence_headers,(num_sequence_headers==1?"":"s"),
num_sequence_ends,(num_sequence_ends==1?"":"s"));
}
/*
@ -380,8 +379,7 @@ static void report_h262_frames(ES_p es,
err = build_h262_context(es,&h262);
if (err)
{
fprintf(stderr,
"### Error trying to build H.262 reader from ES reader\n");
print_err("### Error trying to build H.262 reader from ES reader\n");
return;
}
@ -394,7 +392,7 @@ static void report_h262_frames(ES_p es,
break;
else if (err)
{
fprintf(stderr,"### Error getting next H.262 picture\n");
print_err("### Error getting next H.262 picture\n");
break;
}
count++;
@ -450,50 +448,50 @@ static void report_h262_frames(ES_p es,
}
free_h262_context(&h262);
printf("Found %d MPEG-2 'picture'%s:\n"
" %5d frame%s (%d I, %d P, %d B, %d D)\n"
" %5d sequence header%s\n"
" %5d sequence end%s\n",
count,(count==1?"":"s"),
num_frames,(num_frames==1?"":"s"),
num_x_frames[0],
num_x_frames[1],
num_x_frames[2],
num_x_frames[3],
num_sequence_headers,(num_sequence_headers==1?"":"s"),
num_sequence_ends,(num_sequence_ends==1?"":"s"));
fprint_msg("Found %d MPEG-2 'picture'%s:\n"
" %5d frame%s (%d I, %d P, %d B, %d D)\n"
" %5d sequence header%s\n"
" %5d sequence end%s\n",
count,(count==1?"":"s"),
num_frames,(num_frames==1?"":"s"),
num_x_frames[0],
num_x_frames[1],
num_x_frames[2],
num_x_frames[3],
num_sequence_headers,(num_sequence_headers==1?"":"s"),
num_sequence_ends,(num_sequence_ends==1?"":"s"));
{
double total_seconds = num_frames / (double)FRAMES_PER_SECOND;
int minutes = (int)(total_seconds / 60);
double seconds = total_seconds - 60*minutes;
printf("At 25 frames/second, that is %dm %.1fs (%.2fs)\n",minutes,seconds,
total_seconds);
fprint_msg("At 25 frames/second, that is %dm %.1fs (%.2fs)\n",minutes,seconds,
total_seconds);
}
if (count_sizes)
{
int ii;
if (num_frames > 0)
printf("Frame sizes ranged from %5u to %7u bytes, mean %9.2f\n",
min_frame_size,max_frame_size,
sum_frame_size/(double)num_frames);
fprint_msg("Frame sizes ranged from %5u to %7u bytes, mean %9.2f\n",
min_frame_size,max_frame_size,
sum_frame_size/(double)num_frames);
for (ii = 0; ii < 4; ii++)
{
if (num_x_frames[ii] > 0)
printf(" %s frames from %5u to %7u bytes, mean %9.2f\n",
H262_PICTURE_CODING_STR(ii),
min_x_frame_size[ii],max_x_frame_size[ii],
sum_x_frame_size[ii]/(double)num_x_frames[ii]);
fprint_msg(" %s frames from %5u to %7u bytes, mean %9.2f\n",
H262_PICTURE_CODING_STR(ii),
min_x_frame_size[ii],max_x_frame_size[ii],
sum_x_frame_size[ii]/(double)num_x_frames[ii]);
}
if (num_sequence_headers > 0)
{
if (min_seq_hdr_size == max_seq_hdr_size)
printf("Sequence headers were all %u bytes\n",min_seq_hdr_size);
fprint_msg("Sequence headers were all %u bytes\n",min_seq_hdr_size);
else
printf("Sequence headers from %5u to %7u bytes, mean %9.2f\n",
min_seq_hdr_size,max_seq_hdr_size,
sum_seq_hdr_size/(double)num_sequence_headers);
fprint_msg("Sequence headers from %5u to %7u bytes, mean %9.2f\n",
min_seq_hdr_size,max_seq_hdr_size,
sum_seq_hdr_size/(double)num_sequence_headers);
}
}
}
@ -520,8 +518,7 @@ static void report_h262_afds(ES_p es,
err = build_h262_context(es,&h262);
if (err)
{
fprintf(stderr,
"### Error trying to build H.262 reader from ES reader\n");
print_err("### Error trying to build H.262 reader from ES reader\n");
return;
}
@ -534,7 +531,7 @@ static void report_h262_afds(ES_p es,
break;
else if (err)
{
fprintf(stderr,"### Error getting next H.262 picture\n");
print_err("### Error getting next H.262 picture\n");
break;
}
@ -542,8 +539,8 @@ static void report_h262_afds(ES_p es,
{
// NB: the time at which the frame *starts*
if (frames % report_every == 0)
printf("%d minute%s\n",frames/FRAMES_PER_MINUTE,
(frames/FRAMES_PER_MINUTE==1?"":"s"));
fprint_msg("%d minute%s\n",frames/FRAMES_PER_MINUTE,
(frames/FRAMES_PER_MINUTE==1?"":"s"));
frames ++;
}
@ -552,8 +549,8 @@ static void report_h262_afds(ES_p es,
double total_seconds = frames / (double)FRAMES_PER_SECOND;
int minutes = (int)(total_seconds / 60);
double seconds = total_seconds - 60*minutes;
printf("%dm %4.1fs (frame %d @ %.2fs): ",minutes,seconds,
frames,total_seconds);
fprint_msg("%dm %4.1fs (frame %d @ %.2fs): ",minutes,seconds,
frames,total_seconds);
report_h262_picture(picture,FALSE);
afd = picture->afd;
}
@ -569,8 +566,8 @@ static void report_h262_afds(ES_p es,
double total_seconds = frames / (double)FRAMES_PER_SECOND;
int minutes = (int)(total_seconds / 60);
double seconds = total_seconds - 60*minutes;
printf("Found %d MPEG-2 frame%s",frames,(frames==1?"":"s"));
printf(" which is %dm %.1fs (%.2fs)\n",minutes,seconds,total_seconds);
fprint_msg("Found %d MPEG-2 frame%s",frames,(frames==1?"":"s"));
fprint_msg(" which is %dm %.1fs (%.2fs)\n",minutes,seconds,total_seconds);
}
}
@ -598,7 +595,7 @@ static void report_h262_items(ES_p es,
break;
else if (err)
{
fprintf(stderr,"### Error finding next H.262 item\n");
print_err("### Error finding next H.262 item\n");
break;
}
count++;
@ -614,7 +611,7 @@ static void report_h262_items(ES_p es,
if (max > 0 && count >= max)
break;
}
printf("Found %d MPEG-2 item%s\n",count,(count==1?"":"s"));
fprint_msg("Found %d MPEG-2 item%s\n",count,(count==1?"":"s"));
}
/*
@ -636,7 +633,7 @@ static void report_by_nal_unit(ES_p es,
err = build_nal_unit_context(es,&context);
if (err)
{
fprintf(stderr,"### Unable to build NAL unit context to read ES\n");
print_err("### Unable to build NAL unit context to read ES\n");
return;
}
@ -649,15 +646,15 @@ static void report_by_nal_unit(ES_p es,
if (max > 0 && context->count >= max)
{
printf("\nStopping because %d NAL units have been read\n",
context->count);
fprint_msg("\nStopping because %d NAL units have been read\n",
context->count);
break;
}
err = find_next_NAL_unit(context,!quiet,&nal);
if (err == 2)
{
printf("... ignoring broken NAL unit\n");
print_msg("... ignoring broken NAL unit\n");
continue;
}
else if (err)
@ -678,33 +675,33 @@ static void report_by_nal_unit(ES_p es,
free_nal_unit(&nal);
}
if (err == EOF && !quiet)
printf("EOF\n");
print_msg("EOF\n");
if (err == 0 || err == EOF)
{
int ii;
printf("Found %d NAL unit%s\n",context->count,(context->count==1?"":"s"));
printf("nal_ref_idc:\n");
fprint_msg("Found %d NAL unit%s\n",context->count,(context->count==1?"":"s"));
print_msg("nal_ref_idc:\n");
for (ii=0; ii<4; ii++)
if (ref_idcs[ii] > 0)
printf(" %8d of %2d%s\n",ref_idcs[ii],ii,ii?"":" (non-reference)");
fprint_msg(" %8d of %2d%s\n",ref_idcs[ii],ii,ii?"":" (non-reference)");
printf("nal_unit_type:\n");
print_msg("nal_unit_type:\n");
for (ii=0; ii<13; ii++)
if (unit_types[ii] > 0)
printf(" %8d of type %2d (%s)\n",unit_types[ii],ii,NAL_UNIT_TYPE_STR(ii));
fprint_msg(" %8d of type %2d (%s)\n",unit_types[ii],ii,NAL_UNIT_TYPE_STR(ii));
if (unit_types[13] > 0)
printf(" %8d of type 13..23 (Reserved)\n",unit_types[13]);
fprint_msg(" %8d of type 13..23 (Reserved)\n",unit_types[13]);
if (unit_types[14] > 0)
printf(" %8d of typ 24..31 (Unspecified)\n",unit_types[14]);
fprint_msg(" %8d of typ 24..31 (Unspecified)\n",unit_types[14]);
printf("slice_type:\n");
print_msg("slice_type:\n");
for (ii=0; ii<10; ii++)
if (slice_types[ii] > 0)
printf(" %8d of type %2d (%s)\n",slice_types[ii],ii,
fprint_msg(" %8d of type %2d (%s)\n",slice_types[ii],ii,
NAL_SLICE_TYPE_STR(ii));
}
else
fprintf(stderr,"### Abandoning reporting due to error\n");
print_err("### Abandoning reporting due to error\n");
free_nal_unit_context(&context);
}
@ -744,7 +741,7 @@ static void find_h264_fields(ES_p es,
break;
else if (err)
{
fprintf(stderr,"### Error getting next access unit\n");
print_err("### Error getting next access unit\n");
break;
}
count++;
@ -765,12 +762,12 @@ static void find_h264_fields(ES_p es,
if (max > 0 && count >= max)
break;
}
printf("Found %d MPEG-4 picture%s, %d field%s, %d frame%s\n",
count,(count==1?"":"s"),
num_fields,(num_fields==1?"":"s"),
num_frames,(num_frames==1?"":"s"));
fprint_msg("Found %d MPEG-4 picture%s, %d field%s, %d frame%s\n",
count,(count==1?"":"s"),
num_fields,(num_fields==1?"":"s"),
num_frames,(num_frames==1?"":"s"));
printf("Fields with PTS associated: %u\n",num_with_PTS);
fprint_msg("Fields with PTS associated: %u\n",num_with_PTS);
free_access_unit_context(&context);
}
@ -888,93 +885,93 @@ static void report_h264_frames(ES_p es,
// Did the logical stream end after the last access unit?
if (context->end_of_stream)
{
if (!quiet) printf("Found End-of-stream NAL unit\n");
if (!quiet) print_msg("Found End-of-stream NAL unit\n");
break;
}
if (max > 0 && access_unit_count >= max)
{
printf("\nStopping because (at least) %d frames have been read\n",
access_unit_count);
fprint_msg("\nStopping because (at least) %d frames have been read\n",
access_unit_count);
break;
}
}
printf("Found %d frame%s (%d NAL unit%s)\n",
access_unit_count,(access_unit_count==1?"":"s"),
context->nac->count,(context->nac->count==1?"":"s"));
fprint_msg("Found %d frame%s (%d NAL unit%s)\n",
access_unit_count,(access_unit_count==1?"":"s"),
context->nac->count,(context->nac->count==1?"":"s"));
if (count_types)
{
if (slice_categories[I_NON_REF] > 0)
{
printf("Non-reference frames:\n");
print_msg("Non-reference frames:\n");
if (slice_types[I_NON_REF][I_SLICE_I] != 0)
printf(" I frames %7d\n",slice_types[I_NON_REF][I_SLICE_I]);
fprint_msg(" I frames %7d\n",slice_types[I_NON_REF][I_SLICE_I]);
if (slice_types[I_NON_REF][I_SLICE_P] != 0)
printf(" P frames %7d\n",slice_types[I_NON_REF][I_SLICE_P]);
fprint_msg(" P frames %7d\n",slice_types[I_NON_REF][I_SLICE_P]);
if (slice_types[I_NON_REF][I_SLICE_B] != 0)
printf(" B frames %7d\n",slice_types[I_NON_REF][I_SLICE_B]);
fprint_msg(" B frames %7d\n",slice_types[I_NON_REF][I_SLICE_B]);
if (slice_types[I_NON_REF][I_SLICE_MIX] != 0)
printf(" Mixed/other %7d\n",slice_types[I_NON_REF][I_SLICE_MIX]);
fprint_msg(" Mixed/other %7d\n",slice_types[I_NON_REF][I_SLICE_MIX]);
}
if (slice_categories[I_REF_IDR] > 0)
{
printf("IDR frames\n");
print_msg("IDR frames\n");
if (slice_types[I_REF_IDR][I_SLICE_I] != 0)
printf(" I frames %7d\n",slice_types[I_REF_IDR][I_SLICE_I]);
fprint_msg(" I frames %7d\n",slice_types[I_REF_IDR][I_SLICE_I]);
if (slice_types[I_REF_IDR][I_SLICE_P] != 0)
printf(" P frames %7d\n",slice_types[I_REF_IDR][I_SLICE_P]);
fprint_msg(" P frames %7d\n",slice_types[I_REF_IDR][I_SLICE_P]);
if (slice_types[I_REF_IDR][I_SLICE_B] != 0)
printf(" B frames %7d\n",slice_types[I_REF_IDR][I_SLICE_B]);
fprint_msg(" B frames %7d\n",slice_types[I_REF_IDR][I_SLICE_B]);
if (slice_types[I_REF_IDR][I_SLICE_MIX] != 0)
printf(" Mixed/other %7d\n",slice_types[I_REF_IDR][I_SLICE_MIX]);
fprint_msg(" Mixed/other %7d\n",slice_types[I_REF_IDR][I_SLICE_MIX]);
}
if (slice_categories[I_REF_NON_IDR] > 0)
{
printf("Non-IDR reference frames:\n");
print_msg("Non-IDR reference frames:\n");
if (slice_types[I_REF_NON_IDR][I_SLICE_I] != 0)
printf(" I frames %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_I]);
fprint_msg(" I frames %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_I]);
if (slice_types[I_REF_NON_IDR][I_SLICE_P] != 0)
printf(" P frames %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_P]);
fprint_msg(" P frames %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_P]);
if (slice_types[I_REF_NON_IDR][I_SLICE_B] != 0)
printf(" B frames %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_B]);
fprint_msg(" B frames %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_B]);
if (slice_types[I_REF_NON_IDR][I_SLICE_MIX] != 0)
printf(" Mixed/other %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_MIX]);
fprint_msg(" Mixed/other %7d\n",slice_types[I_REF_NON_IDR][I_SLICE_MIX]);
}
if (slice_categories[I_OTHER] > 0)
printf("Other frame types: %d\n",slice_categories[I_OTHER]);
fprint_msg("Other frame types: %d\n",slice_categories[I_OTHER]);
}
{
double total_seconds = access_unit_count / (double)FRAMES_PER_SECOND;
int minutes = (int)(total_seconds / 60);
double seconds = total_seconds - 60*minutes;
printf("At 25 frames/second, that is %dm %.1fs (%.2fs)\n",minutes,seconds,
total_seconds);
fprint_msg("At 25 frames/second, that is %dm %.1fs (%.2fs)\n",minutes,seconds,
total_seconds);
}
if (count_sizes && access_unit_count > 0)
printf("Frame sizes ranged from %u to %u bytes, mean %.2f\n",
min_frame_size,max_frame_size,
sum_frame_size/(double)access_unit_count);
fprint_msg("Frame sizes ranged from %u to %u bytes, mean %.2f\n",
min_frame_size,max_frame_size,
sum_frame_size/(double)access_unit_count);
printf("Frames with PTS associated: %u\n",num_with_PTS);
fprint_msg("Frames with PTS associated: %u\n",num_with_PTS);
free_access_unit_context(&context);
}
static void print_usage()
{
printf(
print_msg(
"Usage: esreport [switches] [<infile>]\n"
"\n"
);
REPORT_VERSION("esreport");
printf(
print_msg(
"\n"
" Report on the content of an elementary stream containing H.264\n"
" (MPEG-4/AVC), H.262 (MPEG-2) or AVS video data.\n"
@ -1148,8 +1145,8 @@ int main(int argc, char **argv)
}
else
{
fprintf(stderr,"### esreport: "
"Unrecognised command line switch '%s'\n",argv[ii]);
fprint_err("### esreport: "
"Unrecognised command line switch '%s'\n",argv[ii]);
return 1;
}
}
@ -1157,7 +1154,7 @@ int main(int argc, char **argv)
{
if (had_input_name)
{
fprintf(stderr,"### esreport: Unexpected '%s'\n",argv[ii]);
fprint_err("### esreport: Unexpected '%s'\n",argv[ii]);
return 1;
}
else
@ -1171,7 +1168,7 @@ int main(int argc, char **argv)
if (!had_input_name)
{
fprintf(stderr,"### esreport: No input file specified\n");
print_err("### esreport: No input file specified\n");
return 1;
}
@ -1179,7 +1176,7 @@ int main(int argc, char **argv)
force_stream_type,want_data,&is_data,&es);
if (err)
{
fprintf(stderr,"### esreport: Error opening input file\n");
print_err("### esreport: Error opening input file\n");
return 1;
}
@ -1224,14 +1221,14 @@ int main(int argc, char **argv)
}
else
{
fprintf(stderr,"### esreport: Unexpected type of video data\n");
print_err("### esreport: Unexpected type of video data\n");
return 1;
}
err = close_input_as_ES(input_name,&es);
if (err)
{
fprintf(stderr,"### esreport: Error closing input file\n");
print_err("### esreport: Error closing input file\n");
return 1;
}
return 0;

Wyświetl plik

@ -52,6 +52,7 @@
#include "pes_fns.h"
#include "reverse_fns.h"
#include "misc_fns.h"
#include "printing_fns.h"
#include "version.h"
#define DEBUG 0
@ -110,7 +111,7 @@ static int reverse_h262(ES_p es,
}
if (!quiet)
printf("\nScanning forwards\n");
print_msg("\nScanning forwards\n");
add_h262_reverse_context(hcontext,reverse_data);
err = collect_reverse_h262(hcontext,max,verbose,quiet);
@ -118,8 +119,8 @@ static int reverse_h262(ES_p es,
{
if (reverse_data->length > 0)
{
fprintf(stderr,"!!! Collected %d pictures and sequence headers,"
" continuing to reverse\n",reverse_data->length);
fprint_err("!!! Collected %d pictures and sequence headers,"
" continuing to reverse\n",reverse_data->length);
}
else
{
@ -135,17 +136,17 @@ static int reverse_h262(ES_p es,
int ii;
for (ii=0; ii<reverse_data->length; ii++)
if (reverse_data->seq_offset[ii])
printf("%3d: %4d at " OFFSET_T_FORMAT "/%d for %d\n",
ii,reverse_data->index[ii],
reverse_data->start_file[ii],
reverse_data->start_pkt[ii],
reverse_data->data_len[ii]);
fprint_msg("%3d: %4d at " OFFSET_T_FORMAT "/%d for %d\n",
ii,reverse_data->index[ii],
reverse_data->start_file[ii],
reverse_data->start_pkt[ii],
reverse_data->data_len[ii]);
else
printf("%3d: seqh at " OFFSET_T_FORMAT "/%d for %d\n",
ii,
reverse_data->start_file[ii],
reverse_data->start_pkt[ii],
reverse_data->data_len[ii]);
fprint_msg("%3d: seqh at " OFFSET_T_FORMAT "/%d for %d\n",
ii,
reverse_data->start_file[ii],
reverse_data->start_pkt[ii],
reverse_data->data_len[ii]);
}
if (!es->reading_ES)
write_program_data(es->reader,output.ts_output);
@ -160,7 +161,7 @@ static int reverse_h262(ES_p es,
}
if (!quiet)
printf("\nOutputting in reverse order\n");
print_msg("\nOutputting in reverse order\n");
if (as_TS)
err = output_in_reverse_as_TS(es,output.ts_output,frequency,verbose,quiet,
@ -172,19 +173,19 @@ static int reverse_h262(ES_p es,
if (!err && !quiet)
{
uint32_t final_index = reverse_data->index[reverse_data->first_written];
printf("\n");
printf("Summary\n");
printf("=======\n");
printf(" Considered Used Written\n");
printf("Pictures %10d %10d (%4.1f%%) %10d (%4.1f%%)\n",
final_index,reverse_data->pictures_kept,
100*(((double)reverse_data->pictures_kept)/final_index),
reverse_data->pictures_written,
100*(((double)reverse_data->pictures_written)/final_index));
print_msg("\n");
print_msg("Summary\n");
print_msg("=======\n");
print_msg(" Considered Used Written\n");
fprint_msg("Pictures %10d %10d (%4.1f%%) %10d (%4.1f%%)\n",
final_index,reverse_data->pictures_kept,
100*(((double)reverse_data->pictures_kept)/final_index),
reverse_data->pictures_written,
100*(((double)reverse_data->pictures_written)/final_index));
if (frequency != 0)
printf("Target (pictures) . %10d (%4.1f%%) at requested"
" frequency %d\n",final_index/frequency,100.0/frequency,
frequency);
fprint_msg("Target (pictures) . %10d (%4.1f%%) at requested"
" frequency %d\n",final_index/frequency,100.0/frequency,
frequency);
}
free_reverse_data(&reverse_data);
@ -215,15 +216,15 @@ static int output_parameter_sets(WRITER output,
uint32_t length = seq_param_dict->data_lens[ii];
byte *data = NULL;
if (!quiet)
printf("Writing out sequence parameter set %d\n",
seq_param_dict->ids[ii]);
fprint_msg("Writing out sequence parameter set %d\n",
seq_param_dict->ids[ii]);
err = read_ES_data(nac->es,posn,length,NULL,&data);
if (err)
{
fprintf(stderr,"### Error reading (sequence parameter set %d) data"
" from " OFFSET_T_FORMAT "/%d for %d\n",
seq_param_dict->ids[ii],posn.infile,posn.inpacket,length);
fprint_err("### Error reading (sequence parameter set %d) data"
" from " OFFSET_T_FORMAT "/%d for %d\n",
seq_param_dict->ids[ii],posn.infile,posn.inpacket,length);
return 1;
}
err = write_packet_data(output,as_TS,data,length,DEFAULT_VIDEO_PID,
@ -231,8 +232,8 @@ static int output_parameter_sets(WRITER output,
free(data);
if (err)
{
fprintf(stderr,"### Error writing out (sequence parameter set %d)"
"data\n",seq_param_dict->ids[ii]);
fprint_err("### Error writing out (sequence parameter set %d)"
"data\n",seq_param_dict->ids[ii]);
return 1;
}
}
@ -243,15 +244,15 @@ static int output_parameter_sets(WRITER output,
uint32_t length = pic_param_dict->data_lens[ii];
byte *data = NULL;
if (!quiet)
printf("Writing out picture parameter set %d\n",
pic_param_dict->ids[ii]);
fprint_msg("Writing out picture parameter set %d\n",
pic_param_dict->ids[ii]);
err = read_ES_data(nac->es,posn,length,NULL,&data);
if (err)
{
fprintf(stderr,"### Error reading (picture parameter set %d) data"
" from " OFFSET_T_FORMAT "/%d for %d\n",
pic_param_dict->ids[ii],posn.infile,posn.inpacket,length);
fprint_err("### Error reading (picture parameter set %d) data"
" from " OFFSET_T_FORMAT "/%d for %d\n",
pic_param_dict->ids[ii],posn.infile,posn.inpacket,length);
return 1;
}
err = write_packet_data(output,as_TS,data,length,DEFAULT_VIDEO_PID,
@ -259,8 +260,8 @@ static int output_parameter_sets(WRITER output,
free(data);
if (err)
{
fprintf(stderr,"### Error writing out (picture parameter set %d)"
"data\n",pic_param_dict->ids[ii]);
fprint_err("### Error writing out (picture parameter set %d)"
"data\n",pic_param_dict->ids[ii]);
return 1;
}
}
@ -295,7 +296,7 @@ static int reverse_access_units(ES_p es,
}
if (!quiet)
printf("\nScanning forwards\n");
print_msg("\nScanning forwards\n");
add_access_unit_reverse_context(acontext,reverse_data);
err = collect_reverse_access_units(acontext,max,verbose,quiet);
@ -303,8 +304,8 @@ static int reverse_access_units(ES_p es,
{
if (reverse_data->length > 0)
{
fprintf(stderr,"!!! Collected %d access units,"
" continuing to reverse\n",reverse_data->length);
fprint_err("!!! Collected %d access units,"
" continuing to reverse\n",reverse_data->length);
}
else
{
@ -319,11 +320,11 @@ static int reverse_access_units(ES_p es,
{
int ii;
for (ii=0; ii<reverse_data->length; ii++)
printf("%3d: %4d at " OFFSET_T_FORMAT "/%d for %d\n",
ii,reverse_data->index[ii],
reverse_data->start_file[ii],
reverse_data->start_pkt[ii],
reverse_data->data_len[ii]);
fprint_msg("%3d: %4d at " OFFSET_T_FORMAT "/%d for %d\n",
ii,reverse_data->index[ii],
reverse_data->start_file[ii],
reverse_data->start_pkt[ii],
reverse_data->data_len[ii]);
}
//if (!es->reading_ES)
// write_program_data(es->reader,output.ts_output);
@ -340,7 +341,7 @@ static int reverse_access_units(ES_p es,
// Before outputting any reverse data, it's a good idea to write out the
// picture parameter set(s) and sequence parameter set(s)
if (!quiet)
printf("\nPreparing to output reverse data\n");
print_msg("\nPreparing to output reverse data\n");
err = output_parameter_sets(output,acontext,as_TS,quiet);
if (err)
{
@ -350,7 +351,7 @@ static int reverse_access_units(ES_p es,
}
if (!quiet)
printf("\nOutputting in reverse order\n");
print_msg("\nOutputting in reverse order\n");
if (as_TS)
err = output_in_reverse_as_TS(es,output.ts_output,frequency,verbose,quiet,
@ -361,19 +362,19 @@ static int reverse_access_units(ES_p es,
if (!err && !quiet)
{
uint32_t final_index = reverse_data->index[reverse_data->first_written];
printf("\n");
printf("Summary\n");
printf("=======\n");
printf(" Considered Used Written\n");
printf("Access units %10d %10d (%4.1f%%) %10d (%4.1f%%)\n",
final_index,reverse_data->pictures_kept,
100*(((double)reverse_data->pictures_kept)/final_index),
reverse_data->pictures_written,
100*(((double)reverse_data->pictures_written)/final_index));
print_msg("\n");
print_msg("Summary\n");
print_msg("=======\n");
print_msg(" Considered Used Written\n");
fprint_msg("Access units %10d %10d (%4.1f%%) %10d (%4.1f%%)\n",
final_index,reverse_data->pictures_kept,
100*(((double)reverse_data->pictures_kept)/final_index),
reverse_data->pictures_written,
100*(((double)reverse_data->pictures_written)/final_index));
if (frequency != 0)
printf("Target (access units) . %10d (%4.1f%%) at requested"
" frequency %d\n",final_index/frequency,100.0/frequency,
frequency);
fprint_msg("Target (access units) . %10d (%4.1f%%) at requested"
" frequency %d\n",final_index/frequency,100.0/frequency,
frequency);
}
free_reverse_data(&reverse_data);
free_access_unit_context(&acontext);
@ -382,12 +383,12 @@ static int reverse_access_units(ES_p es,
static void print_usage()
{
printf(
print_msg(
"Usage: esreverse [switches] [<infile>] [<outfile>]\n"
"\n"
);
REPORT_VERSION("esreverse");
printf(
print_msg(
"\n"
" Output a reversed stream derived from the input H.264 (MPEG-4/AVC)\n"
" or H.262 (MPEG-2) elementary stream.\n"
@ -545,8 +546,8 @@ int main(int argc, char **argv)
}
else
{
fprintf(stderr,"### esreverse: "
"Unrecognised command line switch '%s'\n",argv[ii]);
fprint_err("### esreverse: "
"Unrecognised command line switch '%s'\n",argv[ii]);
return 1;
}
}
@ -554,7 +555,7 @@ int main(int argc, char **argv)
{
if (had_input_name && had_output_name)
{
fprintf(stderr,"### esreverse: Unexpected '%s'\n",argv[ii]);
fprint_err("### esreverse: Unexpected '%s'\n",argv[ii]);
return 1;
}
else if (had_input_name)
@ -573,12 +574,12 @@ int main(int argc, char **argv)
if (!had_input_name)
{
fprintf(stderr,"### esreverse: No input file specified\n");
print_err("### esreverse: No input file specified\n");
return 1;
}
if (!had_output_name)
{
fprintf(stderr,"### esreverse: No output file specified\n");
print_err("### esreverse: No output file specified\n");
return 1;
}
@ -593,7 +594,7 @@ int main(int argc, char **argv)
force_stream_type,want_data,&is_data,&es);
if (err)
{
fprintf(stderr,"### esreverse: Error opening input file\n");
print_err("### esreverse: Error opening input file\n");
return 1;
}
@ -603,7 +604,7 @@ int main(int argc, char **argv)
stream_type = AVC_VIDEO_STREAM_TYPE;
else
{
fprintf(stderr,"### esreverse: Unexpected type of video data\n");
print_err("### esreverse: Unexpected type of video data\n");
return 1;
}
@ -617,7 +618,7 @@ int main(int argc, char **argv)
err = tswrite_open(TS_W_FILE,output_name,NULL,0,quiet,&(output.ts_output));
if (err)
{
fprintf(stderr,"### esreverse: Unable to open %s\n",output_name);
fprint_err("### esreverse: Unable to open %s\n",output_name);
(void) close_input_as_ES(input_name,&es);
return 1;
}
@ -627,23 +628,23 @@ int main(int argc, char **argv)
output.es_output = fopen(output_name,"wb");
if (output.es_output == NULL)
{
fprintf(stderr,"### esreverse: Unable to open output file %s: %s\n",
output_name,strerror(errno));
fprint_err("### esreverse: Unable to open output file %s: %s\n",
output_name,strerror(errno));
(void) close_input_as_ES(input_name,&es);
return 1;
}
if (!quiet)
printf("Writing to %s\n",output_name);
fprint_msg("Writing to %s\n",output_name);
}
if (!quiet)
{
if (as_TS)
printf("Writing as Transport Stream\n");
printf("Filtering freqency %d\n",frequency);
print_msg("Writing as Transport Stream\n");
fprint_msg("Filtering freqency %d\n",frequency);
if (max)
printf("Stopping as soon after %d %s as possible\n",max,
(is_data == VIDEO_H262?"MPEG2 items":"NAL units"));
fprint_msg("Stopping as soon after %d %s as possible\n",max,
(is_data == VIDEO_H262?"MPEG2 items":"NAL units"));
}
if (use_pes)
@ -668,8 +669,8 @@ int main(int argc, char **argv)
if (use_pes)
{
if (!quiet)
printf("Using transport stream id 1, PMT PID %#x, program 1 ="
" PID %#x\n",DEFAULT_PMT_PID,DEFAULT_VIDEO_PID);
fprint_msg("Using transport stream id 1, PMT PID %#x, program 1 ="
" PID %#x\n",DEFAULT_PMT_PID,DEFAULT_VIDEO_PID);
set_PES_reader_program_data(es->reader,1,DEFAULT_PMT_PID,
DEFAULT_VIDEO_PID,
DEFAULT_AUDIO_PID, // not actually used
@ -681,15 +682,15 @@ int main(int argc, char **argv)
else
{
if (!quiet)
printf("Using transport stream id 1, PMT PID %#x, program 1 ="
" PID %#x, stream type %#x\n",DEFAULT_PMT_PID,DEFAULT_VIDEO_PID,
stream_type);
fprint_msg("Using transport stream id 1, PMT PID %#x, program 1 ="
" PID %#x, stream type %#x\n",DEFAULT_PMT_PID,DEFAULT_VIDEO_PID,
stream_type);
err = write_TS_program_data(output.ts_output,
1,1,DEFAULT_PMT_PID,DEFAULT_VIDEO_PID,
stream_type);
if (err)
{
fprintf(stderr,"### esreverse: Error writing out TS program data\n");
print_err("### esreverse: Error writing out TS program data\n");
(void) close_input_as_ES(input_name,&es);
if (as_TS)
(void) tswrite_close(output.ts_output,TRUE);
@ -697,9 +698,8 @@ int main(int argc, char **argv)
{
err = fclose(output.es_output);
if (err)
fprintf(stderr,
"### esreverse: (Error closing output file %s: %s)\n",
output_name,strerror(errno));
fprint_err("### esreverse: (Error closing output file %s: %s)\n",
output_name,strerror(errno));
}
return 1;
}
@ -713,7 +713,7 @@ int main(int argc, char **argv)
if (err)
{
fprintf(stderr,"### esreverse: Error reversing input\n");
print_err("### esreverse: Error reversing input\n");
(void) close_input_as_ES(input_name,&es);
if (as_TS)
(void) tswrite_close(output.ts_output,TRUE);
@ -721,8 +721,8 @@ int main(int argc, char **argv)
{
err = fclose(output.es_output);
if (err)
fprintf(stderr,"### esreverse: (Error closing output file %s: %s)\n",
output_name,strerror(errno));
fprint_err("### esreverse: (Error closing output file %s: %s)\n",
output_name,strerror(errno));
}
return 1;
}
@ -733,8 +733,8 @@ int main(int argc, char **argv)
err = tswrite_close(output.ts_output,quiet);
if (err)
{
fprintf(stderr,"### esreverse: Error closing output file %s",
output_name);
fprint_err("### esreverse: Error closing output file %s",
output_name);
(void) close_input_as_ES(input_name,&es);
return 1;
}
@ -745,8 +745,8 @@ int main(int argc, char **argv)
err = fclose(output.es_output);
if (err)
{
fprintf(stderr,"### esreverse: Error closing output file %s: %s\n",
output_name,strerror(errno));
fprint_err("### esreverse: Error closing output file %s: %s\n",
output_name,strerror(errno));
(void) close_input_as_ES(input_name,&es);
return 1;
}
@ -755,7 +755,7 @@ int main(int argc, char **argv)
err = close_input_as_ES(input_name,&es);
if (err)
{
fprintf(stderr,"### esreverse: Error closing input file\n");
print_err("### esreverse: Error closing input file\n");
return 1;
}
return 0;

Wyświetl plik

@ -45,6 +45,7 @@
#include "accessunit_fns.h"
#include "h262_fns.h"
#include "misc_fns.h"
#include "printing_fns.h"
#include "filter_fns.h"
#define DEBUG 0
@ -63,7 +64,7 @@ static int new_h262_filter_context(h262_filter_context_p *fcontext)
h262_filter_context_p new = malloc(SIZEOF_H262_FILTER_CONTEXT);
if (new == NULL)
{
fprintf(stderr,"### Unable to allocate H.262 filter context\n");
print_err("### Unable to allocate H.262 filter context\n");
return 1;
}
new->h262 = NULL;
@ -177,7 +178,7 @@ static int new_h264_filter_context(h264_filter_context_p *fcontext)
h264_filter_context_p new = malloc(SIZEOF_H264_FILTER_CONTEXT);
if (new == NULL)
{
fprintf(stderr,"### Unable to allocate H.264 filter context\n");
print_err("### Unable to allocate H.264 filter context\n");
return 1;
}
@ -341,8 +342,8 @@ extern int get_next_stripped_h262_frame(h262_filter_context_p fcontext,
if (fcontext->filter)
{
fprintf(stderr,"### Calling get_next_stripped_h262_frame with a context"
" set for filtering\n");
print_err("### Calling get_next_stripped_h262_frame with a context"
" set for filtering\n");
return 1;
}
@ -363,7 +364,7 @@ extern int get_next_stripped_h262_frame(h262_filter_context_p fcontext,
}
else if (err)
{
fprintf(stderr,"### Error filtering H.262 frames\n");
print_err("### Error filtering H.262 frames\n");
return 1;
}
@ -380,8 +381,8 @@ extern int get_next_stripped_h262_frame(h262_filter_context_p fcontext,
else
*seq_hdr = NULL;
fcontext->new_seq_hdr = FALSE;
if (verbose) printf(">> %s picture \n",
(this_picture->picture_coding_type==1?"I":"P"));
if (verbose) fprint_msg(">> %s picture \n",
(this_picture->picture_coding_type==1?"I":"P"));
return 0;
}
else
@ -394,11 +395,11 @@ extern int get_next_stripped_h262_frame(h262_filter_context_p fcontext,
{
fcontext->last_seq_hdr = this_picture;
fcontext->new_seq_hdr = TRUE;
if (verbose) printf(">> First sequence header\n");
if (verbose) print_msg(">> First sequence header\n");
}
else if (!same_h262_picture(this_picture,fcontext->last_seq_hdr))
{
if (verbose) printf(">> Different sequence header\n");
if (verbose) print_msg(">> Different sequence header\n");
free_h262_picture(&fcontext->last_seq_hdr);
fcontext->last_seq_hdr = this_picture;
fcontext->new_seq_hdr = TRUE;
@ -406,7 +407,7 @@ extern int get_next_stripped_h262_frame(h262_filter_context_p fcontext,
else
{
fcontext->new_seq_hdr = FALSE;
if (verbose) printf(">> Identical sequence header\n");
if (verbose) print_msg(">> Identical sequence header\n");
free_h262_picture(&this_picture);
}
}
@ -467,8 +468,8 @@ extern int get_next_filtered_h262_frame(h262_filter_context_p fcontext,
if (!fcontext->filter)
{
fprintf(stderr,"### Calling get_next_filtered_h262_frame with a context"
" set for stripping\n");
print_err("### Calling get_next_filtered_h262_frame with a context"
" set for stripping\n");
return 1;
}
@ -494,7 +495,7 @@ extern int get_next_filtered_h262_frame(h262_filter_context_p fcontext,
}
else if (err)
{
fprintf(stderr,"### Error filtering H.262 frames\n");
print_err("### Error filtering H.262 frames\n");
fcontext->h262->add_fake_afd = FALSE;
return 1;
}
@ -516,7 +517,7 @@ extern int get_next_filtered_h262_frame(h262_filter_context_p fcontext,
// It is an I picture, but it is too soon
if (verbose)
{
printf("+++ %d/%d DROP: Too soon\n",fcontext->count,fcontext->freq);
fprint_msg("+++ %d/%d DROP: Too soon\n",fcontext->count,fcontext->freq);
}
}
else if (this_picture->picture_coding_type != 1)
@ -524,7 +525,7 @@ extern int get_next_filtered_h262_frame(h262_filter_context_p fcontext,
// It is not an I picture
if (verbose)
{
printf("+++ %d/%d DROP: %s picture\n",fcontext->count,fcontext->freq,
fprint_msg("+++ %d/%d DROP: %s picture\n",fcontext->count,fcontext->freq,
H262_PICTURE_CODING_STR(this_picture->picture_coding_type));
}
// But do we want to pad with (i.e., repeat) the previous I picture?
@ -534,7 +535,7 @@ extern int get_next_filtered_h262_frame(h262_filter_context_p fcontext,
int repeat = pictures_wanted - fcontext->frames_written;
if (repeat > 0 && fcontext->had_previous_picture)
{
if (verbose) printf(">>> output last picture again\n");
if (verbose) print_msg(">>> output last picture again\n");
free_h262_picture(&this_picture);
*seq_hdr = NULL;
*frame = NULL;
@ -548,7 +549,7 @@ extern int get_next_filtered_h262_frame(h262_filter_context_p fcontext,
// It was an I picture, and not too soon
if (verbose)
{
printf("+++ %d/%d KEEP\n",fcontext->count,fcontext->freq);
fprint_msg("+++ %d/%d KEEP\n",fcontext->count,fcontext->freq);
}
fcontext->count = 0;
fcontext->had_previous_picture = TRUE;
@ -612,7 +613,7 @@ extern int get_next_stripped_h264_frame(h264_filter_context_p fcontext,
return COMMAND_RETURN_CODE;
if (verbose)
printf("\n");
print_msg("\n");
err = get_next_h264_frame(fcontext->access_unit_context,quiet,verbose,
&this_access_unit);
@ -629,14 +630,14 @@ extern int get_next_stripped_h264_frame(h264_filter_context_p fcontext,
// There seems little point in keeping the access unit
keep = FALSE;
if (verbose)
printf("++ DROP: no primary picture\n");
print_msg("++ DROP: no primary picture\n");
}
else if (this_access_unit->primary_start->nal_ref_idc == 0)
{
// This is not a reference frame, so it's of no interest
keep = FALSE;
if (verbose)
printf("++ DROP: not reference\n");
print_msg("++ DROP: not reference\n");
}
else if (fcontext->allref)
{
@ -646,13 +647,13 @@ extern int get_next_stripped_h264_frame(h264_filter_context_p fcontext,
{
keep = TRUE;
if (verbose)
printf("++ KEEP: reference picture\n");
print_msg("++ KEEP: reference picture\n");
}
else
{
keep = FALSE;
if (verbose)
printf("++ DROP: sequence or parameter set, etc.\n");
print_msg("++ DROP: sequence or parameter set, etc.\n");
}
}
else
@ -662,20 +663,20 @@ extern int get_next_stripped_h264_frame(h264_filter_context_p fcontext,
{
keep = TRUE;
if (verbose)
printf("++ KEEP: IDR picture\n");
print_msg("++ KEEP: IDR picture\n");
}
else if (this_access_unit->primary_start->nal_unit_type == NAL_NON_IDR &&
all_slices_I(this_access_unit))
{
keep = TRUE;
if (verbose)
printf("++ KEEP: all slices I\n");
print_msg("++ KEEP: all slices I\n");
}
else
{
keep = FALSE;
if (verbose)
printf("++ DROP: not IDR or all slices I\n");
print_msg("++ DROP: not IDR or all slices I\n");
}
}
@ -736,7 +737,7 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
return COMMAND_RETURN_CODE;
if (verbose)
printf("\n");
print_msg("\n");
err = get_next_h264_frame(fcontext->access_unit_context,quiet,verbose,
&this_access_unit);
@ -756,16 +757,16 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
// There seems little point in keeping the access unit
keep = FALSE;
if (verbose)
printf("++ %d/%d DROP: no primary picture\n",
fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d DROP: no primary picture\n",
fcontext->count,fcontext->freq);
}
else if (this_access_unit->primary_start->nal_ref_idc == 0)
{
// This is not a reference frame, so it's of no interest
keep = FALSE;
if (verbose)
printf("++ %d/%d DROP: not a reference frame\n",
fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d DROP: not a reference frame\n",
fcontext->count,fcontext->freq);
}
else if (this_access_unit->primary_start->nal_unit_type == NAL_IDR &&
fcontext->last_accepted_was_not_IDR)
@ -781,8 +782,8 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
fcontext->skipped_ref_pic = FALSE;
fcontext->last_accepted_was_not_IDR = FALSE;
if (verbose)
printf("++ %d/%d KEEP: IDR and last was not\n",
fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d KEEP: IDR and last was not\n",
fcontext->count,fcontext->freq);
}
else if (this_access_unit->primary_start->nal_unit_type == NAL_IDR &&
fcontext->not_had_IDR)
@ -793,8 +794,8 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
fcontext->skipped_ref_pic = FALSE;
fcontext->last_accepted_was_not_IDR = FALSE;
if (verbose)
printf("++ %d/%d KEEP: IDR and first IDR of filter run\n",
fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d KEEP: IDR and first IDR of filter run\n",
fcontext->count,fcontext->freq);
}
else if (fcontext->count < fcontext->freq)
{
@ -803,8 +804,8 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
keep = FALSE;
fcontext->skipped_ref_pic = TRUE;
if (verbose)
printf("++ %d/%d DROP: Too soon (skipping ref frame)\n",
fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d DROP: Too soon (skipping ref frame)\n",
fcontext->count,fcontext->freq);
}
else if (this_access_unit->primary_start->nal_unit_type == NAL_IDR)
{
@ -813,7 +814,7 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
fcontext->skipped_ref_pic = FALSE;
fcontext->last_accepted_was_not_IDR = FALSE;
if (verbose)
printf("++ %d/%d KEEP: IDR\n",fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d KEEP: IDR\n",fcontext->count,fcontext->freq);
}
else if (all_slices_I(this_access_unit))
{
@ -822,7 +823,7 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
keep = TRUE;
fcontext->last_accepted_was_not_IDR = TRUE;
if (verbose)
printf("++ %d/%d KEEP: I frame\n",fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d KEEP: I frame\n",fcontext->count,fcontext->freq);
}
else if (!fcontext->skipped_ref_pic && all_slices_I_or_P(this_access_unit))
{
@ -832,16 +833,16 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
keep = TRUE;
fcontext->last_accepted_was_not_IDR = TRUE;
if (verbose)
printf("++ %d/%d KEEP: P frame. no skipped ref frames\n",
fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d KEEP: P frame. no skipped ref frames\n",
fcontext->count,fcontext->freq);
}
else
{
keep = FALSE;
fcontext->skipped_ref_pic = TRUE;
if (verbose)
printf("++ %d/%d DROP: ref frame skipped earlier\n",
fcontext->count,fcontext->freq);
fprint_msg("++ %d/%d DROP: ref frame skipped earlier\n",
fcontext->count,fcontext->freq);
}
if (keep)
@ -860,7 +861,7 @@ extern int get_next_filtered_h264_frame(h264_filter_context_p fcontext,
int repeat = access_units_wanted - fcontext->frames_written;
if (repeat > 0 && fcontext->had_previous_access_unit)
{
if (verbose) printf(">>> output last access unit again\n");
if (verbose) print_msg(">>> output last access unit again\n");
free_access_unit(&this_access_unit);
*frame = NULL;
fcontext->frames_written ++;

Wyświetl plik

@ -41,6 +41,7 @@
#include "compat.h"
#include "misc_fns.h"
#include "printing_fns.h"
#include "l2audio_fns.h"
#define DEBUG 0
@ -152,7 +153,7 @@ static int peek_frame_header(const uint32_t header)
version = (header >> 19) & 0x03;
if (version == 1)
{
fprintf(stderr,"### Illegal version (1) in MPEG layer 2 audio header\n");
print_err("### Illegal version (1) in MPEG layer 2 audio header\n");
return -1;
}
version = (version == 3) ? 1: (version == 2) ? 2: 3;
@ -165,7 +166,7 @@ static int peek_frame_header(const uint32_t header)
layer = (header >> 17) & 0x03;
if (layer == 0)
{
fprintf(stderr,"### Illegal layer (0) in MPEG layer 2 audio header\n");
print_err("### Illegal layer (0) in MPEG layer 2 audio header\n");
return -1;
}
layer = 4 - layer;
@ -177,15 +178,15 @@ static int peek_frame_header(const uint32_t header)
bitrate_enc = (header >> 12) & 0x0f;
if (bitrate_enc == 0x0f)
{
fprintf(stderr,"### Illegal bitrate_enc (0x0f) in MPEG layer 2 audio header\n");
print_err("### Illegal bitrate_enc (0x0f) in MPEG layer 2 audio header\n");
return -1;
}
bitrate = (bitrate_table[version-1][layer-1])[bitrate_enc];
if (bitrate == 0) // bitrate now in kbits per channel
{
fprintf(stderr,"### Illegal bitrate (0 kbits/channel) in MPEG level 2"
" audio header\n");
print_err("### Illegal bitrate (0 kbits/channel) in MPEG level 2"
" audio header\n");
return -1;
}
@ -193,7 +194,7 @@ static int peek_frame_header(const uint32_t header)
sampling_enc = (header >> 10) & 0x03;
if (sampling_enc == 3)
{
fprintf(stderr,"### Illegal sampleing_enc (3) in MPEG layer 2 audio header\n");
print_err("### Illegal sampleing_enc (3) in MPEG layer 2 audio header\n");
return -1;
}
sampling = sampling_table[version-1][sampling_enc];
@ -249,7 +250,7 @@ static inline int build_audio_frame(audio_frame_p *frame)
audio_frame_p new = malloc(SIZEOF_AUDIO_FRAME);
if (new == NULL)
{
fprintf(stderr,"### Unable to allocate audio frame datastructure\n");
print_err("### Unable to allocate audio frame datastructure\n");
return 1;
}
@ -284,7 +285,7 @@ extern int read_next_l2audio_frame(int file,
offset_t posn = tell_file(file);
#if DEBUG
printf("Offset: " OFFSET_T_FORMAT "\n",posn);
fprint_msg("Offset: " OFFSET_T_FORMAT "\n",posn);
#endif
err = read_bytes(file,JUST_ENOUGH,header);
@ -292,28 +293,27 @@ extern int read_next_l2audio_frame(int file,
return EOF;
else if (err)
{
fprintf(stderr,"### Error reading header bytes of MPEG layer 2 audio frame\n");
fprintf(stderr," (in frame starting at " OFFSET_T_FORMAT ")\n",posn);
fprint_err("### Error reading header bytes of MPEG layer 2 audio frame\n"
" (in frame starting at " OFFSET_T_FORMAT ")\n",posn);
free(data);
return 1;
}
#if DEBUG
printf("MPEG layer 2 frame\n");
print_msg("MPEG layer 2 frame\n");
print_data(TRUE,"Start",header,JUST_ENOUGH,JUST_ENOUGH);
#endif
while (header[0] != 0xFF || (header[1] & 0xe0) != 0xe0)
{
int skip = JUST_ENOUGH;
fprintf(stderr,
"### MPEG layer 2 audio frame does not start with '1111 1111 111x'\n"
" syncword - lost synchronisation?\n"
" Found 0x%X%X%X instead of 0xFFE\n",
(header[0] & 0xF0) >> 4,
(header[0] & 0x0F),
(header[1] & 0xe0) >> 4);
fprintf(stderr," (in frame starting at " OFFSET_T_FORMAT ")\n",posn);
fprint_err("### MPEG layer 2 audio frame does not start with '1111 1111 111x'\n"
" syncword - lost synchronisation?\n"
" Found 0x%X%X%X instead of 0xFFE\n",
(header[0] & 0xF0) >> 4,
(header[0] & 0x0F),
(header[1] & 0xe0) >> 4);
fprint_err(" (in frame starting at " OFFSET_T_FORMAT ")\n",posn);
do
{
err = read_bytes(file,1,header);
@ -330,20 +330,20 @@ extern int read_next_l2audio_frame(int file,
}
} while (!err);
if (err) return 1;
fprintf(stderr,"#################### Resuming after %d skipped bytes\n",skip);
fprint_err("#################### Resuming after %d skipped bytes\n",skip);
}
frame_length = peek_frame_header((header[1] << 16) | (header[2] << 8) | header[3]);
if (frame_length < 1)
{
fprintf(stderr,"### Bad MPEG layer 2 audio header\n");
print_err("### Bad MPEG layer 2 audio header\n");
return 1;
}
data = malloc(frame_length);
if (data == NULL)
{
fprintf(stderr,"### Unable to extend data buffer for MPEG layer 2 audio frame\n");
print_err("### Unable to extend data buffer for MPEG layer 2 audio frame\n");
free(data);
return 1;
}
@ -355,9 +355,9 @@ extern int read_next_l2audio_frame(int file,
if (err)
{
if (err == EOF)
fprintf(stderr,"### Unexpected EOF reading rest of MPEG layer 2 audio frame\n");
print_err("### Unexpected EOF reading rest of MPEG layer 2 audio frame\n");
else
fprintf(stderr,"### Error reading rest of MPEG layer 2 audio frame\n");
print_err("### Error reading rest of MPEG layer 2 audio frame\n");
free(data);
return 1;
}

Wyświetl plik

@ -42,6 +42,7 @@
#include "compat.h"
#include "ts_defns.h"
#include "misc_fns.h"
#include "printing_fns.h"
#include "version.h"
#define M2TS_PACKET_SIZE (4 + TS_PACKET_SIZE)
@ -111,10 +112,10 @@ static int extract_packets(int input, FILE * output,
{
packet_buffer = malloc(sizeof(struct _m2ts_packet_buffer));
/***DEBUG***/
printf("Allocated buffer @ 0x%08x\n", (unsigned int)packet_buffer);
fprint_msg("Allocated buffer @ 0x%08x\n", (unsigned int)packet_buffer);
if (packet_buffer == NULL)
{
fprintf(stderr, "### m2ts2ts: out of memory allocating M2TS packet buffer\n");
print_err( "### m2ts2ts: out of memory allocating M2TS packet buffer\n");
while (reorder_buffer_head != NULL)
{
packet_buffer = reorder_buffer_head->next;
@ -131,7 +132,7 @@ static int extract_packets(int input, FILE * output,
{
// End of file, no more to do, thank you and goodnight
if (!quiet)
printf("m2ts2ts: Reached end of file\n");
print_msg("m2ts2ts: Reached end of file\n");
break;
}
else if (err)
@ -149,21 +150,21 @@ static int extract_packets(int input, FILE * output,
}
parse_m2ts_packet(packet_buffer);
if (verbose)
printf("Read timestamp 0x%08x\n", packet_buffer->timestamp);
fprint_msg("Read timestamp 0x%08x\n", packet_buffer->timestamp);
// Insert the packet in the reorder buffer, in time order
// It's most likely that we'll get an up to date packet,
// so start at the tail and work to the front
p = reorder_buffer_tail;
if (p != NULL)
printf("tail timestamp = 0x%08x @ 0x%08x\n",
p->timestamp, (unsigned int)p);
fprint_msg("tail timestamp = 0x%08x @ 0x%08x\n",
p->timestamp, (unsigned int)p);
while (p != NULL && p->timestamp > packet_buffer->timestamp)
{
p = p->prev;
if (p != NULL)
printf("p timestamp = 0x%08x @ 0x%08x\n",
p->timestamp, (unsigned int)p);
fprint_msg("p timestamp = 0x%08x @ 0x%08x\n",
p->timestamp, (unsigned int)p);
}
if (p == NULL)
@ -199,23 +200,23 @@ static int extract_packets(int input, FILE * output,
else
{
if (verbose)
printf("Reordered packet timestamp=0x%08x\n",
packet_buffer->timestamp);
fprint_msg("Reordered packet timestamp=0x%08x\n",
packet_buffer->timestamp);
packet_buffer->next->prev = packet_buffer;
}
}
printf("### packet at 0x%08x, prev=0x%08x, next=0x%08x\n",
(unsigned int)packet_buffer,
(unsigned int)(packet_buffer->prev),
(unsigned int)(packet_buffer->next));
fprint_msg("### packet at 0x%08x, prev=0x%08x, next=0x%08x\n",
(unsigned int)packet_buffer,
(unsigned int)(packet_buffer->prev),
(unsigned int)(packet_buffer->next));
reorder_buffer_entries++;
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",
(unsigned int)reorder_buffer_head,
(unsigned int)(reorder_buffer_head->next));
fprint_msg("### queue head @ 0x%08x, next=0x%08x\n",
(unsigned int)reorder_buffer_head,
(unsigned int)(reorder_buffer_head->next));
packet_buffer = reorder_buffer_head;
reorder_buffer_head = reorder_buffer_head->next;
reorder_buffer_head->prev = NULL;
@ -224,8 +225,8 @@ static int extract_packets(int input, FILE * output,
if (written != 1)
{
// Major output catastrophe!
fprintf(stderr, "### m2ts2ts: Error writing TS packet: %s\n",
strerror(errno));
fprint_err( "### m2ts2ts: Error writing TS packet: %s\n",
strerror(errno));
free(packet_buffer);
while (reorder_buffer_head != NULL)
{
@ -239,7 +240,7 @@ static int extract_packets(int input, FILE * output,
reorder_buffer_entries--;
if (verbose)
printf("Written timestamp 0x%08x\n", packet_buffer->timestamp);
fprint_msg("Written timestamp 0x%08x\n", packet_buffer->timestamp);
packet_buffer_in_hand = packet_buffer;
}
}
@ -255,8 +256,8 @@ static int extract_packets(int input, FILE * output,
if (written != 1)
{
// So close...
fprintf(stderr, "### m2ts2ts: Error writing final TS packets: %s\n",
strerror(errno));
fprint_err( "### m2ts2ts: Error writing final TS packets: %s\n",
strerror(errno));
while (reorder_buffer_head != NULL)
{
packet_buffer = reorder_buffer_head->next;
@ -275,10 +276,10 @@ static int extract_packets(int input, FILE * output,
static void print_usage(void)
{
printf("Usage: m2ts2es [switches] [<infile>] [<outfile>]\n"
print_msg("Usage: m2ts2es [switches] [<infile>] [<outfile>]\n"
"\n");
REPORT_VERSION("m2ts2ts");
printf("\n"
print_msg("\n"
"Files:\n"
" <infile> is a BDAV MPEG-2 Transport Stream file (M2TS)\n"
" (but see -stdin)\n"
@ -360,8 +361,8 @@ int main(int argc, char *argv[])
}
else
{
fprintf(stderr, "### m2ts2ts: "
"Unrecognised command line switch '%s'\n", argv[ii]);
fprint_err( "### m2ts2ts: "
"Unrecognised command line switch '%s'\n", argv[ii]);
return 1;
}
}
@ -369,7 +370,7 @@ int main(int argc, char *argv[])
{
if (had_input_name && had_output_name)
{
fprintf(stderr, "### m2ts2ts: Unexpected '%s'\n", argv[ii]);
fprint_err( "### m2ts2ts: Unexpected '%s'\n", argv[ii]);
return 1;
}
else if (had_input_name) // and not had_output_name, inc "-stdout"
@ -388,13 +389,13 @@ int main(int argc, char *argv[])
if (!had_input_name)
{
fprintf(stderr, "### m2ts2ts: No input file specified\n");
print_err( "### m2ts2ts: No input file specified\n");
return 1;
}
if (!had_output_name)
{
fprintf(stderr, "### m2ts2ts: No output file specified\n");
print_err( "### m2ts2ts: No output file specified\n");
return 1;
}
@ -414,13 +415,13 @@ int main(int argc, char *argv[])
input = open_binary_file(input_name, FALSE);
if (input == -1)
{
fprintf(stderr, "### m2ts2ts: Unable to open input file %s\n",
input_name);
fprint_err( "### m2ts2ts: Unable to open input file %s\n",
input_name);
return 1;
}
}
if (!quiet)
printf("Reading from %s\n", (use_stdin ? "<stdin>" : input_name));
fprint_msg("Reading from %s\n", (use_stdin ? "<stdin>" : input_name));
if (use_stdout)
{
@ -433,19 +434,19 @@ int main(int argc, char *argv[])
{
if (!use_stdin)
(void) close_file(input);
fprintf(stderr, "### m2ts2ts: Unable to open output file %s: %s\n",
output_name, strerror(errno));
fprint_err( "### m2ts2ts: Unable to open output file %s: %s\n",
output_name, strerror(errno));
return 1;
}
}
if (!quiet)
printf("Writing to %s\n", (use_stdout ? "<stdout>" : output_name));
fprint_msg("Writing to %s\n", (use_stdout ? "<stdout>" : output_name));
err = extract_packets(input, output, reorder_buff_size, verbose, quiet);
if (err)
{
fprintf(stderr, "### m2ts2ts: Error extracting data\n");
print_err( "### m2ts2ts: Error extracting data\n");
if (!use_stdin) (void) close_file(input);
if (!use_stdout) (void) fclose(output);
return 1;
@ -458,8 +459,8 @@ int main(int argc, char *argv[])
err = fclose(output);
if (err)
{
fprintf(stderr, "### m2ts2ts: Error closing output file %s: %s\n",
output_name, strerror(errno));
fprint_err( "### m2ts2ts: Error closing output file %s: %s\n",
output_name, strerror(errno));
(void) close_file(input);
return 1;
}
@ -469,8 +470,8 @@ int main(int argc, char *argv[])
{
err = close_file(input);
if (err)
fprintf(stderr, "### m2ts2ts: Error closing input file %s\n",
input_name);
fprint_err( "### m2ts2ts: Error closing input file %s\n",
input_name);
}
return 0;
}

327
nalunit.c
Wyświetl plik

@ -44,6 +44,7 @@
#include "bitdata_fns.h"
#include "nalunit_fns.h"
#include "misc_fns.h"
#include "printing_fns.h"
#define DEBUG 0
@ -74,7 +75,7 @@ extern int build_nal_unit_context(ES_p es,
nal_unit_context_p new = malloc(SIZEOF_NAL_UNIT_CONTEXT);
if (new == NULL)
{
fprint_err("### Unable to allocate NAL unit context datastructure\n");
print_err("### Unable to allocate NAL unit context datastructure\n");
return 1;
}
new->es = es;
@ -150,14 +151,14 @@ extern int build_nal_unit(nal_unit_p *nal)
nal_unit_p new = malloc(SIZEOF_NAL_UNIT);
if (new == NULL)
{
fprint_err("### Unable to allocate NAL unit datastructure\n");
print_err("### Unable to allocate NAL unit datastructure\n");
return 1;
}
err = setup_ES_unit(&(new->unit));
if (err)
{
fprint_err("### Unable to allocate NAL unit data buffer\n");
print_err("### Unable to allocate NAL unit data buffer\n");
free(new);
return 1;
}
@ -248,7 +249,7 @@ static int remove_emulation_prevention(byte data[],
tgt = malloc(data_len);
if (tgt == NULL)
{
fprint_err("### Cannot malloc RBSP target array\n");
print_err("### Cannot malloc RBSP target array\n");
return 1;
}
@ -291,7 +292,7 @@ static inline int prepare_rbsp(nal_unit_p nal)
&(nal->rbsp),&(nal->rbsp_len));
if (err)
{
fprint_err("### Error removing emulation prevention bytes\n");
print_err("### Error removing emulation prevention bytes\n");
return 1;
}
}
@ -299,7 +300,7 @@ static inline int prepare_rbsp(nal_unit_p nal)
err = build_bitdata(&bd,nal->rbsp,nal->rbsp_len);
if (err)
{
fprint_err("### Unable to build bitdata datastructure for NAL RBSP\n");
print_err("### Unable to build bitdata datastructure for NAL RBSP\n");
return 1;
}
nal->bit_data = bd;
@ -347,16 +348,16 @@ static int read_slice_data(nal_unit_p nal,
if (show_nal_details)
{
printf("@@ NAL " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
printf(" first_mb_in_slice %u, slice_type %u (%s),"
" pic_parameter_set_id %d\n",data->first_mb_in_slice,
data->slice_type,NAL_SLICE_TYPE_STR(data->slice_type),
data->pic_parameter_set_id);
fprint_msg("@@ NAL " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
fprint_msg(" first_mb_in_slice %u, slice_type %u (%s),"
" pic_parameter_set_id %d\n",data->first_mb_in_slice,
data->slice_type,NAL_SLICE_TYPE_STR(data->slice_type),
data->pic_parameter_set_id);
}
// If we don't have sequence/parameter sets, then we can't go any
@ -381,15 +382,15 @@ static int read_slice_data(nal_unit_p nal,
data->seq_param_set_pic_order_cnt_type = seq_param_data->pic_order_cnt_type;
if (show_nal_details)
printf(" seq_param_set->pic_order_cnt_type %u\n",
data->seq_param_set_pic_order_cnt_type);
fprint_msg(" seq_param_set->pic_order_cnt_type %u\n",
data->seq_param_set_pic_order_cnt_type);
err = read_bits(bd,seq_param_data->log2_max_frame_num,&data->frame_num);
CHECK("frame_num");
if (show_nal_details)
printf(" frame_num %u (%d bits)\n",data->frame_num,
seq_param_data->log2_max_frame_num);
fprint_msg(" frame_num %u (%d bits)\n",data->frame_num,
seq_param_data->log2_max_frame_num);
data->field_pic_flag = 0; // value if not present - i.e., a frame
data->bottom_field_flag = 0;
@ -399,14 +400,14 @@ static int read_slice_data(nal_unit_p nal,
err = read_bit(bd,&data->field_pic_flag);
CHECK("field_pic_flag");
if (show_nal_details)
printf(" field_pic_flag %d\n",data->field_pic_flag);
fprint_msg(" field_pic_flag %d\n",data->field_pic_flag);
if (data->field_pic_flag)
{
data->bottom_field_flag_present = TRUE;
err = read_bit(bd,&data->bottom_field_flag);
CHECK("bottom_field_flag");
if (show_nal_details)
printf(" bottom_field_flag %d\n",data->bottom_field_flag);
fprint_msg(" bottom_field_flag %d\n",data->bottom_field_flag);
}
}
@ -415,7 +416,7 @@ static int read_slice_data(nal_unit_p nal,
err = read_exp_golomb(bd,&data->idr_pic_id);
CHECK("idr_pic_id");
if (show_nal_details)
printf(" idr_pic_id %u\n",data->idr_pic_id);
fprint_msg(" idr_pic_id %u\n",data->idr_pic_id);
}
data->delta_pic_order_cnt_bottom = 0; // value if not present
@ -432,11 +433,11 @@ static int read_slice_data(nal_unit_p nal,
CHECK("delta_pic_order_cnt_bottom");
}
if (show_nal_details)
printf(" pic_order_cnt_lsb %u (%d bits)\n"
" delta_pic_order_cnt_bottom %d\n",
data->pic_order_cnt_lsb,
seq_param_data->log2_max_pic_order_cnt_lsb,
data->delta_pic_order_cnt_bottom);
fprint_msg(" pic_order_cnt_lsb %u (%d bits)\n"
" delta_pic_order_cnt_bottom %d\n",
data->pic_order_cnt_lsb,
seq_param_data->log2_max_pic_order_cnt_lsb,
data->delta_pic_order_cnt_bottom);
}
else if (seq_param_data->pic_order_cnt_type == 1 &&
!seq_param_data->delta_pic_order_always_zero_flag)
@ -444,14 +445,14 @@ static int read_slice_data(nal_unit_p nal,
err = read_signed_exp_golomb(bd,&data->delta_pic_order_cnt[0]);
CHECK("delta_pic_order_cnt[0]");
if (show_nal_details)
printf(" delta_pic_order_cnt[0] %d\n",data->delta_pic_order_cnt[0]);
fprint_msg(" delta_pic_order_cnt[0] %d\n",data->delta_pic_order_cnt[0]);
if (pic_param_data->pic_order_present_flag && !data->field_pic_flag)
{
err = read_signed_exp_golomb(bd,&data->delta_pic_order_cnt[1]);
CHECK("delta_pic_order_cnt[1]");
if (show_nal_details)
printf(" delta_pic_order_cnt[1] %d\n",data->delta_pic_order_cnt[1]);
fprint_msg(" delta_pic_order_cnt[1] %d\n",data->delta_pic_order_cnt[1]);
}
}
@ -467,7 +468,7 @@ static int read_slice_data(nal_unit_p nal,
err = read_exp_golomb(bd,&data->redundant_pic_cnt);
CHECK("redundant_pic_cnt");
if (show_nal_details)
printf(" redundant_pic_cnt %u\n",data->redundant_pic_cnt);
fprint_msg(" redundant_pic_cnt %u\n",data->redundant_pic_cnt);
}
nal->decoded = TRUE;
@ -502,11 +503,11 @@ static int read_pic_param_set_data(nal_unit_p nal,
byte constrained_intra_pred_flag;
#undef CHECK
#define CHECK(name) \
if (err) \
{ \
fprint_err("### Error reading %s field from picture parameter set\n", \
(name)); \
#define CHECK(name) \
if (err) \
{ \
fprint_err("### Error reading %s field from picture parameter set\n",\
(name)); \
}
// We need to know the id of this picture parameter set, and also
@ -526,17 +527,17 @@ static int read_pic_param_set_data(nal_unit_p nal,
if (show_nal_details)
{
printf("@@ PPS " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
printf(" pic_parameter_set_id %d, seq_parameter_set_id %d\n",
data->pic_parameter_set_id,data->seq_parameter_set_id);
printf(" entropy_coding_mode_flag %d\n",
data->entropy_coding_mode_flag);
printf(" pic_order_present_flag %d\n",data->pic_order_present_flag);
fprint_msg("@@ PPS " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
fprint_msg(" pic_parameter_set_id %d, seq_parameter_set_id %d\n",
data->pic_parameter_set_id,data->seq_parameter_set_id);
fprint_msg(" entropy_coding_mode_flag %d\n",
data->entropy_coding_mode_flag);
fprint_msg(" pic_order_present_flag %d\n",data->pic_order_present_flag);
}
// After this, we don't (at the moment) really need any of the rest.
@ -549,14 +550,14 @@ static int read_pic_param_set_data(nal_unit_p nal,
data->num_slice_groups ++;
if (show_nal_details)
printf(" num_slice_groups %u\n",data->num_slice_groups);
fprint_msg(" num_slice_groups %u\n",data->num_slice_groups);
if (data->num_slice_groups > 1)
{
err = read_exp_golomb(bd,&data->slice_group_map_type);
CHECK("slice_group_map_type");
if (show_nal_details)
printf(" slice_group_map_type %u\n",data->slice_group_map_type);
fprint_msg(" slice_group_map_type %u\n",data->slice_group_map_type);
if (data->slice_group_map_type == 0)
{
// NB: 0..num_slice_groups-1, not 0..num_slice_groups-1 - 1
@ -601,7 +602,7 @@ static int read_pic_param_set_data(nal_unit_p nal,
pic_size_in_map_units ++;
CHECK("pic_size_in_map_units");
if (show_nal_details)
printf(" pic_size_in_map_units %u\n",pic_size_in_map_units);
fprint_msg(" pic_size_in_map_units %u\n",pic_size_in_map_units);
size = (int) ceil(log2(data->num_slice_groups));
// Again, notice the range
for (ii=0; ii < pic_size_in_map_units; ii++)
@ -616,51 +617,51 @@ static int read_pic_param_set_data(nal_unit_p nal,
CHECK("num_ref_idx_10_active");
num_ref_idx_10_active ++;
if (show_nal_details)
printf(" num_ref_idx_10_active %u\n",num_ref_idx_10_active);
fprint_msg(" num_ref_idx_10_active %u\n",num_ref_idx_10_active);
err = read_exp_golomb(bd,&num_ref_idx_11_active); // minus 1
CHECK("num_ref_idx_11_active");
num_ref_idx_11_active ++;
if (show_nal_details)
printf(" num_ref_idx_11_active %u\n",num_ref_idx_11_active);
fprint_msg(" num_ref_idx_11_active %u\n",num_ref_idx_11_active);
err = read_bit(bd,&weighted_pred_flag);
CHECK("weighted_pred_flag");
if (show_nal_details)
printf(" weighted_pred_flag %d\n",weighted_pred_flag);
fprint_msg(" weighted_pred_flag %d\n",weighted_pred_flag);
err = read_bits(bd,2,&weighted_bipred_idc);
CHECK("weighted_bipred_idc");
if (show_nal_details)
printf(" weighted_bipred_idc %u\n",weighted_bipred_idc);
fprint_msg(" weighted_bipred_idc %u\n",weighted_bipred_idc);
err = read_signed_exp_golomb(bd,&pic_init_qp); // minus 26
CHECK("pic_init_qp");
pic_init_qp += 26;
if (show_nal_details)
printf(" pic_init_qp %d\n",pic_init_qp);
fprint_msg(" pic_init_qp %d\n",pic_init_qp);
err = read_signed_exp_golomb(bd,&pic_init_qs); // minus 26
CHECK("pic_init_qs");
pic_init_qs += 26;
if (show_nal_details)
printf(" pic_init_qs %d\n",pic_init_qs);
fprint_msg(" pic_init_qs %d\n",pic_init_qs);
err = read_signed_exp_golomb(bd,&chroma_qp_index_offset);
CHECK("chroma_qp_index_offset");
if (show_nal_details)
printf(" chroma_qp_index_offset %d\n",chroma_qp_index_offset);
fprint_msg(" chroma_qp_index_offset %d\n",chroma_qp_index_offset);
err = read_bit(bd,&deblocking_filter_control_present_flag);
CHECK("deblocking_filter_control_present_flag");
if (show_nal_details)
printf(" deblocking_filter_control_present_flag %d\n",
deblocking_filter_control_present_flag);
fprint_msg(" deblocking_filter_control_present_flag %d\n",
deblocking_filter_control_present_flag);
err = read_bit(bd,&constrained_intra_pred_flag);
CHECK("constrained_intra_pred_flag");
if (show_nal_details)
printf(" constrained_intra_pred_flag %d\n",constrained_intra_pred_flag);
fprint_msg(" constrained_intra_pred_flag %d\n",constrained_intra_pred_flag);
// We (sort of) care about redundant_pic_cnt_present_flag
// in that we need to know it if we are going to read the later bits
// of a slice header
err = read_bit(bd,&data->redundant_pic_cnt_present_flag);
CHECK("redundant_pic_cnt_present_flag");
if (show_nal_details)
printf(" redundant_pic_cnt_present_flag %d\n",
data->redundant_pic_cnt_present_flag);
fprint_msg(" redundant_pic_cnt_present_flag %d\n",
data->redundant_pic_cnt_present_flag);
nal->decoded = TRUE;
return 0;
@ -690,11 +691,11 @@ static int read_seq_param_set_data(nal_unit_p nal,
uint32_t pic_height_in_map_units;
#undef CHECK
#define CHECK(name) \
if (err) \
{ \
#define CHECK(name) \
if (err) \
{ \
fprint_err("### Error reading %s field from sequence parameter set\n",\
(name)); \
(name)); \
}
err = read_bits_into_byte(bd,8,&data->profile_idc);
@ -711,9 +712,9 @@ static int read_seq_param_set_data(nal_unit_p nal,
if (reserved_zero_5bits != 0)
{
fprint_err("### reserved_zero_5bits not zero (%d) in sequence"
" parameter set NAL unit at " OFFSET_T_FORMAT "/%d\n",
reserved_zero_5bits,
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket);
" parameter set NAL unit at " OFFSET_T_FORMAT "/%d\n",
reserved_zero_5bits,
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket);
print_data(FALSE," Data",nal->bit_data->data,nal->bit_data->data_len,
20);
// Should we carry on or give up? On the whole, if this is broken
@ -726,18 +727,18 @@ static int read_seq_param_set_data(nal_unit_p nal,
if (show_nal_details)
{
printf("@@ SPS " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
printf(" profile_idc %u, constraint set flags: %d %d %d\n",
data->profile_idc,
data->constraint_set0_flag,
data->constraint_set1_flag,
data->constraint_set2_flag);
printf(" level_idc %u\n",data->level_idc);
fprint_msg("@@ SPS " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
fprint_msg(" profile_idc %u, constraint set flags: %d %d %d\n",
data->profile_idc,
data->constraint_set0_flag,
data->constraint_set1_flag,
data->constraint_set2_flag);
fprint_msg(" level_idc %u\n",data->level_idc);
}
err = read_exp_golomb(bd,&temp);
@ -753,9 +754,9 @@ static int read_seq_param_set_data(nal_unit_p nal,
if (show_nal_details)
{
printf(" seq_parameter_set_id %u\n",data->seq_parameter_set_id);
printf(" log2_max_frame_num %u\n",data->log2_max_frame_num);
printf(" pic_order_cnt_type %u\n",data->pic_order_cnt_type);
fprint_msg(" seq_parameter_set_id %u\n",data->seq_parameter_set_id);
fprint_msg(" log2_max_frame_num %u\n",data->log2_max_frame_num);
fprint_msg(" pic_order_cnt_type %u\n",data->pic_order_cnt_type);
}
if (data->pic_order_cnt_type == 0)
@ -764,8 +765,8 @@ static int read_seq_param_set_data(nal_unit_p nal,
CHECK("log2_max_pic_order_cnt_lsb");
data->log2_max_pic_order_cnt_lsb += 4;
if (show_nal_details)
printf(" log2_max_pic_order_cnt_lsb %u\n",
data->log2_max_pic_order_cnt_lsb);
fprint_msg(" log2_max_pic_order_cnt_lsb %u\n",
data->log2_max_pic_order_cnt_lsb);
}
else if (data->pic_order_cnt_type == 1)
{
@ -777,8 +778,8 @@ static int read_seq_param_set_data(nal_unit_p nal,
err = read_bit(bd,&data->delta_pic_order_always_zero_flag);
CHECK("delta_pic_order_always_zero_flag");
if (show_nal_details)
printf(" delta_pic_order_always_zero_flag %d\n",
data->delta_pic_order_always_zero_flag);
fprint_msg(" delta_pic_order_always_zero_flag %d\n",
data->delta_pic_order_always_zero_flag);
err = read_signed_exp_golomb(bd,&offset_for_non_ref_pic);
CHECK("offset_for_non_ref_pic");
err = read_signed_exp_golomb(bd,&offset_for_top_to_bottom_field);
@ -797,28 +798,28 @@ static int read_seq_param_set_data(nal_unit_p nal,
err = read_exp_golomb(bd,&num_ref_frames);
CHECK("num_ref_frames");
if (show_nal_details)
printf(" num_ref_frames %u\n",num_ref_frames);
fprint_msg(" num_ref_frames %u\n",num_ref_frames);
err = read_bit(bd,&gaps_in_frame_num_value_allowed_flag);
CHECK("gaps_in_frame_num_value_allowed_flag");
if (show_nal_details)
if (show_nal_details)
printf(" gaps_in_frame_num_value_allowed_flag %d\n",
gaps_in_frame_num_value_allowed_flag);
fprint_msg(" gaps_in_frame_num_value_allowed_flag %d\n",
gaps_in_frame_num_value_allowed_flag);
err = read_exp_golomb(bd,&pic_width_in_mbs); // minus 1
CHECK("pic_width_in_mbs");
pic_width_in_mbs ++;
if (show_nal_details)
printf(" pic_width_in_mbs %u\n",pic_width_in_mbs);
fprint_msg(" pic_width_in_mbs %u\n",pic_width_in_mbs);
err = read_exp_golomb(bd,&pic_height_in_map_units); // minus 1
CHECK("pic_height_in_map_units");
pic_height_in_map_units ++;
if (show_nal_details)
printf(" pic_height_in_map_units %u\n",pic_height_in_map_units);
fprint_msg(" pic_height_in_map_units %u\n",pic_height_in_map_units);
// We care about frame_mbs_only_flag
err = read_bit(bd,&data->frame_mbs_only_flag);
CHECK("frame_mbs_only_flag");
if (show_nal_details)
printf(" frame_mbs_only_flag %d\n",data->frame_mbs_only_flag);
fprint_msg(" frame_mbs_only_flag %d\n",data->frame_mbs_only_flag);
nal->decoded = TRUE;
return 0;
@ -839,11 +840,11 @@ static int read_SEI_recovery_point(nal_unit_p nal,
uint32_t temp;
#undef CHECK
#define CHECK(name) \
if (err) \
{ \
#define CHECK(name) \
if (err) \
{ \
fprint_err("### Error reading %s field from SEI\n", \
(name)); \
(name)); \
}
err = read_exp_golomb(bd,&temp);
@ -861,9 +862,9 @@ static int read_SEI_recovery_point(nal_unit_p nal,
if (show_nal_details)
{
printf("@@ Recovery Point SEI\n");
printf(" recovery_frame_cnt %d\n exact_match_flag %d\n", data->recovery_frame_cnt, data->exact_match_flag);
printf(" broken_link_flag %d\n changing_slice_group_idc %d", data->broken_link_flag, data->changing_slice_group_idc);
print_msg("@@ Recovery Point SEI\n");
fprint_msg(" recovery_frame_cnt %d\n exact_match_flag %d\n", data->recovery_frame_cnt, data->exact_match_flag);
fprint_msg(" broken_link_flag %d\n changing_slice_group_idc %d", data->broken_link_flag, data->changing_slice_group_idc);
}
return 0;
@ -888,11 +889,11 @@ static int read_SEI(nal_unit_p nal,
uint32_t temp = 0;
#undef CHECK
#define CHECK(name) \
if (err) \
{ \
#define CHECK(name) \
if (err) \
{ \
fprint_err("### Error reading %s field from SEI\n", \
(name)); \
(name)); \
}
// read payloadtype (see H.264:7.3.2.3.1)
@ -969,22 +970,22 @@ static int read_rbsp_data(nal_unit_p nal,
else if (nal->nal_unit_type == 6) // SEI
err = read_SEI(nal,show_nal_details);
else if (show_nal_details)
printf("@@ nal " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
fprint_msg("@@ nal " OFFSET_T_FORMAT_08 "/%04d: size %d\n"
" nal_ref_idc %x nal_unit_type %02x (%s)\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket,
nal->data_len,
nal->nal_ref_idc,nal->nal_unit_type,
NAL_UNIT_TYPE_STR(nal->nal_unit_type));
if (err)
{
fprint_err("### Error reading RBSP data for %s NAL (ref idc %x,"
" unit type %x) at " OFFSET_T_FORMAT_08 "/%04d\n",
NAL_UNIT_TYPE_STR(nal->nal_unit_type),
nal->nal_ref_idc,
nal->nal_unit_type,
nal->unit.start_posn.infile,
nal->unit.start_posn.inpacket);
" unit type %x) at " OFFSET_T_FORMAT_08 "/%04d\n",
NAL_UNIT_TYPE_STR(nal->nal_unit_type),
nal->nal_ref_idc,
nal->nal_unit_type,
nal->unit.start_posn.infile,
nal->unit.start_posn.inpacket);
}
// At this point, we've finished with the actual RBSP data
@ -1103,8 +1104,8 @@ extern int nal_is_first_VCL_NAL(nal_unit_p nal,
if (!nal->decoded)
{
fprint_err("### Cannot decide if NAL unit is first VCL NAL\n"
" its RBSP data has not been interpreted\n");
print_err("### Cannot decide if NAL unit is first VCL NAL\n"
" its RBSP data has not been interpreted\n");
return FALSE;
}
@ -1263,13 +1264,13 @@ static void check_profile(nal_unit_p nal,
if (nal == NULL)
{
fprint_err("### Attempt to check profile on a NULL NAL unit\n");
print_err("### Attempt to check profile on a NULL NAL unit\n");
return;
}
else if (nal->nal_unit_type != 7)
{
fprint_err("### Attempt to check profile on a NAL unit that is not a "
"sequence parameter set\n");
print_err("### Attempt to check profile on a NAL unit that is not a "
"sequence parameter set\n");
report_nal(FALSE,nal);
return;
}
@ -1281,8 +1282,8 @@ static void check_profile(nal_unit_p nal,
int err = read_rbsp_data(nal,NULL,NULL,show_nal_details);
if (err)
{
fprint_err("### Error trying to decode RBSP for first sequence"
" parameter set\n");
print_err("### Error trying to decode RBSP for first sequence"
" parameter set\n");
return;
}
}
@ -1298,23 +1299,23 @@ static void check_profile(nal_unit_p nal,
{
int sum = data.constraint_set0_flag + data.constraint_set1_flag +
data.constraint_set2_flag;
fprint_err("\n");
print_err("\n");
fprint_err("Warning: This bitstream declares itself as %s profile (%d)",
name,data.profile_idc);
name,data.profile_idc);
if (sum == 0)
fprint_err(".\n");
print_err(".\n");
else
{
fprint_err(",\n");
fprint_err(" and as obeying the constraints of the");
if (data.constraint_set0_flag) fprint_err(" baseline");
if (data.constraint_set1_flag) fprint_err(" main");
if (data.constraint_set2_flag) fprint_err(" extended");
print_err(",\n");
print_err(" and as obeying the constraints of the");
if (data.constraint_set0_flag) print_err(" baseline");
if (data.constraint_set1_flag) print_err(" main");
if (data.constraint_set2_flag) print_err(" extended");
fprint_err(" profile%s.\n",(sum==1?"":"s"));
}
fprint_err(" This software does not support %s profile,\n",
name);
fprint_err(" and may give incorrect results or fail.\n\n");
name);
print_err(" and may give incorrect results or fail.\n\n");
return;
}
}
@ -1351,13 +1352,13 @@ extern int setup_NAL_data(int verbose,
if (forbidden_zero_bit)
{
fprint_err("### NAL forbidden_zero_bit is non-zero, at "
OFFSET_T_FORMAT "/%d\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket);
OFFSET_T_FORMAT "/%d\n",
nal->unit.start_posn.infile,nal->unit.start_posn.inpacket);
fprint_err(" First byte of NAL unit is %02x",nal->data[0]);
if (nal->data[0] == 0xB3)
fprint_err(", which is H.262 sequence header start code\n"
" Data may be MPEG-1 or MPEG-2");
fprint_err("\n");
print_err(", which is H.262 sequence header start code\n"
" Data may be MPEG-1 or MPEG-2");
print_err("\n");
return 1;
}
nal->nal_ref_idc = (nal->data[0] & 0x60) >> 5;
@ -1428,7 +1429,7 @@ extern int find_next_NAL_unit(nal_unit_context_p context,
(context->count) ++;
if (context->show_nal_details)
printf("\n");
print_msg("\n");
err = setup_NAL_data(verbose,*nal);
if (err)
@ -1468,7 +1469,7 @@ extern int find_next_NAL_unit(nal_unit_context_p context,
(*nal)->u.pic.pic_parameter_set_id,*nal);
if (err)
{
fprint_err("### Error remembering picture parameter set ");
print_err("### Error remembering picture parameter set ");
report_nal(FALSE,*nal);
free_nal_unit(nal);
return 1;
@ -1480,7 +1481,7 @@ extern int find_next_NAL_unit(nal_unit_context_p context,
(*nal)->u.seq.seq_parameter_set_id,*nal);
if (err)
{
fprint_err("### Error remembering sequence parameter set ");
print_err("### Error remembering sequence parameter set ");
report_nal(FALSE,*nal);
free_nal_unit(nal);
return 1;
@ -1504,7 +1505,7 @@ extern int write_NAL_unit_as_ES(FILE *output,
int err = write_ES_unit(output,&(nal->unit));
if (err)
{
fprint_err("### Error writing NAL unit as ES\n");
print_err("### Error writing NAL unit as ES\n");
return err;
}
else
@ -1533,7 +1534,7 @@ extern int write_NAL_unit_as_TS(TS_writer_p tswriter,
video_pid,DEFAULT_VIDEO_STREAM_ID);
if (err)
{
fprint_err("### Error writing NAL unit as TS\n");
print_err("### Error writing NAL unit as TS\n");
return err;
}
else
@ -1554,8 +1555,7 @@ extern int build_param_dict(param_dict_p *param_dict)
param_dict_p new = malloc(SIZEOF_PARAM_DICT);
if (new == NULL)
{
fprint_err("### Unable to allocate parameter 'dictionary'"
" datastructure\n");
print_err("### Unable to allocate parameter 'dictionary' datastructure\n");
return 1;
}
@ -1565,8 +1565,8 @@ extern int build_param_dict(param_dict_p *param_dict)
new->ids = malloc(sizeof(uint32_t)*NAL_PIC_PARAM_START_SIZE);
if (new->ids == NULL)
{
fprint_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
print_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
free(new);
return 1;
}
@ -1574,8 +1574,8 @@ extern int build_param_dict(param_dict_p *param_dict)
new->params = malloc(SIZEOF_NAL_INNARDS*NAL_PIC_PARAM_START_SIZE);
if (new->params == NULL)
{
fprint_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
print_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
free(new->ids);
free(new);
return 1;
@ -1584,8 +1584,8 @@ extern int build_param_dict(param_dict_p *param_dict)
new->posns = malloc(SIZEOF_ES_OFFSET*NAL_PIC_PARAM_START_SIZE);
if (new->posns == NULL)
{
fprint_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
print_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
free(new->params);
free(new->ids);
free(new);
@ -1595,8 +1595,8 @@ extern int build_param_dict(param_dict_p *param_dict)
new->data_lens = malloc(sizeof(uint32_t)*NAL_PIC_PARAM_START_SIZE);
if (new->data_lens == NULL)
{
fprint_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
print_err("### Unable to allocate array within 'dictionary'"
" datastructure\n");
free(new->params);
free(new->ids);
free(new);
@ -1680,27 +1680,27 @@ extern int remember_param_data(param_dict_p param_dict,
param_dict->ids = realloc(param_dict->ids,newsize*sizeof(uint32_t));
if (param_dict->ids == NULL)
{
fprint_err("### Unable to extend parameter set dictionary array\n");
print_err("### Unable to extend parameter set dictionary array\n");
return 1;
}
param_dict->params = realloc(param_dict->params,
newsize*SIZEOF_NAL_INNARDS);
if (param_dict->params == NULL)
{
fprint_err("### Unable to extend parameter set dictionary array\n");
print_err("### Unable to extend parameter set dictionary array\n");
return 1;
}
param_dict->posns = realloc(param_dict->params,newsize*SIZEOF_ES_OFFSET);
if (param_dict->posns == NULL)
{
fprint_err("### Unable to extend parameter set dictionary array\n");
print_err("### Unable to extend parameter set dictionary array\n");
return 1;
}
param_dict->data_lens = realloc(param_dict->params,
newsize*sizeof(uint32_t));
if (param_dict->data_lens == NULL)
{
fprint_err("### Unable to extend parameter set dictionary array\n");
print_err("### Unable to extend parameter set dictionary array\n");
return 1;
}
param_dict->size = newsize;
@ -1772,7 +1772,7 @@ extern int get_pic_param_data(param_dict_p pic_param_dict,
if (absent)
{
fprint_err("### Unable to find picture parameter set with id %u\n",
pic_param_id);
pic_param_id);
return 1;
}
*pic_param_data = &(innards->pic);
@ -1803,7 +1803,7 @@ extern int get_seq_param_data(param_dict_p seq_param_dict,
if (absent)
{
fprint_err("### Unable to find sequence parameter set with id %u\n",
seq_param_id);
seq_param_id);
return 1;
}
*seq_param_data = &(innards->seq);
@ -1829,7 +1829,7 @@ extern int build_nal_unit_list(nal_unit_list_p *list)
nal_unit_list_p new = malloc(SIZEOF_NAL_UNIT_LIST);
if (new == NULL)
{
fprint_err("### Unable to allocate NAL unit list datastructure\n");
print_err("### Unable to allocate NAL unit list datastructure\n");
return 1;
}
@ -1839,8 +1839,7 @@ extern int build_nal_unit_list(nal_unit_list_p *list)
if (new->array == NULL)
{
free(new);
fprint_err(
"### Unable to allocate array in NAL unit list datastructure\n");
print_err("### Unable to allocate array in NAL unit list datastructure\n");
return 1;
}
@ -1862,7 +1861,7 @@ extern int append_to_nal_unit_list(nal_unit_list_p list,
list->array = realloc(list->array,newsize*sizeof(nal_unit_p));
if (list->array == NULL)
{
fprint_err("### Unable to extend NAL unit list array\n");
print_err("### Unable to extend NAL unit list array\n");
return 1;
}
list->size = newsize;