/*
* header.c
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 2003 Regis Duchesne <hpreg@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
* See http://libmpeg2.sourceforge.net/ for updates.
*
* mpeg2dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* mpeg2dec 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
* libmpeg2 sync history:
* 2008-07-01 - CVS revision 1.101
*/
#include "plugin.h"
#include "mpeg2dec_config.h"
#include "mpeg2.h"
#include "attributes.h"
#include "mpeg2_internal.h"
#define SEQ_EXT 2
#define SEQ_DISPLAY_EXT 4
#define QUANT_MATRIX_EXT 8
#define COPYRIGHT_EXT 0x10
#define PIC_DISPLAY_EXT 0x80
#define PIC_CODING_EXT 0x100
/* default intra quant matrix, in zig-zag order */
static const uint8_t default_intra_quantizer_matrix[64] =
{
8,
16, 16,
19, 16, 19,
22, 22, 22, 22,
22, 22, 26, 24, 26,
27, 27, 27, 26, 26, 26,
26, 27, 27, 27, 29, 29, 29,
34, 34, 34, 29, 29, 29, 27, 27,
29, 29, 32, 32, 34, 34, 37,
38, 37, 35, 35, 34, 35,
38, 38, 40, 40, 40,
48, 48, 46, 46,
56, 56, 58,
69, 69,
83
};
const uint8_t default_mpeg2_scan_norm[64] =
{
/* Zig-Zag scan pattern */
0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63
};
const uint8_t default_mpeg2_scan_alt[64] =
{
/* Alternate scan pattern */
0, 8, 16, 24, 1, 9, 2, 10,
17, 25, 32, 40, 48, 56, 57, 49,
41, 33, 26, 18, 3, 11, 4, 12,
19, 27, 34, 42, 50, 58, 35, 43,
51, 59, 20, 28, 5, 13, 6, 14,
21, 29, 36, 44, 52, 60, 37, 45,
53, 61, 22, 30, 7, 15, 23, 31,
38, 46, 54, 62, 39, 47, 55, 63
};
uint8_t mpeg2_scan_norm[64] IDATA_ATTR;
uint8_t mpeg2_scan_alt[64] IDATA_ATTR;
void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
{
if (mpeg2dec->sequence.width != (unsigned)-1)
{
mpeg2dec->sequence.width = (unsigned)-1;
mpeg2_mem_reset(); /* Clean the memory slate */
#if 0
if (!mpeg2dec->custom_fbuf)
{
int i;
for (i = mpeg2dec->alloc_index_user;
i < mpeg2dec->alloc_index; i++)
{
mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
#if MPEG2_COLOR
mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[1]);
mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[2]);
#endif
}
}
if (mpeg2dec->convert_start)
{
int i;
for (i = 0; i < 3; i++)
{
mpeg2_free(mpeg2dec->yuv_buf[i][0]);
#if MPEG2_COLOR
mpeg2_free(mpeg2dec->yuv_buf[i][1]);
mpeg2_free(mpeg2dec->yuv_buf[i][2]);
#endif
}
}
if (mpeg2dec->decoder.convert_id)
{
mpeg2_free(mpeg2dec->decoder.convert_id);
}
#endif
}
mpeg2dec->decoder.coding_type = I_TYPE;
mpeg2dec->decoder.convert = NULL;
mpeg2dec->decoder.convert_id = NULL;
mpeg2dec->picture = mpeg2dec->pictures;
mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf;
mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf;
mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf;
mpeg2dec->first = 1;
mpeg2dec->alloc_index = 0;
mpeg2dec->alloc_index_user = 0;
mpeg2dec->first_decode_slice = 1;
mpeg2dec->nb_decode_slices = 0xb0 - 1;
mpeg2dec->convert = NULL;
mpeg2dec->convert_start = NULL;
mpeg2dec->custom_fbuf = 0;
mpeg2dec->yuv_index = 0;
}
void mpeg2_reset_info (mpeg2_info_t * info)
{
info->current_picture =
info->current_picture_2nd = NULL;
info->display_picture =
info->display_picture_2nd = NULL;
info->current_fbuf =
info->display_fbuf =
info->discard_fbuf = NULL;
}
static void info_user_data (mpeg2dec_t * mpeg2dec)
{
if (mpeg2dec->user_data_len)
{
mpeg2dec->info.user_data = mpeg2dec->chunk_buffer;
mpeg2dec->info.user_data_len = mpeg2dec->user_data_len - 3;
}
}
int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
{
static const unsigned int frame_period[16] =
{
0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000,
/* unofficial: xing 15 fps */
1800000,
/* unofficial: libmpeg3 "Unofficial economy rates" 5/10/12/15 fps */
5400000, 2700000, 2250000, 1800000, 0, 0
};
uint8_t * buffer = mpeg2dec->chunk_start;
mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
int i;
if ((buffer[6] & 0x20) != 0x20) /* missing marker_bit */
return 1;
i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
if (!(sequence->display_width = sequence->picture_width = i >> 12))
return 1;
if (!(sequence->display_height = sequence->picture_height = i & 0xfff))
return 1;
sequence->width = (sequence->picture_width + 15) & ~15;
|