Changeset 163

Show
Ignore:
Timestamp:
10/15/06 17:42:46 (2 years ago)
Author:
dconrad
Message:

Native MPEG4 video requires the esds atom, so create it from what we have in the Matroska track entry

Files:

Legend:

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

    r156 r163  
    182182} 
    183183 
     184/* write the int32_t data to target & then return a pointer which points after that data */ 
     185uint8_t *write_int32(uint8_t *target, int32_t data) 
     186{ 
     187        return write_data(target, (uint8_t*)&data, sizeof(data)); 
     188} /* write_int32() */ 
     189 
     190/* write the int16_t data to target & then return a pointer which points after that data */ 
     191uint8_t *write_int16(uint8_t *target, int16_t data) 
     192{ 
     193        return write_data(target, (uint8_t*)&data, sizeof(data)); 
     194} /* write_int16() */ 
     195 
     196/* write the data to the target adress & then return a pointer which points after the written data */ 
     197uint8_t *write_data(uint8_t *target, uint8_t* data, int32_t data_size) 
     198{ 
     199        if(data_size > 0) 
     200                memcpy(target, data, data_size); 
     201        return (target + data_size); 
     202} /* write_data() */ 
     203 
  • trunk/CommonUtils.h

    r156 r163  
    2222short ThreeCharLangCodeToQTLangCode(char *lang); 
    2323 
     24/* write the int32_t data to target & then return a pointer which points after that data */ 
     25uint8_t *write_int32(uint8_t *target, int32_t data); 
     26 
     27/* write the int16_t data to target & then return a pointer which points after that data */ 
     28uint8_t *write_int16(uint8_t *target, int16_t data); 
     29 
     30/* write the data to the target adress & then return a pointer which points after the written data */ 
     31uint8_t *write_data(uint8_t *target, uint8_t* data, int32_t data_size); 
     32 
    2433#ifdef __cplusplus 
    2534} 
  • trunk/MatroskaCodecIDs.cpp

    r159 r163  
    242242                 
    243243                AddImageDescriptionExtension(imgDesc, imgDescExt, kSampleDescriptionExtensionReal); 
     244                 
     245                DisposeHandle((Handle) imgDescExt); 
     246        } 
     247        return noErr; 
     248} 
     249 
     250// the esds atom creation is based off of the routines for it in ffmpeg's movenc.c 
     251static unsigned int descrLength(unsigned int len) 
     252{ 
     253    int i; 
     254    for(i=1; len>>(7*i); i++); 
     255    return len + 1 + i; 
     256} 
     257 
     258static uint8_t* putDescr(uint8_t *buffer, int tag, unsigned int size) 
     259{ 
     260    int i= descrLength(size) - size - 2; 
     261    *buffer++ = tag; 
     262    for(; i>0; i--) 
     263       *buffer++ = (size>>(7*i)) | 0x80; 
     264    *buffer++ = size & 0x7F; 
     265        return buffer; 
     266} 
     267 
     268// ESDS layout: 
     269//  + version             (4 bytes) 
     270//  + ES descriptor  
     271//   + Track ID            (2 bytes) 
     272//   + Flags               (1 byte) 
     273//   + DecoderConfig descriptor 
     274//    + Object Type         (1 byte) 
     275//    + Stream Type         (1 byte) 
     276//    + Buffersize DB       (3 bytes) 
     277//    + Max bitrate         (4 bytes) 
     278//    + VBR/Avg bitrate     (4 bytes) 
     279//    + DecoderSpecific info descriptor 
     280//     + codecPrivate        (codecPrivate->GetSize()) 
     281//   + SL descriptor 
     282//    + dunno               (1 byte) 
     283 
     284ComponentResult DescExt_mp4v(KaxTrackEntry *tr_entry, SampleDescriptionHandle desc, DescExtDirection dir) 
     285{ 
     286        if (!tr_entry || !desc) return paramErr; 
     287        ImageDescriptionHandle imgDesc = (ImageDescriptionHandle) desc; 
     288         
     289        if (dir == kToSampleDescription) { 
     290                KaxCodecPrivate *codecPrivate = FindChild<KaxCodecPrivate>(*tr_entry); 
     291                KaxTrackNumber *trackNum = FindChild<KaxTrackNumber>(*tr_entry); 
     292                 
     293                int vosLen = codecPrivate ? codecPrivate->GetSize() : 0; 
     294                int trackID = trackNum ? uint16(*trackNum) : 1; 
     295                int decoderSpecificInfoLen = vosLen ? descrLength(vosLen) : 0; 
     296                 
     297                Handle imgDescExt = NewHandle(4 + descrLength(3 + descrLength(13 + decoderSpecificInfoLen) + descrLength(1))); 
     298                UInt8 *pos = (UInt8 *) *imgDescExt; 
     299                 
     300                pos = write_int32(pos, 0);              // version 
     301                 
     302                // ES Descriptor 
     303                pos = putDescr(pos, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) + descrLength(1)); 
     304                pos = write_int16(pos, EndianS16_NtoB(trackID)); 
     305                *pos++ = 0;             // no flags 
     306                 
     307                // DecoderConfig descriptor 
     308                pos = putDescr(pos, 0x04, 13 + decoderSpecificInfoLen); 
     309                 
     310                // Object type indication, see http://gpac.sourceforge.net/tutorial/mediatypes.htm 
     311                *pos++ = 0x20; 
     312                 
     313                // streamtype (video) 
     314                *pos++ = 0x11; 
     315                 
     316                // 3 bytes: buffersize DB (not sure how to get easily) 
     317                *pos++ = 0; 
     318                pos = write_int16(pos, 0); 
     319                 
     320                // max bitrate, not sure how to get easily 
     321                pos = write_int32(pos, 0); 
     322                 
     323                // vbr 
     324                pos = write_int32(pos, 0); 
     325                 
     326                if (vosLen) { 
     327                        pos = putDescr(pos, 0x05, vosLen); 
     328                        pos = write_data(pos, codecPrivate->GetBuffer(), vosLen); 
     329                } 
     330                 
     331                // SL descriptor 
     332                pos = putDescr(pos, 0x06, 1); 
     333                *pos++ = 0x02; 
     334                 
     335                AddImageDescriptionExtension(imgDesc, imgDescExt, 'esds'); 
    244336                 
    245337                DisposeHandle((Handle) imgDescExt); 
  • trunk/MatroskaCodecIDs.h

    r157 r163  
    8585        kSubFormatVobSub                        = 'SPU ', 
    8686         
    87         // the following 4CCs aren't official, nor have any decoder suppor
     87        // the following 4CCs don't have decoder support ye
    8888        kMPEG1VisualCodecType                   = 'mp1v', 
    8989        kMPEG2VisualCodecType                   = 'mp2v', 
     
    115115 
    116116 
    117  
    118117// these functions modify the AudioStreamBasicDescription properly for the audio format 
    119118ComponentResult ASBDExt_AC3(KaxTrackEntry *tr_entry, AudioStreamBasicDescription *asbd); 
    120119ComponentResult ASBDExt_LPCM(KaxTrackEntry *tr_entry, AudioStreamBasicDescription *asbd); 
    121120ComponentResult ASBDExt_AAC(KaxTrackEntry *tr_entry, AudioStreamBasicDescription *asbd); 
     121 
    122122 
    123123struct ASBDExtensionFunc { 
     
    126126}; 
    127127 
    128 static const struct ASBDExtensionFunc kMatroskaASBDExtensionFuncs[] = { 
     128const struct ASBDExtensionFunc kMatroskaASBDExtensionFuncs[] = { 
    129129        { kAudioFormatMPEG4AAC, ASBDExt_AAC }, 
    130130        { kAudioFormatAC3, ASBDExt_AC3 }, 
     
    144144ComponentResult DescExt_VobSub(KaxTrackEntry *tr_entry, SampleDescriptionHandle desc, DescExtDirection dir); 
    145145ComponentResult DescExt_Real(KaxTrackEntry *tr_entry, SampleDescriptionHandle desc, DescExtDirection dir); 
     146ComponentResult DescExt_mp4v(KaxTrackEntry *tr_entry, SampleDescriptionHandle desc, DescExtDirection dir); 
     147 
    146148 
    147149struct CodecDescExtFunc { 
     
    150152}; 
    151153 
    152 static const struct CodecDescExtFunc kMatroskaSampleDescExtFuncs[] = { 
     154const struct CodecDescExtFunc kMatroskaSampleDescExtFuncs[] = { 
    153155        { kH264CodecType, DescExt_H264 }, 
    154156        { kAudioFormatXiphVorbis, DescExt_XiphVorbis }, 
     
    159161        { kVideoFormatReal8, DescExt_Real }, 
    160162        { kVideoFormatReal9, DescExt_Real }, 
     163        { kMPEG4VisualCodecType, DescExt_mp4v }, 
    161164}; 
     165 
    162166 
    163167short GetTrackLanguage(KaxTrackEntry *tr_entry); 
  • trunk/ff_private.c

    r162 r163  
    2424#include "avcodec.h" 
    2525#include "Codecprintf.h" 
     26#include "CommonUtils.h" 
    2627 
    2728#include <CoreServices/CoreServices.h> 
     
    423424        return result; 
    424425} /* create_extension() */ 
    425  
    426 /* write the int32_t data to target & then return a pointer which points after that data */ 
    427 uint8_t *write_int32(uint8_t *target, int32_t data) 
    428 { 
    429         return write_data(target, (uint8_t*)&data, sizeof(data)); 
    430 } /* write_int32() */ 
    431  
    432 /* write the int16_t data to target & then return a pointer which points after that data */ 
    433 uint8_t *write_int16(uint8_t *target, int16_t data) 
    434 { 
    435         return write_data(target, (uint8_t*)&data, sizeof(data)); 
    436 } /* write_int16() */ 
    437  
    438 /* write the data to the target adress & then return a pointer which points after the written data */ 
    439 uint8_t *write_data(uint8_t *target, uint8_t* data, int32_t data_size) 
    440 { 
    441         if(data_size > 0) 
    442                 memcpy(target, data, data_size); 
    443         return (target + data_size); 
    444 } /* write_data() */ 
    445  
    446426 
    447427/* Add the meta data that lavf exposes to the movie */