2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "onyx_int.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/threading.h"
|
|
|
|
#include "vp8/common/common.h"
|
|
|
|
#include "vp8/common/extend.h"
|
2012-02-09 11:37:03 +01:00
|
|
|
#include "bitstream.h"
|
2012-05-04 18:46:57 +02:00
|
|
|
#include "encodeframe.h"
|
2012-02-09 11:37:03 +01:00
|
|
|
|
2011-02-05 06:29:25 +01:00
|
|
|
#if CONFIG_MULTITHREAD
|
|
|
|
|
2011-11-08 18:11:48 +01:00
|
|
|
extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-09-16 12:54:06 +02:00
|
|
|
extern void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm);
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2011-09-16 12:54:06 +02:00
|
|
|
static THREAD_FUNCTION thread_loopfilter(void *p_data)
|
2011-02-25 12:42:05 +01:00
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(((LPFTHREAD_DATA *)p_data)->ptr1);
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (cpi->b_multi_threaded == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (sem_wait(&cpi->h_event_start_lpf) == 0)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
if (cpi->b_multi_threaded == 0) /* we're shutting down */
|
2011-02-25 12:42:05 +01:00
|
|
|
break;
|
|
|
|
|
2011-09-16 12:54:06 +02:00
|
|
|
vp8_loopfilter_frame(cpi, cm);
|
2011-02-25 12:42:05 +01:00
|
|
|
|
|
|
|
sem_post(&cpi->h_event_end_lpf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
static
|
|
|
|
THREAD_FUNCTION thread_encoding_proc(void *p_data)
|
|
|
|
{
|
|
|
|
int ithread = ((ENCODETHREAD_DATA *)p_data)->ithread;
|
2011-01-26 09:29:46 +01:00
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr1);
|
2010-05-18 17:58:33 +02:00
|
|
|
MB_ROW_COMP *mbri = (MB_ROW_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr2);
|
2010-08-31 16:49:57 +02:00
|
|
|
ENTROPY_CONTEXT_PLANES mb_row_left_context;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (cpi->b_multi_threaded == 0)
|
|
|
|
break;
|
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
if (sem_wait(&cpi->h_event_start_encoding[ithread]) == 0)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-07-31 13:04:45 +02:00
|
|
|
const int nsync = cpi->mt_sync_range;
|
2011-01-26 09:29:46 +01:00
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
int mb_row;
|
|
|
|
MACROBLOCK *x = &mbri->mb;
|
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
|
|
|
TOKENEXTRA *tp ;
|
2012-02-09 11:37:03 +01:00
|
|
|
#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
|
|
|
|
TOKENEXTRA *tp_start = cpi->tok + (1 + ithread) * (16 * 24);
|
|
|
|
const int num_part = (1 << cm->multi_token_partition);
|
|
|
|
#endif
|
2011-01-26 09:29:46 +01:00
|
|
|
|
|
|
|
int *segment_counts = mbri->segment_counts;
|
|
|
|
int *totalrate = &mbri->totalrate;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
if (cpi->b_multi_threaded == 0) /* we're shutting down */
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
2011-01-26 09:29:46 +01:00
|
|
|
|
|
|
|
for (mb_row = ithread + 1; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1))
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
int recon_yoffset, recon_uvoffset;
|
|
|
|
int mb_col;
|
|
|
|
int ref_fb_idx = cm->lst_fb_idx;
|
|
|
|
int dst_fb_idx = cm->new_fb_idx;
|
|
|
|
int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride;
|
|
|
|
int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
|
2011-05-12 18:01:55 +02:00
|
|
|
int map_index = (mb_row * cm->mb_cols);
|
2012-02-09 11:37:03 +01:00
|
|
|
volatile const int *last_row_current_mb_col;
|
|
|
|
volatile int *current_mb_col = &cpi->mt_current_mb_col[mb_row];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-09 11:37:03 +01:00
|
|
|
#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
|
|
|
|
vp8_writer *w = &cpi->bc[1 + (mb_row % num_part)];
|
|
|
|
#else
|
2011-01-26 09:29:46 +01:00
|
|
|
tp = cpi->tok + (mb_row * (cm->mb_cols * 16 * 24));
|
2012-02-09 11:37:03 +01:00
|
|
|
cpi->tplist[mb_row].start = tp;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
last_row_current_mb_col = &cpi->mt_current_mb_col[mb_row - 1];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* reset above block coeffs */
|
2011-01-26 09:29:46 +01:00
|
|
|
xd->above_context = cm->above_context;
|
|
|
|
xd->left_context = &mb_row_left_context;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
vp8_zero(mb_row_left_context);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
xd->up_available = (mb_row != 0);
|
|
|
|
recon_yoffset = (mb_row * recon_y_stride * 16);
|
|
|
|
recon_uvoffset = (mb_row * recon_uv_stride * 8);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Set the mb activity pointer to the start of the row. */
|
2011-05-12 18:01:55 +02:00
|
|
|
x->mb_activity_ptr = &cpi->mb_activity_map[map_index];
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* for each macroblock col in image */
|
2011-01-26 09:29:46 +01:00
|
|
|
for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
|
|
|
|
{
|
2012-02-09 11:37:03 +01:00
|
|
|
*current_mb_col = mb_col - 1;
|
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
if ((mb_col & (nsync - 1)) == 0)
|
|
|
|
{
|
2012-02-09 11:37:03 +01:00
|
|
|
while (mb_col > (*last_row_current_mb_col - nsync))
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
x86_pause_hint();
|
|
|
|
thread_sleep(0);
|
|
|
|
}
|
2011-01-26 09:29:46 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-09 11:37:03 +01:00
|
|
|
#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
|
|
|
|
tp = tp_start;
|
|
|
|
#endif
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Distance of Mb to the various image edges.
|
|
|
|
* These specified to 8th pel as they are always compared
|
|
|
|
* to values that are in 1/8th pel units
|
|
|
|
*/
|
2011-01-26 09:29:46 +01:00
|
|
|
xd->mb_to_left_edge = -((mb_col * 16) << 3);
|
|
|
|
xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3;
|
|
|
|
xd->mb_to_top_edge = -((mb_row * 16) << 3);
|
|
|
|
xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Set up limit values for motion vectors used to prevent
|
|
|
|
* them extending outside the UMV borders
|
|
|
|
*/
|
2011-01-26 09:29:46 +01:00
|
|
|
x->mv_col_min = -((mb_col * 16) + (VP8BORDERINPIXELS - 16));
|
|
|
|
x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + (VP8BORDERINPIXELS - 16);
|
|
|
|
x->mv_row_min = -((mb_row * 16) + (VP8BORDERINPIXELS - 16));
|
|
|
|
x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16) + (VP8BORDERINPIXELS - 16);
|
|
|
|
|
|
|
|
xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
|
|
|
|
xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
|
|
|
|
xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
|
|
|
|
xd->left_available = (mb_col != 0);
|
|
|
|
|
|
|
|
x->rddiv = cpi->RDDIV;
|
|
|
|
x->rdmult = cpi->RDMULT;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Copy current mb to a buffer */
|
2012-01-13 01:55:44 +01:00
|
|
|
vp8_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16);
|
2011-06-23 19:54:02 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
if (cpi->oxcf.tuning == VP8_TUNE_SSIM)
|
2011-05-12 18:01:55 +02:00
|
|
|
vp8_activity_masking(cpi, x);
|
2011-01-26 09:29:46 +01:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Is segmentation enabled */
|
|
|
|
/* MB level adjustment to quantizer */
|
2011-01-26 09:29:46 +01:00
|
|
|
if (xd->segmentation_enabled)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Code to set segment id in xd->mbmi.segment_id for
|
|
|
|
* current MB (with range checking)
|
|
|
|
*/
|
2011-05-12 18:01:55 +02:00
|
|
|
if (cpi->segmentation_map[map_index + mb_col] <= 3)
|
|
|
|
xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[map_index + mb_col];
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
2011-01-26 09:29:46 +01:00
|
|
|
xd->mode_info_context->mbmi.segment_id = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-08 18:11:48 +01:00
|
|
|
vp8cx_mb_init_quantizer(cpi, x, 1);
|
2011-01-26 09:29:46 +01:00
|
|
|
}
|
|
|
|
else
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Set to Segment 0 by default */
|
|
|
|
xd->mode_info_context->mbmi.segment_id = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-12 18:01:55 +02:00
|
|
|
x->active_ptr = cpi->active_map + map_index + mb_col;
|
2011-01-26 09:29:46 +01:00
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
{
|
2012-05-04 12:32:43 +02:00
|
|
|
*totalrate += vp8cx_encode_intra_macroblock(cpi, x, &tp);
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifdef MODE_STATS
|
2011-01-26 09:29:46 +01:00
|
|
|
y_modes[xd->mbmi.mode] ++;
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2011-01-26 09:29:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-04 12:32:43 +02:00
|
|
|
*totalrate += vp8cx_encode_inter_macroblock(cpi, x, &tp, recon_yoffset, recon_uvoffset, mb_row, mb_col);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#ifdef MODE_STATS
|
2011-01-26 09:29:46 +01:00
|
|
|
inter_y_modes[xd->mbmi.mode] ++;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
if (xd->mbmi.mode == SPLITMV)
|
|
|
|
{
|
|
|
|
int b;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
for (b = 0; b < xd->mbmi.partition_count; b++)
|
|
|
|
{
|
|
|
|
inter_b_modes[x->partition->bmi[b].mode] ++;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-01-26 09:29:46 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Special case code for cyclic refresh
|
|
|
|
* If cyclic update enabled then copy
|
|
|
|
* xd->mbmi.segment_id; (which may have been updated
|
|
|
|
* based on mode during
|
|
|
|
* vp8cx_encode_inter_macroblock()) back into the
|
|
|
|
* global segmentation map
|
|
|
|
*/
|
2011-01-26 09:29:46 +01:00
|
|
|
if (cpi->cyclic_refresh_mode_enabled && xd->segmentation_enabled)
|
|
|
|
{
|
|
|
|
const MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
|
2011-05-12 18:01:55 +02:00
|
|
|
cpi->segmentation_map[map_index + mb_col] = mbmi->segment_id;
|
2011-01-26 09:29:46 +01:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* If the block has been refreshed mark it as clean
|
|
|
|
* (the magnitude of the -ve influences how long it
|
|
|
|
* will be before we consider another refresh):
|
|
|
|
* Else if it was coded (last frame 0,0) and has
|
|
|
|
* not already been refreshed then mark it as a
|
|
|
|
* candidate for cleanup next time (marked 0) else
|
|
|
|
* mark it as dirty (1).
|
|
|
|
*/
|
2011-01-26 09:29:46 +01:00
|
|
|
if (mbmi->segment_id)
|
2011-05-12 18:01:55 +02:00
|
|
|
cpi->cyclic_refresh_map[map_index + mb_col] = -1;
|
2011-01-26 09:29:46 +01:00
|
|
|
else if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME))
|
2010-12-10 19:48:30 +01:00
|
|
|
{
|
2011-05-12 18:01:55 +02:00
|
|
|
if (cpi->cyclic_refresh_map[map_index + mb_col] == 1)
|
|
|
|
cpi->cyclic_refresh_map[map_index + mb_col] = 0;
|
2010-12-10 19:48:30 +01:00
|
|
|
}
|
2011-01-26 09:29:46 +01:00
|
|
|
else
|
2011-05-12 18:01:55 +02:00
|
|
|
cpi->cyclic_refresh_map[map_index + mb_col] = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-09 11:37:03 +01:00
|
|
|
#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
|
|
|
|
/* pack tokens for this MB */
|
|
|
|
{
|
|
|
|
int tok_count = tp - tp_start;
|
|
|
|
pack_tokens(w, tp_start, tok_count);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
cpi->tplist[mb_row].stop = tp;
|
|
|
|
#endif
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Increment pointer into gf usage flags structure. */
|
2011-05-12 18:01:55 +02:00
|
|
|
x->gf_active_ptr++;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Increment the activity mask pointers. */
|
2011-05-12 18:01:55 +02:00
|
|
|
x->mb_activity_ptr++;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* adjust to the next column of macroblocks */
|
2011-01-26 09:29:46 +01:00
|
|
|
x->src.y_buffer += 16;
|
|
|
|
x->src.u_buffer += 8;
|
|
|
|
x->src.v_buffer += 8;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
recon_yoffset += 16;
|
|
|
|
recon_uvoffset += 8;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Keep track of segment usage */
|
2011-01-26 09:29:46 +01:00
|
|
|
segment_counts[xd->mode_info_context->mbmi.segment_id]++;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* skip to next mb */
|
2010-05-18 17:58:33 +02:00
|
|
|
xd->mode_info_context++;
|
2010-09-02 22:17:52 +02:00
|
|
|
x->partition_info++;
|
2011-01-26 09:29:46 +01:00
|
|
|
xd->above_context++;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-09 11:37:03 +01:00
|
|
|
vp8_extend_mb_row( &cm->yv12_fb[dst_fb_idx],
|
|
|
|
xd->dst.y_buffer + 16,
|
|
|
|
xd->dst.u_buffer + 8,
|
|
|
|
xd->dst.v_buffer + 8);
|
|
|
|
|
|
|
|
*current_mb_col = mb_col + nsync;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* this is to account for the border */
|
2011-01-26 09:29:46 +01:00
|
|
|
xd->mode_info_context++;
|
|
|
|
x->partition_info++;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
x->src.y_buffer += 16 * x->src.y_stride * (cpi->encoding_thread_count + 1) - 16 * cm->mb_cols;
|
|
|
|
x->src.u_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
|
|
|
|
x->src.v_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
|
|
|
|
x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
|
2011-05-06 18:00:44 +02:00
|
|
|
x->gf_active_ptr += cm->mb_cols * cpi->encoding_thread_count;
|
2011-01-26 09:29:46 +01:00
|
|
|
|
|
|
|
if (mb_row == cm->mb_rows - 1)
|
|
|
|
{
|
|
|
|
sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* printf("exit thread %d\n", ithread); */
|
2010-05-18 17:58:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc)
|
|
|
|
{
|
|
|
|
|
|
|
|
MACROBLOCK *x = mbsrc;
|
|
|
|
MACROBLOCK *z = mbdst;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
z->ss = x->ss;
|
|
|
|
z->ss_count = x->ss_count;
|
|
|
|
z->searches_per_step = x->searches_per_step;
|
|
|
|
z->errorperbit = x->errorperbit;
|
|
|
|
|
|
|
|
z->sadperbit16 = x->sadperbit16;
|
|
|
|
z->sadperbit4 = x->sadperbit4;
|
|
|
|
|
|
|
|
/*
|
|
|
|
z->mv_col_min = x->mv_col_min;
|
|
|
|
z->mv_col_max = x->mv_col_max;
|
|
|
|
z->mv_row_min = x->mv_row_min;
|
|
|
|
z->mv_row_max = x->mv_row_max;
|
|
|
|
*/
|
|
|
|
|
2012-01-13 01:55:44 +01:00
|
|
|
z->short_fdct4x4 = x->short_fdct4x4;
|
|
|
|
z->short_fdct8x4 = x->short_fdct8x4;
|
2010-05-18 17:58:33 +02:00
|
|
|
z->short_walsh4x4 = x->short_walsh4x4;
|
|
|
|
z->quantize_b = x->quantize_b;
|
2011-05-09 09:09:41 +02:00
|
|
|
z->quantize_b_pair = x->quantize_b_pair;
|
2010-12-14 19:12:21 +01:00
|
|
|
z->optimize = x->optimize;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
z->mvc = x->mvc;
|
|
|
|
z->src.y_buffer = x->src.y_buffer;
|
|
|
|
z->src.u_buffer = x->src.u_buffer;
|
|
|
|
z->src.v_buffer = x->src.v_buffer;
|
|
|
|
*/
|
|
|
|
|
2012-04-17 09:40:56 +02:00
|
|
|
z->mvcost[0] = x->mvcost[0];
|
|
|
|
z->mvcost[1] = x->mvcost[1];
|
|
|
|
z->mvsadcost[0] = x->mvsadcost[0];
|
|
|
|
z->mvsadcost[1] = x->mvsadcost[1];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-17 09:40:56 +02:00
|
|
|
z->token_costs = x->token_costs;
|
|
|
|
z->inter_bmode_costs = x->inter_bmode_costs;
|
|
|
|
z->mbmode_cost = x->mbmode_cost;
|
|
|
|
z->intra_uv_mode_cost = x->intra_uv_mode_cost;
|
|
|
|
z->bmode_costs = x->bmode_costs;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 25; i++)
|
|
|
|
{
|
|
|
|
z->block[i].quant = x->block[i].quant;
|
2010-12-29 22:28:24 +01:00
|
|
|
z->block[i].quant_fast = x->block[i].quant_fast;
|
2010-06-29 02:15:09 +02:00
|
|
|
z->block[i].quant_shift = x->block[i].quant_shift;
|
2010-05-18 17:58:33 +02:00
|
|
|
z->block[i].zbin = x->block[i].zbin;
|
2012-04-17 09:40:56 +02:00
|
|
|
z->block[i].zrun_zbin_boost = x->block[i].zrun_zbin_boost;
|
2010-05-18 17:58:33 +02:00
|
|
|
z->block[i].round = x->block[i].round;
|
2012-04-17 09:40:56 +02:00
|
|
|
z->block[i].src_stride = x->block[i].src_stride;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-04-17 09:40:56 +02:00
|
|
|
z->q_index = x->q_index;
|
|
|
|
z->act_zbin_adj = x->act_zbin_adj;
|
|
|
|
z->last_act_zbin_adj = x->last_act_zbin_adj;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
|
|
|
MACROBLOCKD *zd = &z->e_mbd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
zd->mode_info_context = xd->mode_info_context;
|
|
|
|
zd->mode_info = xd->mode_info;
|
|
|
|
|
|
|
|
zd->mode_info_stride = xd->mode_info_stride;
|
|
|
|
zd->frame_type = xd->frame_type;
|
|
|
|
zd->up_available = xd->up_available ;
|
|
|
|
zd->left_available = xd->left_available;
|
|
|
|
zd->left_context = xd->left_context;
|
|
|
|
zd->last_frame_dc = xd->last_frame_dc;
|
|
|
|
zd->last_frame_dccons = xd->last_frame_dccons;
|
|
|
|
zd->gold_frame_dc = xd->gold_frame_dc;
|
|
|
|
zd->gold_frame_dccons = xd->gold_frame_dccons;
|
|
|
|
zd->mb_to_left_edge = xd->mb_to_left_edge;
|
|
|
|
zd->mb_to_right_edge = xd->mb_to_right_edge;
|
|
|
|
zd->mb_to_top_edge = xd->mb_to_top_edge ;
|
|
|
|
zd->mb_to_bottom_edge = xd->mb_to_bottom_edge;
|
|
|
|
zd->gf_active_ptr = xd->gf_active_ptr;
|
|
|
|
zd->frames_since_golden = xd->frames_since_golden;
|
|
|
|
zd->frames_till_alt_ref_frame = xd->frames_till_alt_ref_frame;
|
|
|
|
*/
|
|
|
|
zd->subpixel_predict = xd->subpixel_predict;
|
|
|
|
zd->subpixel_predict8x4 = xd->subpixel_predict8x4;
|
|
|
|
zd->subpixel_predict8x8 = xd->subpixel_predict8x8;
|
|
|
|
zd->subpixel_predict16x16 = xd->subpixel_predict16x16;
|
|
|
|
zd->segmentation_enabled = xd->segmentation_enabled;
|
|
|
|
zd->mb_segement_abs_delta = xd->mb_segement_abs_delta;
|
2012-04-17 09:40:56 +02:00
|
|
|
vpx_memcpy(zd->segment_feature_data, xd->segment_feature_data,
|
|
|
|
sizeof(xd->segment_feature_data));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-17 09:40:56 +02:00
|
|
|
vpx_memcpy(zd->dequant_y1_dc, xd->dequant_y1_dc,
|
|
|
|
sizeof(xd->dequant_y1_dc));
|
2012-01-04 17:56:50 +01:00
|
|
|
vpx_memcpy(zd->dequant_y1, xd->dequant_y1, sizeof(xd->dequant_y1));
|
|
|
|
vpx_memcpy(zd->dequant_y2, xd->dequant_y2, sizeof(xd->dequant_y2));
|
|
|
|
vpx_memcpy(zd->dequant_uv, xd->dequant_uv, sizeof(xd->dequant_uv));
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
/*TODO: Remove dequant from BLOCKD. This is a temporary solution until
|
|
|
|
* the quantizer code uses a passed in pointer to the dequant constants.
|
|
|
|
* This will also require modifications to the x86 and neon assembly.
|
|
|
|
* */
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
zd->block[i].dequant = zd->dequant_y1;
|
|
|
|
for (i = 16; i < 24; i++)
|
|
|
|
zd->block[i].dequant = zd->dequant_uv;
|
|
|
|
zd->block[24].dequant = zd->dequant_y2;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
|
|
|
|
MACROBLOCK *x,
|
|
|
|
MB_ROW_COMP *mbr_ei,
|
|
|
|
int mb_row,
|
|
|
|
int count
|
|
|
|
)
|
|
|
|
{
|
|
|
|
|
|
|
|
VP8_COMMON *const cm = & cpi->common;
|
|
|
|
MACROBLOCKD *const xd = & x->e_mbd;
|
|
|
|
int i;
|
|
|
|
(void) mb_row;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
MACROBLOCK *mb = & mbr_ei[i].mb;
|
|
|
|
MACROBLOCKD *mbd = &mb->e_mbd;
|
|
|
|
|
|
|
|
mbd->subpixel_predict = xd->subpixel_predict;
|
|
|
|
mbd->subpixel_predict8x4 = xd->subpixel_predict8x4;
|
|
|
|
mbd->subpixel_predict8x8 = xd->subpixel_predict8x8;
|
|
|
|
mbd->subpixel_predict16x16 = xd->subpixel_predict16x16;
|
2010-08-11 17:02:31 +02:00
|
|
|
mb->gf_active_ptr = x->gf_active_ptr;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
vpx_memset(mbr_ei[i].segment_counts, 0, sizeof(mbr_ei[i].segment_counts));
|
|
|
|
mbr_ei[i].totalrate = 0;
|
|
|
|
|
2010-09-02 22:17:52 +02:00
|
|
|
mb->partition_info = x->pi + x->e_mbd.mode_info_stride * (i + 1);
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
mbd->mode_info_context = cm->mi + x->e_mbd.mode_info_stride * (i + 1);
|
|
|
|
mbd->mode_info_stride = cm->mode_info_stride;
|
|
|
|
|
|
|
|
mbd->frame_type = cm->frame_type;
|
|
|
|
|
|
|
|
mb->src = * cpi->Source;
|
2010-07-22 14:07:32 +02:00
|
|
|
mbd->pre = cm->yv12_fb[cm->lst_fb_idx];
|
|
|
|
mbd->dst = cm->yv12_fb[cm->new_fb_idx];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
mb->src.y_buffer += 16 * x->src.y_stride * (i + 1);
|
|
|
|
mb->src.u_buffer += 8 * x->src.uv_stride * (i + 1);
|
|
|
|
mb->src.v_buffer += 8 * x->src.uv_stride * (i + 1);
|
|
|
|
|
|
|
|
vp8_build_block_offsets(mb);
|
|
|
|
|
2010-08-31 16:49:57 +02:00
|
|
|
mbd->left_context = &cm->left_context;
|
2010-05-18 17:58:33 +02:00
|
|
|
mb->mvc = cm->fc.mvc;
|
|
|
|
|
|
|
|
setup_mbby_copy(&mbr_ei[i].mb, x);
|
|
|
|
|
2011-09-13 17:46:33 +02:00
|
|
|
mbd->fullpixel_mask = 0xffffffff;
|
|
|
|
if(cm->full_pixel)
|
|
|
|
mbd->fullpixel_mask = 0xfffffff8;
|
2012-11-03 00:04:52 +01:00
|
|
|
|
|
|
|
vp8_zero(mb->coef_counts);
|
2012-11-05 21:25:18 +01:00
|
|
|
vp8_zero(x->ymode_count);
|
2012-11-03 02:03:03 +01:00
|
|
|
mb->skip_true_count = 0;
|
2012-11-05 21:41:24 +01:00
|
|
|
vp8_zero(mb->MVcount);
|
2012-11-06 02:30:49 +01:00
|
|
|
mb->prediction_error = 0;
|
|
|
|
mb->intra_error = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-14 21:00:23 +02:00
|
|
|
int vp8cx_create_encoder_threads(VP8_COMP *cpi)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-03-18 09:44:08 +01:00
|
|
|
const VP8_COMMON * cm = &cpi->common;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-18 09:44:08 +01:00
|
|
|
cpi->b_multi_threaded = 0;
|
|
|
|
cpi->encoding_thread_count = 0;
|
2011-09-16 12:54:06 +02:00
|
|
|
cpi->b_lpf_running = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-25 11:53:03 +01:00
|
|
|
if (cm->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int ithread;
|
2011-03-18 09:44:08 +01:00
|
|
|
int th_count = cpi->oxcf.multi_threaded - 1;
|
2012-08-14 21:00:23 +02:00
|
|
|
int rc = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-25 11:53:03 +01:00
|
|
|
/* don't allocate more threads than cores available */
|
|
|
|
if (cpi->oxcf.multi_threaded > cm->processor_core_count)
|
|
|
|
th_count = cm->processor_core_count - 1;
|
2011-03-18 09:44:08 +01:00
|
|
|
|
|
|
|
/* we have th_count + 1 (main) threads processing one row each */
|
|
|
|
/* no point to have more threads than the sync range allows */
|
|
|
|
if(th_count > ((cm->mb_cols / cpi->mt_sync_range) - 1))
|
|
|
|
{
|
|
|
|
th_count = (cm->mb_cols / cpi->mt_sync_range) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(th_count == 0)
|
2012-08-14 21:00:23 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
CHECK_MEM_ERROR(cpi->h_encoding_thread,
|
|
|
|
vpx_malloc(sizeof(pthread_t) * th_count));
|
|
|
|
CHECK_MEM_ERROR(cpi->h_event_start_encoding,
|
|
|
|
vpx_malloc(sizeof(sem_t) * th_count));
|
|
|
|
CHECK_MEM_ERROR(cpi->mb_row_ei,
|
|
|
|
vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count));
|
2011-03-18 09:44:08 +01:00
|
|
|
vpx_memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count);
|
|
|
|
CHECK_MEM_ERROR(cpi->en_thread_data,
|
|
|
|
vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count));
|
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
sem_init(&cpi->h_event_end_encoding, 0, 0);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->b_multi_threaded = 1;
|
2011-03-18 09:44:08 +01:00
|
|
|
cpi->encoding_thread_count = th_count;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-18 09:44:08 +01:00
|
|
|
/*
|
|
|
|
printf("[VP8:] multi_threaded encoding is enabled with %d threads\n\n",
|
|
|
|
(cpi->encoding_thread_count +1));
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-18 09:44:08 +01:00
|
|
|
for (ithread = 0; ithread < th_count; ithread++)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-04-24 14:17:28 +02:00
|
|
|
ENCODETHREAD_DATA *ethd = &cpi->en_thread_data[ithread];
|
|
|
|
|
|
|
|
/* Setup block ptrs and offsets */
|
|
|
|
vp8_setup_block_ptrs(&cpi->mb_row_ei[ithread].mb);
|
|
|
|
vp8_setup_block_dptrs(&cpi->mb_row_ei[ithread].mb.e_mbd);
|
2011-01-26 09:29:46 +01:00
|
|
|
|
|
|
|
sem_init(&cpi->h_event_start_encoding[ithread], 0, 0);
|
2012-04-24 14:17:28 +02:00
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
ethd->ithread = ithread;
|
|
|
|
ethd->ptr1 = (void *)cpi;
|
|
|
|
ethd->ptr2 = (void *)&cpi->mb_row_ei[ithread];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-08-14 21:00:23 +02:00
|
|
|
rc = pthread_create(&cpi->h_encoding_thread[ithread], 0,
|
|
|
|
thread_encoding_proc, ethd);
|
|
|
|
if(rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
/* shutdown other threads */
|
|
|
|
cpi->b_multi_threaded = 0;
|
|
|
|
for(--ithread; ithread >= 0; ithread--)
|
|
|
|
{
|
|
|
|
pthread_join(cpi->h_encoding_thread[ithread], 0);
|
|
|
|
sem_destroy(&cpi->h_event_start_encoding[ithread]);
|
|
|
|
}
|
|
|
|
sem_destroy(&cpi->h_event_end_encoding);
|
|
|
|
|
|
|
|
/* free thread related resources */
|
|
|
|
vpx_free(cpi->h_event_start_encoding);
|
|
|
|
vpx_free(cpi->h_encoding_thread);
|
|
|
|
vpx_free(cpi->mb_row_ei);
|
|
|
|
vpx_free(cpi->en_thread_data);
|
|
|
|
|
|
|
|
return -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-08-14 21:00:23 +02:00
|
|
|
|
2011-02-25 12:42:05 +01:00
|
|
|
{
|
|
|
|
LPFTHREAD_DATA * lpfthd = &cpi->lpf_thread_data;
|
|
|
|
|
|
|
|
sem_init(&cpi->h_event_start_lpf, 0, 0);
|
|
|
|
sem_init(&cpi->h_event_end_lpf, 0, 0);
|
|
|
|
|
|
|
|
lpfthd->ptr1 = (void *)cpi;
|
2012-08-14 21:00:23 +02:00
|
|
|
rc = pthread_create(&cpi->h_filter_thread, 0, thread_loopfilter,
|
|
|
|
lpfthd);
|
|
|
|
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
/* shutdown other threads */
|
|
|
|
cpi->b_multi_threaded = 0;
|
|
|
|
for(--ithread; ithread >= 0; ithread--)
|
|
|
|
{
|
|
|
|
sem_post(&cpi->h_event_start_encoding[ithread]);
|
|
|
|
pthread_join(cpi->h_encoding_thread[ithread], 0);
|
|
|
|
sem_destroy(&cpi->h_event_start_encoding[ithread]);
|
|
|
|
}
|
|
|
|
sem_destroy(&cpi->h_event_end_encoding);
|
|
|
|
sem_destroy(&cpi->h_event_end_lpf);
|
|
|
|
sem_destroy(&cpi->h_event_start_lpf);
|
|
|
|
|
|
|
|
/* free thread related resources */
|
|
|
|
vpx_free(cpi->h_event_start_encoding);
|
|
|
|
vpx_free(cpi->h_encoding_thread);
|
|
|
|
vpx_free(cpi->mb_row_ei);
|
|
|
|
vpx_free(cpi->en_thread_data);
|
|
|
|
|
|
|
|
return -2;
|
|
|
|
}
|
2011-02-25 12:42:05 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-08-14 21:00:23 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void vp8cx_remove_encoder_threads(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
if (cpi->b_multi_threaded)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* shutdown other threads */
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->b_multi_threaded = 0;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < cpi->encoding_thread_count; i++)
|
|
|
|
{
|
2011-01-26 09:29:46 +01:00
|
|
|
sem_post(&cpi->h_event_start_encoding[i]);
|
2010-05-18 17:58:33 +02:00
|
|
|
pthread_join(cpi->h_encoding_thread[i], 0);
|
|
|
|
|
2011-01-26 09:29:46 +01:00
|
|
|
sem_destroy(&cpi->h_event_start_encoding[i]);
|
|
|
|
}
|
2011-02-25 12:42:05 +01:00
|
|
|
|
|
|
|
sem_post(&cpi->h_event_start_lpf);
|
|
|
|
pthread_join(cpi->h_filter_thread, 0);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-01-26 09:29:46 +01:00
|
|
|
|
|
|
|
sem_destroy(&cpi->h_event_end_encoding);
|
2011-02-25 12:42:05 +01:00
|
|
|
sem_destroy(&cpi->h_event_end_lpf);
|
|
|
|
sem_destroy(&cpi->h_event_start_lpf);
|
2011-01-26 09:29:46 +01:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* free thread related resources */
|
2011-01-26 09:29:46 +01:00
|
|
|
vpx_free(cpi->h_event_start_encoding);
|
2010-05-18 17:58:33 +02:00
|
|
|
vpx_free(cpi->h_encoding_thread);
|
|
|
|
vpx_free(cpi->mb_row_ei);
|
|
|
|
vpx_free(cpi->en_thread_data);
|
|
|
|
}
|
|
|
|
}
|
2011-02-05 06:29:25 +01:00
|
|
|
#endif
|