/*************************************************************************** * Copyright (c) 2005-2006, 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: muxts.c $ * $brcm_Revision: Irvine_BSEAVSW_Devel/1 $ * $brcm_Date: 2/21/06 3:46p $ * * Module Description: * * Revision History: * * $brcm_Log: /SetTop/bcmplayer/utils/muxts.c $ * * Irvine_BSEAVSW_Devel/1 2/21/06 3:46p erickson * PR17108: added muxts, not working yet * *************************************************************************/ #include #include #include #include #include "ts_utils.h" #include #define MAXPIDS 100 #define BUFSIZE (1024*32) #define MAX_PACKET_PAYLOAD 184 struct pidstruct { FILE *file; unsigned short pid; unsigned char buf[BUFSIZE]; int bufptr, bufsize; int continuity_counter; } pids[MAXPIDS]; int totalpids = 0; /* TODO: just about everything 1. A/V sync (we can make gross assumptions about the files, but some sync should be done) 2. PES layer and PCR's 3. constant bit rate (padding the result with NULL's) */ void printUsage() { fprintf(stderr, "Usage: muxts FILE PID [FILE PID ...]\n" " Transport output is written to stdout.\n" ); } unsigned char pkt[188]; int write_packet(struct pidstruct *pid) { int size = pid->bufsize - pid->bufptr; /* max size that could be written */ int headersize = 4; int payload; pkt[0] = 0x47; /* SYNC BYTE */ pkt[1] = (pid->pid >> 8) & 0x1f; pkt[2] = pid->pid & 0xff; /* PID */ pkt[3] = 0x10 | pid->continuity_counter; /* not scrambled, payload only, continuity counter */ if (++pid->continuity_counter > 0xF) pid->continuity_counter = 0; payload = 188 - headersize; if (size < payload) { /* pad with adaptation field, should only happen once at end */ pkt[3] |= 0x20; pkt[4] = payload - size - 1; headersize = 188 - size; payload = size; /* TODO: set for private data */ } else if (size > 188 - headersize) { size = 188 - headersize; } fwrite(pkt, headersize, 1, stdout); fwrite(&pid->buf[pid->bufptr], size, 1, stdout); return size; } int main(int argc, char **argv) { int curarg = 1; while (curarg < argc-1) { /* must have two more params */ const char *filename = argv[curarg]; pids[totalpids].file = fopen(filename, "r"); if (!pids[totalpids].file) { fprintf(stderr, "ERROR: Unable to open %s\n", filename); exit(1); } curarg++; pids[totalpids].pid = strtoul(argv[curarg], NULL, 0); pids[totalpids].bufptr = pids[totalpids].bufsize = 0; totalpids++; } if (!totalpids) { printUsage(); exit(1); } while (1) { int i; /* read data */ int more = 0; for (i=0;i