Changeset 91

Show
Ignore:
Timestamp:
09/20/06 19:57:49 (2 years ago)
Author:
dconrad
Message:

Speed up validation by using a simple AVI parser that only looks for the video fourcc to determine if it's a troublesome format that we should pass off to Apple's importer

Files:

Legend:

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

    r86 r91  
    2626#include "allformats.h" 
    2727#include "Codecprintf.h" 
     28#include "riff.h" 
    2829 
    2930/* This one is a little big in ffmpeg and private anyway */ 
     
    237238} /* FFAvi_MovieImportValidate() */ 
    238239 
     240// this function is a small avi parser to get the video track's fourcc as 
     241// fast as possible, so we can decide whether we can handle the necessary  
     242// image description extensions for the format in ValidateDataRef() quickly 
     243OSType get_avi_strf_fourcc(ByteIOContext *pb) 
     244{ 
     245        OSType tag, subtag; 
     246        unsigned int size; 
     247         
     248        if (get_be32(pb) != 'RIFF') 
     249                return 0; 
     250         
     251        // file size 
     252        get_le32(pb); 
     253         
     254        if (get_be32(pb) != 'AVI ') 
     255                return 0; 
     256         
     257        while (!url_feof(pb)) { 
     258                tag = get_be32(pb); 
     259                size = get_le32(pb); 
     260                 
     261                if (tag == 'LIST') { 
     262                        subtag = get_be32(pb); 
     263                         
     264                        // only lists we care about: hdrl & strl, so skip the rest 
     265                        if (subtag != 'hdrl' && subtag != 'strl') 
     266                                url_fskip(pb, size - 4 + (size & 1)); 
     267                         
     268                } else if (tag == 'strf') { 
     269                        // 16-byte offset to the fourcc 
     270                        url_fskip(pb, 16); 
     271                        return get_be32(pb); 
     272                } else 
     273                        url_fskip(pb, size + (size & 1)); 
     274        } 
     275        return 0; 
     276} 
     277 
    239278ComponentResult FFAvi_MovieImportValidateDataRef(ff_global_ptr storage, Handle dataRef, OSType dataRefType, UInt8 *valid) 
    240279{ 
     
    244283        AVProbeData *pd = (AVProbeData *)malloc(sizeof(AVProbeData)); 
    245284        ByteIOContext byteContext; 
    246         AVFormatContext *ic = NULL; 
    247285        AVFormatParameters params; 
    248286        int success, i; 
     
    266304                *valid = 255; /* This means we can read the data */ 
    267305                 
    268                 /* Prepare the iocontext structure */ 
    269                 memset(&byteContext, 0, sizeof(byteContext)); 
    270                 result = url_open_dataref(&byteContext, dataRef, dataRefType); 
    271                 require_noerr(result, bail); 
    272                  
    273                 /* Open the Format Context */ 
    274                 memset(&params, 0, sizeof(params)); 
    275                 result = av_open_input_stream(&ic, &byteContext, "", storage->format, &params); 
    276                 require_noerr(result,bail); 
    277                  
    278                 for (i = 0; i < ic->nb_streams; i++) { 
    279                         if (ic->streams[i]->codec->codec_id == CODEC_ID_MJPEG ||  
    280                                 ic->streams[i]->codec->codec_id == CODEC_ID_MJPEGB ||  
    281                                 ic->streams[i]->codec->codec_id == CODEC_ID_DVVIDEO) 
    282                                 /* but we don't do MJPEG's Huffman tables right yet, and DV video seems to have  
    283                                   an aspect ratio coded in the bitstream that ffmpeg doesn't read */ 
     306                /* we don't do MJPEG's Huffman tables right yet, and DV video seems to have  
     307                an aspect ratio coded in the bitstream that ffmpeg doesn't read, so let Apple's  
     308                AVI importer handle AVIs with these two video types */ 
     309                if (IS_AVI(storage->componentType)) { 
     310                        /* Prepare the iocontext structure */ 
     311                        memset(&byteContext, 0, sizeof(byteContext)); 
     312                        result = url_open_dataref(&byteContext, dataRef, dataRefType); 
     313                        require_noerr(result, bail); 
     314                         
     315                        OSType fourcc = get_avi_strf_fourcc(&byteContext); 
     316                         
     317                        if (codec_get_bmp_id(BSWAP(fourcc)) == CODEC_ID_MJPEG ||  
     318                                codec_get_bmp_id(BSWAP(fourcc)) == CODEC_ID_DVVIDEO) 
    284319                                *valid = 0; 
    285320                } 
     
    289324                if(dataHandler) 
    290325                        CloseComponent(dataHandler); 
    291         if(ic) 
    292                 av_close_input_file(ic); 
    293326        free(pd); 
    294327         
     
    363396        if(ic->streams[0]->index_entries == NULL) 
    364397        { 
    365                 if (storage->componentType == 'AVI ' || storage->componentType == 'VfW ' || storage->componentType == 'VFW '
     398                if (IS_AVI(storage->componentType)
    366399                        //Try to seek to the first frame; don't care if it fails 
    367400                        // Is this really needed for AVIs w/out an index? It seems to work fine without,  
  • trunk/ff_private.c

    r90 r91  
    2828#include <AudioToolbox/AudioToolbox.h> 
    2929 
    30 #define BSWAP(a) ( (((a)&0xff) << 24) | (((a)&0xff00) << 8) | (((a)&0xff0000) >> 8) | (((a) >> 24) & 0xff) ) 
    31  
    3230/* This routine checks if the system requirements are fullfilled */ 
    3331ComponentResult check_system() 
     
    530528short import_avi(AVFormatContext *ic, NCStream *map, int64_t aviheader_offset) 
    531529{ 
    532         int j, k, l
     530        int j, k, l, nextFrame
    533531        NCStream *ncstr; 
    534532        AVStream *stream; 
  • trunk/ff_private.h

    r86 r91  
    3737        AVRational base; 
    3838        int64_t lastpts; 
     39        int idxEntry; 
    3940        SampleReference64Record lastSample; 
    4041}; 
     
    6869uint8_t *write_data(uint8_t *target, uint8_t* data, int32_t data_size); 
    6970 
     71#define BSWAP(a) ( (((a)&0xff) << 24) | (((a)&0xff00) << 8) | (((a)&0xff0000) >> 8) | (((a) >> 24) & 0xff) ) 
     72 
     73#define IS_AVI(x) (x == 'AVI ' || x == 'VfW ' || x == 'VFW ') 
    7074 
    7175#endif