Changeset 334

Show
Ignore:
Timestamp:
02/08/07 18:42:07 (2 years ago)
Author:
astrange
Message:

Hack overlap handling to make sure subtitle samples really don't overlap, which makes QT act really weird.
Restore some bit of control flow in the Matroska importer (which I don't quite understand).
Scale \fs tag properly.
Fix possibility of colorspace converter crashing (ffmpeg only guarantees 8-byte alignment and sse2 needs 16).

Files:

Legend:

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

    r290 r334  
    6363//also, big-endian only 
    6464 
    65 static void Y420_ppc_scalar(UInt8* baseAddr, int outRB, int width, int height, AVFrame * picture) 
     65static void Y420toY422_ppc_scalar(UInt8* baseAddr, int outRB, int width, int height, AVFrame * picture) 
    6666{ 
    6767         int             y = height >> 1; 
     
    106106 } 
    107107 
    108 static void Y420_ppc_altivec(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
     108static void Y420toY422_ppc_altivec(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
    109109{ 
    110110        UInt8          *yc = picture->data[0], *uc = picture->data[1], *vc = picture->data[2]; 
     
    164164                size_t length = sizeof(vType); 
    165165                int error = sysctl(sels, 2, &vType, &length, NULL, 0); 
    166                 if( 0 == error && vType ) y420_function = Y420_ppc_altivec; 
     166                if( 0 == error && vType ) y420_function = Y420toY422_ppc_altivec; 
    167167                else  
    168                 y420_function = Y420_ppc_scalar; 
     168                y420_function = Y420toY422_ppc_scalar; 
    169169        } 
    170170         
     
    174174#include <emmintrin.h> 
    175175 
    176 void Y420toY422(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
     176static void Y420toY422_sse2(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
    177177{ 
    178178        UInt8          *yc = picture->data[0], *uc = picture->data[1], *vc = picture->data[2]; 
    179179        int             rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2]; 
    180         int                             y,x, vWidth = width >> 4, halfheight = height >> 1
     180        int                             y,x, vWidth = width >> 4, halfheight = height >> 1, halfwidth = width >> 1
    181181         
    182182        for (y = 0; y < halfheight; y ++) { 
     
    206206                } 
    207207                 
    208                 if (__builtin_expect(width % 16, FALSE)) { //spill to scalar for the end if the row isn't a multiple of 16 
     208                if (__builtin_expect(width & 15, FALSE)) { //spill to scalar for the end if the row isn't a multiple of 16 
    209209                        UInt8 *o2 = o + outRB, *yc2 = yc + rY; 
    210                         for (x = vWidth * 16; x < width; x += 2) { 
     210                        for (x = vWidth * 16; x < halfwidth; x ++) { 
    211211                                int             hx = x>>1, x2 = x*2; 
    212212                                o2[x2] = o[x2] = uc[hx]; 
     
    224224                vc += rV; 
    225225        } 
    226         _mm_sfence(); // complete all writes 
     226        _mm_sfence(); // complete all writes (probably not really needed) 
     227
     228 
     229 
     230static void Y420toY422_x86_scalar(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
     231
     232        UInt8          *yc = picture->data[0], *u = picture->data[1], *v = picture->data[2]; 
     233        int             rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2], halfheight = height >> 1, halfwidth = width >> 1; 
     234        int                             y, x; 
     235         
     236        for (y = 0; y < halfheight; y ++) { 
     237                UInt8 *o2 = o + outRB, *yc2 = yc + rY; 
     238                 
     239                for (x = 0; x < halfwidth; x ++) { 
     240                        int             hx = x>>1, x2 = x*2; 
     241                        o2[x2] = o[x2] = u[hx]; 
     242                        o[x2 + 1] = yc[x]; 
     243                        o2[x2 + 1] = yc2[x]; 
     244                        o2[x2 + 2] = o[x2 + 2] = v[hx]; 
     245                        o[x2 + 3] = yc[x + 1]; 
     246                        o2[x2 + 3] = yc2[x + 1]; 
     247                } 
     248                 
     249                o += outRB*2; 
     250                yc += rY*2; 
     251                u += rU; 
     252                v += rV; 
     253        } 
     254
     255 
     256void Y420toY422(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
     257
     258        uintptr_t yc = (uintptr_t)picture->data[0]; 
     259 
     260        //make sure the ffmpeg picture buffers are aligned enough, they're only guaranteed to be 8-byte for some reason... 
     261        //if input y isn't 16 byte aligned, sse2 crashes 
     262 
     263        if (__builtin_expect((yc % 16) == 0 && (picture->linesize[0] % 16) == 0, TRUE)) Y420toY422_sse2(o, outRB, width, height, picture); 
     264        else Y420toY422_x86_scalar(o, outRB, width, height, picture); 
    227265} 
    228266#endif 
  • trunk/MatroskaImport.cpp

    r333 r334  
    276276                        } 
    277277                         
    278                 } 
    279                  
     278                } else  
    280279                do { 
    281280                        if (EbmlId(*el_l1) == KaxCluster::ClassInfos.GlobalId) { 
  • trunk/SSATagParsing.m.rl

    r332 r334  
    266266                                 
    267267                                action fsize { 
     268                                        num *= (72./96.); // scale from Windows 96dpi 
    268269                                        fixv = FloatToFixed(num); 
    269270                                        SetATSUStyleOther(cur_style, kATSUSizeTag, sizeof(fixv), &fixv); 
  • trunk/SubImport.mm

    r333 r334  
    387387        if (num == 0) return; 
    388388        unsigned times[num*2+1]; 
    389         SubLine *slines[num]
     389        SubLine *slines[num], *last=nil
    390390        [lines sortUsingFunction:cmp_line context:nil]; 
    391391        [lines getObjects:slines]; 
    392        //NSLog(@"pre - %@",lines); 
     392//     NSLog(@"pre - %@",lines); 
    393393        for (int i=0;i < num;i++) { 
    394394                times[i*2]   = slines[i]->begin_time; 
     
    412412                for (int j=0; j < num; j++) { 
    413413                        if (isinrange(times[i], slines[j]->begin_time, slines[j]->end_time)) { 
    414                                 end = slines[j]->end_time; 
     414                                unsigned next_start = (j == num-1)?slines[j]->end_time:slines[j+1]->begin_time; 
     415                                end = MIN(slines[j]->end_time, next_start); 
    415416                                [accum appendString:slines[j]->line]; 
    416417                                startedOutput = true; 
     
    421422                if (finishedOutput && startedOutput) { 
    422423                        [accum deleteCharactersInRange:NSMakeRange([accum length] - 1, 1)]; // delete last newline 
     424                         
     425                        if (last) { // ensure the last packet's end time isn't after this one's begin time 
     426                                if (last->end_time > start) last->end_time = start; 
     427                        } 
     428                         
    423429                        SubLine *event = [[SubLine alloc] initWithLine:accum start:start end:end]; 
     430 
     431                        [outpackets addObject:event]; 
    424432                         
    425                         [outpackets addObject:event]
     433                        last = event
    426434                } 
    427435        } 
    428436         
    429 //      NSLog(@"%@",outpackets); 
     437//      NSLog(@"out - %@",outpackets); 
    430438 
    431439        if (finished) [lines removeAllObjects];