2 * pesparse.h : MPEG PES parsing utility
3 * Copyright (C) 2011 Edward Hervey <bilboed@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef __PES_PARSE_H__
22 #define __PES_PARSE_H__
25 #include "gstmpegdefs.h"
30 PES_FLAG_PRIORITY = 1 << 3, /* PES_priority (present: high-priority) */
31 PES_FLAG_DATA_ALIGNMENT = 1 << 2, /* data_alignment_indicator */
32 PES_FLAG_COPYRIGHT = 1 << 1, /* copyright */
33 PES_FLAG_ORIGINAL_OR_COPY = 1 << 0 /* original_or_copy */
37 PES_TRICK_MODE_FAST_FORWARD = 0x000,
38 PES_TRICK_MODE_SLOW_MOTION = 0x001,
39 PES_TRICK_MODE_FREEZE_FRAME = 0x010,
40 PES_TRICK_MODE_FAST_REVERSE = 0x011,
41 PES_TRICK_MODE_SLOW_REVERSE = 0x100,
43 PES_TRICK_MODE_INVALID = 0xfff /* Not present or invalid */
44 } PESTrickModeControl;
47 PES_FIELD_ID_TOP_ONLY = 0x00, /* Display from top field only */
48 PES_FIELD_ID_BOTTOM_ONLY = 0x01, /* Display from bottom field only */
49 PES_FIELD_ID_COMPLETE_FRAME = 0x10, /* Display complete frame */
50 PES_FIELD_ID_INVALID = 0x11 /* Reserved/Invalid */
54 PES_PARSING_OK = 0, /* Header fully parsed and valid */
55 PES_PARSING_BAD = 1, /* Header invalid (CRC error for ex) */
56 PES_PARSING_NEED_MORE = 2 /* Not enough data to parse header */
60 guint8 stream_id; /* See ID_* in gstmpegdefs.h */
61 guint16 packet_length; /* The size of the PES header and PES data
62 * (if 0 => unbounded packet) */
63 guint16 header_size; /* The complete size of the PES header */
65 /* All remaining entries in this structure are optional */
66 guint8 scrambling_control; /* 0x00 : Not scrambled/unspecified,
67 * The following are according to ETSI TS 101 154
68 * 0x01 : reserved for future DVB use
69 * 0x10 : PES packet scrambled with Even key
70 * 0x11 : PES packet scrambled with Odd key
74 guint64 PTS; /* PTS (-1 if not present or invalid) */
75 guint64 DTS; /* DTS (-1 if not present or invalid) */
76 guint64 ESCR; /* ESCR (-1 if not present or invalid) */
78 guint32 ES_rate; /* in bytes/seconds (0 if not present or invalid) */
79 PESTrickModeControl trick_mode;
81 /* Only valid for _FAST_FORWARD, _FAST_REVERSE and _FREEZE_FRAME */
83 /* Only valid for _FAST_FORWARD and _FAST_REVERSE */
84 gboolean intra_slice_refresh;
85 guint8 frequency_truncation;
86 /* Only valid for _SLOW_FORWARD and _SLOW_REVERSE */
89 guint8 additional_copy_info; /* Private data */
90 guint16 previous_PES_packet_CRC;
92 /* Extension fields */
93 const guint8* private_data; /* PES_private_data, 16 bytes long */
94 guint8 pack_header_size; /* Size of pack_header in bytes */
95 const guint8* pack_header;
96 gint8 program_packet_sequence_counter; /* -1 if not present or invalid */
97 gboolean MPEG1_MPEG2_identifier;
98 guint8 original_stuff_length;
100 guint32 P_STD_buffer_size; /* P-STD buffer size in bytes (0 if invalid
103 gsize extension_field_length;
104 guint8 stream_id_extension; /* Only valid if stream_id == ID_EXTENDED_STREAM_ID */
105 const guint8* stream_id_extension_data;
108 PESParsingResult mpegts_parse_pes_header (const guint8* data, gsize size,
109 PESHeader *res, gint *offset);
110 void init_pes_parser (void);
112 #endif /* __PES_PARSE_H__ */