Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5380)
+++ ChangeLog	(revision 5388)
@@ -1,5 +1,5 @@
 v. 1.0beta0 - ?
 	* Updated API (SONAME change)
-	  (Closes: #184, #185, #128, #135, #134, #133, #129, #188, #126)
+	  (Closes: #184, #185, #128, #135, #134, #133, #129, #188, #126, #127)
 	* Do not set errno to zero in ogg_vorbis codec filter (Closes: #191)
 	* Updated data types for struct roar_audio_info (Closes: #189)
Index: include/libroar/vio.h
===================================================================
--- include/libroar/vio.h	(revision 5381)
+++ include/libroar/vio.h	(revision 5388)
@@ -52,5 +52,5 @@
 
 #define ROAR_VIO_FLAGS_NONE        0x00000000UL
-#define ROAR_VIO_FLAGS_FREESELF    0x00000020UL /* Free the VIO object */
+#define ROAR_VIO_FLAGS_FREESELF    0x00000001UL /* Free the VIO object */
 
 struct roar_connection;
@@ -81,5 +81,8 @@
 int     roar_vio_sync    (struct roar_vio_calls * vio) _LIBROAR_ATTR_NONNULL_ALL;
 int     roar_vio_ctl     (struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) _LIBROAR_ATTR_USE_RESULT _LIBROAR_ATTR_NONNULL(1);
-int     roar_vio_close   (struct roar_vio_calls * vio) _LIBROAR_ATTR_NONNULL_ALL;
+
+#define roar_vio_close(x) roar_vio_unref((x))
+int     roar_vio_ref     (struct roar_vio_calls * vio) _LIBROAR_ATTR_NONNULL_ALL;
+int     roar_vio_unref   (struct roar_vio_calls * vio) _LIBROAR_ATTR_NONNULL_ALL;
 
 // specal commands:
Index: include/libroar/vio_dstr.h
===================================================================
--- include/libroar/vio_dstr.h	(revision 5381)
+++ include/libroar/vio_dstr.h	(revision 5388)
@@ -199,4 +199,5 @@
 
 int     roar_vio_open_dstr_simple(struct roar_vio_calls * calls, const char * dstr, int o_flags);
+struct roar_vio_calls * roar_vio_open_dstr_simple_new(const char * dstr, int o_flags);
 
 int     roar_vio_open_dstr    (struct roar_vio_calls * calls, const char * dstr, struct roar_vio_defaults * def, int dnum);
Index: libroar/vio.c
===================================================================
--- libroar/vio.c	(revision 5381)
+++ libroar/vio.c	(revision 5388)
@@ -53,5 +53,5 @@
  memset((void*)calls, 0, sizeof(struct roar_vio_calls));
  calls->flags = ROAR_VIO_FLAGS_NONE;
- calls->refc  = 0;
+ calls->refc  = 1;
 
  return 0;
@@ -202,18 +202,35 @@
 }
 
-int     roar_vio_close    (struct roar_vio_calls * vio) {
+
+int     roar_vio_ref      (struct roar_vio_calls * vio) {
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ vio->refc++;
+
+ return 0;
+}
+
+int     roar_vio_unref    (struct roar_vio_calls * vio) {
  int ret;
 
- ROAR_DBG("roar_vio_close(vio=%p) = ?", vio);
-
- if ( vio == NULL ) {
-  roar_err_set(ROAR_ERROR_FAULT);
-  return -1;
- }
-
- if ( vio->close == NULL ) {
+ ROAR_DBG("roar_vio_unref(vio=%p) = ?", vio);
+
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->refc == 1 && vio->close == NULL ) {
   roar_err_set(ROAR_ERROR_NOSYS);
   return -1;
  }
+
+ vio->refc--;
+
+ if ( vio->refc )
+  return 0;
 
  roar_err_clear_all();
@@ -221,4 +238,7 @@
  roar_err_update();
 
+ if ( vio->flags & ROAR_VIO_FLAGS_FREESELF )
+  roar_mm_free(vio);
+
  return ret;
 }
@@ -257,4 +277,6 @@
 
  memset((void*)calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read     = roar_vio_basic_read;
@@ -642,4 +664,6 @@
 
  memset((void*)calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read     = roar_vio_pass_read;
Index: libroar/vio_bio.c
===================================================================
--- libroar/vio_bio.c	(revision 5381)
+++ libroar/vio_bio.c	(revision 5388)
@@ -42,4 +42,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read     = roar_vio_bio_read;
Index: libroar/vio_buffer.c
===================================================================
--- libroar/vio_buffer.c	(revision 5381)
+++ libroar/vio_buffer.c	(revision 5388)
@@ -59,4 +59,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->inst     = self;
Index: libroar/vio_buffer_store.c
===================================================================
--- libroar/vio_buffer_store.c	(revision 5381)
+++ libroar/vio_buffer_store.c	(revision 5388)
@@ -50,4 +50,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  if ( inst != NULL )
Index: libroar/vio_cmd.c
===================================================================
--- libroar/vio_cmd.c	(revision 5381)
+++ libroar/vio_cmd.c	(revision 5388)
@@ -54,4 +54,6 @@
  // clear all
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  memset(state, 0, sizeof(struct roar_vio_cmd_state));
 
@@ -233,4 +235,6 @@
  // clear all
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  memset(state, 0, sizeof(struct roar_vio_2popen_state));
 
Index: libroar/vio_dstr.c
===================================================================
--- libroar/vio_dstr.c	(revision 5381)
+++ libroar/vio_dstr.c	(revision 5388)
@@ -411,4 +411,23 @@
 }
 
+struct roar_vio_calls * roar_vio_open_dstr_simple_new(const char * dstr, int o_flags) {
+ struct roar_vio_calls * ret = roar_mm_malloc(sizeof(struct roar_vio_calls));
+ int err;
+
+ if ( ret == NULL )
+  return NULL;
+
+ if ( roar_vio_open_dstr_simple(ret, dstr, o_flags) == -1 ) {
+  err = roar_error;
+  roar_mm_free(ret);
+  roar_error = err;
+  return NULL;
+ }
+
+ ret->flags |= ROAR_VIO_FLAGS_FREESELF;
+
+ return ret;
+}
+
 int     roar_vio_open_dstr    (struct roar_vio_calls * calls, const char * dstr, struct roar_vio_defaults * def, int dnum) {
  return roar_vio_open_dstr_vio(calls, dstr, def, dnum, NULL);
Index: libroar/vio_jumbo.c
===================================================================
--- libroar/vio_jumbo.c	(revision 5381)
+++ libroar/vio_jumbo.c	(revision 5388)
@@ -53,4 +53,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  calls->inst     = self;
  calls->close    = roar_vio_jumbo_close;
Index: libroar/vio_misc.c
===================================================================
--- libroar/vio_misc.c	(revision 5381)
+++ libroar/vio_misc.c	(revision 5388)
@@ -106,4 +106,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  calls->read     = roar_vio_misc_read;
  calls->write    = roar_vio_misc_write;
Index: libroar/vio_pipe.c
===================================================================
--- libroar/vio_pipe.c	(revision 5381)
+++ libroar/vio_pipe.c	(revision 5388)
@@ -125,4 +125,6 @@
 
  memset(s, 0, sizeof(struct roar_vio_calls));
+ s->flags    = ROAR_VIO_FLAGS_NONE;
+ s->refc     = 1;
 
  s->close    = roar_vio_pipe_close;
Index: libroar/vio_rtp.c
===================================================================
--- libroar/vio_rtp.c	(revision 5381)
+++ libroar/vio_rtp.c	(revision 5388)
@@ -110,4 +110,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->inst               = self;
Index: libroar/vio_stack.c
===================================================================
--- libroar/vio_stack.c	(revision 5381)
+++ libroar/vio_stack.c	(revision 5388)
@@ -56,4 +56,6 @@
  memset(self,  0, sizeof(struct roar_vio_stack));
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  self->free      = func;
Index: libroar/vio_stdio.c
===================================================================
--- libroar/vio_stdio.c	(revision 5381)
+++ libroar/vio_stdio.c	(revision 5388)
@@ -42,4 +42,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read  = roar_vio_stdio_read;
Index: libroar/vio_tantalos.c
===================================================================
--- libroar/vio_tantalos.c	(revision 5381)
+++ libroar/vio_tantalos.c	(revision 5388)
@@ -97,5 +97,5 @@
    return 0;
 
-  memset(calls, 0, sizeof(*calls));
+  memset(calls, 0, sizeof(struct roar_vio_calls));
  }
 
Index: libroar/vio_zlib.c
===================================================================
--- libroar/vio_zlib.c	(revision 5381)
+++ libroar/vio_zlib.c	(revision 5388)
@@ -538,4 +538,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags      = ROAR_VIO_FLAGS_NONE;
+ calls->refc       = 1;
 
  calls->inst       = self;
Index: libroardsp/vio_transcode.c
===================================================================
--- libroardsp/vio_transcode.c	(revision 5381)
+++ libroardsp/vio_transcode.c	(revision 5388)
@@ -44,4 +44,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags  = ROAR_VIO_FLAGS_NONE;
+ calls->refc   = 1;
 
  calls->inst   = (void*)xcoder;
@@ -115,8 +117,10 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags = ROAR_VIO_FLAGS_NONE;
+ calls->refc  = 1;
 
- calls->inst   = (void*)bixcoder;
+ calls->inst  = (void*)bixcoder;
 
- calls->close  = roar_vio_bixcode_close;
+ calls->close = roar_vio_bixcode_close;
 
  calls->read  = roar_vio_bixcode_read;
Index: libroareio/driver.c
===================================================================
--- libroareio/driver.c	(revision 5381)
+++ libroareio/driver.c	(revision 5388)
@@ -38,4 +38,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags = ROAR_VIO_FLAGS_NONE;
+ calls->refc  = 1;
  calls->read  = roar_vio_null_rw;
  calls->write = roar_vio_null_rw;
Index: roard/beep.c
===================================================================
--- roard/beep.c	(revision 5381)
+++ roard/beep.c	(revision 5388)
@@ -61,5 +61,6 @@
 
  memset(vio, 0, sizeof(struct roar_vio_calls));
-
+ vio->flags = ROAR_VIO_FLAGS_NONE;
+ vio->refc  = 1;
  vio->inst  = inst;
  vio->read  = beep_read;
Index: roard/container_framework.c
===================================================================
--- roard/container_framework.c	(revision 5381)
+++ roard/container_framework.c	(revision 5388)
@@ -169,6 +169,7 @@
 
  memset(vio, 0, sizeof(struct roar_vio_calls));
- vio->inst = inst;
-
+ vio->flags = ROAR_VIO_FLAGS_NONE;
+ vio->refc  = 1;
+ vio->inst  = inst;
  vio->read  = cont_fw_read;
  vio->write = cont_fw_write;
@@ -238,4 +239,6 @@
 int     cont_pvio_open    (struct roar_vio_calls * vio, void * inst) {
  memset(vio, 0, sizeof(struct roar_vio_calls));
+ vio->flags = ROAR_VIO_FLAGS_NONE;
+ vio->refc  = 1;
 
  vio->inst  = inst;
Index: roard/driver.c
===================================================================
--- roard/driver.c	(revision 5381)
+++ roard/driver.c	(revision 5388)
@@ -220,4 +220,6 @@
     if ( g_driver[i].open == NULL ) { // this is the null driver
      memset(calls, 0, sizeof(struct roar_vio_calls));
+     calls->flags = ROAR_VIO_FLAGS_NONE;
+     calls->refc  = 1;
      calls->read  = roar_vio_null_rw;
      calls->write = roar_vio_null_rw;
Index: roard/driver_alsa.c
===================================================================
--- roard/driver_alsa.c	(revision 5381)
+++ roard/driver_alsa.c	(revision 5388)
@@ -225,4 +225,6 @@
 
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
 
  inst->inst     = (void*) interface;
Index: roard/driver_ao.c
===================================================================
--- roard/driver_ao.c	(revision 5381)
+++ roard/driver_ao.c	(revision 5388)
@@ -131,4 +131,6 @@
 
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
  inst->inst     = (void*) aodevice;
  inst->write    = driver_ao_write;
Index: roard/driver_artsc.c
===================================================================
--- roard/driver_artsc.c	(revision 5381)
+++ roard/driver_artsc.c	(revision 5388)
@@ -119,4 +119,6 @@
 
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
 
  inst->inst     = (void*) self;
Index: roard/driver_jack.c
===================================================================
--- roard/driver_jack.c	(revision 5381)
+++ roard/driver_jack.c	(revision 5388)
@@ -61,4 +61,6 @@
  // set up VIO:
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
 
  inst->read     = driver_jack_read;
Index: roard/driver_oss.c
===================================================================
--- roard/driver_oss.c	(revision 5381)
+++ roard/driver_oss.c	(revision 5388)
@@ -35,4 +35,6 @@
 
  memset(vio, 0, sizeof(struct roar_vio_calls));
+ vio->flags    = ROAR_VIO_FLAGS_NONE;
+ vio->refc     = 1;
 
  vio->write    = driver_oss_write;
Index: roard/driver_portaudio.c
===================================================================
--- roard/driver_portaudio.c	(revision 5381)
+++ roard/driver_portaudio.c	(revision 5388)
@@ -120,4 +120,6 @@
 
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags = ROAR_VIO_FLAGS_NONE;
+ inst->refc  = 1;
 
  inst->inst  = self;
Index: roard/driver_pulsesimple.c
===================================================================
--- roard/driver_pulsesimple.c	(revision 5381)
+++ roard/driver_pulsesimple.c	(revision 5388)
@@ -121,4 +121,6 @@
 
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
 
  inst->inst     = self;
Index: roard/driver_rsound.c
===================================================================
--- roard/driver_rsound.c	(revision 5381)
+++ roard/driver_rsound.c	(revision 5388)
@@ -167,4 +167,6 @@
 
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
 
  inst->inst     = self;
Index: roard/driver_shout.c
===================================================================
--- roard/driver_shout.c	(revision 5381)
+++ roard/driver_shout.c	(revision 5388)
@@ -199,4 +199,6 @@
 
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
  inst->inst     = (void*)shout;
  inst->write    = driver_shout_write;
Index: roard/driver_sndio.c
===================================================================
--- roard/driver_sndio.c	(revision 5381)
+++ roard/driver_sndio.c	(revision 5388)
@@ -32,4 +32,6 @@
 
  memset(vio, 0, sizeof(struct roar_vio_calls));
+ vio->flags    = ROAR_VIO_FLAGS_NONE;
+ vio->refc     = 1;
 
  vio->close    = driver_sndio_close_vio;
Index: roard/driver_sysclock.c
===================================================================
--- roard/driver_sysclock.c	(revision 5381)
+++ roard/driver_sysclock.c	(revision 5388)
@@ -39,4 +39,6 @@
  memset(self, 0, sizeof(struct driver_sysclock));
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
 
  inst->inst     = self;
Index: roard/driver_wmm.c
===================================================================
--- roard/driver_wmm.c	(revision 5381)
+++ roard/driver_wmm.c	(revision 5388)
@@ -188,4 +188,6 @@
  // VIO Setup:
  memset(inst, 0, sizeof(struct roar_vio_calls));
+ inst->flags    = ROAR_VIO_FLAGS_NONE;
+ inst->refc     = 1;
  inst->inst     = self;
  inst->close    = driver_wmm_close_vio;
Index: roard/sources.c
===================================================================
--- roard/sources.c	(revision 5381)
+++ roard/sources.c	(revision 5388)
@@ -441,4 +441,6 @@
 
  memset(&(ss->vio), 0, sizeof(struct roar_vio_calls));
+ ss->vio.flags    = ROAR_VIO_FLAGS_NONE;
+ ss->vio.refc     = 1;
  ss->vio.read     = sources_radionoise_read;
  ss->vio.close    = sources_radionoise_return_zero;
