That's what I was thinking of doing but I just wanted to know when and why the other code would crash.
Regards, Alexandru
On August 14, 2013 at 9:32:15 PM, Kevin Dixon (email@hidden) wrote: I always use the method CFDictionaryGetValueIfPresent. If it returns
non-true, then you must not dereference the output (e.g. it will be
NULL)
example:
CFDictionaryRef routes;
UInt32 size = sizeof(routes);
OSStatus result =
AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription,
&size, &routes);
if(result == kAudioSessionNoError)
{
CFArrayRef outputs;
if(CFDictionaryGetValueIfPresent(routes,
kAudioSession_AudioRouteKey_Outputs, (const void**)&outputs))
{
for(int i = 0; i < CFArrayGetCount(outputs); i++)
{
CFDictionaryRef item = CFArrayGetValueAtIndex(outputs, i);
if(item != NULL)
{
CFStringRef itemName;
if(CFDictionaryGetValueIfPresent(item,
kAudioSession_AudioRouteKey_Type, (const void**)&itemName))
{
// compare strings to the
kAudioSessionOutputRoute_Headphones
}
}
}
}
}
Hope that helps
-Kevin
On Wed, Aug 14, 2013 at 6:58 AM, Alexandru Gologan
<email@hidden> wrote:
> Hi,
>
> I'm seeing a crash that I have no reproduction steps for and I'm wandering
> if I'm missing something in code.
> I want to check if headphones have been disconnected so I add a listener to
> audio route change.
>
> AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange,
> sessionPropertyListener, (__bridge void *)(self))
>
> And than in the session property listener I check if I had headphones
> connected when kAudioSessionRouteChangeReason_OldDeviceUnavailable like so:
>
> CFDictionaryRef previousRouteDescription = CFDictionaryGetValue(dict,
> kAudioSession_AudioRouteChangeKey_PreviousRouteDescription);
>
> CFArrayRef outputs = CFDictionaryGetValue(previousRouteDescription,
> kAudioSession_AudioRouteKey_Outputs);
>
> CFIndex count = CFArrayGetCount(outputs);
>
> for (int i = 0; i < count; ++i) {
>
> CFDictionaryRef outputDesc = CFArrayGetValueAtIndex(outputs, i);
>
> CFStringRef outputRoute = CFDictionaryGetValue(outputDesc,
> kAudioSession_AudioRouteKey_Type);
>
> if (kCFCompareEqualTo == CFStringCompare(outputRoute,
> kAudioSessionOutputRoute_Headphones, 0)) {
>
> hadHeadphones = YES;
>
> }
>
> }
>
>
>
>
> The crash I'm seeing is on CFStringCompare and it crashes with
> EXC_BAD_ACCESS and code: KERN_INVALID_ADDRESS at 0x0
> That would mean that in some scenarios the outputRoute is NULL. I can do a
> proper check to be certain I don't run in any further issues but I'd like to
> understand when the error might happen in the code I wrote.
>
> Regards,
> Alexandru
>
> _______________________________________________
> 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
|