|
7 | 7 |
|
8 | 8 | #include <tsdemux.h> |
9 | 9 |
|
| 10 | +#define PRINT_PIDS_LEN (16) |
| 11 | + |
| 12 | +// prints out the data assoicated with certain PIDs (up to 16) |
| 13 | +uint16_t print_pids[PRINT_PIDS_LEN]; |
| 14 | + |
10 | 15 | // demux callback (see tsd_set_event_callback for details). |
11 | 16 | void event_cb(TSDemuxContext *ctx, uint16_t pid, TSDEventId event_id, void *data); |
12 | 17 | // prints information about a PAT. |
@@ -35,6 +40,9 @@ int main(int argc, char **charv) { |
35 | 40 | return -20; |
36 | 41 | } |
37 | 42 |
|
| 43 | + // create the pids we plan on printing |
| 44 | + memset(print_pids, 0, sizeof(print_pids)); |
| 45 | + |
38 | 46 | // create a demuxing context. |
39 | 47 | TSDemuxContext ctx; |
40 | 48 | // set default values onto the context. |
@@ -100,6 +108,25 @@ void event_cb(TSDemuxContext *ctx, uint16_t pid, TSDEventId event_id, void *data |
100 | 108 | // This is where we would write the PES data into our buffer. |
101 | 109 | printf("\n====================\n"); |
102 | 110 | printf("PID %d PES Packet, Size: %d, stream_id=%u, pts=%llu, dts=%llu\n", pid, pes->data_bytes_length, pes->stream_id, pes->pts, pes->dts); |
| 111 | + // print out the PES Packet data if it's in our print list |
| 112 | + int i; |
| 113 | + for(i=0; i<PRINT_PIDS_LEN; ++i) { |
| 114 | + if(print_pids[i] == pid) { |
| 115 | + printf(" PES data: "); |
| 116 | + int j = 0; |
| 117 | + while(j < pes->data_bytes_length) { |
| 118 | + char n = pes->data_bytes[j]; |
| 119 | + if(n >= 32) { |
| 120 | + printf("%c", n); |
| 121 | + }else{ |
| 122 | + printf("(0x%02X)", n); |
| 123 | + } |
| 124 | + ++j; |
| 125 | + } |
| 126 | + printf("\n"); |
| 127 | + } |
| 128 | + } |
| 129 | + |
103 | 130 | }else if(event_id == TSD_EVENT_ADAP_FIELD_PRV_DATA) { |
104 | 131 | // we're only watching for SCTE Adaptions Field Private Data, |
105 | 132 | // so we know that we must parse it as a list of descritors. |
@@ -159,11 +186,24 @@ void print_pmt(TSDemuxContext *ctx, void *data) { |
159 | 186 | printf(" elementary pid: 0x%04X\n", prog->elementary_pid); |
160 | 187 | printf(" es info length: %d\n", prog->es_info_length); |
161 | 188 | printf(" descriptors length: %d\n", prog->descriptors_length); |
162 | | - size_t j; |
| 189 | + |
| 190 | + // keep track of metadata pids, we'll print the data for these |
| 191 | + if(prog->stream_type == TSD_PMT_STREAM_TYPE_PES_METADATA) |
| 192 | + { |
| 193 | + int k; |
| 194 | + for(k=0; k<PRINT_PIDS_LEN; ++k) { |
| 195 | + // find a spare slot in the pids |
| 196 | + if(print_pids[k] == 0) { |
| 197 | + print_pids[k] = prog->elementary_pid; |
| 198 | + break; |
| 199 | + } |
| 200 | + } |
| 201 | + } |
163 | 202 |
|
164 | 203 | // we'll register to listen to the PES data for this program. |
165 | 204 | int reg_types = TSD_REG_PES; |
166 | 205 |
|
| 206 | + size_t j; |
167 | 207 | for(j=0;j<prog->descriptors_length;++j) { |
168 | 208 | TSDDescriptor *des = &prog->descriptors[j]; |
169 | 209 | printf(" %d) tag: (0x%04X) %s\n", j, des->tag, descriptor_tag_to_str(des->tag)); |
|
0 commit comments