Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/App/utils/BitrateTargeting/GuessLambdaModifiers.cpp

    r872 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2014, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4646  {
    4747    assert( right.empty( ) );
    48    
     48
    4949    for( ; ; )
    5050    {
    5151      assert( left.good( ) );
    52      
     52
    5353      double bitrate;
    5454      left >> bitrate;
    55       if( left.fail( ) ) break;
     55      if( left.fail( ) )
     56      {
     57        break;
     58      }
    5659      if( bitrate <= ( double )0.0 )
    5760      {
     
    6265        right.push_back( bitrate );
    6366      }
    64       if( !left.good( ) ) break;
    65      
     67      if( !left.good( ) )
     68      {
     69        break;
     70      }
     71
    6672      if( left.peek( ) == ' ' )
    6773      {
     
    7480    }
    7581  }
    76  
     82
    7783  /// Makes a next guess for a single Lambda-modifier based on only one previous guess
    7884  /// \param initialAdjustmentParameter The proportionality to use between the target bitrate and the previous guess
     
    8894    assert( ( double )0.0 < previousPoint.lambdaModifier );
    8995    assert( ( double )0.0 < previousPoint.bitrate );
    90    
     96
    9197    double extrapolated( previousPoint.lambdaModifier * targetBitrate / previousPoint.bitrate );
    9298    return previousPoint.lambdaModifier + initialAdjustmentParameter * ( extrapolated - previousPoint.lambdaModifier );
     
    102108  assert( point1.lambdaModifier != point2.lambdaModifier );
    103109  assert( point1.bitrate != point2.bitrate );
    104  
     110
    105111  // Calculate and return the result
    106112  double denominator( point1.bitrate - point2.bitrate );
     
    119125  assert( interDampeningFactor <= ( double )1.0 );
    120126  assert( !pointList.empty( ) );
    121  
     127
    122128  double preliminaryResult;
    123  
     129
    124130  if( 1 == pointList.size( ) )  // If there is only one prevous point, then we cannot interpolate, so we call incrementLambdaModifier
    125131  {
     
    132138    ++i;
    133139    Point point2 = *i;
    134    
     140
    135141    // If the slope is either horizontal or vertical, we cannot interpolate
    136142    if( point1.lambdaModifier == point2.lambdaModifier || point1.bitrate == point2.bitrate )
     
    143149    }
    144150  }
    145  
     151
    146152  double previousResult( pointList.back( ).lambdaModifier );
    147  
     153
    148154  // Apply "intra dampening"
    149155  {
     
    159165    }
    160166  }
    161  
     167
    162168  // Apply "inter dampening factor".  If necessary, reduce the factor until a positive result is acheived.
    163169  double result;
     
    180186    return result;
    181187  }
    182  
     188
    183189  /// Calculates the inter dampening factor based
    184190  /// \param parameter The inter dampening parameter which determines how severely the inter dampening factor is affected by Lambda-modifier changes at previous temporal layers
     
    202208  assert( !targetBitrateVector.empty( ) );
    203209  assert( !metaLogEntryList.empty( ) );
    204  
     210
    205211  double cumulativeDelta( 0.0 );
    206212  std::vector< double > resultVector;
     
    212218    pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
    213219    ++j;
    214     if( j != metaLogEntryList.rend( ) ) pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
    215    
     220    if( j != metaLogEntryList.rend( ) )
     221    {
     222      pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
     223    }
     224
    216225    // Calculate the new Lambda-modifier guess and add it to the result vector
    217226    const double newLambdaModifier( guessLambdaModifier(
     
    221230        interDampeningFactor( 50.0, cumulativeDelta ) ) );
    222231    resultVector.push_back( newLambdaModifier );
    223    
     232
    224233    // Increment the cumulativeDelta
    225234    const double oldLambdaModifier( pointList.back( ).lambdaModifier );
    226235    cumulativeDelta += std::abs( newLambdaModifier - oldLambdaModifier ) / oldLambdaModifier;
    227236  }
    228  
     237
    229238  return resultVector;
    230239}
     
    240249    while( i.good( ) && character != i.get( ) )
    241250      ;
    242     if( !i.good( ) ) throw MetaLogParseException( );
    243   }
    244  
     251    if( !i.good( ) )
     252    {
     253      throw MetaLogParseException( );
     254    }
     255  }
     256
    245257  /// Parses a Lambda-modifier map
    246258  /// \param right The map to write the output to
     
    250262    {
    251263      assert( left.good( ) );
    252      
     264
    253265      // Ignore the "-LM"
    254       if( '-' != left.get( ) ) left.setstate( std::istream::failbit );
    255       if( !left.good( ) ) break;
    256       if( 'L' != left.get( ) ) left.setstate( std::istream::failbit );
    257       if( !left.good( ) ) break;
    258       if( 'M' != left.get( ) ) left.setstate( std::istream::failbit );
    259       if( !left.good( ) ) break;
    260      
     266      if( '-' != left.get( ) )
     267      {
     268        left.setstate( std::istream::failbit );
     269      }
     270      if( !left.good( ) )
     271      {
     272        break;
     273      }
     274      if( 'L' != left.get( ) )
     275      {
     276        left.setstate( std::istream::failbit );
     277      }
     278      if( !left.good( ) )
     279      {
     280        break;
     281      }
     282      if( 'M' != left.get( ) )
     283      {
     284        left.setstate( std::istream::failbit );
     285      }
     286      if( !left.good( ) )
     287      {
     288        break;
     289      }
     290
    261291      // Parse the index
    262292      long indexLong;
    263293      left >> indexLong;
    264       if( !left.good( ) ) break;
    265       if( indexLong < std::numeric_limits< unsigned char >::min( ) ) left.setstate( std::istream::failbit );
    266       if( std::numeric_limits< unsigned char >::max( ) < indexLong ) left.setstate( std::istream::failbit );
    267       if( !left.good( ) ) break;
     294      if( !left.good( ) )
     295      {
     296        break;
     297      }
     298      if( indexLong < std::numeric_limits< unsigned char >::min( ) )
     299      {
     300        left.setstate( std::istream::failbit );
     301      }
     302      if( std::numeric_limits< unsigned char >::max( ) < indexLong )
     303      {
     304        left.setstate( std::istream::failbit );
     305      }
     306      if( !left.good( ) )
     307      {
     308        break;
     309      }
    268310      unsigned char index( ( unsigned char )indexLong );
    269      
    270       if( ' ' != left.get( ) ) left.setstate( std::istream::failbit );
    271       if( !left.good( ) ) break;
    272      
     311
     312      if( ' ' != left.get( ) )
     313      {
     314        left.setstate( std::istream::failbit );
     315      }
     316      if( !left.good( ) )
     317      {
     318        break;
     319      }
     320
    273321      // Parse the Lambda-modifier
    274322      double lambdaModifier;
     
    282330        right[ index ] = lambdaModifier;
    283331      }
    284       if( !left.good( ) ) break;
    285      
     332      if( !left.good( ) )
     333      {
     334        break;
     335      }
     336
    286337      // If we peek and see a space, then there should be more Lambda-modifiers to parse.  Otherwise, we are finished.
    287338      if( left.peek( ) == ' ' )
     
    295346    }
    296347  }
    297  
     348
    298349  /// Extracts the indexes from the given maps
    299350  /// \return The set of indexes
     
    322373    throw InitialAdjustmentParameterParseException( );
    323374  }
    324  
     375
    325376  // Parse the targets
    326377  std::vector< double > targetVector;
    327378  parseBitrateVector( targetsIstream, targetVector );
    328   if( targetVector.empty( ) || targetsIstream.fail( ) || targetsIstream.good( ) ) throw TargetsParseException( );
    329  
     379  if( targetVector.empty( ) || targetsIstream.fail( ) || targetsIstream.good( ) )
     380  {
     381    throw TargetsParseException( );
     382  }
     383
    330384  // Parse the metalog
    331385  std::list< MetaLogEntry< std::map< unsigned char, double > > > metaLogEntryList;
     
    335389    MetaLogEntry< std::map< unsigned char, double > > entry;
    336390    parseLambdaModifierMap( metaLogIstream, entry.lambdaModifiers );
    337     if( !metaLogIstream.good( ) ) throw MetaLogParseException( );
    338    
     391    if( !metaLogIstream.good( ) )
     392    {
     393      throw MetaLogParseException( );
     394    }
     395
    339396    // Skip the ';'
    340     if( ';' != metaLogIstream.get( ) ) throw MetaLogParseException( );
    341     if( !metaLogIstream.good( ) ) throw MetaLogParseException( );
    342    
     397    if( ';' != metaLogIstream.get( ) )
     398    {
     399      throw MetaLogParseException( );
     400    }
     401    if( !metaLogIstream.good( ) )
     402    {
     403      throw MetaLogParseException( );
     404    }
     405
    343406    // Parse the bitrates
    344407    parseBitrateVector( metaLogIstream, entry.bitrateVector );
    345     if( metaLogIstream.fail( ) ) throw MetaLogParseException( );
     408    if( metaLogIstream.fail( ) )
     409    {
     410      throw MetaLogParseException( );
     411    }
    346412    metaLogEntryList.push_back( entry );
    347    
    348     if( !metaLogIstream.good( ) ) break;
    349     if( metaLogIstream.get( ) != '\n' ) throw MetaLogParseException( );
     413
     414    if( !metaLogIstream.good( ) )
     415    {
     416      break;
     417    }
     418    if( metaLogIstream.get( ) != '\n' )
     419    {
     420      throw MetaLogParseException( );
     421    }
    350422    metaLogIstream.peek( );
    351423  } while( metaLogIstream.good( ) );
    352   if( metaLogEntryList.empty( ) ) throw MetaLogParseException( );  // The meta-log should not be empty
    353  
     424  if( metaLogEntryList.empty( ) )
     425  {
     426    throw MetaLogParseException( );  // The meta-log should not be empty
     427  }
     428
    354429  // Initialize firstIndexVector and check that the sizes and indexes match
    355430  std::set< unsigned char > firstIndexSet( indexSetFromMap( metaLogEntryList.front( ).lambdaModifiers ) );
    356   if( firstIndexSet.size( ) != targetVector.size( ) ) throw MismatchedIndexesException( );
     431  if( firstIndexSet.size( ) != targetVector.size( ) )
     432  {
     433    throw MismatchedIndexesException( );
     434  }
    357435  for( std::list< MetaLogEntry< std::map< unsigned char, double > > >::const_iterator i( metaLogEntryList.begin( ) );
    358436      i != metaLogEntryList.end( );
    359437      ++i )
    360438  {
    361     if( indexSetFromMap( i->lambdaModifiers ) != firstIndexSet ) throw MismatchedIndexesException( );
    362     if( i->bitrateVector.size( ) != targetVector.size( ) ) throw MismatchedIndexesException( );
    363   }
    364  
     439    if( indexSetFromMap( i->lambdaModifiers ) != firstIndexSet )
     440    {
     441      throw MismatchedIndexesException( );
     442    }
     443    if( i->bitrateVector.size( ) != targetVector.size( ) )
     444    {
     445      throw MismatchedIndexesException( );
     446    }
     447  }
     448
    365449  // Initialize simplifiedMetaLogEntryList
    366450  std::list< MetaLogEntry< std::vector< double > > > simplifiedMetaLogEntryList;
     
    376460    simplifiedMetaLogEntryList.back( ).bitrateVector = i->bitrateVector;
    377461  }
    378  
     462
    379463  // Run the calculations
    380464  std::vector< double > resultVector( guessLambdaModifiers( initialAdjustmentParameter, targetVector, simplifiedMetaLogEntryList ) );
    381  
     465
    382466  // Output the results
    383467  std::set< unsigned char >::const_iterator indexIter( firstIndexSet.begin( ) );
     
    385469  do
    386470  {
    387     if( indexIter != firstIndexSet.begin( ) ) o << " ";
     471    if( indexIter != firstIndexSet.begin( ) )
     472    {
     473      o << " ";
     474    }
    388475    o << "-LM" << ( long )( *indexIter ) << " ";
    389476    o.setf( std::ostream::fixed, std::ostream::floatfield );
    390477    o.precision( 7 );
    391478    o << ( *resultIter );
    392    
     479
    393480    ++indexIter;
    394481    ++resultIter;
Note: See TracChangeset for help on using the changeset viewer.