Allow read as well as read_block
authorJames Stembridge <jstembridge@users.sourceforge.net>
Sat, 28 May 2005 09:26:59 +0000
changeset 7469a470c338149c
parent 7468 004abca2b8cc
child 7470 2618e9605154
Allow read as well as read_block

CVS patchset: 7574
CVS date: 2005/05/28 09:26:59
src/input/input_cdda.c
     1.1 --- a/src/input/input_cdda.c	Sat May 28 02:41:38 2005 +0000
     1.2 +++ b/src/input/input_cdda.c	Sat May 28 09:26:59 2005 +0000
     1.3 @@ -20,7 +20,7 @@
     1.4   * Compact Disc Digital Audio (CDDA) Input Plugin 
     1.5   *   by Mike Melanson (melanson@pcisys.net)
     1.6   *
     1.7 - * $Id: input_cdda.c,v 1.71 2005/02/07 23:58:57 tmattern Exp $
     1.8 + * $Id: input_cdda.c,v 1.72 2005/05/28 09:26:59 jstembridge Exp $
     1.9   */
    1.10  
    1.11  #ifdef HAVE_CONFIG_H
    1.12 @@ -2098,24 +2098,15 @@
    1.13  
    1.14  static off_t cdda_plugin_read (input_plugin_t *this_gen, char *buf, off_t len) {
    1.15  
    1.16 +  cdda_input_plugin_t *this = (cdda_input_plugin_t *) this_gen;
    1.17 +  int err = 0;
    1.18 +
    1.19    /* only allow reading in block-sized chunks */
    1.20 -
    1.21 -  return 0;
    1.22 -}
    1.23 -
    1.24 -static buf_element_t *cdda_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo, 
    1.25 -  off_t nlen) {
    1.26 -
    1.27 -  cdda_input_plugin_t *this = (cdda_input_plugin_t *) this_gen;
    1.28 -  buf_element_t *buf;
    1.29 -  unsigned char frame_data[CD_RAW_FRAME_SIZE];
    1.30 -  int err = 0;
    1.31 -
    1.32 -  if (nlen != CD_RAW_FRAME_SIZE)
    1.33 -    return NULL;
    1.34 +  if (len != CD_RAW_FRAME_SIZE)
    1.35 +    return 0;
    1.36  
    1.37    if (this->current_frame > this->last_frame)
    1.38 -    return NULL;
    1.39 +    return 0;
    1.40  
    1.41    /* populate frame cache */
    1.42    if( this->cache_first == -1 ||
    1.43 @@ -2143,16 +2134,28 @@
    1.44    }
    1.45  
    1.46    if( err < 0 )
    1.47 -    return NULL;
    1.48 +    return 0;
    1.49      
    1.50 -  memcpy(frame_data, this->cache[this->current_frame-this->cache_first], CD_RAW_FRAME_SIZE);
    1.51 +  memcpy(buf, this->cache[this->current_frame-this->cache_first], CD_RAW_FRAME_SIZE);
    1.52    this->current_frame++;
    1.53  
    1.54 +  return CD_RAW_FRAME_SIZE;
    1.55 +}
    1.56 +
    1.57 +static buf_element_t *cdda_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo, 
    1.58 +  off_t nlen) {
    1.59 +
    1.60 +  buf_element_t *buf;
    1.61 +
    1.62    buf = fifo->buffer_pool_alloc(fifo);
    1.63    buf->content = buf->mem;
    1.64    buf->type = BUF_DEMUX_BLOCK;
    1.65 -  buf->size = CD_RAW_FRAME_SIZE;
    1.66 -  memcpy(buf->mem, frame_data, CD_RAW_FRAME_SIZE);
    1.67 +
    1.68 +  buf->size = cdda_plugin_read(this_gen, buf->content, nlen);
    1.69 +  if (buf->size == 0) {
    1.70 +    buf->free_buffer(buf);
    1.71 +    buf = NULL;
    1.72 +  }
    1.73  
    1.74    return buf;
    1.75  }