Changeset 210

Show
Ignore:
Timestamp:
12/22/06 21:28:07 (2 years ago)
Author:
dconrad
Message:

Support for native MPEG-4 part 2 video in mp4/mov/mkv by completely overriding Apple's decoder. This allows for better decoding of various features that Apple's decoder lacks support for. Closes #66.

Files:

Legend:

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

    r163 r210  
    88 */ 
    99 
     10#include "avcodec.h" 
    1011#include "CommonUtils.h" 
    1112 
     
    202203} /* write_data() */ 
    203204 
     205 
     206 
     207#define MP4ESDescrTag                   0x03 
     208#define MP4DecConfigDescrTag            0x04 
     209#define MP4DecSpecificDescrTag          0x05 
     210 
     211// based off of mov_mp4_read_descr_len from mov.c in ffmpeg's libavformat 
     212static int readDescrLen(UInt8 **buffer) 
     213{ 
     214        int len = 0; 
     215        int count = 4; 
     216        while (count--) { 
     217                int c = *(*buffer)++; 
     218                len = (len << 7) | (c & 0x7f); 
     219                if (!(c & 0x80)) 
     220                        break; 
     221        } 
     222        return len; 
     223} 
     224 
     225// based off of mov_mp4_read_descr from mov.c in ffmpeg's libavformat 
     226static int readDescr(UInt8 **buffer, int *tag) 
     227{ 
     228        int len; 
     229        *tag = *(*buffer)++; 
     230        return readDescrLen(buffer); 
     231} 
     232 
     233// based off of mov_read_esds from mov.c in ffmpeg's libavformat 
     234ComponentResult ReadESDSDescExt(Handle descExt, UInt8 **buffer, int *size) 
     235{ 
     236        UInt8 *esds = (UInt8 *) *descExt; 
     237        int tag, len; 
     238         
     239        *size = 0; 
     240         
     241        esds += 4;              // version + flags 
     242        len = readDescr(&esds, &tag); 
     243        esds += 2;              // ID 
     244        if (tag == MP4ESDescrTag) 
     245                esds++;         // priority 
     246         
     247        len = readDescr(&esds, &tag); 
     248        if (tag == MP4DecConfigDescrTag) { 
     249                esds++;         // object type id 
     250                esds++;         // stream type 
     251                esds += 3;      // buffer size db 
     252                esds += 4;      // max bitrate 
     253                esds += 4;      // average bitrate 
     254                 
     255                len = readDescr(&esds, &tag); 
     256                if (tag == MP4DecSpecificDescrTag) { 
     257                        *buffer = calloc(1, len + FF_INPUT_BUFFER_PADDING_SIZE); 
     258                        if (*buffer) { 
     259                                memcpy(*buffer, esds, len); 
     260                                *size = len; 
     261                        } 
     262                } 
     263        } 
     264         
     265        return noErr; 
     266} 
  • trunk/CommonUtils.h

    r163 r210  
    3131uint8_t *write_data(uint8_t *target, uint8_t* data, int32_t data_size); 
    3232 
     33// mallocs the buffer and copies the codec-specific description to it, in the same format 
     34// as is specified in Matroska and is used in libavcodec 
     35ComponentResult ReadESDSDescExt(Handle descExt, UInt8 **buffer, int *size); 
     36 
    3337#ifdef __cplusplus 
    3438} 
  • trunk/FFusionCodec.c

    r209 r210  
    410410    char altivec = 0; 
    411411    Byte* myptr; 
     412        long count = 0; 
     413        Handle imgDescExt; 
    412414         
    413415    // We first open libavcodec library and the codec corresponding 
     
    456458                                break; 
    457459                                 
     460                        case 'mp4v':    // MPEG4 part 2 in mov/mp4 
     461                                glob->quicktimeDoesReorder = true; 
    458462            case 'divx':        // DivX 4 
    459463            case 'DIVX': 
     
    554558                // avc1 requires the avcC extension 
    555559                if (glob->componentType == 'avc1') { 
    556                         long count = 0; 
    557                         Handle imgDescExt; 
     560                        CountImageDescriptionExtensionType(p->imageDescription, 'avcC', &count); 
    558561                         
    559                         CountImageDescriptionExtensionType(p->imageDescription, 'avcC', &count); 
    560562                        if (count >= 1) { 
    561563                                imgDescExt = NewHandle(0); 
    562564                                GetImageDescriptionExtension(p->imageDescription, &imgDescExt, 'avcC', 1); 
    563565                                 
    564                                 glob->avContext->extradata = malloc(GetHandleSize(imgDescExt)); 
     566                                glob->avContext->extradata = calloc(1, GetHandleSize(imgDescExt) + FF_INPUT_BUFFER_PADDING_SIZE); 
    565567                                memcpy(glob->avContext->extradata, *imgDescExt, GetHandleSize(imgDescExt)); 
    566568                                glob->avContext->extradata_size = GetHandleSize(imgDescExt); 
     569                                 
     570                                DisposeHandle(imgDescExt); 
     571                        } 
     572                } else if (glob->componentType == 'mp4v') { 
     573                        CountImageDescriptionExtensionType(p->imageDescription, 'esds', &count); 
     574                         
     575                        if (count >= 1) { 
     576                                imgDescExt = NewHandle(0); 
     577                                GetImageDescriptionExtension(p->imageDescription, &imgDescExt, 'esds', 1); 
     578                                 
     579                                ReadESDSDescExt(imgDescExt, &glob->avContext->extradata, &glob->avContext->extradata_size); 
    567580                                 
    568581                                DisposeHandle(imgDescExt); 
     
    12291242                        case 'FMP4': 
    12301243                        case 'SMP4': 
     1244                        case 'mp4v': 
    12311245                                err = GetComponentResource((Component)glob->self, codecInfoResourceType, kMPEG4CodecInfoResID, (Handle *)&tempCodecInfo); 
    12321246                                break; 
  • trunk/FFusionCodec.r

    r209 r210  
    19251925}; 
    19261926 
     1927// XXX: can we do this without claiming Apple's manufacturer (and thus unregistering their decoder)? 
     1928resource 'thng' (304) { 
     1929        decompressorComponentType,              // Type                  
     1930        'mp4v',                                 // SubType 
     1931        'appl',                 // Manufacturer 
     1932        0,                                      // - use componentHasMultiplePlatforms 
     1933        0, 
     1934        0, 
     1935        0, 
     1936        'STR ',                                 // Name Type 
     1937        kMPEG4NameResID,                                // Name ID 
     1938        'STR ',                                 // Info Type 
     1939        kMPEG4NameResID,                                // Info ID 
     1940        0,                                      // Icon Type 
     1941        0,                                      // Icon ID 
     1942        kFFusionCodecVersion + 0x10000,                 // Version 
     1943        componentHasMultiplePlatforms +         // Registration Flags  
     1944        componentDoAutoVersion,                 // Registration Flags 
     1945        0,                                      // Resource ID of Icon Family 
     1946        { 
     1947                kFFusionDecompressionFlags,  
     1948                'dlle',                         // Entry point found by symbol name 'dlle' resource 
     1949                256,                            // ID of 'dlle' resource 
     1950                platformPowerPCNativeEntryPoint, 
     1951                kFFusionDecompressionFlags, 
     1952                'dlle', 
     1953                256, 
     1954                platformIA32NativeEntryPoint, 
     1955        }; 
     1956}; 
     1957 
    19271958 
    19281959//--------------------------------------------------------------------------- 
    19291960// H264 Components 
    19301961//--------------------------------------------------------------------------- 
    1931 resource 'thng' (304) { 
     1962resource 'thng' (305) { 
    19321963        decompressorComponentType,              // Type                  
    19331964        'H264',                                 // SubType 
     
    19591990}; 
    19601991 
    1961 resource 'thng' (305) { 
     1992resource 'thng' (306) { 
    19621993        decompressorComponentType,              // Type                  
    19631994        'h264',                                 // SubType 
     
    19892020}; 
    19902021 
    1991 resource 'thng' (306) { 
     2022resource 'thng' (307) { 
    19922023        decompressorComponentType,              // Type                  
    19932024        'X264',                                 // SubType 
     
    20192050}; 
    20202051 
    2021 resource 'thng' (307) { 
     2052resource 'thng' (308) { 
    20222053        decompressorComponentType,              // Type                  
    20232054        'x264',                                 // SubType 
     
    20492080}; 
    20502081 
    2051 resource 'thng' (308) { 
     2082resource 'thng' (309) { 
    20522083        decompressorComponentType,              // Type                  
    20532084        'DAVC',                                 // SubType 
     
    20792110}; 
    20802111 
    2081 resource 'thng' (309) { 
     2112resource 'thng' (310) { 
    20822113        decompressorComponentType,              // Type                  
    20832114        'VSSH',                                 // SubType 
     
    21092140}; 
    21102141 
    2111 resource 'thng' (310) { 
     2142resource 'thng' (311) { 
    21122143        decompressorComponentType,              // Type                  
    21132144        'AVC1',                                 // SubType 
     
    21392170}; 
    21402171 
    2141 resource 'thng' (311) { 
     2172resource 'thng' (312) { 
    21422173        decompressorComponentType,              // Type                  
    21432174        'avc1',                                 // SubType 
     
    21732204// Flash Video Codecs 
    21742205//--------------------------------------------------------------------------- 
    2175 resource 'thng' (312) { 
     2206resource 'thng' (313) { 
    21762207        decompressorComponentType,              // Type                  
    21772208        'FLV1',                                 // SubType 
     
    22032234}; 
    22042235 
    2205 resource 'thng' (313) { 
     2236resource 'thng' (314) { 
    22062237        decompressorComponentType,              // Type                  
    22072238        'FSV1',                                 // SubType 
     
    22372268// VP6 Components 
    22382269//--------------------------------------------------------------------------- 
    2239 resource 'thng' (314) { 
     2270resource 'thng' (315) { 
    22402271        decompressorComponentType,              // Type                  
    22412272        'VP60',                                 // SubType 
     
    22672298}; 
    22682299 
    2269 resource 'thng' (315) { 
     2300resource 'thng' (316) { 
    22702301        decompressorComponentType,              // Type                  
    22712302        'VP61',                                 // SubType 
     
    22972328}; 
    22982329 
    2299 resource 'thng' (316) { 
     2330resource 'thng' (317) { 
    23002331        decompressorComponentType,              // Type                  
    23012332        'VP62',                                 // SubType 
     
    23272358}; 
    23282359 
    2329 resource 'thng' (317) { 
     2360resource 'thng' (318) { 
    23302361        decompressorComponentType,              // Type                  
    23312362        'VP6F',                                 // SubType 
     
    23612392// Intel H.263 Components 
    23622393//--------------------------------------------------------------------------- 
    2363 resource 'thng' (318) { 
     2394resource 'thng' (319) { 
    23642395        decompressorComponentType,              // Type                  
    23652396        'I263',                                 // SubType 
     
    23912422}; 
    23922423 
    2393 resource 'thng' (319) { 
     2424resource 'thng' (320) { 
    23942425        decompressorComponentType,              // Type                  
    23952426        'i263',                                 // SubType 
     
    24252456// VP3 Components 
    24262457//--------------------------------------------------------------------------- 
    2427 resource 'thng' (320) { 
     2458resource 'thng' (321) { 
    24282459        decompressorComponentType,              // Type                  
    24292460        'VP30',                                 // SubType 
     
    24552486}; 
    24562487 
    2457 resource 'thng' (321) { 
     2488resource 'thng' (322) { 
    24582489        decompressorComponentType,              // Type                  
    24592490        'VP31',                                 // SubType