📄 bs-stats.c
字号:
for (i=0; i<nil; i++) { if (strstr(argv[2], format_str(i))) break; } if (i==nil) { HARAKIRI("Invalid BS format type. Aborted\n", 5); } else bs_format = i; /* Move arg{c,v} over the option to the next argument */ argc -= 2; argv += 2; } else if (strcmp (argv[1], "-qq") == 0) { /* Disables creation of output ASCII file */ log = 0; /* Move arg{c,v} over the option to the next argument */ argc--; argv++; } else if (strcmp (argv[1], "-q") == 0) { /* Set quiet mode */ quiet = 1; /* Move arg{c,v} over the option to the next argument */ argc--; argv++; } else if (strcmp (argv[1], "-?") == 0) { display_usage(0); } else if (strstr(argv[1], "-help")) { display_usage(1); } else { fprintf (stderr, "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); display_usage (0); } } /* Get command line parameters */ GET_PAR_S (1, "_Input bit stream file ..................: ", ibs_file); if (log) { GET_PAR_S (2, "_Output ASCII file ......................: ", out_file); } /* Initializations */ memset(distr, 0, (int)MAX_FRAME * sizeof(long)); /* Starting frame is from 0 to number_of_frames-1 */ start_frame--; /* Open files */ if ((Fibs= fopen (ibs_file, RB)) == NULL) HARAKIRI ("Could not open input bitstream file\n", 1); if (strcmp(out_file,"-")==0) Fout=stdout; else if (log) { if ((Fout= fopen (out_file, WT)) == NULL) HARAKIRI ("Could not open output ASCII file\n", 1); }#ifdef DEBUG F = fopen ("ep.g192", WB); /* File to save the EP in G.192 format */#endif /* *** CHECK CONSISTENCY *** */ /* Do preliminary inspection in the INPUT BITSTREAM FILE to check its format (byte, bit, g192) */ i = check_eid_format(Fibs, ibs_file, &tmp_type); /* Check whether the specified BS format matches with the one in the file */ if (i != bs_format) { /* The input bitstream format is not the same as specified */ fprintf (stderr, "*** Switching bitstream format from %s to %s ***\n", format_str((int)bs_format), format_str(i)); bs_format = i; } /* Check whether the BS has a sync header */ if (tmp_type == FER) { /* The input BS may have a G.192 synchronism header - verify */ if (bs_format == g192) { short tmp[2]; /* Get presumed first G.192 sync header */ fread(tmp, sizeof(short), 2, Fibs); /* tmp[1] should have the frame length */ i = tmp[1]; /* advance file to the (presumed) next G.192 sync header */ fseek(Fibs, (long)(tmp[1])*sizeof(short), SEEK_CUR); /* get (presumed) next G.192 sync header */ fread(tmp, sizeof(short), 2, Fibs); /* Verify */ /* if (((tmp[0] & 0xFFF0) == 0x6B20) && (i == tmp[1])) */ if ((tmp[0] & 0xFFF0) == 0x6B20) { fr_len = i; sync_header = 1; if (i != tmp[1]) vbr = 1; } else sync_header = 0; } else if (bs_format == byte) { char tmp[2]; /* Get presumed first byte-wise G.192 sync header */ fread(tmp, sizeof(char), 2, Fibs); /* tmp[1] should have the frame length */ i = tmp[1]; /* advance file to the (presumed) next byte-wise G.192 sync header */ fseek(Fibs, (long)tmp[1], SEEK_CUR); /* get (presumed) next G.192 sync header */ fread(tmp, sizeof(char), 2, Fibs); /* Verify */ /* if (((tmp[0] & 0xF0) == 0x20) && (i == tmp[1])) */ if ((tmp[0] & 0xF0) == 0x20) { fr_len = i; sync_header = 1; if (i != tmp[1]) vbr = 1; } else sync_header = 0; } else sync_header = 0; /* Rewind file */ fseek(Fibs, 0l, SEEK_SET); } /* Can't work with compact or headerless bitstreams: abort */ if (bs_format == compact) HARAKIRI("Compact bitstreams are not supported by this program.\n", 6); if (!sync_header || fr_len == 0) HARAKIRI("Headerless bitstreams are not supported by this program.\n", 6); /* *** FINAL INITIALIZATIONS *** */ /* Use the proper data I/O functions */ read_data = bs_format==byte? read_byte : (bs_format==g192? read_g192 : read_bit_ber); /* Define BS sample size, in bytes */ ibs_sample_len = bs_format==byte? 1: (bs_format==g192? 2 : 0); /* Inspect the bitstream file for variable frame sizes */ while (!feof(Fibs)) { /* Move to position where next frame length value is expected */ fseek(Fibs, (long)(ibs_sample_len + offset), SEEK_CUR); /* Get (presumed) next G.192 sync header */ if ((items=read_data(&offset, 1l, Fibs))!=1) break; /* Increment conters in histogram */ distr[offset]++; /* Do we have a different frame length here? */ if (offset>max_fr) { max_fr = offset; no_sizes++; } if (offset<min_fr) { min_fr = offset; no_sizes++; } /* Write frame length to file, if enabled (default) */ if (log) { if (fprintf(Fout,"%d\n",offset)<=0) HARAKIRI("Error writing to output ASCII file\n", 5); } /* Increment frame counter */ frame_no++; /* Convert offset number read to no.of bytes */ offset *= ibs_sample_len; } /* Rewind file */ fseek(Fibs, 0l, SEEK_SET); /* Set the frame length to the maximum possible value */ fr_len = max_fr; /* Define how many samples are read for each frame */ /* Bitstream may have sync headers, which are 2 samples-long */ bs_len = sync_header? fr_len + 2 : fr_len; /* Save frame lengths in memory */ ori_bs_len = bs_len; ori_fr_len = fr_len; /* Allocate memory for data buffers */ if ((bs = (short *)calloc(bs_len, sizeof(short))) == NULL) HARAKIRI("Can't allocate memory for bitstream. Aborted.\n",6); /* Initializes to the start of the payload in input bitstream */ payload = sync_header? bs + 2: bs; /* *** PRINT SUMMARY OF OPTIONS & RESULTS ON SCREEN *** */ /* Restore frame lengths from memory (just in case they were changed) */ bs_len = ori_bs_len; fr_len = ori_fr_len; /* Print summary */ printf("# -----------------------------------------------------\n"); printf("# Bitstream file: ........... %s\n", ibs_file); if (log) printf("# Frame lengths saved in: ... %s\n", strcmp(out_file,"-")==0?"stdout":out_file); else printf("# Frame lengths NOT saved to a file\n"); printf("# Bitstream format %s...... : %s\n", sync_header? "(G.192 header) " : "(headerless) ..", format_str((int)bs_format)); printf("# Frame size count summary (total %ld frame sizes found):\n", no_sizes); for (i=0;i<MAX_FRAME;i++) { if (distr[i]) printf("# -Frame length %3ld count is %5ld\n",i,distr[i]); } printf("# Total number of frames: %.0f\n", frame_no);#ifdef DEBUG printf("# (MMR) Ratio between longest and shortest frame count is %7.3f\n", (double)distr[max_fr]/(double)distr[min_fr]);#endif printf("# (Act) Ratio between longest and total frame count is %7.3f\n", (double)distr[max_fr]/frame_no); printf("# (Efc) Ratio between shortest and total frame count is %7.3f\n", no_sizes==1?0.0:(double)distr[min_fr]/frame_no); /* *** FINALIZATIONS *** */ /* Free memory allocated */ free(bs); /* Close the output file and quit *** */ fclose (Fibs); if (log) fclose (Fout);#ifdef DEBUG fclose(F);#endif#ifndef VMS /* return value to OS if not VMS */ return 0;#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -