ethreading.c revision 7bc9febe8749e98a3812a0dc4380ceae75c29450
190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/*
2f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber *
4f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Use of this source code is governed by a BSD-style license
5f71323e297a928af368937089d3ed71239786f86Andreas Huber *  that can be found in the LICENSE file in the root of the source
6f71323e297a928af368937089d3ed71239786f86Andreas Huber *  tree. An additional intellectual property rights grant can be found
7f71323e297a928af368937089d3ed71239786f86Andreas Huber *  in the file PATENTS.  All contributing project authors may
8f71323e297a928af368937089d3ed71239786f86Andreas Huber *  be found in the AUTHORS file in the root of the source tree.
990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber */
1090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "onyx_int.h"
1279f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/threading.h"
1379f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/common.h"
1479f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/extend.h"
151b362b15af34006e6a11974088a46d42b903418eJohann#include "bitstream.h"
161b362b15af34006e6a11974088a46d42b903418eJohann#include "encodeframe.h"
1790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1879f15823c34ae1e423108295e416213200bb280fAndreas Huber#if CONFIG_MULTITHREAD
1990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
207bc9febe8749e98a3812a0dc4380ceae75c29450Johannextern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x,
217bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                    int ok_to_skip);
2290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
237bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic THREAD_FUNCTION thread_loopfilter(void *p_data) {
247bc9febe8749e98a3812a0dc4380ceae75c29450Johann  VP8_COMP *cpi = (VP8_COMP *)(((LPFTHREAD_DATA *)p_data)->ptr1);
257bc9febe8749e98a3812a0dc4380ceae75c29450Johann  VP8_COMMON *cm = &cpi->common;
2679f15823c34ae1e423108295e416213200bb280fAndreas Huber
277bc9febe8749e98a3812a0dc4380ceae75c29450Johann  while (1) {
287bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0) break;
2979f15823c34ae1e423108295e416213200bb280fAndreas Huber
307bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (sem_wait(&cpi->h_event_start_lpf) == 0) {
317bc9febe8749e98a3812a0dc4380ceae75c29450Johann      /* we're shutting down */
327bc9febe8749e98a3812a0dc4380ceae75c29450Johann      if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0) break;
3379f15823c34ae1e423108295e416213200bb280fAndreas Huber
347bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vp8_loopfilter_frame(cpi, cm);
3579f15823c34ae1e423108295e416213200bb280fAndreas Huber
367bc9febe8749e98a3812a0dc4380ceae75c29450Johann      sem_post(&cpi->h_event_end_lpf);
3779f15823c34ae1e423108295e416213200bb280fAndreas Huber    }
387bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
3979f15823c34ae1e423108295e416213200bb280fAndreas Huber
407bc9febe8749e98a3812a0dc4380ceae75c29450Johann  return 0;
4179f15823c34ae1e423108295e416213200bb280fAndreas Huber}
4279f15823c34ae1e423108295e416213200bb280fAndreas Huber
437bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic THREAD_FUNCTION thread_encoding_proc(void *p_data) {
447bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int ithread = ((ENCODETHREAD_DATA *)p_data)->ithread;
457bc9febe8749e98a3812a0dc4380ceae75c29450Johann  VP8_COMP *cpi = (VP8_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr1);
467bc9febe8749e98a3812a0dc4380ceae75c29450Johann  MB_ROW_COMP *mbri = (MB_ROW_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr2);
477bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ENTROPY_CONTEXT_PLANES mb_row_left_context;
487bc9febe8749e98a3812a0dc4380ceae75c29450Johann
497bc9febe8749e98a3812a0dc4380ceae75c29450Johann  while (1) {
507bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0) break;
517bc9febe8749e98a3812a0dc4380ceae75c29450Johann
527bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (sem_wait(&cpi->h_event_start_encoding[ithread]) == 0) {
537bc9febe8749e98a3812a0dc4380ceae75c29450Johann      const int nsync = cpi->mt_sync_range;
547bc9febe8749e98a3812a0dc4380ceae75c29450Johann      VP8_COMMON *cm = &cpi->common;
557bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int mb_row;
567bc9febe8749e98a3812a0dc4380ceae75c29450Johann      MACROBLOCK *x = &mbri->mb;
577bc9febe8749e98a3812a0dc4380ceae75c29450Johann      MACROBLOCKD *xd = &x->e_mbd;
587bc9febe8749e98a3812a0dc4380ceae75c29450Johann      TOKENEXTRA *tp;
591b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
607bc9febe8749e98a3812a0dc4380ceae75c29450Johann      TOKENEXTRA *tp_start = cpi->tok + (1 + ithread) * (16 * 24);
617bc9febe8749e98a3812a0dc4380ceae75c29450Johann      const int num_part = (1 << cm->multi_token_partition);
621b362b15af34006e6a11974088a46d42b903418eJohann#endif
6379f15823c34ae1e423108295e416213200bb280fAndreas Huber
647bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int *segment_counts = mbri->segment_counts;
657bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int *totalrate = &mbri->totalrate;
667bc9febe8749e98a3812a0dc4380ceae75c29450Johann
677bc9febe8749e98a3812a0dc4380ceae75c29450Johann      /* we're shutting down */
687bc9febe8749e98a3812a0dc4380ceae75c29450Johann      if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded) == 0) break;
697bc9febe8749e98a3812a0dc4380ceae75c29450Johann
707bc9febe8749e98a3812a0dc4380ceae75c29450Johann      xd->mode_info_context = cm->mi + cm->mode_info_stride * (ithread + 1);
717bc9febe8749e98a3812a0dc4380ceae75c29450Johann      xd->mode_info_stride = cm->mode_info_stride;
727bc9febe8749e98a3812a0dc4380ceae75c29450Johann
737bc9febe8749e98a3812a0dc4380ceae75c29450Johann      for (mb_row = ithread + 1; mb_row < cm->mb_rows;
747bc9febe8749e98a3812a0dc4380ceae75c29450Johann           mb_row += (cpi->encoding_thread_count + 1)) {
757bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int recon_yoffset, recon_uvoffset;
767bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int mb_col;
777bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int ref_fb_idx = cm->lst_fb_idx;
787bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int dst_fb_idx = cm->new_fb_idx;
797bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride;
807bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
817bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int map_index = (mb_row * cm->mb_cols);
827bc9febe8749e98a3812a0dc4380ceae75c29450Johann        const int *last_row_current_mb_col;
837bc9febe8749e98a3812a0dc4380ceae75c29450Johann        int *current_mb_col = &cpi->mt_current_mb_col[mb_row];
847bc9febe8749e98a3812a0dc4380ceae75c29450Johann
857bc9febe8749e98a3812a0dc4380ceae75c29450Johann#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
867bc9febe8749e98a3812a0dc4380ceae75c29450Johann        vp8_writer *w = &cpi->bc[1 + (mb_row % num_part)];
871b362b15af34006e6a11974088a46d42b903418eJohann#else
887bc9febe8749e98a3812a0dc4380ceae75c29450Johann        tp = cpi->tok + (mb_row * (cm->mb_cols * 16 * 24));
897bc9febe8749e98a3812a0dc4380ceae75c29450Johann        cpi->tplist[mb_row].start = tp;
901b362b15af34006e6a11974088a46d42b903418eJohann#endif
9190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
927bc9febe8749e98a3812a0dc4380ceae75c29450Johann        last_row_current_mb_col = &cpi->mt_current_mb_col[mb_row - 1];
9390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
947bc9febe8749e98a3812a0dc4380ceae75c29450Johann        /* reset above block coeffs */
957bc9febe8749e98a3812a0dc4380ceae75c29450Johann        xd->above_context = cm->above_context;
967bc9febe8749e98a3812a0dc4380ceae75c29450Johann        xd->left_context = &mb_row_left_context;
9790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
987bc9febe8749e98a3812a0dc4380ceae75c29450Johann        vp8_zero(mb_row_left_context);
9990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1007bc9febe8749e98a3812a0dc4380ceae75c29450Johann        xd->up_available = (mb_row != 0);
1017bc9febe8749e98a3812a0dc4380ceae75c29450Johann        recon_yoffset = (mb_row * recon_y_stride * 16);
1027bc9febe8749e98a3812a0dc4380ceae75c29450Johann        recon_uvoffset = (mb_row * recon_uv_stride * 8);
10390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1047bc9febe8749e98a3812a0dc4380ceae75c29450Johann        /* Set the mb activity pointer to the start of the row. */
1057bc9febe8749e98a3812a0dc4380ceae75c29450Johann        x->mb_activity_ptr = &cpi->mb_activity_map[map_index];
10679f15823c34ae1e423108295e416213200bb280fAndreas Huber
1077bc9febe8749e98a3812a0dc4380ceae75c29450Johann        /* for each macroblock col in image */
1087bc9febe8749e98a3812a0dc4380ceae75c29450Johann        for (mb_col = 0; mb_col < cm->mb_cols; ++mb_col) {
1097bc9febe8749e98a3812a0dc4380ceae75c29450Johann          if (((mb_col - 1) % nsync) == 0) {
1107bc9febe8749e98a3812a0dc4380ceae75c29450Johann            pthread_mutex_t *mutex = &cpi->pmutex[mb_row];
1117bc9febe8749e98a3812a0dc4380ceae75c29450Johann            protected_write(mutex, current_mb_col, mb_col - 1);
1127bc9febe8749e98a3812a0dc4380ceae75c29450Johann          }
11390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1147bc9febe8749e98a3812a0dc4380ceae75c29450Johann          if (mb_row && !(mb_col & (nsync - 1))) {
1157bc9febe8749e98a3812a0dc4380ceae75c29450Johann            pthread_mutex_t *mutex = &cpi->pmutex[mb_row - 1];
1167bc9febe8749e98a3812a0dc4380ceae75c29450Johann            sync_read(mutex, mb_col, last_row_current_mb_col, nsync);
1177bc9febe8749e98a3812a0dc4380ceae75c29450Johann          }
11890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1191b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
1207bc9febe8749e98a3812a0dc4380ceae75c29450Johann          tp = tp_start;
1211b362b15af34006e6a11974088a46d42b903418eJohann#endif
1221b362b15af34006e6a11974088a46d42b903418eJohann
1237bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* Distance of Mb to the various image edges.
1247bc9febe8749e98a3812a0dc4380ceae75c29450Johann           * These specified to 8th pel as they are always compared
1257bc9febe8749e98a3812a0dc4380ceae75c29450Johann           * to values that are in 1/8th pel units
1267bc9febe8749e98a3812a0dc4380ceae75c29450Johann           */
1277bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->mb_to_left_edge = -((mb_col * 16) << 3);
1287bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3;
1297bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->mb_to_top_edge = -((mb_row * 16) << 3);
1307bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3;
1317bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1327bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* Set up limit values for motion vectors used to prevent
1337bc9febe8749e98a3812a0dc4380ceae75c29450Johann           * them extending outside the UMV borders
1347bc9febe8749e98a3812a0dc4380ceae75c29450Johann           */
1357bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->mv_col_min = -((mb_col * 16) + (VP8BORDERINPIXELS - 16));
1367bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->mv_col_max =
1377bc9febe8749e98a3812a0dc4380ceae75c29450Johann              ((cm->mb_cols - 1 - mb_col) * 16) + (VP8BORDERINPIXELS - 16);
1387bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->mv_row_min = -((mb_row * 16) + (VP8BORDERINPIXELS - 16));
1397bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->mv_row_max =
1407bc9febe8749e98a3812a0dc4380ceae75c29450Johann              ((cm->mb_rows - 1 - mb_row) * 16) + (VP8BORDERINPIXELS - 16);
1417bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1427bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
1437bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
1447bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
1457bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->left_available = (mb_col != 0);
1467bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1477bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->rddiv = cpi->RDDIV;
1487bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->rdmult = cpi->RDMULT;
1497bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1507bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* Copy current mb to a buffer */
1517bc9febe8749e98a3812a0dc4380ceae75c29450Johann          vp8_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16);
1527bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1537bc9febe8749e98a3812a0dc4380ceae75c29450Johann          if (cpi->oxcf.tuning == VP8_TUNE_SSIM) vp8_activity_masking(cpi, x);
1547bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1557bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* Is segmentation enabled */
1567bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* MB level adjustment to quantizer */
1577bc9febe8749e98a3812a0dc4380ceae75c29450Johann          if (xd->segmentation_enabled) {
1587bc9febe8749e98a3812a0dc4380ceae75c29450Johann            /* Code to set segment id in xd->mbmi.segment_id for
1597bc9febe8749e98a3812a0dc4380ceae75c29450Johann             * current MB (with range checking)
1607bc9febe8749e98a3812a0dc4380ceae75c29450Johann             */
1617bc9febe8749e98a3812a0dc4380ceae75c29450Johann            if (cpi->segmentation_map[map_index + mb_col] <= 3) {
1627bc9febe8749e98a3812a0dc4380ceae75c29450Johann              xd->mode_info_context->mbmi.segment_id =
1637bc9febe8749e98a3812a0dc4380ceae75c29450Johann                  cpi->segmentation_map[map_index + mb_col];
1647bc9febe8749e98a3812a0dc4380ceae75c29450Johann            } else {
1657bc9febe8749e98a3812a0dc4380ceae75c29450Johann              xd->mode_info_context->mbmi.segment_id = 0;
1667bc9febe8749e98a3812a0dc4380ceae75c29450Johann            }
1677bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1687bc9febe8749e98a3812a0dc4380ceae75c29450Johann            vp8cx_mb_init_quantizer(cpi, x, 1);
1697bc9febe8749e98a3812a0dc4380ceae75c29450Johann          } else {
1707bc9febe8749e98a3812a0dc4380ceae75c29450Johann            /* Set to Segment 0 by default */
1717bc9febe8749e98a3812a0dc4380ceae75c29450Johann            xd->mode_info_context->mbmi.segment_id = 0;
1727bc9febe8749e98a3812a0dc4380ceae75c29450Johann          }
1737bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1747bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->active_ptr = cpi->active_map + map_index + mb_col;
1757bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1767bc9febe8749e98a3812a0dc4380ceae75c29450Johann          if (cm->frame_type == KEY_FRAME) {
1777bc9febe8749e98a3812a0dc4380ceae75c29450Johann            *totalrate += vp8cx_encode_intra_macroblock(cpi, x, &tp);
17890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#ifdef MODE_STATS
1797bc9febe8749e98a3812a0dc4380ceae75c29450Johann            y_modes[xd->mbmi.mode]++;
18090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
1817bc9febe8749e98a3812a0dc4380ceae75c29450Johann          } else {
1827bc9febe8749e98a3812a0dc4380ceae75c29450Johann            *totalrate += vp8cx_encode_inter_macroblock(
1837bc9febe8749e98a3812a0dc4380ceae75c29450Johann                cpi, x, &tp, recon_yoffset, recon_uvoffset, mb_row, mb_col);
18490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
18590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#ifdef MODE_STATS
1867bc9febe8749e98a3812a0dc4380ceae75c29450Johann            inter_y_modes[xd->mbmi.mode]++;
18790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1887bc9febe8749e98a3812a0dc4380ceae75c29450Johann            if (xd->mbmi.mode == SPLITMV) {
1897bc9febe8749e98a3812a0dc4380ceae75c29450Johann              int b;
19090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1917bc9febe8749e98a3812a0dc4380ceae75c29450Johann              for (b = 0; b < xd->mbmi.partition_count; ++b) {
1927bc9febe8749e98a3812a0dc4380ceae75c29450Johann                inter_b_modes[x->partition->bmi[b].mode]++;
1937bc9febe8749e98a3812a0dc4380ceae75c29450Johann              }
1947bc9febe8749e98a3812a0dc4380ceae75c29450Johann            }
19590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
19679f15823c34ae1e423108295e416213200bb280fAndreas Huber#endif
1977bc9febe8749e98a3812a0dc4380ceae75c29450Johann            // Keep track of how many (consecutive) times a  block
1987bc9febe8749e98a3812a0dc4380ceae75c29450Johann            // is coded as ZEROMV_LASTREF, for base layer frames.
1997bc9febe8749e98a3812a0dc4380ceae75c29450Johann            // Reset to 0 if its coded as anything else.
2007bc9febe8749e98a3812a0dc4380ceae75c29450Johann            if (cpi->current_layer == 0) {
2017bc9febe8749e98a3812a0dc4380ceae75c29450Johann              if (xd->mode_info_context->mbmi.mode == ZEROMV &&
2027bc9febe8749e98a3812a0dc4380ceae75c29450Johann                  xd->mode_info_context->mbmi.ref_frame == LAST_FRAME) {
2037bc9febe8749e98a3812a0dc4380ceae75c29450Johann                // Increment, check for wrap-around.
2047bc9febe8749e98a3812a0dc4380ceae75c29450Johann                if (cpi->consec_zero_last[map_index + mb_col] < 255) {
2057bc9febe8749e98a3812a0dc4380ceae75c29450Johann                  cpi->consec_zero_last[map_index + mb_col] += 1;
2067bc9febe8749e98a3812a0dc4380ceae75c29450Johann                }
2077bc9febe8749e98a3812a0dc4380ceae75c29450Johann                if (cpi->consec_zero_last_mvbias[map_index + mb_col] < 255) {
2087bc9febe8749e98a3812a0dc4380ceae75c29450Johann                  cpi->consec_zero_last_mvbias[map_index + mb_col] += 1;
2097bc9febe8749e98a3812a0dc4380ceae75c29450Johann                }
2107bc9febe8749e98a3812a0dc4380ceae75c29450Johann              } else {
2117bc9febe8749e98a3812a0dc4380ceae75c29450Johann                cpi->consec_zero_last[map_index + mb_col] = 0;
2127bc9febe8749e98a3812a0dc4380ceae75c29450Johann                cpi->consec_zero_last_mvbias[map_index + mb_col] = 0;
2137bc9febe8749e98a3812a0dc4380ceae75c29450Johann              }
2147bc9febe8749e98a3812a0dc4380ceae75c29450Johann              if (x->zero_last_dot_suppress) {
2157bc9febe8749e98a3812a0dc4380ceae75c29450Johann                cpi->consec_zero_last_mvbias[map_index + mb_col] = 0;
2167bc9febe8749e98a3812a0dc4380ceae75c29450Johann              }
2177bc9febe8749e98a3812a0dc4380ceae75c29450Johann            }
2187bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2197bc9febe8749e98a3812a0dc4380ceae75c29450Johann            /* Special case code for cyclic refresh
2207bc9febe8749e98a3812a0dc4380ceae75c29450Johann             * If cyclic update enabled then copy
2217bc9febe8749e98a3812a0dc4380ceae75c29450Johann             * xd->mbmi.segment_id; (which may have been updated
2227bc9febe8749e98a3812a0dc4380ceae75c29450Johann             * based on mode during
2237bc9febe8749e98a3812a0dc4380ceae75c29450Johann             * vp8cx_encode_inter_macroblock()) back into the
2247bc9febe8749e98a3812a0dc4380ceae75c29450Johann             * global segmentation map
2257bc9febe8749e98a3812a0dc4380ceae75c29450Johann             */
2267bc9febe8749e98a3812a0dc4380ceae75c29450Johann            if ((cpi->current_layer == 0) &&
2277bc9febe8749e98a3812a0dc4380ceae75c29450Johann                (cpi->cyclic_refresh_mode_enabled &&
2287bc9febe8749e98a3812a0dc4380ceae75c29450Johann                 xd->segmentation_enabled)) {
2297bc9febe8749e98a3812a0dc4380ceae75c29450Johann              const MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
2307bc9febe8749e98a3812a0dc4380ceae75c29450Johann              cpi->segmentation_map[map_index + mb_col] = mbmi->segment_id;
2317bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2327bc9febe8749e98a3812a0dc4380ceae75c29450Johann              /* If the block has been refreshed mark it as clean
2337bc9febe8749e98a3812a0dc4380ceae75c29450Johann               * (the magnitude of the -ve influences how long it
2347bc9febe8749e98a3812a0dc4380ceae75c29450Johann               * will be before we consider another refresh):
2357bc9febe8749e98a3812a0dc4380ceae75c29450Johann               * Else if it was coded (last frame 0,0) and has
2367bc9febe8749e98a3812a0dc4380ceae75c29450Johann               * not already been refreshed then mark it as a
2377bc9febe8749e98a3812a0dc4380ceae75c29450Johann               * candidate for cleanup next time (marked 0) else
2387bc9febe8749e98a3812a0dc4380ceae75c29450Johann               * mark it as dirty (1).
2397bc9febe8749e98a3812a0dc4380ceae75c29450Johann               */
2407bc9febe8749e98a3812a0dc4380ceae75c29450Johann              if (mbmi->segment_id) {
2417bc9febe8749e98a3812a0dc4380ceae75c29450Johann                cpi->cyclic_refresh_map[map_index + mb_col] = -1;
2427bc9febe8749e98a3812a0dc4380ceae75c29450Johann              } else if ((mbmi->mode == ZEROMV) &&
2437bc9febe8749e98a3812a0dc4380ceae75c29450Johann                         (mbmi->ref_frame == LAST_FRAME)) {
2447bc9febe8749e98a3812a0dc4380ceae75c29450Johann                if (cpi->cyclic_refresh_map[map_index + mb_col] == 1) {
2457bc9febe8749e98a3812a0dc4380ceae75c29450Johann                  cpi->cyclic_refresh_map[map_index + mb_col] = 0;
2467bc9febe8749e98a3812a0dc4380ceae75c29450Johann                }
2477bc9febe8749e98a3812a0dc4380ceae75c29450Johann              } else {
2487bc9febe8749e98a3812a0dc4380ceae75c29450Johann                cpi->cyclic_refresh_map[map_index + mb_col] = 1;
2497bc9febe8749e98a3812a0dc4380ceae75c29450Johann              }
2507bc9febe8749e98a3812a0dc4380ceae75c29450Johann            }
2517bc9febe8749e98a3812a0dc4380ceae75c29450Johann          }
25290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2531b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
2547bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* pack tokens for this MB */
2557bc9febe8749e98a3812a0dc4380ceae75c29450Johann          {
2567bc9febe8749e98a3812a0dc4380ceae75c29450Johann            int tok_count = tp - tp_start;
2577bc9febe8749e98a3812a0dc4380ceae75c29450Johann            vp8_pack_tokens(w, tp_start, tok_count);
2587bc9febe8749e98a3812a0dc4380ceae75c29450Johann          }
2591b362b15af34006e6a11974088a46d42b903418eJohann#else
2607bc9febe8749e98a3812a0dc4380ceae75c29450Johann          cpi->tplist[mb_row].stop = tp;
2611b362b15af34006e6a11974088a46d42b903418eJohann#endif
2627bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* Increment pointer into gf usage flags structure. */
2637bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->gf_active_ptr++;
26490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2657bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* Increment the activity mask pointers. */
2667bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->mb_activity_ptr++;
26790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2687bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* adjust to the next column of macroblocks */
2697bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->src.y_buffer += 16;
2707bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->src.u_buffer += 8;
2717bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->src.v_buffer += 8;
27290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2737bc9febe8749e98a3812a0dc4380ceae75c29450Johann          recon_yoffset += 16;
2747bc9febe8749e98a3812a0dc4380ceae75c29450Johann          recon_uvoffset += 8;
27590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2767bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* Keep track of segment usage */
2777bc9febe8749e98a3812a0dc4380ceae75c29450Johann          segment_counts[xd->mode_info_context->mbmi.segment_id]++;
27879f15823c34ae1e423108295e416213200bb280fAndreas Huber
2797bc9febe8749e98a3812a0dc4380ceae75c29450Johann          /* skip to next mb */
2807bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->mode_info_context++;
2817bc9febe8749e98a3812a0dc4380ceae75c29450Johann          x->partition_info++;
2827bc9febe8749e98a3812a0dc4380ceae75c29450Johann          xd->above_context++;
28390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        }
2847bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2857bc9febe8749e98a3812a0dc4380ceae75c29450Johann        vp8_extend_mb_row(&cm->yv12_fb[dst_fb_idx], xd->dst.y_buffer + 16,
2867bc9febe8749e98a3812a0dc4380ceae75c29450Johann                          xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
2877bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2887bc9febe8749e98a3812a0dc4380ceae75c29450Johann        protected_write(&cpi->pmutex[mb_row], current_mb_col, mb_col + nsync);
2897bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2907bc9febe8749e98a3812a0dc4380ceae75c29450Johann        /* this is to account for the border */
2917bc9febe8749e98a3812a0dc4380ceae75c29450Johann        xd->mode_info_context++;
2927bc9febe8749e98a3812a0dc4380ceae75c29450Johann        x->partition_info++;
2937bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2947bc9febe8749e98a3812a0dc4380ceae75c29450Johann        x->src.y_buffer +=
2957bc9febe8749e98a3812a0dc4380ceae75c29450Johann            16 * x->src.y_stride * (cpi->encoding_thread_count + 1) -
2967bc9febe8749e98a3812a0dc4380ceae75c29450Johann            16 * cm->mb_cols;
2977bc9febe8749e98a3812a0dc4380ceae75c29450Johann        x->src.u_buffer +=
2987bc9febe8749e98a3812a0dc4380ceae75c29450Johann            8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) -
2997bc9febe8749e98a3812a0dc4380ceae75c29450Johann            8 * cm->mb_cols;
3007bc9febe8749e98a3812a0dc4380ceae75c29450Johann        x->src.v_buffer +=
3017bc9febe8749e98a3812a0dc4380ceae75c29450Johann            8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) -
3027bc9febe8749e98a3812a0dc4380ceae75c29450Johann            8 * cm->mb_cols;
3037bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3047bc9febe8749e98a3812a0dc4380ceae75c29450Johann        xd->mode_info_context +=
3057bc9febe8749e98a3812a0dc4380ceae75c29450Johann            xd->mode_info_stride * cpi->encoding_thread_count;
3067bc9febe8749e98a3812a0dc4380ceae75c29450Johann        x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
3077bc9febe8749e98a3812a0dc4380ceae75c29450Johann        x->gf_active_ptr += cm->mb_cols * cpi->encoding_thread_count;
3087bc9febe8749e98a3812a0dc4380ceae75c29450Johann      }
3097bc9febe8749e98a3812a0dc4380ceae75c29450Johann      /* Signal that this thread has completed processing its rows. */
3107bc9febe8749e98a3812a0dc4380ceae75c29450Johann      sem_post(&cpi->h_event_end_encoding[ithread]);
31190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    }
3127bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
31390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3147bc9febe8749e98a3812a0dc4380ceae75c29450Johann  /* printf("exit thread %d\n", ithread); */
3157bc9febe8749e98a3812a0dc4380ceae75c29450Johann  return 0;
31690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
31790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3187bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc) {
3197bc9febe8749e98a3812a0dc4380ceae75c29450Johann  MACROBLOCK *x = mbsrc;
3207bc9febe8749e98a3812a0dc4380ceae75c29450Johann  MACROBLOCK *z = mbdst;
3217bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int i;
3227bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3237bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->ss = x->ss;
3247bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->ss_count = x->ss_count;
3257bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->searches_per_step = x->searches_per_step;
3267bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->errorperbit = x->errorperbit;
3277bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3287bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->sadperbit16 = x->sadperbit16;
3297bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->sadperbit4 = x->sadperbit4;
3307bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3317bc9febe8749e98a3812a0dc4380ceae75c29450Johann  /*
3327bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mv_col_min    = x->mv_col_min;
3337bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mv_col_max    = x->mv_col_max;
3347bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mv_row_min    = x->mv_row_min;
3357bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mv_row_max    = x->mv_row_max;
3367bc9febe8749e98a3812a0dc4380ceae75c29450Johann  */
3377bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3387bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->short_fdct4x4 = x->short_fdct4x4;
3397bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->short_fdct8x4 = x->short_fdct8x4;
3407bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->short_walsh4x4 = x->short_walsh4x4;
3417bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->quantize_b = x->quantize_b;
3427bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->optimize = x->optimize;
3437bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3447bc9febe8749e98a3812a0dc4380ceae75c29450Johann  /*
3457bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mvc              = x->mvc;
3467bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->src.y_buffer      = x->src.y_buffer;
3477bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->src.u_buffer      = x->src.u_buffer;
3487bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->src.v_buffer      = x->src.v_buffer;
3497bc9febe8749e98a3812a0dc4380ceae75c29450Johann  */
3507bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3517bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mvcost[0] = x->mvcost[0];
3527bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mvcost[1] = x->mvcost[1];
3537bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mvsadcost[0] = x->mvsadcost[0];
3547bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mvsadcost[1] = x->mvsadcost[1];
3557bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3567bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->token_costs = x->token_costs;
3577bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->inter_bmode_costs = x->inter_bmode_costs;
3587bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->mbmode_cost = x->mbmode_cost;
3597bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->intra_uv_mode_cost = x->intra_uv_mode_cost;
3607bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->bmode_costs = x->bmode_costs;
3617bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3627bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 0; i < 25; ++i) {
3637bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->block[i].quant = x->block[i].quant;
3647bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->block[i].quant_fast = x->block[i].quant_fast;
3657bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->block[i].quant_shift = x->block[i].quant_shift;
3667bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->block[i].zbin = x->block[i].zbin;
3677bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->block[i].zrun_zbin_boost = x->block[i].zrun_zbin_boost;
3687bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->block[i].round = x->block[i].round;
3697bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->block[i].src_stride = x->block[i].src_stride;
3707bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
3717bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3727bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->q_index = x->q_index;
3737bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->act_zbin_adj = x->act_zbin_adj;
3747bc9febe8749e98a3812a0dc4380ceae75c29450Johann  z->last_act_zbin_adj = x->last_act_zbin_adj;
3757bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3767bc9febe8749e98a3812a0dc4380ceae75c29450Johann  {
3777bc9febe8749e98a3812a0dc4380ceae75c29450Johann    MACROBLOCKD *xd = &x->e_mbd;
3787bc9febe8749e98a3812a0dc4380ceae75c29450Johann    MACROBLOCKD *zd = &z->e_mbd;
37990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
38090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    /*
3817bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mode_info_context = xd->mode_info_context;
3827bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mode_info        = xd->mode_info;
3837bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3847bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mode_info_stride  = xd->mode_info_stride;
3857bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->frame_type       = xd->frame_type;
3867bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->up_available     = xd->up_available   ;
3877bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->left_available   = xd->left_available;
3887bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->left_context     = xd->left_context;
3897bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->last_frame_dc     = xd->last_frame_dc;
3907bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->last_frame_dccons = xd->last_frame_dccons;
3917bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->gold_frame_dc     = xd->gold_frame_dc;
3927bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->gold_frame_dccons = xd->gold_frame_dccons;
3937bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mb_to_left_edge    = xd->mb_to_left_edge;
3947bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mb_to_right_edge   = xd->mb_to_right_edge;
3957bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mb_to_top_edge     = xd->mb_to_top_edge   ;
3967bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mb_to_bottom_edge  = xd->mb_to_bottom_edge;
3977bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->gf_active_ptr     = xd->gf_active_ptr;
3987bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->frames_since_golden       = xd->frames_since_golden;
3997bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->frames_till_alt_ref_frame   = xd->frames_till_alt_ref_frame;
40090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    */
4017bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->subpixel_predict = xd->subpixel_predict;
4027bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->subpixel_predict8x4 = xd->subpixel_predict8x4;
4037bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->subpixel_predict8x8 = xd->subpixel_predict8x8;
4047bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->subpixel_predict16x16 = xd->subpixel_predict16x16;
4057bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->segmentation_enabled = xd->segmentation_enabled;
4067bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->mb_segement_abs_delta = xd->mb_segement_abs_delta;
4077bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(zd->segment_feature_data, xd->segment_feature_data,
4087bc9febe8749e98a3812a0dc4380ceae75c29450Johann           sizeof(xd->segment_feature_data));
4097bc9febe8749e98a3812a0dc4380ceae75c29450Johann
4107bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(zd->dequant_y1_dc, xd->dequant_y1_dc, sizeof(xd->dequant_y1_dc));
4117bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(zd->dequant_y1, xd->dequant_y1, sizeof(xd->dequant_y1));
4127bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(zd->dequant_y2, xd->dequant_y2, sizeof(xd->dequant_y2));
4137bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(zd->dequant_uv, xd->dequant_uv, sizeof(xd->dequant_uv));
4141b362b15af34006e6a11974088a46d42b903418eJohann
4151b362b15af34006e6a11974088a46d42b903418eJohann#if 1
4167bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /*TODO:  Remove dequant from BLOCKD.  This is a temporary solution until
4177bc9febe8749e98a3812a0dc4380ceae75c29450Johann     * the quantizer code uses a passed in pointer to the dequant constants.
4187bc9febe8749e98a3812a0dc4380ceae75c29450Johann     * This will also require modifications to the x86 and neon assembly.
4197bc9febe8749e98a3812a0dc4380ceae75c29450Johann     * */
4207bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (i = 0; i < 16; ++i) zd->block[i].dequant = zd->dequant_y1;
4217bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (i = 16; i < 24; ++i) zd->block[i].dequant = zd->dequant_uv;
4227bc9febe8749e98a3812a0dc4380ceae75c29450Johann    zd->block[24].dequant = zd->dequant_y2;
4231b362b15af34006e6a11974088a46d42b903418eJohann#endif
424ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
4257bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(z->rd_threshes, x->rd_threshes, sizeof(x->rd_threshes));
4267bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(z->rd_thresh_mult, x->rd_thresh_mult, sizeof(x->rd_thresh_mult));
427ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
4287bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->zbin_over_quant = x->zbin_over_quant;
4297bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->zbin_mode_boost_enabled = x->zbin_mode_boost_enabled;
4307bc9febe8749e98a3812a0dc4380ceae75c29450Johann    z->zbin_mode_boost = x->zbin_mode_boost;
431ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
4327bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memset(z->error_bins, 0, sizeof(z->error_bins));
4337bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
43490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
43590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4367bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8cx_init_mbrthread_data(VP8_COMP *cpi, MACROBLOCK *x,
4377bc9febe8749e98a3812a0dc4380ceae75c29450Johann                               MB_ROW_COMP *mbr_ei, int count) {
4387bc9febe8749e98a3812a0dc4380ceae75c29450Johann  VP8_COMMON *const cm = &cpi->common;
4397bc9febe8749e98a3812a0dc4380ceae75c29450Johann  MACROBLOCKD *const xd = &x->e_mbd;
4407bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int i;
44190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4427bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 0; i < count; ++i) {
4437bc9febe8749e98a3812a0dc4380ceae75c29450Johann    MACROBLOCK *mb = &mbr_ei[i].mb;
4447bc9febe8749e98a3812a0dc4380ceae75c29450Johann    MACROBLOCKD *mbd = &mb->e_mbd;
44590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4467bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->subpixel_predict = xd->subpixel_predict;
4477bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->subpixel_predict8x4 = xd->subpixel_predict8x4;
4487bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->subpixel_predict8x8 = xd->subpixel_predict8x8;
4497bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->subpixel_predict16x16 = xd->subpixel_predict16x16;
4507bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->gf_active_ptr = x->gf_active_ptr;
45190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4527bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memset(mbr_ei[i].segment_counts, 0, sizeof(mbr_ei[i].segment_counts));
4537bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbr_ei[i].totalrate = 0;
45490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4557bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->partition_info = x->pi + x->e_mbd.mode_info_stride * (i + 1);
456f71323e297a928af368937089d3ed71239786f86Andreas Huber
4577bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->frame_type = cm->frame_type;
45890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4597bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->src = *cpi->Source;
4607bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->pre = cm->yv12_fb[cm->lst_fb_idx];
4617bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->dst = cm->yv12_fb[cm->new_fb_idx];
46290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4637bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->src.y_buffer += 16 * x->src.y_stride * (i + 1);
4647bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->src.u_buffer += 8 * x->src.uv_stride * (i + 1);
4657bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->src.v_buffer += 8 * x->src.uv_stride * (i + 1);
46690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4677bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_build_block_offsets(mb);
46890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4697bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->left_context = &cm->left_context;
4707bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->mvc = cm->fc.mvc;
47190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4727bc9febe8749e98a3812a0dc4380ceae75c29450Johann    setup_mbby_copy(&mbr_ei[i].mb, x);
47390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4747bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mbd->fullpixel_mask = 0xffffffff;
4757bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (cm->full_pixel) mbd->fullpixel_mask = 0xfffffff8;
4761b362b15af34006e6a11974088a46d42b903418eJohann
4777bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_zero(mb->coef_counts);
4787bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_zero(x->ymode_count);
4797bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->skip_true_count = 0;
4807bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_zero(mb->MVcount);
4817bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->prediction_error = 0;
4827bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->intra_error = 0;
4837bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_zero(mb->count_mb_ref_frame_usage);
4847bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->mbs_tested_so_far = 0;
4857bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mb->mbs_zero_last_dot_suppress = 0;
4867bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
48790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
48890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4897bc9febe8749e98a3812a0dc4380ceae75c29450Johannint vp8cx_create_encoder_threads(VP8_COMP *cpi) {
4907bc9febe8749e98a3812a0dc4380ceae75c29450Johann  const VP8_COMMON *cm = &cpi->common;
49190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4927bc9febe8749e98a3812a0dc4380ceae75c29450Johann  cpi->b_multi_threaded = 0;
4937bc9febe8749e98a3812a0dc4380ceae75c29450Johann  cpi->encoding_thread_count = 0;
4947bc9febe8749e98a3812a0dc4380ceae75c29450Johann  cpi->b_lpf_running = 0;
49590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4967bc9febe8749e98a3812a0dc4380ceae75c29450Johann  pthread_mutex_init(&cpi->mt_mutex, NULL);
49790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4987bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (cm->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1) {
4997bc9febe8749e98a3812a0dc4380ceae75c29450Johann    int ithread;
5007bc9febe8749e98a3812a0dc4380ceae75c29450Johann    int th_count = cpi->oxcf.multi_threaded - 1;
5017bc9febe8749e98a3812a0dc4380ceae75c29450Johann    int rc = 0;
5021b362b15af34006e6a11974088a46d42b903418eJohann
5037bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /* don't allocate more threads than cores available */
5047bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (cpi->oxcf.multi_threaded > cm->processor_core_count) {
5057bc9febe8749e98a3812a0dc4380ceae75c29450Johann      th_count = cm->processor_core_count - 1;
5067bc9febe8749e98a3812a0dc4380ceae75c29450Johann    }
5071b362b15af34006e6a11974088a46d42b903418eJohann
5087bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /* we have th_count + 1 (main) threads processing one row each */
5097bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /* no point to have more threads than the sync range allows */
5107bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (th_count > ((cm->mb_cols / cpi->mt_sync_range) - 1)) {
5117bc9febe8749e98a3812a0dc4380ceae75c29450Johann      th_count = (cm->mb_cols / cpi->mt_sync_range) - 1;
5127bc9febe8749e98a3812a0dc4380ceae75c29450Johann    }
5131b362b15af34006e6a11974088a46d42b903418eJohann
5147bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (th_count == 0) return 0;
5151b362b15af34006e6a11974088a46d42b903418eJohann
5167bc9febe8749e98a3812a0dc4380ceae75c29450Johann    CHECK_MEM_ERROR(cpi->h_encoding_thread,
5177bc9febe8749e98a3812a0dc4380ceae75c29450Johann                    vpx_malloc(sizeof(pthread_t) * th_count));
5187bc9febe8749e98a3812a0dc4380ceae75c29450Johann    CHECK_MEM_ERROR(cpi->h_event_start_encoding,
5197bc9febe8749e98a3812a0dc4380ceae75c29450Johann                    vpx_malloc(sizeof(sem_t) * th_count));
5207bc9febe8749e98a3812a0dc4380ceae75c29450Johann    CHECK_MEM_ERROR(cpi->h_event_end_encoding,
5217bc9febe8749e98a3812a0dc4380ceae75c29450Johann                    vpx_malloc(sizeof(sem_t) * th_count));
5227bc9febe8749e98a3812a0dc4380ceae75c29450Johann    CHECK_MEM_ERROR(cpi->mb_row_ei,
5237bc9febe8749e98a3812a0dc4380ceae75c29450Johann                    vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count));
5247bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count);
5257bc9febe8749e98a3812a0dc4380ceae75c29450Johann    CHECK_MEM_ERROR(cpi->en_thread_data,
5267bc9febe8749e98a3812a0dc4380ceae75c29450Johann                    vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count));
52768e1c830ade592be74773e249bf94e2bbfb50de7Johann
5287bc9febe8749e98a3812a0dc4380ceae75c29450Johann    cpi->b_multi_threaded = 1;
5297bc9febe8749e98a3812a0dc4380ceae75c29450Johann    cpi->encoding_thread_count = th_count;
53090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5317bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /*
5327bc9febe8749e98a3812a0dc4380ceae75c29450Johann    printf("[VP8:] multi_threaded encoding is enabled with %d threads\n\n",
5337bc9febe8749e98a3812a0dc4380ceae75c29450Johann           (cpi->encoding_thread_count +1));
5347bc9febe8749e98a3812a0dc4380ceae75c29450Johann    */
5351b362b15af34006e6a11974088a46d42b903418eJohann
5367bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (ithread = 0; ithread < th_count; ++ithread) {
5377bc9febe8749e98a3812a0dc4380ceae75c29450Johann      ENCODETHREAD_DATA *ethd = &cpi->en_thread_data[ithread];
53890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5397bc9febe8749e98a3812a0dc4380ceae75c29450Johann      /* Setup block ptrs and offsets */
5407bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vp8_setup_block_ptrs(&cpi->mb_row_ei[ithread].mb);
5417bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vp8_setup_block_dptrs(&cpi->mb_row_ei[ithread].mb.e_mbd);
54290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5437bc9febe8749e98a3812a0dc4380ceae75c29450Johann      sem_init(&cpi->h_event_start_encoding[ithread], 0, 0);
5447bc9febe8749e98a3812a0dc4380ceae75c29450Johann      sem_init(&cpi->h_event_end_encoding[ithread], 0, 0);
5451b362b15af34006e6a11974088a46d42b903418eJohann
5467bc9febe8749e98a3812a0dc4380ceae75c29450Johann      ethd->ithread = ithread;
5477bc9febe8749e98a3812a0dc4380ceae75c29450Johann      ethd->ptr1 = (void *)cpi;
5487bc9febe8749e98a3812a0dc4380ceae75c29450Johann      ethd->ptr2 = (void *)&cpi->mb_row_ei[ithread];
5491b362b15af34006e6a11974088a46d42b903418eJohann
5507bc9febe8749e98a3812a0dc4380ceae75c29450Johann      rc = pthread_create(&cpi->h_encoding_thread[ithread], 0,
5517bc9febe8749e98a3812a0dc4380ceae75c29450Johann                          thread_encoding_proc, ethd);
5527bc9febe8749e98a3812a0dc4380ceae75c29450Johann      if (rc) break;
5537bc9febe8749e98a3812a0dc4380ceae75c29450Johann    }
55468e1c830ade592be74773e249bf94e2bbfb50de7Johann
5557bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (rc) {
5567bc9febe8749e98a3812a0dc4380ceae75c29450Johann      /* shutdown other threads */
5577bc9febe8749e98a3812a0dc4380ceae75c29450Johann      protected_write(&cpi->mt_mutex, &cpi->b_multi_threaded, 0);
5587bc9febe8749e98a3812a0dc4380ceae75c29450Johann      for (--ithread; ithread >= 0; ithread--) {
5597bc9febe8749e98a3812a0dc4380ceae75c29450Johann        pthread_join(cpi->h_encoding_thread[ithread], 0);
5607bc9febe8749e98a3812a0dc4380ceae75c29450Johann        sem_destroy(&cpi->h_event_start_encoding[ithread]);
5617bc9febe8749e98a3812a0dc4380ceae75c29450Johann        sem_destroy(&cpi->h_event_end_encoding[ithread]);
5627bc9febe8749e98a3812a0dc4380ceae75c29450Johann      }
5637bc9febe8749e98a3812a0dc4380ceae75c29450Johann
5647bc9febe8749e98a3812a0dc4380ceae75c29450Johann      /* free thread related resources */
5657bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vpx_free(cpi->h_event_start_encoding);
5667bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vpx_free(cpi->h_event_end_encoding);
5677bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vpx_free(cpi->h_encoding_thread);
5687bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vpx_free(cpi->mb_row_ei);
5697bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vpx_free(cpi->en_thread_data);
5707bc9febe8749e98a3812a0dc4380ceae75c29450Johann
5717bc9febe8749e98a3812a0dc4380ceae75c29450Johann      pthread_mutex_destroy(&cpi->mt_mutex);
5727bc9febe8749e98a3812a0dc4380ceae75c29450Johann
5737bc9febe8749e98a3812a0dc4380ceae75c29450Johann      return -1;
57490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    }
57590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
57690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    {
5777bc9febe8749e98a3812a0dc4380ceae75c29450Johann      LPFTHREAD_DATA *lpfthd = &cpi->lpf_thread_data;
57890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5797bc9febe8749e98a3812a0dc4380ceae75c29450Johann      sem_init(&cpi->h_event_start_lpf, 0, 0);
5807bc9febe8749e98a3812a0dc4380ceae75c29450Johann      sem_init(&cpi->h_event_end_lpf, 0, 0);
58179f15823c34ae1e423108295e416213200bb280fAndreas Huber
5827bc9febe8749e98a3812a0dc4380ceae75c29450Johann      lpfthd->ptr1 = (void *)cpi;
5837bc9febe8749e98a3812a0dc4380ceae75c29450Johann      rc = pthread_create(&cpi->h_filter_thread, 0, thread_loopfilter, lpfthd);
58490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5857bc9febe8749e98a3812a0dc4380ceae75c29450Johann      if (rc) {
5867bc9febe8749e98a3812a0dc4380ceae75c29450Johann        /* shutdown other threads */
5877bc9febe8749e98a3812a0dc4380ceae75c29450Johann        protected_write(&cpi->mt_mutex, &cpi->b_multi_threaded, 0);
5887bc9febe8749e98a3812a0dc4380ceae75c29450Johann        for (--ithread; ithread >= 0; ithread--) {
5897bc9febe8749e98a3812a0dc4380ceae75c29450Johann          sem_post(&cpi->h_event_start_encoding[ithread]);
5907bc9febe8749e98a3812a0dc4380ceae75c29450Johann          sem_post(&cpi->h_event_end_encoding[ithread]);
5917bc9febe8749e98a3812a0dc4380ceae75c29450Johann          pthread_join(cpi->h_encoding_thread[ithread], 0);
5927bc9febe8749e98a3812a0dc4380ceae75c29450Johann          sem_destroy(&cpi->h_event_start_encoding[ithread]);
5937bc9febe8749e98a3812a0dc4380ceae75c29450Johann          sem_destroy(&cpi->h_event_end_encoding[ithread]);
59490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        }
59579f15823c34ae1e423108295e416213200bb280fAndreas Huber        sem_destroy(&cpi->h_event_end_lpf);
59679f15823c34ae1e423108295e416213200bb280fAndreas Huber        sem_destroy(&cpi->h_event_start_lpf);
59779f15823c34ae1e423108295e416213200bb280fAndreas Huber
5981b362b15af34006e6a11974088a46d42b903418eJohann        /* free thread related resources */
59979f15823c34ae1e423108295e416213200bb280fAndreas Huber        vpx_free(cpi->h_event_start_encoding);
6007bc9febe8749e98a3812a0dc4380ceae75c29450Johann        vpx_free(cpi->h_event_end_encoding);
60190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        vpx_free(cpi->h_encoding_thread);
60290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        vpx_free(cpi->mb_row_ei);
60390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        vpx_free(cpi->en_thread_data);
6047bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6057bc9febe8749e98a3812a0dc4380ceae75c29450Johann        pthread_mutex_destroy(&cpi->mt_mutex);
6067bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6077bc9febe8749e98a3812a0dc4380ceae75c29450Johann        return -2;
6087bc9febe8749e98a3812a0dc4380ceae75c29450Johann      }
60990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    }
6107bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
6117bc9febe8749e98a3812a0dc4380ceae75c29450Johann  return 0;
6127bc9febe8749e98a3812a0dc4380ceae75c29450Johann}
6137bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6147bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8cx_remove_encoder_threads(VP8_COMP *cpi) {
6157bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (protected_read(&cpi->mt_mutex, &cpi->b_multi_threaded)) {
6167bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /* shutdown other threads */
6177bc9febe8749e98a3812a0dc4380ceae75c29450Johann    protected_write(&cpi->mt_mutex, &cpi->b_multi_threaded, 0);
6187bc9febe8749e98a3812a0dc4380ceae75c29450Johann    {
6197bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int i;
6207bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6217bc9febe8749e98a3812a0dc4380ceae75c29450Johann      for (i = 0; i < cpi->encoding_thread_count; ++i) {
6227bc9febe8749e98a3812a0dc4380ceae75c29450Johann        sem_post(&cpi->h_event_start_encoding[i]);
6237bc9febe8749e98a3812a0dc4380ceae75c29450Johann        sem_post(&cpi->h_event_end_encoding[i]);
6247bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6257bc9febe8749e98a3812a0dc4380ceae75c29450Johann        pthread_join(cpi->h_encoding_thread[i], 0);
6267bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6277bc9febe8749e98a3812a0dc4380ceae75c29450Johann        sem_destroy(&cpi->h_event_start_encoding[i]);
6287bc9febe8749e98a3812a0dc4380ceae75c29450Johann        sem_destroy(&cpi->h_event_end_encoding[i]);
6297bc9febe8749e98a3812a0dc4380ceae75c29450Johann      }
6307bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6317bc9febe8749e98a3812a0dc4380ceae75c29450Johann      sem_post(&cpi->h_event_start_lpf);
6327bc9febe8749e98a3812a0dc4380ceae75c29450Johann      pthread_join(cpi->h_filter_thread, 0);
6337bc9febe8749e98a3812a0dc4380ceae75c29450Johann    }
6347bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6357bc9febe8749e98a3812a0dc4380ceae75c29450Johann    sem_destroy(&cpi->h_event_end_lpf);
6367bc9febe8749e98a3812a0dc4380ceae75c29450Johann    sem_destroy(&cpi->h_event_start_lpf);
6377bc9febe8749e98a3812a0dc4380ceae75c29450Johann
6387bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /* free thread related resources */
6397bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vpx_free(cpi->h_event_start_encoding);
6407bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vpx_free(cpi->h_event_end_encoding);
6417bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vpx_free(cpi->h_encoding_thread);
6427bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vpx_free(cpi->mb_row_ei);
6437bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vpx_free(cpi->en_thread_data);
6447bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
6457bc9febe8749e98a3812a0dc4380ceae75c29450Johann  pthread_mutex_destroy(&cpi->mt_mutex);
64690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
64779f15823c34ae1e423108295e416213200bb280fAndreas Huber#endif
648