Changeset 5348:83fcc9598253 in roaraudio


Ignore:
Timestamp:
12/11/11 12:38:30 (8 years ago)
Author:
phi
Branch:
default
Message:

Converted roar_buffer API to fully use refcounter (Closes: #126)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5296 r5348  
    11v. 1.0beta0 - ? 
    2         * Updated API (SONAME change) (Closes: #184, #185, #128, #135, #134, #133, #129, #188) 
     2        * Updated API (SONAME change) 
     3          (Closes: #184, #185, #128, #135, #134, #133, #129, #188, #126) 
    34        * Do not set errno to zero in ogg_vorbis codec filter (Closes: #191) 
    45        * Updated data types for struct roar_audio_info (Closes: #189) 
  • include/libroar/buffer.h

    r5302 r5348  
    6565#define roar_buffer_free(x)    roar_buffer_unref(x) 
    6666 
    67 #define roar_buffer_foreach(cur) for (; (cur) != NULL; (cur) = (roar_buffer_get_next((cur), &(cur)) == -1) ? NULL : (cur)) 
     67#define roar_buffer_foreach(cur) for (; (cur) != NULL; (cur) = (roar_buffer_next(&(cur)) == -1) ? NULL : (cur)) 
    6868 
    6969int roar_buffer_new_no_ma(struct roar_buffer ** buf, size_t len, void * data) _LIBROAR_BUFFER_STDATTRS; // no internal malloc 
  • libroar/buffer.c

    r5300 r5348  
    181181 ROAR_DBG("roar_buffer_unref(buf=%p) = ?", buf); 
    182182 
    183  flags = buf->flags & (ROAR_BUFFER_FLAG_USEABLE|ROAR_BUFFER_FLAG_FREED); 
    184  if ( flags == ROAR_BUFFER_FLAG_FREED ) { 
    185   roar_panic(ROAR_FATAL_ERROR_MEMORY_DOUBLE_FREE, NULL); 
    186  } 
    187  
    188  _ckmem_corruption(buf, 0); 
    189  
    190  ROAR_DBG("roar_buffer_unref(buf=%p) = ?", buf); 
    191  
    192  if ( buf->refc == 0 ) { 
    193   ROAR_WARN("roar_buffer_unref(buf=%p): Ref counter is wrong. assuming one."); 
    194   buf->refc = 1; 
    195   roar_panic(ROAR_FATAL_ERROR_MEMORY_CORRUPTION, NULL); 
    196  } 
    197  
    198  buf->refc--; 
    199  
    200  if ( buf->refc ) { 
    201   ROAR_DBG("roar_buffer_unref(buf=%p) = 0", buf); 
    202   return 0; 
    203  } 
    204  
    205  ROAR_DBG("roar_buffer_unref(buf=%p) = ?", buf); 
    206  
    207  cur = buf->next; 
     183 cur = buf; 
    208184 while (cur != NULL) { 
    209185  flags = cur->flags & (ROAR_BUFFER_FLAG_USEABLE|ROAR_BUFFER_FLAG_FREED); 
     
    212188  } 
    213189 
     190  _ckmem_corruption(cur, 0); 
     191 
     192  if ( cur->refc == 0 ) { 
     193   ROAR_WARN("roar_buffer_unref(buf=%p): Ref counter for buffer at %p is wrong. assuming one.", cur); 
     194   cur->refc = 1; 
     195   roar_panic(ROAR_FATAL_ERROR_MEMORY_CORRUPTION, NULL); 
     196  } else if ( cur->refc > 1 ) { 
     197   cur->refc--; 
     198   return 0; 
     199  } 
     200 
    214201  ROAR_DBG("roar_buffer_unref(buf=%p) = ?", buf); 
    215  
    216   _ckmem_corruption(cur, 0); 
    217202 
    218203  if ( roar_buffer_get_flag(cur, ROAR_BUFFER_FLAG_NOFREE) != 1 ) 
     
    224209  cur = next; 
    225210 } 
    226  
    227  ROAR_DBG("roar_buffer_unref(buf=%p) = ?", buf); 
    228  
    229  if ( !(buf->flags & ROAR_BUFFER_FLAG_NOFREE) ) 
    230   roar_mm_free(buf->data); 
    231  
    232  ROAR_DBG("roar_buffer_unref(buf=%p): setting flags = ROAR_BUFFER_FLAG_FREED", buf); 
    233  buf->flags = ROAR_BUFFER_FLAG_FREED; 
    234  
    235  roar_mm_free(buf); 
    236211 
    237212 ROAR_DBG("roar_buffer_unref(buf=%p) = 0", buf); 
     
    247222 } 
    248223 
    249  ROAR_DBG("buffer_delete(buf=%p, next=%p) = ?", buf, next); 
    250  
    251  if ( next != NULL ) 
    252   *next = buf->next; 
    253  
    254  if ( roar_buffer_get_flag(buf, ROAR_BUFFER_FLAG_NOFREE) != 1 ) 
    255   roar_mm_free(buf->data); 
    256  
    257  roar_mm_free(buf); 
    258  
    259  ROAR_DBG("buffer_delete(buf=%p, next=%p) = 0", buf, next); 
    260  return 0; 
     224 ROAR_DBG("roar_buffer_delete(buf=%p, next=%p) = ?", buf, next); 
     225 
     226 if ( next != NULL ) { 
     227  *next = buf; 
     228  return roar_buffer_next(next); 
     229 } else { 
     230  return roar_buffer_unref(buf); 
     231 } 
    261232} 
    262233 
    263234int roar_buffer_next     (struct roar_buffer ** buf) { 
    264  return roar_buffer_delete(*buf, buf); 
     235 struct roar_buffer * ret; 
     236 
     237 if ( buf == NULL || *buf == NULL ) { 
     238  roar_err_set(ROAR_ERROR_FAULT); 
     239 } 
     240 
     241 ret = (*buf)->next; 
     242 
     243 if ( ret != NULL ) 
     244  roar_buffer_ref(ret); 
     245 
     246 roar_buffer_unref(*buf); 
     247 
     248 *buf = ret; 
     249 
     250 return 0; 
    265251} 
    266252 
    267253int roar_buffer_add      (struct roar_buffer * buf, struct roar_buffer *  next) { 
     254 if ( roar_buffer_ref(next) == -1 ) 
     255  return -1; 
    268256 return roar_buffer_moveinto(buf, &next); 
    269257} 
     
    314302 *next = buf->next; 
    315303 
    316  return 0; 
     304 return roar_buffer_ref(*next); 
    317305} 
    318306 
  • libroarpulse/stream.c

    r5300 r5348  
    235235   break; 
    236236  case PA_STREAM_RECORD: 
    237     if ( roar_buffer_new(&buf, s->fragments.size) == -1 ) 
     237    if ( roar_buffer_new_data(&buf, s->fragments.size, &data) == -1 ) 
    238238     return; 
    239  
    240     if ( roar_buffer_get_data(buf, &data) == -1 ) { 
    241      roar_buffer_free(buf); 
    242      return; 
    243     } 
    244239 
    245240    if ( (ret = roar_vio_read(&(s->vio), data, s->fragments.size)) < 1 ) { 
     
    442437 // seems we have a valid write from here. 
    443438 
    444  if ( roar_buffer_new(&buf, length) == -1 ) { 
    445   if ( free_cb != NULL ) 
    446    free_cb((void*)data); 
    447  
    448   return -1; 
    449  } 
    450  
    451  if ( roar_buffer_get_data(buf, &bufdata) == -1 ) { 
     439 if ( roar_buffer_new_data(&buf, length, &bufdata) == -1 ) { 
    452440  if ( free_cb != NULL ) 
    453441   free_cb((void*)data); 
     
    463451  p->iobuffer = buf; 
    464452 } else { 
    465   if ( roar_buffer_moveinto(p->iobuffer, &buf) == -1 ) 
     453  if ( roar_buffer_moveinto(p->iobuffer, &buf) == -1 ) { 
     454   roar_buffer_free(buf); 
    466455   return -1; 
     456  } 
    467457 } 
    468458 
  • roard/midi.c

    r5305 r5348  
    583583 send_clock = streams_get_flag(id, ROAR_FLAG_SYNC); 
    584584 
     585 if ( roar_buffer_ref(buf) == -1 ) 
     586  return -1; 
     587 
    585588 roar_buffer_foreach(buf) { 
    586589  if ( roar_buffer_get_data(buf, &bufdata) == -1 ) { 
     
    650653 void                      * bufdata; 
    651654 
     655 if ( roar_buffer_ref(g_midi_mess.buf) == -1 ) 
     656  return -1; 
     657 
    652658 roar_buffer_foreach(buf) { 
    653659  if ( roar_buffer_get_data(buf, &bufdata) == -1 ) { 
Note: See TracChangeset for help on using the changeset viewer.