| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef _IEC13818_1_H |
| 21 |
#define _IEC13818_1_H 1 |
| 22 |
|
| 23 |
#include "error.h" |
| 24 |
|
| 25 |
#define HDV_PACKET_SIZE 188 |
| 26 |
#define HDV_PACKET_MARKER 0x47 |
| 27 |
|
| 28 |
#define STREAM_VIDEO (0x02) |
| 29 |
#define STREAM_AUDIO (0x03) |
| 30 |
#define STREAM_SONY_PRIVATE_A0 (0xa0) |
| 31 |
#define STREAM_SONY_PRIVATE_A1 (0xa1) |
| 32 |
|
| 33 |
#define PID_NULL_PACKET (0x1fff) |
| 34 |
|
| 35 |
#define DUMP_RAW_DATA( type, bytes, start, end ) do { \ |
| 36 |
int i, j; \ |
| 37 |
for ( j = end; ( j > start+1 ) && ( bytes[j-1] == 0xff ) && ( bytes[j-2] == 0xff ); j-- ); \ |
| 38 |
for ( i = start; i < j; i++ ) DEBUG_RAW( type, "%02x ", bytes[ i ] ); \ |
| 39 |
if ( j < end ) DEBUG_RAW( type, "\b*%d ", end - j + 1 ); \ |
| 40 |
} while(0) |
| 41 |
|
| 42 |
#define BCD(c) ( ((((c) >> 4) & 0x0f) * 10) + ((c) & 0x0f) ) |
| 43 |
|
| 44 |
#define TOBYTES( n ) ( ( n + 7 ) / 8 ) |
| 45 |
static unsigned char bitmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; |
| 46 |
#define GETBITS( offset, len ) do { \ |
| 47 |
unsigned long value = 0; \ |
| 48 |
while ( len > 0 ) \ |
| 49 |
{ \ |
| 50 |
int bits = 8 - ( offset % 8 ); \ |
| 51 |
unsigned char data = GetData( offset / 8 ) & bitmask[bits-1]; \ |
| 52 |
if ( len > bits ) \ |
| 53 |
value += data << ( len - bits ); \ |
| 54 |
else if ( len < bits ) \ |
| 55 |
value += data >> ( bits - len ); \ |
| 56 |
else \ |
| 57 |
value += data; \ |
| 58 |
offset += bits; \ |
| 59 |
len -= bits; \ |
| 60 |
} \ |
| 61 |
return value; \ |
| 62 |
} while (0) |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
class PAT |
| 67 |
{ |
| 68 |
public: |
| 69 |
PAT(); |
| 70 |
~PAT(); |
| 71 |
|
| 72 |
void SetData( unsigned char *d, int len ); |
| 73 |
int GetLength(); |
| 74 |
unsigned char GetData( int pos ); |
| 75 |
unsigned long GetBits( int offset, int len ) { GETBITS( offset, len ); } |
| 76 |
void Dump(); |
| 77 |
|
| 78 |
unsigned char table_id(); |
| 79 |
bool section_syntax_indicator(); |
| 80 |
unsigned short section_length(); |
| 81 |
unsigned short transport_stream_id(); |
| 82 |
unsigned char version_number(); |
| 83 |
bool current_next_indicator(); |
| 84 |
unsigned char section_number(); |
| 85 |
unsigned char last_section_number(); |
| 86 |
|
| 87 |
int program_number( unsigned int n ); |
| 88 |
int pid( unsigned int n ); |
| 89 |
|
| 90 |
int network_PID(); |
| 91 |
int program_map_PID(); |
| 92 |
|
| 93 |
protected: |
| 94 |
unsigned char *data; |
| 95 |
int length; |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
class PMT_element |
| 101 |
{ |
| 102 |
public: |
| 103 |
PMT_element(); |
| 104 |
~PMT_element(); |
| 105 |
|
| 106 |
void SetData( unsigned char *d, int len ); |
| 107 |
int GetLength(); |
| 108 |
unsigned char GetData( int pos ); |
| 109 |
unsigned long GetBits( int offset, int len ) { GETBITS( offset, len ); } |
| 110 |
void Dump(); |
| 111 |
|
| 112 |
unsigned char stream_type(); |
| 113 |
unsigned short elementary_PID(); |
| 114 |
unsigned short ES_info_length(); |
| 115 |
|
| 116 |
unsigned char *descriptor( unsigned int n ); |
| 117 |
|
| 118 |
protected: |
| 119 |
unsigned char *data; |
| 120 |
int length; |
| 121 |
}; |
| 122 |
|
| 123 |
class PMT |
| 124 |
{ |
| 125 |
public: |
| 126 |
PMT(); |
| 127 |
~PMT(); |
| 128 |
|
| 129 |
void SetData( unsigned char *d, int len ); |
| 130 |
int GetLength(); |
| 131 |
unsigned char GetData( int pos ); |
| 132 |
unsigned long GetBits( int offset, int len ) { GETBITS( offset, len ); } |
| 133 |
void Dump(); |
| 134 |
|
| 135 |
unsigned char table_id(); |
| 136 |
bool section_syntax_indicator(); |
| 137 |
unsigned short section_length(); |
| 138 |
unsigned short program_number(); |
| 139 |
unsigned char version_number(); |
| 140 |
bool current_next_indicator(); |
| 141 |
unsigned char section_number(); |
| 142 |
unsigned char last_section_number(); |
| 143 |
unsigned short PCR_PID(); |
| 144 |
unsigned short program_info_length(); |
| 145 |
|
| 146 |
unsigned char *descriptor( unsigned int n ); |
| 147 |
|
| 148 |
PMT_element *GetPmtElement( unsigned int n ); |
| 149 |
|
| 150 |
protected: |
| 151 |
void CreatePmtElements(); |
| 152 |
|
| 153 |
protected: |
| 154 |
unsigned char *data; |
| 155 |
int length; |
| 156 |
|
| 157 |
#define MAX_PMT_ELEMENTS 32 |
| 158 |
PMT_element pmtElement[MAX_PMT_ELEMENTS]; |
| 159 |
unsigned int nPmtElements; |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
class PES |
| 165 |
{ |
| 166 |
public: |
| 167 |
PES(); |
| 168 |
~PES(); |
| 169 |
|
| 170 |
void Clear(); |
| 171 |
void AddData( unsigned char *d, int l ); |
| 172 |
unsigned char *GetBuffer(); |
| 173 |
unsigned char GetData( int pos ); |
| 174 |
unsigned long GetBits( int offset, int len ) { GETBITS( offset, len ); } |
| 175 |
int GetLength(); |
| 176 |
void Dump(); |
| 177 |
|
| 178 |
unsigned int packet_start_code_prefix(); |
| 179 |
unsigned char stream_id(); |
| 180 |
unsigned short PES_packet_length(); |
| 181 |
unsigned char PES_scrambling_control(); |
| 182 |
bool PES_priority(); |
| 183 |
bool data_alignment_indicator(); |
| 184 |
bool copyright(); |
| 185 |
bool original_or_copy(); |
| 186 |
unsigned char PTS_DTS_flags(); |
| 187 |
bool ESCR_flag(); |
| 188 |
bool ES_rate_flag(); |
| 189 |
bool DSM_trick_mode_flag(); |
| 190 |
bool additional_copy_info_flag(); |
| 191 |
bool PES_CRC_flag(); |
| 192 |
bool PES_extension_flag(); |
| 193 |
unsigned char PES_header_data_length(); |
| 194 |
|
| 195 |
bool PES_private_data_flag(); |
| 196 |
bool pack_header_field_flag(); |
| 197 |
bool program_packet_sequence_counter_flag(); |
| 198 |
bool P_STD_buffer_flag(); |
| 199 |
bool PES_extension_flag_2(); |
| 200 |
|
| 201 |
int GetPacketDataOffset(); |
| 202 |
int GetPacketDataLength(); |
| 203 |
|
| 204 |
unsigned char PES_packet_data_byte( int n ); |
| 205 |
|
| 206 |
protected: |
| 207 |
bool IsHeaderPresent(); |
| 208 |
|
| 209 |
private: |
| 210 |
#define MAX_PES_SIZE 1024*1024 |
| 211 |
unsigned char data[MAX_PES_SIZE]; |
| 212 |
int length; |
| 213 |
|
| 214 |
int packetDataOffset; |
| 215 |
}; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
class SonyA1 |
| 220 |
{ |
| 221 |
public: |
| 222 |
SonyA1(); |
| 223 |
~SonyA1(); |
| 224 |
|
| 225 |
void SetData( unsigned char *d, int len ); |
| 226 |
int GetLength(); |
| 227 |
unsigned char GetData( int pos ); |
| 228 |
unsigned long GetBits( int offset, int len ) { GETBITS( offset, len ); } |
| 229 |
void Dump(); |
| 230 |
|
| 231 |
unsigned char year(); |
| 232 |
unsigned char month(); |
| 233 |
unsigned char day(); |
| 234 |
unsigned char hour(); |
| 235 |
unsigned char minute(); |
| 236 |
unsigned char second(); |
| 237 |
|
| 238 |
unsigned char timecode_hour(); |
| 239 |
unsigned char timecode_minute(); |
| 240 |
unsigned char timecode_second(); |
| 241 |
unsigned char timecode_frame(); |
| 242 |
|
| 243 |
bool scene_start(); |
| 244 |
|
| 245 |
protected: |
| 246 |
unsigned char *data; |
| 247 |
int length; |
| 248 |
}; |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
class HDVFrame; |
| 253 |
class HDVStreamParams; |
| 254 |
|
| 255 |
class HDVPacket |
| 256 |
{ |
| 257 |
public: |
| 258 |
HDVPacket( HDVFrame *f, HDVStreamParams *p ); |
| 259 |
~HDVPacket(); |
| 260 |
|
| 261 |
void SetData( unsigned char *d ); |
| 262 |
int GetLength(); |
| 263 |
unsigned char GetData( int pos ); |
| 264 |
unsigned long GetBits( int offset, int len ) { GETBITS( offset, len ); } |
| 265 |
void Dump(); |
| 266 |
|
| 267 |
unsigned char sync_byte(); |
| 268 |
bool transport_error_indicator(); |
| 269 |
bool payload_unit_start_indicator(); |
| 270 |
bool transport_priority(); |
| 271 |
unsigned short pid(); |
| 272 |
unsigned char transport_scrambling_control(); |
| 273 |
unsigned char adaptation_field_control(); |
| 274 |
unsigned char continuity_counter(); |
| 275 |
|
| 276 |
unsigned char *pointer_field(); |
| 277 |
|
| 278 |
unsigned char *adaptation_field(); |
| 279 |
|
| 280 |
unsigned char *payload(); |
| 281 |
int PayloadOffset(); |
| 282 |
int PayloadLength(); |
| 283 |
|
| 284 |
bool is_program_association_packet(); |
| 285 |
PAT *program_association_table(); |
| 286 |
|
| 287 |
bool is_program_map_packet(); |
| 288 |
PMT *program_map_table(); |
| 289 |
|
| 290 |
bool is_video_packet(); |
| 291 |
bool is_audio_packet(); |
| 292 |
bool is_sony_private_a0_packet(); |
| 293 |
bool is_sony_private_a1_packet(); |
| 294 |
bool is_null_packet(); |
| 295 |
SonyA1 *GetSonyA1(); |
| 296 |
|
| 297 |
protected: |
| 298 |
unsigned char *data; |
| 299 |
|
| 300 |
HDVFrame *frame; |
| 301 |
HDVStreamParams *params; |
| 302 |
|
| 303 |
PAT pat; |
| 304 |
PMT pmt; |
| 305 |
SonyA1 sonyA1; |
| 306 |
}; |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
#endif |