| 1 |
|
| /*
|
| 2 |
|
| * parse_si_sit.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_sit.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 |
|
| // selection_information_section(){
|
| 43 |
|
| // table_id 8 uimsbf
|
| 44 |
|
| // section_syntax_indicator 1 bslbf
|
| 45 |
|
| // DVB_reserved_future_use 1 bslbf
|
| 46 |
|
| // ISO_reserved 2 bslbf
|
| 47 |
|
| // section_length 12 uimsbf
|
| 48 |
|
| // DVB_reserved_future_use 16 uimsbf
|
| 49 |
|
| // ISO_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 |
|
| // DVB_reserved_for_future_use 4 uimsbf
|
| 55 |
|
| // transmission_info_loop_length 12 bslbf
|
| 56 |
|
| // for(i =0;i<N;i++) {
|
| 57 |
|
| // descriptor()
|
| 58 |
|
| // }
|
| 59 |
|
| // for(i=0;i<N;i++){
|
| 60 |
|
| // service_id 16 uimsbf
|
| 61 |
|
| // DVB_reserved_future_use 1 uimsbf
|
| 62 |
|
| // running_status 3 bslbf
|
| 63 |
|
| // service_loop_length 12 bslbf
|
| 64 |
|
| // for(j=0;j<N;j++){
|
| 65 |
|
| // descriptor()
|
| 66 |
|
| // }
|
| 67 |
|
| // }
|
| 68 |
|
| // CRC_32 32 rpchof
|
| 69 |
|
| // }
|
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
| /* ----------------------------------------------------------------------- */
|
| 73 |
0 |
| void print_sit(struct Section_selection_information *sit)
|
| 74 |
|
| {
|
| 75 |
|
| struct list_head *item, *safe;
|
| 76 |
|
| int end_buff_len ;
|
| 77 |
|
|
|
| 78 |
0 |
| printf("Table: selection_information [0x%02x]\n", sit->table_id) ;
|
| 79 |
0 |
| printf("Length: %d\n", sit->section_length) ;
|
| 80 |
|
|
|
| 81 |
|
| //== data ==
|
| 82 |
0 |
| printf("section_syntax_indicator = %d\n", sit->section_syntax_indicator) ;
|
| 83 |
0 |
| printf("version_number = %d\n", sit->version_number) ;
|
| 84 |
0 |
| printf("current_next_indicator = %d\n", sit->current_next_indicator) ;
|
| 85 |
0 |
| printf("section_number = %d\n", sit->section_number) ;
|
| 86 |
0 |
| printf("last_section_number = %d\n", sit->last_section_number) ;
|
| 87 |
0 |
| printf("transmission_info_loop_length = %d\n", sit->transmission_info_loop_length) ;
|
| 88 |
|
|
|
| 89 |
|
| // Descriptors list
|
| 90 |
0 |
| print_desc_list(&sit->transmission_info_array, 1) ;
|
| 91 |
|
|
|
| 92 |
0 |
▶ | list_for_each_safe(item,safe,&sit->sit_array) {
|
Branch: 1 branch
| Branch | True | False | Total |
| list_for_each_safe(item,safe,&sit->sit_array) {
|
0 |
0 |
0 |
|
| 93 |
0 |
| struct SIT_entry *sit_entry = list_entry(item, struct SIT_entry, next);
|
| 94 |
|
|
|
| 95 |
|
| // SIT entry
|
| 96 |
0 |
| printf(" -SIT entry-\n") ;
|
| 97 |
|
|
|
| 98 |
0 |
| printf(" service_id = %d\n", sit_entry->service_id) ;
|
| 99 |
0 |
| printf(" running_status = %d\n", sit_entry->running_status) ;
|
| 100 |
0 |
| printf(" service_loop_length = %d\n", sit_entry->service_loop_length) ;
|
| 101 |
|
|
|
| 102 |
|
| // Descriptors list
|
| 103 |
0 |
| print_desc_list(&sit_entry->service_array, 1) ;
|
| 104 |
|
| }
|
| 105 |
|
|
|
| 106 |
0 |
| }
|
| 107 |
|
|
|
| 108 |
|
| /* ----------------------------------------------------------------------- */
|
| 109 |
0 |
| void parse_sit(struct TS_reader *tsreader, struct TS_state *tsstate, struct TS_bits *bits,
|
| 110 |
|
| Section_handler handler, struct Section_decode_flags *flags)
|
| 111 |
|
| {
|
| 112 |
|
| struct Section_selection_information sit ;
|
| 113 |
|
| struct list_head *item, *safe;
|
| 114 |
|
| unsigned byte ;
|
| 115 |
|
| int end_buff_len ;
|
| 116 |
|
|
|
| 117 |
|
| //== Parse data ==
|
| 118 |
|
|
|
| 119 |
0 |
| sit.table_id = bits_get(bits, 8) ;
|
| 120 |
0 |
| sit.section_syntax_indicator = bits_get(bits, 1) ;
|
| 121 |
0 |
| bits_skip(bits, 1) ;
|
| 122 |
0 |
| bits_skip(bits, 2) ;
|
| 123 |
0 |
| sit.section_length = bits_get(bits, 12) ;
|
| 124 |
0 |
| bits_skip(bits, 16) ;
|
| 125 |
0 |
| bits_skip(bits, 2) ;
|
| 126 |
0 |
| sit.version_number = bits_get(bits, 5) ;
|
| 127 |
0 |
| sit.current_next_indicator = bits_get(bits, 1) ;
|
| 128 |
0 |
| sit.section_number = bits_get(bits, 8) ;
|
| 129 |
0 |
| sit.last_section_number = bits_get(bits, 8) ;
|
| 130 |
0 |
| bits_skip(bits, 4) ;
|
| 131 |
0 |
| sit.transmission_info_loop_length = bits_get(bits, 12) ;
|
| 132 |
|
|
|
| 133 |
|
| // Descriptors
|
| 134 |
0 |
| INIT_LIST_HEAD(&sit.transmission_info_array);
|
| 135 |
0 |
| end_buff_len = bits_len_calc(bits, -sit.transmission_info_loop_length ) ;
|
| 136 |
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 |
|
| 137 |
|
| {
|
| 138 |
0 |
| enum TS_descriptor_ids desc_tag = parse_desc(&sit.transmission_info_array, bits, flags->decode_descriptor) ;
|
| 139 |
|
| }
|
| 140 |
|
|
|
| 141 |
|
|
|
| 142 |
0 |
| INIT_LIST_HEAD(&sit.sit_array) ;
|
| 143 |
0 |
▶ | while (bits->buff_len >= 4)
|
Branch: 1 branch
| Branch | True | False | Total |
| while (bits->buff_len >= 4)
|
0 |
0 |
0 |
|
| 144 |
|
| {
|
| 145 |
0 |
| struct SIT_entry *sit_entry = malloc(sizeof(*sit_entry));
|
| 146 |
0 |
| memset(sit_entry,0,sizeof(*sit_entry));
|
| 147 |
0 |
| list_add_tail(&sit_entry->next,&sit.sit_array);
|
| 148 |
|
|
|
| 149 |
0 |
| sit_entry->service_id = bits_get(bits, 16) ;
|
| 150 |
0 |
| bits_skip(bits, 1) ;
|
| 151 |
0 |
| sit_entry->running_status = bits_get(bits, 3) ;
|
| 152 |
0 |
| sit_entry->service_loop_length = bits_get(bits, 12) ;
|
| 153 |
|
|
|
| 154 |
|
| // Descriptors
|
| 155 |
0 |
| INIT_LIST_HEAD(&sit_entry->service_array);
|
| 156 |
0 |
| end_buff_len = bits_len_calc(bits, -sit_entry->service_loop_length ) ;
|
| 157 |
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 |
|
| 158 |
|
| {
|
| 159 |
0 |
| enum TS_descriptor_ids desc_tag = parse_desc(&sit_entry->service_array, bits, flags->decode_descriptor) ;
|
| 160 |
|
| }
|
| 161 |
|
|
|
| 162 |
|
| }
|
| 163 |
|
|
|
| 164 |
|
|
|
| 165 |
|
| //== Call handler ==
|
| 166 |
0 |
▶ | if (handler)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (handler)
|
0 |
0 |
0 |
|
| 167 |
0 |
| handler(tsreader, tsstate, (struct Section *)&sit, tsreader->user_data) ;
|
| 168 |
|
|
|
| 169 |
|
| //== Tidy up ==
|
| 170 |
0 |
| free_descriptors_list(&sit.transmission_info_array);
|
| 171 |
|
|
|
| 172 |
0 |
▶ | list_for_each_safe(item,safe,&sit.sit_array) {
|
Branch: 1 branch
| Branch | True | False | Total |
| list_for_each_safe(item,safe,&sit.sit_array) {
|
0 |
0 |
0 |
|
| 173 |
0 |
| struct SIT_entry *sit_entry = list_entry(item, struct SIT_entry, next);
|
| 174 |
0 |
| free_descriptors_list(&sit_entry->service_array);
|
| 175 |
0 |
| free(sit_entry) ;
|
| 176 |
|
| }
|
| 177 |
|
|
|
| 178 |
0 |
| }
|