1 /*
2 	out123_int: internal header for libout123
3 
4 	copyright ?-2016 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 Michael Hipp (some traces left)
7 */
8 
9 #ifndef _MPG123_OUT123_INT_H_
10 #define _MPG123_OUT123_INT_H_
11 
12 #include "config.h"
13 #include "intsym.h"
14 #include "abi_align.h"
15 #include "compat.h"
16 #include "out123.h"
17 #include "module.h"
18 
19 #ifndef NOXFERMEM
20 #include "xfermem.h"
21 #endif
22 
23 /* 3% rate tolerance */
24 #define AUDIO_RATE_TOLERANCE	  3
25 
26 /* Keep those internally? To the outside, it's just a selection of
27    driver modules. */
28 enum {
29 	DECODE_TEST,  /* "test" */
30 	DECODE_AUDIO, /* gone */
31 	DECODE_FILE,  /* "raw" */
32 	DECODE_BUFFER, /* internal use only, if at all */
33 	DECODE_WAV,    /* wav */
34 	DECODE_AU,     /* au */
35 	DECODE_CDR,    /* cdr */
36 	DECODE_AUDIOFILE /* internal use only, if at all */
37 };
38 
39 /* Playback states mostly for the buffer process.
40    Maybe also used in main program. */
41 enum playstate
42 {
43 	play_dead = 0 /* nothing playing, nothing loaded */
44 ,	play_stopped  /* driver present, but no device configured/opened */
45 /* The ordering is used, state > play_stopped means some device is opened. */
46 ,	play_paused   /* paused, ready to continue, device still active */
47 ,	play_live     /* playing right now */
48 };
49 
50 struct out123_struct
51 {
52 	enum out123_error errcode;
53 #ifndef NOXFERMEM
54 	/* If buffer_pid >= 0, there is a separate buffer process actually
55 	   handling everything, this instance here is then only a proxy. */
56 	int buffer_pid;
57 	int buffer_fd[2];
58 	txfermem *buffermem;
59 #endif
60 
61 	int fn;			/* filenumber */
62 	void *userptr;	/* driver specific pointer */
63 
64 	/* Callbacks */
65 	int (*open)(out123_handle *);
66 	int (*get_formats)(out123_handle *);
67 	int (*write)(out123_handle *, unsigned char *,int);
68 	void (*flush)(out123_handle *); /* flush == drop != drain */
69 	void (*drain)(out123_handle *);
70 	int (*close)(out123_handle *);
71 	int (*deinit)(out123_handle *);
72 
73 	/* the loaded that has set the above */
74 	mpg123_module_t *module;
75 
76 	char *name;	    /* optional name of this instance */
77 	char *realname; /* name possibly changed by backend */
78 	char *driver;	/* driver (module) name */
79 	char *device;	/* device name */
80 	int   flags;	/* some bits; namely headphone/speaker/line */
81 	long rate;		/* sample rate */
82 	long gain;		/* output gain */
83 	int channels;	/* number of channels */
84 	int format;		/* encoding (TODO: rename this to "encoding"!) */
85 	int framesize;	/* Output needs data in chunks of framesize bytes. */
86 	enum playstate state; /* ... */
87 	int auxflags;	/* For now just one: quiet mode (for probing). */
88 	int propflags;	/* Property flags, set by driver. */
89 	double preload;	/* buffer fraction to preload before play */
90 	int verbose;	/* verbosity to stderr */
91 	double device_buffer; /* device buffer in seconds */
92 	char *bindir;	/* OUT123_BINDIR */
93 /* TODO int intflag;   ... is it really useful/necessary from the outside? */
94 };
95 
96 /* Lazy. */
97 #define AOQUIET ((ao->auxflags | ao->flags) & OUT123_QUIET)
98 #define AOVERBOSE(v) (!AOQUIET && ao->verbose >= (v))
99 #define GOOD_WRITEVAL(fd, val)     (unintr_write(fd, &(val), sizeof((val))) == sizeof((val)))
100 #define GOOD_WRITEBUF(fd, addr, n) (unintr_write(fd, (addr), (n)) == (n))
101 #define GOOD_READVAL(fd, val)      (unintr_read(fd, &(val), sizeof((val))) == sizeof((val)))
102 #define GOOD_READBUF(fd, addr, n)  (unintr_read(fd, (addr), (n)) == (n))
103 
104 struct audio_format_name {
105 	int  val;
106 	char *name;
107 	char *sname;
108 };
109 
110 int write_parameters(out123_handle *ao, int fd);
111 int read_parameters(out123_handle *ao
112 ,	int fd, byte *prebuf, int *preoff, int presize);
113 
114 #endif
115 
116