Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.         reader: reading input data
  3.  
  4.         copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
  5.         see COPYING and AUTHORS files in distribution or http://mpg123.org
  6.         initially written by Thomas Orgis (after code from Michael Hipp)
  7. */
  8.  
  9. #ifndef MPG123_READER_H
  10. #define MPG123_READER_H
  11.  
  12. #include "config.h"
  13. #include "mpg123.h"
  14.  
  15. struct buffy
  16. {
  17.         unsigned char *data;
  18.         ssize_t size;
  19.         struct buffy *next;
  20. };
  21.  
  22. struct bufferchain
  23. {
  24.         struct buffy* first; /* The beginning of the chain. */
  25.         struct buffy* last;  /* The end...    of the chain. */
  26.         ssize_t size;        /* Aggregated size of all buffies. */
  27.         /* These positions are relative to buffer chain beginning. */
  28.         ssize_t pos;         /* Position in whole chain. */
  29.         ssize_t firstpos;    /* The point of return on non-forget() */
  30.         /* The "real" filepos is fileoff + pos. */
  31.         off_t fileoff;       /* Beginning of chain is at this file offset. */
  32. };
  33.  
  34. struct reader_data
  35. {
  36.         off_t filelen; /* total file length or total buffer size */
  37.         off_t filepos; /* position in file or position in buffer chain */
  38.         int   filept;
  39.         int   flags;
  40. #ifndef WIN32
  41.         long timeout_sec;
  42. #endif
  43.         ssize_t (*fdread) (mpg123_handle *, void *, size_t);
  44.         /* User can replace the read and lseek functions. The r_* are the stored replacement functions or NULL,
  45.            The second two pointers are the actual workers (default map to POSIX read/lseek). */
  46.         ssize_t (*r_read) (int fd, void *buf, size_t count);
  47.         off_t   (*r_lseek)(int fd, off_t offset, int whence);
  48.         ssize_t (*read) (int fd, void *buf, size_t count);
  49.         off_t   (*lseek)(int fd, off_t offset, int whence);
  50.         /* Buffered readers want that abstracted, set internally. */
  51.         ssize_t (*fullread)(mpg123_handle *, unsigned char *, ssize_t);
  52.         struct bufferchain buffer; /* Not dynamically allocated, these few struct bytes aren't worth the trouble. */
  53. };
  54.  
  55. /* start to use off_t to properly do LFS in future ... used to be long */
  56. struct reader
  57. {
  58.         int     (*init)           (mpg123_handle *);
  59.         void    (*close)          (mpg123_handle *);
  60.         ssize_t (*fullread)       (mpg123_handle *, unsigned char *, ssize_t);
  61.         int     (*head_read)      (mpg123_handle *, unsigned long *newhead);    /* succ: TRUE, else <= 0 (FALSE or READER_MORE) */
  62.         int     (*head_shift)     (mpg123_handle *, unsigned long *head);       /* succ: TRUE, else <= 0 (FALSE or READER_MORE) */
  63.         off_t   (*skip_bytes)     (mpg123_handle *, off_t len);                 /* succ: >=0, else error or READER_MORE         */
  64.         int     (*read_frame_body)(mpg123_handle *, unsigned char *, int size);
  65.         int     (*back_bytes)     (mpg123_handle *, off_t bytes);
  66.         int     (*seek_frame)     (mpg123_handle *, off_t num);
  67.         off_t   (*tell)           (mpg123_handle *);
  68.         void    (*rewind)         (mpg123_handle *);
  69.         void    (*forget)         (mpg123_handle *);
  70. };
  71.  
  72. /* Open a file by path or use an opened file descriptor. */
  73. int open_stream(mpg123_handle *, const char *path, int fd);
  74.  
  75. /* feed based operation has some specials */
  76. int open_feed(mpg123_handle *);
  77. /* externally called function, returns 0 on success, -1 on error */
  78. int  feed_more(mpg123_handle *fr, const unsigned char *in, long count);
  79. void feed_forget(mpg123_handle *fr);  /* forget the data that has been read (free some buffers) */
  80. off_t feed_set_pos(mpg123_handle *fr, off_t pos); /* Set position (inside available data if possible), return wanted byte offset of next feed. */
  81.  
  82. void open_bad(mpg123_handle *);
  83.  
  84. #define READER_FD_OPENED 0x1
  85. #define READER_ID3TAG    0x2
  86. #define READER_SEEKABLE  0x4
  87. #define READER_BUFFERED  0x8
  88. #define READER_NONBLOCK  0x20
  89.  
  90. #define READER_STREAM 0
  91. #define READER_ICY_STREAM 1
  92. #define READER_FEED       2
  93. /* These two add a little buffering to enable small seeks for peek ahead. */
  94. #define READER_BUF_STREAM 3
  95. #define READER_BUF_ICY_STREAM 4
  96.  
  97. #ifdef READ_SYSTEM
  98. #define READER_SYSTEM 5
  99. #define READERS 6
  100. #else
  101. #define READERS 5
  102. #endif
  103.  
  104. #define READER_ERROR MPG123_ERR
  105. #define READER_MORE  MPG123_NEED_MORE
  106.  
  107. #endif
  108.