player-mp3.c
branchtrunk
changeset 23 3b14b8aacaa0
parent 22 93aaf15c145a
child 29 640ce9201139
     1.1 --- a/player-mp3.c	Tue Feb 03 20:33:04 2009 +0800
     1.2 +++ b/player-mp3.c	Wed Feb 04 12:30:14 2009 +0800
     1.3 @@ -909,13 +909,13 @@
     1.4  {
     1.5    if(MP3Setup.BgrScan) {
     1.6      if(!thr && throttle) {
     1.7 -      db(printf("mgr: bgr-scan -> run (%d)\n",time_ms()))
     1.8 +      db(printf("mgr: bgr-scan -> run (%llu)\n",cTimeMs::Now()))
     1.9        listMutex.Lock();
    1.10        throttle=false; bgCond.Broadcast();
    1.11        listMutex.Unlock();
    1.12        }
    1.13      if(thr && !throttle) {
    1.14 -      db(printf("mgr: bgr-scan -> throttle (%d)\n",time_ms()))
    1.15 +      db(printf("mgr: bgr-scan -> throttle (%llu)\n",cTimeMs::Now()))
    1.16        throttle=true;
    1.17        }
    1.18      }
    1.19 @@ -1583,12 +1583,12 @@
    1.20    const unsigned char *p=0;
    1.21    int pc=0, readindex=0;
    1.22    bool imageValid=true;
    1.23 -  int imageCheck=0;
    1.24 +  cTimeMs imageCheck;
    1.25  #ifdef DEBUG
    1.26    int beat=0;
    1.27  #endif
    1.28  #ifdef DEBUG_DELAY
    1.29 -  int lastwrite=0;
    1.30 +  cTimeMs lastwrite(2000000);
    1.31  #endif
    1.32  
    1.33    dsyslog("mp3: player thread started (pid=%d)", getpid());
    1.34 @@ -1622,13 +1622,13 @@
    1.35      Lock();
    1.36  
    1.37  next:
    1.38 -    if(!pframe && playing && !imageValid && imageCheck<time_ms()) {
    1.39 +    if(!pframe && playing && !imageValid && imageCheck.Elapsed()) {
    1.40        unsigned char *mem;
    1.41        int len;
    1.42 -      imageCheck=time_ms()+250;
    1.43 +      imageCheck.Set(250);
    1.44        imageValid=playing->Image(mem,len);
    1.45        if(mem) {
    1.46 -        if(playindex) SLEEP(80); // stillpicture ioctl freezes without this
    1.47 +        if(playindex) cCondWait::SleepMs(80); // stillpicture ioctl freezes without this
    1.48          DeviceStillPicture(mem,len);
    1.49          free(mem);
    1.50          }
    1.51 @@ -1648,10 +1648,9 @@
    1.52      if(pframe) {
    1.53  #ifdef DEBUG_DELAY
    1.54        {
    1.55 -      int now=time_ms();
    1.56 -      if(lastwrite && lastwrite<now-(DEBUG_DELAY+50))
    1.57 -        printf("mp3: write delayed %d ms\n",now-lastwrite);
    1.58 -      lastwrite=now;
    1.59 +      if(lastwrite.TimedOut())
    1.60 +        printf("mp3: write delayed %llu ms\n",lastwrite.Elapsed());
    1.61 +      lastwrite.Set(DEBUG_DELAY+50);
    1.62        }
    1.63  #endif
    1.64        int w=output->Output(p,pc,SOF);
    1.65 @@ -1714,12 +1713,11 @@
    1.66          case msDecode:
    1.67            {
    1.68  #ifdef DEBUG_DELAY
    1.69 -          int now=time_ms();
    1.70 +          cTimeMs check(DEBUG_DELAY);
    1.71  #endif
    1.72            struct Decode *ds=decoder->Decode();
    1.73  #ifdef DEBUG_DELAY
    1.74 -          now=time_ms()-now;
    1.75 -          if(now>DEBUG_DELAY) printf("mp3: decode delayed %d ms\n",now);
    1.76 +          if(check.TimedOut()) printf("mp3: decode delayed %llu ms\n",check.Elapsed());
    1.77  #endif
    1.78            switch(ds->status) {
    1.79              case dsPlay:
    1.80 @@ -1837,14 +1835,14 @@
    1.81      else if(playMode!=pmPlay) {
    1.82        mgr->Throttle(false);
    1.83        if(!imageValid)
    1.84 -        SLEEP(100);
    1.85 +        cCondWait::SleepMs(100);
    1.86        else {
    1.87          playModeMutex.Lock();
    1.88          if(playMode!=pmPlay) WaitPlayMode(playMode,true);
    1.89          playModeMutex.Unlock();
    1.90          }
    1.91  #ifdef DEBUG_DELAY
    1.92 -      lastwrite=0;
    1.93 +      lastwrite.Set(2000000);
    1.94  #endif
    1.95        }
    1.96      else if(state!=msWait && ringBuffer->Available()<(MP3BUFSIZE*50/100)) {