2645
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
2770
|
3
|
2921
|
4 #include <linux/em8300.h>
|
2770
|
5 #include <sys/ioctl.h>
|
2645
|
6 #include <unistd.h>
|
2770
|
7 #include <sys/time.h>
|
2645
|
8 #include <sys/types.h>
|
2770
|
9 #include <sys/stat.h>
|
|
10 #include <fcntl.h>
|
2645
|
11
|
|
12 #include "../config.h"
|
|
13
|
|
14 #include "afmt.h"
|
|
15
|
|
16 #include "audio_out.h"
|
|
17 #include "audio_out_internal.h"
|
|
18
|
2770
|
19 extern int verbose;
|
2645
|
20
|
|
21 static ao_info_t info =
|
|
22 {
|
|
23 "DXR3/H+ audio out",
|
|
24 "dxr3",
|
|
25 "David Holm <dholm@iname.com>",
|
|
26 ""
|
|
27 };
|
|
28
|
|
29 LIBAO_EXTERN(dxr3)
|
|
30
|
|
31 // there are some globals:
|
|
32 // ao_samplerate
|
|
33 // ao_channels
|
|
34 // ao_format
|
|
35 // ao_bps
|
|
36 // ao_outburst
|
|
37 // ao_buffersize
|
|
38
|
2921
|
39 //static char *em8300_ma="/dev/em8300_ma";
|
2770
|
40 static audio_buf_info dxr3_buf_info;
|
2921
|
41 static int fd_control = 0, fd_audio = 0;
|
2770
|
42
|
2645
|
43 // to set/get/query special features/parameters
|
|
44 static int control(int cmd,int arg)
|
|
45 {
|
|
46 switch(cmd)
|
|
47 {
|
|
48 case AOCONTROL_QUERY_FORMAT:
|
|
49 return CONTROL_TRUE;
|
|
50 case AOCONTROL_GET_VOLUME:
|
|
51 case AOCONTROL_SET_VOLUME:
|
2770
|
52 return CONTROL_OK;
|
|
53 return CONTROL_ERROR;
|
2645
|
54 }
|
2770
|
55 return CONTROL_UNKNOWN;
|
2645
|
56 }
|
|
57
|
|
58 // open & setup audio device
|
|
59 // return: 1=success 0=fail
|
|
60 static int init(int rate,int channels,int format,int flags)
|
|
61 {
|
2921
|
62 int ioval;
|
|
63 fd_audio = open( "/dev/em8300_ma", O_WRONLY );
|
|
64 if( fd_audio < 0 )
|
|
65 {
|
2968
|
66 printf("AO: [dxr3] Can't open audio device /dev/em8300_ma -> nosound\n");
|
2921
|
67 return 0;
|
|
68 }
|
2770
|
69
|
2921
|
70 fd_control = open( "/dev/em8300", O_WRONLY );
|
|
71 if( fd_control < 0 )
|
2770
|
72 {
|
2968
|
73 printf("AO: [dxr3] Can't open em8300 control /dev/em8300\n");
|
2770
|
74 return 0;
|
|
75 }
|
|
76
|
|
77 ao_format = format;
|
2968
|
78 if( ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_format) < 0 )
|
|
79 printf( "AO: [dxr3] Unable to set audio format\n" );
|
2770
|
80 if(format == AFMT_AC3 && ao_format != AFMT_AC3)
|
|
81 {
|
2968
|
82 printf("AO: [dxr3] Can't set audio device /dev/em8300_ma to AC3 output\n");
|
2770
|
83 return 0;
|
|
84 }
|
2968
|
85 printf("AO: [dxr3] Sample format: %s (requested: %s)\n",
|
2770
|
86 audio_out_format_name(ao_format), audio_out_format_name(format));
|
|
87
|
|
88 if(format != AFMT_AC3)
|
|
89 {
|
|
90 ao_channels=channels-1;
|
2968
|
91 if( ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_channels) < 0 )
|
|
92 printf( "AO: [dxr3] Unable to set number of channels\n" );
|
2770
|
93
|
|
94 // set rate
|
|
95 ao_samplerate=rate;
|
2968
|
96 if( ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_samplerate) < 0 )
|
|
97 printf( "AO: [dxr3] Unable to set samplerate\n" );
|
|
98 printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_samplerate,rate);
|
2770
|
99 }
|
|
100
|
2968
|
101 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 )
|
|
102 {
|
2770
|
103 int r=0;
|
2968
|
104 printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
|
|
105 if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 )
|
|
106 {
|
|
107 printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_outburst );
|
|
108 }
|
|
109 else
|
|
110 {
|
2770
|
111 ao_outburst=r;
|
2968
|
112 printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_outburst);
|
2770
|
113 }
|
2968
|
114 }
|
|
115 else
|
|
116 {
|
|
117 printf("AO: [dxr3] frags: %3d/%d (%d bytes/frag) free: %6d\n",
|
|
118 dxr3_buf_info.fragments+1, dxr3_buf_info.fragstotal, dxr3_buf_info.fragsize, dxr3_buf_info.bytes);
|
2770
|
119 if(ao_buffersize==-1) ao_buffersize=dxr3_buf_info.bytes;
|
|
120 ao_outburst=dxr3_buf_info.fragsize;
|
|
121 }
|
|
122
|
|
123 if(ao_buffersize==-1){
|
|
124 // Measuring buffer size:
|
|
125 void* data;
|
|
126 ao_buffersize=0;
|
|
127 #ifdef HAVE_AUDIO_SELECT
|
|
128 data=malloc(ao_outburst); memset(data,0,ao_outburst);
|
|
129 while(ao_buffersize<0x40000){
|
|
130 fd_set rfds;
|
|
131 struct timeval tv;
|
2921
|
132 FD_ZERO(&rfds); FD_SET(fd_audio,&rfds);
|
2770
|
133 tv.tv_sec=0; tv.tv_usec = 0;
|
2921
|
134 if(!select(fd_audio+1, NULL, &rfds, NULL, &tv)) break;
|
|
135 write(fd_audio,data,ao_outburst);
|
2770
|
136 ao_buffersize+=ao_outburst;
|
2645
|
137 }
|
2770
|
138 free(data);
|
|
139 if(ao_buffersize==0){
|
2968
|
140 printf("\nAO: [dxr3] *** Your audio driver DOES NOT support select() ***\n");
|
2770
|
141 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
|
|
142 return 0;
|
|
143 }
|
|
144 #endif
|
|
145 }
|
2645
|
146
|
2921
|
147 ioval = EM8300_PLAYMODE_PLAY;
|
2968
|
148 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
|
|
149 printf( "AO: [dxr3] Unable to set playmode\n" );
|
2921
|
150 close( fd_control );
|
2770
|
151
|
|
152 return 1;
|
2645
|
153 }
|
|
154
|
|
155 // close audio device
|
|
156 static void uninit()
|
|
157 {
|
2968
|
158 printf( "AO: [dxr3] Uninitializing\n" );
|
|
159 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
|
|
160 printf( "AO: [dxr3] Unable to reset device\n" );
|
2921
|
161 close( fd_audio );
|
2645
|
162 }
|
|
163
|
|
164 // stop playing and empty buffers (for seeking/pause)
|
|
165 static void reset()
|
|
166 {
|
2968
|
167 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
|
|
168 printf( "AO: [dxr3] Unable to reset device\n" );
|
2645
|
169 }
|
|
170
|
|
171 // stop playing, keep buffers (for pause)
|
|
172 static void audio_pause()
|
|
173 {
|
|
174 // for now, just call reset();
|
2968
|
175 // reset();
|
|
176 int ioval;
|
|
177 fd_control = open( "/dev/em8300", O_WRONLY );
|
|
178 if( fd_control < 0 )
|
|
179 printf( "AO: [dxr3] Oops, unable to pause playback\n" );
|
|
180 else
|
|
181 {
|
|
182 ioval = EM8300_PLAYMODE_PAUSED;
|
|
183 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
|
|
184 printf( "AO: [dxr3] Unable to pause playback\n" );
|
|
185 close( fd_control );
|
|
186 }
|
2645
|
187 }
|
|
188
|
|
189 // resume playing, after audio_pause()
|
|
190 static void audio_resume()
|
|
191 {
|
2968
|
192 int ioval;
|
|
193 fd_control = open( "/dev/em8300", O_WRONLY );
|
|
194 if( fd_control < 0 )
|
|
195 printf( "AO: [dxr3] Oops, unable to resume playback\n" );
|
|
196 else
|
|
197 {
|
|
198 ioval = EM8300_PLAYMODE_PLAY;
|
|
199 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
|
|
200 printf( "AO: [dxr3] Unable to resume playback\n" );
|
|
201 close( fd_control );
|
|
202 }
|
2645
|
203 }
|
|
204
|
|
205
|
|
206 // return: how many bytes can be played without blocking
|
|
207 static int get_space()
|
|
208 {
|
2968
|
209 int space = 0;
|
|
210 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info) < 0 )
|
|
211 {
|
|
212 printf( "AO: [dxr3] Unable to get free space in buffer\n" );
|
|
213 return 0;
|
|
214 }
|
|
215
|
|
216 space = dxr3_buf_info.fragments*dxr3_buf_info.fragsize;
|
|
217 return space;
|
2645
|
218 }
|
|
219
|
|
220 static int play(void* data,int len,int flags)
|
|
221 {
|
2968
|
222 int pts = ao_pts;
|
|
223 if( ioctl( fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &pts ) < 0 )
|
|
224 printf( "AO: [dxr3] Unable to set pts\n" );
|
2921
|
225 return write(fd_audio,data,len);
|
2645
|
226 }
|
|
227
|
|
228 // return: how many unplayed bytes are in the buffer
|
|
229 static int get_delay()
|
|
230 {
|
2968
|
231 int r=0;
|
|
232 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 )
|
|
233 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
|
2921
|
234 return r;
|
2645
|
235 }
|
|
236
|