Skip to content

Commit ce9fecd

Browse files
committed
README: explain descriptor helpers
Signed-off-by: junka <[email protected]>
1 parent 8f671cc commit ce9fecd

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

README.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# TS Analyze
22

3-
use basic rules from ISO 13818 and ETSI EN 300 468 to decode MPEG2 TS
3+
A TS packet start with 4 bytes header, total length could be 188, 192 or 204 bytes.
4+
Most system will use 188 bytes.
45

5-
use EN 300 743 to decode subtitle
6-
use ETS 300 706 to decide teletext
6+
Construct TS packets we will get PES/PSI packets. PSI is structured for search and
7+
other auxiliary functions. PES contains ES packets which could be audio or vedio
8+
streams.
79

8-
Pinrt descriptors for DVB/ATSC/ISDB standard.
10+
With this understanding, you can start decoding a TS stream or file now.
911

12+
13+
Use basic rules from ISO 13818 and ETSI EN 300 468 to decode MPEG2 TS
14+
Use EN 300 743 to decode subtitle
15+
Use ETS 300 706 to decode teletext
16+
17+
Print descriptors for DVB/ATSC/ISDB standard.
1018
Print PSI tables infomation and some other subsystem infomation
1119

1220

@@ -24,21 +32,21 @@ and then do ```make``` for both ways
2432
```
2533
./tsanalyze tsfile
2634
```
27-
- support file and udp stream analyze
35+
- Support file and udp stream analyze
2836
```
29-
./tsanalyze -f udp udp://url
37+
./tsanalyze -f udp udp://url_of_stream
3038
```
31-
`Ctrl + C` to stop and show received ts info
39+
`Ctrl + C` to stop and show received ts information
3240

33-
- print table selected
41+
- Print table selected
3442
```
3543
./tsanalyze tsfile -s pat -s cat
3644
```
37-
- show stats about ts stream
45+
- Print stats about ts streams
3846
```
3947
./tsanalyze tsfile -S
4048
```
4149

4250

4351
# descriptor
44-
not all descriptor implemented now, see ```doc/descriptor.md``` to add new descriptors
52+
Not all descriptor implemented now, see ```doc/descriptor.md``` to add new descriptors

doc/descriptor.md

+33-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,39 @@ typedef struct descriptor
1212
A basic descriptor should have a structure with TLV like above.
1313
A descriptor is a list node. As descriptors can be chained in a table.
1414

15-
Deine sevaral MACROs as helpers to expand the struct, parse the ts sections,
15+
Define sevaral MACROs as helpers to expand the struct, parse the ts sections,
1616
dump the result and free the list.
17+
For example, this expands definitions of a struct:
1718
```
18-
__m(type, member, bits)
19-
__m1(type, member)
20-
__mplast(type, member)
19+
#define __m(type, name, bits) type name : bits; /* define the struct member with bits width */
20+
#define __m1(type, name) type name; /* define the struct member, which consume a type width */
2121
```
22+
And this define how to parse the struct member:
23+
```
24+
#define __m(type, name, bits) \
25+
dr->name = TS_READ_BITS_##type(buf + bytes_off, bits, bits_off); \
26+
bits_off += bits; \
27+
if (bits_off == sizeof(type) * 8) { \
28+
bits_off = 0; \
29+
bytes_off += sizeof(type); \
30+
}
31+
32+
#define __m1(type, name) \
33+
if (bytes_off < len) { \
34+
dr->name = TS_READ_##type(buf + bytes_off); \
35+
bytes_off += sizeof(type); }
36+
```
37+
We should implement macros for free and dump too.
38+
Every macro should be well defined for the four helper types.
39+
see ```include/descriptor.h```
40+
41+
Also, not every sub-structrue of a descriptor is defined as above. A simple TLV is not enough,
42+
macro define could be too compilated.
43+
If we do have many descriptors share the same pattern, we can do things like below
44+
```
45+
define __mplast_custom_sub(type, name, parser_cb, dump_cb, free_cb)
46+
```
47+
we can add all parse, dump and free functions as callback here.
48+
49+
If we don't have many structures share the same pattern, just write functions for it.
50+
And add initialization for descriptors in ```init_descriptor_parsers``` function.

0 commit comments

Comments
 (0)