Merge branch 'origin/eider' into master
authorJohn Koleszar <jkoleszar@google.com>
Fri, 11 May 2012 17:51:05 +0000 (10:51 -0700)
committerJohn Koleszar <jkoleszar@google.com>
Fri, 11 May 2012 17:51:05 +0000 (10:51 -0700)
Conflicts:
vp8/common/entropymode.c
vp8/common/entropymode.h
vp8/encoder/encodeframe.c
vp8/vp8_cx_iface.c

Change-Id: I708b0f30449b9502b382e47b745d56f5ed2ce265

14 files changed:
1  2 
configure
libs.mk
vp8/common/entropymode.c
vp8/common/entropymode.h
vp8/decoder/decodframe.c
vp8/decoder/threading.c
vp8/encoder/bitstream.c
vp8/encoder/encodeframe.c
vp8/encoder/ethreading.c
vp8/encoder/onyx_if.c
vp8/encoder/onyx_int.h
vp8/encoder/temporal_filter.c
vp8/vp8_cx_iface.c
vp8/vp8cx.mk

diff --combined configure
+++ b/configure
@@@ -109,6 -109,8 +109,8 @@@ all_platforms="${all_platforms} x86-dar
  all_platforms="${all_platforms} x86-darwin9-gcc"
  all_platforms="${all_platforms} x86-darwin9-icc"
  all_platforms="${all_platforms} x86-darwin10-gcc"
+ all_platforms="${all_platforms} x86-darwin11-gcc"
+ all_platforms="${all_platforms} x86-darwin12-gcc"
  all_platforms="${all_platforms} x86-linux-gcc"
  all_platforms="${all_platforms} x86-linux-icc"
  all_platforms="${all_platforms} x86-os2-gcc"
@@@ -120,6 -122,7 +122,7 @@@ all_platforms="${all_platforms} x86-win
  all_platforms="${all_platforms} x86_64-darwin9-gcc"
  all_platforms="${all_platforms} x86_64-darwin10-gcc"
  all_platforms="${all_platforms} x86_64-darwin11-gcc"
+ all_platforms="${all_platforms} x86_64-darwin12-gcc"
  all_platforms="${all_platforms} x86_64-linux-gcc"
  all_platforms="${all_platforms} x86_64-linux-icc"
  all_platforms="${all_platforms} x86_64-solaris-gcc"
@@@ -128,6 -131,9 +131,9 @@@ all_platforms="${all_platforms} x86_64-
  all_platforms="${all_platforms} x86_64-win64-vs9"
  all_platforms="${all_platforms} universal-darwin8-gcc"
  all_platforms="${all_platforms} universal-darwin9-gcc"
+ all_platforms="${all_platforms} universal-darwin10-gcc"
+ all_platforms="${all_platforms} universal-darwin11-gcc"
+ all_platforms="${all_platforms} universal-darwin12-gcc"
  all_platforms="${all_platforms} generic-gnu"
  
  # all_targets is a list of all targets that can be configured
@@@ -493,11 -499,20 +499,20 @@@ process_toolchain() 
      case $toolchain in
          universal-darwin*)
              local darwin_ver=${tgt_os##darwin}
-             fat_bin_archs="$fat_bin_archs ppc32-${tgt_os}-gcc"
  
-             # Intel
-             fat_bin_archs="$fat_bin_archs x86-${tgt_os}-${tgt_cc}"
-             if [ $darwin_ver -gt 8 ]; then
+             # Snow Leopard (10.6/darwin10) dropped support for PPC
+             # Include PPC support for all prior versions
+             if [ $darwin_ver -lt 10 ]; then
+                 fat_bin_archs="$fat_bin_archs ppc32-${tgt_os}-gcc"
+             fi
+             # Tiger (10.4/darwin8) brought support for x86
+             if [ $darwin_ver -ge 8 ]; then
+                 fat_bin_archs="$fat_bin_archs x86-${tgt_os}-${tgt_cc}"
+             fi
+             # Leopard (10.5/darwin9) brought 64 bit support
+             if [ $darwin_ver -ge 9 ]; then
                  fat_bin_archs="$fat_bin_archs x86_64-${tgt_os}-${tgt_cc}"
              fi
              ;;
          check_add_cflags -Wpointer-arith
          check_add_cflags -Wtype-limits
          check_add_cflags -Wcast-qual
 -        check_add_cflags -Wunused-but-set-variable        
+         check_add_cflags -Wimplicit-function-declaration
+         check_add_cflags -Wuninitialized
+         check_add_cflags -Wunused-variable
++        check_add_cflags -Wunused-but-set-variable
          enabled extra_warnings || check_add_cflags -Wno-unused-function
      fi
  
diff --combined libs.mk
+++ b/libs.mk
@@@ -35,9 -35,9 +35,9 @@@ ifeq ($(CONFIG_VP8_ENCODER),yes
    include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8cx.mk
    CODEC_SRCS-yes += $(addprefix $(VP8_PREFIX),$(call enabled,VP8_CX_SRCS))
    CODEC_EXPORTS-yes += $(addprefix $(VP8_PREFIX),$(VP8_CX_EXPORTS))
-   CODEC_SRCS-yes += $(VP8_PREFIX)vp8cx.mk vpx/vp8.h vpx/vp8cx.h vpx/vp8e.h
+   CODEC_SRCS-yes += $(VP8_PREFIX)vp8cx.mk vpx/vp8.h vpx/vp8cx.h
    CODEC_SRCS-$(ARCH_ARM) += $(VP8_PREFIX)vp8cx_arm.mk
-   INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8e.h include/vpx/vp8cx.h
+   INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8cx.h
    INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP8_PREFIX)/%
    CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8cx.h
    CODEC_DOC_SECTIONS += vp8 vp8_encoder
@@@ -66,7 -66,6 +66,7 @@@ endi
  
  ifeq ($(CONFIG_MSVS),yes)
  CODEC_LIB=$(if $(CONFIG_STATIC_MSVCRT),vpxmt,vpxmd)
 +GTEST_LIB=$(if $(CONFIG_STATIC_MSVCRT),gtestmt,gtestmd)
  # This variable uses deferred expansion intentionally, since the results of
  # $(wildcard) may change during the course of the Make.
  VS_PLATFORMS = $(foreach d,$(wildcard */Release/$(CODEC_LIB).lib),$(word 1,$(subst /, ,$(d))))
@@@ -116,7 -115,6 +116,6 @@@ INSTALL-LIBS-yes += include/vpx/vpx_int
  INSTALL-LIBS-yes += include/vpx/vpx_codec_impl_top.h
  INSTALL-LIBS-yes += include/vpx/vpx_codec_impl_bottom.h
  INSTALL-LIBS-$(CONFIG_DECODERS) += include/vpx/vpx_decoder.h
- INSTALL-LIBS-$(CONFIG_DECODERS) += include/vpx/vpx_decoder_compat.h
  INSTALL-LIBS-$(CONFIG_ENCODERS) += include/vpx/vpx_encoder.h
  ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
  ifeq ($(CONFIG_MSVS),yes)
@@@ -235,7 -233,7 +234,7 @@@ vpx.pc: config.mk libs.m
        $(qexec)echo '# pkg-config file from libvpx $(VERSION_STRING)' > $@
        $(qexec)echo 'prefix=$(PREFIX)' >> $@
        $(qexec)echo 'exec_prefix=$${prefix}' >> $@
-       $(qexec)echo 'libdir=$${prefix}/lib' >> $@
+       $(qexec)echo 'libdir=$${prefix}/$(LIBSUBDIR)' >> $@
        $(qexec)echo 'includedir=$${prefix}/include' >> $@
        $(qexec)echo '' >> $@
        $(qexec)echo 'Name: vpx' >> $@
@@@ -381,7 -379,7 +380,7 @@@ $(notdir $(1:.cc=.vcproj)): $(SRC_PATH_
              $$(if $$(CONFIG_STATIC_MSVCRT),--static-crt) \
              --out=$$@ $$(INTERNAL_CFLAGS) $$(CFLAGS) \
              -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
 -            -L. -lvpxmt -lwinmm -lgtestmt $$^
 +            -L. -l$(CODEC_LIB) -lwinmm -l$(GTEST_LIB) $$^
  endef
  
  $(foreach proj,$(LIBVPX_TEST_BINS),\
diff --combined vp8/common/entropymode.c
@@@ -160,7 -160,9 +160,7 @@@ const vp8_tree_index vp8_small_mvtree [
  void vp8_init_mbmode_probs(VP8_COMMON *x)
  {
      vpx_memcpy(x->fc.ymode_prob, vp8_ymode_prob, sizeof(vp8_ymode_prob));
 -    vpx_memcpy(x->kf_ymode_prob, vp8_kf_ymode_prob, sizeof(vp8_kf_ymode_prob));
      vpx_memcpy(x->fc.uv_mode_prob, vp8_uv_mode_prob, sizeof(vp8_uv_mode_prob));
 -    vpx_memcpy(x->kf_uv_mode_prob, vp8_kf_uv_mode_prob, sizeof(vp8_kf_uv_mode_prob));
      vpx_memcpy(x->fc.sub_mv_ref_prob, sub_mv_ref_prob, sizeof(sub_mv_ref_prob));
  }
  
@@@ -169,4 -171,7 +169,3 @@@ void vp8_default_bmode_probs(vp8_prob 
      vpx_memcpy(p, vp8_bmode_prob, sizeof(vp8_bmode_prob));
  }
  
 -void vp8_kf_default_bmode_probs(vp8_prob p [VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES-1])
 -{
 -    vpx_memcpy(p, vp8_kf_bmode_prob, sizeof(vp8_kf_bmode_prob));
 -}
diff --combined vp8/common/entropymode.h
@@@ -67,15 -67,9 +67,14 @@@ extern const vp8_tree_index vp8_small_m
  
  extern const struct vp8_token_struct vp8_small_mvencodings[8];
  
 -void vp8_init_mbmode_probs(VP8_COMMON *x);
 +/* Key frame default mode probs */
 +extern const vp8_prob vp8_kf_bmode_prob[VP8_BINTRAMODES][VP8_BINTRAMODES]
 +[VP8_BINTRAMODES-1];
 +extern const vp8_prob vp8_kf_uv_mode_prob[VP8_UV_MODES-1];
 +extern const vp8_prob vp8_kf_ymode_prob[VP8_YMODES-1];
  
 -void   vp8_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES-1]);
 +void vp8_init_mbmode_probs(VP8_COMMON *x);
 +void vp8_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES-1]);
  void vp8_kf_default_bmode_probs(vp8_prob dest [VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES-1]);
  
  #endif
diff --combined vp8/decoder/decodframe.c
@@@ -53,7 -53,7 +53,7 @@@ void vp8cx_init_de_quantizer(VP8D_COMP 
      }
  }
  
- void mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd)
+ void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd)
  {
      int i;
      int QIndex;
@@@ -117,7 -117,7 +117,7 @@@ static void decode_macroblock(VP8D_COM
      mode = xd->mode_info_context->mbmi.mode;
  
      if (xd->segmentation_enabled)
-         mb_init_dequantizer(pbi, xd);
+         vp8_mb_init_dequantizer(pbi, xd);
  
  
  #if CONFIG_ERROR_CONCEALMENT
@@@ -507,7 -507,7 +507,7 @@@ static unsigned int read_available_part
  {
      VP8_COMMON* pc = &pbi->common;
      const unsigned char *partition_size_ptr = token_part_sizes + i * 3;
-     unsigned int partition_size;
+     unsigned int partition_size = 0;
      ptrdiff_t bytes_left = fragment_end - fragment_start;
      /* Calculate the length of this partition. The last partition
       * size is implicit. If the partition size can't be read, then
@@@ -661,6 -661,7 +661,6 @@@ static void init_frame(VP8D_COMP *pbi
          vp8_init_mbmode_probs(pc);
  
          vp8_default_coef_probs(pc);
 -        vp8_kf_default_bmode_probs(pc->kf_bmode_prob);
  
          /* reset the segment feature data to 0 with delta coding (Default state). */
          vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
      }
      else
      {
 -        if (!pc->use_bilinear_mc_filter)
 -            pc->mcomp_filter_type = SIXTAP;
 -        else
 -            pc->mcomp_filter_type = BILINEAR;
 -
          /* To enable choice of different interploation filters */
 -        if (pc->mcomp_filter_type == SIXTAP)
 +        if (!pc->use_bilinear_mc_filter)
          {
              xd->subpixel_predict        = vp8_sixtap_predict4x4;
              xd->subpixel_predict8x4     = vp8_sixtap_predict8x4;
@@@ -731,8 -737,6 +731,8 @@@ int vp8_decode_frame(VP8D_COMP *pbi
      int corrupt_tokens = 0;
      int prev_independent_partitions = pbi->independent_partitions;
  
 +    int frame_size_change = 0;
 +
      /* start with no corruption of current frame */
      xd->corrupted = 0;
      pc->yv12_fb[pc->new_fb_idx].corrupted = 0;
                      vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
                                         "Failed to allocate frame buffers");
  
 +                /* allocate memory for last frame MODE_INFO array */
  #if CONFIG_ERROR_CONCEALMENT
 -                pbi->overlaps = NULL;
 +
                  if (pbi->ec_enabled)
                  {
 +                    /* old prev_mip was released by vp8_de_alloc_frame_buffers()
 +                     * called in vp8_alloc_frame_buffers() */
 +                    pc->prev_mip = vpx_calloc(
 +                                       (pc->mb_cols + 1) * (pc->mb_rows + 1),
 +                                       sizeof(MODE_INFO));
 +
 +                    if (!pc->prev_mip)
 +                    {
 +                        vp8_de_alloc_frame_buffers(pc);
 +                        vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
 +                                           "Failed to allocate"
 +                                           "last frame MODE_INFO array");
 +                    }
 +
 +                    pc->prev_mi = pc->prev_mip + pc->mode_info_stride + 1;
 +
                      if (vp8_alloc_overlap_lists(pbi))
                          vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
                                             "Failed to allocate overlap lists "
                                             "for error concealment");
                  }
 +
  #endif
  
  #if CONFIG_MULTITHREAD
 +
                  if (pbi->b_multithreaded_rd)
                      vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows);
 +
  #endif
 +                frame_size_change = 1;
              }
          }
      }
              vp8cx_init_de_quantizer(pbi);
  
          /* MB level dequantizer setup */
-         mb_init_dequantizer(pbi, &pbi->mb);
+         vp8_mb_init_dequantizer(pbi, &pbi->mb);
      }
  
      /* Determine if the golden frame or ARF buffer should be updated and how.
  #endif
          vp8_setup_intra_recon(&pc->yv12_fb[pc->new_fb_idx]);
  
 -    vp8_setup_block_dptrs(xd);
 -
 -    vp8_build_block_doffsets(xd);
 +    if(frame_size_change)
 +    {
 +#if CONFIG_MULTITHREAD
 +        for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
 +        {
 +            pbi->mb_row_di[i].mbd.dst = pc->yv12_fb[pc->new_fb_idx];
 +            vp8_build_block_doffsets(&pbi->mb_row_di[i].mbd);
 +        }
 +#endif
 +        vp8_build_block_doffsets(&pbi->mb);
 +    }
  
      /* clear out the coeff buffer */
      vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff));
diff --combined vp8/decoder/threading.c
@@@ -28,7 -28,7 +28,7 @@@
  #include "error_concealment.h"
  #endif
  
- extern void mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
+ extern void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
  
  static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count)
  {
@@@ -50,6 -50,8 +50,6 @@@
          mbd->pre = pc->yv12_fb[pc->lst_fb_idx];
          mbd->dst = pc->yv12_fb[pc->new_fb_idx];
  
 -        vp8_setup_block_dptrs(mbd);
 -        vp8_build_block_doffsets(mbd);
          mbd->segmentation_enabled    = xd->segmentation_enabled;
          mbd->mb_segement_abs_delta     = xd->mb_segement_abs_delta;
          vpx_memcpy(mbd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));
          vpx_memcpy(mbd->dequant_uv, xd->dequant_uv, sizeof(xd->dequant_uv));
  
          mbd->fullpixel_mask = 0xffffffff;
 -        if(pc->full_pixel)
 +
 +        if (pc->full_pixel)
              mbd->fullpixel_mask = 0xfffffff8;
  
      }
  
 -    for (i=0; i< pc->mb_rows; i++)
 -        pbi->mt_current_mb_col[i]=-1;
 +    for (i = 0; i < pc->mb_rows; i++)
 +        pbi->mt_current_mb_col[i] = -1;
  }
  
 -static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, unsigned int mb_idx)
 +static void mt_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd,
 +                                 unsigned int mb_idx)
  {
      MB_PREDICTION_MODE mode;
      int i;
      mode = xd->mode_info_context->mbmi.mode;
  
      if (xd->segmentation_enabled)
-         mb_init_dequantizer(pbi, xd);
+         vp8_mb_init_dequantizer(pbi, xd);
  
  
  #if CONFIG_ERROR_CONCEALMENT
      }
  }
  
 -typedef void (*init_current_bc_fn_t)(VP8D_COMP *pbi, MACROBLOCKD *xd,
 -    int start_mb_row, int mb_row, int num_part);
 -
 -static void init_current_bc(VP8D_COMP *pbi, MACROBLOCKD *xd, int start_mb_row,
 -                     int mb_row, int num_part)
 -{
 -    (void) start_mb_row;
 -
 -    xd->current_bc = &pbi->mbc[mb_row%num_part];
 -}
 -
 -static void init_current_bc_threads(VP8D_COMP *pbi, MACROBLOCKD *xd,
 -                     int start_mb_row, int mb_row, int num_part)
 +static void mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd, int start_mb_row)
  {
 -    (void) xd;
 -    pbi->mb_row_di[start_mb_row - 1].mb_row = mb_row;
 -    pbi->mb_row_di[start_mb_row - 1].mbd.current_bc =  &pbi->mbc[mb_row%num_part];
 -}
 -
 -
 -static void decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd, int start_mb_row,
 -                           init_current_bc_fn_t init_current_bc_fn)
 -{
 -    volatile int *last_row_current_mb_col = NULL;
 +    volatile const int *last_row_current_mb_col;
 +    volatile int *current_mb_col;
      int mb_row;
      VP8_COMMON *pc = &pbi->common;
 -    int nsync = pbi->sync_range;
 +    const int nsync = pbi->sync_range;
 +    const int first_row_no_sync_above = pc->mb_cols + nsync;
      int num_part = 1 << pbi->common.multi_token_partition;
 +    int last_mb_row = start_mb_row;
  
      int dst_fb_idx = pc->new_fb_idx;
      unsigned char *ref_buffer[MAX_REF_FRAMES][3];
         int filter_level;
         loop_filter_info_n *lfi_n = &pc->lf_info;
  
 -       init_current_bc_fn(pbi, xd, start_mb_row, mb_row, num_part);
 +       /* save last row processed by this thread */
 +       last_mb_row = mb_row;
 +       /* select bool coder for current partition */
 +       xd->current_bc =  &pbi->mbc[mb_row%num_part];
  
         if (mb_row > 0)
             last_row_current_mb_col = &pbi->mt_current_mb_col[mb_row -1];
 +       else
 +           last_row_current_mb_col = &first_row_no_sync_above;
 +
 +       current_mb_col = &pbi->mt_current_mb_col[mb_row];
  
         recon_yoffset = mb_row * recon_y_stride * 16;
         recon_uvoffset = mb_row * recon_uv_stride * 8;
  
         for (mb_col = 0; mb_col < pc->mb_cols; mb_col++)
         {
 -           if ( mb_row > 0 && (mb_col & (nsync-1)) == 0)
 +           *current_mb_col = mb_col - 1;
 +
 +           if ((mb_col & (nsync - 1)) == 0)
             {
 -               while (mb_col > (*last_row_current_mb_col - nsync) && *last_row_current_mb_col != pc->mb_cols - 1)
 +               while (mb_col > (*last_row_current_mb_col - nsync))
                 {
                     x86_pause_hint();
                     thread_sleep(0);
             /* propagate errors from reference frames */
             xd->corrupted |= ref_fb_corrupted[xd->mode_info_context->mbmi.ref_frame];
  
 -           decode_macroblock(pbi, xd, 0);
 +           mt_decode_macroblock(pbi, xd, 0);
  
             xd->left_available = 1;
  
             ++xd->mode_info_context;  /* next mb */
  
             xd->above_context++;
 -
 -           /*pbi->mb_row_di[ithread].current_mb_col = mb_col;*/
 -           pbi->mt_current_mb_col[mb_row] = mb_col;
         }
  
         /* adjust to the next row of mbs */
                     pbi->mt_vabove_row[mb_row +1][lastuv + i] = pbi->mt_vabove_row[mb_row +1][lastuv -1];
                 }
             }
 -       } else
 -           vp8_extend_mb_row(&pc->yv12_fb[dst_fb_idx], xd->dst.y_buffer + 16, xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
 +       }
 +       else
 +           vp8_extend_mb_row(&pc->yv12_fb[dst_fb_idx], xd->dst.y_buffer + 16,
 +                             xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
 +
 +       /* last MB of row is ready just after extension is done */
 +       *current_mb_col = mb_col + nsync;
  
         ++xd->mode_info_context;      /* skip prediction column */
         xd->up_available = 1;
         /* since we have multithread */
         xd->mode_info_context += xd->mode_info_stride * pbi->decoding_thread_count;
      }
 +
 +    /* signal end of frame decoding if this thread processed the last mb_row */
 +    if (last_mb_row == (pc->mb_rows - 1))
 +        sem_post(&pbi->h_event_end_decoding);
 +
  }
  
  
@@@ -633,6 -635,7 +633,6 @@@ static THREAD_FUNCTION thread_decoding_
          if (pbi->b_multithreaded_rd == 0)
              break;
  
 -        /*if(WaitForSingleObject(pbi->h_event_start_decoding[ithread], INFINITE) == WAIT_OBJECT_0)*/
          if (sem_wait(&pbi->h_event_start_decoding[ithread]) == 0)
          {
              if (pbi->b_multithreaded_rd == 0)
              else
              {
                  MACROBLOCKD *xd = &mbrd->mbd;
 -
                  xd->left_context = &mb_row_left_context;
  
 -                decode_mb_rows(pbi, xd, ithread+1, init_current_bc_threads);
 +                mt_decode_mb_rows(pbi, xd, ithread+1);
              }
          }
 -
 -        /*  add this to each frame */
 -        if ((mbrd->mb_row == pbi->common.mb_rows-1) ||
 -            ((mbrd->mb_row == pbi->common.mb_rows-2) &&
 -                (pbi->common.mb_rows % (pbi->decoding_thread_count+1))==1))
 -        {
 -            /*SetEvent(pbi->h_event_end_decoding);*/
 -            sem_post(&pbi->h_event_end_decoding);
 -        }
      }
  
      return 0 ;
@@@ -681,8 -694,6 +681,8 @@@ void vp8_decoder_create_threads(VP8D_CO
          {
              sem_init(&pbi->h_event_start_decoding[ithread], 0, 0);
  
 +            vp8_setup_block_dptrs(&pbi->mb_row_di[ithread].mbd);
 +
              pbi->de_thread_data[ithread].ithread  = ithread;
              pbi->de_thread_data[ithread].ptr1     = (void *)pbi;
              pbi->de_thread_data[ithread].ptr2     = (void *) &pbi->mb_row_di[ithread];
@@@ -905,7 -916,7 +905,7 @@@ void vp8mt_decode_mb_rows( VP8D_COMP *p
      for (i = 0; i < pbi->decoding_thread_count; i++)
          sem_post(&pbi->h_event_start_decoding[i]);
  
 -    decode_mb_rows(pbi, xd, 0, init_current_bc);
 +    mt_decode_mb_rows(pbi, xd, 0);
  
      sem_wait(&pbi->h_event_end_decoding);   /* add back for each frame */
  }
diff --combined vp8/encoder/bitstream.c
@@@ -521,12 -521,11 +521,11 @@@ static void pack_inter_mode_mvs(VP8_COM
      const MV_CONTEXT *mvc = pc->fc.mvc;
  
  
-     MODE_INFO *m = pc->mi, *ms;
+     MODE_INFO *m = pc->mi;
      const int mis = pc->mode_info_stride;
      int mb_row = -1;
  
      int prob_skip_false = 0;
-     ms = pc->mi - 1;
  
      cpi->mb.partition_info = cpi->mb.pi;
  
@@@ -755,7 -754,7 +754,7 @@@ static void write_kfmodes(VP8_COMP *cpi
              if (c->mb_no_coeff_skip)
                  vp8_encode_bool(bc, m->mbmi.mb_skip_coeff, prob_skip_false);
  
 -            kfwrite_ymode(bc, ym, c->kf_ymode_prob);
 +            kfwrite_ymode(bc, ym, vp8_kf_ymode_prob);
  
              if (ym == B_PRED)
              {
                      ++intra_mode_stats [A] [L] [bm];
  #endif
  
 -                    write_bmode(bc, bm, c->kf_bmode_prob [A] [L]);
 +                    write_bmode(bc, bm, vp8_kf_bmode_prob [A] [L]);
                  }
                  while (++i < 16);
              }
  
 -            write_uv_mode(bc, (m++)->mbmi.uv_mode, c->kf_uv_mode_prob);
 +            write_uv_mode(bc, (m++)->mbmi.uv_mode, vp8_kf_uv_mode_prob);
          }
  
          m++;    // skip L prediction border
@@@ -1296,6 -1295,11 +1295,6 @@@ void vp8_pack_bitstream(VP8_COMP *cpi, 
      Sectionbits[active_section = 1] += sizeof(VP8_HEADER) * 8 * 256;
  #endif
  
 -    //vp8_kf_default_bmode_probs() is called in vp8_setup_key_frame() once for each
 -    //K frame before encode frame. pc->kf_bmode_prob doesn't get changed anywhere
 -    //else. No need to call it again here. --yw
 -    //vp8_kf_default_bmode_probs( pc->kf_bmode_prob);
 -
      // every keyframe send startcode, width, height, scale factor, clamp and color type
      if (oh.type == KEY_FRAME)
      {
@@@ -31,6 -31,7 +31,7 @@@
  #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
  #include "bitstream.h"
  #endif
+ #include "encodeframe.h"
  
  extern void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) ;
  extern void vp8_calc_ref_frame_costs(int *ref_frame_cost,
@@@ -46,13 -47,6 +47,6 @@@ extern void vp8cx_init_mbrthread_data(V
                                        MB_ROW_COMP *mbr_ei,
                                        int mb_row,
                                        int count);
- void vp8_build_block_offsets(MACROBLOCK *x);
- void vp8_setup_block_ptrs(MACROBLOCK *x);
- int vp8cx_encode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t,
-                                   int recon_yoffset, int recon_uvoffset,
-                                   int mb_row, int mb_col);
- int vp8cx_encode_intra_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
-                                    TOKENEXTRA **t);
  static void adjust_act_zbin( VP8_COMP *cpi, MACROBLOCK *x );
  
  #ifdef MODE_STATS
@@@ -596,7 -590,7 +590,7 @@@ void encode_mb_row(VP8_COMP *cpi
      x->partition_info++;
  }
  
- void init_encode_frame_mb_context(VP8_COMP *cpi)
static void init_encode_frame_mb_context(VP8_COMP *cpi)
  {
      MACROBLOCK *const x = & cpi->mb;
      VP8_COMMON *const cm = & cpi->common;
@@@ -698,7 -692,7 +692,7 @@@ void vp8_encode_frame(VP8_COMP *cpi
      }
  
      // Functions setup for all frame types so we can use MC in AltRef
 -    if (cm->mcomp_filter_type == SIXTAP)
 +    if(!cm->use_bilinear_mc_filter)
      {
          xd->subpixel_predict        = vp8_sixtap_predict4x4;
          xd->subpixel_predict8x4     = vp8_sixtap_predict8x4;
diff --combined vp8/encoder/ethreading.c
@@@ -12,8 -12,8 +12,8 @@@
  #include "vp8/common/threading.h"
  #include "vp8/common/common.h"
  #include "vp8/common/extend.h"
  #include "bitstream.h"
+ #include "encodeframe.h"
  
  #if CONFIG_MULTITHREAD
  
@@@ -24,8 -24,6 +24,6 @@@ extern int vp8cx_encode_inter_macrobloc
  extern int vp8cx_encode_intra_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
                                           TOKENEXTRA **t);
  extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip);
- extern void vp8_build_block_offsets(MACROBLOCK *x);
- extern void vp8_setup_block_ptrs(MACROBLOCK *x);
  
  extern void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm);
  
@@@ -338,16 -336,21 +336,16 @@@ static void setup_mbby_copy(MACROBLOCK 
      z->src.v_buffer      = x->src.v_buffer;
      */
  
 +    z->mvcost[0] =  x->mvcost[0];
 +    z->mvcost[1] =  x->mvcost[1];
 +    z->mvsadcost[0] =  x->mvsadcost[0];
 +    z->mvsadcost[1] =  x->mvsadcost[1];
  
 -    vpx_memcpy(z->mvcosts,          x->mvcosts,         sizeof(x->mvcosts));
 -    z->mvcost[0] = &z->mvcosts[0][mv_max+1];
 -    z->mvcost[1] = &z->mvcosts[1][mv_max+1];
 -    z->mvsadcost[0] = &z->mvsadcosts[0][mvfp_max+1];
 -    z->mvsadcost[1] = &z->mvsadcosts[1][mvfp_max+1];
 -
 -
 -    vpx_memcpy(z->token_costs,       x->token_costs,      sizeof(x->token_costs));
 -    vpx_memcpy(z->inter_bmode_costs,  x->inter_bmode_costs, sizeof(x->inter_bmode_costs));
 -    //memcpy(z->mvcosts,            x->mvcosts,         sizeof(x->mvcosts));
 -    //memcpy(z->mvcost,         x->mvcost,          sizeof(x->mvcost));
 -    vpx_memcpy(z->mbmode_cost,       x->mbmode_cost,      sizeof(x->mbmode_cost));
 -    vpx_memcpy(z->intra_uv_mode_cost,  x->intra_uv_mode_cost, sizeof(x->intra_uv_mode_cost));
 -    vpx_memcpy(z->bmode_costs,       x->bmode_costs,      sizeof(x->bmode_costs));
 +    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;
  
      for (i = 0; i < 25; i++)
      {
          z->block[i].quant_fast      = x->block[i].quant_fast;
          z->block[i].quant_shift     = x->block[i].quant_shift;
          z->block[i].zbin            = x->block[i].zbin;
 -        z->block[i].zrun_zbin_boost   = x->block[i].zrun_zbin_boost;
 +        z->block[i].zrun_zbin_boost = x->block[i].zrun_zbin_boost;
          z->block[i].round           = x->block[i].round;
 -        z->q_index                  = x->q_index;
 -        z->act_zbin_adj             = x->act_zbin_adj;
 -        z->last_act_zbin_adj        = x->last_act_zbin_adj;
 -        /*
 -        z->block[i].src             = x->block[i].src;
 -        */
 -        z->block[i].src_stride       = x->block[i].src_stride;
 +        z->block[i].src_stride      = x->block[i].src_stride;
      }
  
 +    z->q_index           = x->q_index;
 +    z->act_zbin_adj      = x->act_zbin_adj;
 +    z->last_act_zbin_adj = x->last_act_zbin_adj;
 +
      {
          MACROBLOCKD *xd = &x->e_mbd;
          MACROBLOCKD *zd = &z->e_mbd;
          zd->subpixel_predict16x16    = xd->subpixel_predict16x16;
          zd->segmentation_enabled     = xd->segmentation_enabled;
          zd->mb_segement_abs_delta      = xd->mb_segement_abs_delta;
 -        vpx_memcpy(zd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));
 +        vpx_memcpy(zd->segment_feature_data, xd->segment_feature_data,
 +                   sizeof(xd->segment_feature_data));
  
 -        vpx_memcpy(zd->dequant_y1_dc, xd->dequant_y1_dc, sizeof(xd->dequant_y1_dc));
 +        vpx_memcpy(zd->dequant_y1_dc, xd->dequant_y1_dc,
 +                   sizeof(xd->dequant_y1_dc));
          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));
diff --combined vp8/encoder/onyx_if.c
@@@ -36,6 -36,7 +36,7 @@@
  #if CONFIG_MULTI_RES_ENCODING
  #include "mr_dissim.h"
  #endif
+ #include "encodeframe.h"
  
  #include <math.h>
  #include <stdio.h>
@@@ -1016,8 -1017,10 +1017,10 @@@ void vp8_set_speed_features(VP8_COMP *c
  
  static void alloc_raw_frame_buffers(VP8_COMP *cpi)
  {
+ #if VP8_TEMPORAL_ALT_REF
      int width = (cpi->oxcf.Width + 15) & ~15;
      int height = (cpi->oxcf.Height + 15) & ~15;
+ #endif
  
      cpi->lookahead = vp8_lookahead_init(cpi->oxcf.Width, cpi->oxcf.Height,
                                          cpi->oxcf.lag_in_frames);
@@@ -1336,7 -1339,7 +1339,7 @@@ static void init_config(VP8_COMP *cpi, 
  #endif
  }
  
- void update_layer_contexts (VP8_COMP *cpi)
static void update_layer_contexts (VP8_COMP *cpi)
  {
      VP8_CONFIG *oxcf = &cpi->oxcf;
  
@@@ -1398,12 -1401,24 +1401,24 @@@ void vp8_change_config(VP8_COMP *cpi, V
      if (!oxcf)
          return;
  
+ #if CONFIG_MULTITHREAD
+     /*  wait for the last picture loopfilter thread done */
+     if (cpi->b_lpf_running)
+     {
+         sem_wait(&cpi->h_event_end_lpf);
+         cpi->b_lpf_running = 0;
+     }
+ #endif
      if (cm->version != oxcf->Version)
      {
          cm->version = oxcf->Version;
          vp8_setup_version(cm);
      }
  
+     last_w = cpi->oxcf.Width;
+     last_h = cpi->oxcf.Height;
      cpi->oxcf = *oxcf;
  
      switch (cpi->oxcf.Mode)
      // Only allow dropped frames in buffered mode
      cpi->drop_frames_allowed = cpi->oxcf.allow_df && cpi->buffered_mode;
  
 -    if (!cm->use_bilinear_mc_filter)
 -        cm->mcomp_filter_type = SIXTAP;
 -    else
 -        cm->mcomp_filter_type = BILINEAR;
 -
      cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
  
  
-     last_w = cm->Width;
-     last_h = cm->Height;
      cm->Width       = cpi->oxcf.Width;
      cm->Height      = cpi->oxcf.Height;
  
-     cm->horiz_scale  = cpi->horiz_scale;
-     cm->vert_scale   = cpi->vert_scale;
+     /* TODO(jkoleszar): if an internal spatial resampling is active,
+      * and we downsize the input image, maybe we should clear the
+      * internal scale immediately rather than waiting for it to
+      * correct.
+      */
  
      // VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs)
      if (cpi->oxcf.Sharpness > 7)
          cm->Height = (vs - 1 + cpi->oxcf.Height * vr) / vs;
      }
  
-     if (last_w != cm->Width || last_h != cm->Height)
+     if (last_w != cpi->oxcf.Width || last_h != cpi->oxcf.Height)
          cpi->force_next_frame_intra = 1;
  
      if (((cm->Width + 15) & 0xfffffff0) !=
@@@ -1883,6 -1903,13 +1898,6 @@@ struct VP8_COMP* vp8_create_compressor(
      cpi->gf_rate_correction_factor  = 1.0;
      cpi->twopass.est_max_qcorrection_factor  = 1.0;
  
 -    cpi->mb.mvcost[0] = &cpi->mb.mvcosts[0][mv_max+1];
 -    cpi->mb.mvcost[1] = &cpi->mb.mvcosts[1][mv_max+1];
 -    cpi->mb.mvsadcost[0] = &cpi->mb.mvsadcosts[0][mvfp_max+1];
 -    cpi->mb.mvsadcost[1] = &cpi->mb.mvsadcosts[1][mvfp_max+1];
 -
 -    cal_mvsadcosts(cpi->mb.mvsadcost);
 -
      for (i = 0; i < KEY_FRAME_CONTEXT; i++)
      {
          cpi->prior_key_frame_distance[i] = (int)cpi->output_frame_rate;
      cpi->common.error.setjmp = 0;
  
  #if CONFIG_MULTI_RES_ENCODING
 +
      /* Calculate # of MBs in a row in lower-resolution level image. */
      if (cpi->oxcf.mr_encoder_id > 0)
          vp8_cal_low_res_mb_cols(cpi);
 +
  #endif
  
 -    return  cpi;
 +    /* setup RD costs to MACROBLOCK struct */
 +
 +    cpi->mb.mvcost[0] = &cpi->rd_costs.mvcosts[0][mv_max+1];
 +    cpi->mb.mvcost[1] = &cpi->rd_costs.mvcosts[1][mv_max+1];
 +    cpi->mb.mvsadcost[0] = &cpi->rd_costs.mvsadcosts[0][mvfp_max+1];
 +    cpi->mb.mvsadcost[1] = &cpi->rd_costs.mvsadcosts[1][mvfp_max+1];
 +
 +    cal_mvsadcosts(cpi->mb.mvsadcost);
 +
 +    cpi->mb.mbmode_cost = cpi->rd_costs.mbmode_cost;
 +    cpi->mb.intra_uv_mode_cost = cpi->rd_costs.intra_uv_mode_cost;
 +    cpi->mb.bmode_costs = cpi->rd_costs.bmode_costs;
 +    cpi->mb.inter_bmode_costs = cpi->rd_costs.inter_bmode_costs;
 +    cpi->mb.token_costs = cpi->rd_costs.token_costs;
  
 +    return  cpi;
  }
  
  
@@@ -3009,7 -3020,7 +3024,7 @@@ static int recode_loop_test( VP8_COMP *
      return force_recode;
  }
  
- void update_reference_frames(VP8_COMMON *cm)
static void update_reference_frames(VP8_COMMON *cm)
  {
      YV12_BUFFER_CONFIG *yv12_fb = cm->yv12_fb;
  
@@@ -3158,20 -3169,21 +3173,21 @@@ static void encode_frame_to_data_rat
  
      int Loop = 0;
      int loop_count;
-     int this_q;
-     int last_zbin_oq;
  
+     VP8_COMMON *cm = &cpi->common;
+     int active_worst_qchanged = 0;
+ #if !(CONFIG_REALTIME_ONLY)
      int q_low;
      int q_high;
      int zbin_oq_high;
      int zbin_oq_low = 0;
      int top_index;
      int bottom_index;
-     VP8_COMMON *cm = &cpi->common;
-     int active_worst_qchanged = 0;
      int overshoot_seen = 0;
      int undershoot_seen = 0;
+ #endif
      int drop_mark = cpi->oxcf.drop_frames_water_mark * cpi->oxcf.optimal_buffer_level / 100;
      int drop_mark75 = drop_mark * 2 / 3;
      int drop_mark50 = drop_mark / 4;
      // Clear down mmx registers to allow floating point in what follows
      vp8_clear_system_state();
  
+ #if CONFIG_MULTITHREAD
+     /*  wait for the last picture loopfilter thread done */
+     if (cpi->b_lpf_running)
+     {
+         sem_wait(&cpi->h_event_end_lpf);
+         cpi->b_lpf_running = 0;
+     }
+ #endif
      // Test code for segmentation of gf/arf (0,0)
      //segmentation_test_function( cpi);
  
          {
              cpi->decimation_factor = 1;
          }
          //vpx_log("Encoder: Decimation Factor: %d \n",cpi->decimation_factor);
      }
  
  
      // Determine initial Q to try
      Q = vp8_regulate_q(cpi, cpi->this_frame_target);
-     last_zbin_oq = cpi->zbin_over_quant;
+ #if !(CONFIG_REALTIME_ONLY)
  
      // Set highest allowed value for Zbin over quant
      if (cm->frame_type == KEY_FRAME)
      }
      else
          zbin_oq_high = ZBIN_OQ_MAX;
+ #endif
  
      // Setup background Q adjustment for error resilient mode.
      // For multi-layer encodes only enable this for the base layer.
  
      vp8_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, &frame_over_shoot_limit);
  
+ #if !(CONFIG_REALTIME_ONLY)
      // Limit Q range for the adaptive loop.
      bottom_index = cpi->active_best_quality;
      top_index    = cpi->active_worst_quality;
      q_low  = cpi->active_best_quality;
      q_high = cpi->active_worst_quality;
+ #endif
  
      vp8_save_coding_context(cpi);
  
      loop_count = 0;
  
      scale_and_extend_source(cpi->un_scaled_source, cpi);
  #if !(CONFIG_REALTIME_ONLY) && CONFIG_POSTPROC && !(CONFIG_TEMPORAL_DENOISING)
  
      if (cpi->oxcf.noise_sensitivity > 0)
              */
  
          vp8_set_quantizer(cpi, Q);
-         this_q = Q;
  
          // setup skip prob for costing in mode/mv decision
          if (cpi->common.mb_no_coeff_skip)
              vp8_setup_key_frame(cpi);
          }
  
- #if CONFIG_MULTITHREAD
-         /*  wait for the last picture loopfilter thread done */
-         if (cpi->b_lpf_running)
-         {
-             sem_wait(&cpi->h_event_end_lpf);
-             cpi->b_lpf_running = 0;
-         }
- #endif
  
  #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
          {
              if (cpi->compressor_speed == 2)
              {
                  /* we don't do re-encoding in realtime mode
-                  * if key frame is decided than we force it on next frame */
+                  * if key frame is decided then we force it on next frame */
                  cpi->force_next_frame_intra = key_frame_decision;
              }
+ #if !(CONFIG_REALTIME_ONLY)
              else if (key_frame_decision)
              {
                  // Reset all our sizing numbers and recode
  
                  continue;
              }
+ #endif
          }
  
          vp8_clear_system_state();
              while ((cpi->active_worst_quality < cpi->worst_quality) && (over_size_percent > 0))
              {
                  cpi->active_worst_quality++;
-                 top_index = cpi->active_worst_quality;
                  over_size_percent = (int)(over_size_percent * 0.96);        // Assume 1 qstep = about 4% on frame size.
              }
+ #if !(CONFIG_REALTIME_ONLY)
+             top_index = cpi->active_worst_quality;
+ #endif
              // If we have updated the active max Q do not call vp8_update_rate_correction_factors() this loop.
              active_worst_qchanged = 1;
          }
              // Clamp cpi->zbin_over_quant
              cpi->zbin_over_quant = (cpi->zbin_over_quant < zbin_oq_low) ? zbin_oq_low : (cpi->zbin_over_quant > zbin_oq_high) ? zbin_oq_high : cpi->zbin_over_quant;
  
-             //Loop = (Q != last_q) || (last_zbin_oq != cpi->zbin_over_quant);
              Loop = Q != last_q;
-             last_zbin_oq = cpi->zbin_over_quant;
          }
          else
  #endif
@@@ -4797,7 -4815,7 +4819,7 @@@ int vp8_get_compressed_data(VP8_COMP *c
      }
  
      // adjust frame rates based on timestamps given
-     if (!cm->refresh_alt_ref_frame || (cpi->oxcf.number_of_layers > 1))
+     if (cm->show_frame)
      {
          int64_t this_duration;
          int step = 0;
diff --combined vp8/encoder/onyx_int.h
@@@ -57,8 -57,6 +57,6 @@@
  #define VP8_TEMPORAL_ALT_REF 1
  #endif
  
- #define MAX_PERIODICITY 16
  #define MAX(x,y) (((x)>(y))?(x):(y))
  #define MIN(x,y) (((x)<(y))?(x):(y))
  
@@@ -485,8 -483,6 +483,6 @@@ typedef struct VP8_COM
      int goldfreq;
      int auto_worst_q;
      int cpu_used;
-     int horiz_scale;
-     int vert_scale;
      int pass;
  
  
  
      // Coding layer state variables
      unsigned int current_layer;
-     LAYER_CONTEXT layer_context[MAX_LAYERS];
-     int64_t frames_in_layer[MAX_LAYERS];
-     int64_t bytes_in_layer[MAX_LAYERS];
-     double sum_psnr[MAX_LAYERS];
-     double sum_psnr_p[MAX_LAYERS];
-     double total_error2[MAX_LAYERS];
-     double total_error2_p[MAX_LAYERS];
-     double sum_ssim[MAX_LAYERS];
-     double sum_weights[MAX_LAYERS];
-     double total_ssimg_y_in_layer[MAX_LAYERS];
-     double total_ssimg_u_in_layer[MAX_LAYERS];
-     double total_ssimg_v_in_layer[MAX_LAYERS];
-     double total_ssimg_all_in_layer[MAX_LAYERS];
+     LAYER_CONTEXT layer_context[VPX_TS_MAX_LAYERS];
+     int64_t frames_in_layer[VPX_TS_MAX_LAYERS];
+     int64_t bytes_in_layer[VPX_TS_MAX_LAYERS];
+     double sum_psnr[VPX_TS_MAX_LAYERS];
+     double sum_psnr_p[VPX_TS_MAX_LAYERS];
+     double total_error2[VPX_TS_MAX_LAYERS];
+     double total_error2_p[VPX_TS_MAX_LAYERS];
+     double sum_ssim[VPX_TS_MAX_LAYERS];
+     double sum_weights[VPX_TS_MAX_LAYERS];
+     double total_ssimg_y_in_layer[VPX_TS_MAX_LAYERS];
+     double total_ssimg_u_in_layer[VPX_TS_MAX_LAYERS];
+     double total_ssimg_v_in_layer[VPX_TS_MAX_LAYERS];
+     double total_ssimg_all_in_layer[VPX_TS_MAX_LAYERS];
  
  #if CONFIG_MULTI_RES_ENCODING
      /* Number of MBs per row at lower-resolution level */
      int    mr_low_res_mb_cols;
  #endif
  
 +    struct rd_costs_struct
 +    {
 +        int mvcosts[2][MVvals+1];
 +        int mvsadcosts[2][MVfpvals+1];
 +        int mbmode_cost[2][MB_MODE_COUNT];
 +        int intra_uv_mode_cost[2][MB_MODE_COUNT];
 +        int bmode_costs[10][10][10];
 +        int inter_bmode_costs[B_MODE_COUNT];
 +        int token_costs[BLOCK_TYPES][COEF_BANDS]
 +        [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS];
 +    } rd_costs;
  } VP8_COMP;
  
  void control_data_rate(VP8_COMP *cpi);
  
- void vp8_encode_frame(VP8_COMP *cpi);
  void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned char *dest_end, unsigned long *size);
  
- void vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x);
  int rd_cost_intra_mb(MACROBLOCKD *x);
  
  void vp8_tokenize_mb(VP8_COMP *, MACROBLOCKD *, TOKENEXTRA **);
@@@ -134,6 -134,7 +134,6 @@@ void vp8_temporal_filter_apply_
  }
  
  #if ALT_REF_MC_ENABLED
 -static int dummy_cost[2*mv_max+1];
  
  static int vp8_temporal_filter_find_matching_mb_c
  (
  {
      MACROBLOCK *x = &cpi->mb;
      int step_param;
-     int further_steps;
      int sadpb = x->sadperbit16;
      int bestsme = INT_MAX;
  
      int_mv best_ref_mv1;
      int_mv best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */
  
 -    int *mvcost[2]    = { &dummy_cost[mv_max+1], &dummy_cost[mv_max+1] };
 -    int *mvsadcost[2] = { &dummy_cost[mv_max+1], &dummy_cost[mv_max+1] };
 -
      // Save input state
      unsigned char **base_src = b->base_src;
      int src = b->src;
      // Further step/diamond searches as necessary
      if (cpi->Speed < 8)
      {
-         step_param = cpi->sf.first_step +
-                     (cpi->Speed > 5);
-         further_steps =
-             (cpi->sf.max_step_search_steps - 1)-step_param;
+         step_param = cpi->sf.first_step + (cpi->Speed > 5);
      }
      else
      {
          step_param = cpi->sf.first_step + 2;
-         further_steps = 0;
      }
  
      /*cpi->sf.search_method == HEX*/
      // TODO Check that the 16x16 vf & sdf are selected here
 -    bestsme = vp8_hex_search(x, b, d,
 -        &best_ref_mv1_full, &d->bmi.mv,
 -        step_param,
 -        sadpb,
 -        &cpi->fn_ptr[BLOCK_16X16],
 -        mvsadcost, mvcost, &best_ref_mv1);
 +    // Ignore mv costing by sending NULL cost arrays
 +    bestsme = vp8_hex_search(x, b, d, &best_ref_mv1_full, &d->bmi.mv,
 +                             step_param, sadpb,
 +                             &cpi->fn_ptr[BLOCK_16X16],
 +                             NULL, NULL, &best_ref_mv1);
  
  #if ALT_REF_SUBPEL_ENABLED
      // Try sub-pixel MC?
      {
          int distortion;
          unsigned int sse;
 +        // Ignore mv costing by sending NULL cost array
          bestsme = cpi->find_fractional_mv_step(x, b, d,
 -                    &d->bmi.mv, &best_ref_mv1,
 -                    x->errorperbit, &cpi->fn_ptr[BLOCK_16X16],
 -                    mvcost, &distortion, &sse);
 +                                               &d->bmi.mv,
 +                                               &best_ref_mv1,
 +                                               x->errorperbit,
 +                                               &cpi->fn_ptr[BLOCK_16X16],
 +                                               NULL, &distortion, &sse);
      }
  #endif
  
@@@ -288,36 -285,32 +283,36 @@@ static void vp8_temporal_filter_iterate
  
              for (frame = 0; frame < frame_count; frame++)
              {
 -                int err = 0;
 -
                  if (cpi->frames[frame] == NULL)
                      continue;
  
                  mbd->block[0].bmi.mv.as_mv.row = 0;
                  mbd->block[0].bmi.mv.as_mv.col = 0;
  
 +                if (frame == alt_ref_index)
 +                {
 +                    filter_weight = 2;
 +                }
 +                else
 +                {
 +                    int err = 0;
  #if ALT_REF_MC_ENABLED
  #define THRESH_LOW   10000
  #define THRESH_HIGH  20000
 -
 -                // Find best match in this frame by MC
 -                err = vp8_temporal_filter_find_matching_mb_c
 -                      (cpi,
 -                       cpi->frames[alt_ref_index],
 -                       cpi->frames[frame],
 -                       mb_y_offset,
 -                       THRESH_LOW);
 -
 +                    // Find best match in this frame by MC
 +                    err = vp8_temporal_filter_find_matching_mb_c
 +                              (cpi,
 +                               cpi->frames[alt_ref_index],
 +                               cpi->frames[frame],
 +                               mb_y_offset,
 +                               THRESH_LOW);
  #endif
 -                // Assign higher weight to matching MB if it's error
 -                // score is lower. If not applying MC default behavior
 -                // is to weight all MBs equal.
 -                filter_weight = err<THRESH_LOW
 -                                  ? 2 : err<THRESH_HIGH ? 1 : 0;
 +                    // Assign higher weight to matching MB if it's error
 +                    // score is lower. If not applying MC default behavior
 +                    // is to weight all MBs equal.
 +                    filter_weight = err<THRESH_LOW
 +                                       ? 2 : err<THRESH_HIGH ? 1 : 0;
 +                }
  
                  if (filter_weight != 0)
                  {
diff --combined vp8/vp8_cx_iface.c
  #include "vpx/internal/vpx_codec_internal.h"
  #include "vpx_version.h"
  #include "vp8/encoder/onyx_int.h"
- #include "vpx/vp8e.h"
+ #include "vpx/vp8cx.h"
  #include "vp8/encoder/firstpass.h"
  #include "vp8/common/onyx.h"
  #include <stdlib.h>
  #include <string.h>
  
- /* This value is a sentinel for determining whether the user has set a mode
-  * directly through the deprecated VP8E_SET_ENCODING_MODE control.
-  */
- #define NO_MODE_SET 255
  struct vp8_extracfg
  {
      struct vpx_codec_pkt_list *pkt_list;
@@@ -94,7 -89,6 +89,6 @@@ struct vpx_codec_alg_pri
      unsigned int            next_frame_flag;
      vp8_postproc_cfg_t      preview_ppcfg;
      vpx_codec_pkt_list_decl(64) pkt_list;              // changed to accomendate the maximum number of lagged frames allowed
-     int                         deprecated_mode;
      unsigned int                fixed_kf_cntr;
  };
  
@@@ -183,19 -177,16 +177,16 @@@ static vpx_codec_err_t validate_config(
  
      RANGE_CHECK_BOOL(vp8_cfg,               enable_auto_alt_ref);
      RANGE_CHECK(vp8_cfg, cpu_used,           -16, 16);
- #if CONFIG_TEMPORAL_DENOISING
-     RANGE_CHECK(vp8_cfg, noise_sensitivity, 0, 1);
- #endif
  #if !(CONFIG_REALTIME_ONLY)
      RANGE_CHECK(vp8_cfg, encoding_mode,      VP8_BEST_QUALITY_ENCODING, VP8_REAL_TIME_ENCODING);
- #if !(CONFIG_TEMPORAL_DENOISING)
-     RANGE_CHECK_HI(vp8_cfg, noise_sensitivity,  6);
- #endif
  #else
      RANGE_CHECK(vp8_cfg, encoding_mode,      VP8_REAL_TIME_ENCODING, VP8_REAL_TIME_ENCODING);
- #if !(CONFIG_TEMPORAL_DENOISING)
-     RANGE_CHECK(vp8_cfg, noise_sensitivity,  0, 0);
  #endif
+ #if CONFIG_REALTIME_ONLY && !CONFIG_TEMPORAL_DENOISING
+     RANGE_CHECK(vp8_cfg, noise_sensitivity,  0, 0);
+ #else
+     RANGE_CHECK_HI(vp8_cfg, noise_sensitivity,  6);
  #endif
  
      RANGE_CHECK(vp8_cfg, token_partitions,   VP8_ONE_TOKENPARTITION, VP8_EIGHT_TOKENPARTITION);
@@@ -516,7 -507,6 +507,6 @@@ static vpx_codec_err_t set_param(vpx_co
  
      switch (ctrl_id)
      {
-         MAP(VP8E_SET_ENCODING_MODE,         ctx->deprecated_mode);
          MAP(VP8E_SET_CPUUSED,               xcfg.cpu_used);
          MAP(VP8E_SET_ENABLEAUTOALTREF,      xcfg.enable_auto_alt_ref);
          MAP(VP8E_SET_NOISE_SENSITIVITY,     xcfg.noise_sensitivity);
@@@ -571,7 -561,7 +561,7 @@@ static vpx_codec_err_t vp8e_mr_alloc_me
  static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx,
                                   vpx_codec_priv_enc_mr_cfg_t *mr_cfg)
  {
-     vpx_codec_err_t        res = VPX_DEC_OK;
+     vpx_codec_err_t        res = VPX_CODEC_OK;
      struct vpx_codec_alg_priv *priv;
      vpx_codec_enc_cfg_t       *cfg;
      unsigned int               i;
              return VPX_CODEC_MEM_ERROR;
          }
  
-         priv->deprecated_mode = NO_MODE_SET;
          res = validate_config(priv, &priv->cfg, &priv->vp8_cfg, 0);
  
          if (!res)
@@@ -718,19 -706,6 +706,6 @@@ static void pick_quickcompress_mode(vpx
      new_qc = MODE_REALTIME;
  #endif
  
-     switch (ctx->deprecated_mode)
-     {
-     case VP8_BEST_QUALITY_ENCODING:
-         new_qc = MODE_BESTQUALITY;
-         break;
-     case VP8_GOOD_QUALITY_ENCODING:
-         new_qc = MODE_GOODQUALITY;
-         break;
-     case VP8_REAL_TIME_ENCODING:
-         new_qc = MODE_REALTIME;
-         break;
-     }
      if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS)
          new_qc = MODE_FIRSTPASS;
      else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS)
@@@ -758,6 -733,6 +733,9 @@@ static vpx_codec_err_t vp8e_encode(vpx_
      if (!ctx->cfg.rc_target_bitrate)
          return res;
  
++    if (!ctx->cfg.rc_target_bitrate)
++        return res;
++
      if (img)
          res = validate_img(ctx, img);
  
@@@ -1207,7 -1182,6 +1185,6 @@@ static vpx_codec_ctrl_fn_map_t vp8e_ctf
      {VP8E_SET_ROI_MAP,                  vp8e_set_roi_map},
      {VP8E_SET_ACTIVEMAP,                vp8e_set_activemap},
      {VP8E_SET_SCALEMODE,                vp8e_set_scalemode},
-     {VP8E_SET_ENCODING_MODE,            set_param},
      {VP8E_SET_CPUUSED,                  set_param},
      {VP8E_SET_NOISE_SENSITIVITY,        set_param},
      {VP8E_SET_ENABLEAUTOALTREF,         set_param},
@@@ -1318,88 -1292,3 +1295,3 @@@ CODEC_INTERFACE(vpx_codec_vp8_cx) 
          vp8e_mr_alloc_mem,
      } /* encoder functions */
  };
- /*
-  * BEGIN BACKWARDS COMPATIBILITY SHIM.
-  */
- #define FORCE_KEY   2
- static vpx_codec_err_t api1_control(vpx_codec_alg_priv_t *ctx,
-                                     int                   ctrl_id,
-                                     va_list               args)
- {
-     vpx_codec_ctrl_fn_map_t *entry;
-     switch (ctrl_id)
-     {
-     case VP8E_SET_FLUSHFLAG:
-         /* VP8 sample code did VP8E_SET_FLUSHFLAG followed by
-          * vpx_codec_get_cx_data() rather than vpx_codec_encode().
-          */
-         return vp8e_encode(ctx, NULL, 0, 0, 0, 0);
-     case VP8E_SET_FRAMETYPE:
-         ctx->base.enc.tbd |= FORCE_KEY;
-         return VPX_CODEC_OK;
-     }
-     for (entry = vp8e_ctf_maps; entry && entry->fn; entry++)
-     {
-         if (!entry->ctrl_id || entry->ctrl_id == ctrl_id)
-         {
-             return entry->fn(ctx, ctrl_id, args);
-         }
-     }
-     return VPX_CODEC_ERROR;
- }
- static vpx_codec_ctrl_fn_map_t api1_ctrl_maps[] =
- {
-     {0, api1_control},
-     { -1, NULL}
- };
- static vpx_codec_err_t api1_encode(vpx_codec_alg_priv_t  *ctx,
-                                    const vpx_image_t     *img,
-                                    vpx_codec_pts_t        pts,
-                                    unsigned long          duration,
-                                    vpx_enc_frame_flags_t  flags,
-                                    unsigned long          deadline)
- {
-     int force = ctx->base.enc.tbd;
-     ctx->base.enc.tbd = 0;
-     return vp8e_encode
-            (ctx,
-             img,
-             pts,
-             duration,
-             flags | ((force & FORCE_KEY) ? VPX_EFLAG_FORCE_KF : 0),
-             deadline);
- }
- vpx_codec_iface_t vpx_enc_vp8_algo =
- {
-     "WebM Project VP8 Encoder (Deprecated API)" VERSION_STRING,
-     VPX_CODEC_INTERNAL_ABI_VERSION,
-     VPX_CODEC_CAP_ENCODER,
-     /* vpx_codec_caps_t          caps; */
-     vp8e_init,          /* vpx_codec_init_fn_t       init; */
-     vp8e_destroy,       /* vpx_codec_destroy_fn_t    destroy; */
-     api1_ctrl_maps,     /* vpx_codec_ctrl_fn_map_t  *ctrl_maps; */
-     NOT_IMPLEMENTED,    /* vpx_codec_get_mmap_fn_t   get_mmap; */
-     NOT_IMPLEMENTED,    /* vpx_codec_set_mmap_fn_t   set_mmap; */
-     {NOT_IMPLEMENTED},  /* decoder functions */
-     {
-         vp8e_usage_cfg_map, /* vpx_codec_enc_cfg_map_t    peek_si; */
-         api1_encode,        /* vpx_codec_encode_fn_t      encode; */
-         vp8e_get_cxdata,    /* vpx_codec_get_cx_data_fn_t   frame_get; */
-         vp8e_set_config,
-         NOT_IMPLEMENTED,
-         vp8e_get_preview,
-         vp8e_mr_alloc_mem,
-     } /* encoder functions */
- };
diff --combined vp8/vp8cx.mk
@@@ -39,6 -39,7 +39,7 @@@ VP8_CX_SRCS-yes += encoder/bitstream.
  VP8_CX_SRCS-yes += encoder/boolhuff.c
  VP8_CX_SRCS-yes += encoder/dct.c
  VP8_CX_SRCS-yes += encoder/encodeframe.c
+ VP8_CX_SRCS-yes += encoder/encodeframe.h
  VP8_CX_SRCS-yes += encoder/encodeintra.c
  VP8_CX_SRCS-yes += encoder/encodemb.c
  VP8_CX_SRCS-yes += encoder/encodemv.c
@@@ -87,8 -88,6 +88,8 @@@ VP8_CX_SRCS-yes += encoder/temporal_fil
  VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING) += encoder/mr_dissim.c
  VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING) += encoder/mr_dissim.h
  
 +VP8_CX_SRCS-$(CONFIG_UNIT_TESTS) += encoder/boolcoder_test.cc
 +
  ifeq ($(CONFIG_REALTIME_ONLY),yes)
  VP8_CX_SRCS_REMOVE-yes += encoder/firstpass.c
  VP8_CX_SRCS_REMOVE-yes += encoder/temporal_filter.c