Home | History | Annotate | Download | only in encoder
      1 /*
      2  *  Copyright (c) 2016 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed  by a BSD-style license that can be
      5  *  found in the LICENSE file in the root of the source tree. An additional
      6  *  intellectual property  rights grant can  be found in the  file PATENTS.
      7  *  All contributing  project authors may be  found in the AUTHORS  file in
      8  *  the root of the source tree.
      9  */
     10 
     11 /*
     12  *  \file vp9_alt_ref_aq.h
     13  *
     14  *  This file  contains public interface  for setting up  adaptive segmentation
     15  *  for altref frames.  Go to alt_ref_aq_private.h for implmentation details.
     16  */
     17 
     18 #ifndef VP9_ENCODER_VP9_ALT_REF_AQ_H_
     19 #define VP9_ENCODER_VP9_ALT_REF_AQ_H_
     20 
     21 #include "vpx/vpx_integer.h"
     22 
     23 // Where to disable segmentation
     24 #define ALT_REF_AQ_LOW_BITRATE_BOUNDARY 150
     25 
     26 // Last frame always has overall quality = 0,
     27 // so it is questionable if I can process it
     28 #define ALT_REF_AQ_APPLY_TO_LAST_FRAME 1
     29 
     30 // If I should try to compare gain
     31 // against segmentation overhead
     32 #define ALT_REF_AQ_PROTECT_GAIN 0
     33 
     34 // Threshold to disable segmentation
     35 #define ALT_REF_AQ_PROTECT_GAIN_THRESH 0.5
     36 
     37 #ifdef __cplusplus
     38 extern "C" {
     39 #endif
     40 
     41 // Simple structure for storing images
     42 struct MATX_8U {
     43   int rows;
     44   int cols;
     45   int stride;
     46 
     47   uint8_t *data;
     48 };
     49 
     50 struct VP9_COMP;
     51 struct ALT_REF_AQ;
     52 
     53 /*!\brief Constructor
     54  *
     55  * \return Instance of the class
     56  */
     57 struct ALT_REF_AQ *vp9_alt_ref_aq_create();
     58 
     59 /*!\brief Upload segmentation_map to self object
     60  *
     61  * \param    self             Instance of the class
     62  * \param    segmentation_map Segmentation map to upload
     63  */
     64 void vp9_alt_ref_aq_upload_map(struct ALT_REF_AQ *const self,
     65                                const struct MATX_8U *segmentation_map);
     66 
     67 /*!\brief Return pointer to the altref segmentation map
     68  *
     69  * \param    self                    Instance of the class
     70  * \param    segmentation_overhead   Segmentation overhead in bytes
     71  * \param    bandwidth               Current frame bandwidth in bytes
     72  *
     73  * \return  Boolean value to disable segmentation
     74  */
     75 int vp9_alt_ref_aq_disable_if(const struct ALT_REF_AQ *self,
     76                               int segmentation_overhead, int bandwidth);
     77 
     78 /*!\brief Set number of segments
     79  *
     80  * It is used for delta quantizer computations
     81  * and thus it can be larger than
     82  * maximum value of the segmentation map
     83  *
     84  * \param    self        Instance of the class
     85  * \param    nsegments   Maximum number of segments
     86  */
     87 void vp9_alt_ref_aq_set_nsegments(struct ALT_REF_AQ *const self, int nsegments);
     88 
     89 /*!\brief Set up LOOKAHEAD_AQ segmentation mode
     90  *
     91  * Set up segmentation mode to LOOKAHEAD_AQ
     92  * (expected future frames prediction
     93  *  quality refering to the current frame).
     94  *
     95  * \param    self    Instance of the class
     96  * \param    cpi     Encoder context
     97  */
     98 void vp9_alt_ref_aq_setup_mode(struct ALT_REF_AQ *const self,
     99                                struct VP9_COMP *const cpi);
    100 
    101 /*!\brief Set up LOOKAHEAD_AQ segmentation map and delta quantizers
    102  *
    103  * \param    self    Instance of the class
    104  * \param    cpi     Encoder context
    105  */
    106 void vp9_alt_ref_aq_setup_map(struct ALT_REF_AQ *const self,
    107                               struct VP9_COMP *const cpi);
    108 
    109 /*!\brief Restore main segmentation map mode and reset the class variables
    110  *
    111  * \param    self    Instance of the class
    112  * \param    cpi     Encoder context
    113  */
    114 void vp9_alt_ref_aq_unset_all(struct ALT_REF_AQ *const self,
    115                               struct VP9_COMP *const cpi);
    116 
    117 /*!\brief Destructor
    118  *
    119  * \param    self    Instance of the class
    120  */
    121 void vp9_alt_ref_aq_destroy(struct ALT_REF_AQ *const self);
    122 
    123 #ifdef __cplusplus
    124 }  // extern "C"
    125 #endif
    126 
    127 #endif  // VP9_ENCODER_VP9_ALT_REF_AQ_H_
    128