Skip to content

Commit 59716e0

Browse files
committed
In tsinfo example, printing out metadata using a stream type of 0x15
1 parent df25f03 commit 59716e0

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

examples/tsinfo.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
#include <tsdemux.h>
99

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+
1015
// demux callback (see tsd_set_event_callback for details).
1116
void event_cb(TSDemuxContext *ctx, uint16_t pid, TSDEventId event_id, void *data);
1217
// prints information about a PAT.
@@ -35,6 +40,9 @@ int main(int argc, char **charv) {
3540
return -20;
3641
}
3742

43+
// create the pids we plan on printing
44+
memset(print_pids, 0, sizeof(print_pids));
45+
3846
// create a demuxing context.
3947
TSDemuxContext ctx;
4048
// set default values onto the context.
@@ -100,6 +108,25 @@ void event_cb(TSDemuxContext *ctx, uint16_t pid, TSDEventId event_id, void *data
100108
// This is where we would write the PES data into our buffer.
101109
printf("\n====================\n");
102110
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+
103130
}else if(event_id == TSD_EVENT_ADAP_FIELD_PRV_DATA) {
104131
// we're only watching for SCTE Adaptions Field Private Data,
105132
// so we know that we must parse it as a list of descritors.
@@ -159,11 +186,24 @@ void print_pmt(TSDemuxContext *ctx, void *data) {
159186
printf(" elementary pid: 0x%04X\n", prog->elementary_pid);
160187
printf(" es info length: %d\n", prog->es_info_length);
161188
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+
}
163202

164203
// we'll register to listen to the PES data for this program.
165204
int reg_types = TSD_REG_PES;
166205

206+
size_t j;
167207
for(j=0;j<prog->descriptors_length;++j) {
168208
TSDDescriptor *des = &prog->descriptors[j];
169209
printf(" %d) tag: (0x%04X) %s\n", j, des->tag, descriptor_tag_to_str(des->tag));

0 commit comments

Comments
 (0)