« clib/dvb_ts_lib/descriptors/parse_desc_transport_stream.c
↑ Summary
clib/dvb_ts_lib/descriptors/parse_desc_vbi_data.c »
| 1 | /* | ||||||||||||||
| 2 | * parse_desc_tva_content_identifier.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_desc_tva_content_identifier.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 | // TVA_content_identifier_descriptor() { | ||||||||||||||
| 43 | // descriptor_tag 8 uimsbf | ||||||||||||||
| 44 | // descriptor_length 8 uimsbf | ||||||||||||||
| 45 | // for (i=0;i<N;i++) { | ||||||||||||||
| 46 | // crid_type 6 uimsbf | ||||||||||||||
| 47 | // crid_location 2 uimsbf | ||||||||||||||
| 48 | // if (crid_location == '00' ) { | ||||||||||||||
| 49 | // crid_length 8 uimsbf | ||||||||||||||
| 50 | // for (j=0;j<crid_length;j++) { | ||||||||||||||
| 51 | // crid_byte 8 uimsbf | ||||||||||||||
| 52 | // } | ||||||||||||||
| 53 | // } | ||||||||||||||
| 54 | // if (crid_location == '01' ) { | ||||||||||||||
| 55 | // crid_ref 16 uimsbf | ||||||||||||||
| 56 | // } | ||||||||||||||
| 57 | // } | ||||||||||||||
| 58 | // } | ||||||||||||||
| 59 | |||||||||||||||
| 60 | |||||||||||||||
| 61 | /* ----------------------------------------------------------------------- */ | ||||||||||||||
| 62 | 0 | void print_tva_content_identifier(struct Descriptor_tva_content_identifier *tcid, int level) | |||||||||||||
| 63 | { | ||||||||||||||
| 64 | struct list_head *item, *safe; | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | printf(" Descriptor: tva_content_identifier [0x%02x]\n", tcid->descriptor_tag) ; | |||||||||||||
| 67 | 0 | printf(" Length: %d\n", tcid->descriptor_length) ; | |||||||||||||
| 68 | |||||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | ▶ | list_for_each_safe(item,safe,&tcid->tcid_array) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | 0 | struct TCID_entry *tcid_entry = list_entry(item, struct TCID_entry, next); | |||||||||||||
| 72 | |||||||||||||||
| 73 | // TCID entry | ||||||||||||||
| 74 | 0 | printf(" -TCID entry-\n") ; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | printf(" crid_type = %d\n", tcid_entry->crid_type) ; | |||||||||||||
| 77 | 0 | printf(" crid_location = %d\n", tcid_entry->crid_location) ; | |||||||||||||
| 78 | 0 | ▶ | if (tcid_entry->crid_location == 0x0 ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | { | ||||||||||||||
| 80 | 0 | printf(" crid_length = %d\n", tcid_entry->crid_length) ; | |||||||||||||
| 81 | 0 | printf(" crid = \"%s\"\n", tcid_entry->crid) ; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | ▶ | if (tcid_entry->crid_location == 0x1 ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | { | ||||||||||||||
| 86 | 0 | printf(" crid_ref = %d\n", tcid_entry->crid_ref) ; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | } | |||||||||||||
| 92 | |||||||||||||||
| 93 | /* ----------------------------------------------------------------------- */ | ||||||||||||||
| 94 | 0 | struct Descriptor *parse_tva_content_identifier(struct TS_bits *bits, unsigned tag, unsigned len) | |||||||||||||
| 95 | { | ||||||||||||||
| 96 | struct Descriptor_tva_content_identifier *tcid ; | ||||||||||||||
| 97 | unsigned byte ; | ||||||||||||||
| 98 | int end_buff_len ; | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | tcid = (struct Descriptor_tva_content_identifier *)malloc( sizeof(*tcid) ) ; | |||||||||||||
| 101 | 0 | memset(tcid,0,sizeof(*tcid)); | |||||||||||||
| 102 | |||||||||||||||
| 103 | //== Parse data == | ||||||||||||||
| 104 | 0 | INIT_LIST_HEAD(&tcid->next); | |||||||||||||
| 105 | 0 | tcid->descriptor_tag = tag ; // already extracted by parse_desc() | |||||||||||||
| 106 | 0 | tcid->descriptor_length = len ; // already extracted by parse_desc() | |||||||||||||
| 107 | |||||||||||||||
| 108 | 0 | INIT_LIST_HEAD(&tcid->tcid_array) ; | |||||||||||||
| 109 | 0 | end_buff_len = bits_len_calc(bits, -tcid->descriptor_length ) ; | |||||||||||||
| 110 | 0 | ▶ | while (bits->buff_len > end_buff_len) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | { | ||||||||||||||
| 112 | 0 | struct TCID_entry *tcid_entry = malloc(sizeof(*tcid_entry)); | |||||||||||||
| 113 | 0 | memset(tcid_entry,0,sizeof(*tcid_entry)); | |||||||||||||
| 114 | 0 | list_add_tail(&tcid_entry->next,&tcid->tcid_array); | |||||||||||||
| 115 | |||||||||||||||
| 116 | 0 | tcid_entry->crid_type = bits_get(bits, 6) ; | |||||||||||||
| 117 | 0 | tcid_entry->crid_location = bits_get(bits, 2) ; | |||||||||||||
| 118 | 0 | ▶ | if (tcid_entry->crid_location == 0x0 ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 119 | { | ||||||||||||||
| 120 | 0 | tcid_entry->crid_length = bits_get(bits, 8) ; | |||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | end_buff_len = bits_len_calc(bits, -tcid_entry->crid_length) ; | |||||||||||||
| 123 | 0 | tcid_entry->crid[0] = 0 ; | |||||||||||||
| 124 | 0 | ▶ | for (byte=0; (bits->buff_len > end_buff_len) && (byte < MAX_CRID_LEN); ++byte) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 125 | { | ||||||||||||||
| 126 | 0 | tcid_entry->crid[byte] = bits_get(bits, 8) ; | |||||||||||||
| 127 | 0 | tcid_entry->crid[byte+1] = 0 ; | |||||||||||||
| 128 | } | ||||||||||||||
| 129 | |||||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | 0 | ▶ | if (tcid_entry->crid_location == 0x1 ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 133 | { | ||||||||||||||
| 134 | 0 | tcid_entry->crid_ref = bits_get(bits, 16) ; | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | |||||||||||||||
| 137 | } | ||||||||||||||
| 138 | |||||||||||||||
| 139 | |||||||||||||||
| 140 | 0 | return (struct Descriptor *)tcid ; | |||||||||||||
| 141 | } | ||||||||||||||
| 142 | |||||||||||||||
| 143 | /* ----------------------------------------------------------------------- */ | ||||||||||||||
| 144 | 0 | void free_tva_content_identifier(struct Descriptor_tva_content_identifier *tcid) | |||||||||||||
| 145 | { | ||||||||||||||
| 146 | struct list_head *item, *safe; | ||||||||||||||
| 147 | |||||||||||||||
| 148 | 0 | ▶ | list_for_each_safe(item,safe,&tcid->tcid_array) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 149 | 0 | struct TCID_entry *tcid_entry = list_entry(item, struct TCID_entry, next); | |||||||||||||
| 150 | 0 | free(tcid_entry) ; | |||||||||||||
| 151 | } | ||||||||||||||
| 152 | |||||||||||||||
| 153 | |||||||||||||||
| 154 | 0 | free(tcid) ; | |||||||||||||
| 155 | 0 | } | |||||||||||||