/*************************************************************************** * Copyright (c) 2002-2009, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: printpes.c $ * $brcm_Revision: 3 $ * $brcm_Date: 10/28/09 1:30p $ * * Module Description: print out contents of PES stream * * Revision History: * * $brcm_Log: /BSEAV/lib/bcmplayer/utils/printpes.c $ * * 3 10/28/09 1:30p erickson * SW7405-3287: move common code to ts_utils * * 2 3/14/07 11:25a erickson * PR28320: improve MPEG2 PES debug support * * Irvine_BSEAVSW_Devel/5 6/30/06 9:39a erickson * PR21941: fix start code detection algorithm, and eliminate duplication * by moving to ts_utils * * Irvine_BSEAVSW_Devel/4 1/6/06 10:16a erickson * PR17108: updated for magnum basemodules and 64 bit cpus * * Irvine_BSEAVSW_Devel/3 12/6/05 4:34p erickson * PR17108: fixed bitshift, print only most significant 32 bits, which is * what we use * * Irvine_BSEAVSW_Devel/2 8/19/05 4:00p erickson * PR16208: fixed cmdline * * Irvine_BSEAVSW_Devel/1 8/8/05 3:57p erickson * PR16138: added printpes util * *************************************************************************/ #include #include #include #include #include #include #include "ts_utils.h" /* decode and print the pes header. buf points to the stream_id and is guaranteed to point to whole pes header. */ void print_pes_header(unsigned char *buf) { b_pes_header pes_header; b_get_pes_header(buf, &pes_header); printf(" packet_length %d\n", pes_header.packet_length); if (pes_header.pes_type == b_pes_packet_type_pes) { printf(" header_data_length %d\n", pes_header.header_data_length); if (pes_header.pts_dts_flags == 2) { printf(" pts 0x%08x\n", pes_header.pts); } else if (pes_header.pts_dts_flags == 3) { printf(" pts 0x%08x\n", pes_header.pts); printf(" dts 0x%08x\n", pes_header.dts); } else if (pes_header.pts_dts_flags == 0) { /* no pts or dts */ } else { printf("### forbidden pts_dts_flags value\n"); } /* TODO: ESCR flag, ES rate flag, DSM trick mode flag, etc. */ } else if (pes_header.pes_type == b_pes_packet_type_data) { printf(" data\n"); } else if (pes_header.pes_type == b_pes_packet_type_padding) { /* padding stream */ printf(" padding\n"); } else { /* not a PES stream_id */ } } int main(int argc, char **argv) { FILE *fin = stdin; #define BUFSIZE 4096 unsigned char buf[BUFSIZE]; int sccount = 0; int curarg = 1; uint64_t fileoffset = 0; if (argc > 1 && !strcmp(argv[curarg], "--help")) { printf("Usage: printpes [FILENAME]\n"); exit(0); } if (curarg < argc) { fin = fopen(argv[curarg], "r"); if (!fin) return printf("Unable to open %s: %d\n", argv[curarg], errno); } else { printf("Reading stdin\n"); } while (!feof(fin)) { int i; int n; n = fread(buf, 1, BUFSIZE, fin); if (n == -1) break; /* search for start codes */ for (i=0; i