Changeset 2012

Show
Ignore:
Timestamp:
2006-02-09 18:03:39 (3 years ago)
Author:
conrad
Message:

oggz_read_*(): when reading is stopped by the user, cache the return value
and return it on the subsequent read call (unless no data has been read, in
which case return it on this call as before). This ensures that when the
user returns OGGZ_STOP_OK or OGGZ_STOP_ERR in a read callback, that condition
is acknowledged in a subsequent call to oggz_read_*().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • liboggz/trunk/src/liboggz/oggz.c

    r817 r2012  
    8484  oggz->offset = 0; 
    8585  oggz->offset_data_begin = 0; 
     86 
     87  oggz->cb_next = 0; 
    8688 
    8789  oggz->streams = oggz_vector_new (); 
  • liboggz/trunk/src/liboggz/oggz_private.h

    r817 r2012  
    199199  off_t offset_data_begin; /* offset of unit 0 page start */ 
    200200 
     201  int cb_next; 
     202 
    201203  OggzVector * streams; 
    202204  int all_at_eos; /* all streams are at eos */ 
  • liboggz/trunk/src/liboggz/oggz_read.c

    r806 r2012  
    286286 
    287287      if(result == -1) { 
    288         /* hole in the data. */ 
     288#ifdef DEBUG 
     289        printf ("oggz_read_sync: hole in the data\n"); 
     290#endif 
    289291        return -7; 
    290292      } 
     
    368370} 
    369371 
     372/* Map callback return values to error return values for oggz_read_*() */ 
     373static int 
     374map_return_value_to_error (int cb_ret) 
     375{ 
     376  switch (cb_ret) { 
     377  case OGGZ_CONTINUE: 
     378  case OGGZ_READ_EMPTY: 
     379    return OGGZ_CONTINUE; 
     380  case OGGZ_STOP_OK: 
     381    return OGGZ_ERR_READ_STOP_OK; 
     382  case OGGZ_STOP_ERR: 
     383    return OGGZ_ERR_READ_STOP_ERR; 
     384  default: 
     385    return OGGZ_ERR_READ_STOP_ERR; 
     386  } 
     387} 
     388 
    370389long 
    371390oggz_read (OGGZ * oggz, long n) 
     
    380399  if (oggz->flags & OGGZ_WRITE) { 
    381400    return OGGZ_ERR_INVALID; 
     401  } 
     402 
     403  if ((cb_ret = oggz->cb_next) != OGGZ_CONTINUE) { 
     404    oggz->cb_next = 0; 
     405    return map_return_value_to_error (cb_ret); 
    382406  } 
    383407 
     
    432456    } 
    433457 
    434     switch (cb_ret) { 
    435     case OGGZ_CONTINUE: case OGGZ_READ_EMPTY:  
    436 #ifdef DEBUG 
    437       printf ("oggz_read: nread==0, cb_ret==%d, returning 0\n", cb_ret); 
    438 #endif 
    439       return 0; break; 
    440     case OGGZ_STOP_ERR: return OGGZ_ERR_READ_STOP_ERR; break; 
    441     case OGGZ_STOP_OK: default: return OGGZ_ERR_READ_STOP_OK; break; 
    442     } 
     458    return map_return_value_to_error (cb_ret); 
     459 
     460  } else { 
     461    if (cb_ret == OGGZ_READ_EMPTY) cb_ret = OGGZ_CONTINUE; 
     462    oggz->cb_next = cb_ret; 
    443463  } 
    444464 
     
    461481  } 
    462482 
     483  if ((cb_ret = oggz->cb_next) != OGGZ_CONTINUE) { 
     484    oggz->cb_next = 0; 
     485    return map_return_value_to_error (cb_ret); 
     486  } 
     487 
    463488  reader = &oggz->x.reader; 
    464489 
     
    473498#endif 
    474499 
    475   while (cb_ret != -1 && cb_ret != 1 && /* !oggz->eos && */ remaining > 0) { 
     500  while (cb_ret != OGGZ_STOP_ERR && cb_ret != OGGZ_STOP_OK  && 
     501         /* !oggz->eos && */ remaining > 0) { 
    476502    bytes = MIN (remaining, 4096); 
    477503    buffer = ogg_sync_buffer (&reader->ogg_sync, bytes); 
     
    488514  if (cb_ret == OGGZ_STOP_ERR) oggz_purge (oggz); 
    489515 
    490   /* Don't return 0 unless it's actually an EOF condition */ 
    491516  if (nread == 0) { 
    492     switch (cb_ret) { 
    493     case OGGZ_CONTINUE: return 0; break; 
    494     case OGGZ_READ_EMPTY: 
    495 #ifdef DEBUG 
    496       printf ("oggz_read_input: OUT EMPTY\n"); 
    497 #endif 
     517    /* Don't return 0 unless it's actually an EOF condition */ 
     518    if (cb_ret == OGGZ_READ_EMPTY) { 
    498519      return OGGZ_ERR_READ_STOP_OK; 
    499       break; 
    500     case OGGZ_STOP_ERR: return OGGZ_ERR_READ_STOP_ERR; break; 
    501     case OGGZ_STOP_OK: default: return OGGZ_ERR_READ_STOP_OK; break; 
    502     } 
     520    } else { 
     521      return map_return_value_to_error (cb_ret); 
     522    } 
     523  } else { 
     524    if (cb_ret == OGGZ_READ_EMPTY) cb_ret = OGGZ_CONTINUE; 
     525    oggz->cb_next = cb_ret; 
    503526  } 
    504527 
  • liboggz/trunk/src/tests/read-stop-ok.c

    r387 r2012  
    132132  OGGZ * reader, * writer; 
    133133  unsigned char buf[READ_SIZE]; 
    134   long n, remaining
     134  long n, remaining, err
    135135 
    136136  INFO ("Testing ability to pause while reading (OGGZ_STOP_OK)"); 
     
    154154    n = oggz_read_input (reader, buf, remaining); 
    155155 
    156     if (n < remaining) 
     156    if (n == OGGZ_ERR_READ_STOP_OK) { 
    157157      INFO ("+ Interrupted read detected"); 
     158    } else { 
     159      remaining -= n; 
    158160 
    159     remaining -= n; 
     161      err = oggz_read_input (reader, buf+n, remaining); 
     162      if (err == OGGZ_ERR_READ_STOP_OK) { 
     163        INFO ("+ Interrupted read detected"); 
     164      } else { 
     165        FAIL ("Interrupted read not reported"); 
     166      } 
     167    } 
    160168 
    161169    n = oggz_read_input (reader, buf+n, remaining);