Changeset 4230 for pjproject


Ignore:
Timestamp:
Aug 14, 2012 8:39:59 AM (12 years ago)
Author:
bennylp
Message:

Fixed #1570: Update BlackBerry? BB10 audio device to the latest SDK R6

File:
1 edited

Legend:

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

    r4151 r4230  
    3434#if defined(PJMEDIA_AUDIO_DEV_HAS_BB10) && PJMEDIA_AUDIO_DEV_HAS_BB10 != 0 
    3535 
     36#ifndef PJ_BBSDK_VER 
     37    /* Format: 0xMMNNRR:  MM: major, NN: minor, RR: revision */ 
     38#   define PJ_BBSDK_VER 0x100006 
     39#endif 
     40 
    3641#include <sys/time.h> 
    3742#include <sys/types.h> 
     
    4146#include <errno.h> 
    4247#include <sys/asoundlib.h> 
     48#if PJ_BBSDK_VER >= 0x100006 
     49#include <audio/audio_manager_routing.h> 
     50#endif 
    4351 
    4452 
     
    116124    /* Playback */ 
    117125    snd_pcm_t           *pb_pcm; 
    118     snd_mixer_t         *pb_mixer; 
    119126    unsigned long        pb_frames;     /* samples_per_frame            */ 
    120127    pjmedia_aud_play_cb  pb_cb; 
     
    125132    /* Capture */ 
    126133    snd_pcm_t           *ca_pcm; 
    127     snd_mixer_t         *ca_mixer; 
    128134    unsigned long        ca_frames;     /* samples_per_frame            */ 
    129135    pjmedia_aud_rec_cb   ca_cb; 
     
    163169    int card = -1; 
    164170    int dev = 0; 
     171    unsigned int handle; 
    165172    snd_pcm_t *pcm_handle; 
    166173 
     
    172179    TRACE_((THIS_FILE, "bb10_add_dev Enter")); 
    173180 
     181#if PJ_BBSDK_VER >= 0x100006 
     182    if ((pb_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
     183                                                     &pcm_handle, 
     184                                                     &handle, 
     185                                                     "/dev/snd/voicep", 
     186                                                     SND_PCM_OPEN_PLAYBACK)) 
     187                                                     >= 0) 
     188#else 
     189    PJ_UNUSED_ARG(handle); 
    174190    if ((pb_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev, 
    175191                                             SND_PCM_OPEN_PLAYBACK)) >= 0) 
     192#endif 
    176193    { 
    177194        TRACE_((THIS_FILE, "Try to open the device for playback - success")); 
     
    181198    } 
    182199 
     200#if PJ_BBSDK_VER >= 0x100006 
     201    if ((ca_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
     202                                                     &pcm_handle, 
     203                                                     &handle, 
     204                                                     "/dev/snd/voicec", 
     205                                                     SND_PCM_OPEN_CAPTURE)) 
     206                                                     >= 0) 
     207#else 
    183208    if ((ca_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev, 
    184209                                             SND_PCM_OPEN_CAPTURE)) >=0) 
     210#endif 
    185211    { 
    186212        TRACE_((THIS_FILE, "Try to open the device for capture - success")); 
     
    240266{ 
    241267    pj_status_t status; 
    242      
     268 
    243269    status = bb10_factory_refresh(f); 
    244270    if (status != PJ_SUCCESS) 
     
    315341    info->caps = PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | 
    316342                 PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY; 
    317      
     343 
    318344    return PJ_SUCCESS; 
    319345} 
     
    359385                       " spf = %d", param->clock_rate, param->flags, 
    360386                       param->samples_per_frame)); 
    361      
     387 
    362388    return PJ_SUCCESS; 
    363389} 
     
    372398} 
    373399 
    374 static void close_play_mixer(struct bb10_stream *stream) 
    375 { 
    376     if (stream != NULL && stream->pb_mixer != NULL) { 
    377         snd_mixer_close(stream->pb_mixer); 
    378         stream->pb_mixer = NULL; 
    379     } 
    380 } 
    381  
    382400static void flush_play(struct bb10_stream *stream) 
    383401{ 
     
    392410        snd_pcm_close(stream->ca_pcm); 
    393411        stream->ca_pcm = NULL; 
    394     } 
    395 } 
    396  
    397 static void close_capture_mixer(struct bb10_stream *stream) 
    398 { 
    399     if (stream != NULL && stream->ca_mixer != NULL) { 
    400         snd_mixer_close(stream->ca_mixer); 
    401         stream->ca_mixer = NULL; 
    402412    } 
    403413} 
     
    436446                                         SND_PCM_CHANNEL_PLAYBACK)) < 0) 
    437447    { 
    438         close_play_mixer(stream); 
    439448        close_play_pcm(stream); 
    440449        TRACE_((THIS_FILE, "pb_thread_func failed prepare = %d", result)); 
     
    461470        /* Write 640 to play unit */ 
    462471        result = snd_pcm_plugin_write(stream->pb_pcm,buf,size); 
    463         if (result != size) { 
     472        if (result != size || result < 0) { 
     473            snd_pcm_channel_status_t status; 
     474            if (snd_pcm_plugin_status (stream->pb_pcm, &status) < 0) { 
     475                PJ_LOG(4,(THIS_FILE, 
     476                          "underrun: playback channel status error")); 
     477                continue; 
     478            } 
     479 
     480            if (status.status == SND_PCM_STATUS_READY || 
     481                status.status == SND_PCM_STATUS_UNDERRUN) 
     482            { 
     483                if (snd_pcm_plugin_prepare (stream->pb_pcm, 
     484                                            SND_PCM_CHANNEL_PLAYBACK) < 0) 
     485                { 
     486                    PJ_LOG(4,(THIS_FILE, 
     487                              "underrun: playback channel prepare error")); 
     488                    continue; 
     489                } 
     490            } 
     491 
    464492            TRACE_((THIS_FILE, "pb_thread_func failed write = %d", result)); 
    465493        } 
     
    469497 
    470498    flush_play(stream); 
    471     close_play_mixer(stream); 
    472499    close_play_pcm(stream); 
    473500    TRACE_((THIS_FILE, "pb_thread_func: Stopped")); 
    474      
     501 
    475502    return PJ_SUCCESS; 
    476503} 
     
    514541                                          SND_PCM_CHANNEL_CAPTURE)) < 0) 
    515542    { 
    516         close_capture_mixer(stream); 
    517543        close_capture_pcm(stream); 
    518544        TRACE_((THIS_FILE, "ca_thread_func failed prepare = %d", result)); 
     
    524550 
    525551        pj_bzero (buf, size); 
    526          
     552 
    527553        result = snd_pcm_plugin_read(stream->ca_pcm, buf,size); 
    528         if (result == -EPIPE) { 
    529             PJ_LOG (4,(THIS_FILE, "ca_thread_func: overrun!")); 
    530             snd_pcm_plugin_prepare (stream->ca_pcm, SND_PCM_CHANNEL_CAPTURE); 
    531             continue; 
    532         } else if (result < 0) { 
    533             PJ_LOG (4,(THIS_FILE, "ca_thread_func: error reading data!")); 
     554        if(result <0 || result != size) { 
     555            snd_pcm_channel_status_t status; 
     556            if (snd_pcm_plugin_status (stream->ca_pcm, &status) < 0) { 
     557                PJ_LOG (4,(THIS_FILE, "overrun: capture channel status " 
     558                                      "error")); 
     559                continue; 
     560            } 
     561 
     562            if (status.status == SND_PCM_STATUS_READY || 
     563                status.status == SND_PCM_STATUS_OVERRUN) { 
     564                if (snd_pcm_plugin_prepare (stream->ca_pcm, 
     565                                            SND_PCM_CHANNEL_CAPTURE) < 0) 
     566                { 
     567                    PJ_LOG (4,(THIS_FILE, "overrun: capture channel prepare  " 
     568                                          "error")); 
     569                    continue; 
     570                } 
     571            } 
    534572        } 
    535573 
     
    551589 
    552590    flush_capture(stream); 
    553     close_capture_mixer(stream); 
    554591    close_capture_pcm(stream); 
    555592    TRACE_((THIS_FILE, "ca_thread_func: Stopped")); 
     
    571608    unsigned int rate; 
    572609    unsigned long tmp_buf_size; 
     610    unsigned int handle; 
    573611 
    574612    if (param->play_id < 0 || param->play_id >= stream->af->dev_cnt) { 
     
    576614    } 
    577615 
     616#if PJ_BBSDK_VER >= 0x100006 
     617    if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
     618                                               &stream->pb_pcm, &handle, 
     619                                               "/dev/snd/voicep", 
     620                                               SND_PCM_OPEN_PLAYBACK)) < 0) 
     621    { 
     622        TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret)); 
     623        return PJMEDIA_EAUD_SYSERR; 
     624    } 
     625 
     626#else 
    578627    if ((ret = snd_pcm_open_preferred (&stream->pb_pcm, &card, &dev, 
    579628                                       SND_PCM_OPEN_PLAYBACK)) < 0) 
     
    582631        return PJMEDIA_EAUD_SYSERR; 
    583632    } 
     633#endif 
    584634 
    585635    /* TODO PJ_ZERO */ 
     
    623673    setup.channel = SND_PCM_CHANNEL_PLAYBACK; 
    624674    setup.mixer_gid = &group.gid; 
    625      
     675 
    626676    if ((ret = snd_pcm_plugin_setup (stream->pb_pcm, &setup)) < 0) { 
    627677        TRACE_((THIS_FILE, "snd_pcm_plugin_setup ret = %d", ret)); 
     
    632682        return PJMEDIA_EAUD_SYSERR; 
    633683    } 
    634      
    635     if ((ret = snd_mixer_open (&stream->pb_mixer, card, 
    636                                setup.mixer_device)) < 0) 
    637     { 
    638         TRACE_((THIS_FILE, "snd_mixer_open ret = %d", ret)); 
    639         return PJMEDIA_EAUD_SYSERR; 
    640     } 
    641  
    642684 
    643685    rate = param->clock_rate; 
     
    676718    snd_pcm_channel_params_t pp; 
    677719    snd_pcm_channel_setup_t setup; 
     720    unsigned int handle; 
    678721 
    679722    if (param->rec_id < 0 || param->rec_id >= stream->af->dev_cnt) 
    680723        return PJMEDIA_EAUD_INVDEV; 
    681724 
     725#if PJ_BBSDK_VER >= 0x100006 
     726    if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 
     727                                               &stream->ca_pcm, 
     728                                               &handle, 
     729                                               "/dev/snd/voicec", 
     730                                               SND_PCM_OPEN_CAPTURE)) < 0) 
     731    { 
     732        TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret)); 
     733        return PJMEDIA_EAUD_SYSERR; 
     734    } 
     735#else 
    682736    /* BB10 Audio init here (not prepare) */ 
     737    PJ_UNUSED_ARG(handle); 
    683738    if ((ret = snd_pcm_open_preferred (&stream->ca_pcm, &card, &dev, 
    684739                                       SND_PCM_OPEN_CAPTURE)) < 0) 
     
    687742        return PJMEDIA_EAUD_SYSERR; 
    688743    } 
     744#endif 
    689745 
    690746    /* sample reads the capabilities of the capture */ 
     
    741797    } 
    742798 
    743     if ((ret = snd_mixer_open (&stream->ca_mixer, card, 
    744                                setup.mixer_device)) < 0) 
    745     { 
    746         TRACE_((THIS_FILE,"snd_mixer_open ret = %d",ret)); 
    747         return PJMEDIA_EAUD_SYSERR; 
    748     } 
    749  
    750799    /* frag_size should be 160 */ 
    751800    frame_size = setup.buf.block.frag_size; 
     
    821870        if (status != PJ_SUCCESS) { 
    822871            if (param->dir & PJMEDIA_DIR_PLAYBACK) { 
    823                 close_play_mixer(stream); 
    824872                close_play_pcm(stream); 
    825873            } 
     
    9531001{ 
    9541002    struct bb10_stream *stream = (struct bb10_stream*)s; 
    955      
     1003 
    9561004    TRACE_((THIS_FILE,"bb10_stream_destroy()")); 
    9571005 
Note: See TracChangeset for help on using the changeset viewer.