1 /*****************************************************************************
2  * desc_4c.h: ETSI EN 300 468 Descriptor 0x4c: (Time shifted service 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_4C_H__
34 #define __BITSTREAM_DVB_DESC_4C_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 0x4c: Time shifted service descriptor
46  *****************************************************************************/
47 #define DESC4C_HEADER_SIZE      (DESC_HEADER_SIZE + 2)
48 
desc4c_init(uint8_t * p_desc)49 static inline void desc4c_init(uint8_t *p_desc)
50 {
51     desc_set_tag(p_desc, 0x4c);
52     desc_set_length(p_desc, DESC4C_HEADER_SIZE - DESC_HEADER_SIZE);
53 }
54 
desc4c_get_reference_sid(const uint8_t * p_desc)55 static inline uint16_t desc4c_get_reference_sid(const uint8_t *p_desc)
56 {
57     return (p_desc[2] << 8) | p_desc[3];
58 }
59 
desc4c_set_reference_sid(uint8_t * p_desc,uint16_t i_reference_sid)60 static inline void desc4c_set_reference_sid(uint8_t *p_desc, uint16_t i_reference_sid)
61 {
62     p_desc[2] = (i_reference_sid >> 8) & 0xff;
63     p_desc[3] =  i_reference_sid       & 0xff;
64 }
65 
desc4c_validate(const uint8_t * p_desc)66 static inline bool desc4c_validate(const uint8_t *p_desc)
67 {
68     return desc_get_length(p_desc) >= DESC4C_HEADER_SIZE - DESC_HEADER_SIZE;
69 }
70 
desc4c_print(const uint8_t * p_desc,f_print pf_print,void * opaque,print_type_t i_print_type)71 static inline void desc4c_print(const uint8_t *p_desc, f_print pf_print,
72                                 void *opaque, print_type_t i_print_type)
73 {
74     switch (i_print_type) {
75     case PRINT_XML:
76         pf_print(opaque, "<TIME_SHIFTED_SERVICE_DESC reference_sid=\"%u\"/>",
77                  desc4c_get_reference_sid(p_desc));
78         break;
79     default:
80         pf_print(opaque, "    - desc 4c time_shifted_service reference_sid=%u",
81                  desc4c_get_reference_sid(p_desc));
82     }
83 }
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif
90