RE: set kAudioFilePropertyAlbumArtwork: fail
RE: set kAudioFilePropertyAlbumArtwork: fail
- Subject: RE: set kAudioFilePropertyAlbumArtwork: fail
- From: Alex _ <email@hidden>
- Date: Mon, 05 Aug 2013 23:50:11 +0200
- Importance: Normal
Thanks Kyle.
I've try to do as you suggested but unfortunately it didn't fix the problem.
This time I got:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000010
0x00007fff904e2250 in objc_msgSend ()
This is the snippet that actually allows you to replicate the problem.
It doesn't do anything special, just create the M4A audio file and set the cover.
int main(int argc, const char * argv[])
{
@autoreleasepool {
AudioFileID audioID;
AudioStreamBasicDescription outFormat = (AudioStreamBasicDescription){0};
outFormat.mFormatID = kAudioFormatMPEG4AAC;
outFormat.mSampleRate = 44100;
outFormat.mChannelsPerFrame = 2;
AudioStreamBasicDescription inFormat = (AudioStreamBasicDescription) {0};
inFormat.mSampleRate = 44100;
inFormat.mFormatID = kAudioFormatLinearPCM;
inFormat.mChannelsPerFrame = 2;
inFormat.mBytesPerPacket = 8;
inFormat.mFramesPerPacket = 1;
inFormat.mBytesPerFrame = 8;
inFormat.mBitsPerChannel = 32;
inFormat.mFormatFlags = 9;
UInt32 dataSize = sizeof(outFormat);
checkError("AudioFormatGetProperty",
AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
0,
NULL,
&dataSize,
&outFormat));
AudioConverterRef audioConverter;
AudioConverterNew(&inFormat, &outFormat, &audioConverter);
checkError("AudioConvertGetPropertyInfo", AudioConverterGetPropertyInfo(audioConverter,
kAudioConverterCompressionMagicCookie,
&dataSize,
NULL));
char *cookie = malloc(dataSize);
checkError("AudioConvertGetProperty", AudioConverterGetProperty(audioConverter,
kAudioConverterCompressionMagicCookie,
&dataSize,
cookie));
NSURL *url = [NSURL URLWithString:@"/tmp/test.m4p"];
checkError("AudioFileOpenURL",
AudioFileCreateWithURL((CFURLRef)url,
kAudioFileM4AType,
&outFormat,
kAudioFileReadWritePermission,
&audioID));
checkError("AudioFileSetProperty", AudioFileSetProperty(audioID,
kAudioFilePropertyMagicCookieData,
dataSize,
cookie));
NSData *image = [NSData dataWithContentsOfFile:@"/tmp/test.jpg"];
if (image != NULL)
{
checkError("AudioFileSetProperty",
AudioFileSetProperty(audioID,
kAudioFilePropertyAlbumArtwork,
(UInt32)[image length],
[image bytes]));
}
checkError("AudioFileClose",
AudioFileClose(audioID));
free(cookie);
NSLog(@"File closed\n");
}
return 0;
}
Thanks a lot for your help
----------------------------------------
> From: email@hidden
> To: email@hidden; email@hidden
> Subject: Re: set kAudioFilePropertyAlbumArtwork: fail
> Date: Mon, 5 Aug 2013 10:30:56 -0700
>
> On Mon, Aug 5, 2013, at 01:37 AM, Alex _ wrote:
>> Unfortunately, as soon as I try to set the artwork, the
>> AudioFileSetProperty doesn't fail, but AudioFileClose does.
>> Specifically I get:á+[NSConcreteData bytes]: unrecognized selector sent
>> to class
>>
>> á á á á ...
>> á á á ááNSDataá*image = [NSDataádataWithContentsOfFile:@"/tmp/test.jpg"];
>> á á á ááifá(image !=áNULL)
>> á á á á {
>> á á á á á áácheckError("AudioFileSetProperty",
>> áá á á á á á á á á á ááAudioFileSetProperty(audioID,
>> á á á á á á á á á á á á á á á á á á á á á áákAudioFilePropertyAlbumArtwork,
>> á á á á á á á á á á á á á á á á á á á á á á (UInt32)[imageálength],
>> á á á á á á á á á á á á á á á á á á á á á ááCFBridgingRetain(image)));
>
> You're assigning a pointer to the NSData object as a property value, but
> telling AudioFileSetData that you're actually assigning a value of the
> size of the bytes held by that NSData. At some point this corrupts your
> heap, and -data (an instance method) winds up getting sent to
> NSConcreteData (the class).
>
> You want to do:
>
> AudioFileSetProperty(audioID, kAudioFilePropertyAlbumArtwork,
> (UInt32)[image length], [image bytes]);
>
> --Kyle Sluder
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden