Changeset 21

Show
Ignore:
Timestamp:
07/11/06 17:03:40 (3 years ago)
Author:
gbooker
Message:

Several things:
Removed globals in favor of a function with a static variable
Made format part of ff_global_context
Use av_probe_input_format to find the file format and set the format in globals
Call FFAvi_MovieImportValidateDataRef in parser to set the format (since it seems that another instance did the validate or something).
av_find_stream_info returns >=0 with success, not 0

This worked with a single AVI I tested, hopefully it is not the last.

Files:

Legend:

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

    r20 r21  
    2828#define PROBE_BUF_SIZE 64 
    2929 
    30 /* Global variables declaration & definition */ 
    31 AVInputFormat *avi_iformat; 
    32  
    33 /* This one is used because Global variables are initialized ONE time 
    34  * until the application quits. Thus, we have to make sure we're initialize 
    35  * the libavformat only once or we get an endlos loop when registering the same 
    36  * element twice!! */ 
    37 Boolean initLib = TRUE; 
    38  
    3930#include <CoreServices/CoreServices.h> 
    4031#include <QuickTime/QuickTime.h> 
     
    5950        ImageDescriptionHandle imgHdl; 
    6051        SoundDescriptionHandle sndHdl; 
     52        AVInputFormat           *format; 
    6153}; 
    6254typedef struct _ff_global_context ff_global_context; 
     
    6860 
    6961#pragma mark - 
     62 
     63void initLib() 
     64{ 
     65        /* This one is used because Global variables are initialized ONE time 
     66        * until the application quits. Thus, we have to make sure we're initialize 
     67        * the libavformat only once or we get an endlos loop when registering the same 
     68        * element twice!! */ 
     69        static Boolean inited = FALSE; 
     70 
     71        /* Register the Parser of ffmpeg, needed because we do no proper setup of the libraries */ 
     72        if(!inited) { 
     73                inited = TRUE; 
     74                av_register_all(); 
     75        } 
     76} 
    7077 
    7178/************************************ 
     
    207214ComponentResult FFAvi_MovieImportValidateDataRef(ff_global_ptr storage, Handle dataRef, OSType dataRefType, UInt8 *valid) 
    208215{ 
    209         AVInputFormat *format = avi_iformat; 
    210216        ComponentResult result = noErr; 
    211217        DataHandler dataHandler = NULL; 
     
    227233        require_noerr(result,bail); 
    228234         
    229         success = format->read_probe(pd); 
    230         if(success) 
     235        initLib(); 
     236        storage->format = av_probe_input_format(pd, 1); 
     237        if(storage->format != NULL) 
    231238                *valid = 255; /* This means we can read the data */ 
    232239bail: 
     
    279286        *outFlags = 0; 
    280287         
    281         /* Register the Parser of ffmpeg, needed because we do no proper setup of the libraries */ 
    282         if(initLib) { 
    283                initLib = FALSE
    284                register_parsers(); 
    285         } 
     288        /* probe the format first */ 
     289        UInt8 valid = 0; 
     290        FFAvi_MovieImportValidateDataRef(storage, dataRef, dataRefType, &valid)
     291        if(valid != 255) 
     292               goto bail; 
    286293         
    287294        /* Prepare the iocontext structure */ 
     
    292299        /* Open the Format Context */ 
    293300        memset(&params, 0, sizeof(params)); 
    294         if (avi_iformat == NULL) 
    295                 avi_iformat = (AVInputFormat *)malloc(sizeof(AVInputFormat)); 
    296         result = av_open_input_stream(&ic, &byteContext, "", avi_iformat, &params); 
     301        result = av_open_input_stream(&ic, &byteContext, "", storage->format, &params); 
    297302        require_noerr(result,bail); 
    298303         
    299304        /* Get the Stream Infos if not already read */ 
    300305        result = av_find_stream_info(ic); 
    301         require_noerr(result,bail); 
     306        if(result < 0) 
     307                goto bail; 
    302308         
    303309        /* Seek backwards to get a manually read packet for file offset */