clib/dvb_ts_lib/tables/parse_si_pat.c

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 57 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« clib/dvb_ts_lib/tables/parse_si_nit.c ↑ Summary clib/dvb_ts_lib/tables/parse_si_pmt.c »
1 /*
2 * parse_si_pat.c
3 *
4 * Created by: si_desc.pl
5 * Created on: 20-May-2011
6 * Author: sdprice1
7 */
8
9
10 // VERSION = 1.00
11
12 /*=============================================================================================*/
13 // USES
14 /*=============================================================================================*/
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <string.h>
20 #include <errno.h>
21 #include <ctype.h>
22 #include <fcntl.h>
23 #include <inttypes.h>
24
25 #include "parse_si_pat.h"
26 #include "descriptors/parse_desc.h"
27
28 /*=============================================================================================*/
29 // CONSTANTS
30 /*=============================================================================================*/
31
32 /*=============================================================================================*/
33 // MACROS
34 /*=============================================================================================*/
35
36 /*=============================================================================================*/
37 // FUNCTIONS
38 /*=============================================================================================*/
39
40 /* ----------------------------------------------------------------------- */
41 //
42 // program_association_section() {
43 // table_id 8 uimsbf
44 // section_syntax_indicator 1 bslbf
45 // '0' 1 bslbf
46 // reserved 2 bslbf
47 // section_length 12 uimsbf
48 // transport_stream_id 16 uimsbf
49 // reserved 2 bslbf
50 // version_number 5 uimsbf
51 // current_next_indicator 1 bslbf
52 // section_number 8 uimsbf
53 // last_section_number 8 uimsbf
54 // for (i = 0; i < N; i++) {
55 // program_number 16 uimsbf
56 // reserved 3 bslbf
57 // if (program_number = = '0') {
58 // network_PID 13 uimsbf
59 // } else {
60 // program_map_PID 13 uimsbf
61 // }
62 // }
63 // CRC_32 32 rpchof
64 // }
65
66
67 /* ----------------------------------------------------------------------- */
68 0 void print_pat(struct Section_program_association *pat)
69 {
70 struct list_head *item, *safe;
71 int end_buff_len ;
72
73 0 printf("Table: program_association [0x%02x]\n", pat->table_id) ;
74 0 printf("Length: %d\n", pat->section_length) ;
75
76 //== data ==
77 0 printf("section_syntax_indicator = %d\n", pat->section_syntax_indicator) ;
78 0 printf("transport_stream_id = %d\n", pat->transport_stream_id) ;
79 0 printf("version_number = %d\n", pat->version_number) ;
80 0 printf("current_next_indicator = %d\n", pat->current_next_indicator) ;
81 0 printf("section_number = %d\n", pat->section_number) ;
82 0 printf("last_section_number = %d\n", pat->last_section_number) ;
83
84 0 ▶ list_for_each_safe(item,safe,&pat->pat_array) {
Branch: 1 branch
BranchTrueFalseTotal
list_for_each_safe(item,safe,&pat->pat_array) { 0 0 0
85 0 struct PAT_entry *pat_entry = list_entry(item, struct PAT_entry, next);
86
87 // PAT entry
88 0 printf(" -PAT entry-\n") ;
89
90 0 printf(" program_number = %d\n", pat_entry->program_number) ;
91 0 ▶ if (pat_entry->program_number == 0x0 )
Branch: 1 branch
BranchTrueFalseTotal
if (pat_entry->program_number == 0x0 ) 0 0 0
92 {
93 0 printf(" network_PID = %d\n", pat_entry->network_PID) ;
94 }
95 else
96 {
97 0 printf(" program_map_PID = %d\n", pat_entry->program_map_PID) ;
98 }
99
100 }
101
102 0 }
103
104 /* ----------------------------------------------------------------------- */
105 0 void parse_pat(struct TS_reader *tsreader, struct TS_state *tsstate, struct TS_bits *bits,
106 Section_handler handler, struct Section_decode_flags *flags)
107 {
108 struct Section_program_association pat ;
109 struct list_head *item, *safe;
110 unsigned byte ;
111 int end_buff_len ;
112
113 //== Parse data ==
114
115 0 pat.table_id = bits_get(bits, 8) ;
116 0 pat.section_syntax_indicator = bits_get(bits, 1) ;
117 0 bits_skip(bits, 1) ;
118 0 bits_skip(bits, 2) ;
119 0 pat.section_length = bits_get(bits, 12) ;
120 0 pat.transport_stream_id = bits_get(bits, 16) ;
121 0 bits_skip(bits, 2) ;
122 0 pat.version_number = bits_get(bits, 5) ;
123 0 pat.current_next_indicator = bits_get(bits, 1) ;
124 0 pat.section_number = bits_get(bits, 8) ;
125 0 pat.last_section_number = bits_get(bits, 8) ;
126
127 0 INIT_LIST_HEAD(&pat.pat_array) ;
128 0 ▶ while (bits->buff_len >= 4)
Branch: 1 branch
BranchTrueFalseTotal
while (bits->buff_len >= 4) 0 0 0
129 {
130 0 struct PAT_entry *pat_entry = malloc(sizeof(*pat_entry));
131 0 memset(pat_entry,0,sizeof(*pat_entry));
132 0 list_add_tail(&pat_entry->next,&pat.pat_array);
133
134 0 pat_entry->program_number = bits_get(bits, 16) ;
135 0 bits_skip(bits, 3) ;
136 0 ▶ if (pat_entry->program_number == 0x0 )
Branch: 1 branch
BranchTrueFalseTotal
if (pat_entry->program_number == 0x0 ) 0 0 0
137 {
138 0 pat_entry->network_PID = bits_get(bits, 13) ;
139 }
140 else
141 {
142 0 pat_entry->program_map_PID = bits_get(bits, 13) ;
143 }
144
145 }
146
147
148 //== Call handler ==
149 0 ▶ if (handler)
Branch: 1 branch
BranchTrueFalseTotal
if (handler) 0 0 0
150 0 handler(tsreader, tsstate, (struct Section *)&pat, tsreader->user_data) ;
151
152 //== Tidy up ==
153
154 0 ▶ list_for_each_safe(item,safe,&pat.pat_array) {
Branch: 1 branch
BranchTrueFalseTotal
list_for_each_safe(item,safe,&pat.pat_array) { 0 0 0
155 0 struct PAT_entry *pat_entry = list_entry(item, struct PAT_entry, next);
156 0 free(pat_entry) ;
157 }
158
159 0 }
« clib/dvb_ts_lib/tables/parse_si_nit.c ↑ Summary clib/dvb_ts_lib/tables/parse_si_pmt.c »