| 155 | //----------------------------------------------------------------------------- |
| 156 | |
| 157 | bool OggTheoraDecoder::_init() |
| 158 | { |
| 159 | ogg_packet nextPacket; |
| 160 | |
| 161 | // Read header packets. |
| 162 | |
| 163 | bool haveTheoraHeader = true; |
| 164 | while( 1 ) |
| 165 | { |
| 166 | if( !_readNextPacket( &nextPacket ) ) |
| 167 | { |
| 168 | haveTheoraHeader = false; |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | S32 result = th_decode_headerin( &mTheoraInfo, &mTheoraComment, &mTheoraSetup, &nextPacket ); |
| 173 | if( result < 0 ) |
| 174 | { |
| 175 | haveTheoraHeader = false; |
| 176 | break; |
| 177 | } |
| 178 | else if( result == 0 ) |
| 179 | break; |
| 180 | } |
| 181 | |
| 182 | // Fail if we have no valid and complete Theora header. |
| 183 | |
| 184 | if( !haveTheoraHeader ) |
| 185 | { |
| 186 | th_comment_clear( &mTheoraComment ); |
| 187 | th_info_clear( &mTheoraInfo ); |
| 188 | |
| 189 | Con::errorf( "OggTheoraDecoder::_init() - incorrect or corrupt Theora headers" ); |
| 190 | |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | // Init the decoder. |
| 195 | |
| 196 | mTheoraDecoder = th_decode_alloc( &mTheoraInfo, mTheoraSetup ); |
| 197 | |
| 198 | // Feed the first video packet to the decoder. |
| 199 | |
| 200 | ogg_int64_t granulePos; |
| 201 | th_decode_packetin( mTheoraDecoder, &nextPacket, &granulePos ); |
| 202 | |
| 203 | mCurrentFrameTime = th_granule_time( mTheoraDecoder, granulePos ); |
| 204 | mCurrentFrameNumber = 0; |
| 205 | mFrameDuration = 1.f / getFramesPerSecond(); |
| 206 | |
| 207 | // Make sure we have a valid pitch. |
| 208 | |
| 209 | if( !mPacketFormat.mPitch ) |
| 210 | mPacketFormat.mPitch = getFrameWidth() * GFXFormatInfo( mPacketFormat.mFormat ).getBytesPerPixel(); |
| 211 | |
| 212 | return true; |
| 213 | } |
| 214 |
no test coverage detected