Changeset 5119:66203ccc8f12 in roaraudio


Ignore:
Timestamp:
08/01/11 12:20:53 (8 years ago)
Author:
phi
Branch:
default
Message:

moved code from roar_vs_latency() into roar_vs_latency2()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/vs.c

    r5114 r5119  
    871871 
    872872roar_mus_t roar_vs_latency(roar_vs_t * vss, int backend, int * error) { 
    873  ssize_t pos  = roar_vs_position(vss, backend, error); 
    874  ssize_t bps;  // byte per sample 
    875  size_t  lioc; // local IO (byte) counter 
    876  size_t  lpos; // local possition 
    877  signed long long int lag; 
    878  
    879 // printf("pos=%zi\n", pos); 
    880  
    881  _initerr(); 
    882  
    883  _ckvss(0); 
    884  _ckasync(-1); 
    885  
    886  if (pos == -1) { 
    887   _seterrre(); 
    888   return 0; 
    889  } 
    890  
    891  if ( !(vss->flags & FLAG_STREAM) ) { 
    892   _seterr(ROAR_ERROR_INVAL); 
    893   return 0; 
    894  } 
    895  
    896  if ( vss->writec == 0 ) { 
    897   lioc = vss->readc; 
    898  } else { 
    899   //printf("writec=%zu\n", vss->writec); 
    900   lioc = vss->writec; 
    901  } 
    902  
    903  bps = roar_info2samplesize(&(vss->info)); 
    904  
    905  if ( bps == -1 ) { 
    906   _seterrre(); 
    907   return 0; 
    908  } 
    909  
    910  lpos = (lioc*8) / bps; 
    911  
    912  //printf("pos=%zi, lpos=%zi, bps=%zi, diff[lpos-pos]=%zi\n", pos, lpos, bps, (lpos - pos)); 
    913  
    914  lag = (signed long long int)lpos - (signed long long int)pos; 
    915  lag /= vss->info.channels; 
    916  
    917  // we now have the lag in frames 
    918  // return value are mus 
    919  // so we need to multiply with 1s/mus and 
    920  // multiply by 1/rate 
    921  
    922  lag *= 1000000; // 1s/mus 
    923  lag /= vss->info.rate; 
    924  
    925  if ( lag == 0 ) { 
    926   _seterr(ROAR_ERROR_NONE); 
    927  } 
    928  
    929 #ifdef _HAVE_SOCKOPT 
    930  if (vss->latc.target > vss->latc.minlag) { 
    931   roar_vs_latency_managed(vss, lag); 
    932  } 
    933 #endif 
    934  
    935  vss->async.read_latency = 1; 
    936  
    937  return lag; 
     873 return roar_vs_latency2(vss, backend, ROAR_VS_WAIT, error); 
    938874} 
    939875 
    940876roar_mus_t roar_vs_latency2(roar_vs_t * vss, int backend, int wait, int * error) { 
     877 ssize_t pos; 
    941878 ssize_t bps;  // byte per sample 
    942879 size_t  lioc; // local IO (byte) counter 
     
    957894 
    958895 if ( wait == ROAR_VS_WAIT ) { 
    959   return roar_vs_latency(vss, backend, error); 
     896  _ckasync(0); 
     897 
     898  pos = roar_vs_position(vss, backend, error); 
     899  if (pos == -1) { 
     900   _seterrre(); 
     901   return 0; 
     902  } 
     903 
     904  if ( vss->writec == 0 ) { 
     905   lioc = vss->readc; 
     906  } else { 
     907   //printf("writec=%zu\n", vss->writec); 
     908   lioc = vss->writec; 
     909  } 
     910 
     911  bps = roar_info2samplesize(&(vss->info)); 
     912 
     913  if ( bps == -1 ) { 
     914   _seterrre(); 
     915   return 0; 
     916  } 
     917 
     918  lpos = (lioc*8) / bps; 
     919 
     920  lag = (signed long long int)lpos - (signed long long int)pos; 
     921  lag /= vss->info.channels; 
     922 
     923  // we now have the lag in frames 
     924  // return value are mus 
     925  // so we need to multiply with 1s/mus and 
     926  // multiply by 1/rate 
     927 
     928  lag *= 1000000; // 1s/mus 
     929  lag /= vss->info.rate; 
     930 
     931#ifdef _HAVE_SOCKOPT 
     932  if (vss->latc.target > vss->latc.minlag) { 
     933   roar_vs_latency_managed(vss, lag); 
     934  } 
     935#endif 
     936 
     937  vss->async.read_latency = 1; 
     938 
     939  if ( lag == 0 ) { 
     940   _seterr(ROAR_ERROR_NONE); 
     941  } 
     942 
     943  return lag; 
    960944 } else if ( wait == ROAR_VS_NOWAIT ) { 
    961945  vss->async.read_latency = 1; 
Note: See TracChangeset for help on using the changeset viewer.