1 /*****************************************************************************
2  * desc_4f.h: ETSI EN 300 468 Descriptor 0x4f: (Time shifted event 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_4F_H__
34 #define __BITSTREAM_DVB_DESC_4F_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 0x4f: Time shifted event descriptor
46  *****************************************************************************/
47 #define DESC4F_HEADER_SIZE      (DESC_HEADER_SIZE + 4)
48 
desc4f_init(uint8_t * p_desc)49 static inline void desc4f_init(uint8_t *p_desc)
50 {
51     desc_set_tag(p_desc, 0x4f);
52     desc_set_length(p_desc, DESC4F_HEADER_SIZE - DESC_HEADER_SIZE);
53 }
54 
desc4f_get_reference_sid(const uint8_t * p_desc)55 static inline uint16_t desc4f_get_reference_sid(const uint8_t *p_desc)
56 {
57     return (p_desc[2] << 8) | p_desc[3];
58 }
59 
desc4f_set_reference_sid(uint8_t * p_desc,uint16_t i_reference_sid)60 static inline void desc4f_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 
desc4f_get_reference_event_id(const uint8_t * p_desc)66 static inline uint16_t desc4f_get_reference_event_id(const uint8_t *p_desc)
67 {
68     return (p_desc[4] << 8) | p_desc[5];
69 }
70 
desc4f_set_reference_event_id(uint8_t * p_desc,uint16_t i_reference_event_id)71 static inline void desc4f_set_reference_event_id(uint8_t *p_desc, uint16_t i_reference_event_id)
72 {
73     p_desc[4] = (i_reference_event_id >> 8) & 0xff;
74     p_desc[5] =  i_reference_event_id       & 0xff;
75 }
76 
desc4f_validate(const uint8_t * p_desc)77 static inline bool desc4f_validate(const uint8_t *p_desc)
78 {
79     return desc_get_length(p_desc) >= DESC4F_HEADER_SIZE - DESC_HEADER_SIZE;
80 }
81 
desc4f_print(const uint8_t * p_desc,f_print pf_print,void * opaque,print_type_t i_print_type)82 static inline void desc4f_print(const uint8_t *p_desc, f_print pf_print,
83                                 void *opaque, print_type_t i_print_type)
84 {
85     switch (i_print_type) {
86     case PRINT_XML:
87         pf_print(opaque, "<TIME_SHIFTED_EVENT_DESC reference_sid=\"%u\" reference_event_id=\"%u\"/>",
88                  desc4f_get_reference_sid(p_desc),
89                  desc4f_get_reference_event_id(p_desc)
90                 );
91         break;
92     default:
93         pf_print(opaque, "    - desc 4f time_shifted_service reference_sid=%u reference_event_id=%u",
94                  desc4f_get_reference_sid(p_desc),
95                  desc4f_get_reference_event_id(p_desc)
96                 );
97     }
98 }
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif
105