]> granicus.if.org Git - libvpx/blobdiff - vp8/encoder/onyx_if.c
Merge "Remove goldfreq in VP8_COMP"
[libvpx] / vp8 / encoder / onyx_if.c
index c24e944ee22af75edd26420b96982d4e85a476ac..d50076d3b871116ed8667002ca740a97c360f170 100644 (file)
@@ -57,10 +57,6 @@ extern unsigned int vp8_get_processor_freq();
 extern void print_tree_update_probs();
 extern void vp8cx_create_encoder_threads(VP8_COMP *cpi);
 extern void vp8cx_remove_encoder_threads(VP8_COMP *cpi);
-#if HAVE_NEON
-extern void vp8_yv12_copy_frame_func_neon(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc);
-extern void vp8_yv12_copy_src_frame_func_neon(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc);
-#endif
 
 int vp8_estimate_entropy_savings(VP8_COMP *cpi);
 
@@ -143,7 +139,7 @@ extern const int qzbin_factors[129];
 extern void vp8cx_init_quantizer(VP8_COMP *cpi);
 extern const int vp8cx_base_skip_false_prob[128];
 
-// Tables relating active max Q to active min Q
+/* Tables relating active max Q to active min Q */
 static const unsigned char kf_low_motion_minq[QINDEX_RANGE] =
 {
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@@ -219,9 +215,8 @@ static void save_layer_context(VP8_COMP *cpi)
 {
     LAYER_CONTEXT *lc = &cpi->layer_context[cpi->current_layer];
 
-    // Save layer dependent coding state
+    /* Save layer dependent coding state */
     lc->target_bandwidth                 = cpi->target_bandwidth;
-    //lc->target_bandwidth                 = cpi->oxcf.target_bandwidth;
     lc->starting_buffer_level            = cpi->oxcf.starting_buffer_level;
     lc->optimal_buffer_level             = cpi->oxcf.optimal_buffer_level;
     lc->maximum_buffer_size              = cpi->oxcf.maximum_buffer_size;
@@ -258,7 +253,7 @@ static void restore_layer_context(VP8_COMP *cpi, const int layer)
 {
     LAYER_CONTEXT *lc = &cpi->layer_context[layer];
 
-    // Restore layer dependent coding state
+    /* Restore layer dependent coding state */
     cpi->current_layer                    = layer;
     cpi->target_bandwidth                 = lc->target_bandwidth;
     cpi->oxcf.target_bandwidth            = lc->target_bandwidth;
@@ -271,9 +266,7 @@ static void restore_layer_context(VP8_COMP *cpi, const int layer)
     cpi->buffer_level                     = lc->buffer_level;
     cpi->bits_off_target                  = lc->bits_off_target;
     cpi->total_actual_bits                = lc->total_actual_bits;
-    //cpi->worst_quality                    = lc->worst_quality;
     cpi->active_worst_quality             = lc->active_worst_quality;
-    //cpi->best_quality                     = lc->best_quality;
     cpi->active_best_quality              = lc->active_best_quality;
     cpi->ni_av_qi                         = lc->ni_av_qi;
     cpi->ni_tot_qi                        = lc->ni_tot_qi;
@@ -296,12 +289,17 @@ static void restore_layer_context(VP8_COMP *cpi, const int layer)
 
 static void setup_features(VP8_COMP *cpi)
 {
-    // Set up default state for MB feature flags
-    cpi->mb.e_mbd.segmentation_enabled = 0;
-    cpi->mb.e_mbd.update_mb_segmentation_map = 0;
-    cpi->mb.e_mbd.update_mb_segmentation_data = 0;
-    vpx_memset(cpi->mb.e_mbd.mb_segment_tree_probs, 255, sizeof(cpi->mb.e_mbd.mb_segment_tree_probs));
-    vpx_memset(cpi->mb.e_mbd.segment_feature_data, 0, sizeof(cpi->mb.e_mbd.segment_feature_data));
+    // If segmentation enabled set the update flags
+    if ( cpi->mb.e_mbd.segmentation_enabled )
+    {
+        cpi->mb.e_mbd.update_mb_segmentation_map = 1;
+        cpi->mb.e_mbd.update_mb_segmentation_data = 1;
+    }
+    else
+    {
+        cpi->mb.e_mbd.update_mb_segmentation_map = 0;
+        cpi->mb.e_mbd.update_mb_segmentation_data = 0;
+    }
 
     cpi->mb.e_mbd.mode_ref_lf_delta_enabled = 0;
     cpi->mb.e_mbd.mode_ref_lf_delta_update = 0;
@@ -323,7 +321,7 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
     vpx_free(cpi->tplist);
     cpi->tplist = NULL;
 
-    // Delete last frame MV storage buffers
+    /* Delete last frame MV storage buffers */
     vpx_free(cpi->lfmv);
     cpi->lfmv = 0;
 
@@ -333,7 +331,7 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
     vpx_free(cpi->lf_ref_frame);
     cpi->lf_ref_frame = 0;
 
-    // Delete sementation map
+    /* Delete sementation map */
     vpx_free(cpi->segmentation_map);
     cpi->segmentation_map = 0;
 
@@ -349,11 +347,11 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
     vpx_free(cpi->tok);
     cpi->tok = 0;
 
-    // Structure used to monitor GF usage
+    /* Structure used to monitor GF usage */
     vpx_free(cpi->gf_active_flags);
     cpi->gf_active_flags = 0;
 
-    // Activity mask based per mb zbin adjustments
+    /* Activity mask based per mb zbin adjustments */
     vpx_free(cpi->mb_activity_map);
     cpi->mb_activity_map = 0;
     vpx_free(cpi->mb_norm_activity_map);
@@ -365,37 +363,42 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
 
 static void enable_segmentation(VP8_COMP *cpi)
 {
-    // Set the appropriate feature bit
+    /* Set the appropriate feature bit */
     cpi->mb.e_mbd.segmentation_enabled = 1;
     cpi->mb.e_mbd.update_mb_segmentation_map = 1;
     cpi->mb.e_mbd.update_mb_segmentation_data = 1;
 }
 static void disable_segmentation(VP8_COMP *cpi)
 {
-    // Clear the appropriate feature bit
+    /* Clear the appropriate feature bit */
     cpi->mb.e_mbd.segmentation_enabled = 0;
 }
 
-// Valid values for a segment are 0 to 3
-// Segmentation map is arrange as [Rows][Columns]
+/* Valid values for a segment are 0 to 3
+ * Segmentation map is arrange as [Rows][Columns]
+ */
 static void set_segmentation_map(VP8_COMP *cpi, unsigned char *segmentation_map)
 {
-    // Copy in the new segmentation map
+    /* Copy in the new segmentation map */
     vpx_memcpy(cpi->segmentation_map, segmentation_map, (cpi->common.mb_rows * cpi->common.mb_cols));
 
-    // Signal that the map should be updated.
+    /* Signal that the map should be updated. */
     cpi->mb.e_mbd.update_mb_segmentation_map = 1;
     cpi->mb.e_mbd.update_mb_segmentation_data = 1;
 }
 
-// The values given for each segment can be either deltas (from the default value chosen for the frame) or absolute values.
-//
-// Valid range for abs values is (0-127 for MB_LVL_ALT_Q) , (0-63 for SEGMENT_ALT_LF)
-// Valid range for delta values are (+/-127 for MB_LVL_ALT_Q) , (+/-63 for SEGMENT_ALT_LF)
-//
-// abs_delta = SEGMENT_DELTADATA (deltas) abs_delta = SEGMENT_ABSDATA (use the absolute values given).
-//
-//
+/* The values given for each segment can be either deltas (from the default
+ * value chosen for the frame) or absolute values.
+ *
+ * Valid range for abs values is:
+ *    (0-127 for MB_LVL_ALT_Q), (0-63 for SEGMENT_ALT_LF)
+ * Valid range for delta values are:
+ *    (+/-127 for MB_LVL_ALT_Q), (+/-63 for SEGMENT_ALT_LF)
+ *
+ * abs_delta = SEGMENT_DELTADATA (deltas)
+ * abs_delta = SEGMENT_ABSDATA (use the absolute values given).
+ *
+ */
 static void set_segment_data(VP8_COMP *cpi, signed char *feature_data, unsigned char abs_delta)
 {
     cpi->mb.e_mbd.mb_segement_abs_delta = abs_delta;
@@ -411,26 +414,6 @@ static void segmentation_test_function(VP8_COMP *cpi)
     // Create a temporary map for segmentation data.
     CHECK_MEM_ERROR(seg_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
 
-    // MB loop to set local segmentation map
-    /*for ( i = 0; i < cpi->common.mb_rows; i++ )
-    {
-        for ( j = 0; j < cpi->common.mb_cols; j++ )
-        {
-            //seg_map[(i*cpi->common.mb_cols) + j] = (j % 2) + ((i%2)* 2);
-            //if ( j < cpi->common.mb_cols/2 )
-
-            // Segment 1 around the edge else 0
-            if ( (i == 0) || (j == 0) || (i == (cpi->common.mb_rows-1)) || (j == (cpi->common.mb_cols-1)) )
-                seg_map[(i*cpi->common.mb_cols) + j] = 1;
-            //else if ( (i < 2) || (j < 2) || (i > (cpi->common.mb_rows-3)) || (j > (cpi->common.mb_cols-3)) )
-            //  seg_map[(i*cpi->common.mb_cols) + j] = 2;
-            //else if ( (i < 5) || (j < 5) || (i > (cpi->common.mb_rows-6)) || (j > (cpi->common.mb_cols-6)) )
-            //  seg_map[(i*cpi->common.mb_cols) + j] = 3;
-            else
-                seg_map[(i*cpi->common.mb_cols) + j] = 0;
-        }
-    }*/
-
     // Set the segmentation Map
     set_segmentation_map(cpi, seg_map);
 
@@ -453,13 +436,12 @@ static void segmentation_test_function(VP8_COMP *cpi)
     set_segment_data(cpi, &feature_data[0][0], SEGMENT_DELTADATA);
 
     // Delete sementation map
-        vpx_free(seg_map);
+    vpx_free(seg_map);
 
     seg_map = 0;
-
 }
 
-// A simple function to cyclically refresh the background at a lower Q
+/* A simple function to cyclically refresh the background at a lower Q */
 static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
 {
     unsigned char *seg_map;
@@ -468,7 +450,7 @@ static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
     int block_count = cpi->cyclic_refresh_mode_max_mbs_perframe;
     int mbs_in_frame = cpi->common.mb_rows * cpi->common.mb_cols;
 
-    // Create a temporary map for segmentation data.
+    /* Create a temporary map for segmentation data. */
     CHECK_MEM_ERROR(seg_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
 
     cpi->cyclic_refresh_q = Q;
@@ -476,7 +458,6 @@ static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
     for (i = Q; i > 0; i--)
     {
         if (vp8_bits_per_mb[cpi->common.frame_type][i] >= ((vp8_bits_per_mb[cpi->common.frame_type][Q]*(Q + 128)) / 64))
-            //if ( vp8_bits_per_mb[cpi->common.frame_type][i] >= ((vp8_bits_per_mb[cpi->common.frame_type][Q]*((2*Q)+96))/64) )
         {
             break;
         }
@@ -484,16 +465,19 @@ static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
 
     cpi->cyclic_refresh_q = i;
 
-    // Only update for inter frames
+    /* Only update for inter frames */
     if (cpi->common.frame_type != KEY_FRAME)
     {
-        // Cycle through the macro_block rows
-        // MB loop to set local segmentation map
+        /* Cycle through the macro_block rows */
+        /* MB loop to set local segmentation map */
         for (i = cpi->cyclic_refresh_mode_index; i < mbs_in_frame; i++)
         {
-            // If the MB is as a candidate for clean up then mark it for possible boost/refresh (segment 1)
-            // The segment id may get reset to 0 later if the MB gets coded anything other than last frame 0,0
-            // as only (last frame 0,0) MBs are eligable for refresh : that is to say Mbs likely to be background blocks.
+            /* If the MB is as a candidate for clean up then mark it for
+             * possible boost/refresh (segment 1) The segment id may get
+             * reset to 0 later if the MB gets coded anything other than
+             * last frame 0,0 as only (last frame 0,0) MBs are eligable for
+             * refresh : that is to say Mbs likely to be background blocks.
+             */
             if (cpi->cyclic_refresh_map[i] == 0)
             {
                 seg_map[i] = 1;
@@ -502,9 +486,8 @@ static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
             {
                 seg_map[i] = 0;
 
-                // Skip blocks that have been refreshed recently anyway.
+                /* Skip blocks that have been refreshed recently anyway. */
                 if (cpi->cyclic_refresh_map[i] < 0)
-                    //cpi->cyclic_refresh_map[i] = cpi->cyclic_refresh_map[i] / 16;
                     cpi->cyclic_refresh_map[i]++;
             }
 
@@ -516,36 +499,35 @@ static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
 
         }
 
-        // If we have gone through the frame reset to the start
+        /* If we have gone through the frame reset to the start */
         cpi->cyclic_refresh_mode_index = i;
 
         if (cpi->cyclic_refresh_mode_index >= mbs_in_frame)
             cpi->cyclic_refresh_mode_index = 0;
     }
 
-    // Set the segmentation Map
+    /* Set the segmentation Map */
     set_segmentation_map(cpi, seg_map);
 
-    // Activate segmentation.
+    /* Activate segmentation. */
     enable_segmentation(cpi);
 
-    // Set up the quant segment data
+    /* Set up the quant segment data */
     feature_data[MB_LVL_ALT_Q][0] = 0;
     feature_data[MB_LVL_ALT_Q][1] = (cpi->cyclic_refresh_q - Q);
     feature_data[MB_LVL_ALT_Q][2] = 0;
     feature_data[MB_LVL_ALT_Q][3] = 0;
 
-    // Set up the loop segment data
+    /* Set up the loop segment data */
     feature_data[MB_LVL_ALT_LF][0] = 0;
     feature_data[MB_LVL_ALT_LF][1] = lf_adjustment;
     feature_data[MB_LVL_ALT_LF][2] = 0;
     feature_data[MB_LVL_ALT_LF][3] = 0;
 
-    // Initialise the feature data structure
-    // SEGMENT_DELTADATA    0, SEGMENT_ABSDATA      1
+    /* Initialise the feature data structure */
     set_segment_data(cpi, &feature_data[0][0], SEGMENT_DELTADATA);
 
-    // Delete sementation map
+    /* Delete sementation map */
     vpx_free(seg_map);
 
     seg_map = 0;
@@ -560,16 +542,16 @@ static void set_default_lf_deltas(VP8_COMP *cpi)
     vpx_memset(cpi->mb.e_mbd.ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
     vpx_memset(cpi->mb.e_mbd.mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
 
-    // Test of ref frame deltas
+    /* Test of ref frame deltas */
     cpi->mb.e_mbd.ref_lf_deltas[INTRA_FRAME] = 2;
     cpi->mb.e_mbd.ref_lf_deltas[LAST_FRAME] = 0;
     cpi->mb.e_mbd.ref_lf_deltas[GOLDEN_FRAME] = -2;
     cpi->mb.e_mbd.ref_lf_deltas[ALTREF_FRAME] = -2;
 
-    cpi->mb.e_mbd.mode_lf_deltas[0] = 4;               // BPRED
-    cpi->mb.e_mbd.mode_lf_deltas[1] = -2;              // Zero
-    cpi->mb.e_mbd.mode_lf_deltas[2] = 2;               // New mv
-    cpi->mb.e_mbd.mode_lf_deltas[3] = 4;               // Split mv
+    cpi->mb.e_mbd.mode_lf_deltas[0] = 4;               /* BPRED */
+    cpi->mb.e_mbd.mode_lf_deltas[1] = -2;              /* Zero */
+    cpi->mb.e_mbd.mode_lf_deltas[2] = 2;               /* New mv */
+    cpi->mb.e_mbd.mode_lf_deltas[3] = 4;               /* Split mv */
 }
 
 /* Convenience macros for mapping speed and mode into a continuous
@@ -669,7 +651,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
     int last_improved_quant = sf->improved_quant;
     int ref_frames;
 
-    // Initialise default mode frequency sampling variables
+    /* Initialise default mode frequency sampling variables */
     for (i = 0; i < MAX_MODES; i ++)
     {
         cpi->mode_check_freq[i] = 0;
@@ -679,7 +661,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
 
     cpi->mbs_tested_so_far = 0;
 
-    // best quality defaults
+    /* best quality defaults */
     sf->RD = 1;
     sf->search_method = NSTEP;
     sf->improved_quant = 1;
@@ -697,7 +679,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
     sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
     sf->improved_mv_pred = 1;
 
-    // default thresholds to 0
+    /* default thresholds to 0 */
     for (i = 0; i < MAX_MODES; i++)
         sf->thresh_mult[i] = 0;
 
@@ -779,7 +761,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
     switch (Mode)
     {
 #if !(CONFIG_REALTIME_ONLY)
-    case 0: // best quality mode
+    case 0: /* best quality mode */
         sf->first_step = 0;
         sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
         break;
@@ -800,8 +782,9 @@ void vp8_set_speed_features(VP8_COMP *cpi)
             sf->improved_quant = 0;
             sf->improved_dct = 0;
 
-            // Only do recode loop on key frames, golden frames and
-            // alt ref frames
+            /* Only do recode loop on key frames, golden frames and
+             * alt ref frames
+             */
             sf->recode_loop = 2;
 
         }
@@ -809,14 +792,14 @@ void vp8_set_speed_features(VP8_COMP *cpi)
         if (Speed > 3)
         {
             sf->auto_filter = 1;
-            sf->recode_loop = 0; // recode loop off
-            sf->RD = 0;         // Turn rd off
+            sf->recode_loop = 0; /* recode loop off */
+            sf->RD = 0;         /* Turn rd off */
 
         }
 
         if (Speed > 4)
         {
-            sf->auto_filter = 0;                     // Faster selection of loop filter
+            sf->auto_filter = 0;  /* Faster selection of loop filter */
         }
 
         break;
@@ -839,7 +822,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
         }
 
         if (Speed > 2)
-            sf->auto_filter = 0;                     // Faster selection of loop filter
+            sf->auto_filter = 0;  /* Faster selection of loop filter */
 
         if (Speed > 3)
         {
@@ -849,7 +832,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
 
         if (Speed > 4)
         {
-            sf->auto_filter = 0;                     // Faster selection of loop filter
+            sf->auto_filter = 0;  /* Faster selection of loop filter */
             sf->search_method = HEX;
             sf->iterative_sub_pixel = 0;
         }
@@ -876,7 +859,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
             total_skip = sum;
             sum = 0;
 
-            // i starts from 2 to make sure thresh started from 2048
+            /* i starts from 2 to make sure thresh started from 2048 */
             for (; i < 1024; i++)
             {
                 sum += cpi->error_bins[i];
@@ -930,7 +913,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
             cm->filter_type = SIMPLE_LOOPFILTER;
         }
 
-        // This has a big hit on quality. Last resort
+        /* This has a big hit on quality. Last resort */
         if (Speed >= 15)
             sf->half_pixel_search = 0;
 
@@ -938,8 +921,9 @@ void vp8_set_speed_features(VP8_COMP *cpi)
 
     }; /* switch */
 
-    // Slow quant, dct and trellis not worthwhile for first pass
-    // so make sure they are always turned off.
+    /* Slow quant, dct and trellis not worthwhile for first pass
+     * so make sure they are always turned off.
+     */
     if ( cpi->pass == 1 )
     {
         sf->improved_quant = 0;
@@ -1107,13 +1091,13 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
         CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok)));
     }
 
-    // Data used for real time vc mode to see if gf needs refreshing
+    /* Data used for real time vc mode to see if gf needs refreshing */
     cpi->inter_zz_count = 0;
     cpi->gf_bad_count = 0;
     cpi->gf_update_recommended = 0;
 
 
-    // Structures used to minitor GF usage
+    /* Structures used to minitor GF usage */
     vpx_free(cpi->gf_active_flags);
     CHECK_MEM_ERROR(cpi->gf_active_flags,
                     vpx_calloc(1, cm->mb_rows * cm->mb_cols));
@@ -1146,7 +1130,7 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
 }
 
 
-// Quant MOD
+/* Quant MOD */
 static const int q_trans[] =
 {
     0,   1,  2,  3,  4,  5,  7,  8,
@@ -1168,7 +1152,7 @@ int vp8_reverse_trans(int x)
             return i;
 
     return 63;
-};
+}
 void vp8_new_frame_rate(VP8_COMP *cpi, double framerate)
 {
     if(framerate < .1)
@@ -1182,16 +1166,16 @@ void vp8_new_frame_rate(VP8_COMP *cpi, double framerate)
     cpi->min_frame_bandwidth    = (int)(cpi->av_per_frame_bandwidth *
                                   cpi->oxcf.two_pass_vbrmin_section / 100);
 
-    // Set Maximum gf/arf interval
+    /* Set Maximum gf/arf interval */
     cpi->max_gf_interval = ((int)(cpi->output_frame_rate / 2.0) + 2);
 
     if(cpi->max_gf_interval < 12)
         cpi->max_gf_interval = 12;
 
-    // Extended interval for genuinely static scenes
+    /* Extended interval for genuinely static scenes */
     cpi->twopass.static_scene_max_gf_interval = cpi->key_frame_frequency >> 1;
 
-     // Special conditions when altr ref frame enabled in lagged compress mode
+     /* Special conditions when altr ref frame enabled in lagged compress mode */
     if (cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames)
     {
         if (cpi->max_gf_interval > cpi->oxcf.lag_in_frames - 1)
@@ -1243,15 +1227,15 @@ static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
 
     cpi->ref_frame_rate = cpi->frame_rate;
 
-    // change includes all joint functionality
+    /* change includes all joint functionality */
     vp8_change_config(cpi, oxcf);
 
-    // Initialize active best and worst q and average q values.
+    /* Initialize active best and worst q and average q values. */
     cpi->active_worst_quality         = cpi->oxcf.worst_allowed_q;
     cpi->active_best_quality          = cpi->oxcf.best_allowed_q;
     cpi->avg_frame_qindex             = cpi->oxcf.worst_allowed_q;
 
-    // Initialise the starting buffer levels
+    /* Initialise the starting buffer levels */
     cpi->buffer_level                 = cpi->oxcf.starting_buffer_level;
     cpi->bits_off_target              = cpi->oxcf.starting_buffer_level;
 
@@ -1263,7 +1247,7 @@ static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
     cpi->total_actual_bits            = 0;
     cpi->total_target_vs_actual       = 0;
 
-    // Temporal scalabilty
+    /* Temporal scalabilty */
     if (cpi->oxcf.number_of_layers > 1)
     {
         unsigned int i;
@@ -1273,7 +1257,7 @@ static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
         {
             LAYER_CONTEXT *lc = &cpi->layer_context[i];
 
-            // Layer configuration
+            /* Layer configuration */
             lc->frame_rate =
                         cpi->output_frame_rate / cpi->oxcf.rate_decimator[i];
             lc->target_bandwidth = cpi->oxcf.target_bitrate[i] * 1000;
@@ -1300,7 +1284,7 @@ static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
                   rescale(oxcf->maximum_buffer_size,
                           lc->target_bandwidth, 1000);
 
-            // Work out the average size of a frame within this layer
+            /* Work out the average size of a frame within this layer */
             if (i > 0)
                 lc->avg_frame_size_for_layer = (cpi->oxcf.target_bitrate[i] -
                     cpi->oxcf.target_bitrate[i-1]) * 1000 /
@@ -1374,7 +1358,7 @@ static void update_layer_contexts (VP8_COMP *cpi)
                           oxcf->maximum_buffer_size_in_ms,
                           lc->target_bandwidth, 1000);
 
-            // Work out the average size of a frame within this layer
+            /* Work out the average size of a frame within this layer */
             if (i > 0)
                 lc->avg_frame_size_for_layer = (oxcf->target_bitrate[i] -
                     oxcf->target_bitrate[i-1]) * 1000 /
@@ -1515,8 +1499,6 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
 
     cpi->ref_frame_flags = VP8_ALTR_FRAME | VP8_GOLD_FRAME | VP8_LAST_FRAME;
 
-    //cpi->use_golden_frame_only = 0;
-    //cpi->use_last_frame_only = 0;
     cm->refresh_golden_frame = 0;
     cm->refresh_last_frame = 1;
     cm->refresh_entropy_probs = 1;
@@ -1538,11 +1520,11 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
             cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout;
     }
 
-    // At the moment the first order values may not be > MAXQ
+    /* At the moment the first order values may not be > MAXQ */
     if (cpi->oxcf.fixed_q > MAXQ)
         cpi->oxcf.fixed_q = MAXQ;
 
-    // local file playback mode == really big buffer
+    /* local file playback mode == really big buffer */
     if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK)
     {
         cpi->oxcf.starting_buffer_level       = 60000;
@@ -1553,14 +1535,14 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
         cpi->oxcf.maximum_buffer_size_in_ms   = 240000;
     }
 
-    // Convert target bandwidth from Kbit/s to Bit/s
+    /* Convert target bandwidth from Kbit/s to Bit/s */
     cpi->oxcf.target_bandwidth       *= 1000;
 
     cpi->oxcf.starting_buffer_level =
         rescale(cpi->oxcf.starting_buffer_level,
                 cpi->oxcf.target_bandwidth, 1000);
 
-    // Set or reset optimal and maximum buffer levels.
+    /* Set or reset optimal and maximum buffer levels. */
     if (cpi->oxcf.optimal_buffer_level == 0)
         cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
     else
@@ -1575,19 +1557,19 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
             rescale(cpi->oxcf.maximum_buffer_size,
                     cpi->oxcf.target_bandwidth, 1000);
 
-    // Set up frame rate and related parameters rate control values.
+    /* Set up frame rate and related parameters rate control values. */
     vp8_new_frame_rate(cpi, cpi->frame_rate);
 
-    // Set absolute upper and lower quality limits
+    /* Set absolute upper and lower quality limits */
     cpi->worst_quality               = cpi->oxcf.worst_allowed_q;
     cpi->best_quality                = cpi->oxcf.best_allowed_q;
 
-    // active values should only be modified if out of new range
+    /* active values should only be modified if out of new range */
     if (cpi->active_worst_quality > cpi->oxcf.worst_allowed_q)
     {
       cpi->active_worst_quality = cpi->oxcf.worst_allowed_q;
     }
-    // less likely
+    /* less likely */
     else if (cpi->active_worst_quality < cpi->oxcf.best_allowed_q)
     {
       cpi->active_worst_quality = cpi->oxcf.best_allowed_q;
@@ -1596,7 +1578,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
     {
       cpi->active_best_quality = cpi->oxcf.best_allowed_q;
     }
-    // less likely
+    /* less likely */
     else if (cpi->active_best_quality > cpi->oxcf.worst_allowed_q)
     {
       cpi->active_best_quality = cpi->oxcf.worst_allowed_q;
@@ -1606,7 +1588,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
 
     cpi->cq_target_quality = cpi->oxcf.cq_level;
 
-    // Only allow dropped frames in buffered mode
+    /* Only allow dropped frames in buffered mode */
     cpi->drop_frames_allowed = cpi->oxcf.allow_df && cpi->buffered_mode;
 
     cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
@@ -1621,7 +1603,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
      * correct.
      */
 
-    // VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs)
+    /* VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs) */
     if (cpi->oxcf.Sharpness > 7)
         cpi->oxcf.Sharpness = 7;
 
@@ -1635,7 +1617,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
         Scale2Ratio(cm->horiz_scale, &hr, &hs);
         Scale2Ratio(cm->vert_scale, &vr, &vs);
 
-        // always go to the next whole number
+        /* always go to the next whole number */
         cm->Width = (hs - 1 + cpi->oxcf.Width * hr) / hs;
         cm->Height = (vs - 1 + cpi->oxcf.Height * vr) / vs;
     }
@@ -1662,16 +1644,16 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
 
     cpi->Speed = cpi->oxcf.cpu_used;
 
-    // force to allowlag to 0 if lag_in_frames is 0;
+    /* force to allowlag to 0 if lag_in_frames is 0; */
     if (cpi->oxcf.lag_in_frames == 0)
     {
         cpi->oxcf.allow_lag = 0;
     }
-    // Limit on lag buffers as these are not currently dynamically allocated
+    /* Limit on lag buffers as these are not currently dynamically allocated */
     else if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS)
         cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS;
 
-    // YX Temp
+    /* YX Temp */
     cpi->alt_ref_source = NULL;
     cpi->is_src_frame_alt_ref = 0;
 
@@ -1688,7 +1670,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
 #endif
 
 #if 0
-    // Experimental RD Code
+    /* Experimental RD Code */
     cpi->frame_distortion = 0;
     cpi->last_frame_distortion = 0;
 #endif
@@ -1723,7 +1705,7 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     VP8_COMMON *cm;
 
     cpi = vpx_memalign(32, sizeof(VP8_COMP));
-    // Check that the CPI instance is valid
+    /* Check that the CPI instance is valid */
     if (!cpi)
         return 0;
 
@@ -1757,14 +1739,15 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     cpi->prob_gf_coded                = 128;
     cpi->prob_intra_coded             = 63;
 
-    // Prime the recent reference frame usage counters.
-    // Hereafter they will be maintained as a sort of moving average
+    /* Prime the recent reference frame usage counters.
+     * Hereafter they will be maintained as a sort of moving average
+     */
     cpi->recent_ref_frame_usage[INTRA_FRAME]  = 1;
     cpi->recent_ref_frame_usage[LAST_FRAME]   = 1;
     cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
     cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
 
-    // Set reference frame sign bias for ALTREF frame to 1 (for now)
+    /* Set reference frame sign bias for ALTREF frame to 1 (for now) */
     cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
 
     cpi->twopass.gf_decay_rate = 0;
@@ -1774,21 +1757,22 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     cpi->alt_is_last  = 0 ;
     cpi->gold_is_alt  = 0 ;
 
-    // allocate memory for storing last frame's MVs for MV prediction.
+    /* allocate memory for storing last frame's MVs for MV prediction. */
     CHECK_MEM_ERROR(cpi->lfmv, vpx_calloc((cpi->common.mb_rows+2) * (cpi->common.mb_cols+2), sizeof(int_mv)));
     CHECK_MEM_ERROR(cpi->lf_ref_frame_sign_bias, vpx_calloc((cpi->common.mb_rows+2) * (cpi->common.mb_cols+2), sizeof(int)));
     CHECK_MEM_ERROR(cpi->lf_ref_frame, vpx_calloc((cpi->common.mb_rows+2) * (cpi->common.mb_cols+2), sizeof(int)));
 
-    // Create the encoder segmentation map and set all entries to 0
+    /* Create the encoder segmentation map and set all entries to 0 */
     CHECK_MEM_ERROR(cpi->segmentation_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
+
     CHECK_MEM_ERROR(cpi->active_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
     vpx_memset(cpi->active_map , 1, (cpi->common.mb_rows * cpi->common.mb_cols));
     cpi->active_map_enabled = 0;
 
 #if 0
-    // Experimental code for lagged and one pass
-    // Initialise one_pass GF frames stats
-    // Update stats used for GF selection
+    /* Experimental code for lagged and one pass */
+    /* Initialise one_pass GF frames stats */
+    /* Update stats used for GF selection */
     if (cpi->pass == 0)
     {
         cpi->one_pass_frame_index = 0;
@@ -1808,8 +1792,9 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     }
 #endif
 
-    // Should we use the cyclic refresh method.
-    // Currently this is tied to error resilliant mode
+    /* Should we use the cyclic refresh method.
+     * Currently this is tied to error resilliant mode
+     */
     cpi->cyclic_refresh_mode_enabled = cpi->oxcf.error_resilient_mode;
     cpi->cyclic_refresh_mode_max_mbs_perframe = (cpi->common.mb_rows * cpi->common.mb_cols) / 40;
     cpi->cyclic_refresh_mode_index = 0;
@@ -1822,9 +1807,6 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     else
         cpi->cyclic_refresh_map = (signed char *) NULL;
 
-    // Test function for segmentation
-    //segmentation_test_function( cpi);
-
 #ifdef ENTROPY_STATS
     init_context_counters();
 #endif
@@ -1832,7 +1814,8 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     /*Initialize the feed-forward activity masking.*/
     cpi->activity_avg = 90<<12;
 
-    cpi->frames_since_key = 8;        // Give a sensible default for the first frame.
+    /* Give a sensible default for the first frame. */
+    cpi->frames_since_key = 8;
     cpi->key_frame_frequency = cpi->oxcf.key_freq;
     cpi->this_key_frame_forced = 0;
     cpi->next_key_frame_forced = 0;
@@ -1875,10 +1858,7 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
 
 #endif
 
-#ifndef LLONG_MAX
-#define LLONG_MAX  9223372036854775807LL
-#endif
-    cpi->first_time_stamp_ever = LLONG_MAX;
+    cpi->first_time_stamp_ever = 0x7FFFFFFF;
 
     cpi->frames_till_gf_update_due      = 0;
     cpi->key_frame_count              = 1;
@@ -1933,14 +1913,13 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
 
     if (cpi->compressor_speed == 2)
     {
-        cpi->cpu_freq            = 0; //vp8_get_processor_freq();
         cpi->avg_encode_time      = 0;
         cpi->avg_pick_mode_time    = 0;
     }
 
     vp8_set_speed_features(cpi);
 
-    // Set starting values of RD threshold multipliers (128 = *1)
+    /* Set starting values of RD threshold multipliers (128 = *1) */
     for (i = 0; i < MAX_MODES; i++)
     {
         cpi->rd_thresh_mult[i] = 128;
@@ -2016,11 +1995,14 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     cpi->diamond_search_sad = vp8_diamond_search_sad;
     cpi->refining_search_sad = vp8_refining_search_sad;
 
-    // make sure frame 1 is okay
+    /* make sure frame 1 is okay */
     cpi->error_bins[0] = cpi->common.MBs;
 
-    //vp8cx_init_quantizer() is first called here. Add check in vp8cx_frame_init_quantizer() so that vp8cx_init_quantizer is only called later
-    //when needed. This will avoid unnecessary calls of vp8cx_init_quantizer() for every frame.
+    /* vp8cx_init_quantizer() is first called here. Add check in
+     * vp8cx_frame_init_quantizer() so that vp8cx_init_quantizer is only
+     * called later when needed. This will avoid unnecessary calls of
+     * vp8cx_init_quantizer() for every frame.
+     */
     vp8cx_init_quantizer(cpi);
 
     vp8_loop_filter_init(cm);
@@ -2205,7 +2187,6 @@ void vp8_remove_compressor(VP8_COMP **ptr)
                 fprintf(f, "%5d", frames_at_speed[i]);
 
             fprintf(f, "\n");
-            //fprintf(f, "%10d PM %10d %10d %10d EF %10d %10d %10d\n", cpi->Speed, cpi->avg_pick_mode_time, (tot_pm/cnt_pm), cnt_pm,  cpi->avg_encode_time, 0, 0);
             fclose(f);
         }
 
@@ -2267,7 +2248,7 @@ void vp8_remove_compressor(VP8_COMP **ptr)
             for (i = 0; i < 10; i++)
             {
 
-                fprintf(fmode, "    { //Above Mode :  %d\n", i);
+                fprintf(fmode, "    { /* Above Mode :  %d */\n", i);
 
                 for (j = 0; j < 10; j++)
                 {
@@ -2282,7 +2263,7 @@ void vp8_remove_compressor(VP8_COMP **ptr)
                             fprintf(fmode, " %5d, ", intra_mode_stats[i][j][k]);
                     }
 
-                    fprintf(fmode, "}, // left_mode %d\n", j);
+                    fprintf(fmode, "}, /* left_mode %d */\n", j);
 
                 }
 
@@ -2584,7 +2565,7 @@ static void scale_and_extend_source(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
 {
     VP8_COMMON *cm = &cpi->common;
 
-    // are we resizing the image
+    /* are we resizing the image */
     if (cm->horiz_scale != 0 || cm->vert_scale != 0)
     {
 #if CONFIG_SPATIAL_RESAMPLING
@@ -2617,36 +2598,40 @@ static int resize_key_frame(VP8_COMP *cpi)
 #if CONFIG_SPATIAL_RESAMPLING
     VP8_COMMON *cm = &cpi->common;
 
-    // Do we need to apply resampling for one pass cbr.
-    // In one pass this is more limited than in two pass cbr
-    // The test and any change is only made one per key frame sequence
+    /* Do we need to apply resampling for one pass cbr.
+     * In one pass this is more limited than in two pass cbr
+     * The test and any change is only made one per key frame sequence
+     */
     if (cpi->oxcf.allow_spatial_resampling && (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER))
     {
         int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
         int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
         int new_width, new_height;
 
-        // If we are below the resample DOWN watermark then scale down a notch.
+        /* If we are below the resample DOWN watermark then scale down a
+         * notch.
+         */
         if (cpi->buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100))
         {
             cm->horiz_scale = (cm->horiz_scale < ONETWO) ? cm->horiz_scale + 1 : ONETWO;
             cm->vert_scale = (cm->vert_scale < ONETWO) ? cm->vert_scale + 1 : ONETWO;
         }
-        // Should we now start scaling back up
+        /* Should we now start scaling back up */
         else if (cpi->buffer_level > (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100))
         {
             cm->horiz_scale = (cm->horiz_scale > NORMAL) ? cm->horiz_scale - 1 : NORMAL;
             cm->vert_scale = (cm->vert_scale > NORMAL) ? cm->vert_scale - 1 : NORMAL;
         }
 
-        // Get the new hieght and width
+        /* Get the new hieght and width */
         Scale2Ratio(cm->horiz_scale, &hr, &hs);
         Scale2Ratio(cm->vert_scale, &vr, &vs);
         new_width = ((hs - 1) + (cpi->oxcf.Width * hr)) / hs;
         new_height = ((vs - 1) + (cpi->oxcf.Height * vr)) / vs;
 
-        // If the image size has changed we need to reallocate the buffers
-        // and resample the source image
+        /* If the image size has changed we need to reallocate the buffers
+         * and resample the source image
+         */
         if ((cm->Width != new_width) || (cm->Height != new_height))
         {
             cm->Width = new_width;
@@ -2666,7 +2651,7 @@ static void update_alt_ref_frame_stats(VP8_COMP *cpi)
 {
     VP8_COMMON *cm = &cpi->common;
 
-    // Select an interval before next GF or altref
+    /* Select an interval before next GF or altref */
     if (!cpi->auto_gold)
         cpi->frames_till_gf_update_due = DEFAULT_GF_INTERVAL;
 
@@ -2674,26 +2659,27 @@ static void update_alt_ref_frame_stats(VP8_COMP *cpi)
     {
         cpi->current_gf_interval = cpi->frames_till_gf_update_due;
 
-        // Set the bits per frame that we should try and recover in subsequent inter frames
-        // to account for the extra GF spend... note that his does not apply for GF updates
-        // that occur coincident with a key frame as the extra cost of key frames is dealt
-        // with elsewhere.
-
+        /* Set the bits per frame that we should try and recover in
+         * subsequent inter frames to account for the extra GF spend...
+         * note that his does not apply for GF updates that occur
+         * coincident with a key frame as the extra cost of key frames is
+         * dealt with elsewhere.
+         */
         cpi->gf_overspend_bits += cpi->projected_frame_size;
         cpi->non_gf_bitrate_adjustment = cpi->gf_overspend_bits / cpi->frames_till_gf_update_due;
     }
 
-    // Update data structure that monitors level of reference to last GF
+    /* Update data structure that monitors level of reference to last GF */
     vpx_memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
     cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
 
-    // this frame refreshes means next frames don't unless specified by user
+    /* this frame refreshes means next frames don't unless specified by user */
     cpi->common.frames_since_golden = 0;
 
-    // Clear the alternate reference update pending flag.
+    /* Clear the alternate reference update pending flag. */
     cpi->source_alt_ref_pending = 0;
 
-    // Set the alternate refernce frame active flag
+    /* Set the alternate refernce frame active flag */
     cpi->source_alt_ref_active = 1;
 
 
@@ -2702,10 +2688,10 @@ static void update_golden_frame_stats(VP8_COMP *cpi)
 {
     VP8_COMMON *cm = &cpi->common;
 
-    // Update the Golden frame usage counts.
+    /* Update the Golden frame usage counts. */
     if (cm->refresh_golden_frame)
     {
-        // Select an interval before next GF
+        /* Select an interval before next GF */
         if (!cpi->auto_gold)
             cpi->frames_till_gf_update_due = DEFAULT_GF_INTERVAL;
 
@@ -2713,14 +2699,18 @@ static void update_golden_frame_stats(VP8_COMP *cpi)
         {
             cpi->current_gf_interval = cpi->frames_till_gf_update_due;
 
-            // Set the bits per frame that we should try and recover in subsequent inter frames
-            // to account for the extra GF spend... note that his does not apply for GF updates
-            // that occur coincident with a key frame as the extra cost of key frames is dealt
-            // with elsewhere.
+            /* Set the bits per frame that we should try and recover in
+             * subsequent inter frames to account for the extra GF spend...
+             * note that his does not apply for GF updates that occur
+             * coincident with a key frame as the extra cost of key frames
+             * is dealt with elsewhere.
+             */
             if ((cm->frame_type != KEY_FRAME) && !cpi->source_alt_ref_active)
             {
-                // Calcluate GF bits to be recovered
-                // Projected size - av frame bits available for inter frames for clip as a whole
+                /* Calcluate GF bits to be recovered
+                 * Projected size - av frame bits available for inter
+                 * frames for clip as a whole
+                 */
                 cpi->gf_overspend_bits += (cpi->projected_frame_size - cpi->inter_frame_target);
             }
 
@@ -2728,32 +2718,25 @@ static void update_golden_frame_stats(VP8_COMP *cpi)
 
         }
 
-        // Update data structure that monitors level of reference to last GF
+        /* Update data structure that monitors level of reference to last GF */
         vpx_memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
         cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
 
-        // this frame refreshes means next frames don't unless specified by user
+        /* this frame refreshes means next frames don't unless specified by
+         * user
+         */
         cm->refresh_golden_frame = 0;
         cpi->common.frames_since_golden = 0;
 
-        //if ( cm->frame_type == KEY_FRAME )
-        //{
         cpi->recent_ref_frame_usage[INTRA_FRAME] = 1;
         cpi->recent_ref_frame_usage[LAST_FRAME] = 1;
         cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
         cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
-        //}
-        //else
-        //{
-        //  // Carry a potrtion of count over to begining of next gf sequence
-        //  cpi->recent_ref_frame_usage[INTRA_FRAME] >>= 5;
-        //  cpi->recent_ref_frame_usage[LAST_FRAME] >>= 5;
-        //  cpi->recent_ref_frame_usage[GOLDEN_FRAME] >>= 5;
-        //  cpi->recent_ref_frame_usage[ALTREF_FRAME] >>= 5;
-        //}
-
-        // ******** Fixed Q test code only ************
-        // If we are going to use the ALT reference for the next group of frames set a flag to say so.
+
+        /* ******** Fixed Q test code only ************ */
+        /* If we are going to use the ALT reference for the next group of
+         * frames set a flag to say so.
+         */
         if (cpi->oxcf.fixed_q >= 0 &&
             cpi->oxcf.play_alternate && !cpi->common.refresh_alt_ref_frame)
         {
@@ -2764,14 +2747,14 @@ static void update_golden_frame_stats(VP8_COMP *cpi)
         if (!cpi->source_alt_ref_pending)
             cpi->source_alt_ref_active = 0;
 
-        // Decrement count down till next gf
+        /* Decrement count down till next gf */
         if (cpi->frames_till_gf_update_due > 0)
             cpi->frames_till_gf_update_due--;
 
     }
     else if (!cpi->common.refresh_alt_ref_frame)
     {
-        // Decrement count down till next gf
+        /* Decrement count down till next gf */
         if (cpi->frames_till_gf_update_due > 0)
             cpi->frames_till_gf_update_due--;
 
@@ -2790,8 +2773,9 @@ static void update_golden_frame_stats(VP8_COMP *cpi)
     }
 }
 
-// This function updates the reference frame probability estimates that
-// will be used during mode selection
+/* This function updates the reference frame probability estimates that
+ * will be used during mode selection
+ */
 static void update_rd_ref_frame_probs(VP8_COMP *cpi)
 {
     VP8_COMMON *cm = &cpi->common;
@@ -2813,7 +2797,9 @@ static void update_rd_ref_frame_probs(VP8_COMP *cpi)
         cpi->prob_gf_coded    = 128;
     }
 
-    // update reference frame costs since we can do better than what we got last frame.
+    /* update reference frame costs since we can do better than what we got
+     * last frame.
+     */
     if (cpi->oxcf.number_of_layers == 1)
     {
         if (cpi->common.refresh_alt_ref_frame)
@@ -2844,7 +2830,7 @@ static void update_rd_ref_frame_probs(VP8_COMP *cpi)
 }
 
 
-// 1 = key, 0 = inter
+/* 1 = key, 0 = inter */
 static int decide_key_frame(VP8_COMP *cpi)
 {
     VP8_COMMON *cm = &cpi->common;
@@ -2856,8 +2842,8 @@ static int decide_key_frame(VP8_COMP *cpi)
     if (cpi->Speed > 11)
         return 0;
 
-    // Clear down mmx registers
-    vp8_clear_system_state();  //__asm emms;
+    /* Clear down mmx registers */
+    vp8_clear_system_state();
 
     if ((cpi->compressor_speed == 2) && (cpi->Speed >= 5) && (cpi->sf.RD == 0))
     {
@@ -2903,7 +2889,7 @@ static int decide_key_frame(VP8_COMP *cpi)
 
     }
 
-    // If the following are true we might as well code a key frame
+    /* If the following are true we might as well code a key frame */
     if (((cpi->this_frame_percent_intra == 100) &&
          (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra + 2))) ||
         ((cpi->this_frame_percent_intra > 95) &&
@@ -2911,9 +2897,12 @@ static int decide_key_frame(VP8_COMP *cpi)
     {
         code_key_frame = 1;
     }
-    // in addition if the following are true and this is not a golden frame then code a key frame
-    // Note that on golden frames there often seems to be a pop in intra useage anyway hence this
-    // restriction is designed to prevent spurious key frames. The Intra pop needs to be investigated.
+    /* in addition if the following are true and this is not a golden frame
+     * then code a key frame Note that on golden frames there often seems
+     * to be a pop in intra useage anyway hence this restriction is
+     * designed to prevent spurious key frames. The Intra pop needs to be
+     * investigated.
+     */
     else if (((cpi->this_frame_percent_intra > 60) &&
               (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra * 2))) ||
              ((cpi->this_frame_percent_intra > 75) &&
@@ -2945,7 +2934,7 @@ static void Pass1Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest,
 void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame)
 {
 
-    // write the frame
+    /* write the frame */
     FILE *yframe;
     int i;
     char filename[255];
@@ -2973,10 +2962,11 @@ void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame)
     fclose(yframe);
 }
 #endif
-// return of 0 means drop frame
+/* return of 0 means drop frame */
 
-// Function to test for conditions that indeicate we should loop
-// back and recode a frame.
+/* Function to test for conditions that indeicate we should loop
+ * back and recode a frame.
+ */
 static int recode_loop_test( VP8_COMP *cpi,
                               int high_limit, int low_limit,
                               int q, int maxq, int minq )
@@ -2984,32 +2974,33 @@ static int recode_loop_test( VP8_COMP *cpi,
     int force_recode = 0;
     VP8_COMMON *cm = &cpi->common;
 
-    // Is frame recode allowed at all
-    // Yes if either recode mode 1 is selected or mode two is selcted
-    // and the frame is a key frame. golden frame or alt_ref_frame
+    /* Is frame recode allowed at all
+     * Yes if either recode mode 1 is selected or mode two is selcted
+     * and the frame is a key frame. golden frame or alt_ref_frame
+     */
     if ( (cpi->sf.recode_loop == 1) ||
          ( (cpi->sf.recode_loop == 2) &&
            ( (cm->frame_type == KEY_FRAME) ||
              cm->refresh_golden_frame ||
              cm->refresh_alt_ref_frame ) ) )
     {
-        // General over and under shoot tests
+        /* General over and under shoot tests */
         if ( ((cpi->projected_frame_size > high_limit) && (q < maxq)) ||
              ((cpi->projected_frame_size < low_limit) && (q > minq)) )
         {
             force_recode = 1;
         }
-        // Special Constrained quality tests
+        /* Special Constrained quality tests */
         else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
         {
-            // Undershoot and below auto cq level
+            /* Undershoot and below auto cq level */
             if ( (q > cpi->cq_target_quality) &&
                  (cpi->projected_frame_size <
                      ((cpi->this_frame_target * 7) >> 3)))
             {
                 force_recode = 1;
             }
-            // Severe undershoot and between auto and user cq level
+            /* Severe undershoot and between auto and user cq level */
             else if ( (q > cpi->oxcf.cq_level) &&
                       (cpi->projected_frame_size < cpi->min_frame_bandwidth) &&
                       (cpi->active_best_quality > cpi->oxcf.cq_level))
@@ -3027,8 +3018,9 @@ static void update_reference_frames(VP8_COMMON *cm)
 {
     YV12_BUFFER_CONFIG *yv12_fb = cm->yv12_fb;
 
-    // At this point the new frame has been encoded.
-    // If any buffer copy / swapping is signaled it should be done here.
+    /* At this point the new frame has been encoded.
+     * If any buffer copy / swapping is signaled it should be done here.
+     */
 
     if (cm->frame_type == KEY_FRAME)
     {
@@ -3239,7 +3231,7 @@ static void encode_frame_to_data_rate
     int drop_mark25 = drop_mark / 8;
 
 
-    // Clear down mmx registers to allow floating point in what follows
+    /* Clear down mmx registers to allow floating point in what follows */
     vp8_clear_system_state();
 
 #if CONFIG_MULTITHREAD
@@ -3251,41 +3243,43 @@ static void encode_frame_to_data_rate
     }
 #endif
 
-    // Test code for segmentation of gf/arf (0,0)
-    //segmentation_test_function( cpi);
-
     if(cpi->force_next_frame_intra)
     {
         cm->frame_type = KEY_FRAME;  /* delayed intra frame */
         cpi->force_next_frame_intra = 0;
     }
 
-    // For an alt ref frame in 2 pass we skip the call to the second pass function that sets the target bandwidth
+    /* For an alt ref frame in 2 pass we skip the call to the second pass
+     * function that sets the target bandwidth
+     */
 #if !(CONFIG_REALTIME_ONLY)
 
     if (cpi->pass == 2)
     {
         if (cpi->common.refresh_alt_ref_frame)
         {
-            cpi->per_frame_bandwidth = cpi->twopass.gf_bits;                           // Per frame bit target for the alt ref frame
-            cpi->target_bandwidth = cpi->twopass.gf_bits * cpi->output_frame_rate;      // per second target bitrate
+            /* Per frame bit target for the alt ref frame */
+            cpi->per_frame_bandwidth = cpi->twopass.gf_bits;
+            /* per second target bitrate */
+            cpi->target_bandwidth = cpi->twopass.gf_bits * cpi->output_frame_rate;
         }
     }
     else
 #endif
         cpi->per_frame_bandwidth  = (int)(cpi->target_bandwidth / cpi->output_frame_rate);
 
-    // Default turn off buffer to buffer copying
+    /* Default turn off buffer to buffer copying */
     cm->copy_buffer_to_gf = 0;
     cm->copy_buffer_to_arf = 0;
 
-    // Clear zbin over-quant value and mode boost values.
+    /* Clear zbin over-quant value and mode boost values. */
     cpi->zbin_over_quant = 0;
     cpi->zbin_mode_boost = 0;
 
-    // Enable or disable mode based tweaking of the zbin
-    // For 2 Pass Only used where GF/ARF prediction quality
-    // is above a threshold
+    /* Enable or disable mode based tweaking of the zbin
+     * For 2 Pass Only used where GF/ARF prediction quality
+     * is above a threshold
+     */
     cpi->zbin_mode_boost_enabled = 1;
     if (cpi->pass == 2)
     {
@@ -3295,19 +3289,21 @@ static void encode_frame_to_data_rate
         }
     }
 
-    // Current default encoder behaviour for the altref sign bias
+    /* Current default encoder behaviour for the altref sign bias */
     if (cpi->source_alt_ref_active)
         cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
     else
         cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 0;
 
-    // Check to see if a key frame is signalled
-    // For two pass with auto key frame enabled cm->frame_type may already be set, but not for one pass.
+    /* Check to see if a key frame is signalled
+     * For two pass with auto key frame enabled cm->frame_type may already
+     * be set, but not for one pass.
+     */
     if ((cm->current_video_frame == 0) ||
         (cm->frame_flags & FRAMEFLAGS_KEY) ||
         (cpi->oxcf.auto_key && (cpi->frames_since_key % cpi->key_frame_frequency == 0)))
     {
-        // Key frame from VFW/auto-keyframe/first frame
+        /* Key frame from VFW/auto-keyframe/first frame */
         cm->frame_type = KEY_FRAME;
     }
 
@@ -3322,48 +3318,29 @@ static void encode_frame_to_data_rate
     }
 #endif
 
-    // Set default state for segment and mode based loop filter update flags
-    cpi->mb.e_mbd.update_mb_segmentation_map = 0;
-    cpi->mb.e_mbd.update_mb_segmentation_data = 0;
-    cpi->mb.e_mbd.mode_ref_lf_delta_update = 0;
-
-    // Set various flags etc to special state if it is a key frame
+    /* Set various flags etc to special state if it is a key frame */
     if (cm->frame_type == KEY_FRAME)
     {
         int i;
 
-        // Reset the loop filter deltas and segmentation map
+        // Set the loop filter deltas and segmentation map update
         setup_features(cpi);
 
-        // If segmentation is enabled force a map update for key frames
-        if (cpi->mb.e_mbd.segmentation_enabled)
-        {
-            cpi->mb.e_mbd.update_mb_segmentation_map = 1;
-            cpi->mb.e_mbd.update_mb_segmentation_data = 1;
-        }
-
-        // The alternate reference frame cannot be active for a key frame
+        /* The alternate reference frame cannot be active for a key frame */
         cpi->source_alt_ref_active = 0;
 
-        // Reset the RD threshold multipliers to default of * 1 (128)
+        /* Reset the RD threshold multipliers to default of * 1 (128) */
         for (i = 0; i < MAX_MODES; i++)
         {
             cpi->rd_thresh_mult[i] = 128;
         }
     }
 
-    // Test code for segmentation
-    //if ( (cm->frame_type == KEY_FRAME) || ((cm->current_video_frame % 2) == 0))
-    //if ( (cm->current_video_frame % 2) == 0 )
-    //  enable_segmentation(cpi);
-    //else
-    //  disable_segmentation(cpi);
-
 #if 0
-    // Experimental code for lagged compress and one pass
-    // Initialise one_pass GF frames stats
-    // Update stats used for GF selection
-    //if ( cpi->pass == 0 )
+    /* Experimental code for lagged compress and one pass
+     * Initialise one_pass GF frames stats
+     * Update stats used for GF selection
+     */
     {
         cpi->one_pass_frame_index = cm->current_video_frame % MAX_LAG_BUFFERS;
 
@@ -3383,8 +3360,9 @@ static void encode_frame_to_data_rate
 
     if (cpi->drop_frames_allowed)
     {
-        // The reset to decimation 0 is only done here for one pass.
-        // Once it is set two pass leaves decimation on till the next kf.
+        /* The reset to decimation 0 is only done here for one pass.
+         * Once it is set two pass leaves decimation on till the next kf.
+         */
         if ((cpi->buffer_level > drop_mark) && (cpi->decimation_factor > 0))
             cpi->decimation_factor --;
 
@@ -3403,14 +3381,17 @@ static void encode_frame_to_data_rate
         {
             cpi->decimation_factor = 1;
         }
-        //vpx_log("Encoder: Decimation Factor: %d \n",cpi->decimation_factor);
     }
 
-    // The following decimates the frame rate according to a regular pattern (i.e. to 1/2 or 2/3 frame rate)
-    // This can be used to help prevent buffer under-run in CBR mode. Alternatively it might be desirable in
-    // some situations to drop frame rate but throw more bits at each frame.
-    //
-    // Note that dropping a key frame can be problematic if spatial resampling is also active
+    /* The following decimates the frame rate according to a regular
+     * pattern (i.e. to 1/2 or 2/3 frame rate) This can be used to help
+     * prevent buffer under-run in CBR mode. Alternatively it might be
+     * desirable in some situations to drop frame rate but throw more bits
+     * at each frame.
+     *
+     * Note that dropping a key frame can be problematic if spatial
+     * resampling is also active
+     */
     if (cpi->decimation_factor > 0)
     {
         switch (cpi->decimation_factor)
@@ -3426,8 +3407,10 @@ static void encode_frame_to_data_rate
             break;
         }
 
-        // Note that we should not throw out a key frame (especially when spatial resampling is enabled).
-        if ((cm->frame_type == KEY_FRAME)) // && cpi->oxcf.allow_spatial_resampling )
+        /* Note that we should not throw out a key frame (especially when
+         * spatial resampling is enabled).
+         */
+        if ((cm->frame_type == KEY_FRAME))
         {
             cpi->decimation_count = cpi->decimation_factor;
         }
@@ -3452,7 +3435,9 @@ static void encode_frame_to_data_rate
             {
                 unsigned int i;
 
-                // Propagate bits saved by dropping the frame to higher layers
+                /* Propagate bits saved by dropping the frame to higher
+                 * layers
+                 */
                 for (i=cpi->current_layer+1; i<cpi->oxcf.number_of_layers; i++)
                 {
                     LAYER_CONTEXT *lc = &cpi->layer_context[i];
@@ -3468,8 +3453,10 @@ static void encode_frame_to_data_rate
         else
             cpi->decimation_count = cpi->decimation_factor;
     }
+    else
+        cpi->decimation_count = 0;
 
-    // Decide how big to make the frame
+    /* Decide how big to make the frame */
     if (!vp8_pick_frame_size(cpi))
     {
         cm->current_video_frame++;
@@ -3477,15 +3464,17 @@ static void encode_frame_to_data_rate
         return;
     }
 
-    // Reduce active_worst_allowed_q for CBR if our buffer is getting too full.
-    // This has a knock on effect on active best quality as well.
-    // For CBR if the buffer reaches its maximum level then we can no longer
-    // save up bits for later frames so we might as well use them up
-    // on the current frame.
+    /* Reduce active_worst_allowed_q for CBR if our buffer is getting too full.
+     * This has a knock on effect on active best quality as well.
+     * For CBR if the buffer reaches its maximum level then we can no longer
+     * save up bits for later frames so we might as well use them up
+     * on the current frame.
+     */
     if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
         (cpi->buffer_level >= cpi->oxcf.optimal_buffer_level) && cpi->buffered_mode)
     {
-        int Adjustment = cpi->active_worst_quality / 4;       // Max adjustment is 1/4
+        /* Max adjustment is 1/4 */
+        int Adjustment = cpi->active_worst_quality / 4;
 
         if (Adjustment)
         {
@@ -3508,8 +3497,9 @@ static void encode_frame_to_data_rate
         }
     }
 
-    // Set an active best quality and if necessary active worst quality
-    // There is some odd behavior for one pass here that needs attention.
+    /* Set an active best quality and if necessary active worst quality
+     * There is some odd behavior for one pass here that needs attention.
+     */
     if ( (cpi->pass == 2) || (cpi->ni_frames > 150))
     {
         vp8_clear_system_state();
@@ -3525,9 +3515,10 @@ static void encode_frame_to_data_rate
                 else
                    cpi->active_best_quality = kf_high_motion_minq[Q];
 
-                // Special case for key frames forced because we have reached
-                // the maximum key frame interval. Here force the Q to a range
-                // based on the ambient Q to reduce the risk of popping
+                /* Special case for key frames forced because we have reached
+                 * the maximum key frame interval. Here force the Q to a range
+                 * based on the ambient Q to reduce the risk of popping
+                 */
                 if ( cpi->this_key_frame_forced )
                 {
                     if ( cpi->active_best_quality > cpi->avg_frame_qindex * 7/8)
@@ -3536,7 +3527,7 @@ static void encode_frame_to_data_rate
                         cpi->active_best_quality = cpi->avg_frame_qindex >> 2;
                 }
             }
-            // One pass more conservative
+            /* One pass more conservative */
             else
                cpi->active_best_quality = kf_high_motion_minq[Q];
         }
@@ -3544,16 +3535,17 @@ static void encode_frame_to_data_rate
         else if (cpi->oxcf.number_of_layers==1 &&
                 (cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame))
         {
-            // Use the lower of cpi->active_worst_quality and recent
-            // average Q as basis for GF/ARF Q limit unless last frame was
-            // a key frame.
+            /* Use the lower of cpi->active_worst_quality and recent
+             * average Q as basis for GF/ARF Q limit unless last frame was
+             * a key frame.
+             */
             if ( (cpi->frames_since_key > 1) &&
                (cpi->avg_frame_qindex < cpi->active_worst_quality) )
             {
                 Q = cpi->avg_frame_qindex;
             }
 
-            // For constrained quality dont allow Q less than the cq level
+            /* For constrained quality dont allow Q less than the cq level */
             if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
                  (Q < cpi->cq_target_quality) )
             {
@@ -3569,14 +3561,14 @@ static void encode_frame_to_data_rate
                 else
                     cpi->active_best_quality = gf_mid_motion_minq[Q];
 
-                // Constrained quality use slightly lower active best.
+                /* Constrained quality use slightly lower active best. */
                 if ( cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY )
                 {
                     cpi->active_best_quality =
                         cpi->active_best_quality * 15/16;
                 }
             }
-            // One pass more conservative
+            /* One pass more conservative */
             else
                 cpi->active_best_quality = gf_high_motion_minq[Q];
         }
@@ -3584,14 +3576,16 @@ static void encode_frame_to_data_rate
         {
             cpi->active_best_quality = inter_minq[Q];
 
-            // For the constant/constrained quality mode we dont want
-            // q to fall below the cq level.
+            /* For the constant/constrained quality mode we dont want
+             * q to fall below the cq level.
+             */
             if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
                 (cpi->active_best_quality < cpi->cq_target_quality) )
             {
-                // If we are strongly undershooting the target rate in the last
-                // frames then use the user passed in cq value not the auto
-                // cq value.
+                /* If we are strongly undershooting the target rate in the last
+                 * frames then use the user passed in cq value not the auto
+                 * cq value.
+                 */
                 if ( cpi->rolling_actual_bits < cpi->min_frame_bandwidth )
                     cpi->active_best_quality = cpi->oxcf.cq_level;
                 else
@@ -3599,12 +3593,14 @@ static void encode_frame_to_data_rate
             }
         }
 
-        // If CBR and the buffer is as full then it is reasonable to allow
-        // higher quality on the frames to prevent bits just going to waste.
+        /* If CBR and the buffer is as full then it is reasonable to allow
+         * higher quality on the frames to prevent bits just going to waste.
+         */
         if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
         {
-            // Note that the use of >= here elliminates the risk of a devide
-            // by 0 error in the else if clause
+            /* Note that the use of >= here elliminates the risk of a devide
+             * by 0 error in the else if clause
+             */
             if (cpi->buffer_level >= cpi->oxcf.maximum_buffer_size)
                 cpi->active_best_quality = cpi->best_quality;
 
@@ -3617,8 +3613,9 @@ static void encode_frame_to_data_rate
             }
         }
     }
-    // Make sure constrained quality mode limits are adhered to for the first
-    // few frames of one pass encodes
+    /* Make sure constrained quality mode limits are adhered to for the first
+     * few frames of one pass encodes
+     */
     else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
     {
         if ( (cm->frame_type == KEY_FRAME) ||
@@ -3632,7 +3629,7 @@ static void encode_frame_to_data_rate
         }
     }
 
-    // Clip the active best and worst quality values to limits
+    /* Clip the active best and worst quality values to limits */
     if (cpi->active_worst_quality > cpi->worst_quality)
         cpi->active_worst_quality = cpi->worst_quality;
 
@@ -3642,14 +3639,14 @@ static void encode_frame_to_data_rate
     if ( cpi->active_worst_quality < cpi->active_best_quality )
         cpi->active_worst_quality = cpi->active_best_quality;
 
-    // Determine initial Q to try
+    /* Determine initial Q to try */
     Q = vp8_regulate_q(cpi, cpi->this_frame_target);
 
 #if !(CONFIG_REALTIME_ONLY)
 
-    // Set highest allowed value for Zbin over quant
+    /* Set highest allowed value for Zbin over quant */
     if (cm->frame_type == KEY_FRAME)
-        zbin_oq_high = 0; //ZBIN_OQ_MAX/16
+        zbin_oq_high = 0;
     else if ((cpi->oxcf.number_of_layers == 1) && ((cm->refresh_alt_ref_frame ||
               (cm->refresh_golden_frame && !cpi->source_alt_ref_active))))
     {
@@ -3659,15 +3656,16 @@ static void encode_frame_to_data_rate
         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.
+    /* Setup background Q adjustment for error resilient mode.
+     * For multi-layer encodes only enable this for the base layer.
+     */
     if (cpi->cyclic_refresh_mode_enabled && (cpi->current_layer==0))
         cyclic_background_refresh(cpi, Q, 0);
 
     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.
+    /* 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;
@@ -3735,16 +3733,11 @@ static void encode_frame_to_data_rate
 
     do
     {
-        vp8_clear_system_state();  //__asm emms;
-
-        /*
-        if(cpi->is_src_frame_alt_ref)
-            Q = 127;
-            */
+        vp8_clear_system_state();
 
         vp8_set_quantizer(cpi, Q);
 
-        // setup skip prob for costing in mode/mv decision
+        /* setup skip prob for costing in mode/mv decision */
         if (cpi->common.mb_no_coeff_skip)
         {
             cpi->prob_skip_false = cpi->base_skip_false_prob[Q];
@@ -3788,7 +3781,9 @@ static void encode_frame_to_data_rate
                         */
                 }
 
-                //as this is for cost estimate, let's make sure it does not go extreme eitehr way
+                /* as this is for cost estimate, let's make sure it does not
+                 * go extreme eitehr way
+                 */
                 if (cpi->prob_skip_false < 5)
                     cpi->prob_skip_false = 5;
 
@@ -3843,7 +3838,7 @@ static void encode_frame_to_data_rate
 
             if (cm->refresh_entropy_probs == 0)
             {
-                // save a copy for later refresh
+                /* save a copy for later refresh */
                 vpx_memcpy(&cm->lfc, &cm->fc, sizeof(cm->fc));
             }
 
@@ -3851,23 +3846,25 @@ static void encode_frame_to_data_rate
 
             vp8_update_coef_probs(cpi);
 
-            // transform / motion compensation build reconstruction frame
-            // +pack coef partitions
+            /* transform / motion compensation build reconstruction frame
+             * +pack coef partitions
+             */
             vp8_encode_frame(cpi);
 
             /* cpi->projected_frame_size is not needed for RT mode */
         }
 #else
-        // transform / motion compensation build reconstruction frame
+        /* transform / motion compensation build reconstruction frame */
         vp8_encode_frame(cpi);
 
         cpi->projected_frame_size -= vp8_estimate_entropy_savings(cpi);
         cpi->projected_frame_size = (cpi->projected_frame_size > 0) ? cpi->projected_frame_size : 0;
 #endif
-        vp8_clear_system_state();  //__asm emms;
+        vp8_clear_system_state();
 
-        // Test to see if the stats generated for this frame indicate that we should have coded a key frame
-        // (assuming that we didn't)!
+        /* Test to see if the stats generated for this frame indicate that
+         * we should have coded a key frame (assuming that we didn't)!
+         */
         if (cpi->pass != 2 && cpi->oxcf.auto_key && cm->frame_type != KEY_FRAME)
         {
             int key_frame_decision = decide_key_frame(cpi);
@@ -3881,31 +3878,26 @@ static void encode_frame_to_data_rate
 #if !(CONFIG_REALTIME_ONLY)
             else if (key_frame_decision)
             {
-                // Reset all our sizing numbers and recode
+                /* Reset all our sizing numbers and recode */
                 cm->frame_type = KEY_FRAME;
 
                 vp8_pick_frame_size(cpi);
 
-                // Clear the Alt reference frame active flag when we have a key frame
+                /* Clear the Alt reference frame active flag when we have
+                 * a key frame
+                 */
                 cpi->source_alt_ref_active = 0;
 
-                // Reset the loop filter deltas and segmentation map
+                // Set the loop filter deltas and segmentation map update
                 setup_features(cpi);
 
-                // If segmentation is enabled force a map update for key frames
-                if (cpi->mb.e_mbd.segmentation_enabled)
-                {
-                    cpi->mb.e_mbd.update_mb_segmentation_map = 1;
-                    cpi->mb.e_mbd.update_mb_segmentation_data = 1;
-                }
-
                 vp8_restore_coding_context(cpi);
 
                 Q = vp8_regulate_q(cpi, cpi->this_frame_target);
 
                 vp8_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, &frame_over_shoot_limit);
 
-                // Limit Q range for the adaptive loop.
+                /* 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;
@@ -3924,7 +3916,7 @@ static void encode_frame_to_data_rate
         if (frame_over_shoot_limit == 0)
             frame_over_shoot_limit = 1;
 
-        // Are we are overshooting and up against the limit of active max Q.
+        /* Are we are overshooting and up against the limit of active max Q. */
         if (((cpi->pass != 2) || (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)) &&
             (Q == cpi->active_worst_quality)                     &&
             (cpi->active_worst_quality < cpi->worst_quality)      &&
@@ -3932,50 +3924,52 @@ static void encode_frame_to_data_rate
         {
             int over_size_percent = ((cpi->projected_frame_size - frame_over_shoot_limit) * 100) / frame_over_shoot_limit;
 
-            // If so is there any scope for relaxing it
+            /* If so is there any scope for relaxing it */
             while ((cpi->active_worst_quality < cpi->worst_quality) && (over_size_percent > 0))
             {
                 cpi->active_worst_quality++;
-
-                over_size_percent = (int)(over_size_percent * 0.96);        // Assume 1 qstep = about 4% on frame size.
+                /* Assume 1 qstep = about 4% on frame size. */
+                over_size_percent = (int)(over_size_percent * 0.96);
             }
 #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.
+            /* If we have updated the active max Q do not call
+             * vp8_update_rate_correction_factors() this loop.
+             */
             active_worst_qchanged = 1;
         }
         else
             active_worst_qchanged = 0;
 
 #if !(CONFIG_REALTIME_ONLY)
-        // Special case handling for forced key frames
+        /* Special case handling for forced key frames */
         if ( (cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced )
         {
             int last_q = Q;
             int kf_err = vp8_calc_ss_err(cpi->Source,
                                          &cm->yv12_fb[cm->new_fb_idx]);
 
-            // The key frame is not good enough
+            /* The key frame is not good enough */
             if ( kf_err > ((cpi->ambient_err * 7) >> 3) )
             {
-                // Lower q_high
+                /* Lower q_high */
                 q_high = (Q > q_low) ? (Q - 1) : q_low;
 
-                // Adjust Q
+                /* Adjust Q */
                 Q = (q_high + q_low) >> 1;
             }
-            // The key frame is much better than the previous frame
+            /* The key frame is much better than the previous frame */
             else if ( kf_err < (cpi->ambient_err >> 1) )
             {
-                // Raise q_low
+                /* Raise q_low */
                 q_low = (Q < q_high) ? (Q + 1) : q_high;
 
-                // Adjust Q
+                /* Adjust Q */
                 Q = (q_high + q_low + 1) >> 1;
             }
 
-            // Clamp Q to upper and lower limits:
+            /* Clamp Q to upper and lower limits: */
             if (Q > q_high)
                 Q = q_high;
             else if (Q < q_low)
@@ -3984,7 +3978,9 @@ static void encode_frame_to_data_rate
             Loop = Q != last_q;
         }
 
-        // Is the projected frame size out of range and are we allowed to attempt to recode.
+        /* Is the projected frame size out of range and are we allowed
+         * to attempt to recode.
+         */
         else if ( recode_loop_test( cpi,
                                frame_over_shoot_limit, frame_under_shoot_limit,
                                Q, top_index, bottom_index ) )
@@ -3992,28 +3988,33 @@ static void encode_frame_to_data_rate
             int last_q = Q;
             int Retries = 0;
 
-            // Frame size out of permitted range:
-            // Update correction factor & compute new Q to try...
+            /* Frame size out of permitted range. Update correction factor
+             * & compute new Q to try...
+             */
 
-            // Frame is too large
+            /* Frame is too large */
             if (cpi->projected_frame_size > cpi->this_frame_target)
             {
-                //if ( cpi->zbin_over_quant == 0 )
-                q_low = (Q < q_high) ? (Q + 1) : q_high; // Raise Qlow as to at least the current value
+                /* Raise Qlow as to at least the current value */
+                q_low = (Q < q_high) ? (Q + 1) : q_high;
 
-                if (cpi->zbin_over_quant > 0)            // If we are using over quant do the same for zbin_oq_low
+                /* If we are using over quant do the same for zbin_oq_low */
+                if (cpi->zbin_over_quant > 0)
                     zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->zbin_over_quant + 1) : zbin_oq_high;
 
-                //if ( undershoot_seen || (Q == MAXQ) )
                 if (undershoot_seen)
                 {
-                    // Update rate_correction_factor unless cpi->active_worst_quality has changed.
+                    /* Update rate_correction_factor unless
+                     * cpi->active_worst_quality has changed.
+                     */
                     if (!active_worst_qchanged)
                         vp8_update_rate_correction_factors(cpi, 1);
 
                     Q = (q_high + q_low + 1) / 2;
 
-                    // Adjust cpi->zbin_over_quant (only allowed when Q is max)
+                    /* Adjust cpi->zbin_over_quant (only allowed when Q
+                     * is max)
+                     */
                     if (Q < MAXQ)
                         cpi->zbin_over_quant = 0;
                     else
@@ -4024,7 +4025,9 @@ static void encode_frame_to_data_rate
                 }
                 else
                 {
-                    // Update rate_correction_factor unless cpi->active_worst_quality has changed.
+                    /* Update rate_correction_factor unless
+                     * cpi->active_worst_quality has changed.
+                     */
                     if (!active_worst_qchanged)
                         vp8_update_rate_correction_factors(cpi, 0);
 
@@ -4040,23 +4043,29 @@ static void encode_frame_to_data_rate
 
                 overshoot_seen = 1;
             }
-            // Frame is too small
+            /* Frame is too small */
             else
             {
                 if (cpi->zbin_over_quant == 0)
-                    q_high = (Q > q_low) ? (Q - 1) : q_low; // Lower q_high if not using over quant
-                else                                    // else lower zbin_oq_high
+                    /* Lower q_high if not using over quant */
+                    q_high = (Q > q_low) ? (Q - 1) : q_low;
+                else
+                    /* else lower zbin_oq_high */
                     zbin_oq_high = (cpi->zbin_over_quant > zbin_oq_low) ? (cpi->zbin_over_quant - 1) : zbin_oq_low;
 
                 if (overshoot_seen)
                 {
-                    // Update rate_correction_factor unless cpi->active_worst_quality has changed.
+                    /* Update rate_correction_factor unless
+                     * cpi->active_worst_quality has changed.
+                     */
                     if (!active_worst_qchanged)
                         vp8_update_rate_correction_factors(cpi, 1);
 
                     Q = (q_high + q_low) / 2;
 
-                    // Adjust cpi->zbin_over_quant (only allowed when Q is max)
+                    /* Adjust cpi->zbin_over_quant (only allowed when Q
+                     * is max)
+                     */
                     if (Q < MAXQ)
                         cpi->zbin_over_quant = 0;
                     else
@@ -4064,16 +4073,19 @@ static void encode_frame_to_data_rate
                 }
                 else
                 {
-                    // Update rate_correction_factor unless cpi->active_worst_quality has changed.
+                    /* Update rate_correction_factor unless
+                     * cpi->active_worst_quality has changed.
+                     */
                     if (!active_worst_qchanged)
                         vp8_update_rate_correction_factors(cpi, 0);
 
                     Q = vp8_regulate_q(cpi, cpi->this_frame_target);
 
-                    // Special case reset for qlow for constrained quality.
-                    // This should only trigger where there is very substantial
-                    // undershoot on a frame and the auto cq level is above
-                    // the user passsed in value.
+                    /* Special case reset for qlow for constrained quality.
+                     * This should only trigger where there is very substantial
+                     * undershoot on a frame and the auto cq level is above
+                     * the user passsed in value.
+                     */
                     if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
                          (Q < q_low) )
                     {
@@ -4091,13 +4103,13 @@ static void encode_frame_to_data_rate
                 undershoot_seen = 1;
             }
 
-            // Clamp Q to upper and lower limits:
+            /* Clamp Q to upper and lower limits: */
             if (Q > q_high)
                 Q = q_high;
             else if (Q < q_low)
                 Q = q_low;
 
-            // Clamp cpi->zbin_over_quant
+            /* 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;
@@ -4121,30 +4133,20 @@ static void encode_frame_to_data_rate
     while (Loop == 1);
 
 #if 0
-    // Experimental code for lagged and one pass
-    // Update stats used for one pass GF selection
-    {
-        /*
-            int frames_so_far;
-            double frame_intra_error;
-            double frame_coded_error;
-            double frame_pcnt_inter;
-            double frame_pcnt_motion;
-            double frame_mvr;
-            double frame_mvr_abs;
-            double frame_mvc;
-            double frame_mvc_abs;
-        */
-
+    /* Experimental code for lagged and one pass
+     * Update stats used for one pass GF selection
+     */
+    {
         cpi->one_pass_frame_stats[cpi->one_pass_frame_index].frame_coded_error = (double)cpi->prediction_error;
         cpi->one_pass_frame_stats[cpi->one_pass_frame_index].frame_intra_error = (double)cpi->intra_error;
         cpi->one_pass_frame_stats[cpi->one_pass_frame_index].frame_pcnt_inter = (double)(100 - cpi->this_frame_percent_intra) / 100.0;
     }
 #endif
 
-    // Special case code to reduce pulsing when key frames are forced at a
-    // fixed interval. Note the reconstruction error if it is the frame before
-    // the force key frame
+    /* Special case code to reduce pulsing when key frames are forced at a
+     * fixed interval. Note the reconstruction error if it is the frame before
+     * the force key frame
+     */
     if ( cpi->next_key_frame_forced && (cpi->twopass.frames_to_key == 0) )
     {
         cpi->ambient_err = vp8_calc_ss_err(cpi->Source,
@@ -4187,9 +4189,10 @@ static void encode_frame_to_data_rate
     vp8_cal_dissimilarity(cpi);
 #endif
 
-    // Update the GF useage maps.
-    // This is done after completing the compression of a frame when all
-    // modes etc. are finalized but before loop filter
+    /* Update the GF useage maps.
+     * This is done after completing the compression of a frame when all
+     * modes etc. are finalized but before loop filter
+     */
     if (cpi->oxcf.number_of_layers == 1)
         vp8_update_gf_useage_maps(cpi, cm, &cpi->mb);
 
@@ -4204,9 +4207,10 @@ static void encode_frame_to_data_rate
     }
 #endif
 
-    // For inter frames the current default behavior is that when
-    // cm->refresh_golden_frame is set we copy the old GF over to the ARF buffer
-    // This is purely an encoder decision at present.
+    /* For inter frames the current default behavior is that when
+     * cm->refresh_golden_frame is set we copy the old GF over to the ARF buffer
+     * This is purely an encoder decision at present.
+     */
     if (!cpi->oxcf.error_resilient_mode && cm->refresh_golden_frame)
         cm->copy_buffer_to_arf  = 2;
     else
@@ -4217,7 +4221,8 @@ static void encode_frame_to_data_rate
 #if CONFIG_MULTITHREAD
     if (cpi->b_multi_threaded)
     {
-        sem_post(&cpi->h_event_start_lpf); /* start loopfilter in separate thread */
+        /* start loopfilter in separate thread */
+        sem_post(&cpi->h_event_start_lpf);
         cpi->b_lpf_running = 1;
     }
     else
@@ -4241,7 +4246,7 @@ static void encode_frame_to_data_rate
         sem_wait(&cpi->h_event_end_lpf);
 #endif
 
-    // build the bitstream
+    /* build the bitstream */
     vp8_pack_bitstream(cpi, dest, dest_end, size);
 
 #if CONFIG_MULTITHREAD
@@ -4257,7 +4262,7 @@ static void encode_frame_to_data_rate
      * needed in motion search besides loopfilter */
     cm->last_frame_type = cm->frame_type;
 
-    // Update rate control heuristics
+    /* Update rate control heuristics */
     cpi->total_byte_count += (*size);
     cpi->projected_frame_size = (*size) << 3;
 
@@ -4278,18 +4283,21 @@ static void encode_frame_to_data_rate
         vp8_adjust_key_frame_context(cpi);
     }
 
-    // Keep a record of ambient average Q.
+    /* Keep a record of ambient average Q. */
     if (cm->frame_type != KEY_FRAME)
         cpi->avg_frame_qindex = (2 + 3 * cpi->avg_frame_qindex + cm->base_qindex) >> 2;
 
-    // Keep a record from which we can calculate the average Q excluding GF updates and key frames
+    /* Keep a record from which we can calculate the average Q excluding
+     * GF updates and key frames
+     */
     if ((cm->frame_type != KEY_FRAME) && ((cpi->oxcf.number_of_layers > 1) ||
         (!cm->refresh_golden_frame && !cm->refresh_alt_ref_frame)))
     {
         cpi->ni_frames++;
 
-        // Calculate the average Q for normal inter frames (not key or GFU
-        // frames).
+        /* Calculate the average Q for normal inter frames (not key or GFU
+         * frames).
+         */
         if ( cpi->pass == 2 )
         {
             cpi->ni_tot_qi += Q;
@@ -4297,57 +4305,62 @@ static void encode_frame_to_data_rate
         }
         else
         {
-            // Damp value for first few frames
+            /* Damp value for first few frames */
             if (cpi->ni_frames > 150 )
             {
                 cpi->ni_tot_qi += Q;
                 cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames);
             }
-            // For one pass, early in the clip ... average the current frame Q
-            // value with the worstq entered by the user as a dampening measure
+            /* For one pass, early in the clip ... average the current frame Q
+             * value with the worstq entered by the user as a dampening measure
+             */
             else
             {
                 cpi->ni_tot_qi += Q;
                 cpi->ni_av_qi = ((cpi->ni_tot_qi / cpi->ni_frames) + cpi->worst_quality + 1) / 2;
             }
 
-            // If the average Q is higher than what was used in the last frame
-            // (after going through the recode loop to keep the frame size within range)
-            // then use the last frame value - 1.
-            // The -1 is designed to stop Q and hence the data rate, from progressively
-            // falling away during difficult sections, but at the same time reduce the number of
-            // itterations around the recode loop.
+            /* If the average Q is higher than what was used in the last
+             * frame (after going through the recode loop to keep the frame
+             * size within range) then use the last frame value - 1. The -1
+             * is designed to stop Q and hence the data rate, from
+             * progressively falling away during difficult sections, but at
+             * the same time reduce the number of itterations around the
+             * recode loop.
+             */
             if (Q > cpi->ni_av_qi)
                 cpi->ni_av_qi = Q - 1;
         }
     }
 
-    // Update the buffer level variable.
-    // Non-viewable frames are a special case and are treated as pure overhead.
+    /* Update the buffer level variable. */
+    /* Non-viewable frames are a special case and are treated as pure overhead. */
     if ( !cm->show_frame )
         cpi->bits_off_target -= cpi->projected_frame_size;
     else
         cpi->bits_off_target += cpi->av_per_frame_bandwidth - cpi->projected_frame_size;
 
-    // Clip the buffer level to the maximum specified buffer size
+    /* Clip the buffer level to the maximum specified buffer size */
     if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
         cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
 
-    // Rolling monitors of whether we are over or underspending used to help regulate min and Max Q in two pass.
+    /* Rolling monitors of whether we are over or underspending used to
+     * help regulate min and Max Q in two pass.
+     */
     cpi->rolling_target_bits = ((cpi->rolling_target_bits * 3) + cpi->this_frame_target + 2) / 4;
     cpi->rolling_actual_bits = ((cpi->rolling_actual_bits * 3) + cpi->projected_frame_size + 2) / 4;
     cpi->long_rolling_target_bits = ((cpi->long_rolling_target_bits * 31) + cpi->this_frame_target + 16) / 32;
     cpi->long_rolling_actual_bits = ((cpi->long_rolling_actual_bits * 31) + cpi->projected_frame_size + 16) / 32;
 
-    // Actual bits spent
+    /* Actual bits spent */
     cpi->total_actual_bits += cpi->projected_frame_size;
 
-    // Debug stats
+    /* Debug stats */
     cpi->total_target_vs_actual += (cpi->this_frame_target - cpi->projected_frame_size);
 
     cpi->buffer_level = cpi->bits_off_target;
 
-    // Propagate values to higher temporal layers
+    /* Propagate values to higher temporal layers */
     if (cpi->oxcf.number_of_layers > 1)
     {
         unsigned int i;
@@ -4360,7 +4373,7 @@ static void encode_frame_to_data_rate
 
             lc->bits_off_target += bits_off_for_this_layer;
 
-            // Clip buffer level to maximum buffer size for the layer
+            /* Clip buffer level to maximum buffer size for the layer */
             if (lc->bits_off_target > lc->maximum_buffer_size)
                 lc->bits_off_target = lc->maximum_buffer_size;
 
@@ -4370,7 +4383,9 @@ static void encode_frame_to_data_rate
         }
     }
 
-    // Update bits left to the kf and gf groups to account for overshoot or undershoot on these frames
+    /* Update bits left to the kf and gf groups to account for overshoot
+     * or undershoot on these frames
+     */
     if (cm->frame_type == KEY_FRAME)
     {
         cpi->twopass.kf_group_bits += cpi->this_frame_target - cpi->projected_frame_size;
@@ -4403,7 +4418,7 @@ static void encode_frame_to_data_rate
             cpi->last_skip_false_probs[0] = cpi->prob_skip_false;
             cpi->last_skip_probs_q[0] = cm->base_qindex;
 
-            //update the baseline
+            /* update the baseline */
             cpi->base_skip_false_prob[cm->base_qindex] = cpi->prob_skip_false;
 
         }
@@ -4413,7 +4428,7 @@ static void encode_frame_to_data_rate
     {
         FILE *f = fopen("tmp.stt", "a");
 
-        vp8_clear_system_state();  //__asm emms;
+        vp8_clear_system_state();
 
         if (cpi->twopass.total_left_stats.coded_error != 0.0)
             fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %10d %6d %6d"
@@ -4429,7 +4444,6 @@ static void encode_frame_to_data_rate
                        cpi->active_best_quality, cpi->active_worst_quality,
                        cpi->ni_av_qi, cpi->cq_target_quality,
                        cpi->zbin_over_quant,
-                       //cpi->avg_frame_qindex, cpi->zbin_over_quant,
                        cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
                        cm->frame_type, cpi->gfu_boost,
                        cpi->twopass.est_max_qcorrection_factor,
@@ -4452,7 +4466,6 @@ static void encode_frame_to_data_rate
                        cpi->active_best_quality, cpi->active_worst_quality,
                        cpi->ni_av_qi, cpi->cq_target_quality,
                        cpi->zbin_over_quant,
-                       //cpi->avg_frame_qindex, cpi->zbin_over_quant,
                        cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
                        cm->frame_type, cpi->gfu_boost,
                        cpi->twopass.est_max_qcorrection_factor,
@@ -4482,7 +4495,7 @@ static void encode_frame_to_data_rate
 
 #endif
 
-    // If this was a kf or Gf note the Q
+    /* If this was a kf or Gf note the Q */
     if ((cm->frame_type == KEY_FRAME) || cm->refresh_golden_frame || cm->refresh_alt_ref_frame)
         cm->last_kf_gf_q = cm->base_qindex;
 
@@ -4497,19 +4510,25 @@ static void encode_frame_to_data_rate
         cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_ALTREF;
 
 
-    if (cm->refresh_last_frame & cm->refresh_golden_frame) // both refreshed
+    if (cm->refresh_last_frame & cm->refresh_golden_frame)
+        /* both refreshed */
         cpi->gold_is_last = 1;
-    else if (cm->refresh_last_frame ^ cm->refresh_golden_frame) // 1 refreshed but not the other
+    else if (cm->refresh_last_frame ^ cm->refresh_golden_frame)
+        /* 1 refreshed but not the other */
         cpi->gold_is_last = 0;
 
-    if (cm->refresh_last_frame & cm->refresh_alt_ref_frame) // both refreshed
+    if (cm->refresh_last_frame & cm->refresh_alt_ref_frame)
+        /* both refreshed */
         cpi->alt_is_last = 1;
-    else if (cm->refresh_last_frame ^ cm->refresh_alt_ref_frame) // 1 refreshed but not the other
+    else if (cm->refresh_last_frame ^ cm->refresh_alt_ref_frame)
+        /* 1 refreshed but not the other */
         cpi->alt_is_last = 0;
 
-    if (cm->refresh_alt_ref_frame & cm->refresh_golden_frame) // both refreshed
+    if (cm->refresh_alt_ref_frame & cm->refresh_golden_frame)
+        /* both refreshed */
         cpi->gold_is_alt = 1;
-    else if (cm->refresh_alt_ref_frame ^ cm->refresh_golden_frame) // 1 refreshed but not the other
+    else if (cm->refresh_alt_ref_frame ^ cm->refresh_golden_frame)
+        /* 1 refreshed but not the other */
         cpi->gold_is_alt = 0;
 
     cpi->ref_frame_flags = VP8_ALTR_FRAME | VP8_GOLD_FRAME | VP8_LAST_FRAME;
@@ -4527,19 +4546,19 @@ static void encode_frame_to_data_rate
     if (!cpi->oxcf.error_resilient_mode)
     {
         if (cpi->oxcf.play_alternate && cm->refresh_alt_ref_frame && (cm->frame_type != KEY_FRAME))
-            // Update the alternate reference frame stats as appropriate.
+            /* Update the alternate reference frame stats as appropriate. */
             update_alt_ref_frame_stats(cpi);
         else
-            // Update the Golden frame stats as appropriate.
+            /* Update the Golden frame stats as appropriate. */
             update_golden_frame_stats(cpi);
     }
 
     if (cm->frame_type == KEY_FRAME)
     {
-        // Tell the caller that the frame was coded as a key frame
+        /* Tell the caller that the frame was coded as a key frame */
         *frame_flags = cm->frame_flags | FRAMEFLAGS_KEY;
 
-        // As this frame is a key frame  the next defaults to an inter frame.
+        /* As this frame is a key frame  the next defaults to an inter frame. */
         cm->frame_type = INTER_FRAME;
 
         cpi->last_frame_percent_intra = 100;
@@ -4551,20 +4570,24 @@ static void encode_frame_to_data_rate
         cpi->last_frame_percent_intra = cpi->this_frame_percent_intra;
     }
 
-    // Clear the one shot update flags for segmentation map and mode/ref loop filter deltas.
+    /* Clear the one shot update flags for segmentation map and mode/ref
+     * loop filter deltas.
+     */
     cpi->mb.e_mbd.update_mb_segmentation_map = 0;
     cpi->mb.e_mbd.update_mb_segmentation_data = 0;
     cpi->mb.e_mbd.mode_ref_lf_delta_update = 0;
 
 
-    // Dont increment frame counters if this was an altref buffer update not a real frame
+    /* Dont increment frame counters if this was an altref buffer update
+     * not a real frame
+     */
     if (cm->show_frame)
     {
         cm->current_video_frame++;
         cpi->frames_since_key++;
     }
 
-    // reset to normal state now that we are done.
+    /* reset to normal state now that we are done. */
 
 
 
@@ -4580,8 +4603,8 @@ static void encode_frame_to_data_rate
     }
 #endif
 
-    // DEBUG
-    //vp8_write_yuv_frame("encoder_recon.yuv", cm->frame_to_show);
+    /* DEBUG */
+    /* vp8_write_yuv_frame("encoder_recon.yuv", cm->frame_to_show); */
 
 
 }
@@ -4594,33 +4617,38 @@ static void check_gf_quality(VP8_COMP *cpi)
     int gf_ref_usage_pct = (cpi->count_mb_ref_frame_usage[GOLDEN_FRAME] * 100) / (cm->mb_rows * cm->mb_cols);
     int last_ref_zz_useage = (cpi->inter_zz_count * 100) / (cm->mb_rows * cm->mb_cols);
 
-    // Gf refresh is not currently being signalled
+    /* Gf refresh is not currently being signalled */
     if (cpi->gf_update_recommended == 0)
     {
         if (cpi->common.frames_since_golden > 7)
         {
-            // Low use of gf
+            /* Low use of gf */
             if ((gf_active_pct < 10) || ((gf_active_pct + gf_ref_usage_pct) < 15))
             {
-                // ...but last frame zero zero usage is reasonbable so a new gf might be appropriate
+                /* ...but last frame zero zero usage is reasonbable so a
+                 * new gf might be appropriate
+                 */
                 if (last_ref_zz_useage >= 25)
                 {
                     cpi->gf_bad_count ++;
 
-                    if (cpi->gf_bad_count >= 8)   // Check that the condition is stable
+                    /* Check that the condition is stable */
+                    if (cpi->gf_bad_count >= 8)
                     {
                         cpi->gf_update_recommended = 1;
                         cpi->gf_bad_count = 0;
                     }
                 }
                 else
-                    cpi->gf_bad_count = 0;        // Restart count as the background is not stable enough
+                    /* Restart count as the background is not stable enough */
+                    cpi->gf_bad_count = 0;
             }
             else
-                cpi->gf_bad_count = 0;            // Gf useage has picked up so reset count
+                /* Gf useage has picked up so reset count */
+                cpi->gf_bad_count = 0;
         }
     }
-    // If the signal is set but has not been read should we cancel it.
+    /* If the signal is set but has not been read should we cancel it. */
     else if (last_ref_zz_useage < 15)
     {
         cpi->gf_update_recommended = 0;
@@ -4660,7 +4688,7 @@ static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest,
 }
 #endif
 
-//For ARM NEON, d8-d15 are callee-saved registers, and need to be saved by us.
+/* For ARM NEON, d8-d15 are callee-saved registers, and need to be saved. */
 #if HAVE_NEON
 extern void vp8_push_neon(int64_t *store);
 extern void vp8_pop_neon(int64_t *store);
@@ -4767,7 +4795,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
     cpi->source = NULL;
 
 #if !(CONFIG_REALTIME_ONLY)
-    // Should we code an alternate reference frame
+    /* Should we code an alternate reference frame */
     if (cpi->oxcf.error_resilient_mode == 0 &&
         cpi->oxcf.play_alternate &&
         cpi->source_alt_ref_pending)
@@ -4788,7 +4816,8 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
             cm->refresh_golden_frame = 0;
             cm->refresh_last_frame = 0;
             cm->show_frame = 0;
-            cpi->source_alt_ref_pending = 0;  // Clear Pending alt Ref flag.
+            /* Clear Pending alt Ref flag. */
+            cpi->source_alt_ref_pending = 0;
             cpi->is_src_frame_alt_ref = 0;
         }
     }
@@ -4860,7 +4889,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
         cpi->last_end_time_stamp_seen = cpi->source->ts_start;
     }
 
-    // adjust frame rates based on timestamps given
+    /* adjust frame rates based on timestamps given */
     if (cm->show_frame)
     {
         int64_t this_duration;
@@ -4878,7 +4907,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
             this_duration = cpi->source->ts_end - cpi->last_end_time_stamp_seen;
             last_duration = cpi->last_end_time_stamp_seen
                             - cpi->last_time_stamp_seen;
-            // do a step update if the duration changes by 10%
+            /* do a step update if the duration changes by 10% */
             if (last_duration)
                 step = ((this_duration - last_duration) * 10 / last_duration);
         }
@@ -4910,7 +4939,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
             {
                 unsigned int i;
 
-                // Update frame rates for each layer
+                /* Update frame rates for each layer */
                 for (i=0; i<cpi->oxcf.number_of_layers; i++)
                 {
                     LAYER_CONTEXT *lc = &cpi->layer_context[i];
@@ -4932,7 +4961,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
 
         update_layer_contexts (cpi);
 
-        // Restore layer specific context & set frame rate
+        /* Restore layer specific context & set frame rate */
         layer = cpi->oxcf.layer_id[
                             cm->current_video_frame % cpi->oxcf.periodicity];
         restore_layer_context (cpi, layer);
@@ -4970,11 +4999,11 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
     }
 #endif
 
-    // start with a 0 size frame
+    /* start with a 0 size frame */
     *size = 0;
 
-    // Clear down mmx registers
-    vp8_clear_system_state();  //__asm emms;
+    /* Clear down mmx registers */
+    vp8_clear_system_state();
 
     cm->frame_type = INTER_FRAME;
     cm->frame_flags = *frame_flags;
@@ -4983,7 +5012,6 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
 
     if (cm->refresh_alt_ref_frame)
     {
-        //cm->refresh_golden_frame = 1;
         cm->refresh_golden_frame = 0;
         cm->refresh_last_frame = 0;
     }
@@ -5041,7 +5069,6 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
 
         if (duration2)
         {
-            //if(*frame_flags!=1)
             {
 
                 if (cpi->avg_pick_mode_time == 0)
@@ -5058,8 +5085,8 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
         vpx_memcpy(&cm->fc, &cm->lfc, sizeof(cm->fc));
     }
 
-    // Save the contexts separately for alt ref, gold and last.
-    // (TODO jbb -> Optimize this with pointers to avoid extra copies. )
+    /* Save the contexts separately for alt ref, gold and last. */
+    /* (TODO jbb -> Optimize this with pointers to avoid extra copies. ) */
     if(cm->refresh_alt_ref_frame)
         vpx_memcpy(&cpi->lfc_a, &cm->fc, sizeof(cm->fc));
 
@@ -5069,12 +5096,12 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
     if(cm->refresh_last_frame)
         vpx_memcpy(&cpi->lfc_n, &cm->fc, sizeof(cm->fc));
 
-    // if its a dropped frame honor the requests on subsequent frames
+    /* if its a dropped frame honor the requests on subsequent frames */
     if (*size > 0)
     {
         cpi->droppable = !frame_is_reference(cpi);
 
-        // return to normal state
+        /* return to normal state */
         cm->refresh_entropy_probs = 1;
         cm->refresh_alt_ref_frame = 0;
         cm->refresh_golden_frame = 0;
@@ -5083,7 +5110,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
 
     }
 
-    // Save layer specific state
+    /* Save layer specific state */
     if (cpi->oxcf.number_of_layers > 1)
         save_layer_context (cpi);
 
@@ -5297,7 +5324,7 @@ int vp8_get_preview_raw_frame(VP8_COMP *cpi, YV12_BUFFER_CONFIG *dest, vp8_ppfla
             ret = -1;
         }
 
-#endif //!CONFIG_POSTPROC
+#endif
         vp8_clear_system_state();
         return ret;
     }
@@ -5306,29 +5333,53 @@ int vp8_get_preview_raw_frame(VP8_COMP *cpi, YV12_BUFFER_CONFIG *dest, vp8_ppfla
 int vp8_set_roimap(VP8_COMP *cpi, unsigned char *map, unsigned int rows, unsigned int cols, int delta_q[4], int delta_lf[4], unsigned int threshold[4])
 {
     signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
+    int internal_delta_q[MAX_MB_SEGMENTS];
+    const unsigned int range = 63;
+    int i;
+
+    // This method is currently incompatible with the cyclic refresh method
+    if ( cpi->cyclic_refresh_mode_enabled )
+        return -1;
 
+    // Check number of rows and columns match
     if (cpi->common.mb_rows != rows || cpi->common.mb_cols != cols)
         return -1;
 
+    // Range check the delta Q values and convert the external Q range values
+    // to internal ones.
+    if ( (abs(delta_q[0]) > range) || (abs(delta_q[1]) > range) ||
+         (abs(delta_q[2]) > range) || (abs(delta_q[3]) > range) )
+        return -1;
+
+    // Range check the delta lf values
+    if ( (abs(delta_lf[0]) > range) || (abs(delta_lf[1]) > range) ||
+         (abs(delta_lf[2]) > range) || (abs(delta_lf[3]) > range) )
+        return -1;
+
     if (!map)
     {
         disable_segmentation(cpi);
         return 0;
     }
 
-    // Set the segmentation Map
+    // Translate the external delta q values to internal values.
+    for ( i = 0; i < MAX_MB_SEGMENTS; i++ )
+        internal_delta_q[i] =
+            ( delta_q[i] >= 0 ) ? q_trans[delta_q[i]] : -q_trans[-delta_q[i]];
+
+    /* Set the segmentation Map */
     set_segmentation_map(cpi, map);
 
-    // Activate segmentation.
+    /* Activate segmentation. */
     enable_segmentation(cpi);
 
-    // Set up the quant segment data
-    feature_data[MB_LVL_ALT_Q][0] = delta_q[0];
-    feature_data[MB_LVL_ALT_Q][1] = delta_q[1];
-    feature_data[MB_LVL_ALT_Q][2] = delta_q[2];
-    feature_data[MB_LVL_ALT_Q][3] = delta_q[3];
+    /* Set up the quant segment data */
+    feature_data[MB_LVL_ALT_Q][0] = internal_delta_q[0];
+    feature_data[MB_LVL_ALT_Q][1] = internal_delta_q[1];
+    feature_data[MB_LVL_ALT_Q][2] = internal_delta_q[2];
+    feature_data[MB_LVL_ALT_Q][3] = internal_delta_q[3];
 
-    // Set up the loop segment data s
+    /* Set up the loop segment data s */
     feature_data[MB_LVL_ALT_LF][0] = delta_lf[0];
     feature_data[MB_LVL_ALT_LF][1] = delta_lf[1];
     feature_data[MB_LVL_ALT_LF][2] = delta_lf[2];
@@ -5339,8 +5390,7 @@ int vp8_set_roimap(VP8_COMP *cpi, unsigned char *map, unsigned int rows, unsigne
     cpi->segment_encode_breakout[2] = threshold[2];
     cpi->segment_encode_breakout[3] = threshold[3];
 
-    // Initialise the feature data structure
-    // SEGMENT_DELTADATA    0, SEGMENT_ABSDATA      1
+    /* Initialise the feature data structure */
     set_segment_data(cpi, &feature_data[0][0], SEGMENT_DELTADATA);
 
     return 0;
@@ -5362,7 +5412,6 @@ int vp8_set_active_map(VP8_COMP *cpi, unsigned char *map, unsigned int rows, uns
     }
     else
     {
-        //cpi->active_map_enabled = 0;
         return -1 ;
     }
 }
@@ -5392,7 +5441,9 @@ int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest)
     unsigned char *src = source->y_buffer;
     unsigned char *dst = dest->y_buffer;
 
-    // Loop through the Y plane raw and reconstruction data summing (square differences)
+    /* Loop through the Y plane raw and reconstruction data summing
+     * (square differences)
+     */
     for (i = 0; i < source->y_height; i += 16)
     {
         for (j = 0; j < source->y_width; j += 16)