| 1 |
|
| /*
|
| 2 |
|
| * parse_si_pmt.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_pmt.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_map_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 |
|
| // program_number 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 |
|
| // reserved 3 bslbf
|
| 55 |
|
| // PCR_PID 13 uimsbf
|
| 56 |
|
| // reserved 4 bslbf
|
| 57 |
|
| // program_info_length 12 uimsbf
|
| 58 |
|
| // for (i = 0; i < N; i++) {
|
| 59 |
|
| // descriptor()
|
| 60 |
|
| // }
|
| 61 |
|
| // for (i = 0; i < N1; i++) {
|
| 62 |
|
| // stream_type 8 uimsbf
|
| 63 |
|
| // reserved 3 bslbf
|
| 64 |
|
| // elementary_PID 13 uimsbf
|
| 65 |
|
| // reserved 4 bslbf
|
| 66 |
|
| // ES_info_length 12 uimsbf
|
| 67 |
|
| // for (i = 0; i < N2; i++) {
|
| 68 |
|
| // descriptor()
|
| 69 |
|
| // }
|
| 70 |
|
| // }
|
| 71 |
|
| // CRC_32 32 rpchof
|
| 72 |
|
| // }
|
| 73 |
|
|
|
| 74 |
|
|
|
| 75 |
|
| /* ----------------------------------------------------------------------- */
|
| 76 |
0 |
| void print_pmt(struct Section_program_map *pmt)
|
| 77 |
|
| {
|
| 78 |
|
| struct list_head *item, *safe;
|
| 79 |
|
| int end_buff_len ;
|
| 80 |
|
|
|
| 81 |
0 |
| printf("Table: program_map [0x%02x]\n", pmt->table_id) ;
|
| 82 |
0 |
| printf("Length: %d\n", pmt->section_length) ;
|
| 83 |
|
|
|
| 84 |
|
| //== data ==
|
| 85 |
0 |
| printf("section_syntax_indicator = %d\n", pmt->section_syntax_indicator) ;
|
| 86 |
0 |
| printf("program_number = %d\n", pmt->program_number) ;
|
| 87 |
0 |
| printf("version_number = %d\n", pmt->version_number) ;
|
| 88 |
0 |
| printf("current_next_indicator = %d\n", pmt->current_next_indicator) ;
|
| 89 |
0 |
| printf("section_number = %d\n", pmt->section_number) ;
|
| 90 |
0 |
| printf("last_section_number = %d\n", pmt->last_section_number) ;
|
| 91 |
0 |
| printf("PCR_PID = %d\n", pmt->PCR_PID) ;
|
| 92 |
0 |
| printf("program_info_length = %d\n", pmt->program_info_length) ;
|
| 93 |
|
|
|
| 94 |
|
| // Descriptors list
|
| 95 |
0 |
| print_desc_list(&pmt->descriptors_array, 1) ;
|
| 96 |
|
|
|
| 97 |
0 |
▶ | list_for_each_safe(item,safe,&pmt->pmt_array) {
|
Branch: 1 branch
| Branch | True | False | Total |
| list_for_each_safe(item,safe,&pmt->pmt_array) {
|
0 |
0 |
0 |
|
| 98 |
0 |
| struct PMT_entry *pmt_entry = list_entry(item, struct PMT_entry, next);
|
| 99 |
|
|
|
| 100 |
|
| // PMT entry
|
| 101 |
0 |
| printf(" -PMT entry-\n") ;
|
| 102 |
|
|
|
| 103 |
0 |
| printf(" stream_type = %d\n", pmt_entry->stream_type) ;
|
| 104 |
0 |
| printf(" elementary_PID = %d\n", pmt_entry->elementary_PID) ;
|
| 105 |
0 |
| printf(" ES_info_length = %d\n", pmt_entry->ES_info_length) ;
|
| 106 |
|
|
|
| 107 |
|
| // Descriptors list
|
| 108 |
0 |
| print_desc_list(&pmt_entry->descriptors_array, 1) ;
|
| 109 |
|
| }
|
| 110 |
|
|
|
| 111 |
0 |
| }
|
| 112 |
|
|
|
| 113 |
|
| /* ----------------------------------------------------------------------- */
|
| 114 |
0 |
| void parse_pmt(struct TS_reader *tsreader, struct TS_state *tsstate, struct TS_bits *bits,
|
| 115 |
|
| Section_handler handler, struct Section_decode_flags *flags)
|
| 116 |
|
| {
|
| 117 |
|
| struct Section_program_map pmt ;
|
| 118 |
|
| struct list_head *item, *safe;
|
| 119 |
|
| unsigned byte ;
|
| 120 |
|
| int end_buff_len ;
|
| 121 |
|
|
|
| 122 |
|
| //== Parse data ==
|
| 123 |
|
|
|
| 124 |
0 |
| pmt.table_id = bits_get(bits, 8) ;
|
| 125 |
0 |
| pmt.section_syntax_indicator = bits_get(bits, 1) ;
|
| 126 |
0 |
| bits_skip(bits, 1) ;
|
| 127 |
0 |
| bits_skip(bits, 2) ;
|
| 128 |
0 |
| pmt.section_length = bits_get(bits, 12) ;
|
| 129 |
0 |
| pmt.program_number = bits_get(bits, 16) ;
|
| 130 |
0 |
| bits_skip(bits, 2) ;
|
| 131 |
0 |
| pmt.version_number = bits_get(bits, 5) ;
|
| 132 |
0 |
| pmt.current_next_indicator = bits_get(bits, 1) ;
|
| 133 |
0 |
| pmt.section_number = bits_get(bits, 8) ;
|
| 134 |
0 |
| pmt.last_section_number = bits_get(bits, 8) ;
|
| 135 |
0 |
| bits_skip(bits, 3) ;
|
| 136 |
0 |
| pmt.PCR_PID = bits_get(bits, 13) ;
|
| 137 |
0 |
| bits_skip(bits, 4) ;
|
| 138 |
0 |
| pmt.program_info_length = bits_get(bits, 12) ;
|
| 139 |
|
|
|
| 140 |
|
| // Descriptors
|
| 141 |
0 |
| INIT_LIST_HEAD(&pmt.descriptors_array);
|
| 142 |
0 |
| end_buff_len = bits_len_calc(bits, -pmt.program_info_length ) ;
|
| 143 |
0 |
▶ | while (bits->buff_len > end_buff_len)
|
Branch: 1 branch
| Branch | True | False | Total |
| while (bits->buff_len > end_buff_len)
|
0 |
0 |
0 |
|
| 144 |
|
| {
|
| 145 |
0 |
| enum TS_descriptor_ids desc_tag = parse_desc(&pmt.descriptors_array, bits, flags->decode_descriptor) ;
|
| 146 |
|
| }
|
| 147 |
|
|
|
| 148 |
|
|
|
| 149 |
0 |
| INIT_LIST_HEAD(&pmt.pmt_array) ;
|
| 150 |
0 |
▶ | while (bits->buff_len >= 5)
|
Branch: 1 branch
| Branch | True | False | Total |
| while (bits->buff_len >= 5)
|
0 |
0 |
0 |
|
| 151 |
|
| {
|
| 152 |
0 |
| struct PMT_entry *pmt_entry = malloc(sizeof(*pmt_entry));
|
| 153 |
0 |
| memset(pmt_entry,0,sizeof(*pmt_entry));
|
| 154 |
0 |
| list_add_tail(&pmt_entry->next,&pmt.pmt_array);
|
| 155 |
|
|
|
| 156 |
0 |
| pmt_entry->stream_type = bits_get(bits, 8) ;
|
| 157 |
0 |
| bits_skip(bits, 3) ;
|
| 158 |
0 |
| pmt_entry->elementary_PID = bits_get(bits, 13) ;
|
| 159 |
0 |
| bits_skip(bits, 4) ;
|
| 160 |
0 |
| pmt_entry->ES_info_length = bits_get(bits, 12) ;
|
| 161 |
|
|
|
| 162 |
|
| // Descriptors
|
| 163 |
0 |
| INIT_LIST_HEAD(&pmt_entry->descriptors_array);
|
| 164 |
0 |
| end_buff_len = bits_len_calc(bits, -pmt_entry->ES_info_length ) ;
|
| 165 |
0 |
▶ | while (bits->buff_len > end_buff_len)
|
Branch: 1 branch
| Branch | True | False | Total |
| while (bits->buff_len > end_buff_len)
|
0 |
0 |
0 |
|
| 166 |
|
| {
|
| 167 |
0 |
| enum TS_descriptor_ids desc_tag = parse_desc(&pmt_entry->descriptors_array, bits, flags->decode_descriptor) ;
|
| 168 |
|
| }
|
| 169 |
|
|
|
| 170 |
|
| }
|
| 171 |
|
|
|
| 172 |
|
|
|
| 173 |
|
| //== Call handler ==
|
| 174 |
0 |
▶ | if (handler)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (handler)
|
0 |
0 |
0 |
|
| 175 |
0 |
| handler(tsreader, tsstate, (struct Section *)&pmt, tsreader->user_data) ;
|
| 176 |
|
|
|
| 177 |
|
| //== Tidy up ==
|
| 178 |
0 |
| free_descriptors_list(&pmt.descriptors_array);
|
| 179 |
|
|
|
| 180 |
0 |
▶ | list_for_each_safe(item,safe,&pmt.pmt_array) {
|
Branch: 1 branch
| Branch | True | False | Total |
| list_for_each_safe(item,safe,&pmt.pmt_array) {
|
0 |
0 |
0 |
|
| 181 |
0 |
| struct PMT_entry *pmt_entry = list_entry(item, struct PMT_entry, next);
|
| 182 |
0 |
| free_descriptors_list(&pmt_entry->descriptors_array);
|
| 183 |
0 |
| free(pmt_entry) ;
|
| 184 |
|
| }
|
| 185 |
|
|
|
| 186 |
0 |
| }
|