072f6fcf7bfc068757483f7390cff57841ed8766
[libav.git] / libavcodec / msmpeg4enc.c
1 /*
2 * MSMPEG4 encoder backend
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of Libav.
9 *
10 * Libav is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * Libav is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with Libav; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * MSMPEG4 encoder backend
28 */
29
30 #include <stdint.h>
31 #include <string.h>
32
33 #include "libavutil/attributes.h"
34 #include "libavutil/avutil.h"
35 #include "libavutil/mem.h"
36 #include "mpegvideo.h"
37 #include "msmpeg4.h"
38 #include "h263.h"
39 #include "internal.h"
40 #include "mpeg4video.h"
41 #include "msmpeg4.h"
42 #include "msmpeg4data.h"
43 #include "put_bits.h"
44 #include "rl.h"
45 #include "vc1data.h"
46
47 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
48
49 /* build the table which associate a (x,y) motion vector to a vlc */
50 static av_cold int init_mv_table(MVTable *tab)
51 {
52 int i, x, y;
53
54 tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
55 if (!tab->table_mv_index)
56 return AVERROR(ENOMEM);
57
58 /* mark all entries as not used */
59 for(i=0;i<4096;i++)
60 tab->table_mv_index[i] = tab->n;
61
62 for(i=0;i<tab->n;i++) {
63 x = tab->table_mvx[i];
64 y = tab->table_mvy[i];
65 tab->table_mv_index[(x << 6) | y] = i;
66 }
67
68 return 0;
69 }
70
71 void ff_msmpeg4_code012(PutBitContext *pb, int n)
72 {
73 if (n == 0) {
74 put_bits(pb, 1, 0);
75 } else {
76 put_bits(pb, 1, 1);
77 put_bits(pb, 1, (n >= 2));
78 }
79 }
80
81 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
82 int size=0;
83 int code;
84 int run_diff= intra ? 0 : 1;
85
86 code = get_rl_index(rl, last, run, level);
87 size+= rl->table_vlc[code][1];
88 if (code == rl->n) {
89 int level1, run1;
90
91 level1 = level - rl->max_level[last][run];
92 if (level1 < 1)
93 goto esc2;
94 code = get_rl_index(rl, last, run, level1);
95 if (code == rl->n) {
96 esc2:
97 size++;
98 if (level > MAX_LEVEL)
99 goto esc3;
100 run1 = run - rl->max_run[last][level] - run_diff;
101 if (run1 < 0)
102 goto esc3;
103 code = get_rl_index(rl, last, run1, level);
104 if (code == rl->n) {
105 esc3:
106 /* third escape */
107 size+=1+1+6+8;
108 } else {
109 /* second escape */
110 size+= 1+1+ rl->table_vlc[code][1];
111 }
112 } else {
113 /* first escape */
114 size+= 1+1+ rl->table_vlc[code][1];
115 }
116 } else {
117 size++;
118 }
119 return size;
120 }
121
122 av_cold int ff_msmpeg4_encode_init(MpegEncContext *s)
123 {
124 static int init_done=0;
125 int i, ret;
126
127 ff_msmpeg4_common_init(s);
128 if(s->msmpeg4_version>=4){
129 s->min_qcoeff= -255;
130 s->max_qcoeff= 255;
131 }
132
133 if (!init_done) {
134 /* init various encoding tables */
135 init_done = 1;
136 if ((ret = init_mv_table(&ff_mv_tables[0])) < 0)
137 return ret;
138 if ((ret = init_mv_table(&ff_mv_tables[1])) < 0)
139 return ret;
140 for(i=0;i<NB_RL_TABLES;i++)
141 ff_init_rl(&ff_rl_table[i], ff_static_rl_table_store[i]);
142
143 for(i=0; i<NB_RL_TABLES; i++){
144 int level;
145 for (level = 1; level <= MAX_LEVEL; level++) {
146 int run;
147 for(run=0; run<=MAX_RUN; run++){
148 int last;
149 for(last=0; last<2; last++){
150 rl_length[i][level][run][last]= get_size_of_code(s, &ff_rl_table[ i], last, run, level, 0);
151 }
152 }
153 }
154 }
155 }
156
157 return 0;
158 }
159
160 static void find_best_tables(MpegEncContext * s)
161 {
162 int i;
163 int best =-1, best_size =9999999;
164 int chroma_best=-1, best_chroma_size=9999999;
165
166 for(i=0; i<3; i++){
167 int level;
168 int chroma_size=0;
169 int size=0;
170
171 if(i>0){// ;)
172 size++;
173 chroma_size++;
174 }
175 for(level=0; level<=MAX_LEVEL; level++){
176 int run;
177 for(run=0; run<=MAX_RUN; run++){
178 int last;
179 const int last_size= size + chroma_size;
180 for(last=0; last<2; last++){
181 int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
182 int intra_luma_count = s->ac_stats[1][0][level][run][last];
183 int intra_chroma_count= s->ac_stats[1][1][level][run][last];
184
185 if(s->pict_type==AV_PICTURE_TYPE_I){
186 size += intra_luma_count *rl_length[i ][level][run][last];
187 chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
188 }else{
189 size+= intra_luma_count *rl_length[i ][level][run][last]
190 +intra_chroma_count*rl_length[i+3][level][run][last]
191 +inter_count *rl_length[i+3][level][run][last];
192 }
193 }
194 if(last_size == size+chroma_size) break;
195 }
196 }
197 if(size<best_size){
198 best_size= size;
199 best= i;
200 }
201 if(chroma_size<best_chroma_size){
202 best_chroma_size= chroma_size;
203 chroma_best= i;
204 }
205 }
206
207 if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
208
209 memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
210
211 s->rl_table_index = best;
212 s->rl_chroma_table_index= chroma_best;
213
214 if(s->pict_type != s->last_non_b_pict_type){
215 s->rl_table_index= 2;
216 if(s->pict_type==AV_PICTURE_TYPE_I)
217 s->rl_chroma_table_index= 1;
218 else
219 s->rl_chroma_table_index= 2;
220 }
221
222 }
223
224 /* write MSMPEG4 compatible frame header */
225 void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
226 {
227 find_best_tables(s);
228
229 avpriv_align_put_bits(&s->pb);
230 put_bits(&s->pb, 2, s->pict_type - 1);
231
232 put_bits(&s->pb, 5, s->qscale);
233 if(s->msmpeg4_version<=2){
234 s->rl_table_index = 2;
235 s->rl_chroma_table_index = 2;
236 }
237
238 s->dc_table_index = 1;
239 s->mv_table_index = 1; /* only if P frame */
240 s->use_skip_mb_code = 1; /* only if P frame */
241 s->per_mb_rl_table = 0;
242 if(s->msmpeg4_version==4)
243 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
244 ff_dlog(s, "%d %d %d %d %d\n", s->pict_type, s->bit_rate,
245 s->inter_intra_pred, s->width, s->height);
246
247 if (s->pict_type == AV_PICTURE_TYPE_I) {
248 s->slice_height= s->mb_height/1;
249 put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
250
251 if(s->msmpeg4_version==4){
252 ff_msmpeg4_encode_ext_header(s);
253 if(s->bit_rate>MBAC_BITRATE)
254 put_bits(&s->pb, 1, s->per_mb_rl_table);
255 }
256
257 if(s->msmpeg4_version>2){
258 if(!s->per_mb_rl_table){
259 ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
260 ff_msmpeg4_code012(&s->pb, s->rl_table_index);
261 }
262
263 put_bits(&s->pb, 1, s->dc_table_index);
264 }
265 } else {
266 put_bits(&s->pb, 1, s->use_skip_mb_code);
267
268 if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
269 put_bits(&s->pb, 1, s->per_mb_rl_table);
270
271 if(s->msmpeg4_version>2){
272 if(!s->per_mb_rl_table)
273 ff_msmpeg4_code012(&s->pb, s->rl_table_index);
274
275 put_bits(&s->pb, 1, s->dc_table_index);
276
277 put_bits(&s->pb, 1, s->mv_table_index);
278 }
279 }
280
281 s->esc3_level_length= 0;
282 s->esc3_run_length= 0;
283 }
284
285 void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
286 {
287 put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
288
289 put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
290
291 if(s->msmpeg4_version>=3)
292 put_bits(&s->pb, 1, s->flipflop_rounding);
293 else
294 assert(s->flipflop_rounding==0);
295 }
296
297 void ff_msmpeg4_encode_motion(MpegEncContext * s,
298 int mx, int my)
299 {
300 int code;
301 MVTable *mv;
302
303 /* modulo encoding */
304 /* WARNING : you cannot reach all the MVs even with the modulo
305 encoding. This is a somewhat strange compromise they took !!! */
306 if (mx <= -64)
307 mx += 64;
308 else if (mx >= 64)
309 mx -= 64;
310 if (my <= -64)
311 my += 64;
312 else if (my >= 64)
313 my -= 64;
314
315 mx += 32;
316 my += 32;
317 #if 0
318 if ((unsigned)mx >= 64 ||
319 (unsigned)my >= 64)
320 av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
321 #endif
322 mv = &ff_mv_tables[s->mv_table_index];
323
324 code = mv->table_mv_index[(mx << 6) | my];
325 put_bits(&s->pb,
326 mv->table_mv_bits[code],
327 mv->table_mv_code[code]);
328 if (code == mv->n) {
329 /* escape : code literally */
330 put_bits(&s->pb, 6, mx);
331 put_bits(&s->pb, 6, my);
332 }
333 }
334
335 void ff_msmpeg4_handle_slices(MpegEncContext *s){
336 if (s->mb_x == 0) {
337 if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
338 if(s->msmpeg4_version < 4){
339 ff_mpeg4_clean_buffers(s);
340 }
341 s->first_slice_line = 1;
342 } else {
343 s->first_slice_line = 0;
344 }
345 }
346 }
347
348 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
349 {
350 int range, bit_size, sign, code, bits;
351
352 if (val == 0) {
353 /* zero vector */
354 code = 0;
355 put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
356 } else {
357 bit_size = s->f_code - 1;
358 range = 1 << bit_size;
359 if (val <= -64)
360 val += 64;
361 else if (val >= 64)
362 val -= 64;
363
364 if (val >= 0) {
365 sign = 0;
366 } else {
367 val = -val;
368 sign = 1;
369 }
370 val--;
371 code = (val >> bit_size) + 1;
372 bits = val & (range - 1);
373
374 put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
375 if (bit_size > 0) {
376 put_bits(&s->pb, bit_size, bits);
377 }
378 }
379 }
380
381 void ff_msmpeg4_encode_mb(MpegEncContext * s,
382 int16_t block[6][64],
383 int motion_x, int motion_y)
384 {
385 int cbp, coded_cbp, i;
386 int pred_x, pred_y;
387 uint8_t *coded_block;
388
389 ff_msmpeg4_handle_slices(s);
390
391 if (!s->mb_intra) {
392 /* compute cbp */
393 cbp = 0;
394 for (i = 0; i < 6; i++) {
395 if (s->block_last_index[i] >= 0)
396 cbp |= 1 << (5 - i);
397 }
398 if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
399 /* skip macroblock */
400 put_bits(&s->pb, 1, 1);
401 s->last_bits++;
402 s->misc_bits++;
403 s->skip_count++;
404
405 return;
406 }
407 if (s->use_skip_mb_code)
408 put_bits(&s->pb, 1, 0); /* mb coded */
409
410 if(s->msmpeg4_version<=2){
411 put_bits(&s->pb,
412 ff_v2_mb_type[cbp&3][1],
413 ff_v2_mb_type[cbp&3][0]);
414 if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
415 else coded_cbp= cbp;
416
417 put_bits(&s->pb,
418 ff_h263_cbpy_tab[coded_cbp>>2][1],
419 ff_h263_cbpy_tab[coded_cbp>>2][0]);
420
421 s->misc_bits += get_bits_diff(s);
422
423 ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
424 msmpeg4v2_encode_motion(s, motion_x - pred_x);
425 msmpeg4v2_encode_motion(s, motion_y - pred_y);
426 }else{
427 put_bits(&s->pb,
428 ff_table_mb_non_intra[cbp + 64][1],
429 ff_table_mb_non_intra[cbp + 64][0]);
430
431 s->misc_bits += get_bits_diff(s);
432
433 /* motion vector */
434 ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
435 ff_msmpeg4_encode_motion(s, motion_x - pred_x,
436 motion_y - pred_y);
437 }
438
439 s->mv_bits += get_bits_diff(s);
440
441 for (i = 0; i < 6; i++) {
442 ff_msmpeg4_encode_block(s, block[i], i);
443 }
444 s->p_tex_bits += get_bits_diff(s);
445 } else {
446 /* compute cbp */
447 cbp = 0;
448 coded_cbp = 0;
449 for (i = 0; i < 6; i++) {
450 int val, pred;
451 val = (s->block_last_index[i] >= 1);
452 cbp |= val << (5 - i);
453 if (i < 4) {
454 /* predict value for close blocks only for luma */
455 pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
456 *coded_block = val;
457 val = val ^ pred;
458 }
459 coded_cbp |= val << (5 - i);
460 }
461
462 if(s->msmpeg4_version<=2){
463 if (s->pict_type == AV_PICTURE_TYPE_I) {
464 put_bits(&s->pb,
465 ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
466 } else {
467 if (s->use_skip_mb_code)
468 put_bits(&s->pb, 1, 0); /* mb coded */
469 put_bits(&s->pb,
470 ff_v2_mb_type[(cbp&3) + 4][1],
471 ff_v2_mb_type[(cbp&3) + 4][0]);
472 }
473 put_bits(&s->pb, 1, 0); /* no AC prediction yet */
474 put_bits(&s->pb,
475 ff_h263_cbpy_tab[cbp>>2][1],
476 ff_h263_cbpy_tab[cbp>>2][0]);
477 }else{
478 if (s->pict_type == AV_PICTURE_TYPE_I) {
479 put_bits(&s->pb,
480 ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
481 } else {
482 if (s->use_skip_mb_code)
483 put_bits(&s->pb, 1, 0); /* mb coded */
484 put_bits(&s->pb,
485 ff_table_mb_non_intra[cbp][1],
486 ff_table_mb_non_intra[cbp][0]);
487 }
488 put_bits(&s->pb, 1, 0); /* no AC prediction yet */
489 if(s->inter_intra_pred){
490 s->h263_aic_dir=0;
491 put_bits(&s->pb, ff_table_inter_intra[s->h263_aic_dir][1], ff_table_inter_intra[s->h263_aic_dir][0]);
492 }
493 }
494 s->misc_bits += get_bits_diff(s);
495
496 for (i = 0; i < 6; i++) {
497 ff_msmpeg4_encode_block(s, block[i], i);
498 }
499 s->i_tex_bits += get_bits_diff(s);
500 s->i_count++;
501 }
502 }
503
504 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
505 {
506 int sign, code;
507 int pred, extquant;
508 int extrabits = 0;
509
510 int16_t *dc_val;
511 pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
512
513 /* update predictor */
514 if (n < 4) {
515 *dc_val = level * s->y_dc_scale;
516 } else {
517 *dc_val = level * s->c_dc_scale;
518 }
519
520 /* do the prediction */
521 level -= pred;
522
523 if(s->msmpeg4_version<=2){
524 if (n < 4) {
525 put_bits(&s->pb,
526 ff_v2_dc_lum_table[level + 256][1],
527 ff_v2_dc_lum_table[level + 256][0]);
528 }else{
529 put_bits(&s->pb,
530 ff_v2_dc_chroma_table[level + 256][1],
531 ff_v2_dc_chroma_table[level + 256][0]);
532 }
533 }else{
534 sign = 0;
535 if (level < 0) {
536 level = -level;
537 sign = 1;
538 }
539 code = level;
540 if (code > DC_MAX)
541 code = DC_MAX;
542 else if( s->msmpeg4_version>=6 ) {
543 if( s->qscale == 1 ) {
544 extquant = (level + 3) & 0x3;
545 code = ((level+3)>>2);
546 } else if( s->qscale == 2 ) {
547 extquant = (level + 1) & 0x1;
548 code = ((level+1)>>1);
549 }
550 }
551
552 if (s->dc_table_index == 0) {
553 if (n < 4) {
554 put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
555 } else {
556 put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
557 }
558 } else {
559 if (n < 4) {
560 put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
561 } else {
562 put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
563 }
564 }
565
566 if(s->msmpeg4_version>=6 && s->qscale<=2)
567 extrabits = 3 - s->qscale;
568
569 if (code == DC_MAX)
570 put_bits(&s->pb, 8 + extrabits, level);
571 else if(extrabits > 0)//== VC1 && s->qscale<=2
572 put_bits(&s->pb, extrabits, extquant);
573
574 if (level != 0) {
575 put_bits(&s->pb, 1, sign);
576 }
577 }
578 }
579
580 /* Encoding of a block. Very similar to MPEG4 except for a different
581 escape coding (same as H263) and more vlc tables.
582 */
583 void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n)
584 {
585 int level, run, last, i, j, last_index;
586 int last_non_zero, sign, slevel;
587 int code, run_diff, dc_pred_dir;
588 const RLTable *rl;
589 const uint8_t *scantable;
590
591 if (s->mb_intra) {
592 msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
593 i = 1;
594 if (n < 4) {
595 rl = &ff_rl_table[s->rl_table_index];
596 } else {
597 rl = &ff_rl_table[3 + s->rl_chroma_table_index];
598 }
599 run_diff = s->msmpeg4_version>=4;
600 scantable= s->intra_scantable.permutated;
601 } else {
602 i = 0;
603 rl = &ff_rl_table[3 + s->rl_table_index];
604 if(s->msmpeg4_version<=2)
605 run_diff = 0;
606 else
607 run_diff = 1;
608 scantable= s->inter_scantable.permutated;
609 }
610
611 /* recalculate block_last_index for M$ wmv1 */
612 if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
613 for(last_index=63; last_index>=0; last_index--){
614 if(block[scantable[last_index]]) break;
615 }
616 s->block_last_index[n]= last_index;
617 }else
618 last_index = s->block_last_index[n];
619 /* AC coefs */
620 last_non_zero = i - 1;
621 for (; i <= last_index; i++) {
622 j = scantable[i];
623 level = block[j];
624 if (level) {
625 run = i - last_non_zero - 1;
626 last = (i == last_index);
627 sign = 0;
628 slevel = level;
629 if (level < 0) {
630 sign = 1;
631 level = -level;
632 }
633
634 if(level<=MAX_LEVEL && run<=MAX_RUN){
635 s->ac_stats[s->mb_intra][n>3][level][run][last]++;
636 }
637
638 s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
639
640 code = get_rl_index(rl, last, run, level);
641 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
642 if (code == rl->n) {
643 int level1, run1;
644
645 level1 = level - rl->max_level[last][run];
646 if (level1 < 1)
647 goto esc2;
648 code = get_rl_index(rl, last, run, level1);
649 if (code == rl->n) {
650 esc2:
651 put_bits(&s->pb, 1, 0);
652 if (level > MAX_LEVEL)
653 goto esc3;
654 run1 = run - rl->max_run[last][level] - run_diff;
655 if (run1 < 0)
656 goto esc3;
657 code = get_rl_index(rl, last, run1+1, level);
658 if (s->msmpeg4_version == 4 && code == rl->n)
659 goto esc3;
660 code = get_rl_index(rl, last, run1, level);
661 if (code == rl->n) {
662 esc3:
663 /* third escape */
664 put_bits(&s->pb, 1, 0);
665 put_bits(&s->pb, 1, last);
666 if(s->msmpeg4_version>=4){
667 if(s->esc3_level_length==0){
668 s->esc3_level_length=8;
669 s->esc3_run_length= 6;
670 //ESCLVLSZ + ESCRUNSZ
671 if(s->qscale<8)
672 put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
673 else
674 put_bits(&s->pb, 8, 3);
675 }
676 put_bits(&s->pb, s->esc3_run_length, run);
677 put_bits(&s->pb, 1, sign);
678 put_bits(&s->pb, s->esc3_level_length, level);
679 }else{
680 put_bits(&s->pb, 6, run);
681 put_sbits(&s->pb, 8, slevel);
682 }
683 } else {
684 /* second escape */
685 put_bits(&s->pb, 1, 1);
686 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
687 put_bits(&s->pb, 1, sign);
688 }
689 } else {
690 /* first escape */
691 put_bits(&s->pb, 1, 1);
692 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
693 put_bits(&s->pb, 1, sign);
694 }
695 } else {
696 put_bits(&s->pb, 1, sign);
697 }
698 last_non_zero = i;
699 }
700 }
701 }