source: svn/trunk/newcon3bcm2_21bu/BSEAV/lib/bcmplayer/utils/printindex.c @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 16.6 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2002-2010, 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: printindex.c $
11 * $brcm_Revision: 8 $
12 * $brcm_Date: 6/21/10 4:31p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/lib/bcmplayer/utils/printindex.c $
19 *
20 * 8   6/21/10 4:31p erickson
21 * SW7405-4249: added BNAV_Version_TimestampOnly option for indexing
22 * audio-only or scrambled streams
23 *
24 * 7   4/16/08 10:34a erickson
25 * PR40307: fix compilation
26 *
27 * 6   2/26/08 12:28p katrep
28 * PR38429: Added AVS record and playback support
29 *
30 * 5   2/19/08 6:12p katrep
31 * PR38979: Fixed -sct6 option, there are tpit entries now in the SCTs
32 *
33 * 4   2/5/08 3:57p gmohile
34 * PR 38979 : Add Random Access indicator in index file
35 *
36 * 3   2/8/07 5:21p erickson
37 * PR22543: make pts default
38 *
39 * 2   11/22/06 12:30p erickson
40 * PR25230: fix warnings
41 *
42 * Irvine_BSEAVSW_Devel/22   6/26/06 12:02p erickson
43 * PR21941: fixed warnings
44 *
45 * Irvine_BSEAVSW_Devel/21   3/6/06 1:21p erickson
46 * PR19853: added VC1 PES support
47 *
48 * Irvine_BSEAVSW_Devel/20   1/6/06 10:16a erickson
49 * PR17108: updated for magnum basemodules and 64 bit cpus
50 *
51 * Irvine_BSEAVSW_Devel/19   8/3/05 12:06p erickson
52 * PR16138: fix compiler warnings, make "-s" completely silent on all non-
53 * frame printouts
54 *
55 * Irvine_BSEAVSW_Devel/18   7/15/05 8:08p erickson
56 * PR16138: added runtime check for AVC format
57 *
58 * Irvine_BSEAVSW_Devel/17   7/13/05 6:47p erickson
59 * PR16138: converted 0&1 fields to seqhdr offset & size
60 *
61 * Irvine_BSEAVSW_Devel/16   7/13/05 2:12p erickson
62 * PR16138: added AVC NAV version support and refactored
63 *
64 ***********************************************/
65#include "bstd.h"
66#include <stdio.h>
67#include <stdlib.h>
68#include <string.h>
69#include "bcmindexer.h"
70#include "bcmindexerpriv.h"
71#include "tsindexer.h"
72#include "tsplayer.h"
73#include "mpeg2types.h"
74#include "avstypes.h"
75
76void printHeader() {
77    printf(
78    "printindex, Rev. 1.3\n"
79    "Broadcom Corp. Confidential\n"
80    "Copyright 2002-2005 Broadcom Corp. All Rights Reserved.\n"
81    "\n"
82    );
83}
84
85#define DEFAULT_OPTIONSTRING "index,lo,size,rfo,type,pts"
86
87void printUsage() {
88    printHeader();
89    printf(
90    "Usage: printindex [options] [filename]\n\n"
91    "  If compiled with 64-bit support, this app will read indexes for mpeg >2GB.\n"
92    "  If filename is blank or \"-\", stdin is used.\n\n"
93    );
94    printf(
95    "  Options:\n"
96    "  -d              Print offset and size in decimal (default is hex)\n"
97    "  -i <index>      Index number to start at. Default is 0.\n"
98    "  -n <number>     Number of indexes to print. Default is -1, which means to EOF.\n"
99    "  -sct            The index is an sct index, not a bcm index. This is defaulted\n"
100    "                  if the filename doesn't have a .nav or .bcm suffix.\n"
101    );
102    printf(
103    "  -sct6           The index is a six word sct index.\n"
104    "                  if the filename has a .nav or .bcm suffix.\n"
105    "  -bcm            The index is a broadcom index\n"
106    );
107    printf(
108    "  -avs            The scts are for AVS streams\n"
109    );
110    printf(
111    "  -skippts        Don't print pts entries in an sct index\n"
112    "  -s              Silence various comments about defaults.\n"
113    "  -o OPTIONS      Specify bcmindex fields. Fields include:\n"
114    "                    index     index number of each index entry\n"
115    "                    seqhdr    seqhdr offset and size\n"
116    "                    hi        hi 32 bits of frame offset\n"
117    "                    lo        lo 32 bits of frame offset\n"
118    "                    pts       presentation time stamp\n"
119    );
120    printf(
121    "                    size      size of the frame\n"
122    "                    vchip     16 bits of vchip content rating\n"
123    "                    ts        continuous time stamp\n"
124    "                    rfo       reference frame offset\n"
125    "                    type      frame type (I,B,P,reference P)\n"
126    "                  Default is " DEFAULT_OPTIONSTRING "\n"
127    );
128}
129
130/* lifted from bcmindexer.c */
131unsigned long bcmindex_returnPts(const sIndexEntry *p_sct)
132{
133    unsigned long pts;
134    /* Calculate PTS[32:1] */
135    pts = p_sct->startCodeBytes & 0x1;
136    pts = (pts << 31) + (p_sct->recordByteCount >> 1);
137    return pts;
138}
139
140unsigned long bcmindex_returnPts2(const sSixWordIndexEntry *p_sct)
141{
142#if 0
143    unsigned long pts;
144    /* Calculate PTS[32:1] */
145    pts = p_sct->startCodeBytes & 0x1;
146    pts = (pts << 31) + (p_sct->recordByteCount >> 1);
147    return pts;
148#else /* for RAVE based platforms */
149    return p_sct->recordByteCountHi;
150#endif
151}
152
153typedef enum {
154    b_indextype_sct,
155    b_indextype_sct6,
156    b_indextype_bcm,
157    b_indextype_avcbcm,
158    b_indextype_vc1bcm,
159    b_indextype_avsbcm,
160    b_indextype_timestamp_only,
161    b_indextype_unknown
162} b_indextype;
163
164/* options */
165char *optionstring = DEFAULT_OPTIONSTRING;
166int decimal = 0;
167int skippts = 0;
168b_indextype indextype = b_indextype_unknown;
169
170void print_naventry(int i, const BNAV_Entry *entry)
171{
172#define FIND(STR) strstr(optionstring, STR)
173    if (FIND("index"))
174        printf("%d: ", i);
175
176    if (FIND("Seqhdr")) { /* use capital S and get absolute offset, 32 bit addresses only */
177        printf("seqhdr %#08lx(%#x) ",
178            BNAV_get_frameOffsetLo(entry) - BNAV_get_seqHdrStartOffset(entry), BNAV_get_seqHdrSize(entry));
179        if (indextype == b_indextype_avcbcm) {
180            printf("sps %#08lx(%#lx) ",
181                BNAV_get_frameOffsetLo(entry) - BNAV_get_SPS_Offset((const BNAV_AVC_Entry*)entry), BNAV_get_SPS_Size((const BNAV_AVC_Entry*)entry));
182        }
183        else if (indextype == b_indextype_vc1bcm) {
184            printf("EP %#08lx(%#lx) ",
185                BNAV_get_frameOffsetLo(entry) - BNAV_get_SPS_Offset((const BNAV_AVC_Entry*)entry), BNAV_get_SPS_Size((const BNAV_AVC_Entry*)entry));
186        }
187    }
188
189    if (FIND("seqhdr")) {
190        printf("seqhdr %#08lx(%#x) ",
191            BNAV_get_seqHdrStartOffset(entry), BNAV_get_seqHdrSize(entry));
192        if (indextype == b_indextype_avcbcm) {
193            printf("sps %#08lx(%#lx) ",
194                BNAV_get_SPS_Offset((const BNAV_AVC_Entry*)entry), BNAV_get_SPS_Size((const BNAV_AVC_Entry*)entry));
195        }
196        else if (indextype == b_indextype_vc1bcm) {
197            printf("EP %#08lx(%#lx) ",
198                BNAV_get_SPS_Offset((const BNAV_AVC_Entry*)entry), BNAV_get_SPS_Size((const BNAV_AVC_Entry*)entry));
199        }
200    }
201    if (FIND("hi")) {
202        if (decimal)
203            printf("hi=%-8ld ", (unsigned long)entry->words[2]);
204        else
205            printf("hi=0x%08x ", entry->words[2]);
206    }
207    if (FIND("lo")) {
208        if (decimal)
209            printf("lo=%-8ld ", (unsigned long)entry->words[3]);
210        else
211            printf("lo=0x%08x ", entry->words[3]);
212    }
213    if (FIND("pts"))
214        printf("pts=0x%08x ", entry->words[4]);
215    if (FIND("size")) {
216        if (decimal)
217            printf("size=%-8ld ", BNAV_get_frameSize(entry));
218        else
219            printf("size=0x%08lx ", BNAV_get_frameSize(entry));
220    }
221    if (FIND("vchip"))
222        printf("vchip=0x%04x ", BNAV_unpack_vchip(BNAV_get_packed_vchip(entry)));
223    if (FIND("ts")) {
224        if (decimal)
225            printf("ts=%d ", entry->words[6]);
226        else
227            printf("ts=0x%08x ", entry->words[6]);
228    }
229    if (FIND("rfo"))
230        printf("rfo=%2d ", BNAV_get_refFrameOffset(entry));
231    if (FIND("type"))
232        printf("(%s) ", BNAV_frameTypeStr[BNAV_get_frameType(entry)]);
233
234    if (FIND("rai"))
235        printf("rai=%s ", BNAV_get_RandomAccessIndicator(entry)?"true":"false");
236
237    printf("\n");
238}
239
240void print_sct(int i, const BSCT_Entry *entry)
241{
242    int pic, sc;
243    sc = entry->startCodeBytes >> 24;
244    if (sc == SC_PTS) {
245        if (!skippts)
246        printf("%03d: PTS=%#lx\n", i, bcmindex_returnPts(entry));
247    }
248    else {
249        pic = sc == SC_PICTURE ? returnPictureCode(entry->startCodeBytes) : 0;
250        printf("%03d: SC=%02lx payload=%04lx offset=%02lx offset=0x%02lx%08lx (%s)\n",
251            i,
252            (unsigned long)entry->startCodeBytes>>24,
253            (unsigned long)(entry->startCodeBytes>>8) & 0xFFFF,
254            (unsigned long)entry->startCodeBytes&0xFF,
255            (unsigned long)entry->recordByteCountHi >> 24,
256            (unsigned long)entry->recordByteCount,
257            pic==PC_I_FRAME?"I":pic==PC_P_FRAME?"P":pic==PC_B_FRAME?"B":"-");
258    }
259}
260
261void print_sct6(int i, const BSCT_SixWord_Entry *entry)
262{
263    int pic, sc,entry_type;
264    entry_type = entry->word0 >> 24;
265    if (entry_type == 0x01)
266    {
267        printf("%03d: TPIT entry\n",i);
268    }
269    else
270    {
271        sc = entry->startCodeBytes >> 24;
272        if (sc == SC_PTS)
273        {
274            if (!skippts)
275                printf("%03d: PTS=%#lx\n", i, bcmindex_returnPts2(entry));
276        }
277        else
278        {
279            pic = sc == SC_PICTURE ? returnPictureCode(entry->startCodeBytes) : 0;
280            printf("%03d: SC=%02lx payload=%04lx%06lx%06lx offset=%02lx offset=0x%02lx%08lx (%s)\n",
281                   i,
282                   (unsigned long)entry->startCodeBytes>>24,
283                   (unsigned long)(entry->startCodeBytes>>8) & 0xFFFF,
284                   (unsigned long)entry->recordByteCountHi & 0xFFFFFF,
285                   (unsigned long)entry->flags & 0xFFFFFF,
286                   (unsigned long)entry->startCodeBytes&0xFF,
287                   (unsigned long)entry->recordByteCountHi >> 24,
288                   (unsigned long)entry->recordByteCount,
289                   pic==PC_I_FRAME?"I":pic==PC_P_FRAME?"P":pic==PC_B_FRAME?"B":"-");
290        }
291    }
292
293}
294
295void print_avs_sct6(int i, const BSCT_SixWord_Entry *entry)
296{
297    int pic, sc,entry_type;
298    entry_type = entry->word0 >> 24;
299    if (entry_type == 0x01)
300    {
301        printf("%03d: TPIT entry\n",i);
302    }
303    else
304    {
305        sc = entry->startCodeBytes >> 24;
306        if (sc == SC_AVS_PTS)
307        {
308            if (!skippts)
309                printf("%03d: PTS=%#lx\n", i, (long unsigned int)entry->recordByteCountHi);
310        }
311        else if(sc == SC_AVS_PICTURE_I)
312        {
313            printf("%03d: SC=%02lx payload=%04lx%06lx%06lx offset=%02lx offset=0x%02lx%08lx (%s)\n",
314                   i,
315                   (unsigned long)entry->startCodeBytes>>24,
316                   (unsigned long)(entry->startCodeBytes>>8) & 0xFFFF,
317                   (unsigned long)entry->recordByteCountHi & 0xFFFFFF,
318                   (unsigned long)entry->flags & 0xFFFFFF,
319                   (unsigned long)entry->startCodeBytes&0xFF,
320                   (unsigned long)entry->recordByteCountHi >> 24,
321                   (unsigned long)entry->recordByteCount,
322                    "I");
323        }
324        else
325        {
326            pic = sc == SC_AVS_PICTURE_PB ? returnAvsPictureCode(entry->recordByteCountHi) : 0;
327            printf("%03d: SC=%02lx payload=%04lx%06lx%06lx offset=%02lx offset=0x%02lx%08lx (%s)\n",
328                   i,
329                   (unsigned long)entry->startCodeBytes>>24,
330                   (unsigned long)(entry->startCodeBytes>>8) & 0xFFFF,
331                   (unsigned long)entry->recordByteCountHi & 0xFFFFFF,
332                   (unsigned long)entry->flags & 0xFFFFFF,
333                   (unsigned long)entry->startCodeBytes&0xFF,
334                   (unsigned long)entry->recordByteCountHi >> 24,
335                   (unsigned long)entry->recordByteCount,
336                   pic==PC_AVS_P_FRAME?"P":pic==PC_AVS_B_FRAME?"B":"-");
337        }
338    }
339
340}
341
342int main(int argc, char **argv) {
343    int i;
344    int offset = 0;
345    int total = -1;
346    int silence = 0;
347    const char *filename = NULL;
348    FILE *file;
349    unsigned entrysize = 0;
350    int sctIsAvs =0;
351
352    for (i=1;i<argc;i++) {
353        if (!strcmp(argv[i], "--help")) {
354            printUsage();
355            exit(0);
356        }
357        else if (!strcmp(argv[i], "-i")) {
358            offset = atoi(argv[++i]);
359        }
360        else if (!strcmp(argv[i], "-n")) {
361            total = atoi(argv[++i]);
362        }
363        else if (!strcmp(argv[i], "-d")) {
364            decimal = 1;
365        }
366        else if (!strcmp(argv[i], "-o")) {
367            optionstring = argv[++i];
368        }
369        else if (!strcmp(argv[i], "-sct")) {
370            indextype = b_indextype_sct;
371        }
372        else if (!strcmp(argv[i], "-sct6")) {
373            indextype = b_indextype_sct6;
374        }
375        else if (!strcmp(argv[i], "-avs")) {
376            sctIsAvs=1;
377        }
378        else if (!strcmp(argv[i], "-bcm")) {
379            indextype = b_indextype_bcm;
380        }
381        else if (!strcmp(argv[i], "-skippts")) {
382            skippts = 1;
383        }
384        else if (!strcmp(argv[i], "-s")) {
385            silence = 1;
386        }
387        else if (!filename) {
388            filename = argv[i];
389        }
390        else {
391            printf("Invalid parameters.\n");
392            exit(1);
393        }
394    }
395
396    if (!silence) {
397        printHeader();
398        printf("'--help' for options.\n");
399    }
400
401
402    if (indextype == b_indextype_unknown) {
403        indextype = b_indextype_sct; /* sct */
404        if (filename) {
405            int len = strlen(filename);
406            if (len > 4 &&
407                (!strcmp(&filename[len-4], ".nav") ||
408                 !strcmp(&filename[len-4], ".bcm")))
409                indextype = b_indextype_bcm;
410        }
411        if (!silence)
412            printf("Default index type: %s\n", indextype==1?"SCT":"BCM");
413    }
414
415    if (!filename || !strcmp(filename, "-")) {
416        if (!filename && !silence)
417            printf("Default index: stdin\n");
418        filename = NULL;
419        file = stdin;
420    }
421    else {
422        file = fopen(filename, "rb");
423        if (!file) {
424            fprintf(stderr, "Cannot open %s\n", filename);
425            exit(1);
426        }
427    }
428
429    if (indextype == b_indextype_bcm) {
430        BNAV_Entry entry;
431        fseek(file, 0, SEEK_SET);
432        if (fread(&entry, sizeof(entry), 1, file) == 1) {
433            BNAV_Version ver = BNAV_get_version(&entry);
434            if (!silence)
435                printf("Version: %d\n", ver);
436            if (ver == BNAV_Version_AVC) {
437                indextype = b_indextype_avcbcm;
438            }
439            else if (ver == BNAV_Version_VC1_PES) {
440                indextype = b_indextype_vc1bcm;
441            }
442            else if (ver == BNAV_Version_AVS) {
443                indextype = b_indextype_avsbcm;
444            }
445            else if (ver == BNAV_Version_TimestampOnly) {
446                indextype = b_indextype_timestamp_only;
447            }
448            else if (ver >= BNAV_VersionUnknown) {
449                printf("Unknown version indicates corrupt index.\n");
450                exit(1);
451            }
452        }
453    }
454
455    switch (indextype) {
456    case b_indextype_sct:
457        entrysize = sizeof(sIndexEntry); break;
458    case b_indextype_sct6:
459        entrysize = sizeof(sSixWordIndexEntry); break;
460    case b_indextype_bcm:
461    case b_indextype_avsbcm:
462    case b_indextype_timestamp_only:
463        entrysize = sizeof(BNAV_Entry); break;
464    case b_indextype_avcbcm:
465    case b_indextype_vc1bcm:
466        entrysize = sizeof(BNAV_AVC_Entry); break;
467    default: break;
468    }
469
470    fseek(file, offset * entrysize, SEEK_SET);
471
472    for (i=0;(total==-1 || i<total) && !feof(file);i++) {
473        switch (indextype) {
474        case b_indextype_sct:
475            {
476            sIndexEntry entry;
477            if (fread(&entry, sizeof(entry), 1, file) != 1)
478                break;
479            print_sct(i+offset, &entry);
480            }
481            break;
482        case b_indextype_sct6:
483            {
484                sSixWordIndexEntry entry;
485                if (fread(&entry, sizeof(entry), 1, file) != 1)
486                    break;
487                if(sctIsAvs)
488                    print_avs_sct6(i+offset, &entry);
489                else
490                    print_sct6(i+offset, &entry);
491            }
492            break;
493        case b_indextype_bcm:
494        case b_indextype_avsbcm:
495        case b_indextype_timestamp_only:
496            {
497            /* TODO: the -o option should also determine the order! */
498            BNAV_Entry entry;
499            if (fread(&entry, sizeof(entry), 1, file) != 1)
500                break;
501            print_naventry(i+offset, &entry);
502            }
503            break;
504        case b_indextype_avcbcm:
505        case b_indextype_vc1bcm:
506            {
507            BNAV_AVC_Entry entry;
508            if (fread(&entry, sizeof(entry), 1, file) != 1)
509                break;
510            print_naventry(i+offset, (const BNAV_Entry*)(void*)&entry);
511            }
512            break;
513        default:
514            printf("Unknown index format\n");
515        }
516    }
517    if (filename)
518        fclose(file);
519    return 0;
520}
521
522
Note: See TracBrowser for help on using the repository browser.