remove \r
[extl.git] / extl / media / ts / opcr.h
blobfac69d4aac3e0b5ee6539e73895d19e10c0d45da
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: opcr.h
4 * Created: 09.02.06
5 * Updated: 09.03.04
7 * Brief: the opcr class - the original program clock reference
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_MEDIA_TS_OPCR_H
14 #define EXTL_MEDIA_TS_OPCR_H
16 /*!\file opcr.h
17 * \brief the opcr class - program clock reference
19 #ifndef __cplusplus
20 # error opcr.h need be supported by c++.
21 #endif
23 /* ///////////////////////////////////////////////////////////////////////
24 * Includes
26 #include "prefix.h"
28 /* ///////////////////////////////////////////////////////////////////////
29 * ::extl::media::ts namespace
31 EXTL_MEDIA_TS_BEGIN_WHOLE_NAMESPACE
33 /*!brief the program clock reference
35 * \ingroup extl_group_media
37 * \code
38 * // original program clock reference
39 * struct opcr
41 opcr_base : 33 ;
42 reseved : 6 ;
43 opcr_extension : 9 ;
45 * \endcode
47 * \param Ada the adaptation field type
49 template<typename_param_k Ada>
50 class opcr
52 /// \name Public Types
53 /// @{
54 public:
55 typedef Ada adaptation_type;
56 typedef opcr class_type;
57 typedef e_byte_t byte_type;
58 typedef e_uint16_t word_type;
59 typedef e_uint32_t dword_type;
60 typedef e_uint64_t qword_type;
61 typedef byte_type* pointer;
62 typedef byte_type const* const_pointer;
63 typedef e_size_t size_type;
64 typedef size_type index_type;
65 typedef e_bool_t bool_type;
66 /// @}
68 /// \name Member Type
69 /// @{
70 private:
71 // program_clock_reference
72 // base + base1 + reseved + opcr_extension
73 // |=> 33bit <=| 6 9
74 struct members_type
76 // 32(base) + 1(base1)
77 dword_type base ;
79 // \note defined in reverse order by word_type
80 word_type extension : 9 ; //< low bit
81 word_type reseved : 6 ;
82 word_type base1 : 1 ; //< high bit
84 /// @}
86 /// \name Constants
87 /// @{
88 public:
89 enum { en_opcr_size = 6 };
90 /// @}
92 /// \name Private Accessors
93 /// @{
94 private:
95 adaptation_type& adaptation() { return static_cast<adaptation_type&>(*this); }
96 adaptation_type const& adaptation() const { return static_cast<adaptation_type const&>(*this); }
98 members_type& members() { return *reinterpret_cast<members_type*>(data()); }
99 members_type const& members() const { return *reinterpret_cast<members_type const*>(data()); }
100 /// @}
102 /// \name Public Accessors
103 /// @{
104 public:
105 pointer data() { return (adaptation().packet().data() + offset()); }
106 const_pointer data() const { return (adaptation().packet().data() + offset()); }
108 qword_type value() const { return (base() * 300 + extension()); }
110 qword_type base() const { return ((static_cast<qword_type>(members().base) << 1) | members().base1); }
111 void base(qword_type value) { members().base = static_cast<dword_type>(value >> 1); members().base1 = static_cast<word_type>(value & 0x1); }
113 size_type extension() const { return static_cast<size_type>(members().extension); }
114 void extension(size_type value) { members().extension = static_cast<word_type>(value); }
115 /// @}
117 /// \name Attributes
118 /// @{
119 public:
120 /// the opcr size
121 size_type size() const { return en_opcr_size; }
123 /// return the offset at the packet
124 size_type offset() const { return (adaptation().pcr().offset() + (exists()? adaptation().pcr().size() : 0)); }
126 /// return \true if exists opcr
127 bool_type exists() const { return (1 == adaptation().header().opcr_flag()); }
129 /// return \true if the packet is valid
130 bool_type is_valid() const { return e_true_v; }
131 /// @}
133 /// \name Attach & Detach
134 /// @{
135 public:
136 /// decodes packet packet_header
137 void decode()
139 if (exists())
141 adaptation().packet().buffer().reverse(offset(), 4);
142 adaptation().packet().buffer().reverse(offset() + 4, 2);
145 /// encodes packet packet_header
146 void encode()
148 if (exists())
150 adaptation().packet().buffer().reverse(offset(), 4);
151 adaptation().packet().buffer().reverse(offset() + 4, 2);
154 /// @}
157 /* ///////////////////////////////////////////////////////////////////////
158 * ::extl::media::ts namespace
160 EXTL_MEDIA_TS_END_WHOLE_NAMESPACE
162 /* //////////////////////////////////////////////////////////////////// */
163 #endif /* EXTL_MEDIA_TS_OPCR_H */
164 /* //////////////////////////////////////////////////////////////////// */