Debian Codegraph @

src/libout123/modules/arts.c

raw
1 /*
2 arts: audio output via aRts Sound Daemon
3
4 copyright 2007-2020 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
7 initially written by Stefan Lenselink ([email protected])
8 */
9
10
11 #include "../out123_int.h"
12 #include <artsc.h>
13 #include "../../common/debug.h"
14
15 typedef struct
16 {
17 arts_stream_t arse; /* That's short for ARts StrEam;-) */
18 } mpg123_arts_t;
19
20 static int open_arts(out123_handle *ao)
21 {
22 short bits = 0;
23 if(!ao) return -1;
24
25 if(ao->format < 0)
26 {
27 ao->format = MPG123_ENC_SIGNED_16;
28 ao->rate = 44100;
29 ao->channels = 2;
30 }
31 /* Trial and error revealed these two formats to work with aRts. */
32 if(ao->format == MPG123_ENC_SIGNED_16) bits = 16;
33 else if(ao->format == MPG123_ENC_UNSIGNED_8) bits = 8;
34 else return -1;
35
36 /* Initialize the aRts lib*/
37 arts_init();
38 /* Open a stream to the aRts server */
39 ((mpg123_arts_t*)ao->userptr)->arse = arts_play_stream( ao->rate, bits, ao->channels, "mpg123" );
40 /* Yeah, black box and all... it's still a pointer that is NULL on error. */
41 return (void*)((mpg123_arts_t*)ao->userptr)->arse == NULL ? -1 : 0;
42 }
43
44 static int get_formats_arts(out123_handle *ao)
45 {
46 /* aRts runs not everything, but any rate. */
47 return MPG123_ENC_SIGNED_16|MPG123_ENC_UNSIGNED_8;
48 }
49
50 static int write_arts(out123_handle *ao,unsigned char *buf,int len)
51 {
52 /* PIPE the PCM forward to the aRts Sound Daemon */
53 return arts_write( ((mpg123_arts_t*)ao->userptr)->arse , buf, len);
54 }
55
56 static int close_arts(out123_handle *ao)
57 {
58 /* Close the connection! */
59 arts_close_stream( ((mpg123_arts_t*)ao->userptr)->arse );
60 /* Free the memory allocated*/
61 arts_free();
62 return 0;
63 }
64
65 static void flush_arts(out123_handle *ao)
66 {
67 /* aRts doesn't have a flush statement! */
68 }
69
70 static void deinit_arts(out123_handle* ao)
71 {
72 if(ao->userptr)
73 {
74 free(ao->userptr);
75 ao->userptr = NULL;
76 }
77 arts_free();
78 }
79
80 static int init_arts(out123_handle* ao)
81 {
82 if (ao==NULL) return -1;
83
84 ao->userptr = malloc(sizeof(mpg123_arts_t));
85 if(ao->userptr == NULL)
86 {
87 if(!AOQUIET)
88 error("Out of memory!");
89 return -1;
90 }
91 /* clear it to have a consistent state */
92 memset(ao->userptr, 0, sizeof(mpg123_arts_t));
93 /* Set callbacks */
94 ao->open = open_arts;
95 ao->flush = flush_arts;
96 ao->write = write_arts;
97 ao->get_formats = get_formats_arts;
98 ao->close = close_arts;
99 ao->deinit = deinit_arts;
100 /* Success */
101 return 0;
102 }
103
104 /*
105 Module information data structure
106 */
107 mpg123_module_t mpg123_output_module_info = {
108 /* api_version */ MPG123_MODULE_API_VERSION,
109 /* name */ "arts",
110 /* description */ "Output audio using aRts Sound Daemon",
111 /* revision */ "$Rev: $",
112 /* handle */ NULL,
113
114 /* init_output */ init_arts,
115 };
116
117