Changeset 3454 for pjproject


Ignore:
Timestamp:
Mar 16, 2011 5:44:14 AM (14 years ago)
Author:
ming
Message:

Re #1175 (Misc): coreaudio fixes:

  • Setting audio session category is now during stream creation instead of in the factory initialization.
  • Reset the audio session category after an interruption.
  • By default, audio route change property listener is disabled as it is no longer required.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c

    r3438 r3454  
    3737 
    3838    #define AudioDeviceID unsigned 
     39 
     40    /** 
     41     * As in iOS SDK 4 or later, audio route change property listener is 
     42     * no longer necessary. Just make surethat your application can receive 
     43     * remote control events by adding the code: 
     44     *     [[UIApplication sharedApplication]  
     45     *      beginReceivingRemoteControlEvents]; 
     46     * Otherwise audio route change (such as headset plug/unplug) will not be 
     47     * processed while your application is in the background mode. 
     48     */ 
     49    #define USE_AUDIO_ROUTE_CHANGE_PROP_LISTENER 0 
     50 
    3951#endif 
    4052 
     
    224236    unsigned i; 
    225237    OSStatus ostatus; 
    226     UInt32 audioCategory; 
    227238#endif 
    228239 
     
    297308    } 
    298309 
    299     /* We want to be able to open playback and recording streams */ 
    300     audioCategory = kAudioSessionCategory_PlayAndRecord; 
    301     ostatus = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, 
    302                                       sizeof(audioCategory), 
    303                                       &audioCategory); 
    304     if (ostatus != kAudioSessionNoError) { 
    305         PJ_LOG(4, (THIS_FILE, 
    306                    "Warning: cannot set the audio session category (%i)", 
    307                    ostatus)); 
    308     } 
    309  
    310     /* Listen for audio routing change notifications */ 
     310    /* Listen for audio routing change notifications. */ 
     311#if USE_AUDIO_ROUTE_CHANGE_PROP_LISTENER != 0 
    311312    ostatus = AudioSessionAddPropertyListener( 
    312313                  kAudioSessionProperty_AudioRouteChange, 
     
    317318                   "notifications (%i)", ostatus)); 
    318319    } 
    319      
     320#endif 
     321 
    320322    cf_instance = cf; 
    321323#endif 
     
    337339 
    338340#if !COREAUDIO_MAC 
     341#if USE_AUDIO_ROUTE_CHANGE_PROP_LISTENER != 0 
    339342    AudioSessionRemovePropertyListenerWithUserData( 
    340343        kAudioSessionProperty_AudioRouteChange, propListener, cf); 
     344#endif 
    341345#endif 
    342346     
     
    10891093            continue; 
    10901094 
    1091         /* This does not seem necessary anymore. Just make sure  
    1092          * that your application can receive remote control 
    1093          * events by adding the code: 
    1094          *     [[UIApplication sharedApplication]  
    1095          *      beginReceivingRemoteControlEvents]; 
    1096          * Otherwise audio route change (such as headset plug/unplug) 
    1097          * will not be processed while your application is in the  
    1098          * background mode. 
    1099          */ 
    11001095        /* 
    11011096        status = ca_stream_stop((pjmedia_aud_stream *)it->stream); 
     
    11311126            it->stream->interrupted == PJ_TRUE) 
    11321127        { 
     1128            UInt32 audioCategory; 
     1129            OSStatus ostatus; 
     1130 
    11331131            /* Make sure that your application can receive remote control 
    11341132             * events by adding the code: 
     
    11381136             * application is in the background mode. 
    11391137             */ 
     1138            /* Make sure we set the correct audio category before restarting */ 
     1139            audioCategory = kAudioSessionCategory_PlayAndRecord; 
     1140            ostatus = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, 
     1141                                              sizeof(audioCategory), 
     1142                                              &audioCategory); 
     1143            if (ostatus != kAudioSessionNoError) { 
     1144                PJ_LOG(4, (THIS_FILE, 
     1145                           "Warning: cannot set the audio session category (%i)", 
     1146                           ostatus)); 
     1147            } 
     1148             
     1149            /* Restart the stream */ 
    11401150            status = ca_stream_start((pjmedia_aud_stream*)it->stream); 
    11411151            if (status != PJ_SUCCESS) { 
     
    12021212{ 
    12031213    OSStatus ostatus; 
    1204  
     1214#if !COREAUDIO_MAC 
     1215    UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord; 
     1216    /* We want to be able to open playback and recording streams */ 
     1217    ostatus = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, 
     1218                                      sizeof(audioCategory), 
     1219                                      &audioCategory); 
     1220    if (ostatus != kAudioSessionNoError) { 
     1221        PJ_LOG(4, (THIS_FILE, 
     1222                   "Warning: cannot set the audio session category (%i)", 
     1223                   ostatus)); 
     1224    }     
     1225#endif 
     1226     
    12051227    /* Create an audio unit to interface with the device */ 
    12061228    ostatus = AudioComponentInstanceNew(io_comp, io_unit); 
     
    14341456        strm->audio_buf->mBuffers[0].mNumberChannels = 
    14351457                strm->streamFormat.mChannelsPerFrame; 
     1458         
    14361459#endif 
    14371460 
Note: See TracChangeset for help on using the changeset viewer.