Changeset 410

Show
Ignore:
Timestamp:
04/12/07 02:28:56 (2 years ago)
Author:
dconrad
Message:

Don't open the decoder until we're asked to decode something, since we're often given bogus formats before then.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/FFissionCodec/FFissionDecoder.cpp

    r409 r410  
    186186        CodecID codecID = GetCodecID(inInputFormat.mFormatID); 
    187187         
    188         avCodec = avcodec_find_decoder(codecID); 
    189          
    190188        // check to make sure the input format is legal 
    191         if (avCodec == NULL) { 
     189        if (avcodec_find_decoder(codecID) == NULL) { 
    192190                Codecprintf(NULL, "Unsupported input format id %4.4s\n", &inInputFormat.mFormatID); 
    193191                CODEC_THROW(kAudioCodecUnsupportedFormatError); 
    194192        } 
    195193         
     194        // tell our base class about the new format 
     195        FFissionCodec::SetCurrentInputFormat(inInputFormat); 
     196} 
     197         
     198void FFissionDecoder::OpenAVCodec() 
     199{ 
     200        if (!mIsInitialized) 
     201                CODEC_THROW(kAudioCodecStateError); 
     202         
     203        CodecID codecID = GetCodecID(mInputFormat.mFormatID); 
     204         
     205        avCodec = avcodec_find_decoder(codecID); 
     206         
    196207        avcodec_get_context_defaults(avContext); 
    197208         
    198         avContext->sample_rate = inInputFormat.mSampleRate; 
    199         avContext->channels = inInputFormat.mChannelsPerFrame; 
    200         avContext->block_align = inInputFormat.mBytesPerPacket; 
    201         avContext->frame_size = inInputFormat.mFramesPerPacket; 
    202         avContext->bits_per_sample = inInputFormat.mBitsPerChannel; 
     209        avContext->sample_rate = mInputFormat.mSampleRate; 
     210        avContext->channels = mInputFormat.mChannelsPerFrame; 
     211        avContext->block_align = mInputFormat.mBytesPerPacket; 
     212        avContext->frame_size = mInputFormat.mFramesPerPacket; 
     213        avContext->bits_per_sample = mInputFormat.mBitsPerChannel; 
    203214         
    204215        if (avContext->sample_rate == 0) { 
     
    209220         
    210221        if (magicCookie) { 
    211                 SetupExtradata(inInputFormat.mFormatID); 
     222                SetupExtradata(mInputFormat.mFormatID); 
    212223        } 
    213224         
    214225        if (avcodec_open(avContext, avCodec)) { 
    215226                Codecprintf(NULL, "error opening audio avcodec\n"); 
    216                  
    217227                avCodec = NULL; 
    218                 CODEC_THROW(kAudioCodecIllegalOperationError); 
    219         } 
    220          
    221         // tell our base class about the new format 
    222         FFissionCodec::SetCurrentInputFormat(inInputFormat); 
     228                CODEC_THROW(kAudioCodecUnsupportedFormatError); 
     229        } 
    223230} 
    224231 
     
    275282        UInt32 ans = kAudioCodecProduceOutputPacketSuccess; 
    276283         
    277         if (!mIsInitialized) 
     284        if (!avCodec) 
     285                OpenAVCodec(); 
     286         
     287        if (!mIsInitialized || !avCodec) 
    278288                CODEC_THROW(kAudioCodecStateError); 
    279289         
  • trunk/FFissionCodec/FFissionDecoder.h

    r408 r410  
    4949private: 
    5050        void SetupExtradata(OSType formatID); 
     51        void OpenAVCodec(); 
    5152         
    5253        UInt32 kIntPCMOutFormatFlag;