source: SHVCSoftware/branches/SHM-1.1-dev/source/App/utils/BitrateTargeting/GuessLambdaModifiers.h

Last change on this file was 2, checked in by seregin, 12 years ago

Initial import by Vadim Seregin <vseregin@…>

File size: 7.5 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2012, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef CALCULATE_LAMBDA_MODIFIER_H
35#define CALCULATE_LAMBDA_MODIFIER_H
36
37#include "RuntimeError.h"
38#include <vector>
39#include <map>
40#include <list>
41#include <set>
42#include <limits>
43
44/// Thrown if there is an error parsing the initial adjustment parameter
45class InitialAdjustmentParameterParseException: public RuntimeError
46{
47  public:
48    virtual ~InitialAdjustmentParameterParseException( ) throw( ) { }
49  protected:
50    void outputWhat( std::ostream& o ) const { o << "Error parsing the initial-adjustment parameter"; }
51};
52
53/// Thrown if there is an error parsing the targets
54class TargetsParseException: public RuntimeError
55{
56  public:
57    virtual ~TargetsParseException( ) throw( ) { }
58  protected:
59    void outputWhat( std::ostream& o ) const { o << "Error parsing targets"; }
60};
61
62/// Thrown if there is an error parsing the meta-log
63class MetaLogParseException: public RuntimeError
64{
65  public:
66    virtual ~MetaLogParseException( ) throw( ) { }
67  protected:
68    void outputWhat( std::ostream& o ) const { o << "Error parsing meta log"; }
69};
70
71/// Thrown if there is a mismatch in the vector sizes or the Lambda-modifier indexes
72class MismatchedIndexesException: public RuntimeError
73{
74  public:
75    virtual ~MismatchedIndexesException( ) throw( ) { }
76  protected:
77    void outputWhat( std::ostream& o ) const { o << "Mismatched vector sizes or lambda modifier indexes"; }
78};
79
80/// Full meta-log entry
81template< typename TLambdaModifier >
82struct MetaLogEntry
83{
84  TLambdaModifier lambdaModifiers;
85  std::vector< double > bitrateVector;
86};
87
88/// Contains a Lambda-modifier and bitrate for only a single index
89struct Point
90{
91  double lambdaModifier;
92  double bitrate;
93};
94
95/// Performs interpolation/extrapolation to guess a single Lambda-modifier
96/// \param target The target bitrate value that this Lambda-modifier is trying to reach
97/// \param point1 One of the two previously tried points where first is the Lambda-modifier and second is the obtained bitrate
98/// \param point2 One of the two previously tried points where first is the Lambda-modifier and second is the obtained bitrate
99/// \return The interpolated Lambda-modifier guess
100/// \pre Both given points must contain only positive non-zero values for first and second
101/// \pre The given points must have different first values and different second values.  If either the first values are the same or the second values are the same, then we have either a vertical or horizontal slope, and thus, interpolation cannot be performed.
102double polateLambdaModifier( double targetBitrate, const Point& point1, const Point& point2 );
103
104/// Guesses a single Lambda-modifier
105/// \param initialAdjustmentParameter If interpolation/extrapolation cannot be performed, then this parameter is used in the "increment" process.
106/// \param targetBitrate The target bitrate value that this Lambda-modifier is trying to reach
107/// \param pointList The list of points that correspond with this index
108/// \param interDampeningFactor This factor is obtained based on guessed Lambda-modifiers for previous temporal layers.  In some cases, this factor will scale down the change of this Lambda-modifier so that we are not making too many severe Lambda-modifier changes for a single encoder run.
109/// \return The Lambda-modifier guess
110/// \pre pointList cannot be empty
111/// \pre interDampeningFactor must be greater than zero and less than or equal to 1 (0 < interDampeningFactor <= 1)
112double guessLambdaModifier(
113    double initialAdjustmentParameter,
114    double targetBitrate,
115    const std::list< Point >& pointList,
116    double interDampeningFactor );
117
118/// Guesses all of the Lambda-modifiers
119/// \param initialAdjustmentParameter If interpolation/extrapolation cannot be performed, then this parameter is used in the "increment" process.
120/// \param targetBitrateVector The target bitrate values that we are trying to reach
121/// \param metaLogEntryList All of the previously run Lambda-modifiers and their corresponding bitrates from the meta-log
122/// \return Vector containing all of the guessed Lambda-modifiers
123/// \pre targetBitrateVector cannot be empty
124/// \pre metaLogEntryList cannot be empty
125/// \pre The size of targetBitrateVector must be the same as the size of bitrateVector in every item in metaLogEntryList
126/// \pre The size of targetBitrateVector must be the same as the size of lambdaModifiers in every item in metaLogEntryList
127std::vector< double > guessLambdaModifiers(
128    double initialAdjustmentParameter,
129    const std::vector< double > &targetBitrateVector,
130    const std::list< MetaLogEntry< std::vector< double > > >& metaLogEntryList );
131
132/// Guesses all of the Lambda-modifiers
133/// This function performs all of the necessary input parsing.  It ends up calling the other guessLambdaModifiers overload to perform the actual calculations.
134/// \param o The output stream to write the guessed Lambda-modifiers to
135/// \param initialAdjustmentParameterIstream The input stream that contains the initial adjustment parameter
136/// \param targetIstream The input stream that contains the target bitrates
137/// \param metaLogIstream The input stream that contains the meta-log
138/// \throw InitialAdjustmentParameterParseException if there is an error parsing the initial adjustment parameter
139/// \throw TargetsParseException if there is an error parsing the target bitrates
140/// \throw MetaLogParseException if there is an error parsing the meta-log
141/// \throw MismatchedIndexesException if there is a mismatch in the vector sizes or the Lambda-modifier indexes
142void guessLambdaModifiers(
143    std::ostream& o,
144    std::istream& initialAdjustmentParameterIstream,
145    std::istream& targetsIstream,
146    std::istream& metaLogIstream );
147
148#endif
Note: See TracBrowser for help on using the repository browser.