Changeset 5068:f11a0c0bacdd in roaraudio


Ignore:
Timestamp:
06/19/11 01:58:05 (10 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Support non-blocking latency request in VS API (Closes: #97)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5064 r5068  
    99        * Added manpages for all VS functions (Closing: #4) 
    1010        * Some updates and small fixes for the win32 stuff. 
     11        * Support non-blocking latency request in VS API (Closes: #97) 
    1112 
    1213v. 0.4beta6 - Mon May 23 2011 19:49 CEST 
  • include/libroar/vs.h

    r5049 r5068  
    173173 */ 
    174174roar_mus_t roar_vs_latency(roar_vs_t * vss, int backend, int * error); 
     175roar_mus_t roar_vs_latency2(roar_vs_t * vss, int backend, int wait, int * error); 
    175176 
    176177/* set pause flag 
  • libroar/time.c

    r5066 r5068  
    147147#endif 
    148148 
     149 ROAR_DBG("roar_clock_gettime(rt=%p, clock=%i) = ?", rt, clock); 
     150 
    149151 if ( rt == NULL ) { 
    150152  roar_err_set(ROAR_ERROR_FAULT); 
     
    159161 switch (clock) { 
    160162  case ROAR_CLOCK_REALTIME: 
     163    ROAR_DBG("roar_clock_gettime(rt=%p, clock=(%i)ROAR_CLOCK_REALTIME) = -1", rt, clock); 
    161164#ifdef ROAR_HAVE_GETTIMEOFDAY 
    162165    if ( gettimeofday(&tv, NULL) == -1 ) { 
     
    179182 } 
    180183 
     184 ROAR_DBG("roar_clock_gettime(rt=%p, clock=%i) = -1 // error=NOTSUP", rt, clock); 
    181185 roar_err_set(ROAR_ERROR_NOTSUP); 
    182186 return -1; 
  • libroar/vs.c

    r5051 r5068  
    4040#endif 
    4141 
     42#define LOCAL_CLOCK    ROAR_CLOCK_DEFAULT 
     43 
    4244#define FLAG_NONE      0x0000 
    4345#define FLAG_STREAM    0x0001 
     
    7880 } latc; 
    7981#endif 
     82 struct { 
     83  ssize_t last_pos; 
     84  struct roar_time last_time; 
     85 } latmes; 
    8086}; 
    8187 
     
    110116 vss->latc.p      =  0.005; 
    111117#endif 
     118 
     119 vss->latmes.last_pos = -1; 
    112120 
    113121 return vss; 
     
    626634 switch (backend) { 
    627635  case ROAR_VS_BACKEND_NONE: 
    628     return stream.pos; 
     636//    return stream.pos; 
     637    // do nothing. 
    629638   break; 
    630639  case ROAR_VS_BACKEND_FIRST: 
     
    655664  offset  = out_info.delay * vss->info.rate; 
    656665  offset /= 1000000; 
     666 } 
     667 
     668 if ( roar_clock_gettime(&(vss->latmes.last_time), LOCAL_CLOCK) == -1 ) { 
     669  vss->latmes.last_pos = -1; 
     670 } else { 
     671  vss->latmes.last_pos = stream.pos + offset; 
    657672 } 
    658673 
     
    698713 _initerr(); 
    699714 
    700  _ckvss(-1); 
     715 _ckvss(0); 
    701716 
    702717 if (pos == -1) { 
     
    750765 
    751766 return lag; 
     767} 
     768 
     769roar_mus_t roar_vs_latency2(roar_vs_t * vss, int backend, int wait, int * error) { 
     770 ssize_t bps;  // byte per sample 
     771 size_t  lioc; // local IO (byte) counter 
     772 size_t  lpos; // local possition 
     773 signed long long int lag; 
     774 struct roar_time rt; 
     775 
     776 _initerr(); 
     777 
     778 _ckvss(0); 
     779 
     780 if ( !(vss->flags & FLAG_STREAM) ) { 
     781  _seterr(ROAR_ERROR_INVAL); 
     782  return 0; 
     783 } 
     784 
     785 if ( wait == ROAR_VS_WAIT ) { 
     786  return roar_vs_latency(vss, backend, error); 
     787 } else if ( wait == ROAR_VS_NOWAIT ) { 
     788  if ( vss->latmes.last_pos == -1 ) { 
     789   _seterr(ROAR_ERROR_NODATA); 
     790   return 0; 
     791  } 
     792 
     793  if ( vss->writec == 0 ) { 
     794   lioc = vss->readc; 
     795  } else { 
     796   //printf("writec=%zu\n", vss->writec); 
     797   lioc = vss->writec; 
     798  } 
     799 
     800  bps = roar_info2samplesize(&(vss->info)); 
     801 
     802  if ( bps == -1 ) { 
     803   _seterrre(); 
     804   return 0; 
     805  } 
     806 
     807  lpos = (lioc*8) / bps; 
     808 
     809  //printf("pos=%zi, lpos=%zi, bps=%zi, diff[lpos-pos]=%zi\n", pos, lpos, bps, (lpos - pos)); 
     810 
     811  lag = (signed long long int)lpos - (signed long long int)vss->latmes.last_pos; 
     812  lag /= vss->info.channels; 
     813 
     814  // we now have the lag in frames 
     815  // return value are mus 
     816  // so we need to multiply with 1s/mus and 
     817  // multiply by 1/rate 
     818 
     819  lag *= 1000000; // 1s/mus 
     820  lag /= vss->info.rate; 
     821 
     822  _initerr(); 
     823  if ( roar_clock_gettime(&rt, LOCAL_CLOCK) == -1 ) { 
     824   _seterrre(); 
     825   return 0; 
     826  } 
     827 
     828//  printf("%lli, %lli\n", (rt.t_sec  - vss->latmes.last_time.t_sec ), (rt.t_ssec/2 - vss->latmes.last_time.t_ssec/2)/ 18446744073710LL); 
     829//  printf("%lli, %llu\n", rt.t_sec, rt.t_ssec); 
     830  lag -= (rt.t_sec  - vss->latmes.last_time.t_sec ) * 1000000LL; 
     831  lag -= ((int64_t)(rt.t_ssec/2) - (int64_t)(vss->latmes.last_time.t_ssec/2)) / 9223372036855LL; 
     832 
     833  if ( lag == 0 ) { 
     834   _seterr(ROAR_ERROR_NONE); 
     835  } 
     836 
     837  return lag; 
     838 } 
     839 
     840 _seterr(ROAR_ERROR_INVAL); 
     841 return 0; 
    752842} 
    753843 
Note: See TracChangeset for help on using the changeset viewer.