annotate svq1enc.c @ 10843:f6afc7837f83 libavcodec

Add missing internal.h to files calling ff_match_2uint16(). Fixes warnings: libavcodec/mpegvideo_enc.c:574: warning: implicit declaration of function 'ff_match_2uint16' libavcodec/ituh263enc.c:143: warning: implicit declaration of function 'ff_match_2uint16' libavcodec/svq1enc.c:97: warning: implicit declaration of function 'ff_match_2uint16'
author astrange
date Mon, 11 Jan 2010 04:57:04 +0000
parents f20726a6d538
children 423410fc29b1
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 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8590
diff changeset
23 * @file libavcodec/svq1enc.c
5233
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"
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10441
diff changeset
33 #include "h263.h"
10843
f6afc7837f83 Add missing internal.h to files calling ff_match_2uint16().
astrange
parents: 10832
diff changeset
34 #include "internal.h"
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
35
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
36 #include "svq1.h"
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
37 #include "svq1enc_cb.h"
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
38
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
39 #undef NDEBUG
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
40 #include <assert.h>
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
41
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
42
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
43 typedef struct SVQ1Context {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
44 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
45 AVCodecContext *avctx;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
46 DSPContext dsp;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
47 AVFrame picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
48 AVFrame current_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
49 AVFrame last_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
50 PutBitContext pb;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
51 GetBitContext gb;
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 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
54
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
55 int frame_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
56 int frame_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
57
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
58 /* Y plane block dimensions */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
59 int y_block_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
60 int y_block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
61
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
62 /* U & V plane (C planes) block dimensions */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
63 int c_block_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
64 int c_block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
65
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
66 uint16_t *mb_type;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
67 uint32_t *dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
68 int16_t (*motion_val8[3])[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
69 int16_t (*motion_val16[3])[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
70
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
71 int64_t rd_total;
8211
b9e82845e7eb svq1enc: move scratch buffer from stack to context to ensure alignment
mru
parents: 7040
diff changeset
72
b9e82845e7eb svq1enc: move scratch buffer from stack to context to ensure alignment
mru
parents: 7040
diff changeset
73 uint8_t *scratchbuf;
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
74 } SVQ1Context;
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 static void svq1_write_header(SVQ1Context *s, int frame_type)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
77 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
78 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
79
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
80 /* frame code */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
81 put_bits(&s->pb, 22, 0x20);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
82
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
83 /* temporal reference (sure hope this is a "don't care") */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
84 put_bits(&s->pb, 8, 0x00);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
85
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
86 /* frame type */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
87 put_bits(&s->pb, 2, frame_type - 1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
88
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
89 if (frame_type == FF_I_TYPE) {
5233
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 /* no checksum since frame code is 0x20 */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
92
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
93 /* no embedded string either */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
94
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
95 /* output 5 unknown bits (2 + 2 + 1) */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
96 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
97
10832
f20726a6d538 Add a function to match a 2 element vector of uint16_t and use it in h263 and svq1
michael
parents: 10828
diff changeset
98 i= ff_match_2uint16(ff_svq1_frame_size_table, FF_ARRAY_ELEMS(ff_svq1_frame_size_table), s->frame_width, s->frame_height);
f20726a6d538 Add a function to match a 2 element vector of uint16_t and use it in h263 and svq1
michael
parents: 10828
diff changeset
99 put_bits(&s->pb, 3, i);
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
100
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
101 if (i == 7)
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 put_bits(&s->pb, 12, s->frame_width);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
104 put_bits(&s->pb, 12, s->frame_height);
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 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
107
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
108 /* no checksum or extra data (next 2 bits get 0) */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
109 put_bits(&s->pb, 2, 0);
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
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
113 #define QUALITY_THRESHOLD 100
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
114 #define THRESHOLD_MULTIPLIER 0.6
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
115
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 8211
diff changeset
116 #if HAVE_ALTIVEC
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
117 #undef vector
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
118 #endif
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 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
121 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
122 int best_vector[6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
123 int block_sum[7]= {0, 0, 0, 0, 0, 0};
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
124 int w= 2<<((level+2)>>1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
125 int h= 2<<((level+1)>>1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
126 int size=w*h;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
127 int16_t block[7][256];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
128 const int8_t *codebook_sum, *codebook;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
129 const uint16_t (*mean_vlc)[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
130 const uint8_t (*multistage_vlc)[2];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
131
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
132 best_score=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
133 //FIXME optimize, this doenst need to be done multiple times
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
134 if(intra){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
135 codebook_sum= svq1_intra_codebook_sum[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
136 codebook= ff_svq1_intra_codebooks[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
137 mean_vlc= ff_svq1_intra_mean_vlc;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
138 multistage_vlc= ff_svq1_intra_multistage_vlc[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
139 for(y=0; y<h; y++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
140 for(x=0; x<w; x++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
141 int v= src[x + y*stride];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
142 block[0][x + w*y]= v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
143 best_score += v*v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
144 block_sum[0] += v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
145 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
146 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
147 }else{
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
148 codebook_sum= svq1_inter_codebook_sum[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
149 codebook= ff_svq1_inter_codebooks[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
150 mean_vlc= ff_svq1_inter_mean_vlc + 256;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
151 multistage_vlc= ff_svq1_inter_multistage_vlc[level];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
152 for(y=0; y<h; y++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
153 for(x=0; x<w; x++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
154 int v= src[x + y*stride] - ref[x + y*stride];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
155 block[0][x + w*y]= v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
156 best_score += v*v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
157 block_sum[0] += v;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
158 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
159 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
160 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
161
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
162 best_count=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
163 best_score -= ((block_sum[0]*block_sum[0])>>(level+3));
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
164 best_mean= (block_sum[0] + (size>>1)) >> (level+3);
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 if(level<4){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
167 for(count=1; count<7; count++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
168 int best_vector_score= INT_MAX;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
169 int best_vector_sum=-999, best_vector_mean=-999;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
170 const int stage= count-1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
171 const int8_t *vector;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
172
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
173 for(i=0; i<16; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
174 int sum= codebook_sum[stage*16 + i];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
175 int sqr, diff, score;
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 vector = codebook + stage*size*16 + i*size;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
178 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
179 diff= block_sum[stage] - sum;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
180 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
181 if(score < best_vector_score){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
182 int mean= (diff + (size>>1)) >> (level+3);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
183 assert(mean >-300 && mean<300);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
184 mean= av_clip(mean, intra?0:-256, 255);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
185 best_vector_score= score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
186 best_vector[stage]= i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
187 best_vector_sum= sum;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
188 best_vector_mean= mean;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
189 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
190 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
191 assert(best_vector_mean != -999);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
192 vector= codebook + stage*size*16 + best_vector[stage]*size;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
193 for(j=0; j<size; j++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
194 block[stage+1][j] = block[stage][j] - vector[j];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
195 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
196 block_sum[stage+1]= block_sum[stage] - best_vector_sum;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
197 best_vector_score +=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
198 lambda*(+ 1 + 4*count
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
199 + multistage_vlc[1+count][1]
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
200 + mean_vlc[best_vector_mean][1]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
201
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
202 if(best_vector_score < best_score){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
203 best_score= best_vector_score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
204 best_count= count;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
205 best_mean= best_vector_mean;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
206 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
207 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
208 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
209
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
210 split=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
211 if(best_score > threshold && level){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
212 int score=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
213 int offset= (level&1) ? stride*h/2 : w/2;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
214 PutBitContext backup[6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
215
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
216 for(i=level-1; i>=0; i--){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
217 backup[i]= s->reorder_pb[i];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
218 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
219 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
220 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
221 score += lambda;
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 if(score < best_score){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
224 best_score= score;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
225 split=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
226 }else{
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
227 for(i=level-1; i>=0; i--){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
228 s->reorder_pb[i]= backup[i];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
229 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
230 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
231 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
232 if (level > 0)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
233 put_bits(&s->reorder_pb[level], 1, split);
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 if(!split){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
236 assert((best_mean >= 0 && best_mean<256) || !intra);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
237 assert(best_mean >= -256 && best_mean<256);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
238 assert(best_count >=0 && best_count<7);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
239 assert(level<4 || best_count==0);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
240
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
241 /* output the encoding */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
242 put_bits(&s->reorder_pb[level],
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
243 multistage_vlc[1 + best_count][1],
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
244 multistage_vlc[1 + best_count][0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
245 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
246 mean_vlc[best_mean][0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
247
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
248 for (i = 0; i < best_count; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
249 assert(best_vector[i]>=0 && best_vector[i]<16);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
250 put_bits(&s->reorder_pb[level], 4, best_vector[i]);
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
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
253 for(y=0; y<h; y++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
254 for(x=0; x<w; x++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
255 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
256 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
257 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
258 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
259
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
260 return best_score;
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 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
265 int width, int height, int src_stride, int stride)
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 int x, y;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
268 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
269 int block_width, block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
270 int level;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
271 int threshold[6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
272 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
273
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
274 /* figure out the acceptable level thresholds in advance */
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
275 threshold[5] = QUALITY_THRESHOLD;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
276 for (level = 4; level >= 0; level--)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
277 threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
278
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
279 block_width = (width + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
280 block_height = (height + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
281
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
282 if(s->picture.pict_type == FF_P_TYPE){
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
283 s->m.avctx= s->avctx;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
284 s->m.current_picture_ptr= &s->m.current_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
285 s->m.last_picture_ptr = &s->m.last_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
286 s->m.last_picture.data[0]= ref_plane;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
287 s->m.linesize=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
288 s->m.last_picture.linesize[0]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
289 s->m.new_picture.linesize[0]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
290 s->m.current_picture.linesize[0]= stride;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
291 s->m.width= width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
292 s->m.height= height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
293 s->m.mb_width= block_width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
294 s->m.mb_height= block_height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
295 s->m.mb_stride= s->m.mb_width+1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
296 s->m.b8_stride= 2*s->m.mb_width+1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
297 s->m.f_code=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
298 s->m.pict_type= s->picture.pict_type;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
299 s->m.me_method= s->avctx->me_method;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
300 s->m.me.scene_change_score=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
301 s->m.flags= s->avctx->flags;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
302 // s->m.out_format = FMT_H263;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
303 // s->m.unrestricted_mv= 1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
304
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
305 s->m.lambda= s->picture.quality;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
306 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
307 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
308
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
309 if(!s->motion_val8[plane]){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
310 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
311 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
312 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
313
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
314 s->m.mb_type= s->mb_type;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
315
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
316 //dummies, to avoid segfaults
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
317 s->m.current_picture.mb_mean= (uint8_t *)s->dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
318 s->m.current_picture.mb_var= (uint16_t*)s->dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
319 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
320 s->m.current_picture.mb_type= s->dummy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
321
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
322 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
323 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
324 s->m.dsp= s->dsp; //move
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
325 ff_init_me(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
326
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
327 s->m.me.dia_size= s->avctx->dia_size;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
328 s->m.first_slice_line=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
329 for (y = 0; y < block_height; y++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
330 uint8_t src[stride*16];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
331
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
332 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
333 s->m.mb_y= y;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
334
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
335 for(i=0; i<16 && i + 16*y<height; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
336 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
337 for(x=width; x<16*block_width; x++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
338 src[i*stride+x]= src[i*stride+x-1];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
339 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
340 for(; i<16 && i + 16*y<16*block_height; i++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
341 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
342
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
343 for (x = 0; x < block_width; x++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
344 s->m.mb_x= x;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
345 ff_init_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
346 ff_update_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
347
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
348 ff_estimate_p_frame_motion(&s->m, x, y);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
349 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
350 s->m.first_slice_line=0;
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
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
353 ff_fix_long_p_mvs(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
354 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
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 s->m.first_slice_line=1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
358 for (y = 0; y < block_height; y++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
359 uint8_t src[stride*16];
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 for(i=0; i<16 && i + 16*y<height; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
362 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
363 for(x=width; x<16*block_width; x++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
364 src[i*stride+x]= src[i*stride+x-1];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
365 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
366 for(; i<16 && i + 16*y<16*block_height; i++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
367 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
368
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
369 s->m.mb_y= y;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
370 for (x = 0; x < block_width; x++) {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
371 uint8_t reorder_buffer[3][6][7*32];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
372 int count[3][6];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
373 int offset = y * 16 * stride + x * 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
374 uint8_t *decoded= decoded_plane + offset;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
375 uint8_t *ref= ref_plane + offset;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
376 int score[4]={0,0,0,0}, best;
8211
b9e82845e7eb svq1enc: move scratch buffer from stack to context to ensure alignment
mru
parents: 7040
diff changeset
377 uint8_t *temp = s->scratchbuf;
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
378
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
379 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
380 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
381 return -1;
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
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
384 s->m.mb_x= x;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
385 ff_init_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
386 ff_update_block_index(&s->m);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
387
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
388 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
389 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
390 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
391 }
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
392 if(s->picture.pict_type == FF_P_TYPE){
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
393 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
394 put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
395 score[0]= vlc[1]*lambda;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
396 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
397 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
398 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
399 count[0][i]= put_bits_count(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
400 flush_put_bits(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
401 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
402 }else
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
403 score[0]= INT_MAX;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
404
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
405 best=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
406
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
407 if(s->picture.pict_type == FF_P_TYPE){
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
408 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
409 int mx, my, pred_x, pred_y, dxy;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
410 int16_t *motion_ptr;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
411
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
412 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
413 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
414 for(i=0; i<6; i++)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
415 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
416
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
417 put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
418
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
419 s->m.pb= s->reorder_pb[5];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
420 mx= motion_ptr[0];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
421 my= motion_ptr[1];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
422 assert(mx>=-32 && mx<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
423 assert(my>=-32 && my<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
424 assert(pred_x>=-32 && pred_x<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
425 assert(pred_y>=-32 && pred_y<=31);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
426 ff_h263_encode_motion(&s->m, mx - pred_x, 1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
427 ff_h263_encode_motion(&s->m, my - pred_y, 1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
428 s->reorder_pb[5]= s->m.pb;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
429 score[1] += lambda*put_bits_count(&s->reorder_pb[5]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
430
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
431 dxy= (mx&1) + 2*(my&1);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
432
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
433 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
434
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
435 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
436 best= score[1] <= score[0];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
437
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
438 vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
439 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
440 score[2]+= vlc[1]*lambda;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
441 if(score[2] < score[best] && mx==0 && my==0){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
442 best=2;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
443 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
444 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
445 count[2][i]=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
446 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
447 put_bits(&s->pb, vlc[1], vlc[0]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
448 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
449 }
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 if(best==1){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
452 for(i=0; i<6; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
453 count[1][i]= put_bits_count(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
454 flush_put_bits(&s->reorder_pb[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
455 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
456 }else{
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
457 motion_ptr[0 ] = motion_ptr[1 ]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
458 motion_ptr[2 ] = motion_ptr[3 ]=
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
459 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
460 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
461 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
462 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
463
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
464 s->rd_total += score[best];
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 for(i=5; i>=0; i--){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
467 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
468 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
469 if(best==0){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
470 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
471 }
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 s->m.first_slice_line=0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
474 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
475 return 0;
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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6481
diff changeset
478 static av_cold int svq1_encode_init(AVCodecContext *avctx)
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
479 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
480 SVQ1Context * const s = avctx->priv_data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
481
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
482 dsputil_init(&s->dsp, avctx);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
483 avctx->coded_frame= (AVFrame*)&s->picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
484
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
485 s->frame_width = avctx->width;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
486 s->frame_height = avctx->height;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
487
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
488 s->y_block_width = (s->frame_width + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
489 s->y_block_height = (s->frame_height + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
490
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
491 s->c_block_width = (s->frame_width / 4 + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
492 s->c_block_height = (s->frame_height / 4 + 15) / 16;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
493
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
494 s->avctx= avctx;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
495 s->m.avctx= avctx;
10042
37485479bb6e fix a crash in SVQ1 with cmp!=sad
lorenm
parents: 8718
diff changeset
496 s->m.me.temp =
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
497 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
498 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
499 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
500 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
501 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
502 h263_encode_init(&s->m); //mv_penalty
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
503
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
504 return 0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
505 }
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 static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
508 int buf_size, void *data)
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 SVQ1Context * const s = avctx->priv_data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
511 AVFrame *pict = data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
512 AVFrame * const p= (AVFrame*)&s->picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
513 AVFrame temp;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
514 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
515
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
516 if(avctx->pix_fmt != PIX_FMT_YUV410P){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
517 av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
518 return -1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
519 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
520
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
521 if(!s->current_picture.data[0]){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
522 avctx->get_buffer(avctx, &s->current_picture);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
523 avctx->get_buffer(avctx, &s->last_picture);
8211
b9e82845e7eb svq1enc: move scratch buffer from stack to context to ensure alignment
mru
parents: 7040
diff changeset
524 s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16);
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
525 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
526
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
527 temp= s->current_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
528 s->current_picture= s->last_picture;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
529 s->last_picture= temp;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
530
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
531 init_put_bits(&s->pb, buf, buf_size);
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 *p = *pict;
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5233
diff changeset
534 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
535 p->key_frame = p->pict_type == FF_I_TYPE;
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
536
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
537 svq1_write_header(s, p->pict_type);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
538 for(i=0; i<3; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
539 if(svq1_encode_plane(s, i,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
540 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
541 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
542 s->picture.linesize[i], s->current_picture.linesize[i]) < 0)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
543 return -1;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
544 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
545
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
546 // align_put_bits(&s->pb);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
547 while(put_bits_count(&s->pb) & 31)
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
548 put_bits(&s->pb, 1, 0);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
549
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
550 flush_put_bits(&s->pb);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
551
6750
c93570aeb3eb Remove unnecessary parentheses from return calls.
diego
parents: 6712
diff changeset
552 return put_bits_count(&s->pb) / 8;
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
553 }
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
554
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6481
diff changeset
555 static av_cold int svq1_encode_end(AVCodecContext *avctx)
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
556 {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
557 SVQ1Context * const s = avctx->priv_data;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
558 int i;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
559
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
560 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
561
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
562 av_freep(&s->m.me.scratchpad);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
563 av_freep(&s->m.me.map);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
564 av_freep(&s->m.me.score_map);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
565 av_freep(&s->mb_type);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
566 av_freep(&s->dummy);
8211
b9e82845e7eb svq1enc: move scratch buffer from stack to context to ensure alignment
mru
parents: 7040
diff changeset
567 av_freep(&s->scratchbuf);
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
568
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
569 for(i=0; i<3; i++){
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
570 av_freep(&s->motion_val8[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
571 av_freep(&s->motion_val16[i]);
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
572 }
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 return 0;
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
575 }
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 AVCodec svq1_encoder = {
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
579 "svq1",
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
580 CODEC_TYPE_VIDEO,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
581 CODEC_ID_SVQ1,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
582 sizeof(SVQ1Context),
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
583 svq1_encode_init,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
584 svq1_encode_frame,
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
585 svq1_encode_end,
10146
38cfe222e1a4 Mark all pix_fmts and supported_framerates compound literals as const.
reimar
parents: 10042
diff changeset
586 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE},
10441
0a6fc654cfb6 Add additional long names for the Sorenson Vector Quantizer 1 decoder
stefano
parents: 10146
diff changeset
587 .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
5233
eca08bfad00f split SVQ1 decoder and encoder in their own files
aurel
parents:
diff changeset
588 };