Changeset 4316 for pjproject/trunk


Ignore:
Timestamp:
01/14/13 04:08:20 (16 months ago)
Author:
bennylp
Message:

Re #1570: Update BB10 audio driver to the latest changes in SDK:

  1. Disable MMAP on play and record
  2. Use type VIDEO_CHAT as opposed to VOICE (recommended by RIM audio team)
  3. Free up audio_manager handles properly (RIM audio team code review)
  4. Set the play to headset because VIDEO_CHAT defaults to speaker (recommended RIM audio team)
  5. Removed the conditional compile for the old SDK version as nothing that’s not built with the current SDK will run on BB10

Thank you Bob Cripps for the patch!

File:
1 edited

Legend:

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

    r4230 r4316  
    124124    /* Playback */ 
    125125    snd_pcm_t           *pb_pcm; 
     126    unsigned int pb_audio_manager_handle; 
    126127    unsigned long        pb_frames;     /* samples_per_frame            */ 
    127128    pjmedia_aud_play_cb  pb_cb; 
     
    132133    /* Capture */ 
    133134    snd_pcm_t           *ca_pcm; 
     135    unsigned int ca_audio_manager_handle; 
    134136    unsigned long        ca_frames;     /* samples_per_frame            */ 
    135137    pjmedia_aud_rec_cb   ca_cb; 
     
    179181    TRACE_((THIS_FILE, "bb10_add_dev Enter")); 
    180182 
    181 #if PJ_BBSDK_VER >= 0x100006 
    182     if ((pb_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
     183    if ((pb_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VIDEO_CHAT, 
    183184                                                     &pcm_handle, 
    184185                                                     &handle, 
     
    186187                                                     SND_PCM_OPEN_PLAYBACK)) 
    187188                                                     >= 0) 
    188 #else 
    189     PJ_UNUSED_ARG(handle); 
    190     if ((pb_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev, 
    191                                              SND_PCM_OPEN_PLAYBACK)) >= 0) 
    192 #endif 
    193189    { 
    194         TRACE_((THIS_FILE, "Try to open the device for playback - success")); 
    195         snd_pcm_close (pcm_handle); 
     190        if ((pb_result = snd_pcm_plugin_set_disable (pcm_handle, PLUGIN_DISABLE_MMAP)) < 0) { 
     191            TRACE_((THIS_FILE, "snd_pcm_plugin_set_disable ret = %d", pb_result)); 
     192        }else{ 
     193            TRACE_((THIS_FILE, "Try to open the device for playback - success")); 
     194        } 
     195            snd_pcm_close (pcm_handle); 
     196            audio_manager_free_handle(handle); 
    196197    } else { 
    197198        TRACE_((THIS_FILE, "Try to open the device for playback - failure")); 
    198199    } 
    199200 
    200 #if PJ_BBSDK_VER >= 0x100006 
    201     if ((ca_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
     201    if ((ca_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VIDEO_CHAT, 
    202202                                                     &pcm_handle, 
    203203                                                     &handle, 
     
    205205                                                     SND_PCM_OPEN_CAPTURE)) 
    206206                                                     >= 0) 
    207 #else 
    208     if ((ca_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev, 
    209                                              SND_PCM_OPEN_CAPTURE)) >=0) 
    210 #endif 
    211207    { 
    212         TRACE_((THIS_FILE, "Try to open the device for capture - success")); 
     208        if ((ca_result = snd_pcm_plugin_set_disable (pcm_handle, PLUGIN_DISABLE_MMAP)) < 0) { 
     209            TRACE_((THIS_FILE, "snd_pcm_plugin_set_disable ret = %d", ca_result)); 
     210        }else{ 
     211            TRACE_((THIS_FILE, "Try to open the device for capture - success"));         
     212        } 
    213213        snd_pcm_close (pcm_handle); 
     214            audio_manager_free_handle(handle); 
     215 
    214216    } else { 
    215217        TRACE_((THIS_FILE, "Try to open the device for capture - failure")); 
     
    395397        snd_pcm_close(stream->pb_pcm); 
    396398        stream->pb_pcm = NULL; 
     399        if(stream->pb_audio_manager_handle != 0){ 
     400            audio_manager_free_handle(stream->pb_audio_manager_handle); 
     401            stream->pb_audio_manager_handle = 0; 
     402        } 
    397403    } 
    398404} 
     
    410416        snd_pcm_close(stream->ca_pcm); 
    411417        stream->ca_pcm = NULL; 
     418        if(stream->ca_audio_manager_handle != 0){ 
     419            audio_manager_free_handle(stream->ca_audio_manager_handle); 
     420            stream->ca_audio_manager_handle = 0; 
     421        } 
    412422    } 
    413423} 
     
    608618    unsigned int rate; 
    609619    unsigned long tmp_buf_size; 
    610     unsigned int handle; 
    611620 
    612621    if (param->play_id < 0 || param->play_id >= stream->af->dev_cnt) { 
     
    614623    } 
    615624 
    616 #if PJ_BBSDK_VER >= 0x100006 
    617     if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
    618                                                &stream->pb_pcm, &handle, 
     625    if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VIDEO_CHAT, 
     626                                               &stream->pb_pcm, &stream->pb_audio_manager_handle, 
    619627                                               "/dev/snd/voicep", 
    620628                                               SND_PCM_OPEN_PLAYBACK)) < 0) 
     
    623631        return PJMEDIA_EAUD_SYSERR; 
    624632    } 
    625  
    626 #else 
    627     if ((ret = snd_pcm_open_preferred (&stream->pb_pcm, &card, &dev, 
    628                                        SND_PCM_OPEN_PLAYBACK)) < 0) 
    629     { 
    630         TRACE_((THIS_FILE, "snd_pcm_open_preferred ret = %d", ret)); 
     633    ret = audio_manager_set_handle_type(stream->pb_audio_manager_handle, AUDIO_TYPE_VIDEO_CHAT, AUDIO_DEVICE_HANDSET , AUDIO_DEVICE_HANDSET); 
     634    if (ret==0) { 
     635          ret = audio_manager_set_handle_routing_conditions(stream->pb_audio_manager_handle, SETTINGS_RESET_ON_DEVICE_CONNECTION); 
     636          if(ret != 0){ 
     637              TRACE_((THIS_FILE, "audio_manager_set_handle_routing_conditions ret = %d", ret)); 
     638              return PJMEDIA_EAUD_SYSERR; 
     639          } 
     640    }else{ 
     641        TRACE_((THIS_FILE, "audio_manager_set_handle_type ret = %d", ret)); 
    631642        return PJMEDIA_EAUD_SYSERR; 
    632643    } 
    633 #endif 
    634  
     644 
     645    if ((ret = snd_pcm_plugin_set_disable (stream->pb_pcm, PLUGIN_DISABLE_MMAP)) < 0) { 
     646        TRACE_((THIS_FILE, "snd_pcm_plugin_set_disable ret = %d", ret)); 
     647        return PJMEDIA_EAUD_SYSERR; 
     648    } 
    635649    /* TODO PJ_ZERO */ 
    636650    memset (&pi, 0, sizeof (pi)); 
     
    718732    snd_pcm_channel_params_t pp; 
    719733    snd_pcm_channel_setup_t setup; 
    720     unsigned int handle; 
    721734 
    722735    if (param->rec_id < 0 || param->rec_id >= stream->af->dev_cnt) 
    723736        return PJMEDIA_EAUD_INVDEV; 
    724737 
    725 #if PJ_BBSDK_VER >= 0x100006 
    726     if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
     738    if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VIDEO_CHAT, 
    727739                                               &stream->ca_pcm, 
    728                                                &handle, 
     740                                               &stream->ca_audio_manager_handle, 
    729741                                               "/dev/snd/voicec", 
    730742                                               SND_PCM_OPEN_CAPTURE)) < 0) 
     
    733745        return PJMEDIA_EAUD_SYSERR; 
    734746    } 
    735 #else 
    736     /* BB10 Audio init here (not prepare) */ 
    737     PJ_UNUSED_ARG(handle); 
    738     if ((ret = snd_pcm_open_preferred (&stream->ca_pcm, &card, &dev, 
    739                                        SND_PCM_OPEN_CAPTURE)) < 0) 
    740     { 
    741         TRACE_((THIS_FILE, "snd_pcm_open_preferred ret = %d", ret)); 
     747    if ((ret = snd_pcm_plugin_set_disable (stream->ca_pcm, PLUGIN_DISABLE_MMAP)) < 0) { 
     748        TRACE_(("snd_pcm_plugin_set_disable failed: %d",ret)); 
    742749        return PJMEDIA_EAUD_SYSERR; 
    743750    } 
    744 #endif 
    745751 
    746752    /* sample reads the capabilities of the capture */ 
Note: See TracChangeset for help on using the changeset viewer.