summaryrefslogtreecommitdiff
path: root/vp8/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'vp8/encoder')
-rw-r--r--vp8/encoder/bitstream.c8
-rw-r--r--vp8/encoder/encodeframe.c43
-rw-r--r--vp8/encoder/encodemv.c2
-rw-r--r--vp8/encoder/ethreading.c18
-rw-r--r--vp8/encoder/onyx_if.c9
-rw-r--r--vp8/encoder/onyx_int.h4
-rw-r--r--vp8/encoder/rdopt.c41
-rw-r--r--vp8/encoder/rdopt.h2
-rw-r--r--vp8/encoder/temporal_filter.c2
9 files changed, 74 insertions, 55 deletions
diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c
index 412542d10..52ad0d6fa 100644
--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -1654,10 +1654,12 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
{
vp8_start_encode(&cpi->bc2, cx_data + bc->pos);
- if (!cpi->b_multi_threaded)
- pack_tokens(&cpi->bc2, cpi->tok, cpi->tok_count);
- else
+#if CONFIG_MULTITHREAD
+ if (cpi->b_multi_threaded)
pack_mb_row_tokens(cpi, &cpi->bc2);
+ else
+#endif
+ pack_tokens(&cpi->bc2, cpi->tok, cpi->tok_count);
vp8_stop_encode(&cpi->bc2);
oh.first_partition_length_in_bytes = cpi->bc.pos ;
diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c
index f06a4ca88..c871e60a9 100644
--- a/vp8/encoder/encodeframe.c
+++ b/vp8/encoder/encodeframe.c
@@ -800,28 +800,9 @@ void vp8_encode_frame(VP8_COMP *cpi)
struct vpx_usec_timer emr_timer;
vpx_usec_timer_start(&emr_timer);
- if (!cpi->b_multi_threaded)
- {
- // for each macroblock row in image
- for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
- {
-
- vp8_zero(cm->left_context)
-
- encode_mb_row(cpi, cm, mb_row, x, xd, &tp, segment_counts, &totalrate);
-
- // adjust to the next row of mbs
- x->src.y_buffer += 16 * x->src.y_stride - 16 * cm->mb_cols;
- x->src.u_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
- x->src.v_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
- }
-
- cpi->tok_count = tp - cpi->tok;
-
- }
- else
- {
#if CONFIG_MULTITHREAD
+ if (cpi->b_multi_threaded)
+ {
int i;
vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei, 1, cpi->encoding_thread_count);
@@ -886,7 +867,25 @@ void vp8_encode_frame(VP8_COMP *cpi)
x->activity_sum += cpi->mb_row_ei[i].mb.activity_sum;
}
+ }
+ else
#endif
+ {
+ // for each macroblock row in image
+ for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
+ {
+
+ vp8_zero(cm->left_context)
+
+ encode_mb_row(cpi, cm, mb_row, x, xd, &tp, segment_counts, &totalrate);
+
+ // adjust to the next row of mbs
+ x->src.y_buffer += 16 * x->src.y_stride - 16 * cm->mb_cols;
+ x->src.u_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
+ x->src.v_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
+ }
+
+ cpi->tok_count = tp - cpi->tok;
}
@@ -1166,7 +1165,7 @@ int vp8cx_encode_intra_macro_block(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
Error16x16 = vp8_rd_pick_intra16x16mby_mode(cpi, x, &rate16x16, &rate16x16_tokenonly, &dist16x16);
- Error4x4 = vp8_rd_pick_intra4x4mby_modes(cpi, x, &rate4x4, &rate4x4_tokenonly, &dist4x4);
+ Error4x4 = vp8_rd_pick_intra4x4mby_modes(cpi, x, &rate4x4, &rate4x4_tokenonly, &dist4x4, Error16x16);
rate += (Error4x4 < Error16x16) ? rate4x4 : rate16x16;
}
diff --git a/vp8/encoder/encodemv.c b/vp8/encoder/encodemv.c
index cce753013..4cb4c6e55 100644
--- a/vp8/encoder/encodemv.c
+++ b/vp8/encoder/encodemv.c
@@ -128,7 +128,7 @@ static unsigned int cost_mvcomponent(const int v, const struct mv_context *mvc)
while (--i > 3);
- if (x & 240)
+ if (x & 0xFFF0)
cost += vp8_cost_bit(p [MVPbits + 3], (x >> 3) & 1);
}
diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c
index 8da93a67c..4ce306ff0 100644
--- a/vp8/encoder/ethreading.c
+++ b/vp8/encoder/ethreading.c
@@ -13,6 +13,8 @@
#include "common.h"
#include "extend.h"
+#if CONFIG_MULTITHREAD
+
extern int vp8cx_encode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
TOKENEXTRA **t, int recon_yoffset,
int recon_uvoffset);
@@ -25,7 +27,6 @@ extern void vp8_setup_block_ptrs(MACROBLOCK *x);
static
THREAD_FUNCTION thread_encoding_proc(void *p_data)
{
-#if CONFIG_MULTITHREAD
int ithread = ((ENCODETHREAD_DATA *)p_data)->ithread;
VP8_COMP *cpi = (VP8_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr1);
MB_ROW_COMP *mbri = (MB_ROW_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr2);
@@ -247,10 +248,6 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
}
}
-#else
- (void) p_data;
-#endif
-
//printf("exit thread %d\n", ithread);
return 0;
}
@@ -436,10 +433,6 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
cpi->processor_core_count = 32; //vp8_get_proc_core_count();
- CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cpi->common.mb_rows));
-
-#if CONFIG_MULTITHREAD
-
if (cpi->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1)
{
int ithread;
@@ -488,13 +481,10 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
}
-#endif
}
void vp8cx_remove_encoder_threads(VP8_COMP *cpi)
{
-#if CONFIG_MULTITHREAD
-
if (cpi->b_multi_threaded)
{
//shutdown other threads
@@ -521,7 +511,5 @@ void vp8cx_remove_encoder_threads(VP8_COMP *cpi)
vpx_free(cpi->en_thread_data);
vpx_free(cpi->mt_current_mb_col);
}
-
-#endif
- vpx_free(cpi->tplist);
}
+#endif
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 912d64179..fc908df06 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -262,6 +262,9 @@ static void setup_features(VP8_COMP *cpi)
void vp8_dealloc_compressor_data(VP8_COMP *cpi)
{
+ vpx_free(cpi->tplist);
+ cpi->tplist = NULL;
+
// Delete last frame MV storage buffers
if (cpi->lfmv != 0)
vpx_free(cpi->lfmv);
@@ -1476,6 +1479,8 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
else
cpi->mt_sync_range = 16;
#endif
+
+ CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cpi->common.mb_rows));
}
@@ -2427,7 +2432,9 @@ VP8_PTR vp8_create_compressor(VP8_CONFIG *oxcf)
init_mv_ref_counts();
#endif
+#if CONFIG_MULTITHREAD
vp8cx_create_encoder_threads(cpi);
+#endif
cpi->fn_ptr[BLOCK_16X16].sdf = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x16);
cpi->fn_ptr[BLOCK_16X16].vf = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x16);
@@ -2702,7 +2709,9 @@ void vp8_remove_compressor(VP8_PTR *ptr)
}
+#if CONFIG_MULTITHREAD
vp8cx_remove_encoder_threads(cpi);
+#endif
vp8_dealloc_compressor_data(cpi);
vpx_free(cpi->mb.ss);
diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h
index e8a452dca..0289b4a45 100644
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -589,6 +589,7 @@ typedef struct
int cyclic_refresh_q;
signed char *cyclic_refresh_map;
+#if CONFIG_MULTITHREAD
// multithread data
int * mt_current_mb_col;
int mt_sync_range;
@@ -596,13 +597,10 @@ typedef struct
int b_multi_threaded;
int encoding_thread_count;
-#if CONFIG_MULTITHREAD
pthread_t *h_encoding_thread;
-#endif
MB_ROW_COMP *mb_row_ei;
ENCODETHREAD_DATA *en_thread_data;
-#if CONFIG_MULTITHREAD
//events
sem_t *h_event_start_encoding;
sem_t h_event_end_encoding;
diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c
index ea21cf452..632bca419 100644
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -584,7 +584,7 @@ static void macro_block_yrd( MACROBLOCK *mb,
*Rate = vp8_rdcost_mby(mb);
}
-static void rd_pick_intra4x4block(
+static int rd_pick_intra4x4block(
VP8_COMP *cpi,
MACROBLOCK *x,
BLOCK *be,
@@ -650,16 +650,20 @@ static void rd_pick_intra4x4block(
b->bmi.mode = (B_PREDICTION_MODE)(*best_mode);
vp8_encode_intra4x4block_rd(IF_RTCD(&cpi->rtcd), x, be, b, b->bmi.mode);
+ return best_rd;
+
}
-int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate, int *rate_y, int *Distortion)
+int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
+ int *rate_y, int *Distortion, int best_rd)
{
MACROBLOCKD *const xd = &mb->e_mbd;
int i;
int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
int distortion = 0;
int tot_rate_y = 0;
+ int total_rd = 0;
ENTROPY_CONTEXT_PLANES t_above, t_left;
ENTROPY_CONTEXT *ta;
ENTROPY_CONTEXT *tl;
@@ -681,7 +685,7 @@ int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate, int
B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SAFE(d);
- rd_pick_intra4x4block(
+ total_rd += rd_pick_intra4x4block(
cpi, mb, mb->block + i, xd->block + i, &best_mode, A, L,
ta + vp8_block2above[i],
tl + vp8_block2left[i], &r, &ry, &d);
@@ -690,8 +694,14 @@ int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate, int
distortion += d;
tot_rate_y += ry;
mic->bmi[i].mode = xd->block[i].bmi.mode = best_mode;
+
+ if(total_rd >= best_rd)
+ break;
}
+ if(total_rd >= best_rd)
+ return INT_MAX;
+
*Rate = cost;
*rate_y += tot_rate_y;
*Distortion = distortion;
@@ -1960,15 +1970,28 @@ int vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
switch (this_mode)
{
case B_PRED:
+ {
+ int tmp_rd;
+
// Note the rate value returned here includes the cost of coding the BPRED mode : x->mbmode_cost[x->e_mbd.frame_type][BPRED];
- vp8_rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &distortion);
+ tmp_rd = vp8_rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &distortion, best_yrd);
rate2 += rate;
distortion2 += distortion;
- rate2 += uv_intra_rate;
- rate_uv = uv_intra_rate_tokenonly;
- distortion2 += uv_intra_distortion;
- distortion_uv = uv_intra_distortion;
- break;
+
+ if(tmp_rd < best_yrd)
+ {
+ rate2 += uv_intra_rate;
+ rate_uv = uv_intra_rate_tokenonly;
+ distortion2 += uv_intra_distortion;
+ distortion_uv = uv_intra_distortion;
+ }
+ else
+ {
+ this_rd = INT_MAX;
+ disable_skip = 1;
+ }
+ }
+ break;
case SPLITMV:
{
diff --git a/vp8/encoder/rdopt.h b/vp8/encoder/rdopt.h
index d87440998..72ba9a0b5 100644
--- a/vp8/encoder/rdopt.h
+++ b/vp8/encoder/rdopt.h
@@ -12,7 +12,7 @@
#ifndef __INC_RDOPT_H
#define __INC_RDOPT_H
void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue);
-int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *rate, int *rate_to, int *distortion);
+int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *rate, int *rate_to, int *distortion, int best_rd);
int vp8_rd_pick_intra16x16mby_mode(VP8_COMP *cpi, MACROBLOCK *x, int *returnrate, int *rate_to, int *returndistortion);
int vp8_rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *rate_to, int *distortion);
extern int vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra);
diff --git a/vp8/encoder/temporal_filter.c b/vp8/encoder/temporal_filter.c
index f28daaff9..3c6d1a4d9 100644
--- a/vp8/encoder/temporal_filter.c
+++ b/vp8/encoder/temporal_filter.c
@@ -70,7 +70,7 @@ static void vp8_temporal_filter_predictors_mb_c
// U & V
mv_row >>= 1;
mv_col >>= 1;
- stride >>= 1;
+ stride = (stride + 1) >> 1;
offset = (mv_row >> 3) * stride + (mv_col >> 3);
uptr = u_mb_ptr + offset;
vptr = v_mb_ptr + offset;