History

Calculate deblock strength per-MB instead of per-row Gives better cache locality, since the VP8Macroblock structs are still in cache. Inspired by the way x264 does it.

Originally committed as revision 24417 to svn://svn.ffmpeg.org/ffmpeg/trunk

Jason Garrett-Glaser committed 16 years ago

Commit 968570d1 parent d1c58fc1 file · +38 −27Browse files

Unified · Split

libavcodec/vp8.c+38−27
@@ -28,6 +28,11 @@ · 27 unmodified lines
2828 #include "h264pred.h"
2929 #include "rectangle.h"
3030
31+typedef struct {
32+ uint8_t filter_level;
33+ uint8_t inner_limit;
34+} VP8FilterStrength;
35+
3136 typedef struct {
3237 uint8_t segment;
3338 uint8_t skip;
@@ -79,6 +84,7 @@ typedef struct { · 45 unmodified lines
7984
8085 VP8Macroblock *macroblocks;
8186 VP8Macroblock *macroblocks_base;
87+ VP8FilterStrength *filter_strength;
8288 int mb_stride;
8389
8490 uint8_t *intra4x4_pred_mode;
@@ -231,11 +237,12 @@ static int update_dimensions(VP8Context *s, int width, int height) · 146 unmodified lines
231237 s->b4_stride = 4*s->mb_stride;
232238
233239 s->macroblocks_base = av_mallocz(s->mb_stride*(s->mb_height+1)*sizeof(*s->macroblocks));
240+ s->filter_strength = av_mallocz(s->mb_stride*sizeof(*s->filter_strength));
234241 s->intra4x4_pred_mode_base = av_mallocz(s->b4_stride*(4*s->mb_height+1));
235242 s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
236243 s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
237244
238− if (!s->macroblocks_base || !s->intra4x4_pred_mode_base || !s->top_nnz || !s->top_border)
245+ if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_base || !s->top_nnz || !s->top_border)
239246 return AVERROR(ENOMEM);
240247
241248 s->macroblocks = s->macroblocks_base + 1 + s->mb_stride;
@@ -1212,7 +1219,7 @@ static void idct_mb(VP8Context *s, uint8_t *y_dst, uint8_t *u_dst, uint8_t *v_ds · 970 unmodified lines
12121219 }
12131220 }
12141221
1215−static void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, int *level, int *inner, int *hev_thresh)
1222+static void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, VP8FilterStrength *f )
12161223 {
12171224 int interior_limit, filter_level;
12181225
@@ -1247,34 +1254,32 @@ static void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, int *level, in · 28 unmodified lines
12471254 }
12481255 interior_limit = FFMAX(interior_limit, 1);
12491256
1250− *level = filter_level;
1251− *inner = interior_limit;
1252−
1253− if (hev_thresh) {
1254− *hev_thresh = filter_level >= 15;
1255−
1256− if (s->keyframe) {
1257− if (filter_level >= 40)
1258− *hev_thresh = 2;
1259− } else {
1260− if (filter_level >= 40)
1261− *hev_thresh = 3;
1262− else if (filter_level >= 20)
1263− *hev_thresh = 2;
1264− }
1265− }
1257+ f->filter_level = filter_level;
1258+ f->inner_limit = interior_limit;
12661259 }
12671260
1268−static void filter_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, int mb_x, int mb_y)
1261+static void filter_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, VP8FilterStrength *f, int mb_x, int mb_y)
12691262 {
1270− int filter_level, inner_limit, hev_thresh, mbedge_lim, bedge_lim;
1263+ int mbedge_lim, bedge_lim, hev_thresh;
1264+ int filter_level = f->filter_level;
1265+ int inner_limit = f->inner_limit;
12711266
1272− filter_level_for_mb(s, mb, &filter_level, &inner_limit, &hev_thresh);
12731267 if (!filter_level)
12741268 return;
12751269
12761270 mbedge_lim = 2*(filter_level+2) + inner_limit;
12771271 bedge_lim = 2* filter_level + inner_limit;
1272+ hev_thresh = filter_level >= 15;
1273+
1274+ if (s->keyframe) {
1275+ if (filter_level >= 40)
1276+ hev_thresh = 2;
1277+ } else {
1278+ if (filter_level >= 40)
1279+ hev_thresh = 3;
1280+ else if (filter_level >= 20)
1281+ hev_thresh = 2;
1282+ }
12781283
12791284 if (mb_x) {
12801285 s->vp8dsp.vp8_h_loop_filter16y(dst[0], s->linesize,
@@ -1319,11 +1324,12 @@ static void filter_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, int mb_ · 38 unmodified lines
13191324 }
13201325 }
13211326
1322−static void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Macroblock *mb, int mb_x, int mb_y)
1327+static void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Macroblock *mb, VP8FilterStrength *f, int mb_x, int mb_y)
13231328 {
1324− int filter_level, inner_limit, mbedge_lim, bedge_lim;
1329+ int mbedge_lim, bedge_lim;
1330+ int filter_level = f->filter_level;
1331+ int inner_limit = f->inner_limit;
13251332
1326− filter_level_for_mb(s, mb, &filter_level, &inner_limit, NULL);
13271333 if (!filter_level)
13281334 return;
13291335
@@ -1349,6 +1355,7 @@ static void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Macroblock *mb, int · 19 unmodified lines
13491355
13501356 static void filter_mb_row(VP8Context *s, int mb_y)
13511357 {
1358+ VP8FilterStrength *f = s->filter_strength;
13521359 VP8Macroblock *mb = s->macroblocks + mb_y*s->mb_stride;
13531360 uint8_t *dst[3] = {
13541361 s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize,
@@ -1359,7 +1366,7 @@ static void filter_mb_row(VP8Context *s, int mb_y) · 4 unmodified lines
13591366
13601367 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
13611368 backup_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0);
1362− filter_mb(s, dst, mb++, mb_x, mb_y);
1369+ filter_mb(s, dst, mb++, f++, mb_x, mb_y);
13631370 dst[0] += 16;
13641371 dst[1] += 8;
13651372 dst[2] += 8;
@@ -1368,13 +1375,14 @@ static void filter_mb_row(VP8Context *s, int mb_y) · 2 unmodified lines
13681375
13691376 static void filter_mb_row_simple(VP8Context *s, int mb_y)
13701377 {
1371− uint8_t *dst = s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize;
1378+ VP8FilterStrength *f = s->filter_strength;
13721379 VP8Macroblock *mb = s->macroblocks + mb_y*s->mb_stride;
1380+ uint8_t *dst = s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize;
13731381 int mb_x;
13741382
13751383 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
13761384 backup_mb_border(s->top_border[mb_x+1], dst, NULL, NULL, s->linesize, 0, 1);
1377− filter_mb_simple(s, dst, mb++, mb_x, mb_y);
1385+ filter_mb_simple(s, dst, mb++, f++, mb_x, mb_y);
13781386 dst += 16;
13791387 }
13801388 }
@@ -1497,6 +1505,9 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 116 unmodified lines
14971505 }
14981506 }
14991507
1508+ if (s->deblock_filter)
1509+ filter_level_for_mb(s, mb, &s->filter_strength[mb_x]);
1510+
15001511 dst[0] += 16;
15011512 dst[1] += 8;
15021513 dst[2] += 8;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t