Changeset 850

Show
Ignore:
Timestamp:
04/18/08 23:31:08 (6 months ago)
Author:
astrange
Message:

Preroll subtitle fonts when loading the file.
This moves the annoying pause on start to the main thread.

Some cleanup.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MatroskaImport.h

    r658 r850  
    258258        // value if not null, and seeks to the specified point in the file. 
    259259        void SetContext(MatroskaSeekContext context); 
     260         
     261        // After the fonts are loaded, preplay the subtitle tracks to avoid an annoying pause 
     262        // from unavoidably lazy rendering APIs looking them up for the first time. 
     263        void PrerollSubtitleTracks(); 
    260264                 
    261265        ComponentInstance               self; 
  • trunk/MatroskaImportPrivate.cpp

    r849 r850  
    111111                 
    112112        } else if (EbmlId(*el_l1) == KaxAttachments::ClassInfos.GlobalId) { 
     113                ComponentResult res; 
    113114                el_l1->Read(*aStream, KaxAttachments::ClassInfos.Context, upperLevel, dummyElt, true); 
    114                 return ReadAttachments(*static_cast<KaxAttachments *>(el_l1)); 
    115                  
     115                res = ReadAttachments(*static_cast<KaxAttachments *>(el_l1)); 
     116                PrerollSubtitleTracks(); 
     117                return res; 
    116118        } else if (EbmlId(*el_l1) == KaxSeekHead::ClassInfos.GlobalId) { 
    117119                el_l1->Read(*aStream, KaxSeekHead::ClassInfos.Context, upperLevel, dummyElt, true); 
     
    876878} 
    877879 
     880void MatroskaImport::PrerollSubtitleTracks() 
     881{ 
     882        if (!seenTracks) return; 
     883                 
     884        for (int i = 0; i < tracks.size(); i++) { 
     885                if (tracks[i].type == track_subtitle) { 
     886                        Handle subtitleDescriptionExt; 
     887                        OSErr err = GetImageDescriptionExtension((ImageDescriptionHandle)tracks[i].desc, &subtitleDescriptionExt, kSubFormatSSA, 0); 
     888                         
     889                        if (err || !subtitleDescriptionExt) continue; 
     890                         
     891                        SubPrerollFromHeader(*subtitleDescriptionExt, GetHandleSize(subtitleDescriptionExt)); 
     892                } 
     893        } 
     894} 
    878895 
    879896MatroskaTrack::MatroskaTrack() 
  • trunk/Subtitles/SubATSUIRenderer.h

    r669 r850  
    66//  Copyright 2007 __MyCompanyName__. All rights reserved. 
    77// 
     8 
     9#ifdef __cplusplus 
     10extern "C" 
     11{ 
     12#endif 
    813 
    914#ifdef __OBJC__ 
     
    3136 
    3237typedef void *SubtitleRendererPtr; 
     38 
     39#endif 
     40 
    3341extern SubtitleRendererPtr SubInitForSSA(char *header, size_t headerLen, int width, int height); 
    3442extern SubtitleRendererPtr SubInitNonSSA(int width, int height); 
    3543extern CGColorSpaceRef SubGetColorSpace(SubtitleRendererPtr s); 
    3644extern void SubRenderPacket(SubtitleRendererPtr s, CGContextRef c, CFStringRef str, int cWidth, int cHeight); 
     45extern void SubPrerollFromHeader(char *header, int headerLen); 
    3746extern void SubDisposeRenderer(SubtitleRendererPtr s); 
    3847 
     48#ifdef __cplusplus 
     49} 
    3950#endif 
  • trunk/Subtitles/SubATSUIRenderer.m

    r849 r850  
    286286} 
    287287 
     288static ATSFontRef gHelveticaATSRef = -1; 
     289static ATSUFontID gHelveticaATSUID; 
     290 
    288291static ATSUFontID GetFontIDForSSAName(NSString *name, ATSFontRef *_fontRef) 
    289292{ 
     
    301304                 
    302305                if (font == kATSUInvalidFontID) { 
    303                         fontRef = ATSFontFindFromName((CFStringRef)@"Helvetica",kATSOptionFlagsDefault); 
    304                         font = FMGetFontFromATSFontRef(fontRef); 
     306                        if (gHelveticaATSRef == -1) { 
     307                                gHelveticaATSRef = ATSFontFindFromName((CFStringRef)@"Helvetica",kATSOptionFlagsDefault); 
     308                                gHelveticaATSUID = FMGetFontFromATSFontRef(fontRef); 
     309                        } 
     310                         
     311                        fontRef = gHelveticaATSRef; 
     312                        font    = gHelveticaATSUID; 
    305313                } 
    306314        } else fontRef = FMGetATSFontRefFromFont(font); 
     
    10971105} 
    10981106 
     1107void SubPrerollFromHeader(char *header, int headerLen) 
     1108{ 
     1109        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
     1110        SubtitleRendererPtr s = headerLen ? SubInitForSSA(header, headerLen, 640, 480) 
     1111                                                                      : SubInitNonSSA(640, 480); 
     1112         
     1113        CGColorSpaceRef csp = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 
     1114        void *buf = malloc(640 * 480 * 4); 
     1115        CGContextRef c = CGBitmapContextCreate(buf,640,480,8,640 * 4,csp,kCGImageAlphaPremultipliedFirst); 
     1116         
     1117        if (!headerLen) { 
     1118                SubRenderPacket(s, c, (CFStringRef)@"to Be continued", 640, 480); 
     1119        } else { 
     1120                NSArray *styles = [s->context->styles allValues]; 
     1121                int i, nstyles = [styles count]; 
     1122                 
     1123                for (i = 0; i < nstyles; i++) { 
     1124                        SubStyle *sty = [styles objectAtIndex:i]; 
     1125                        NSString *line = [NSString stringWithFormat:@"0,0,%@,,0,0,0,,to Be continued", sty->name]; 
     1126                        SubRenderPacket(s, c, (CFStringRef)line, 640, 480); 
     1127                } 
     1128        } 
     1129         
     1130        CGContextRelease(c); 
     1131        free(buf); 
     1132        CGColorSpaceRelease(csp); 
     1133        [pool release]; 
     1134} 
     1135 
    10991136void SubDisposeRenderer(SubtitleRendererPtr s) 
    11001137{ 
  • trunk/Subtitles/SubImport.h

    r806 r850  
    1111 
    1212#include <QuickTime/QuickTime.h> 
     13#ifndef __OBJC__ 
     14#include "SubATSUIRenderer.h" 
     15#endif 
    1316 
    1417#ifndef __OBJC_GC__ 
     
    3134#import <Cocoa/Cocoa.h> 
    3235#import "SubContext.h" 
     36#import "SubATSUIRenderer.h" 
    3337 
    3438@interface SubLine : NSObject 
  • trunk/Subtitles/SubImport.mm

    r806 r850  
    252252        [ss setFinished:YES]; 
    253253 
     254        SubPrerollFromHeader(header ? *header : NULL, header ? GetHandleSize(header) : 0); 
     255         
    254256        Handle dataRefHndl = NewHandleClear(sizeof(Handle) + 1); 
    255257        UInt32 emptyDataRefExt[2] = {EndianU32_NtoB(sizeof(UInt32)*2), EndianU32_NtoB(kDataRefExtensionInitializationData)}; 
     
    293295                        err = GetMoviesError(); 
    294296                        Codecprintf(stderr,"error %d adding line from %d to %d in external subtitles",err,sl->begin_time,sl->end_time); 
    295                         goto inLoopError; 
    296                 } 
    297                  
    298                 ConvertTimeScale(&startTime, movieTimeScale); 
    299                  
    300                 InsertMediaIntoTrack(theTrack, startTime.value.lo, sampleTime, sl->end_time - sl->begin_time, movieRate); 
    301                  
    302 inLoopError: 
     297                } else { 
     298                        ConvertTimeScale(&startTime, movieTimeScale); 
     299                        InsertMediaIntoTrack(theTrack, startTime.value.lo, sampleTime, sl->end_time - sl->begin_time, movieRate); 
     300                } 
     301                 
    303302                err = noErr; 
    304303                DisposeHandle(sampleHndl); 
  • trunk/TextSubCodec.c

    r806 r850  
    248248                 
    249249                if (!glob->ssa) glob->ssa = SubInitNonSSA((**p->imageDescription).width,(**p->imageDescription).height); 
    250                  
    251                 //SSA_PrerollFonts(glob->ssa); 
    252                  
     250                                 
    253251                glob->colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 
    254252        }