| 1 |
|
| /*
|
| 2 |
|
| * parse_si_cit.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_cit.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 |
|
| // content_identifier_section() {
|
| 43 |
|
| // table_id 8 uimsbf
|
| 44 |
|
| // section_syntax_indicator 1 bslbf
|
| 45 |
|
| // private_indicator 1 bslbf
|
| 46 |
|
| // reserved 2 bslbf
|
| 47 |
|
| // section_length 12 uimsbf
|
| 48 |
|
| // service_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 |
|
| // transport_stream_id 16 uimsbf
|
| 55 |
|
| // original_network_id 16 uimsbf
|
| 56 |
|
| // prepend_strings_length 8 uimsbf
|
| 57 |
|
| // for (i=0; i< prepend_strings_length ; i++) {
|
| 58 |
|
| // prepend_strings_byte 8 uimsbf
|
| 59 |
|
| // }
|
| 60 |
|
| // for (j=0; j<N; j++) {
|
| 61 |
|
| // crid_ref 16 uimsbf
|
| 62 |
|
| // prepend_string_index 8 uimsbf
|
| 63 |
|
| // unique_string_length 8 uimsbf
|
| 64 |
|
| // for (k=0; k<unique_string_length; k++) {
|
| 65 |
|
| // unique_string_byte 8 uimsbf
|
| 66 |
|
| // }
|
| 67 |
|
| // }
|
| 68 |
|
| // CRC32 32 rpchof
|
| 69 |
|
| // }
|
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
| /* ----------------------------------------------------------------------- */
|
| 73 |
0 |
| void print_cit(struct Section_content_identifier *cit)
|
| 74 |
|
| {
|
| 75 |
|
| struct list_head *item, *safe;
|
| 76 |
|
| int end_buff_len ;
|
| 77 |
|
|
|
| 78 |
0 |
| printf("Table: content_identifier [0x%02x]\n", cit->table_id) ;
|
| 79 |
0 |
| printf("Length: %d\n", cit->section_length) ;
|
| 80 |
|
|
|
| 81 |
|
| //== data ==
|
| 82 |
0 |
| printf("section_syntax_indicator = %d\n", cit->section_syntax_indicator) ;
|
| 83 |
0 |
| printf("private_indicator = %d\n", cit->private_indicator) ;
|
| 84 |
0 |
| printf("service_id = %d\n", cit->service_id) ;
|
| 85 |
0 |
| printf("version_number = %d\n", cit->version_number) ;
|
| 86 |
0 |
| printf("current_next_indicator = %d\n", cit->current_next_indicator) ;
|
| 87 |
0 |
| printf("section_number = %d\n", cit->section_number) ;
|
| 88 |
0 |
| printf("last_section_number = %d\n", cit->last_section_number) ;
|
| 89 |
0 |
| printf("transport_stream_id = %d\n", cit->transport_stream_id) ;
|
| 90 |
0 |
| printf("original_network_id = %d\n", cit->original_network_id) ;
|
| 91 |
0 |
| printf("prepend_strings_length = %d\n", cit->prepend_strings_length) ;
|
| 92 |
0 |
| printf("prepend_strings = \"%s\"\n", cit->prepend_strings) ;
|
| 93 |
|
|
|
| 94 |
0 |
▶ | list_for_each_safe(item,safe,&cit->cit_array) {
|
Branch: 1 branch
| Branch | True | False | Total |
| list_for_each_safe(item,safe,&cit->cit_array) {
|
0 |
0 |
0 |
|
| 95 |
0 |
| struct CIT_entry *cit_entry = list_entry(item, struct CIT_entry, next);
|
| 96 |
|
|
|
| 97 |
|
| // CIT entry
|
| 98 |
0 |
| printf(" -CIT entry-\n") ;
|
| 99 |
|
|
|
| 100 |
0 |
| printf(" crid_ref = %d\n", cit_entry->crid_ref) ;
|
| 101 |
0 |
| printf(" prepend_string_index = %d\n", cit_entry->prepend_string_index) ;
|
| 102 |
0 |
| printf(" unique_string_length = %d\n", cit_entry->unique_string_length) ;
|
| 103 |
0 |
| printf(" unique_string = \"%s\"\n", cit_entry->unique_string) ;
|
| 104 |
|
| }
|
| 105 |
|
|
|
| 106 |
0 |
| }
|
| 107 |
|
|
|
| 108 |
|
| /* ----------------------------------------------------------------------- */
|
| 109 |
0 |
| void parse_cit(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_content_identifier cit ;
|
| 113 |
|
| struct list_head *item, *safe;
|
| 114 |
|
| unsigned byte ;
|
| 115 |
|
| int end_buff_len ;
|
| 116 |
|
|
|
| 117 |
|
| //== Parse data ==
|
| 118 |
|
|
|
| 119 |
0 |
| cit.table_id = bits_get(bits, 8) ;
|
| 120 |
0 |
| cit.section_syntax_indicator = bits_get(bits, 1) ;
|
| 121 |
0 |
| cit.private_indicator = bits_get(bits, 1) ;
|
| 122 |
0 |
| bits_skip(bits, 2) ;
|
| 123 |
0 |
| cit.section_length = bits_get(bits, 12) ;
|
| 124 |
0 |
| cit.service_id = bits_get(bits, 16) ;
|
| 125 |
0 |
| bits_skip(bits, 2) ;
|
| 126 |
0 |
| cit.version_number = bits_get(bits, 5) ;
|
| 127 |
0 |
| cit.current_next_indicator = bits_get(bits, 1) ;
|
| 128 |
0 |
| cit.section_number = bits_get(bits, 8) ;
|
| 129 |
0 |
| cit.last_section_number = bits_get(bits, 8) ;
|
| 130 |
0 |
| cit.transport_stream_id = bits_get(bits, 16) ;
|
| 131 |
0 |
| cit.original_network_id = bits_get(bits, 16) ;
|
| 132 |
0 |
| cit.prepend_strings_length = bits_get(bits, 8) ;
|
| 133 |
|
|
|
| 134 |
0 |
| end_buff_len = bits_len_calc(bits, -cit.prepend_strings_length) ;
|
| 135 |
0 |
| cit.prepend_strings[0] = 0 ;
|
| 136 |
0 |
▶ | for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_PREPEND_STRINGS_LEN); ++byte)
|
Branch: 2 branches
| Branch | True | False | Total |
| for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_PREPEND_STRINGS_LEN); ++byte)
|
0 |
0 |
0 |
| for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_PREPEND_STRINGS_LEN); ++byte)
|
0 |
0 |
0 |
|
| 137 |
|
| {
|
| 138 |
0 |
| cit.prepend_strings[byte] = bits_get(bits, 8) ;
|
| 139 |
0 |
| cit.prepend_strings[byte+1] = 0 ;
|
| 140 |
|
| }
|
| 141 |
|
|
|
| 142 |
|
|
|
| 143 |
0 |
| INIT_LIST_HEAD(&cit.cit_array) ;
|
| 144 |
0 |
▶ | while (bits->buff_len >= 4)
|
Branch: 1 branch
| Branch | True | False | Total |
| while (bits->buff_len >= 4)
|
0 |
0 |
0 |
|
| 145 |
|
| {
|
| 146 |
0 |
| struct CIT_entry *cit_entry = malloc(sizeof(*cit_entry));
|
| 147 |
0 |
| memset(cit_entry,0,sizeof(*cit_entry));
|
| 148 |
0 |
| list_add_tail(&cit_entry->next,&cit.cit_array);
|
| 149 |
|
|
|
| 150 |
0 |
| cit_entry->crid_ref = bits_get(bits, 16) ;
|
| 151 |
0 |
| cit_entry->prepend_string_index = bits_get(bits, 8) ;
|
| 152 |
0 |
| cit_entry->unique_string_length = bits_get(bits, 8) ;
|
| 153 |
|
|
|
| 154 |
0 |
| end_buff_len = bits_len_calc(bits, -cit_entry->unique_string_length) ;
|
| 155 |
0 |
| cit_entry->unique_string[0] = 0 ;
|
| 156 |
0 |
▶ | for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_UNIQUE_STRING_LEN); ++byte)
|
Branch: 2 branches
| Branch | True | False | Total |
| for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_UNIQUE_STRING_LEN); ++byte)
|
0 |
0 |
0 |
| for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_UNIQUE_STRING_LEN); ++byte)
|
0 |
0 |
0 |
|
| 157 |
|
| {
|
| 158 |
0 |
| cit_entry->unique_string[byte] = bits_get(bits, 8) ;
|
| 159 |
0 |
| cit_entry->unique_string[byte+1] = 0 ;
|
| 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 *)&cit, tsreader->user_data) ;
|
| 168 |
|
|
|
| 169 |
|
| //== Tidy up ==
|
| 170 |
|
|
|
| 171 |
0 |
▶ | list_for_each_safe(item,safe,&cit.cit_array) {
|
Branch: 1 branch
| Branch | True | False | Total |
| list_for_each_safe(item,safe,&cit.cit_array) {
|
0 |
0 |
0 |
|
| 172 |
0 |
| struct CIT_entry *cit_entry = list_entry(item, struct CIT_entry, next);
|
| 173 |
0 |
| free(cit_entry) ;
|
| 174 |
|
| }
|
| 175 |
|
|
|
| 176 |
0 |
| }
|