| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <errno.h> |
|---|
| 4 | |
|---|
| 5 | #include "bcmindexer.h" |
|---|
| 6 | #include "bcmplayer.h" |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | This test creates a NAV file from an SCT file, incrementing a vchip state. |
|---|
| 10 | The NAV file is then read back using bcmplayer. The output should be |
|---|
| 11 | the same as running the printindex utility as followed: |
|---|
| 12 | |
|---|
| 13 | ./printindex -o index,vchip NAVFILE |
|---|
| 14 | |
|---|
| 15 | **/ |
|---|
| 16 | |
|---|
| 17 | int do_nothing(const char *ptr, int size, int count, void *fp) |
|---|
| 18 | { |
|---|
| 19 | return count; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Create the NAV file from an SCT file, inserting vchip information. |
|---|
| 24 | **/ |
|---|
| 25 | void createindex(const char *sctfile) |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | FILE *sct = fopen(sctfile, "r"); |
|---|
| 29 | if (!sct) { |
|---|
| 30 | printf("Cannot open %s to read: %d\n", sctfile, errno); |
|---|
| 31 | exit(1); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | BNAV_Indexer_Handle bcmi; |
|---|
| 35 | BNAV_Indexer_Settings settings; |
|---|
| 36 | |
|---|
| 37 | BNAV_Indexer_GetDefaultSettings(&settings); |
|---|
| 38 | settings.writeCallback = (BNAV_WRITE_CB)do_nothing; |
|---|
| 39 | settings.filePointer = (void*)1; |
|---|
| 40 | |
|---|
| 41 | if (BNAV_Indexer_Open(&bcmi, &settings)) { |
|---|
| 42 | printf("Failed to open BNAV_Indexer\n"); |
|---|
| 43 | exit(1); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | int vchip = 0; |
|---|
| 47 | while (!feof(sct)) { |
|---|
| 48 | //#define BUFSIZE 4096 |
|---|
| 49 | #define BUFSIZE sizeof(BSCT_Entry) |
|---|
| 50 | char buf[BUFSIZE]; |
|---|
| 51 | BNAV_Indexer_Position position; |
|---|
| 52 | |
|---|
| 53 | int n = fread(buf, 1, BUFSIZE, sct); |
|---|
| 54 | if (n == -1) { |
|---|
| 55 | printf("fread error: %d\n", errno); |
|---|
| 56 | exit(1); |
|---|
| 57 | } |
|---|
| 58 | if (BNAV_Indexer_SetVChipState(bcmi, (vchip++ | 0x4040))) |
|---|
| 59 | printf("Error setting vchip\n"); |
|---|
| 60 | BNAV_Indexer_Feed(bcmi, (BSCT_Entry*)buf, n / sizeof(BSCT_Entry)); |
|---|
| 61 | |
|---|
| 62 | printf("BSCT_Entry's fed: %d\n", n / sizeof(BSCT_Entry)); |
|---|
| 63 | if (BNAV_Indexer_GetPosition(bcmi, &position)) |
|---|
| 64 | printf("BNAV_Indexer_GetPosition failed\n"); |
|---|
| 65 | else |
|---|
| 66 | printf( |
|---|
| 67 | "BNAV_Indexer_Position:\n" |
|---|
| 68 | " index: %d\n" |
|---|
| 69 | " pts: 0x%lx\n" |
|---|
| 70 | " offsetHi: 0x%lx\n" |
|---|
| 71 | " offsetLo: 0x%lx\n" |
|---|
| 72 | " timestamp: %d\n" |
|---|
| 73 | " vchipState: 0x%x\n", |
|---|
| 74 | position.index, |
|---|
| 75 | position.pts, |
|---|
| 76 | position.offsetHi, |
|---|
| 77 | position.offsetLo, |
|---|
| 78 | position.timestamp, |
|---|
| 79 | position.vchipState); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | BNAV_Indexer_Close(bcmi); |
|---|
| 83 | fclose(sct); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | int main(int argc, char **argv) { |
|---|
| 87 | if (argc < 2) { |
|---|
| 88 | printf( |
|---|
| 89 | "BNAV_Indexer_GetPosition test\n" |
|---|
| 90 | "Usage: %s SCTFILE\n", argv[0]); |
|---|
| 91 | exit(1); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | const char *sctfile = argv[1]; |
|---|
| 95 | |
|---|
| 96 | createindex(sctfile); |
|---|
| 97 | return 0; |
|---|
| 98 | } |
|---|