1 /*****************************************************************************
2 * desc_2c.h: ISO/IEC 13818-1 Descriptor 0x2c (FlexMuxTiming 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 * - ISO/IEC 13818-1:2007(E) (MPEG-2 Systems)
31 */
32
33 #ifndef __BITSTREAM_MPEG_DESC_2C_H__
34 #define __BITSTREAM_MPEG_DESC_2C_H__
35
36 #include <bitstream/common.h>
37 #include <bitstream/mpeg/psi/descriptors.h>
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43
44 /*****************************************************************************
45 * Descriptor 0x2c (FlexMuxTiming descriptor)
46 *****************************************************************************/
47 #define DESC2C_HEADER_SIZE (DESC_HEADER_SIZE + 8)
48
desc2c_init(uint8_t * p_desc)49 static inline void desc2c_init(uint8_t *p_desc)
50 {
51 desc_set_tag(p_desc, 0x2c);
52 desc_set_length(p_desc, DESC2C_HEADER_SIZE - DESC_HEADER_SIZE);
53 }
54
desc2c_validate(const uint8_t * p_desc)55 static inline bool desc2c_validate(const uint8_t *p_desc)
56 {
57 return desc_get_length(p_desc) >= DESC2C_HEADER_SIZE - DESC_HEADER_SIZE;
58 }
59
desc2c_get_fcr_es_id(const uint8_t * p_desc)60 static inline uint16_t desc2c_get_fcr_es_id(const uint8_t *p_desc)
61 {
62 return (p_desc[2] << 8) | p_desc[3];
63 }
64
desc2c_set_fcr_es_id(uint8_t * p_desc,uint16_t i_fcr_es_id)65 static inline void desc2c_set_fcr_es_id(uint8_t *p_desc, uint16_t i_fcr_es_id)
66 {
67 p_desc[2] = (i_fcr_es_id >> 8) & 0xff;
68 p_desc[3] = i_fcr_es_id & 0xff;
69 }
70
desc2c_get_fcr_resolution(const uint8_t * p_desc)71 static inline uint32_t desc2c_get_fcr_resolution(const uint8_t *p_desc)
72 {
73 return (p_desc[4] << 24) | (p_desc[5] << 16) | (p_desc[6] << 8) | p_desc[7];
74 }
75
desc2c_set_fcr_resolution(uint8_t * p_desc,uint32_t i_fcr_resolution)76 static inline void desc2c_set_fcr_resolution(uint8_t *p_desc, uint32_t i_fcr_resolution)
77 {
78 p_desc[4] = (i_fcr_resolution >> 24) & 0xff;
79 p_desc[5] = (i_fcr_resolution >> 16) & 0xff;
80 p_desc[6] = (i_fcr_resolution >> 8) & 0xff;
81 p_desc[7] = i_fcr_resolution & 0xff;
82 }
83
desc2c_get_fcr_length(const uint8_t * p_desc)84 static inline uint8_t desc2c_get_fcr_length(const uint8_t *p_desc)
85 {
86 return p_desc[8];
87 }
88
desc2c_set_fcr_length(uint8_t * p_desc,uint8_t i_fcr_length)89 static inline void desc2c_set_fcr_length(uint8_t *p_desc, uint8_t i_fcr_length)
90 {
91 p_desc[8] = i_fcr_length;
92 }
93
desc2c_get_fmx_rate_length(const uint8_t * p_desc)94 static inline uint8_t desc2c_get_fmx_rate_length(const uint8_t *p_desc)
95 {
96 return p_desc[9];
97 }
98
desc2c_set_fmx_rate_length(uint8_t * p_desc,uint8_t i_fmx_rate_length)99 static inline void desc2c_set_fmx_rate_length(uint8_t *p_desc, uint8_t i_fmx_rate_length)
100 {
101 p_desc[9] = i_fmx_rate_length;
102 }
103
desc2c_print(const uint8_t * p_desc,f_print pf_print,void * opaque,print_type_t i_print_type)104 static inline void desc2c_print(const uint8_t *p_desc, f_print pf_print,
105 void *opaque, print_type_t i_print_type)
106 {
107 switch (i_print_type) {
108 case PRINT_XML:
109 pf_print(opaque, "<FLEXMUX_TIMING_DESC fcr_es_id=\"0x%04x\""
110 " fcr_resolution=\"%u\" fcr_length=\"%u\" fmx_rate_length=\"%u\"/>",
111 desc2c_get_fcr_es_id(p_desc),
112 desc2c_get_fcr_resolution(p_desc),
113 desc2c_get_fcr_length(p_desc),
114 desc2c_get_fmx_rate_length(p_desc)
115 );
116 break;
117 default:
118 pf_print(opaque," - desc 2c flexmux_timing fcr_es_id=0x%04x"
119 " fcr_resolution=%u fcr_length=%u fmx_rate_length=%u",
120 desc2c_get_fcr_es_id(p_desc),
121 desc2c_get_fcr_resolution(p_desc),
122 desc2c_get_fcr_length(p_desc),
123 desc2c_get_fmx_rate_length(p_desc)
124 );
125 }
126 }
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif
133