1
/*****************************************************************************
2
* transrate.h: MPEG2 video transrating module
3
*****************************************************************************
4
* Copyright (C) 2003 VideoLAN
5
* Copyright (C) 2003 Antoine Missout
6
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
7
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
8
* $Id: transrate.h 7411 2004-04-21 15:54:09Z massiot $
10
* Authors: Christophe Massiot <massiot@via.ecp.fr>
11
* Laurent Aimar <fenrir@via.ecp.fr>
13
* Michel Lespinasse <walken@zoy.org>
14
* Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
16
* This program is free software; you can redistribute it and/or modify
17
* it under the terms of the GNU General Public License as published by
18
* the Free Software Foundation; either version 2 of the License, or
19
* (at your option) any later version.
21
* This program is distributed in the hope that it will be useful,
22
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
* GNU General Public License for more details.
26
* You should have received a copy of the GNU General Public License
27
* along with this program; if not, write to the Free Software
28
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
29
*****************************************************************************/
31
/*****************************************************************************
33
*****************************************************************************/
51
uint32_t i_bit_in_cache;
52
uint32_t i_bit_out_cache;
65
unsigned int horizontal_size_value;
66
unsigned int vertical_size_value;
67
uint8_t intra_quantizer_matrix [64];
68
uint8_t non_intra_quantizer_matrix [64];
72
unsigned int picture_coding_type;
75
unsigned int f_code[2][2];
76
/* unsigned int intra_dc_precision; */
77
unsigned int picture_structure;
78
unsigned int frame_pred_frame_dct;
79
unsigned int concealment_motion_vectors;
80
unsigned int q_scale_type;
81
unsigned int intra_vlc_format;
85
// quantizer_scale_code
86
unsigned int quantizer_scale;
87
unsigned int new_quantizer_scale;
88
unsigned int last_coded_scale;
89
int h_offset, v_offset;
94
int i_admissible_error, i_minimum_error;
97
ssize_t i_total_input, i_remaining_input;
99
ssize_t i_current_output, i_wanted_output;
103
struct sout_stream_id_t
106
vlc_bool_t b_transrate;
108
block_t *p_current_buffer;
110
mtime_t i_next_gop_duration;
111
size_t i_next_gop_size;
117
#ifdef HAVE_BUILTIN_EXPECT
118
#define likely(x) __builtin_expect ((x) != 0, 1)
119
#define unlikely(x) __builtin_expect ((x) != 0, 0)
121
#define likely(x) (x)
122
#define unlikely(x) (x)
125
#define BITS_IN_BUF (8)
127
#define LOG(msg) fprintf (stderr, msg)
128
#define LOGF(format, args...) fprintf (stderr, format, args)
130
static inline void bs_write( bs_transrate_t *s, unsigned int val, int n )
133
assert(!(val & (0xffffffffU << n)));
135
while (unlikely(n >= s->i_bit_out))
137
s->p_w[0] = (s->i_bit_out_cache << s->i_bit_out ) | (val >> (n - s->i_bit_out));
140
s->i_bit_out_cache = 0;
141
val &= ~(0xffffffffU << n);
142
s->i_bit_out = BITS_IN_BUF;
147
s->i_bit_out_cache = (s->i_bit_out_cache << n) | val;
151
assert(s->i_bit_out > 0);
152
assert(s->i_bit_out <= BITS_IN_BUF);
155
static inline void bs_refill( bs_transrate_t *s )
157
assert((s->p_r - s->p_c) >= 1);
158
s->i_bit_in_cache |= s->p_c[0] << (24 - s->i_bit_in);
163
static inline void bs_flush( bs_transrate_t *s, unsigned int n )
165
assert(s->i_bit_in >= n);
167
s->i_bit_in_cache <<= n;
170
assert( (!n) || ((n>0) && !(s->i_bit_in_cache & 0x1)) );
172
while (unlikely(s->i_bit_in < 24)) bs_refill( s );
175
static inline unsigned int bs_read( bs_transrate_t *s, unsigned int n )
177
unsigned int Val = ((unsigned int)s->i_bit_in_cache) >> (32 - n);
182
static inline unsigned int bs_copy( bs_transrate_t *s, unsigned int n )
184
unsigned int Val = bs_read( s, n);
189
static inline void bs_flush_read( bs_transrate_t *s )
191
int i = s->i_bit_in & 0x7;
194
assert(((unsigned int)s->i_bit_in_cache) >> (32 - i) == 0);
195
s->i_bit_in_cache <<= i;
198
s->p_c += -1 * (s->i_bit_in >> 3);
201
static inline void bs_flush_write( bs_transrate_t *s )
203
if( s->i_bit_out != 8 ) bs_write(s, 0, s->i_bit_out);
206
int scale_quant( transrate_t *tr, double qrate );
207
int transrate_mb( transrate_t *tr, RunLevel blk[6][65], RunLevel new_blk[6][65], int i_cbp, int intra );
208
void get_intra_block_B14( transrate_t *tr, RunLevel *blk );
209
void get_intra_block_B15( transrate_t *tr, RunLevel *blk );
210
int get_non_intra_block( transrate_t *tr, RunLevel *blk );
211
void putnonintrablk( bs_transrate_t *bs, RunLevel *blk);
212
void putintrablk( bs_transrate_t *bs, RunLevel *blk, int vlcformat);
214
int process_frame( sout_stream_t *p_stream, sout_stream_id_t *id,
215
block_t *in, block_t **out, int i_handicap );