summaryrefslogtreecommitdiff
path: root/sys/vdpau/mpeg/mpegutil.h
blob: 38f17d7e743d64a87db7edb3b29af19c293ad4bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* GStreamer
 * Copyright (C) 2007 Jan Schmidt <thaytan@mad.scientist.com>
 * Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __MPEGUTIL_H__
#define __MPEGUTIL_H__

#include <gst/gst.h>

typedef struct MPEGSeqHdr MPEGSeqHdr;
typedef struct MPEGSeqExtHdr MPEGSeqExtHdr;
typedef struct MPEGPictureHdr MPEGPictureHdr;
typedef struct MPEGPictureExt MPEGPictureExt;
typedef struct MPEGGop MPEGGop;
typedef struct MPEGQuantMatrix MPEGQuantMatrix;

/* Packet ID codes for different packet types we
 * care about */
#define MPEG_PACKET_PICTURE      0x00
#define MPEG_PACKET_SLICE_MIN    0x01
#define MPEG_PACKET_SLICE_MAX    0xaf
#define MPEG_PACKET_SEQUENCE     0xb3
#define MPEG_PACKET_EXTENSION    0xb5
#define MPEG_PACKET_SEQUENCE_END 0xb7
#define MPEG_PACKET_GOP          0xb8
#define MPEG_PACKET_NONE         0xff

/* Extension codes we care about */
#define MPEG_PACKET_EXT_SEQUENCE         0x01
#define MPEG_PACKET_EXT_SEQUENCE_DISPLAY 0x02
#define MPEG_PACKET_EXT_QUANT_MATRIX     0x03
#define MPEG_PACKET_EXT_PICTURE_CODING   0x08

/* frame types */
#define I_FRAME         1
#define P_FRAME         2
#define B_FRAME         3

struct MPEGSeqHdr
{
  /* Pixel-Aspect Ratio from DAR code via set_par_from_dar */
  guint par_w, par_h;
  /* Width and Height of the video */
  guint16 width, height;
  /* Framerate */
  guint fps_n, fps_d;

  guint32 bitrate;
  guint16 vbv_buffer;

  guint8 constrained_parameters_flag;
  
  guint8 intra_quantizer_matrix[64];
  guint8 non_intra_quantizer_matrix[64];
};

struct MPEGSeqExtHdr
{

  /* mpeg2 decoder profile */
  guint8 profile;
  /* mpeg2 decoder level */
  guint8 level;

  guint8 progressive;
  guint8 chroma_format;
  
  guint8 horiz_size_ext, vert_size_ext;

  guint16 bitrate_ext;
  guint8 fps_n_ext, fps_d_ext;
  
};

struct MPEGPictureHdr
{
  guint16 tsn;
  guint8 pic_type;
  guint16 vbv_delay;
  
  guint8 full_pel_forward_vector, full_pel_backward_vector;

  guint8 f_code[2][2];
};

struct MPEGPictureExt
{
  guint8 f_code[2][2];

  guint8 intra_dc_precision;
  guint8 picture_structure;
  guint8 top_field_first;
  guint8 frame_pred_frame_dct;
  guint8 concealment_motion_vectors;
  guint8 q_scale_type;
  guint8 intra_vlc_format;
  guint8 alternate_scan;
  guint8 repeat_first_field;
  guint8 chroma_420_type;
  guint8 progressive_frame;
};

struct MPEGGop
{
  guint8 drop_frame_flag;

  guint8 hour, minute, second, frame;

  guint8 closed_gop;
  guint8 broken_gop;
};

struct MPEGQuantMatrix
{
  guint8 intra_quantizer_matrix[64];
  guint8 non_intra_quantizer_matrix[64];
};

gboolean mpeg_util_parse_sequence_hdr (MPEGSeqHdr *hdr, GstBuffer *buffer);

gboolean mpeg_util_parse_sequence_extension (MPEGSeqExtHdr *hdr,
    GstBuffer *buffer);

gboolean mpeg_util_parse_picture_hdr (MPEGPictureHdr * hdr, GstBuffer *buffer);

gboolean mpeg_util_parse_picture_coding_extension (MPEGPictureExt *ext,
    GstBuffer *buffer);

gboolean mpeg_util_parse_gop (MPEGGop * gop, GstBuffer *buffer);

gboolean mpeg_util_parse_quant_matrix (MPEGQuantMatrix * qm, GstBuffer *buffer);

#endif