Changeset 1042

Show
Ignore:
Timestamp:
04/20/09 21:09:28 (1 year ago)
Author:
astrange
Message:

MovieImport?:
- allow importing AVI with no video track (fixes a file I generated while testing)
- improve audio sample descriptions (MP3 should work better, don't know how to test it)
- pass magic cookies through to all API that supports them, minus AAC since that breaks

FFusion:
- fix memory leak if update checker isn't found

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/FFusionCodec.c

    r1039 r1042  
    233233        if(CFStringGetFileSystemRepresentation(absLocation, fileRep, 1024)) 
    234234            if(FSPathMakeRef((UInt8 *)fileRep, updateCheckRef, NULL) != noErr) 
    235                 return;  //We have failed 
     235                goto err;  //We have failed 
    236236    } 
    237237        pthread_t thread; 
    238238        pthread_create(&thread, NULL, launchUpdateChecker, updateCheckRef); 
     239         
     240        return; 
     241err: 
     242        free(updateCheckRef); 
    239243} 
    240244 
  • trunk/ff_MovieImport.c

    r1031 r1042  
    376376                        enum CodecID id = codec_get_id(codec_bmp_tags, BSWAP(fourcc)); 
    377377                         
    378                         if (id == CODEC_ID_MJPEG || id == CODEC_ID_DVVIDEO || id == CODEC_ID_RAWVIDEO || id == CODEC_ID_NONE || id == CODEC_ID_MSVIDEO1) 
     378                        if (id == CODEC_ID_MJPEG || id == CODEC_ID_DVVIDEO || id == CODEC_ID_RAWVIDEO || id == CODEC_ID_MSVIDEO1) 
    379379                                *valid = 0; 
    380380                         
  • trunk/ff_private.c

    r1031 r1042  
    210210        AVCodecContext *codec; 
    211211        UInt32 ioSize; 
    212         OSStatus err
     212        OSStatus err = noErr
    213213         
    214214        uint8_t *cookie = NULL; 
     
    228228         
    229229        /* Ask the AudioToolbox about vbr of the codec */ 
     230        // FIXME this sets vbr even if it was encoded in CBR mode 
     231        // which means our mBytesPerPacket is wrong for CBR mp3 (does not really matter) 
    230232        ioSize = sizeof(UInt32); 
    231233        AudioFormatGetProperty(kAudioFormatProperty_FormatIsVBR, sizeof(AudioStreamBasicDescription), &asbd, &ioSize, &map->vbr); 
    232234         
     235        cookie = create_cookie(codec, &cookieSize, asbd.mFormatID, map->vbr); 
     236         
    233237        /* ask the toolbox about more information */ 
    234         ioSize = sizeof(AudioStreamBasicDescription); 
    235         AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &ioSize, &asbd); 
     238        // FIXME the cookie for AAC is wrong somehow, passing it in breaks FormatInfo & ASBDFromESDS 
     239        // either fix it (like in MKV) or just ignore it 
     240        if (asbd.mFormatID != kAudioFormatMPEG4AAC) { 
     241                ioSize = sizeof(AudioStreamBasicDescription); 
     242                err = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, cookieSize, &cookie, &ioSize, &asbd); 
     243                if (err || !asbd.mFormatID) 
     244                        fprintf(stderr, "AudioFormatGetProperty dislikes the magic cookie (error %ld / format id %lx)\n", err, asbd.mFormatID); 
     245        } 
    236246         
    237247        /* Set some fields of the AudioStreamBasicDescription. Then ask the AudioToolbox 
     
    239249        asbd.mSampleRate = codec->sample_rate; 
    240250        asbd.mChannelsPerFrame = codec->channels; 
    241         if(!map->vbr && asbd.mBytesPerPacket == 0) /* This works for all the tested codecs. but is there any better way? */ 
     251        if(!map->vbr && !asbd.mBytesPerPacket) /* This works for all the tested codecs. but is there any better way? */ 
    242252                asbd.mBytesPerPacket = codec->block_align; /* this is tested for alaw/mulaw/msadpcm */ 
    243         asbd.mFramesPerPacket = codec->frame_size; /* works for mp3, all other codecs this is 0 anyway */ 
    244         asbd.mBitsPerChannel = codec->bits_per_coded_sample; 
    245          
    246         // this probably isn't quite right; FLV doesn't set frame_size or block_align,  
    247         // but we need > 0 frames per packet or Apple's mp3 decoder won't work 
     253         
     254        /* 
     255         FIXME:  
     256         - at least ffmp3 does not set these values without parsing+the decoder being enabled 
     257           (so we avoid overwriting them from above for now) 
     258         - it is unclear whether the ASBD values correspond to decoded or encoded data (same for lavc) 
     259         - this should be 0 for formats with variable framesPerPacket 
     260         - lavc frame_size is in bytes, mFramesPerPacket is in frames (maybe) 
     261         */ 
     262        if (!asbd.mFramesPerPacket) 
     263                asbd.mFramesPerPacket = codec->frame_size; 
    248264        if (asbd.mFormatID == kAudioFormatMPEG4AAC) 
    249265                asbd.mFramesPerPacket = 1024; 
    250         else if (asbd.mBytesPerPacket == 0 && asbd.mFramesPerPacket == 0
     266        if (!asbd.mFramesPerPacket && !asbd.mBytesPerPacket
    251267                asbd.mFramesPerPacket = 1; 
     268        asbd.mBitsPerChannel = codec->bits_per_coded_sample; 
    252269         
    253270        // if we don't have mBytesPerPacket, we can't import as CBR. Probably should be VBR, and the codec 
     
    309326        } 
    310327         
    311         if (asbd.mSampleRate > 0) { 
    312                 err = QTSoundDescriptionCreate(&asbd, aclSize == 0 ? NULL : &acl, aclSize, NULL, 0, kQTSoundDescriptionKind_Movie_LowestPossibleVersion, &sndHdl); 
     328        if (asbd.mSampleRate > 0) {              
     329                err = QTSoundDescriptionCreate(&asbd, aclSize == 0 ? NULL : &acl, aclSize, cookie, cookieSize, kQTSoundDescriptionKind_Movie_LowestPossibleVersion, &sndHdl); 
     330                 
    313331                if(err) { 
    314332                        fprintf(stderr, "AVI IMPORTER: Error %ld creating the sound description\n", err); 
    315                         return err; 
    316                 } 
    317          
    318                 /* Create the magic cookie */ 
    319                 cookie = create_cookie(codec, &cookieSize, asbd.mFormatID, map->vbr); 
    320                 if(cookie) { 
    321                         err = QTSoundDescriptionSetProperty(sndHdl, kQTPropertyClass_SoundDescription, kQTSoundDescriptionPropertyID_MagicCookie, 
    322                                                                                                 cookieSize, cookie); 
    323                         if(err) fprintf(stderr, "AVI IMPORTER: Error %ld appending the magic cookie to the sound description\n", err); 
    324                         av_free(cookie); 
     333                        goto bail; 
     334                } 
     335                 
     336                // QTSoundDescriptionCreate sets this to 576 which is wrong 
     337                if ((**sndHdl).version == 1 && asbd.mFormatID == kAudioFormatMPEGLayer3) { 
     338                        SoundDescriptionV1Handle v1h = (SoundDescriptionV1Handle)sndHdl; 
     339                        (**v1h).samplesPerPacket = 1152; 
    325340                } 
    326341        }        
    327342        map->sampleHdl = (SampleDescriptionHandle)sndHdl; 
    328343        map->asbd = asbd; 
     344         
     345bail: 
     346        if(cookie) 
     347                av_free(cookie); 
    329348         
    330349        return noErr;