| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2002-2009, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: printsc.c $ |
|---|
| 11 | * $brcm_Revision: 2 $ |
|---|
| 12 | * $brcm_Date: 10/28/09 1:30p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /BSEAV/lib/bcmplayer/utils/printsc.c $ |
|---|
| 19 | * |
|---|
| 20 | * 2 10/28/09 1:30p erickson |
|---|
| 21 | * SW7405-3287: move common code to ts_utils |
|---|
| 22 | * |
|---|
| 23 | * Irvine_BSEAVSW_Devel/7 6/30/06 9:39a erickson |
|---|
| 24 | * PR21941: fix start code detection algorithm, and eliminate duplication |
|---|
| 25 | * by moving to ts_utils |
|---|
| 26 | * |
|---|
| 27 | * Irvine_BSEAVSW_Devel/6 1/6/06 10:16a erickson |
|---|
| 28 | * PR17108: updated for magnum basemodules and 64 bit cpus |
|---|
| 29 | * |
|---|
| 30 | * Irvine_BSEAVSW_Devel/5 9/2/05 12:24p erickson |
|---|
| 31 | * PR16138: defaulted to pes/es to make utils more consistent |
|---|
| 32 | * |
|---|
| 33 | * Irvine_BSEAVSW_Devel/4 8/19/05 3:59p erickson |
|---|
| 34 | * PR16208: fixed cmdline, print payload between sc's |
|---|
| 35 | * |
|---|
| 36 | * Irvine_BSEAVSW_Devel/3 8/8/05 3:58p erickson |
|---|
| 37 | * PR16138: added -pes and -es option |
|---|
| 38 | * |
|---|
| 39 | *************************************************************************/ |
|---|
| 40 | #include <stdlib.h> |
|---|
| 41 | #include <stdio.h> |
|---|
| 42 | #include <string.h> |
|---|
| 43 | #include <errno.h> |
|---|
| 44 | #include "ts_utils.h" |
|---|
| 45 | |
|---|
| 46 | int main(int argc, char **argv) { |
|---|
| 47 | FILE *fin = stdin; |
|---|
| 48 | int fileoffset = 0; |
|---|
| 49 | #define BUFSIZE 4096 |
|---|
| 50 | unsigned char buf[BUFSIZE]; |
|---|
| 51 | int sccount = 0; |
|---|
| 52 | int curarg = 1; |
|---|
| 53 | unsigned payload = 0; |
|---|
| 54 | int num_startcodes = 0; |
|---|
| 55 | |
|---|
| 56 | if (curarg < argc && !strcmp(argv[curarg], "--help")) { |
|---|
| 57 | printf("Usage: printsc [FILENAME]\n"); |
|---|
| 58 | exit(0); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | if (curarg < argc) { |
|---|
| 62 | fin = fopen(argv[curarg], "r"); |
|---|
| 63 | if (!fin) |
|---|
| 64 | return printf("Unable to open %s: %d\n", argv[curarg], errno); |
|---|
| 65 | } |
|---|
| 66 | else { |
|---|
| 67 | printf("Reading stdin\n"); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | while (!feof(fin)) { |
|---|
| 71 | int i, n; |
|---|
| 72 | |
|---|
| 73 | n = fread(buf, 1, BUFSIZE, fin); |
|---|
| 74 | if (n <= 0) break; |
|---|
| 75 | |
|---|
| 76 | for (i=0; i<n; i++) { |
|---|
| 77 | payload++; |
|---|
| 78 | if (sccount == 3) { |
|---|
| 79 | if (num_startcodes > 0) { |
|---|
| 80 | payload -= 4; /* subtract for 00 00 01 SC */ |
|---|
| 81 | printf(" payload %d\n", payload); /* from previous sc */ |
|---|
| 82 | } |
|---|
| 83 | printf("SC %02x at %#x\n", buf[i], fileoffset + i - 3); |
|---|
| 84 | sccount = 0; |
|---|
| 85 | payload = 0; |
|---|
| 86 | num_startcodes++; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | sccount = b_check_for_start_code(buf[i], sccount); |
|---|
| 90 | } |
|---|
| 91 | fileoffset += n; |
|---|
| 92 | } |
|---|
| 93 | return 0; |
|---|
| 94 | } |
|---|
| 95 | |
|---|