1 /*****************************************************************************
2 * desc_1f.h: ISO/IEC 13818-1 Descriptor 0x1f (FMC 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_1F_H__
34 #define __BITSTREAM_MPEG_DESC_1F_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 0x1f: FMC descriptor
46 *****************************************************************************/
47 #define DESC1F_HEADER_SIZE DESC_HEADER_SIZE
48 #define DESC1F_ENTRY_SIZE 3
49
desc1f_init(uint8_t * p_desc)50 static inline void desc1f_init(uint8_t *p_desc)
51 {
52 desc_set_tag(p_desc, 0x1f);
53 }
54
desc1f_get_entry(uint8_t * p_desc,uint8_t n)55 static inline uint8_t *desc1f_get_entry(uint8_t *p_desc, uint8_t n)
56 {
57 uint8_t *p_desc_n = p_desc + DESC1F_HEADER_SIZE + n * DESC1F_ENTRY_SIZE;
58 if (p_desc_n + DESC1F_ENTRY_SIZE - p_desc
59 > desc_get_length(p_desc) + DESC1F_HEADER_SIZE)
60 return NULL;
61 return p_desc_n;
62 }
63
desc1fn_get_es_id(const uint8_t * p_desc)64 static inline uint16_t desc1fn_get_es_id(const uint8_t *p_desc)
65 {
66 return (p_desc[0] << 8) | p_desc[1];
67 }
68
desc1fn_set_es_id(uint8_t * p_desc_n,uint16_t i_es_id)69 static inline void desc1fn_set_es_id(uint8_t *p_desc_n, uint16_t i_es_id)
70 {
71 p_desc_n[0] = (i_es_id >> 8) & 0xff;
72 p_desc_n[1] = i_es_id & 0xff;
73 }
74
desc1fn_get_flexmux_channel(const uint8_t * p_desc_n)75 static inline uint8_t desc1fn_get_flexmux_channel(const uint8_t *p_desc_n)
76 {
77 return p_desc_n[2];
78 }
79
desc1fn_set_flexmux_channel(uint8_t * p_desc_n,uint8_t i_flexmux_channel)80 static inline void desc1fn_set_flexmux_channel(uint8_t *p_desc_n, uint8_t i_flexmux_channel)
81 {
82 p_desc_n[2] = i_flexmux_channel;
83 }
84
desc1f_validate(const uint8_t * p_desc)85 static inline bool desc1f_validate(const uint8_t *p_desc)
86 {
87 return !(desc_get_length(p_desc) % DESC1F_ENTRY_SIZE);
88 }
89
desc1f_print(uint8_t * p_desc,f_print pf_print,void * opaque,print_type_t i_print_type)90 static inline void desc1f_print(uint8_t *p_desc, f_print pf_print,
91 void *opaque, print_type_t i_print_type)
92 {
93 uint8_t j = 0;
94 uint8_t *p_desc_n;
95
96 while ((p_desc_n = desc1f_get_entry(p_desc, j)) != NULL) {
97 j++;
98 switch (i_print_type) {
99 case PRINT_XML:
100 pf_print(opaque, "<FMC_DESC es_id=\"0x%04x\" flexmux_channel=\"0x%02x\"/>",
101 desc1fn_get_es_id(p_desc_n),
102 desc1fn_get_flexmux_channel(p_desc_n));
103 break;
104 default:
105 pf_print(opaque, " - desc 1f fmc es_id=0x%04x flexmux_channel=0x%02x",
106 desc1fn_get_es_id(p_desc_n),
107 desc1fn_get_flexmux_channel(p_desc_n));
108 }
109 }
110 }
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif
117