annotate h264enc.c @ 9886:3207f2314192 libavcodec

Rewrite doxy for av_strtod().
author stefano
date Wed, 24 Jun 2009 22:35:11 +0000
parents 0dce4fe6e6f3
children b94e1810ce4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4291
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
1 /*
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
2 * H.264 encoder
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
3 *
7803
de080c5c0960 license header consistency cosmetics
diego
parents: 6763
diff changeset
4 * This file is part of FFmpeg.
de080c5c0960 license header consistency cosmetics
diego
parents: 6763
diff changeset
5 *
4291
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
10 *
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
14 * Lesser General Public License for more details.
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
15 *
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
19 */
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
20
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
21
6763
f7cbb7733146 Use full path for #includes from another directory.
diego
parents: 6524
diff changeset
22 #include "libavutil/common.h"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 8216
diff changeset
23 #include "get_bits.h"
4291
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
24 #include "mpegvideo.h"
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
25 #include "h264data.h"
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
26
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
27 /**
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
28 * Write out the provided data into a NAL unit.
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
29 * @param nal_ref_idc NAL reference IDC
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
30 * @param nal_unit_type NAL unit payload type
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
31 * @param dest the target buffer, dst+1 == src is allowed as a special case
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
32 * @param destsize the length of the dst array
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
33 * @param b2 the data which should be escaped
6524
01647ac078a7 typo: occured --> occurred
diego
parents: 4291
diff changeset
34 * @returns pointer to current position in the output buffer or NULL if an error occurred
4291
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
35 */
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
36 static uint8_t *h264_write_nal_unit(int nal_ref_idc, int nal_unit_type, uint8_t *dest, int *destsize,
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
37 PutBitContext *b2)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
38 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
39 PutBitContext b;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
40 int i, destpos, rbsplen, escape_count;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
41 uint8_t *rbsp;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
42
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
43 if (nal_unit_type != NAL_END_STREAM)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
44 put_bits(b2,1,1); // rbsp_stop_bit
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
45
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
46 // Align b2 on a byte boundary
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
47 align_put_bits(b2);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
48 rbsplen = put_bits_count(b2)/8;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
49 flush_put_bits(b2);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
50 rbsp = b2->buf;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
51
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
52 init_put_bits(&b,dest,*destsize);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
53
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
54 put_bits(&b,16,0);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
55 put_bits(&b,16,0x01);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
56
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
57 put_bits(&b,1,0); // forbidden zero bit
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
58 put_bits(&b,2,nal_ref_idc); // nal_ref_idc
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
59 put_bits(&b,5,nal_unit_type); // nal_unit_type
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
60
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
61 flush_put_bits(&b);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
62
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
63 destpos = 5;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
64 escape_count= 0;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
65
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
66 for (i=0; i<rbsplen; i+=2)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
67 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
68 if (rbsp[i]) continue;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
69 if (i>0 && rbsp[i-1]==0)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
70 i--;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
71 if (i+2<rbsplen && rbsp[i+1]==0 && rbsp[i+2]<=3)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
72 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
73 escape_count++;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
74 i+=2;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
75 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
76 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
77
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
78 if(escape_count==0)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
79 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
80 if(dest+destpos != rbsp)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
81 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
82 memcpy(dest+destpos, rbsp, rbsplen);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
83 *destsize -= (rbsplen+destpos);
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
84 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
85 return dest+rbsplen+destpos;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
86 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
87
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
88 if(rbsplen + escape_count + 1> *destsize)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
89 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
90 av_log(NULL, AV_LOG_ERROR, "Destination buffer too small!\n");
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
91 return NULL;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
92 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
93
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
94 // this should be damn rare (hopefully)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
95 for (i = 0 ; i < rbsplen ; i++)
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
96 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
97 if (i + 2 < rbsplen && (rbsp[i] == 0 && rbsp[i+1] == 0 && rbsp[i+2] < 4))
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
98 {
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
99 dest[destpos++] = rbsp[i++];
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
100 dest[destpos++] = rbsp[i];
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
101 dest[destpos++] = 0x03; // emulation prevention byte
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
102 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
103 else
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
104 dest[destpos++] = rbsp[i];
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
105 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
106 *destsize -= destpos;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
107 return dest+destpos;
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
108 }
0c090df061f8 Adding function which enables writing H.264 NAL units.
takis
parents:
diff changeset
109
8189
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
110 static const uint8_t pict_type_to_golomb[7] = {-1, 2, 0, 1, -1, 4, 3};
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
111
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
112 static const uint8_t intra4x4_cbp_to_golomb[48] = {
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
113 3, 29, 30, 17, 31, 18, 37, 8, 32, 38, 19, 9, 20, 10, 11, 2,
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
114 16, 33, 34, 21, 35, 22, 39, 4, 36, 40, 23, 5, 24, 6, 7, 1,
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
115 41, 42, 43, 25, 44, 26, 46, 12, 45, 47, 27, 13, 28, 14, 15, 0
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
116 };
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
117
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
118 static const uint8_t inter_cbp_to_golomb[48] = {
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
119 0, 2, 3, 7, 4, 8, 17, 13, 5, 18, 9, 14, 10, 15, 16, 11,
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
120 1, 32, 33, 36, 34, 37, 44, 40, 35, 45, 38, 41, 39, 42, 43, 19,
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
121 6, 24, 25, 20, 26, 21, 46, 28, 27, 47, 22, 29, 23, 30, 31, 12
9915843e67e2 Move H.264 tables that are only useful for encoding to h264enc.c.
diego
parents: 7803
diff changeset
122 };
8216
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
123
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
124 #define QUANT_SHIFT 22
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
125
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
126 static const int quant_coeff[52][16] = {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
127 { 419430, 258111, 419430, 258111, 258111, 167772, 258111, 167772, 419430, 258111, 419430, 258111, 258111, 167772, 258111, 167772,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
128 { 381300, 239675, 381300, 239675, 239675, 149131, 239675, 149131, 381300, 239675, 381300, 239675, 239675, 149131, 239675, 149131,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
129 { 322639, 209715, 322639, 209715, 209715, 134218, 209715, 134218, 322639, 209715, 322639, 209715, 209715, 134218, 209715, 134218,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
130 { 299593, 186414, 299593, 186414, 186414, 116711, 186414, 116711, 299593, 186414, 299593, 186414, 186414, 116711, 186414, 116711,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
131 { 262144, 167772, 262144, 167772, 167772, 107374, 167772, 107374, 262144, 167772, 262144, 167772, 167772, 107374, 167772, 107374,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
132 { 233017, 145889, 233017, 145889, 145889, 92564, 145889, 92564, 233017, 145889, 233017, 145889, 145889, 92564, 145889, 92564,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
133 { 209715, 129056, 209715, 129056, 129056, 83886, 129056, 83886, 209715, 129056, 209715, 129056, 129056, 83886, 129056, 83886,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
134 { 190650, 119837, 190650, 119837, 119837, 74565, 119837, 74565, 190650, 119837, 190650, 119837, 119837, 74565, 119837, 74565,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
135 { 161319, 104858, 161319, 104858, 104858, 67109, 104858, 67109, 161319, 104858, 161319, 104858, 104858, 67109, 104858, 67109,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
136 { 149797, 93207, 149797, 93207, 93207, 58356, 93207, 58356, 149797, 93207, 149797, 93207, 93207, 58356, 93207, 58356,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
137 { 131072, 83886, 131072, 83886, 83886, 53687, 83886, 53687, 131072, 83886, 131072, 83886, 83886, 53687, 83886, 53687,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
138 { 116508, 72944, 116508, 72944, 72944, 46282, 72944, 46282, 116508, 72944, 116508, 72944, 72944, 46282, 72944, 46282,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
139 { 104858, 64528, 104858, 64528, 64528, 41943, 64528, 41943, 104858, 64528, 104858, 64528, 64528, 41943, 64528, 41943,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
140 { 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283, 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
141 { 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554, 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
142 { 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178, 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
143 { 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844, 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
144 { 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141, 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
145 { 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972, 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
146 { 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641, 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
147 { 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777, 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
148 { 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589, 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
149 { 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422, 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
150 { 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570, 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
151 { 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486, 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
152 { 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321, 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
153 { 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389, 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
154 { 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294, 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
155 { 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711, 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
156 { 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785, 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
157 { 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243, 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
158 { 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660, 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
159 { 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194, 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
160 { 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647, 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
161 { 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355, 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
162 { 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893, 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
163 { 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621, 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
164 { 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330, 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
165 { 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097, 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
166 { 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824, 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
167 { 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678, 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
168 { 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446, 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
169 { 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311, 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
170 { 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165, 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
171 { 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049, 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
172 { 2341, 1456, 2341, 1456, 1456, 912, 1456, 912, 2341, 1456, 2341, 1456, 1456, 912, 1456, 912,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
173 { 2048, 1311, 2048, 1311, 1311, 839, 1311, 839, 2048, 1311, 2048, 1311, 1311, 839, 1311, 839,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
174 { 1820, 1140, 1820, 1140, 1140, 723, 1140, 723, 1820, 1140, 1820, 1140, 1140, 723, 1140, 723,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
175 { 1638, 1008, 1638, 1008, 1008, 655, 1008, 655, 1638, 1008, 1638, 1008, 1008, 655, 1008, 655,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
176 { 1489, 936, 1489, 936, 936, 583, 936, 583, 1489, 936, 1489, 936, 936, 583, 936, 583,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
177 { 1260, 819, 1260, 819, 819, 524, 819, 524, 1260, 819, 1260, 819, 819, 524, 819, 524,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
178 { 1170, 728, 1170, 728, 728, 456, 728, 456, 1170, 728, 1170, 728, 728, 456, 728, 456,},
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
179 };
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
180
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
181 //FIXME need to check that this does not overflow signed 32 bit for low qp, I am not sure, it's very close
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
182 //FIXME check that gcc inlines this (and optimizes intra & separate_dc stuff away)
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
183 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale,
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
184 int intra, int separate_dc)
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
185 {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
186 int i;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
187 const int * const quant_3Btable = quant_coeff[qscale];
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
188 const int bias = intra ? (1 << QUANT_SHIFT) / 3 : (1 << QUANT_SHIFT) / 6;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
189 const unsigned int threshold1 = (1 << QUANT_SHIFT) - bias - 1;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
190 const unsigned int threshold2 = (threshold1 << 1);
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
191 int last_non_zero;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
192
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
193 if (separate_dc) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
194 if (qscale <= 18) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
195 //avoid overflows
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
196 const int dc_bias = intra ? (1 << (QUANT_SHIFT - 2)) / 3 : (1 << (QUANT_SHIFT - 2)) / 6;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
197 const unsigned int dc_threshold1 = (1 << (QUANT_SHIFT - 2)) - dc_bias - 1;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
198 const unsigned int dc_threshold2 = (dc_threshold1 << 1);
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
199
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
200 int level = block[0]*quant_coeff[qscale+18][0];
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
201 if (((unsigned)(level + dc_threshold1)) > dc_threshold2) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
202 if (level > 0) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
203 level = (dc_bias + level) >> (QUANT_SHIFT - 2);
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
204 block[0] = level;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
205 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
206 level = (dc_bias - level) >> (QUANT_SHIFT - 2);
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
207 block[0] = -level;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
208 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
209 // last_non_zero = i;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
210 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
211 block[0] = 0;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
212 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
213 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
214 const int dc_bias = intra ? (1 << (QUANT_SHIFT + 1)) / 3 : (1 << (QUANT_SHIFT + 1)) / 6;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
215 const unsigned int dc_threshold1 = (1 << (QUANT_SHIFT + 1)) - dc_bias - 1;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
216 const unsigned int dc_threshold2 = (dc_threshold1 << 1);
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
217
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
218 int level = block[0]*quant_table[0];
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
219 if (((unsigned)(level + dc_threshold1)) > dc_threshold2) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
220 if (level > 0) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
221 level = (dc_bias + level) >> (QUANT_SHIFT + 1);
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
222 block[0] = level;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
223 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
224 level = (dc_bias - level) >> (QUANT_SHIFT + 1);
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
225 block[0] = -level;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
226 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
227 // last_non_zero = i;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
228 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
229 block[0] = 0;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
230 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
231 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
232 last_non_zero = 0;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
233 i = 1;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
234 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
235 last_non_zero = -1;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
236 i = 0;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
237 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
238
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
239 for (; i < 16; i++) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
240 const int j = scantable[i];
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
241 int level = block[j]*quant_table[j];
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
242
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
243 // if ( bias+level >= (1 << (QMAT_SHIFT - 3))
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
244 // || bias-level >= (1 << (QMAT_SHIFT - 3))) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
245 if (((unsigned)(level + threshold1)) > threshold2) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
246 if (level > 0) {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
247 level = (bias + level) >> QUANT_SHIFT;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
248 block[j] = level;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
249 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
250 level = (bias - level) >> QUANT_SHIFT;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
251 block[j] = -level;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
252 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
253 last_non_zero = i;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
254 } else {
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
255 block[j] = 0;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
256 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
257 }
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
258
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
259 return last_non_zero;
018299720403 Move encoder-specific quantize_c and related tables to the H.264 encoder.
diego
parents: 8189
diff changeset
260 }