« clib/dvb_ts_lib/descriptors/parse_desc_nvod_reference.c
↑ Summary
clib/dvb_ts_lib/descriptors/parse_desc_partial_transport_stream.c »
| 1 | /* | ||||||||||
| 2 | * parse_desc_parental_rating.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_parental_rating.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 | // parental_rating_descriptor(){ | ||||||||||
| 43 | // descriptor_tag 8 uimsbf | ||||||||||
| 44 | // descriptor_length 8 uimsbf | ||||||||||
| 45 | // for (i=0;i<N;i++){ | ||||||||||
| 46 | // country_code 24 bslbf | ||||||||||
| 47 | // rating 8 uimsbf | ||||||||||
| 48 | // } | ||||||||||
| 49 | // } | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | /* ----------------------------------------------------------------------- */ | ||||||||||
| 53 | 0 | void print_parental_rating(struct Descriptor_parental_rating *prd, int level) | |||||||||
| 54 | { | ||||||||||
| 55 | struct list_head *item, *safe; | ||||||||||
| 56 | |||||||||||
| 57 | 0 | printf(" Descriptor: parental_rating [0x%02x]\n", prd->descriptor_tag) ; | |||||||||
| 58 | 0 | printf(" Length: %d\n", prd->descriptor_length) ; | |||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | list_for_each_safe(item,safe,&prd->prd_array) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | struct PRD_entry *prd_entry = list_entry(item, struct PRD_entry, next); | |||||||||
| 63 | |||||||||||
| 64 | // PRD entry | ||||||||||
| 65 | 0 | printf(" -PRD entry-\n") ; | |||||||||
| 66 | |||||||||||
| 67 | 0 | printf(" country_code = %d\n", prd_entry->country_code) ; | |||||||||
| 68 | 0 | printf(" rating = %d\n", prd_entry->rating) ; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | } | |||||||||
| 72 | |||||||||||
| 73 | /* ----------------------------------------------------------------------- */ | ||||||||||
| 74 | 0 | struct Descriptor *parse_parental_rating(struct TS_bits *bits, unsigned tag, unsigned len) | |||||||||
| 75 | { | ||||||||||
| 76 | struct Descriptor_parental_rating *prd ; | ||||||||||
| 77 | unsigned byte ; | ||||||||||
| 78 | int end_buff_len ; | ||||||||||
| 79 | |||||||||||
| 80 | 0 | prd = (struct Descriptor_parental_rating *)malloc( sizeof(*prd) ) ; | |||||||||
| 81 | 0 | memset(prd,0,sizeof(*prd)); | |||||||||
| 82 | |||||||||||
| 83 | //== Parse data == | ||||||||||
| 84 | 0 | INIT_LIST_HEAD(&prd->next); | |||||||||
| 85 | 0 | prd->descriptor_tag = tag ; // already extracted by parse_desc() | |||||||||
| 86 | 0 | prd->descriptor_length = len ; // already extracted by parse_desc() | |||||||||
| 87 | |||||||||||
| 88 | 0 | INIT_LIST_HEAD(&prd->prd_array) ; | |||||||||
| 89 | 0 | end_buff_len = bits_len_calc(bits, -prd->descriptor_length ) ; | |||||||||
| 90 | 0 | ▶ | while (bits->buff_len > end_buff_len) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | { | ||||||||||
| 92 | 0 | struct PRD_entry *prd_entry = malloc(sizeof(*prd_entry)); | |||||||||
| 93 | 0 | memset(prd_entry,0,sizeof(*prd_entry)); | |||||||||
| 94 | 0 | list_add_tail(&prd_entry->next,&prd->prd_array); | |||||||||
| 95 | |||||||||||
| 96 | 0 | prd_entry->country_code = bits_get(bits, 24) ; | |||||||||
| 97 | 0 | prd_entry->rating = bits_get(bits, 8) ; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | |||||||||||
| 101 | 0 | return (struct Descriptor *)prd ; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | /* ----------------------------------------------------------------------- */ | ||||||||||
| 105 | 0 | void free_parental_rating(struct Descriptor_parental_rating *prd) | |||||||||
| 106 | { | ||||||||||
| 107 | struct list_head *item, *safe; | ||||||||||
| 108 | |||||||||||
| 109 | 0 | ▶ | list_for_each_safe(item,safe,&prd->prd_array) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | struct PRD_entry *prd_entry = list_entry(item, struct PRD_entry, next); | |||||||||
| 111 | 0 | free(prd_entry) ; | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | |||||||||||
| 115 | 0 | free(prd) ; | |||||||||
| 116 | 0 | } | |||||||||