Changeset 312
- Timestamp:
- 01/28/07 20:31:53 (2 years ago)
- Files:
-
- trunk/MatroskaImportPrivate.cpp (modified) (2 diffs)
- trunk/Perian.xcodeproj/project.pbxproj (modified) (4 diffs)
- trunk/SSADocument.m (modified) (4 diffs)
- trunk/SSATagParsing.m.rl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/MatroskaImportPrivate.cpp
r311 r312 478 478 { 479 479 KaxEditionEntry & edition = GetChild<KaxEditionEntry>(chapterEntries); 480 UInt32 emptyDataRefExtension[2]; 480 481 481 482 chapterTrack = NewMovieTrack(theMovie, 0, 0, kNoVolume); … … 488 489 // sample references (TextMediaAddTextSample() will behave the same as AddSample() 489 490 // in that it modifies the original file if that's the data reference of the media) 490 Handle dataRef = NULL; 491 Handle dataRefData = NewHandle(0); 492 PtrToHand(&dataRefData, &dataRef, sizeof(Handle)); 491 Handle dataRef = NewHandleClear(sizeof(Handle) + 1); 492 493 emptyDataRefExtension[0] = EndianU32_NtoB(sizeof(UInt32)*2); 494 emptyDataRefExtension[1] = EndianU32_NtoB(kDataRefExtensionInitializationData); 495 496 PtrAndHand(&emptyDataRefExtension[0], dataRef, sizeof(emptyDataRefExtension)); 497 493 498 Media chapterMedia = NewTrackMedia(chapterTrack, TextMediaType, GetMovieTimeScale(theMovie), 494 499 dataRef, HandleDataHandlerSubType); trunk/Perian.xcodeproj/project.pbxproj
r310 r312 107 107 3D211A300B6B1AD80051299D /* SSATagParsing.m.rl in Resources */ = {isa = PBXBuildFile; fileRef = 3D211A2F0B6B1AD80051299D /* SSATagParsing.m.rl */; }; 108 108 3D4A7A990B5533BC004C5D6A /* ColorConversions.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D4A7A980B5533BC004C5D6A /* ColorConversions.c */; }; 109 3DB2BB290B6C92F000416863 /* SSARenderCodec.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DB2BB280B6C92F000416863 /* SSARenderCodec.m */; }; 109 110 6116E5510B43C27B0020F1CE /* ACBaseCodec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6116E5370B43C27B0020F1CE /* ACBaseCodec.cpp */; }; 110 111 6116E5520B43C27B0020F1CE /* ACCodec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6116E5390B43C27B0020F1CE /* ACCodec.cpp */; }; … … 443 444 3D4A7A970B5533BC004C5D6A /* ColorConversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorConversions.h; sourceTree = "<group>"; }; 444 445 3D4A7A980B5533BC004C5D6A /* ColorConversions.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ColorConversions.c; sourceTree = "<group>"; }; 446 3DB2BB270B6C92F000416863 /* SSARenderCodec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSARenderCodec.h; sourceTree = "<group>"; }; 447 3DB2BB280B6C92F000416863 /* SSARenderCodec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSARenderCodec.m; sourceTree = "<group>"; }; 445 448 6116E5370B43C27B0020F1CE /* ACBaseCodec.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ACBaseCodec.cpp; sourceTree = "<group>"; }; 446 449 6116E5380B43C27B0020F1CE /* ACBaseCodec.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ACBaseCodec.h; sourceTree = "<group>"; }; … … 876 879 61D514DC0ADF3DBA00A671E1 /* SubImport.h */, 877 880 61D514DD0ADF3DBA00A671E1 /* SubImport.c */, 881 3DB2BB270B6C92F000416863 /* SSARenderCodec.h */, 882 3DB2BB280B6C92F000416863 /* SSARenderCodec.m */, 878 883 ); 879 884 name = Subtitles; … … 1512 1517 3D211A200B6B1A540051299D /* SSADocument.m in Sources */, 1513 1518 3D211A230B6B1A660051299D /* Categories.m in Sources */, 1519 3DB2BB290B6C92F000416863 /* SSARenderCodec.m in Sources */, 1514 1520 ); 1515 1521 runOnlyForDeploymentPostprocessing = 0; trunk/SSADocument.m
r311 r312 473 473 @end 474 474 475 //based on Apple sample code http://developer.apple.com/samplecode/QTKitCreateMovie/listing5.html476 477 static Movie CreateQuicktimeMovieFromTempFile(DataHandler * outDataHandler, OSErr *outErr, NSString **movieName)478 {479 *outErr = -1;480 char *c_tempName = tempnam(NULL,"perian-subtitle-");481 482 // generate a name for our movie file483 NSString *tempName = [NSString stringWithCString:c_tempName484 encoding:[NSString defaultCStringEncoding]];485 if (nil == tempName) goto nostring;486 free(c_tempName);487 488 Handle dataRefH = nil;489 OSType dataRefType;490 491 // create a file data reference for our movie492 *outErr = QTNewDataReferenceFromFullPathCFString((CFStringRef)tempName,493 kQTNativeDefaultPathStyle,494 0,495 &dataRefH,496 &dataRefType);497 if (*outErr != noErr) goto nodataref;498 499 // create a QuickTime movie from our file data reference500 Movie qtMovie = nil;501 CreateMovieStorage (dataRefH,502 dataRefType,503 'TVOD',504 smSystemScript,505 newMovieActive,506 outDataHandler,507 &qtMovie);508 *outErr = GetMoviesError();509 if (*outErr != noErr) goto cantcreatemovstorage;510 511 return qtMovie;512 513 // error handling514 cantcreatemovstorage:515 DisposeHandle(dataRefH);516 nodataref:517 nostring:518 519 return nil;520 }521 522 /*523 We import SSA by creating a temporary movie, adding samples to it, and copying it to the current movie, which can't have samples added to it as it's read-only.524 525 I tried to use an in-memory temporary, but it completely failed to work.526 527 This works except for saving reference movies, which include a dependency on the temporary file. They will break when it's deleted upon restart.528 I don't see any apparent workaround.529 */530 475 ComponentResult LoadSubStationAlphaSubtitles(const FSRef *theDirectory, CFStringRef filename, Movie theMovie, Track *firstSubTrack) 531 476 { 532 477 ComponentResult err = noErr; 533 Track theTrack = NULL , track2 = NULL;534 Media theMedia = NULL , media2 = NULL;478 Track theTrack = NULL; 479 Media theMedia = NULL; 535 480 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 536 481 SSADocument *ssa = [[SSADocument alloc] init]; 537 static UInt8 path[PATH_MAX];538 Handle sampleHndl = NULL, headerHndl=NULL;539 c har *data = NULL; const char *header;482 Handle sampleHndl = NULL, headerHndl=NULL, drefHndl; 483 Ptr initData = NewPtr(0); 484 const char *header; 540 485 int i, packetCount, sampleLen; 541 486 ImageDescriptionHandle textDesc; 542 DataHandler tempStor;543 Movie tempMovie;544 OSErr oErr;545 NSString *movieName;546 487 Rect movieBox; 547 488 static UInt8 path[PATH_MAX]; 489 UInt32 emptyDataRefExtension[2]; 490 548 491 FSRefMakePath(theDirectory, path, PATH_MAX); 549 492 … … 558 501 PtrToHand(header, &headerHndl, sampleLen); 559 502 560 tempMovie = CreateQuicktimeMovieFromTempFile(&tempStor,&oErr,&movieName); 561 562 GetMovieBox(theMovie, &movieBox); 563 564 theTrack = CreatePlaintextSubTrack(tempMovie, textDesc, 100, NULL, 0, kSubFormatSSA, headerHndl, movieBox); 503 drefHndl = NewHandleClear(sizeof(Handle) + 1); 504 505 /* Explanation of next three lines: 506 * The magic 'data' atom, added to an in-memory data handler, allows its data to be saved by value to a reference movie. 507 * It does this by saving the whole thing in the MOV header. 508 * This is imperfectly documented. 509 */ 510 emptyDataRefExtension[0] = EndianU32_NtoB(sizeof(UInt32)*2); 511 emptyDataRefExtension[1] = EndianU32_NtoB(kDataRefExtensionInitializationData); 512 513 PtrAndHand(&emptyDataRefExtension[0], drefHndl, sizeof(emptyDataRefExtension)); 514 515 GetMovieBox(theMovie,&movieBox); 516 theTrack = CreatePlaintextSubTrack(theMovie, textDesc, 100, drefHndl, HandleDataHandlerSubType, 'SSA ', headerHndl, movieBox); 565 517 if (theTrack == NULL) { 566 518 err = GetMoviesError(); 567 519 goto bail; 568 520 } 569 521 570 522 theMedia = GetTrackMedia(theTrack); 571 523 if (theMedia == NULL) { … … 575 527 576 528 BeginMediaEdits(theMedia); 577 529 578 530 for (i = 0; i < packetCount; i++) { 579 531 SSAEvent *p = [ssa movPacket:i]; 580 TimeRecord movieStartTime = { SInt64ToWide(p->begin_time), 100, 0 };581 532 const char *str = [p->line UTF8String]; 582 533 sampleLen = strlen(str); 583 534 584 535 PtrToHand(str,&sampleHndl,sampleLen); 585 536 586 537 err=AddMediaSample(theMedia,sampleHndl,0,sampleLen, p->end_time - p->begin_time,(SampleDescriptionHandle)textDesc, 1, 0, NULL); 587 if (err != noErr) { goto bail;}588 538 if (err != noErr) {NSLog(@"a %d",GetMoviesError()); goto bail;} 539 589 540 DisposeHandle(sampleHndl); 590 541 } 591 542 592 543 EndMediaEdits(theMedia); 593 594 InsertMediaIntoTrack(theTrack,0,0,GetMediaDuration(theMedia),fixed1); 595 if (err != noErr) {goto bail;} 596 597 track2 = CreatePlaintextSubTrack(theMovie, textDesc, 100, NULL, 0, kSubFormatSSA, headerHndl, movieBox); 598 599 media2 = GetTrackMedia(track2); 600 601 BeginMediaEdits(media2); 602 err=InsertTrackSegment(theTrack,track2,0,GetTrackDuration(theTrack),0); 603 EndMediaEdits(media2); 604 605 544 545 InsertMediaIntoTrack(theTrack,0,0,GetMediaDuration(theMedia),fixed1); 546 if (err != noErr) NSLog(@"i %d",GetMoviesError()); 547 606 548 if (*firstSubTrack == NULL) 607 *firstSubTrack = t rack2;549 *firstSubTrack = theTrack; 608 550 else 609 SetTrackAlternate(*firstSubTrack, t rack2);610 611 SetMediaLanguage( media2, GetFilenameLanguage(filename));551 SetTrackAlternate(*firstSubTrack, theTrack); 552 553 SetMediaLanguage(theMedia, GetFilenameLanguage(filename)); 612 554 613 555 bail: 556 557 [ssa release]; 558 [pool release]; 614 559 615 560 if (err) { … … 625 570 626 571 if (headerHndl) DisposeHandle((Handle)headerHndl); 627 CloseMovieStorage(tempStor); 628 DisposeMovieTrack(theTrack); 629 DisposeMovie(tempMovie); 630 //unlink([movieName UTF8String]); 631 632 [ssa release]; 633 [pool release]; 572 DisposeHandle((Handle)drefHndl); 634 573 635 574 return err; trunk/SSATagParsing.m.rl
r310 r312 87 87 BOOL ldirty = NO; 88 88 89 if ([ar count] < 9) {continue;}89 if ([ar count] < 9) continue; 90 90 91 91 re = [[[SSARenderEntity alloc] init] autorelease]; … … 147 147 re->styles[re->style_count-1]->astyle = cur_style;\ 148 148 re->styles[re->style_count-1]->range = cur_range;\ 149 re->styles[re->style_count-1]->outlineblur = cur_be;\ 150 re->styles[re->style_count-1]->color = cur_color;\ 149 151 parsetmp = [NSString stringWithCharacters:skipbegin length:p-skipbegin];\ 150 152 [output appendString:parsetmp]; \
