00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 typedef struct
00036 {
00037 uint8_t run;
00038 short level;
00039 } RunLevel;
00040
00041 typedef struct
00042 {
00043 uint8_t *p_c;
00044 uint8_t *p_r;
00045 uint8_t *p_w;
00046 uint8_t *p_ow;
00047 uint8_t *p_rw;
00048
00049 int i_bit_in;
00050 int i_bit_out;
00051 uint32_t i_bit_in_cache;
00052 uint32_t i_bit_out_cache;
00053
00054 uint32_t i_byte_in;
00055 uint32_t i_byte_out;
00056 } bs_transrate_t;
00057
00058 typedef struct
00059 {
00060 bs_transrate_t bs;
00061
00062
00063
00064
00065 unsigned int horizontal_size_value;
00066 unsigned int vertical_size_value;
00067 uint8_t intra_quantizer_matrix [64];
00068 uint8_t non_intra_quantizer_matrix [64];
00069 int mpeg4_matrix;
00070
00071
00072 unsigned int picture_coding_type;
00073
00074
00075 unsigned int f_code[2][2];
00076
00077 unsigned int picture_structure;
00078 unsigned int frame_pred_frame_dct;
00079 unsigned int concealment_motion_vectors;
00080 unsigned int q_scale_type;
00081 unsigned int intra_vlc_format;
00082 const uint8_t * scan;
00083
00084
00085
00086 unsigned int quantizer_scale;
00087 unsigned int new_quantizer_scale;
00088 unsigned int last_coded_scale;
00089 int h_offset, v_offset;
00090 vlc_bool_t b_error;
00091
00092
00093 double qrate;
00094 int i_admissible_error, i_minimum_error;
00095
00096
00097 ssize_t i_total_input, i_remaining_input;
00098
00099 ssize_t i_current_output, i_wanted_output;
00100 } transrate_t;
00101
00102
00103 struct sout_stream_id_t
00104 {
00105 void *id;
00106 vlc_bool_t b_transrate;
00107
00108 block_t *p_current_buffer;
00109 block_t *p_next_gop;
00110 mtime_t i_next_gop_duration;
00111 size_t i_next_gop_size;
00112
00113 transrate_t tr;
00114 };
00115
00116
00117 #ifdef HAVE_BUILTIN_EXPECT
00118 #define likely(x) __builtin_expect ((x) != 0, 1)
00119 #define unlikely(x) __builtin_expect ((x) != 0, 0)
00120 #else
00121 #define likely(x) (x)
00122 #define unlikely(x) (x)
00123 #endif
00124
00125 #define BITS_IN_BUF (8)
00126
00127 #define LOG(msg) fprintf (stderr, msg)
00128 #define LOGF(format, args...) fprintf (stderr, format, args)
00129
00130 static inline void bs_write( bs_transrate_t *s, unsigned int val, int n )
00131 {
00132 assert(n < 32);
00133 assert(!(val & (0xffffffffU << n)));
00134
00135 while (unlikely(n >= s->i_bit_out))
00136 {
00137 s->p_w[0] = (s->i_bit_out_cache << s->i_bit_out ) | (val >> (n - s->i_bit_out));
00138 s->p_w++;
00139 n -= s->i_bit_out;
00140 s->i_bit_out_cache = 0;
00141 val &= ~(0xffffffffU << n);
00142 s->i_bit_out = BITS_IN_BUF;
00143 }
00144
00145 if (likely(n))
00146 {
00147 s->i_bit_out_cache = (s->i_bit_out_cache << n) | val;
00148 s->i_bit_out -= n;
00149 }
00150
00151 assert(s->i_bit_out > 0);
00152 assert(s->i_bit_out <= BITS_IN_BUF);
00153 }
00154
00155 static inline void bs_refill( bs_transrate_t *s )
00156 {
00157 assert((s->p_r - s->p_c) >= 1);
00158 s->i_bit_in_cache |= s->p_c[0] << (24 - s->i_bit_in);
00159 s->i_bit_in += 8;
00160 s->p_c++;
00161 }
00162
00163 static inline void bs_flush( bs_transrate_t *s, unsigned int n )
00164 {
00165 assert(s->i_bit_in >= n);
00166
00167 s->i_bit_in_cache <<= n;
00168 s->i_bit_in -= n;
00169
00170 assert( (!n) || ((n>0) && !(s->i_bit_in_cache & 0x1)) );
00171
00172 while (unlikely(s->i_bit_in < 24)) bs_refill( s );
00173 }
00174
00175 static inline unsigned int bs_read( bs_transrate_t *s, unsigned int n )
00176 {
00177 unsigned int Val = ((unsigned int)s->i_bit_in_cache) >> (32 - n);
00178 bs_flush( s, n );
00179 return Val;
00180 }
00181
00182 static inline unsigned int bs_copy( bs_transrate_t *s, unsigned int n )
00183 {
00184 unsigned int Val = bs_read( s, n);
00185 bs_write(s, Val, n);
00186 return Val;
00187 }
00188
00189 static inline void bs_flush_read( bs_transrate_t *s )
00190 {
00191 int i = s->i_bit_in & 0x7;
00192 if( i )
00193 {
00194 assert(((unsigned int)s->i_bit_in_cache) >> (32 - i) == 0);
00195 s->i_bit_in_cache <<= i;
00196 s->i_bit_in -= i;
00197 }
00198 s->p_c += -1 * (s->i_bit_in >> 3);
00199 s->i_bit_in = 0;
00200 }
00201 static inline void bs_flush_write( bs_transrate_t *s )
00202 {
00203 if( s->i_bit_out != 8 ) bs_write(s, 0, s->i_bit_out);
00204 }
00205
00206 int scale_quant( transrate_t *tr, double qrate );
00207 int transrate_mb( transrate_t *tr, RunLevel blk[6][65], RunLevel new_blk[6][65], int i_cbp, int intra );
00208 void get_intra_block_B14( transrate_t *tr, RunLevel *blk );
00209 void get_intra_block_B15( transrate_t *tr, RunLevel *blk );
00210 int get_non_intra_block( transrate_t *tr, RunLevel *blk );
00211 void putnonintrablk( bs_transrate_t *bs, RunLevel *blk);
00212 void putintrablk( bs_transrate_t *bs, RunLevel *blk, int vlcformat);
00213
00214 int process_frame( sout_stream_t *p_stream, sout_stream_id_t *id,
00215 block_t *in, block_t **out, int i_handicap );