Wasabi ExpressPlay SDK for Embedded Systems  1.23.0
Ts2Packet.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | MPEG2 Transport Stream - Packet
4 |
5 | $Id: Ts2Packet.h 196 2012-01-05 14:18:55Z jebaseelir $
6 | Original author: Julien Boeuf
7 |
8 | This software is provided to you pursuant to your agreement
9 | with Intertrust Technologies Corporation ("Intertrust").
10 | This software may be used only in accordance with the terms
11 | of the agreement.
12 |
13 | Copyright (c) 2009-2012 Intertrust. All rights reserved.
14 |
15 ****************************************************************/
16 
17 #ifndef _TS2_PACKET_H_
18 #define _TS2_PACKET_H_
19 
20 /*----------------------------------------------------------------------
21 | includes
22 +---------------------------------------------------------------------*/
23 #include "Atomix.h"
24 #include "Ts2Config.h"
25 
26 /*----------------------------------------------------------------------
27 | constants
28 +---------------------------------------------------------------------*/
29 /* pids */
30 #define TS2_NULL_PACKET_PID 0x1FFF
31 #define TS2_INVALID_PID 0xFFFF
32 
33 /* frequency/PCR */
34 #define TS2_SYSTEM_CLOCK_FREQUENCY 27000000.0 /* 27 MHz */
35 #define TS2_INVALID_PCR_IN_SECS -1.0
36 #define TS2_MAX_PCR_IN_SECS 95443.717696703708 /* ((2**33-1)*300+(2**9-1)) / 27000000.0 */
37 
38 /* packet size */
39 #define TS2_PACKET_SIZE 188
40 #define TS2_PACKET_HEADER_SIZE 4
41 #define TS2_PACKET_PAYLOAD_SIZE (TS2_PACKET_SIZE - TS2_PACKET_HEADER_SIZE)
42 
43 #define TS2_PACKET_SYNC_BYTE 0x47
44 
45 #define TS2_PACKET_AF_CLOCK_REFERENCE_DATA_SIZE 6
46 #define TS2_PACKET_AF_EXTENSION_SEAMLESS_SIZE 5
47 
48 #define TS2_STUFFING_BYTE 0xFF
49 
50 /* flags */
51 #define TS2_PACKET_TRANSPORT_ERROR_INDICATOR_FLAG_MASK 0x04
52 #define TS2_PACKET_PAYLOAD_UNIT_START_INDICATOR_FLAG_MASK 0x02
53 #define TS2_PACKET_TRANSPORT_PRIORITY_FLAG_MASK 0x01
54 
55 /*----------------------------------------------------------------------
56 | types
57 +---------------------------------------------------------------------*/
58 typedef struct {
59  ATX_UInt8 length;
60  ATX_UInt8 flags;
61  ATX_UInt16 ltw;
62  ATX_UInt32 piecewise;
63  ATX_UInt8 seamless_splice[TS2_PACKET_AF_EXTENSION_SEAMLESS_SIZE];
65 
66 typedef struct {
67  ATX_UInt8 length;
68  ATX_UInt8 flags;
71  ATX_UInt8 splice_countdown;
76 
77 typedef enum {
83 
84 typedef enum {
90 
91 typedef struct {
92  ATX_UInt8 flags;
93  ATX_UInt16 pid;
96  ATX_UInt8 continuity_counter;
99  ATX_Size payload_size;
100 } TS2_Packet;
101 
103 
104 typedef struct {
105  void* instance;
106  ATX_Result (*HandlePacket)(void* handler_instance,
107  TS2_PacketDispatcher* dispatcher,
108  TS2_Packet* packet);
110 
112 
113 #ifdef __cplusplus
114 extern "C" {
115 #endif /* __cplusplus */
116 
117 /*----------------------------------------------------------------------
118 | TS2_AdaptationField functions and macros
119 +---------------------------------------------------------------------*/
120 ATX_Float
122 
123 #define TS2_AF_Flags_DiscontinuityIndicator(flags) ((flags) & 0x80)
124 #define TS2_AF_Flags_RandomAccessIndicator(flags) ((flags) & 0x40)
125 #define TS2_AF_Flags_EsPriorityIndicator(flags) ((flags) & 0x20)
126 #define TS2_AF_Flags_PcrFlag(flags) ((flags) & 0x10)
127 #define TS2_AF_Flags_OpcrFlag(flags) ((flags) & 0x08)
128 #define TS2_AF_Flags_SplicingPointFlag(flags) ((flags) & 0x04)
129 #define TS2_AF_Flags_TransportPrivateDataFlag(flags) ((flags) & 0x02)
130 #define TS2_AF_Flags_ExtensionFlag(flags) ((flags) & 0x01)
131 
132 #define TS2_AF_Extension_Flags_LtwFlag(flags) ((flags) & 0x80)
133 #define TS2_AF_Extension_Flags_PiecewiseRateFlag(flags) ((flags) & 0x40)
134 #define TS2_AF_Extension_Flags_SeamlessSpliceFlag(flags) ((flags) & 0x20)
135 
136 /*----------------------------------------------------------------------
137 | TS2_Packet functions and macros
138 +---------------------------------------------------------------------*/
139 ATX_Result
140 TS2_Packet_InitFromInputStream(ATX_InputStream* stream,
141  TS2_Packet* packet);
142 
143 ATX_Result
144 TS2_Packet_InitFromBuffer(const ATX_Byte* buffer,
145  TS2_Packet* packet);
146 
148 ATX_Result
150  ATX_Byte* buffer);
151 
152 void
154 
155 void
156 TS2_FormatPacketHeader(ATX_Byte* buffer, /* TS2_PACKET_HEADER_SIZE */
157  ATX_UInt32 transport_error_indicator,
158  ATX_UInt32 payload_unit_start_indicator,
159  ATX_UInt32 transport_priority,
160  ATX_UInt16 pid,
161  TS2_ScramblingControl scrambling_control,
162  TS2_AfControl af_control,
163  ATX_UInt32 continuity_counter);
164 
165 
166 #define TS2_Packet_HasAdaptationField(packet) ((packet)->af_control & 0x02)
167 #define TS2_Packet_HasPayload(packet) ((packet)->af_control & 0x01)
168 #define TS2_Packet_HasPcr(packet) ( \
169  TS2_Packet_HasAdaptationField(packet) && \
170  packet->adaptation_field != NULL && \
171  TS2_AF_Flags_PcrFlag(packet->adaptation_field->flags) \
172 )
173 
174 #define TS2_Packet_Flags_TransportError(pflags) (((pflags) & 0x04) >> 2)
175 #define TS2_Packet_Flags_PayloadUnitStart(pflags) (((pflags) & 0x02) >> 1)
176 #define TS2_Packet_Flags_TransportPriority(pflags) (((pflags) & 0x01) )
177 
178 /*----------------------------------------------------------------------
179 | TS2_PacketDispatcher functions
180 +---------------------------------------------------------------------*/
181 ATX_Result
183 
184 TS2_EXPORT ATX_Result
186  ATX_UInt16 pid,
187  TS2_PacketHandler handler);
188 
189 TS2_EXPORT ATX_Result
191  ATX_UInt16 pid);
192 
193 ATX_Result
195  TS2_PacketHandler handler);
196 
197 ATX_Result
199 
200 ATX_Result
202  TS2_Packet* packet);
203 
204 ATX_UInt16
206 
207 ATX_Boolean
209 
210 void
212 
213 /*----------------------------------------------------------------------
214 | TS2_Packet functions
215 +---------------------------------------------------------------------*/
216 TS2_EXPORT ATX_Result
217 TS2_PacketPump_Create(ATX_InputStream* stream,
218  TS2_PacketDispatcher* dispatcher, /* takes ownership. If NULL, will create one */
219  TS2_PacketPump** pump);
220 
223 
224 TS2_EXPORT ATX_Result
226 
227 TS2_EXPORT ATX_Result
229  ATX_InputStream* stream);
230 
231 TS2_EXPORT void
233 
234 #ifdef __cplusplus
235 }
236 #endif /* __cplusplus */
237 
238 #endif /* _TS2_PACKET_H_ */
ATX_UInt8 transport_private_data_length
Definition: Ts2Packet.h:72
Definition: Ts2Packet.h:104
ATX_UInt32 piecewise
Definition: Ts2Packet.h:62
TS2_AfControl
Definition: Ts2Packet.h:84
ATX_UInt8 splice_countdown
Definition: Ts2Packet.h:71
ATX_UInt8 flags
Definition: Ts2Packet.h:60
void * instance
Definition: Ts2Packet.h:105
TS2_EXPORT ATX_Result TS2_PacketDispatcher_SetHandler(TS2_PacketDispatcher *self, ATX_UInt16 pid, TS2_PacketHandler handler)
ATX_UInt16 pid
Definition: Ts2Packet.h:93
ATX_Result TS2_PacketDispatcher_ResetDefaultHandler(TS2_PacketDispatcher *self)
void TS2_Packet_Destruct(TS2_Packet *packet)
ATX_Float TS2_AdaptationField_PcrInSecs(TS2_AdaptationField *self)
ATX_Result TS2_Packet_SerializeToBuffer(TS2_Packet *packet, ATX_Byte *buffer)
TS2_PACKET_SIZE bytes will be written into buffer.
struct TS2_PacketPump TS2_PacketPump
Definition: Ts2Packet.h:111
Definition: Ts2Packet.h:87
ATX_UInt8 length
Definition: Ts2Packet.h:67
ATX_UInt8 continuity_counter
Definition: Ts2Packet.h:96
#define TS2_PACKET_AF_CLOCK_REFERENCE_DATA_SIZE
Definition: Ts2Packet.h:45
Definition: Ts2Packet.h:78
Definition: Ts2Packet.h:79
Definition: Ts2Packet.h:80
TS2_EXPORT ATX_Result TS2_PacketPump_ResetStream(TS2_PacketPump *self, ATX_InputStream *stream)
ATX_UInt8 length
Definition: Ts2Packet.h:59
Definition: Ts2Packet.h:86
ATX_UInt8 flags
Definition: Ts2Packet.h:92
ATX_Result TS2_PacketDispatcher_Create(TS2_PacketDispatcher **dispatcher)
#define TS2_EXPORT
Definition: Ts2Config.h:67
Definition: Ts2Packet.h:58
TS2_EXPORT TS2_PacketDispatcher * TS2_PacketPump_GetDispatcher(TS2_PacketPump *self)
TS2_EXPORT ATX_Result TS2_PacketPump_Create(ATX_InputStream *stream, TS2_PacketDispatcher *dispatcher, TS2_PacketPump **pump)
Definition: Ts2Packet.h:66
TS2_ScramblingControl
Definition: Ts2Packet.h:77
Definition: Ts2Packet.h:88
TS2_EXPORT void TS2_PacketPump_Destroy(TS2_PacketPump *self)
Definition: Ts2Packet.h:91
void TS2_FormatPacketHeader(ATX_Byte *buffer, ATX_UInt32 transport_error_indicator, ATX_UInt32 payload_unit_start_indicator, ATX_UInt32 transport_priority, ATX_UInt16 pid, TS2_ScramblingControl scrambling_control, TS2_AfControl af_control, ATX_UInt32 continuity_counter)
void TS2_PacketDispatcher_Destroy(TS2_PacketDispatcher *self)
TS2_EXPORT ATX_Result TS2_PacketPump_Pump(TS2_PacketPump *self)
TS2_ScramblingControl scrambling_control
Definition: Ts2Packet.h:94
struct TS2_PacketDispatcher TS2_PacketDispatcher
Definition: Ts2Packet.h:102
ATX_UInt16 ltw
Definition: Ts2Packet.h:61
ATX_Result TS2_PacketDispatcher_SetDefaultHandler(TS2_PacketDispatcher *self, TS2_PacketHandler handler)
ATX_Size payload_size
Definition: Ts2Packet.h:99
TS2_AfControl af_control
Definition: Ts2Packet.h:95
ATX_Result TS2_PacketDispatcher_Dispatch(TS2_PacketDispatcher *self, TS2_Packet *packet)
ATX_Byte * transport_private_data
Definition: Ts2Packet.h:73
ATX_Result TS2_Packet_InitFromInputStream(ATX_InputStream *stream, TS2_Packet *packet)
TS2_AdaptationField_Extension * extension
Definition: Ts2Packet.h:74
#define TS2_PACKET_SIZE
Definition: Ts2Packet.h:39
ATX_Result TS2_Packet_InitFromBuffer(const ATX_Byte *buffer, TS2_Packet *packet)
#define TS2_PACKET_HEADER_SIZE
Definition: Ts2Packet.h:40
TS2_AdaptationField * adaptation_field
Definition: Ts2Packet.h:97
#define TS2_PACKET_AF_EXTENSION_SEAMLESS_SIZE
Definition: Ts2Packet.h:46
Definition: Ts2Packet.h:85
TS2_EXPORT ATX_Result TS2_PacketDispatcher_ResetHandler(TS2_PacketDispatcher *self, ATX_UInt16 pid)
ATX_Boolean TS2_PacketDispatcher_IsPidUsed(TS2_PacketDispatcher *self, ATX_UInt16 pid)
Definition: Ts2Packet.h:81
ATX_UInt16 TS2_PacketDispatcher_GetNextAvailablePid(TS2_PacketDispatcher *self)
ATX_UInt8 flags
Definition: Ts2Packet.h:68