RE: set kAudioFilePropertyAlbumArtwork: fail
RE: set kAudioFilePropertyAlbumArtwork: fail
- Subject: RE: set kAudioFilePropertyAlbumArtwork: fail
- From: Alex _ <email@hidden>
- Date: Tue, 06 Aug 2013 10:26:50 +0200
- Importance: Normal
Hey guys,
I got it working. I'm feeling so stupid!!!
This is the working piece of code:
...
NSData *image = [NSData dataWithContentsOfFile:@"/tmp/test.jpg"];
if (image != NULL)
{
checkError("AudioFileSetProperty",
AudioFileSetProperty(audioID,
kAudioFilePropertyAlbumArtwork,
sizeof(image),
&image));
}
...
OSStatus AudioFileSetProperty (
AudioFileID inAudioFile,
AudioFilePropertyID inPropertyID,
UInt32 inDataSize,
const void *inPropertyData
);
AudioFileSetPrototype require inDataSize which is the size of the value you're passing in inPropertyData.
inPropertyData in this case is an object, thus you've to pass it's address, even though you can see the "image" as an address itself and could mislead.
Thereby the size of the obj has to be set in inDataSize.
Moreover, if you carefully read the Documentation regarding kAudioFilePropertyAlbumArtwork says that the returned object (in case of AudioFileGetProperty) is CFDataRef.
This implies that you need to pass an NSData object (toll-free bridged) and not a pointer to the buffer and its length.
Thanks a lot guys
----------------------------------------
> From: email@hidden
> Subject: Re: set kAudioFilePropertyAlbumArtwork: fail
> Date: Tue, 6 Aug 2013 00:12:06 +0200
> To: email@hidden; email@hidden
>
> yeah, thanks guys ... i am gettin' that @autoreleasepool { also, and
> very often .. ....
>
> Am 05.08.2013 um 23:50 schrieb Alex _:
>
>> 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:
>> email@hidden
>>
>> This email sent to email@hidden
>
_______________________________________________
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