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