annotate h261enc.c @ 11994:ea2cb1a9e815 libavcodec

aacenc: Properly pad extradata. This fixes a valgrind error when encoding to ADTS.
author alexc
date Mon, 28 Jun 2010 21:34:57 +0000
parents 7dd2a45249a9
children fdafbcef52f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1 /*
5057
5b63f62602fa Split the h261.c file into separate files for the encoder, decoder and common stuff.
takis
parents: 4962
diff changeset
2 * H261 encoder
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
4 * Copyright (c) 2004 Maarten Daniels
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
5 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3740
diff changeset
6 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3740
diff changeset
7 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3740
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3740
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
12 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3740
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
16 * Lesser General Public License for more details.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
17 *
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3740
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
21 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
22
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
23 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11560
diff changeset
24 * @file
5057
5b63f62602fa Split the h261.c file into separate files for the encoder, decoder and common stuff.
takis
parents: 4962
diff changeset
25 * H.261 encoder.
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
26 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
27
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
28 #include "dsputil.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
29 #include "avcodec.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
30 #include "mpegvideo.h"
11082
f48de939cf88 Add include necessary for ff_set_qscale
reimar
parents: 10146
diff changeset
31 #include "h263.h"
5158
65b1bfb3a74c move definition of MB_TYPE_H261_FIL to h261.h so h261.c doesn't
mru
parents: 5057
diff changeset
32 #include "h261.h"
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
33 #include "h261data.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
34
5057
5b63f62602fa Split the h261.c file into separate files for the encoder, decoder and common stuff.
takis
parents: 4962
diff changeset
35 extern uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3];
4668
1f1a0e67b961 kill av_mallocz_static() calls in init_rl()
michael
parents: 4206
diff changeset
36
5057
5b63f62602fa Split the h261.c file into separate files for the encoder, decoder and common stuff.
takis
parents: 4962
diff changeset
37 static void h261_encode_block(H261Context * h, DCTELEM * block,
5b63f62602fa Split the h261.c file into separate files for the encoder, decoder and common stuff.
takis
parents: 4962
diff changeset
38 int n);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
39
4206
be94e97ecb6e throw error if unsupported resolution is used with h261
bcoudurier
parents: 3947
diff changeset
40 int ff_h261_get_picture_format(int width, int height){
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
41 // QCIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
42 if (width == 176 && height == 144)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
43 return 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
44 // CIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
45 else if (width == 352 && height == 288)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
46 return 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
47 // ERROR
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
48 else
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
49 return -1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
50 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
51
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
52 void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
53 H261Context * h = (H261Context *) s;
2328
7b5353eb0dd8 cleanup
michael
parents: 2327
diff changeset
54 int format, temp_ref;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
55
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
56 align_put_bits(&s->pb);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
57
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
58 /* Update the pointer to last GOB */
9431
932543edc1d2 Rename pbBufPtr() to put_bits_ptr().
stefano
parents: 8718
diff changeset
59 s->ptr_lastgob = put_bits_ptr(&s->pb);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
60
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
61 put_bits(&s->pb, 20, 0x10); /* PSC */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
62
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
63 temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num /
2637
ef44d24680d1 switch to native time bases
michael
parents: 2632
diff changeset
64 (1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp
7260
3ec34b551aae bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents: 7040
diff changeset
65 put_sbits(&s->pb, 5, temp_ref); /* TemporalReference */
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
66
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
67 put_bits(&s->pb, 1, 0); /* split screen off */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
68 put_bits(&s->pb, 1, 0); /* camera off */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
69 put_bits(&s->pb, 1, 0); /* freeze picture release off */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
70
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
71 format = ff_h261_get_picture_format(s->width, s->height);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
72
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
73 put_bits(&s->pb, 1, format); /* 0 == QCIF, 1 == CIF */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
74
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
75 put_bits(&s->pb, 1, 0); /* still image mode */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
76 put_bits(&s->pb, 1, 0); /* reserved */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
77
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
78 put_bits(&s->pb, 1, 0); /* no PEI */
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
79 if(format == 0)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
80 h->gob_number = -1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
81 else
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
82 h->gob_number = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
83 h->current_mba = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
84 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
85
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
86 /**
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
87 * Encodes a group of blocks header.
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
88 */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
89 static void h261_encode_gob_header(MpegEncContext * s, int mb_line){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
90 H261Context * h = (H261Context *)s;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
91 if(ff_h261_get_picture_format(s->width, s->height) == 0){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
92 h->gob_number+=2; // QCIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
93 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
94 else{
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
95 h->gob_number++; // CIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
96 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
97 put_bits(&s->pb, 16, 1); /* GBSC */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
98 put_bits(&s->pb, 4, h->gob_number); /* GN */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
99 put_bits(&s->pb, 5, s->qscale); /* GQUANT */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
100 put_bits(&s->pb, 1, 0); /* no GEI */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
101 h->current_mba = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
102 h->previous_mba = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
103 h->current_mv_x=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
104 h->current_mv_y=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
105 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
106
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
107 void ff_h261_reorder_mb_index(MpegEncContext* s){
2331
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
108 int index= s->mb_x + s->mb_y*s->mb_width;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
109
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
110 if(index % 33 == 0)
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
111 h261_encode_gob_header(s,0);
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
112
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
113 /* for CIF the GOB's are fragmented in the middle of a scanline
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
114 that's why we need to adjust the x and y index of the macroblocks */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
115 if(ff_h261_get_picture_format(s->width,s->height) == 1){ // CIF
2331
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
116 s->mb_x = index % 11 ; index /= 11;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
117 s->mb_y = index % 3 ; index /= 3;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
118 s->mb_x+= 11*(index % 2); index /= 2;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
119 s->mb_y+= 3*index;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
120
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
121 ff_init_block_index(s);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
122 ff_update_block_index(s);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
123 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
124 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
125
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
126 static void h261_encode_motion(H261Context * h, int val){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
127 MpegEncContext * const s = &h->s;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
128 int sign, code;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
129 if(val==0){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
130 code = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
131 put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
132 }
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
133 else{
2345
ada3891b859d H261 fixing and cleaning:
michael
parents: 2332
diff changeset
134 if(val > 15)
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
135 val -=32;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
136 if(val < -16)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
137 val+=32;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
138 sign = val < 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
139 code = sign ? -val : val;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
140 put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
141 put_bits(&s->pb,1,sign);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
142 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
143 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
144
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
145 static inline int get_cbp(MpegEncContext * s,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
146 DCTELEM block[6][64])
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
147 {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
148 int i, cbp;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
149 cbp= 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
150 for (i = 0; i < 6; i++) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
151 if (s->block_last_index[i] >= 0)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
152 cbp |= 1 << (5 - i);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
153 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
154 return cbp;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
155 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
156 void ff_h261_encode_mb(MpegEncContext * s,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
157 DCTELEM block[6][64],
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
158 int motion_x, int motion_y)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
159 {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
160 H261Context * h = (H261Context *)s;
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
161 int mvd, mv_diff_x, mv_diff_y, i, cbp;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
162 cbp = 63; // avoid warning
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
163 mvd = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
164
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
165 h->current_mba++;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
166 h->mtype = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
167
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
168 if (!s->mb_intra){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
169 /* compute cbp */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
170 cbp= get_cbp(s, block);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
171
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
172 /* mvd indicates if this block is motion compensated */
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
173 mvd = motion_x | motion_y;
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
174
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
175 if((cbp | mvd | s->dquant ) == 0) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
176 /* skip macroblock */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
177 s->skip_count++;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
178 h->current_mv_x=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
179 h->current_mv_y=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
180 return;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
181 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
182 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
183
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
184 /* MB is not skipped, encode MBA */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
185 put_bits(&s->pb, h261_mba_bits[(h->current_mba-h->previous_mba)-1], h261_mba_code[(h->current_mba-h->previous_mba)-1]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
186
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
187 /* calculate MTYPE */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
188 if(!s->mb_intra){
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
189 h->mtype++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
190
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
191 if(mvd || s->loop_filter)
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
192 h->mtype+=3;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
193 if(s->loop_filter)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
194 h->mtype+=3;
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
195 if(cbp || s->dquant)
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
196 h->mtype++;
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
197 assert(h->mtype > 1);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
198 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
199
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
200 if(s->dquant)
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
201 h->mtype++;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
202
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
203 put_bits(&s->pb, h261_mtype_bits[h->mtype], h261_mtype_code[h->mtype]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
204
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
205 h->mtype = h261_mtype_map[h->mtype];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
206
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
207 if(IS_QUANT(h->mtype)){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
208 ff_set_qscale(s,s->qscale+s->dquant);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
209 put_bits(&s->pb, 5, s->qscale);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
210 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
211
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
212 if(IS_16X16(h->mtype)){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
213 mv_diff_x = (motion_x >> 1) - h->current_mv_x;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
214 mv_diff_y = (motion_y >> 1) - h->current_mv_y;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
215 h->current_mv_x = (motion_x >> 1);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
216 h->current_mv_y = (motion_y >> 1);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
217 h261_encode_motion(h,mv_diff_x);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
218 h261_encode_motion(h,mv_diff_y);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
219 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
220
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
221 h->previous_mba = h->current_mba;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
222
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
223 if(HAS_CBP(h->mtype)){
3317
e2a44d47dae8 cbp must be >0 here or we are in troubble
michael
parents: 3177
diff changeset
224 assert(cbp>0);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
225 put_bits(&s->pb,h261_cbp_tab[cbp-1][1],h261_cbp_tab[cbp-1][0]);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
226 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
227 for(i=0; i<6; i++) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
228 /* encode each block */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
229 h261_encode_block(h, block[i], i);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
230 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
231
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
232 if ( ( h->current_mba == 11 ) || ( h->current_mba == 22 ) || ( h->current_mba == 33 ) || ( !IS_16X16 ( h->mtype ) )){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
233 h->current_mv_x=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
234 h->current_mv_y=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
235 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
236 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
237
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
238 void ff_h261_encode_init(MpegEncContext *s){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
239 static int done = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
240
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
241 if (!done) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
242 done = 1;
5057
5b63f62602fa Split the h261.c file into separate files for the encoder, decoder and common stuff.
takis
parents: 4962
diff changeset
243 init_rl(&h261_rl_tcoeff, ff_h261_rl_table_store);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
244 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
245
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
246 s->min_qcoeff= -127;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
247 s->max_qcoeff= 127;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
248 s->y_dc_scale_table=
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
249 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
250 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
251
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
252
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
253 /**
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
254 * encodes a 8x8 block.
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
255 * @param block the 8x8 block
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
256 * @param n block index (0-3 are luma, 4-5 are chroma)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
257 */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
258 static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
259 MpegEncContext * const s = &h->s;
9478
b0874961f1e2 Remove unused variable from h261_encode_block() found by CSA.
michael
parents: 9431
diff changeset
260 int level, run, i, j, last_index, last_non_zero, sign, slevel, code;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
261 RLTable *rl;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
262
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
263 rl = &h261_rl_tcoeff;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
264 if (s->mb_intra) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
265 /* DC coef */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
266 level = block[0];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
267 /* 255 cannot be represented, so we clamp */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
268 if (level > 254) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
269 level = 254;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
270 block[0] = 254;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
271 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
272 /* 0 cannot be represented also */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
273 else if (level < 1) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
274 level = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
275 block[0] = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
276 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
277 if (level == 128)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
278 put_bits(&s->pb, 8, 0xff);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
279 else
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
280 put_bits(&s->pb, 8, level);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
281 i = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
282 } else if((block[0]==1 || block[0] == -1) && (s->block_last_index[n] > -1)){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
283 //special case
2332
cb3f0954e982 cleanup
michael
parents: 2331
diff changeset
284 put_bits(&s->pb,2,block[0]>0 ? 2 : 3 );
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
285 i = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
286 } else {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
287 i = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
288 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
289
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
290 /* AC coefs */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
291 last_index = s->block_last_index[n];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
292 last_non_zero = i - 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
293 for (; i <= last_index; i++) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
294 j = s->intra_scantable.permutated[i];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
295 level = block[j];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
296 if (level) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
297 run = i - last_non_zero - 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
298 sign = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
299 slevel = level;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
300 if (level < 0) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
301 sign = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
302 level = -level;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
303 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
304 code = get_rl_index(rl, 0 /*no last in H.261, EOB is used*/, run, level);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
305 if(run==0 && level < 16)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
306 code+=1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
307 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
308 if (code == rl->n) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
309 put_bits(&s->pb, 6, run);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
310 assert(slevel != 0);
2332
cb3f0954e982 cleanup
michael
parents: 2331
diff changeset
311 assert(level <= 127);
7260
3ec34b551aae bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents: 7040
diff changeset
312 put_sbits(&s->pb, 8, slevel);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
313 } else {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
314 put_bits(&s->pb, 1, sign);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
315 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
316 last_non_zero = i;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
317 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
318 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
319 if(last_index > -1){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
320 put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]);// END OF BLOCK
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
321 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
322 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
323
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
324 AVCodec h261_encoder = {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
325 "h261",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 11082
diff changeset
326 AVMEDIA_TYPE_VIDEO,
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
327 CODEC_ID_H261,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
328 sizeof(H261Context),
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
329 MPV_encode_init,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
330 MPV_encode_picture,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
331 MPV_encode_end,
10146
38cfe222e1a4 Mark all pix_fmts and supported_framerates compound literals as const.
reimar
parents: 9478
diff changeset
332 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6788
diff changeset
333 .long_name= NULL_IF_CONFIG_SMALL("H.261"),
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
334 };
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
335