Wasabi ExpressPlay SDK for Embedded Systems  1.23.0
Ts2Pes.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | MPEG2 Transport Stream - PES Packet
4 |
5 | $Id: Ts2Pes.h 296 2014-06-25 11:20:09Z 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) 2005-2014 by Intertrust. All rights reserved.
14 |
15 ****************************************************************/
16 
17 #ifndef _TS2_PES_H_
18 #define _TS2_PES_H_
19 
20 /*----------------------------------------------------------------------
21 | includes
22 +---------------------------------------------------------------------*/
23 #include "Atomix.h"
24 #include "Ts2Packet.h"
25 
26 /*----------------------------------------------------------------------
27 | constants
28 +---------------------------------------------------------------------*/
29 #define TS2_PES_START_CODE_PREFIX 0x000001
30 
31 #define TS2_PES_COMMON_HEADER_SIZE 3
32 
33 #define TS2_PROGRAM_MAP_STREAM_ID 0xBC
34 #define TS2_PRIVATE_1_STREAM_ID 0xBD
35 #define TS2_PADDING_STREAM_ID 0xBE
36 #define TS2_PRIVATE_2_STREAM_ID 0xBF
37 #define TS2_ECM_STREAM_ID 0xF0
38 #define TS2_EMM_STREAM_ID 0xF1
39 #define TS2_DSMCC_STREAM_ID 0xF2
40 #define TS2_ISO_IEC_13522_STREAM_ID 0xF3
41 #define TS2_H222_1_TYPE_A_STREAM_ID 0xF4
42 #define TS2_H222_1_TYPE_B_STREAM_ID 0xF5
43 #define TS2_H222_1_TYPE_C_STREAM_ID 0xF6
44 #define TS2_H222_1_TYPE_D_STREAM_ID 0xF7
45 #define TS2_H222_1_TYPE_E_STREAM_ID 0xF8
46 #define TS2_PROGRAM_DIRECTORY_STREAM_ID 0xFF
47 
48 /*----------------------------------------------------------------------
49 | types
50 +---------------------------------------------------------------------*/
51 #define TS2_PES_HEADER_EXTENSION_PRIVATE_DATA_LENGTH 16
52 typedef struct {
56  ATX_Byte mpeg1_2_id;
59  ATX_UInt16 pstd_buffer_size;
60  ATX_UInt8 field_length;
62 
63 typedef struct {
64  ATX_UInt16 flags;
65  ATX_UInt8 header_data_length;
66  ATX_UInt64 pts;
67  ATX_UInt64 dts;
68  struct {
69  ATX_UInt64 base;
70  ATX_UInt16 extension;
71  } escr;
72  ATX_UInt32 es_rate;
73  ATX_UInt8 trick_mode;
74  ATX_UInt8 extra_copy_info;
75  ATX_UInt16 previous_pes_crc;
78 
79 typedef struct {
80  ATX_UInt8 stream_id;
81  ATX_Size length;
83  ATX_DataBuffer* payload;
85 
86 typedef struct {
88  ATX_Size pes_length_read; /* amount of data read so far. paired with TS2_PesPacket.length */
91 
92 /*----------------------------------------------------------------------
93 | helpers
94 +---------------------------------------------------------------------*/
95 #define TS2_IsStreamIdVideo(stream_id) (((stream_id) & 0xE0) == 0xC0)
96 #define TS2_VideoStreamNumber(stream_id) ((stream_id) & 0x1F)
97 #define TS2_IsStreamIdAudio(stream_id) (((stream_id) & 0xF0) == 0xE0)
98 #define TS2_AudioStreamNumber(stream_id) ((stream_id) & 0x0F)
99 
100 #define TS2_PesHeader_ScramblingControl(hflags) (((hflags) & 0x3000) >> 12)
101 #define TS2_PesHeader_PriorityFlag(hflags) (((hflags) & 0x0800) >> 11)
102 #define TS2_PesHeader_AlignmentIndicator(hflags) (((hflags) & 0x0400) >> 10)
103 #define TS2_PesHeader_Copyright(hflags) (((hflags) & 0x0200) >> 9)
104 #define TS2_PesHeader_OriginalOrCopy(hflags) (((hflags) & 0x0100) >> 8)
105 #define TS2_PesHeader_PtsDtsFlags(hflags) (((hflags) & 0x00C0) >> 6)
106 #define TS2_PesHeader_EscrFlag(hflags) (((hflags) & 0x0020) >> 5)
107 #define TS2_PesHeader_EsRateFlag(hflags) (((hflags) & 0x0010) >> 4)
108 #define TS2_PesHeader_DsmTrickModeFlag(hflags) (((hflags) & 0x0008) >> 3)
109 #define TS2_PesHeader_ExtraCopyInfoFlag(hflags) (((hflags) & 0x0004) >> 2)
110 #define TS2_PesHeader_PesCrcFlag(hflags) (((hflags) & 0x0002) >> 1)
111 #define TS2_PesHeader_ExtensionFlag(hflags) (((hflags) & 0x0001) )
112 
113 #define TS2_PesExtension_PrivateData(eflags) (((eflags) & 0x80) )
114 #define TS2_PesExtension_PacketHeader(eflags) (((eflags) & 0x40) )
115 #define TS2_PesExtension_SequenceCounter(eflags) (((eflags) & 0x20) )
116 #define TS2_PesExtension_StdBuffer(eflags) (((eflags) & 0x10) )
117 #define TS2_PesExtension_Flag2(eflags) (((eflags) & 0x01) )
118 
119 /*----------------------------------------------------------------------
120 | methods
121 +---------------------------------------------------------------------*/
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
125 
127 
145 ATX_Result TS2_PesPacket_Unpack(TS2_PesPacketAssembler* assembler,
146  const TS2_Packet* packet,
147  TS2_PesPacket** packet_out);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif /* _TS2_PES_H_ */
ATX_UInt64 pts
Definition: Ts2Pes.h:66
void TS2_PesPacket_Destroy(TS2_PesPacket *pp)
ATX_Size length
Definition: Ts2Pes.h:81
#define TS2_PES_HEADER_EXTENSION_PRIVATE_DATA_LENGTH
Definition: Ts2Pes.h:51
ATX_UInt8 stream_id
Definition: Ts2Pes.h:80
Definition: Ts2Pes.h:52
ATX_Int8 last_continuity_counter
Definition: Ts2Pes.h:89
ATX_UInt8 field_length
Definition: Ts2Pes.h:60
Definition: Ts2Pes.h:79
ATX_UInt8 extra_copy_info
Definition: Ts2Pes.h:74
TS2_PesHeaderExtension * extension
Definition: Ts2Pes.h:76
ATX_UInt8 trick_mode
Definition: Ts2Pes.h:73
ATX_UInt16 pstd_buffer_size
Definition: Ts2Pes.h:59
ATX_Byte mpeg1_2_id
Definition: Ts2Pes.h:56
TS2_PesPacketHeader * header
Definition: Ts2Pes.h:82
ATX_UInt64 base
Definition: Ts2Pes.h:69
ATX_UInt16 flags
Definition: Ts2Pes.h:64
TS2_PesPacket * current
Definition: Ts2Pes.h:87
ATX_Size pes_length_read
Definition: Ts2Pes.h:88
ATX_Byte pack_field_length
Definition: Ts2Pes.h:54
ATX_UInt8 header_data_length
Definition: Ts2Pes.h:65
ATX_Byte original_stuff_length
Definition: Ts2Pes.h:57
ATX_Result TS2_PesPacket_Unpack(TS2_PesPacketAssembler *assembler, const TS2_Packet *packet, TS2_PesPacket **packet_out)
packet_out must be non-NULL.
Definition: Ts2Packet.h:91
Definition: Ts2Pes.h:63
ATX_UInt16 previous_pes_crc
Definition: Ts2Pes.h:75
ATX_UInt64 dts
Definition: Ts2Pes.h:67
ATX_UInt32 es_rate
Definition: Ts2Pes.h:72
ATX_UInt16 extension
Definition: Ts2Pes.h:70
ATX_Byte program_packet_seq_count
Definition: Ts2Pes.h:55
ATX_Byte pstd_buffer_scale
Definition: Ts2Pes.h:58
ATX_DataBuffer * payload
Definition: Ts2Pes.h:83
Definition: Ts2Pes.h:86