From c00e7fb89dc6f44b74036256e55e00e9287b67db Mon Sep 17 00:00:00 2001 From: Damien Plisson Date: Sat, 17 Apr 2010 08:33:42 +0000 Subject: Quicktime audio export: force AAC sample rate to be <=48kHz to avoid later codec error + potential quicktime mem leaks fixes AAC Codec does not handle sample rates above 48kHz. --- source/blender/quicktime/apple/qtkit_export.m | 9 ++++++--- source/blender/quicktime/apple/qtkit_import.m | 9 ++++----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'source') diff --git a/source/blender/quicktime/apple/qtkit_export.m b/source/blender/quicktime/apple/qtkit_export.m index cfe86017e3a..35f3629cb61 100644 --- a/source/blender/quicktime/apple/qtkit_export.m +++ b/source/blender/quicktime/apple/qtkit_export.m @@ -275,7 +275,7 @@ static OSStatus AudioConverterInputCallback(AudioConverterRef inAudioConverter, *ioNumberDataPackets = AUDIOOUTPUTBUFFERSIZE / qtexport->audioInputFormat.mBytesPerPacket; if ((qtexport->audioTotalExportedFrames + *ioNumberDataPackets) > qtexport->audioLastFrame) - *ioNumberDataPackets += qtexport->audioLastFrame - qtexport->audioTotalExportedFrames; + *ioNumberDataPackets = (qtexport->audioLastFrame - qtexport->audioTotalExportedFrames) / qtexport->audioInputFormat.mFramesPerPacket; qtexport->audioTotalExportedFrames += *ioNumberDataPackets; @@ -379,7 +379,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R break; } qtexport->audioInputFormat.mBytesPerFrame = qtexport->audioInputFormat.mChannelsPerFrame * qtexport->audioInputFormat.mBitsPerChannel / 8; - qtexport->audioInputFormat.mFramesPerPacket = 1; + qtexport->audioInputFormat.mFramesPerPacket = 1; /*If not ==1, then need to check input callback for "rounding" issues"*/ qtexport->audioInputFormat.mBytesPerPacket = qtexport->audioInputFormat.mBytesPerFrame; qtexport->audioInputFormat.mFormatFlags |= kLinearPCMFormatFlagIsPacked; @@ -399,6 +399,9 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R switch (rd->qtcodecsettings.audiocodecType) { case kAudioFormatMPEG4AAC: qtexport->audioOutputFormat.mFormatFlags = kMPEG4Object_AAC_Main; + /* AAC codec does not handle sample rates above 48kHz, force this limit instead of getting an error afterwards */ + if (qtexport->audioOutputFormat.mSampleRate > 48000) qtexport->audioOutputFormat.mSampleRate = 48000; + break; case kAudioFormatAppleLossless: switch (U.audioformat) { case AUD_FORMAT_S16: @@ -531,7 +534,6 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R [QTMovie exitQTKitOnThread]; } else { [qtexport->movie retain]; - [qtexport->filename retain]; [qtexport->movie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute]; [qtexport->movie setAttribute:@"Made with Blender" forKey:QTMovieCopyrightAttribute]; @@ -736,6 +738,7 @@ void end_qt(void) fileManager = [[NSFileManager alloc] init]; [fileManager removeItemAtPath:qtexport->audioFileName error:&error]; [fileManager removeItemAtPath:qtexport->videoTempFileName error:&error]; + [fileManager release]; } else { /* Flush update of the movie file */ diff --git a/source/blender/quicktime/apple/qtkit_import.m b/source/blender/quicktime/apple/qtkit_import.m index 43c17644681..322f2757419 100644 --- a/source/blender/quicktime/apple/qtkit_import.m +++ b/source/blender/quicktime/apple/qtkit_import.m @@ -198,7 +198,6 @@ static ImBuf * nsImageToiBuf(NSImage *sourceImage, int width, int height) rasterRGB = (uchar*)[blBitmapFormatImageRGB bitmapData]; if (rasterRGB == NULL) { - [bitmapImage release]; [blBitmapFormatImageRGB release]; return NULL; } @@ -220,7 +219,6 @@ static ImBuf * nsImageToiBuf(NSImage *sourceImage, int width, int height) rasterRGBA = (uchar*)[blBitmapFormatImageRGBA bitmapData]; if (rasterRGBA == NULL) { - [bitmapImage release]; [blBitmapFormatImageRGB release]; [blBitmapFormatImageRGBA release]; return NULL; @@ -390,13 +388,14 @@ int imb_is_a_quicktime (char *name) BLI_testextensie(name, ".mp3")) return 0; - image = [NSImage alloc]; - if ([image initWithContentsOfFile:[NSString stringWithUTF8String:name]]) + image = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithUTF8String:name]]; + if (image) { + [image release]; result = true; + } else result = false; - [image release]; [pool drain]; return result; } -- cgit v1.2.3