2
stores sequence header info, for reinit of stream
3
Copyright (C) 2000 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
14
#include "mpegVideoHeader.h"
16
#include "mpegExtension.h"
17
#include "mpegVideoStream.h"
19
/* Video rates table */
20
/* Cheat on Vid rates, round to 30, and use 30 if illegal value
21
Except for 9, where Xing means 15, and given their popularity, we'll
24
static double VidRateNum[16]={29.97, 24, 24, 25, 29.97, 29.97, 50, 59.94,
25
59.94, 14.985, 29.97, 29.97, 29.97, 29.97,
30
static const unsigned char default_intra_matrix[64] = {
31
8, 16, 19, 22, 26, 27, 29, 34,
32
16, 16, 22, 24, 27, 29, 34, 37,
33
19, 22, 26, 27, 29, 34, 34, 38,
34
22, 22, 26, 27, 29, 34, 37, 40,
35
22, 26, 27, 29, 32, 35, 40, 48,
36
26, 27, 29, 32, 35, 40, 48, 58,
37
26, 27, 29, 34, 38, 46, 56, 69,
38
27, 29, 35, 38, 46, 56, 69, 83};
42
/* Set up array for fast conversion from zig zag order to row/column
46
const int zigzag[64][2] = {
47
{0,0},{1,0},{0,1},{0,2},{1,1},{2,0},{3,0},{2,1},{1,2},{0,3},{0,4},{1,3},
48
{2,2},{3,1},{4,0},{5,0},{4,1},{3,2},{2,3},{1,4},{0,5},{0,6},{1,5},{2,4},
49
{3,3},{4,2},{5,1},{6,0},{7,0},{6,1},{5,2},{4,3},{3,4},{2,5},{1,6},{0,7},
50
{1,7},{2,6},{3,5},{4,4},{5,3},{6,2},{7,1},{7,2},{6,3},{5,4},{4,5},{3,6},
51
{2,7},{3,7},{4,6},{5,5},{6,4},{7,3},{7,4},{6,5},{5,6},{4,7},{5,7},{6,6},
52
{7,5},{7,6},{6,7},{7,7} };
58
MpegVideoHeader::MpegVideoHeader() {
64
void MpegVideoHeader::init() {
76
extension=new MpegExtension();
81
void MpegVideoHeader::init_quanttables() {
85
/* Copy default intra matrix. */
87
for (i = 0; i < 8; i++) {
88
for (j = 0; j < 8; j++) {
89
intra_quant_matrix[i][j]=default_intra_matrix[i*8+j];
93
/* Initialize non intra quantization matrix. */
95
for (i = 0; i < 8; i++) {
96
for (j = 0; j < 8; j++) {
97
non_intra_quant_matrix[i][j] = 16;
103
MpegVideoHeader::~MpegVideoHeader() {
112
*--------------------------------------------------------------
116
* Assumes bit stream is at the END of the sequence
117
* header start code. Parses off the sequence header.
120
* Fills the vid_stream structure with values derived and
121
* decoded from the sequence header. Allocates the pict image
122
* structures based on the dimensions of the image space
123
* found in the sequence header.
126
* Bit stream irreversibly parsed off.
128
*--------------------------------------------------------------
130
int MpegVideoHeader::parseSeq(MpegVideoStream* mpegVideoStream) {
134
// seq_start_code already flushed!!!
136
/* Get horizontal size of image space. */
138
h_size=mpegVideoStream->getBits(12);
140
/* Get vertical size of image space. */
142
v_size=mpegVideoStream->getBits(12);
145
/* Calculate macroblock width and height of image space. */
147
mb_width = (h_size + 15) / 16;
148
mb_height = (v_size + 15) / 16;
149
mb_size=mb_height * mb_width-1;
153
/* Parse of aspect ratio code. */
155
data=mpegVideoStream->getBits(4);
157
aspect_ratio = (unsigned char) data;
159
/* Parse off picture rate code. */
161
data=mpegVideoStream->getBits(4);
162
picture_rate=VidRateNum[data];
164
/* Parse off bit rate. */
166
data=mpegVideoStream->getBits(18);
169
/* Flush marker bit. */
171
mpegVideoStream->flushBits(1);
173
/* Parse off vbv buffer size. */
175
data=mpegVideoStream->getBits(10);
176
vbv_buffer_size = data;
178
/* Parse off contrained parameter flag. */
180
data=mpegVideoStream->getBits(1);
182
const_param_flag = true;
184
const_param_flag = false;
187
* If intra_quant_matrix_flag set, parse off intra quant matrix values.
189
data=mpegVideoStream->getBits(1);
191
for (i = 0; i < 64; i++) {
192
data=mpegVideoStream->getBits(8);
193
intra_quant_matrix[zigzag[i][1]][zigzag[i][0]]=(unsigned char)data;
197
* If non intra quant matrix flag set, parse off non intra quant matrix
201
data=mpegVideoStream->getBits(1);
203
for (i = 0; i < 64; i++) {
204
data=mpegVideoStream->getBits(8);
206
non_intra_quant_matrix[zigzag[i&0x3f][1]][zigzag[i&0x3f][0]]=
207
(unsigned char) data;
211
* If next start code is extension/user start code,
212
* parse off extension data.
214
extension->processExtensionData(mpegVideoStream);
223
void MpegVideoHeader::copyTo(MpegVideoHeader* dest) {
228
dest->mb_height=mb_height;
229
dest->mb_width=mb_width;
230
dest->mb_size=mb_size;
231
dest->aspect_ratio=aspect_ratio;
232
dest->bit_rate=bit_rate;
233
dest->vbv_buffer_size=vbv_buffer_size;
234
dest->const_param_flag=const_param_flag;
235
dest->picture_rate=picture_rate;
241
/* Copy default intra matrix. */
243
for (i = 0; i < 8; i++) {
244
for (j = 0; j < 8; j++) {
245
dest->intra_quant_matrix[i][j]=intra_quant_matrix[i][j];
250
/* Initialize non intra quantization matrix. */
252
for (i = 0; i < 8; i++) {
253
for (j = 0; j < 8; j++) {
254
dest->non_intra_quant_matrix[i][j] =non_intra_quant_matrix[i][j] ;
263
double MpegVideoHeader::getPictureTime() {
264
if (picture_rate > 0) {
265
return 1.0/picture_rate;
276
void MpegVideoHeader::print(char* description) {
277
cout << "MpegVideoHeader [START]:"<<description<<endl;
278
cout <<"h_size:"<<h_size<<endl;
279
cout <<"v_size:"<<v_size<<endl;
280
cout <<"mb_height:"<<mb_height<<endl;
281
cout <<"mb_width:"<<mb_width<<endl;
282
cout <<"mb_size:"<<mb_size<<endl;
283
cout <<"aspect_ratio:"<<aspect_ratio<<endl;
284
cout <<"bit_rate:"<<bit_rate<<endl;
285
cout <<"vbv_buffer_size:"<<vbv_buffer_size<<endl;
286
cout <<"const_param_flag:"<<const_param_flag<<endl;
287
cout << "MpegVideoHeader [END]:"<<endl;