1 /*****************************************************************************
2 * desc_50.h: ETSI EN 300 468 Descriptor 0x50: Component descriptor
3 *****************************************************************************
4 * Copyright (C) 2011 Unix Solutions Ltd.
5 *
6 * Authors: Georgi Chorbadzhiyski <georgi@unixsol.org>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject
14 * to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *****************************************************************************/
27
28 /*
29 * Normative references:
30 * - ETSI EN 300 468 V1.11.1 (2010-04) (SI in DVB systems)
31 */
32
33 #ifndef __BITSTREAM_DVB_DESC_50_H__
34 #define __BITSTREAM_DVB_DESC_50_H__
35
36 #include <bitstream/common.h>
37 #include <bitstream/mpeg/psi/descriptors.h>
38 #include <bitstream/dvb/si/strings.h>
39
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44
45 /*****************************************************************************
46 * Descriptor 0x50: Component descriptor
47 *****************************************************************************/
48 #define DESC50_HEADER_SIZE (DESC_HEADER_SIZE + 6)
49
desc50_init(uint8_t * p_desc)50 static inline void desc50_init(uint8_t *p_desc)
51 {
52 desc_set_tag(p_desc, 0x50);
53 p_desc[2] = 0xf0;
54 desc_set_length(p_desc, DESC50_HEADER_SIZE - DESC_HEADER_SIZE);
55 }
56
desc50_get_stream_content(const uint8_t * p_desc)57 static inline uint8_t desc50_get_stream_content(const uint8_t *p_desc)
58 {
59 return p_desc[2] & 0x0f;
60 }
61
desc50_set_stream_content(uint8_t * p_desc,uint8_t i_stream_content)62 static inline void desc50_set_stream_content(uint8_t *p_desc, uint8_t i_stream_content)
63 {
64 p_desc[2] = 0xf0 | (i_stream_content & 0x0f);
65 }
66
desc50_get_component_type(const uint8_t * p_desc)67 static inline uint8_t desc50_get_component_type(const uint8_t *p_desc)
68 {
69 return p_desc[3];
70 }
71
desc50_set_component_type(uint8_t * p_desc,uint8_t i_component_type)72 static inline void desc50_set_component_type(uint8_t *p_desc, uint8_t i_component_type)
73 {
74 p_desc[3] = i_component_type;
75 }
76
desc50_get_component_tag(const uint8_t * p_desc)77 static inline uint8_t desc50_get_component_tag(const uint8_t *p_desc)
78 {
79 return p_desc[4];
80 }
81
desc50_set_component_tag(uint8_t * p_desc,uint8_t i_component_tag)82 static inline void desc50_set_component_tag(uint8_t *p_desc, uint8_t i_component_tag)
83 {
84 p_desc[4] = i_component_tag;
85 }
86
desc50_set_language(uint8_t * p_desc,const uint8_t p_language[3])87 static inline void desc50_set_language(uint8_t *p_desc, const uint8_t p_language[3])
88 {
89 p_desc[5] = p_language[0];
90 p_desc[6] = p_language[1];
91 p_desc[7] = p_language[2];
92 }
93
desc50_get_language(const uint8_t * p_desc)94 static inline const uint8_t *desc50_get_language(const uint8_t *p_desc)
95 {
96 return p_desc + 5;
97 }
98
desc50_get_text(const uint8_t * p_desc,uint8_t * pi_length)99 static inline const uint8_t *desc50_get_text(const uint8_t *p_desc, uint8_t *pi_length)
100 {
101 *pi_length = desc_get_length(p_desc) - (DESC50_HEADER_SIZE - DESC_HEADER_SIZE);
102 return p_desc + DESC50_HEADER_SIZE;
103 }
104
desc50_set_text(uint8_t * p_desc,const uint8_t * p_text,uint8_t i_length)105 static inline void desc50_set_text(uint8_t *p_desc, const uint8_t *p_text, uint8_t i_length)
106 {
107 desc_set_length(p_desc, DESC50_HEADER_SIZE - DESC_HEADER_SIZE + i_length);
108 memcpy(p_desc + DESC50_HEADER_SIZE, p_text, i_length);
109 }
110
desc50_validate(const uint8_t * p_desc)111 static inline bool desc50_validate(const uint8_t *p_desc)
112 {
113 return desc_get_length(p_desc) >= DESC50_HEADER_SIZE - DESC_HEADER_SIZE;
114 }
115
desc50_print(const uint8_t * p_desc,f_print pf_print,void * print_opaque,f_iconv pf_iconv,void * iconv_opaque,print_type_t i_print_type)116 static inline void desc50_print(const uint8_t *p_desc,
117 f_print pf_print, void *print_opaque,
118 f_iconv pf_iconv, void *iconv_opaque,
119 print_type_t i_print_type)
120 {
121 uint8_t i_text_len;
122 const uint8_t *p_text = desc50_get_text(p_desc, &i_text_len);
123 char *psz_text = dvb_string_get(p_text, i_text_len, pf_iconv, iconv_opaque);
124
125 switch (i_print_type) {
126 case PRINT_XML:
127 psz_text = dvb_string_xml_escape(psz_text);
128 pf_print(print_opaque,
129 "<COMPONENT_DESC stream_content=\"0x%02x\" component_type=\"0x%02x\""
130 " component_tag=\"%u\" language=\"%3.3s\" text=\"%s\"/>",
131 desc50_get_stream_content(p_desc),
132 desc50_get_component_type(p_desc),
133 desc50_get_component_tag(p_desc),
134 (char *)desc50_get_language(p_desc),
135 psz_text
136 );
137 break;
138 default:
139 pf_print(print_opaque,
140 " - desc 50 component stream_content=0x%02x component_type=0x%02x"
141 " component_tag=%u language=%3.3s text=\"%s\"/>",
142 desc50_get_stream_content(p_desc),
143 desc50_get_component_type(p_desc),
144 desc50_get_component_tag(p_desc),
145 (char *)desc50_get_language(p_desc),
146 psz_text
147 );
148 }
149
150 free(psz_text);
151 }
152
153 #ifdef __cplusplus
154 }
155 #endif
156
157 #endif
158