Index: /pjproject/trunk/pjmedia/src/pjmedia-audiodev/bb10_dev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-audiodev/bb10_dev.c	(revision 4229)
+++ /pjproject/trunk/pjmedia/src/pjmedia-audiodev/bb10_dev.c	(revision 4230)
@@ -34,4 +34,9 @@
 #if defined(PJMEDIA_AUDIO_DEV_HAS_BB10) && PJMEDIA_AUDIO_DEV_HAS_BB10 != 0
 
+#ifndef PJ_BBSDK_VER
+    /* Format: 0xMMNNRR:  MM: major, NN: minor, RR: revision */
+#   define PJ_BBSDK_VER	0x100006
+#endif
+
 #include <sys/time.h>
 #include <sys/types.h>
@@ -41,4 +46,7 @@
 #include <errno.h>
 #include <sys/asoundlib.h>
+#if PJ_BBSDK_VER >= 0x100006
+#include <audio/audio_manager_routing.h>
+#endif
 
 
@@ -116,5 +124,4 @@
     /* Playback */
     snd_pcm_t		*pb_pcm;
-    snd_mixer_t         *pb_mixer;
     unsigned long        pb_frames; 	/* samples_per_frame		*/
     pjmedia_aud_play_cb  pb_cb;
@@ -125,5 +132,4 @@
     /* Capture */
     snd_pcm_t		*ca_pcm;
-    snd_mixer_t         *ca_mixer;
     unsigned long        ca_frames; 	/* samples_per_frame		*/
     pjmedia_aud_rec_cb   ca_cb;
@@ -163,4 +169,5 @@
     int card = -1;
     int dev = 0;
+    unsigned int handle;
     snd_pcm_t *pcm_handle;
 
@@ -172,6 +179,16 @@
     TRACE_((THIS_FILE, "bb10_add_dev Enter"));
 
+#if PJ_BBSDK_VER >= 0x100006
+    if ((pb_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE,
+                                                     &pcm_handle,
+                                                     &handle,
+                                                     "/dev/snd/voicep",
+                                                     SND_PCM_OPEN_PLAYBACK))
+                                                     >= 0)
+#else
+    PJ_UNUSED_ARG(handle);
     if ((pb_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev,
                                              SND_PCM_OPEN_PLAYBACK)) >= 0)
+#endif
     {
         TRACE_((THIS_FILE, "Try to open the device for playback - success"));
@@ -181,6 +198,15 @@
     }
 
+#if PJ_BBSDK_VER >= 0x100006
+    if ((ca_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE,
+                                                     &pcm_handle,
+                                                     &handle,
+                                                     "/dev/snd/voicec",
+                                                     SND_PCM_OPEN_CAPTURE))
+                                                     >= 0)
+#else
     if ((ca_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev,
                                              SND_PCM_OPEN_CAPTURE)) >=0)
+#endif
     {
         TRACE_((THIS_FILE, "Try to open the device for capture - success"));
@@ -240,5 +266,5 @@
 {
     pj_status_t status;
-    
+
     status = bb10_factory_refresh(f);
     if (status != PJ_SUCCESS)
@@ -315,5 +341,5 @@
     info->caps = PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY |
                  PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY;
-    
+
     return PJ_SUCCESS;
 }
@@ -359,5 +385,5 @@
                        " spf = %d", param->clock_rate, param->flags,
                        param->samples_per_frame));
-    
+
     return PJ_SUCCESS;
 }
@@ -372,12 +398,4 @@
 }
 
-static void close_play_mixer(struct bb10_stream *stream)
-{
-    if (stream != NULL && stream->pb_mixer != NULL) {
-        snd_mixer_close(stream->pb_mixer);
-        stream->pb_mixer = NULL;
-    }
-}
-
 static void flush_play(struct bb10_stream *stream)
 {
@@ -392,12 +410,4 @@
         snd_pcm_close(stream->ca_pcm);
         stream->ca_pcm = NULL;
-    }
-}
-
-static void close_capture_mixer(struct bb10_stream *stream)
-{
-    if (stream != NULL && stream->ca_mixer != NULL) {
-        snd_mixer_close(stream->ca_mixer);
-        stream->ca_mixer = NULL;
     }
 }
@@ -436,5 +446,4 @@
                                          SND_PCM_CHANNEL_PLAYBACK)) < 0)
     {
-        close_play_mixer(stream);
         close_play_pcm(stream);
         TRACE_((THIS_FILE, "pb_thread_func failed prepare = %d", result));
@@ -461,5 +470,24 @@
         /* Write 640 to play unit */
         result = snd_pcm_plugin_write(stream->pb_pcm,buf,size);
-        if (result != size) {
+        if (result != size || result < 0) {
+            snd_pcm_channel_status_t status;
+            if (snd_pcm_plugin_status (stream->pb_pcm, &status) < 0) {
+                PJ_LOG(4,(THIS_FILE,
+                	  "underrun: playback channel status error"));
+                continue;
+            }
+
+            if (status.status == SND_PCM_STATUS_READY ||
+        	status.status == SND_PCM_STATUS_UNDERRUN)
+            {
+                if (snd_pcm_plugin_prepare (stream->pb_pcm,
+                                            SND_PCM_CHANNEL_PLAYBACK) < 0)
+                {
+                    PJ_LOG(4,(THIS_FILE,
+                    	      "underrun: playback channel prepare error"));
+                    continue;
+                }
+            }
+
             TRACE_((THIS_FILE, "pb_thread_func failed write = %d", result));
         }
@@ -469,8 +497,7 @@
 
     flush_play(stream);
-    close_play_mixer(stream);
     close_play_pcm(stream);
     TRACE_((THIS_FILE, "pb_thread_func: Stopped"));
-    
+
     return PJ_SUCCESS;
 }
@@ -514,5 +541,4 @@
                                           SND_PCM_CHANNEL_CAPTURE)) < 0)
     {
-        close_capture_mixer(stream);
         close_capture_pcm(stream);
         TRACE_((THIS_FILE, "ca_thread_func failed prepare = %d", result));
@@ -524,12 +550,24 @@
 
         pj_bzero (buf, size);
-        
+
         result = snd_pcm_plugin_read(stream->ca_pcm, buf,size);
-        if (result == -EPIPE) {
-            PJ_LOG (4,(THIS_FILE, "ca_thread_func: overrun!"));
-            snd_pcm_plugin_prepare (stream->ca_pcm, SND_PCM_CHANNEL_CAPTURE);
-            continue;
-        } else if (result < 0) {
-            PJ_LOG (4,(THIS_FILE, "ca_thread_func: error reading data!"));
+        if(result <0 || result != size) {
+            snd_pcm_channel_status_t status;
+            if (snd_pcm_plugin_status (stream->ca_pcm, &status) < 0) {
+                PJ_LOG (4,(THIS_FILE, "overrun: capture channel status "
+                                      "error"));
+                continue;
+            }
+
+            if (status.status == SND_PCM_STATUS_READY ||
+        	status.status == SND_PCM_STATUS_OVERRUN) {
+                if (snd_pcm_plugin_prepare (stream->ca_pcm,
+                                            SND_PCM_CHANNEL_CAPTURE) < 0)
+                {
+                    PJ_LOG (4,(THIS_FILE, "overrun: capture channel prepare  "
+                                          "error"));
+                    continue;
+                }
+            }
         }
 
@@ -551,5 +589,4 @@
 
     flush_capture(stream);
-    close_capture_mixer(stream);
     close_capture_pcm(stream);
     TRACE_((THIS_FILE, "ca_thread_func: Stopped"));
@@ -571,4 +608,5 @@
     unsigned int rate;
     unsigned long tmp_buf_size;
+    unsigned int handle;
 
     if (param->play_id < 0 || param->play_id >= stream->af->dev_cnt) {
@@ -576,4 +614,15 @@
     }
 
+#if PJ_BBSDK_VER >= 0x100006
+    if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE,
+                                               &stream->pb_pcm, &handle,
+                                               "/dev/snd/voicep",
+                                               SND_PCM_OPEN_PLAYBACK)) < 0)
+    {
+        TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret));
+        return PJMEDIA_EAUD_SYSERR;
+    }
+
+#else
     if ((ret = snd_pcm_open_preferred (&stream->pb_pcm, &card, &dev,
                                        SND_PCM_OPEN_PLAYBACK)) < 0)
@@ -582,4 +631,5 @@
         return PJMEDIA_EAUD_SYSERR;
     }
+#endif
 
     /* TODO PJ_ZERO */
@@ -623,5 +673,5 @@
     setup.channel = SND_PCM_CHANNEL_PLAYBACK;
     setup.mixer_gid = &group.gid;
-    
+
     if ((ret = snd_pcm_plugin_setup (stream->pb_pcm, &setup)) < 0) {
         TRACE_((THIS_FILE, "snd_pcm_plugin_setup ret = %d", ret));
@@ -632,12 +682,4 @@
         return PJMEDIA_EAUD_SYSERR;
     }
-    
-    if ((ret = snd_mixer_open (&stream->pb_mixer, card,
-                               setup.mixer_device)) < 0)
-    {
-        TRACE_((THIS_FILE, "snd_mixer_open ret = %d", ret));
-        return PJMEDIA_EAUD_SYSERR;
-    }
-
 
     rate = param->clock_rate;
@@ -676,9 +718,22 @@
     snd_pcm_channel_params_t pp;
     snd_pcm_channel_setup_t setup;
+    unsigned int handle;
 
     if (param->rec_id < 0 || param->rec_id >= stream->af->dev_cnt)
         return PJMEDIA_EAUD_INVDEV;
 
+#if PJ_BBSDK_VER >= 0x100006
+    if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE,
+                                               &stream->ca_pcm,
+                                               &handle,
+                                               "/dev/snd/voicec",
+                                               SND_PCM_OPEN_CAPTURE)) < 0)
+    {
+	TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret));
+	return PJMEDIA_EAUD_SYSERR;
+    }
+#else
     /* BB10 Audio init here (not prepare) */
+    PJ_UNUSED_ARG(handle);
     if ((ret = snd_pcm_open_preferred (&stream->ca_pcm, &card, &dev,
                                        SND_PCM_OPEN_CAPTURE)) < 0)
@@ -687,4 +742,5 @@
         return PJMEDIA_EAUD_SYSERR;
     }
+#endif
 
     /* sample reads the capabilities of the capture */
@@ -741,11 +797,4 @@
     }
 
-    if ((ret = snd_mixer_open (&stream->ca_mixer, card,
-                               setup.mixer_device)) < 0)
-    {
-        TRACE_((THIS_FILE,"snd_mixer_open ret = %d",ret));
-        return PJMEDIA_EAUD_SYSERR;
-    }
-
     /* frag_size should be 160 */
     frame_size = setup.buf.block.frag_size;
@@ -821,5 +870,4 @@
         if (status != PJ_SUCCESS) {
             if (param->dir & PJMEDIA_DIR_PLAYBACK) {
-                close_play_mixer(stream);
                 close_play_pcm(stream);
             }
@@ -953,5 +1001,5 @@
 {
     struct bb10_stream *stream = (struct bb10_stream*)s;
-    
+
     TRACE_((THIS_FILE,"bb10_stream_destroy()"));
 
