1 /*****************************************************************************
2  * desc_0f.h: ISO/IEC 13818-1 Descriptor 0x0f (Private data indicator)
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_0F_H__
34 #define __BITSTREAM_MPEG_DESC_0F_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 0x0f: Private data indicator descriptor
46  *****************************************************************************/
47 #define DESC0F_HEADER_SIZE      (DESC_HEADER_SIZE + 4)
48 
desc0f_init(uint8_t * p_desc)49 static inline void desc0f_init(uint8_t *p_desc)
50 {
51     desc_set_tag(p_desc, 0x0F);
52     desc_set_length(p_desc, DESC0F_HEADER_SIZE - DESC_HEADER_SIZE);
53 }
54 
desc0f_get_private_indicator(const uint8_t * p_desc)55 static inline uint32_t desc0f_get_private_indicator(const uint8_t *p_desc)
56 {
57     return (p_desc[2] << 24) | (p_desc[3] << 16) | (p_desc[4] << 8) | p_desc[5];
58 }
59 
desc0f_set_private_indicator(uint8_t * p_desc,uint32_t i_private_indicator)60 static inline void desc0f_set_private_indicator(uint8_t *p_desc, uint32_t i_private_indicator)
61 {
62     p_desc[2] = (i_private_indicator >> 24) & 0xff;
63     p_desc[3] = (i_private_indicator >> 16) & 0xff;
64     p_desc[4] = (i_private_indicator >>  8) & 0xff;
65     p_desc[5] =  i_private_indicator        & 0xff;;
66 }
67 
desc0f_validate(const uint8_t * p_desc)68 static inline bool desc0f_validate(const uint8_t *p_desc)
69 {
70     return desc_get_length(p_desc) >= DESC0F_HEADER_SIZE - DESC_HEADER_SIZE;
71 }
72 
desc0f_print(const uint8_t * p_desc,f_print pf_print,void * opaque,print_type_t i_print_type)73 static inline void desc0f_print(const uint8_t *p_desc, f_print pf_print,
74                                 void *opaque, print_type_t i_print_type)
75 {
76     switch (i_print_type) {
77     case PRINT_XML:
78         pf_print(opaque, "<PRIVATE_DATA_INDICATOR_DESC private_indicator=\"0x%08x\"/>",
79                  desc0f_get_private_indicator(p_desc));
80         break;
81     default:
82         pf_print(opaque, "    - desc 0f private_data_indicator private_indicator=0x%08x",
83                  desc0f_get_private_indicator(p_desc));
84     }
85 }
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif
92