Changeset 1313 in 3DVCSoftware for trunk/source/App/utils/BitrateTargeting/ExtractBitrates.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/App/utils/BitrateTargeting/ExtractBitrates.cpp
r872 r1313 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 5 * 6 * Copyright (c) 2010-201 4, ITU/ISO/IEC4 * granted under this license. 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 45 45 { 46 46 public: 47 47 48 48 /// Contructs a new zeroed tally 49 49 Tally( ): m_sum( 0.0 ), m_numSlices( 0 ) { } 50 50 51 51 /// Adds to the sum and increments the sample-count 52 52 void add( double in ) { ++m_numSlices; m_sum += in; } 53 53 54 54 /// \return The calculated average 55 55 double average( ) const { return m_sum / ( double )m_numSlices; } 56 56 57 57 private: 58 58 double m_sum; 59 59 unsigned long m_numSlices; 60 60 }; 61 61 62 62 /// Ignores all of the the characters up to and including a given character 63 63 /// \param line The line being read from … … 69 69 while( iLine.good( ) && character != iLine.get( ) ) 70 70 ; 71 if( !iLine.good( ) ) throw POCParseException( line ); 71 if( !iLine.good( ) ) 72 { 73 throw POCParseException( line ); 74 } 72 75 } 73 76 74 77 /// Extracts the average bitrates for each of the temporal layers from the given log 75 78 /// \param i The input stream that represents the log … … 79 82 { 80 83 std::map< unsigned char, Tally > tallyMap; 81 84 82 85 while( i.good( ) ) 83 86 { … … 86 89 std::getline( i, line ); 87 90 std::istringstream iLine( line ); 88 if( !iLine.good( ) ) continue; 89 91 if( !iLine.good( ) ) 92 { 93 continue; 94 } 95 90 96 // Ignore the "POC" 91 if( iLine.get( ) != 'P' ) continue; 92 if( !iLine.good( ) ) continue; 93 if( iLine.get( ) != 'O' ) continue; 94 if( !iLine.good( ) ) continue; 95 if( iLine.get( ) != 'C' ) continue; 96 if( !iLine.good( ) ) throw POCParseException( line ); 97 97 if( iLine.get( ) != 'P' ) 98 { 99 continue; 100 } 101 if( !iLine.good( ) ) 102 { 103 continue; 104 } 105 if( iLine.get( ) != 'O' ) 106 { 107 continue; 108 } 109 if( !iLine.good( ) ) 110 { 111 continue; 112 } 113 if( iLine.get( ) != 'C' ) 114 { 115 continue; 116 } 117 if( !iLine.good( ) ) 118 { 119 throw POCParseException( line ); 120 } 121 98 122 ignoreUpTo( line, iLine, '(' ); 99 100 if( iLine.get( ) != ' ' ) throw POCParseException( line ); 101 if( !iLine.good( ) ) throw POCParseException( line ); 102 103 if( 'I' == iLine.get( ) ) continue; 104 if( !iLine.good( ) ) throw POCParseException( line ); 105 123 124 if( iLine.get( ) != ' ' ) 125 { 126 throw POCParseException( line ); 127 } 128 if( !iLine.good( ) ) 129 { 130 throw POCParseException( line ); 131 } 132 133 if( 'I' == iLine.get( ) ) 134 { 135 continue; 136 } 137 if( !iLine.good( ) ) 138 { 139 throw POCParseException( line ); 140 } 141 106 142 ignoreUpTo( line, iLine, ' ' ); 107 143 ignoreUpTo( line, iLine, ' ' ); 108 144 109 145 // Parse the qpIndex 110 146 long qpIndexLong; 111 147 iLine >> qpIndexLong; 112 if( ( long )std::numeric_limits< unsigned char >::max( ) < qpIndexLong ) throw POCParseException( line ); 148 if( ( long )std::numeric_limits< unsigned char >::max( ) < qpIndexLong ) 149 { 150 throw POCParseException( line ); 151 } 113 152 unsigned char qpIndex( ( unsigned char )qpIndexLong ); 114 if( !iLine.good( ) ) throw POCParseException( line ); 115 153 if( !iLine.good( ) ) 154 { 155 throw POCParseException( line ); 156 } 157 116 158 ignoreUpTo( line, iLine, ')' ); 117 159 ignoreUpTo( line, iLine, ' ' ); 118 160 119 161 // Parse the number of bits 120 162 unsigned long bitsULong; 121 163 iLine >> bitsULong; 122 if( !iLine.good( ) ) throw POCParseException( line ); 123 164 if( !iLine.good( ) ) 165 { 166 throw POCParseException( line ); 167 } 168 124 169 // Find the tally that corresponds to our QP. If there is no such tally yet, then add a new one to the map. 125 170 std::map< unsigned char, Tally >::iterator iter( tallyMap.find( qpIndex ) ); … … 130 175 } 131 176 assert( iter != tallyMap.end( ) ); 132 177 133 178 iter->second.add( ( double )bitsULong ); 134 179 } 135 180 136 181 // Populate and return the result based on all of the tallies 137 182 std::map< unsigned char, double > result; … … 147 192 { 148 193 std::vector< double > result; 149 194 150 195 std::map< unsigned char, double > bitratesForQPsMap( extractBitratesForQPs( i ) ); 151 196 if( !bitratesForQPsMap.empty( ) ) 152 197 { 153 198 unsigned char expectedNextQPIndex( bitratesForQPsMap.begin( )->first ); 154 199 155 200 for( std::map< unsigned char, double >::const_iterator i( bitratesForQPsMap.begin( ) ); i != bitratesForQPsMap.end( ); ++i ) 156 201 { 157 if( i->first != expectedNextQPIndex ) throw NonContiguousQPSetException( ); 202 if( i->first != expectedNextQPIndex ) 203 { 204 throw NonContiguousQPSetException( ); 205 } 158 206 ++expectedNextQPIndex; 159 207 result.push_back( i->second ); 160 208 } 161 209 } 162 210 163 211 return result; 164 212 }
Note: See TracChangeset for help on using the changeset viewer.