annotate svq1enc.c @ 6852:84dc84916bab libavcodec

Simplify eq()
author vitor
date Sat, 24 May 2008 12:33:00 +0000
parents e1302edb0f69
children e943e1409077
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
1 /*
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
2 * SVQ1 Encoder
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
3 * Copyright (C) 2004 Mike Melanson <melanson@pcisys.net>
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
4 *
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
5 * This file is part of FFmpeg.
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
6 *
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
11 *
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
16 *
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
20 */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
21
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
22 /**
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
23 * @file svq1enc.c
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
24 * Sorenson Vector Quantizer #1 (SVQ1) video codec.
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
25 * For more information of the SVQ1 algorithm, visit:
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
26 * http://www.pcisys.net/~melanson/codecs/
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
27 */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
28
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
29
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
30 #include "avcodec.h"
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
31 #include "dsputil.h"
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
32 #include "mpegvideo.h"
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
33
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
34 #include "svq1.h"
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
35 #include "svq1enc_cb.h"
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
36
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
37 #undef NDEBUG
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
38 #include <assert.h>
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
39
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
40
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
41 typedef struct SVQ1Context {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
42 MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
43 AVCodecContext *avctx;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
44 DSPContext dsp;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
45 AVFrame picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
46 AVFrame current_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
47 AVFrame last_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
48 PutBitContext pb;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
49 GetBitContext gb;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
50
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
51 PutBitContext reorder_pb[6]; //why ooh why this sick breadth first order, everything is slower and more complex
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
52
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
53 int frame_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
54 int frame_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
55
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
56 /* Y plane block dimensions */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
57 int y_block_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
58 int y_block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
59
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
60 /* U & V plane (C planes) block dimensions */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
61 int c_block_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
62 int c_block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
63
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
64 uint16_t *mb_type;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
65 uint32_t *dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
66 int16_t (*motion_val8[3])[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
67 int16_t (*motion_val16[3])[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
68
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
69 int64_t rd_total;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
70 } SVQ1Context;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
71
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
72 static void svq1_write_header(SVQ1Context *s, int frame_type)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
73 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
74 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
75
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
76 /* frame code */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
77 put_bits(&s->pb, 22, 0x20);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
78
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
79 /* temporal reference (sure hope this is a "don't care") */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
80 put_bits(&s->pb, 8, 0x00);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
81
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
82 /* frame type */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
83 put_bits(&s->pb, 2, frame_type - 1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
84
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
85 if (frame_type == FF_I_TYPE) {
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
86
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
87 /* no checksum since frame code is 0x20 */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
88
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
89 /* no embedded string either */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
90
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
91 /* output 5 unknown bits (2 + 2 + 1) */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
92 put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
93
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
94 for (i = 0; i < 7; i++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
95 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
96 if ((ff_svq1_frame_size_table[i].width == s->frame_width) &&
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
97 (ff_svq1_frame_size_table[i].height == s->frame_height))
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
98 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
99 put_bits(&s->pb, 3, i);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
100 break;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
101 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
102 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
103
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
104 if (i == 7)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
105 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
106 put_bits(&s->pb, 3, 7);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
107 put_bits(&s->pb, 12, s->frame_width);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
108 put_bits(&s->pb, 12, s->frame_height);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
109 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
110 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
111
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
112 /* no checksum or extra data (next 2 bits get 0) */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
113 put_bits(&s->pb, 2, 0);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
114 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
115
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
116
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
117 #define QUALITY_THRESHOLD 100
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
118 #define THRESHOLD_MULTIPLIER 0.6
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
119
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
120 #if defined(HAVE_ALTIVEC)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
121 #undef vector
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
122 #endif
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
123
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
124 static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
125 int count, y, x, i, j, split, best_mean, best_score, best_count;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
126 int best_vector[6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
127 int block_sum[7]= {0, 0, 0, 0, 0, 0};
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
128 int w= 2<<((level+2)>>1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
129 int h= 2<<((level+1)>>1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
130 int size=w*h;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
131 int16_t block[7][256];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
132 const int8_t *codebook_sum, *codebook;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
133 const uint16_t (*mean_vlc)[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
134 const uint8_t (*multistage_vlc)[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
135
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
136 best_score=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
137 //FIXME optimize, this doenst need to be done multiple times
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
138 if(intra){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
139 codebook_sum= svq1_intra_codebook_sum[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
140 codebook= ff_svq1_intra_codebooks[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
141 mean_vlc= ff_svq1_intra_mean_vlc;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
142 multistage_vlc= ff_svq1_intra_multistage_vlc[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
143 for(y=0; y<h; y++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
144 for(x=0; x<w; x++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
145 int v= src[x + y*stride];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
146 block[0][x + w*y]= v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
147 best_score += v*v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
148 block_sum[0] += v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
149 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
150 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
151 }else{
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
152 codebook_sum= svq1_inter_codebook_sum[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
153 codebook= ff_svq1_inter_codebooks[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
154 mean_vlc= ff_svq1_inter_mean_vlc + 256;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
155 multistage_vlc= ff_svq1_inter_multistage_vlc[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
156 for(y=0; y<h; y++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
157 for(x=0; x<w; x++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
158 int v= src[x + y*stride] - ref[x + y*stride];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
159 block[0][x + w*y]= v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
160 best_score += v*v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
161 block_sum[0] += v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
162 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
163 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
164 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
165
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
166 best_count=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
167 best_score -= ((block_sum[0]*block_sum[0])>>(level+3));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
168 best_mean= (block_sum[0] + (size>>1)) >> (level+3);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
169
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
170 if(level<4){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
171 for(count=1; count<7; count++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
172 int best_vector_score= INT_MAX;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
173 int best_vector_sum=-999, best_vector_mean=-999;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
174 const int stage= count-1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
175 const int8_t *vector;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
176
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
177 for(i=0; i<16; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
178 int sum= codebook_sum[stage*16 + i];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
179 int sqr, diff, score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
180
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
181 vector = codebook + stage*size*16 + i*size;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
182 sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
183 diff= block_sum[stage] - sum;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
184 score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
185 if(score < best_vector_score){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
186 int mean= (diff + (size>>1)) >> (level+3);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
187 assert(mean >-300 && mean<300);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
188 mean= av_clip(mean, intra?0:-256, 255);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
189 best_vector_score= score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
190 best_vector[stage]= i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
191 best_vector_sum= sum;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
192 best_vector_mean= mean;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
193 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
194 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
195 assert(best_vector_mean != -999);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
196 vector= codebook + stage*size*16 + best_vector[stage]*size;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
197 for(j=0; j<size; j++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
198 block[stage+1][j] = block[stage][j] - vector[j];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
199 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
200 block_sum[stage+1]= block_sum[stage] - best_vector_sum;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
201 best_vector_score +=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
202 lambda*(+ 1 + 4*count
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
203 + multistage_vlc[1+count][1]
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
204 + mean_vlc[best_vector_mean][1]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
205
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
206 if(best_vector_score < best_score){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
207 best_score= best_vector_score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
208 best_count= count;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
209 best_mean= best_vector_mean;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
210 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
211 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
212 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
213
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
214 split=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
215 if(best_score > threshold && level){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
216 int score=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
217 int offset= (level&1) ? stride*h/2 : w/2;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
218 PutBitContext backup[6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
219
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
220 for(i=level-1; i>=0; i--){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
221 backup[i]= s->reorder_pb[i];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
222 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
223 score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
224 score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
225 score += lambda;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
226
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
227 if(score < best_score){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
228 best_score= score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
229 split=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
230 }else{
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
231 for(i=level-1; i>=0; i--){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
232 s->reorder_pb[i]= backup[i];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
233 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
234 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
235 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
236 if (level > 0)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
237 put_bits(&s->reorder_pb[level], 1, split);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
238
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
239 if(!split){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
240 assert((best_mean >= 0 && best_mean<256) || !intra);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
241 assert(best_mean >= -256 && best_mean<256);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
242 assert(best_count >=0 && best_count<7);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
243 assert(level<4 || best_count==0);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
244
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
245 /* output the encoding */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
246 put_bits(&s->reorder_pb[level],
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
247 multistage_vlc[1 + best_count][1],
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
248 multistage_vlc[1 + best_count][0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
249 put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1],
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
250 mean_vlc[best_mean][0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
251
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
252 for (i = 0; i < best_count; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
253 assert(best_vector[i]>=0 && best_vector[i]<16);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
254 put_bits(&s->reorder_pb[level], 4, best_vector[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
255 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
256
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
257 for(y=0; y<h; y++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
258 for(x=0; x<w; x++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
259 decoded[x + y*stride]= src[x + y*stride] - block[best_count][x + w*y] + best_mean;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
260 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
261 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
262 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
263
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
264 return best_score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
265 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
266
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
267
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
268 static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane, unsigned char *ref_plane, unsigned char *decoded_plane,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
269 int width, int height, int src_stride, int stride)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
270 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
271 int x, y;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
272 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
273 int block_width, block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
274 int level;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
275 int threshold[6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
276 const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
277
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
278 /* figure out the acceptable level thresholds in advance */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
279 threshold[5] = QUALITY_THRESHOLD;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
280 for (level = 4; level >= 0; level--)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
281 threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
282
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
283 block_width = (width + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
284 block_height = (height + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
285
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
286 if(s->picture.pict_type == FF_P_TYPE){
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
287 s->m.avctx= s->avctx;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
288 s->m.current_picture_ptr= &s->m.current_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
289 s->m.last_picture_ptr = &s->m.last_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
290 s->m.last_picture.data[0]= ref_plane;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
291 s->m.linesize=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
292 s->m.last_picture.linesize[0]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
293 s->m.new_picture.linesize[0]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
294 s->m.current_picture.linesize[0]= stride;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
295 s->m.width= width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
296 s->m.height= height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
297 s->m.mb_width= block_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
298 s->m.mb_height= block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
299 s->m.mb_stride= s->m.mb_width+1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
300 s->m.b8_stride= 2*s->m.mb_width+1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
301 s->m.f_code=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
302 s->m.pict_type= s->picture.pict_type;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
303 s->m.me_method= s->avctx->me_method;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
304 s->m.me.scene_change_score=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
305 s->m.flags= s->avctx->flags;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
306 // s->m.out_format = FMT_H263;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
307 // s->m.unrestricted_mv= 1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
308
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
309 s->m.lambda= s->picture.quality;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
310 s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
311 s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
312
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
313 if(!s->motion_val8[plane]){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
314 s->motion_val8 [plane]= av_mallocz((s->m.b8_stride*block_height*2 + 2)*2*sizeof(int16_t));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
315 s->motion_val16[plane]= av_mallocz((s->m.mb_stride*(block_height + 2) + 1)*2*sizeof(int16_t));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
316 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
317
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
318 s->m.mb_type= s->mb_type;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
319
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
320 //dummies, to avoid segfaults
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
321 s->m.current_picture.mb_mean= (uint8_t *)s->dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
322 s->m.current_picture.mb_var= (uint16_t*)s->dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
323 s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
324 s->m.current_picture.mb_type= s->dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
325
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
326 s->m.current_picture.motion_val[0]= s->motion_val8[plane] + 2;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
327 s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
328 s->m.dsp= s->dsp; //move
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
329 ff_init_me(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
330
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
331 s->m.me.dia_size= s->avctx->dia_size;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
332 s->m.first_slice_line=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
333 for (y = 0; y < block_height; y++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
334 uint8_t src[stride*16];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
335
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
336 s->m.new_picture.data[0]= src - y*16*stride; //ugly
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
337 s->m.mb_y= y;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
338
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
339 for(i=0; i<16 && i + 16*y<height; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
340 memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
341 for(x=width; x<16*block_width; x++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
342 src[i*stride+x]= src[i*stride+x-1];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
343 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
344 for(; i<16 && i + 16*y<16*block_height; i++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
345 memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
346
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
347 for (x = 0; x < block_width; x++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
348 s->m.mb_x= x;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
349 ff_init_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
350 ff_update_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
351
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
352 ff_estimate_p_frame_motion(&s->m, x, y);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
353 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
354 s->m.first_slice_line=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
355 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
356
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
357 ff_fix_long_p_mvs(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
358 ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
359 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
360
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
361 s->m.first_slice_line=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
362 for (y = 0; y < block_height; y++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
363 uint8_t src[stride*16];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
364
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
365 for(i=0; i<16 && i + 16*y<height; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
366 memcpy(&src[i*stride], &src_plane[(i+16*y)*src_stride], width);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
367 for(x=width; x<16*block_width; x++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
368 src[i*stride+x]= src[i*stride+x-1];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
369 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
370 for(; i<16 && i + 16*y<16*block_height; i++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
371 memcpy(&src[i*stride], &src[(i-1)*stride], 16*block_width);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
372
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
373 s->m.mb_y= y;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
374 for (x = 0; x < block_width; x++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
375 uint8_t reorder_buffer[3][6][7*32];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
376 int count[3][6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
377 int offset = y * 16 * stride + x * 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
378 uint8_t *decoded= decoded_plane + offset;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
379 uint8_t *ref= ref_plane + offset;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
380 int score[4]={0,0,0,0}, best;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
381 uint8_t temp[16*stride];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
382
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
383 if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3000){ //FIXME check size
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
384 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
385 return -1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
386 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
387
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
388 s->m.mb_x= x;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
389 ff_init_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
390 ff_update_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
391
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
392 if(s->picture.pict_type == FF_I_TYPE || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
393 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
394 init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
395 }
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
396 if(s->picture.pict_type == FF_P_TYPE){
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
397 const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
398 put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
399 score[0]= vlc[1]*lambda;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
400 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
401 score[0]+= encode_block(s, src+16*x, NULL, temp, stride, 5, 64, lambda, 1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
402 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
403 count[0][i]= put_bits_count(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
404 flush_put_bits(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
405 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
406 }else
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
407 score[0]= INT_MAX;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
408
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
409 best=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
410
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
411 if(s->picture.pict_type == FF_P_TYPE){
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
412 const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
413 int mx, my, pred_x, pred_y, dxy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
414 int16_t *motion_ptr;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
415
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
416 motion_ptr= h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
417 if(s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTER){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
418 for(i=0; i<6; i++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
419 init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], 7*32);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
420
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
421 put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
422
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
423 s->m.pb= s->reorder_pb[5];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
424 mx= motion_ptr[0];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
425 my= motion_ptr[1];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
426 assert(mx>=-32 && mx<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
427 assert(my>=-32 && my<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
428 assert(pred_x>=-32 && pred_x<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
429 assert(pred_y>=-32 && pred_y<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
430 ff_h263_encode_motion(&s->m, mx - pred_x, 1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
431 ff_h263_encode_motion(&s->m, my - pred_y, 1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
432 s->reorder_pb[5]= s->m.pb;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
433 score[1] += lambda*put_bits_count(&s->reorder_pb[5]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
434
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
435 dxy= (mx&1) + 2*(my&1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
436
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
437 s->dsp.put_pixels_tab[0][dxy](temp+16, ref + (mx>>1) + stride*(my>>1), stride, 16);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
438
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
439 score[1]+= encode_block(s, src+16*x, temp+16, decoded, stride, 5, 64, lambda, 0);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
440 best= score[1] <= score[0];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
441
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
442 vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
443 score[2]= s->dsp.sse[0](NULL, src+16*x, ref, stride, 16);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
444 score[2]+= vlc[1]*lambda;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
445 if(score[2] < score[best] && mx==0 && my==0){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
446 best=2;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
447 s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
448 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
449 count[2][i]=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
450 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
451 put_bits(&s->pb, vlc[1], vlc[0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
452 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
453 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
454
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
455 if(best==1){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
456 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
457 count[1][i]= put_bits_count(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
458 flush_put_bits(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
459 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
460 }else{
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
461 motion_ptr[0 ] = motion_ptr[1 ]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
462 motion_ptr[2 ] = motion_ptr[3 ]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
463 motion_ptr[0+2*s->m.b8_stride] = motion_ptr[1+2*s->m.b8_stride]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
464 motion_ptr[2+2*s->m.b8_stride] = motion_ptr[3+2*s->m.b8_stride]=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
465 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
466 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
467
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
468 s->rd_total += score[best];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
469
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
470 for(i=5; i>=0; i--){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
471 ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
472 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
473 if(best==0){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
474 s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
475 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
476 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
477 s->m.first_slice_line=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
478 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
479 return 0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
480 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
481
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6481
diff changeset
482 static av_cold int svq1_encode_init(AVCodecContext *avctx)
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
483 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
484 SVQ1Context * const s = avctx->priv_data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
485
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
486 dsputil_init(&s->dsp, avctx);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
487 avctx->coded_frame= (AVFrame*)&s->picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
488
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
489 s->frame_width = avctx->width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
490 s->frame_height = avctx->height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
491
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
492 s->y_block_width = (s->frame_width + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
493 s->y_block_height = (s->frame_height + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
494
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
495 s->c_block_width = (s->frame_width / 4 + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
496 s->c_block_height = (s->frame_height / 4 + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
497
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
498 s->avctx= avctx;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
499 s->m.avctx= avctx;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
500 s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
501 s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
502 s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
503 s->mb_type = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int16_t));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
504 s->dummy = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int32_t));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
505 h263_encode_init(&s->m); //mv_penalty
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
506
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
507 return 0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
508 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
509
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
510 static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
511 int buf_size, void *data)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
512 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
513 SVQ1Context * const s = avctx->priv_data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
514 AVFrame *pict = data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
515 AVFrame * const p= (AVFrame*)&s->picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
516 AVFrame temp;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
517 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
518
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
519 if(avctx->pix_fmt != PIX_FMT_YUV410P){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
520 av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
521 return -1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
522 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
523
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
524 if(!s->current_picture.data[0]){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
525 avctx->get_buffer(avctx, &s->current_picture);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
526 avctx->get_buffer(avctx, &s->last_picture);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
527 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
528
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
529 temp= s->current_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
530 s->current_picture= s->last_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
531 s->last_picture= temp;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
532
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
533 init_put_bits(&s->pb, buf, buf_size);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
534
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
535 *p = *pict;
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
536 p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? FF_P_TYPE : FF_I_TYPE;
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
537 p->key_frame = p->pict_type == FF_I_TYPE;
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
538
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
539 svq1_write_header(s, p->pict_type);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
540 for(i=0; i<3; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
541 if(svq1_encode_plane(s, i,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
542 s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i],
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
543 s->frame_width / (i?4:1), s->frame_height / (i?4:1),
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
544 s->picture.linesize[i], s->current_picture.linesize[i]) < 0)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
545 return -1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
546 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
547
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
548 // align_put_bits(&s->pb);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
549 while(put_bits_count(&s->pb) & 31)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
550 put_bits(&s->pb, 1, 0);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
551
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
552 flush_put_bits(&s->pb);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
553
6750
c93570aeb3eb Remove unnecessary parentheses from return calls.
diego
parents: 6712
diff changeset
554 return put_bits_count(&s->pb) / 8;
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
555 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
556
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6481
diff changeset
557 static av_cold int svq1_encode_end(AVCodecContext *avctx)
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
558 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
559 SVQ1Context * const s = avctx->priv_data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
560 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
561
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
562 av_log(avctx, AV_LOG_DEBUG, "RD: %f\n", s->rd_total/(double)(avctx->width*avctx->height*avctx->frame_number));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
563
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
564 av_freep(&s->m.me.scratchpad);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
565 av_freep(&s->m.me.map);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
566 av_freep(&s->m.me.score_map);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
567 av_freep(&s->mb_type);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
568 av_freep(&s->dummy);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
569
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
570 for(i=0; i<3; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
571 av_freep(&s->motion_val8[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
572 av_freep(&s->motion_val16[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
573 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
574
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
575 return 0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
576 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
577
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
578
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
579 AVCodec svq1_encoder = {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
580 "svq1",
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
581 CODEC_TYPE_VIDEO,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
582 CODEC_ID_SVQ1,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
583 sizeof(SVQ1Context),
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
584 svq1_encode_init,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
585 svq1_encode_frame,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
586 svq1_encode_end,
6788
e1302edb0f69 Replace some occurrences of -1 with PIX_FMT_NONE.
cehoyos
parents: 6750
diff changeset
587 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE},
6712
5b3acf9fd50a Add long names to AVCodec declarations.
diego
parents: 6517
diff changeset
588 .long_name= "Sorenson Vector Quantizer 1",
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
589 };