1 /*****************************************************************************
2 * desc_28.h: ISO/IEC 13818-1 Descriptor 0x28 (AVC video 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_28_H__
34 #define __BITSTREAM_MPEG_DESC_28_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 0x28 (AVC video descriptor)
46 *****************************************************************************/
47 #define DESC28_HEADER_SIZE (DESC_HEADER_SIZE + 4)
48
desc28_init(uint8_t * p_desc)49 static inline void desc28_init(uint8_t *p_desc)
50 {
51 desc_set_tag(p_desc, 0x28);
52 desc_set_length(p_desc, DESC28_HEADER_SIZE - DESC_HEADER_SIZE);
53 p_desc[5] = 0x3f;
54 }
55
desc28_validate(const uint8_t * p_desc)56 static inline bool desc28_validate(const uint8_t *p_desc)
57 {
58 return desc_get_length(p_desc) >= DESC28_HEADER_SIZE - DESC_HEADER_SIZE;
59 }
60
desc28_get_profile_idc(const uint8_t * p_desc)61 static inline uint8_t desc28_get_profile_idc(const uint8_t *p_desc)
62 {
63 return p_desc[2];
64 }
65
desc28_set_profile_idc(uint8_t * p_desc,uint8_t i_profile_idc)66 static inline void desc28_set_profile_idc(uint8_t *p_desc, uint8_t i_profile_idc)
67 {
68 p_desc[2] = i_profile_idc;
69 }
70
desc28_get_constraint_set0_flag(const uint8_t * p_desc)71 static inline bool desc28_get_constraint_set0_flag(const uint8_t *p_desc)
72 {
73 return (p_desc[3] & 0x80) == 0x80;
74 }
75
desc28_set_constraint_set0_flag(uint8_t * p_desc,bool b_constraint_set0_flag)76 static inline void desc28_set_constraint_set0_flag(uint8_t *p_desc, bool b_constraint_set0_flag)
77 {
78 p_desc[3] = b_constraint_set0_flag ? (p_desc[3] | 0x80) : (p_desc[3] &~ 0x80);
79 }
80
desc28_get_constraint_set1_flag(const uint8_t * p_desc)81 static inline bool desc28_get_constraint_set1_flag(const uint8_t *p_desc)
82 {
83 return (p_desc[3] & 0x40) == 0x40;
84 }
85
desc28_set_constraint_set1_flag(uint8_t * p_desc,bool b_constraint_set1_flag)86 static inline void desc28_set_constraint_set1_flag(uint8_t *p_desc, bool b_constraint_set1_flag)
87 {
88 p_desc[3] = b_constraint_set1_flag ? (p_desc[3] | 0x40) : (p_desc[3] &~ 0x40);
89 }
90
desc28_get_constraint_set2_flag(const uint8_t * p_desc)91 static inline bool desc28_get_constraint_set2_flag(const uint8_t *p_desc)
92 {
93 return (p_desc[3] & 0x20) == 0x20;
94 }
95
desc28_set_constraint_set2_flag(uint8_t * p_desc,bool b_constraint_set2_flag)96 static inline void desc28_set_constraint_set2_flag(uint8_t *p_desc, bool b_constraint_set2_flag)
97 {
98 p_desc[3] = b_constraint_set2_flag ? (p_desc[3] | 0x20) : (p_desc[3] &~ 0x20);
99 }
100
desc28_get_avc_compatible_flags(const uint8_t * p_desc)101 static inline uint8_t desc28_get_avc_compatible_flags(const uint8_t *p_desc)
102 {
103 return p_desc[3] & 0x1f;
104 }
105
desc28_set_avc_compatible_flags(uint8_t * p_desc,uint8_t i_avc_compatible_flags)106 static inline void desc28_set_avc_compatible_flags(uint8_t *p_desc, uint8_t i_avc_compatible_flags)
107 {
108 p_desc[3] = (p_desc[3] & 0xe0) | (i_avc_compatible_flags & 0x1f);
109 }
110
desc28_get_level_idc(const uint8_t * p_desc)111 static inline uint8_t desc28_get_level_idc(const uint8_t *p_desc)
112 {
113 return p_desc[4];
114 }
115
desc28_set_level_idc(uint8_t * p_desc,uint8_t i_level_idc)116 static inline void desc28_set_level_idc(uint8_t *p_desc, uint8_t i_level_idc)
117 {
118 p_desc[4] = i_level_idc;
119 }
120
desc28_get_avc_still_present(const uint8_t * p_desc)121 static inline bool desc28_get_avc_still_present(const uint8_t *p_desc)
122 {
123 return (p_desc[5] & 0x80) == 0x80;
124 }
125
desc28_set_avc_still_present(uint8_t * p_desc,bool b_avc_still_present)126 static inline void desc28_set_avc_still_present(uint8_t *p_desc, bool b_avc_still_present)
127 {
128 p_desc[5] = b_avc_still_present ? (p_desc[5] | 0x80) : (p_desc[5] &~ 0x80);
129 }
130
desc28_get_avc_24_hour_picture_flag(const uint8_t * p_desc)131 static inline bool desc28_get_avc_24_hour_picture_flag(const uint8_t *p_desc)
132 {
133 return (p_desc[5] & 0x40) == 0x40;
134 }
135
desc28_set_avc_24_hour_picture_flag(uint8_t * p_desc,bool b_avc_24_hour_picture_flag)136 static inline void desc28_set_avc_24_hour_picture_flag(uint8_t *p_desc, bool b_avc_24_hour_picture_flag)
137 {
138 p_desc[5] = b_avc_24_hour_picture_flag ? (p_desc[5] | 0x40) : (p_desc[5] &~ 0x40);
139 }
140
desc28_print(const uint8_t * p_desc,f_print pf_print,void * opaque,print_type_t i_print_type)141 static inline void desc28_print(const uint8_t *p_desc, f_print pf_print,
142 void *opaque, print_type_t i_print_type)
143 {
144 switch (i_print_type) {
145 case PRINT_XML:
146 pf_print(opaque, "<AVC_VIDEO_DESC profile_idc=\"0x%02x\" constraint_set0_flag=\"%u\""
147 " constraint_set1_flag=\"%u\" constraint_set2_flag=\"%u\""
148 " AVC_compatible_flags=\"0x%02x\" level_idc=\"0x%02x\""
149 " AVC_still_present=\"%u\" AVC_24_hour_picture_flag=\"%u\"/>",
150 desc28_get_profile_idc(p_desc),
151 desc28_get_constraint_set0_flag(p_desc),
152 desc28_get_constraint_set1_flag(p_desc),
153 desc28_get_constraint_set2_flag(p_desc),
154 desc28_get_avc_compatible_flags(p_desc),
155 desc28_get_level_idc(p_desc),
156 desc28_get_avc_still_present(p_desc),
157 desc28_get_avc_24_hour_picture_flag(p_desc)
158 );
159 break;
160 default:
161 pf_print(opaque," - desc 28 avc_video profile_idc=0x%02x constraint_set0_flag=%u"
162 " constraint_set1_flag=%u constraint_set2_flag=%u"
163 " AVC_compatible_flags=0x%02x level_idc=0x%02x"
164 " AVC_still_present=%u AVC_24_hour_picture_flag=%u",
165 desc28_get_profile_idc(p_desc),
166 desc28_get_constraint_set0_flag(p_desc),
167 desc28_get_constraint_set1_flag(p_desc),
168 desc28_get_constraint_set2_flag(p_desc),
169 desc28_get_avc_compatible_flags(p_desc),
170 desc28_get_level_idc(p_desc),
171 desc28_get_avc_still_present(p_desc),
172 desc28_get_avc_24_hour_picture_flag(p_desc)
173 );
174 }
175 }
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif
182