• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Crash on AudioRouteKey Compare
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash on AudioRouteKey Compare


  • Subject: Re: Crash on AudioRouteKey Compare
  • From: Kevin Dixon <email@hidden>
  • Date: Wed, 14 Aug 2013 11:32:14 -0700

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
 _______________________________________________
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


  • Follow-Ups:
    • Re: Crash on AudioRouteKey Compare
      • From: Alexandru Gologan <email@hidden>
References: 
 >Crash on AudioRouteKey Compare (From: Alexandru Gologan <email@hidden>)

  • Prev by Date: handlepitchwheel in auinstrument
  • Next by Date: handlepitchwheel in auinstrument
  • Previous by thread: Crash on AudioRouteKey Compare
  • Next by thread: Re: Crash on AudioRouteKey Compare
  • Index(es):
    • Date
    • Thread