| 349 | } |
| 350 | |
| 351 | void MovieWriter::Obj::createCompressionSession() |
| 352 | { |
| 353 | OSStatus err = noErr; |
| 354 | ::ICMEncodedFrameOutputRecord encodedFrameOutputRecord = {0}; |
| 355 | ::ICMCompressionSessionOptionsRef sessionOptions = NULL; |
| 356 | ::ICMMultiPassStorageRef multiPassStorage = 0; |
| 357 | bool attemptMultiPass = mFormat.mEnableMultiPass; |
| 358 | |
| 359 | err = ::ICMCompressionSessionOptionsCreateCopy( NULL, mFormat.mOptions, &sessionOptions ); |
| 360 | if( err ) |
| 361 | goto bail; |
| 362 | |
| 363 | // We need durations when we store frames. |
| 364 | err = ::ICMCompressionSessionOptionsSetDurationsNeeded( sessionOptions, true ); |
| 365 | if( err ) |
| 366 | goto bail; |
| 367 | |
| 368 | // if this codec definitely cannot do multipass, let's disable it |
| 369 | ::CodecInfo cInfo; |
| 370 | ::GetCodecInfo( &cInfo, mFormat.mCodec, 0 ); |
| 371 | |
| 372 | /*if( ! (cInfo.compressFlags & codecInfoDoesMultiPass) ) |
| 373 | attemptMultiPass = false;*/ |
| 374 | |
| 375 | // if we have not enabled multiPass then explicitly disable it |
| 376 | if( ! attemptMultiPass ) { |
| 377 | ::ICMMultiPassStorageRef nullStorage = NULL; |
| 378 | ::ICMCompressionSessionOptionsSetProperty( sessionOptions, kQTPropertyClass_ICMCompressionSessionOptions, kICMCompressionSessionOptionsPropertyID_MultiPassStorage, sizeof(ICMMultiPassStorageRef), &nullStorage ); |
| 379 | mRequestedMultiPass = false; |
| 380 | } |
| 381 | else { |
| 382 | err = enableMultiPassWithTemporaryFile( sessionOptions, &multiPassStorage ); |
| 383 | if( err ) |
| 384 | goto bail; |
| 385 | mRequestedMultiPass = true; |
| 386 | } |
| 387 | |
| 388 | encodedFrameOutputRecord.encodedFrameOutputCallback = encodedFrameOutputCallback; |
| 389 | encodedFrameOutputRecord.encodedFrameOutputRefCon = this; |
| 390 | encodedFrameOutputRecord.frameDataAllocator = NULL; |
| 391 | err = ::ICMCompressionSessionCreate( NULL, mWidth, mHeight, mFormat.mCodec, mFormat.mTimeBase, |
| 392 | sessionOptions, NULL, &encodedFrameOutputRecord, &mCompressionSession ); |
| 393 | if( err ) |
| 394 | goto bail; |
| 395 | |
| 396 | if( mRequestedMultiPass ) { |
| 397 | mDoingMultiPass = ::ICMCompressionSessionSupportsMultiPassEncoding( mCompressionSession, 0, &mMultiPassModeFlags ) != 0; |
| 398 | |
| 399 | if( mDoingMultiPass ) { |
| 400 | fs::path tempPath; |
| 401 | #if defined( CINDER_MSW ) |
| 402 | TCHAR tempFileName[MAX_PATH]; |
| 403 | TCHAR tempPathBuffer[MAX_PATH]; |
| 404 | DWORD retVal = ::GetTempPath( MAX_PATH, tempPathBuffer ); |
| 405 | if( retVal > MAX_PATH || (retVal == 0) ) |
| 406 | goto bail; |
| 407 | |
| 408 | if( ::GetTempFileName( tempPathBuffer, TEXT("multipass"), 0, tempFileName ) == 0 ) |
nothing calls this directly
no test coverage detected