| 1 |
/* |
| 2 |
streamdump: I/O interposing for reading input streams |
| 3 |
|
| 4 |
This initially was about dumping a copy of the input data, as read |
| 5 |
by libmpg123. Now it is a generic interposer to wrap around plain file |
| 6 |
and network stream reading. |
| 7 |
|
| 8 |
copyright 2010-2022 by the mpg123 project - free software under the terms of the LGPL 2.1 |
| 9 |
see COPYING and AUTHORS files in distribution or http://mpg123.org |
| 10 |
initially written by Thomas Orgis |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef STREAMDUMP_H |
| 14 |
#define STREAMDUMP_H |
| 15 |
|
| 16 |
#include "mpg123app.h" |
| 17 |
|
| 18 |
#ifdef NET123 |
| 19 |
#include "net123.h" |
| 20 |
#endif |
| 21 |
#ifdef NETWORK |
| 22 |
#include "httpget.h" |
| 23 |
#endif |
| 24 |
|
| 25 |
// The stream is either addressed via file descriptor or net123 handle. |
| 26 |
struct stream |
| 27 |
{ |
| 28 |
char buf[256]; // buffer for getline |
| 29 |
char *bufp; // read pointer in buffer |
| 30 |
int fill; // bytes in buffer |
| 31 |
int fd; // if > 0: plain file descriptor or win32 net socket |
| 32 |
struct httpdata htd; |
| 33 |
#ifdef NET123 |
| 34 |
net123_handle *nh; // if != null: a net123 stream |
| 35 |
#endif |
| 36 |
}; |
| 37 |
|
| 38 |
// Open a stream resource, creating and returning a new handle. |
| 39 |
struct stream * stream_open(const char *url); |
| 40 |
// Read lines, with arbitrary line end, which is stripped. |
| 41 |
// Return number of bytes in line (including closing zero byte) or error < 0. |
| 42 |
// End of file returns zero, consequently. |
| 43 |
mpg123_ssize_t stream_getline(struct stream *sd, mpg123_string *line); |
| 44 |
void stream_close(struct stream *sd); |
| 45 |
|
| 46 |
// Use an open stream object to optionally prepare the dump and |
| 47 |
// link up input to the mpg123 handle. |
| 48 |
// Can be called repeatedly to switch input methods with new |
| 49 |
// stream objects, but keeping a stream dump file open. |
| 50 |
// Return value is 0 for no error, -1 when bad. |
| 51 |
int dump_setup(struct stream *sd, mpg123_handle *mh); |
| 52 |
// Just close the dump output, not touching anything else. |
| 53 |
void dump_close(void); |
| 54 |
|
| 55 |
#endif |